[Tex/LaTex] Upper case in chapter title? (Follow Up)

table of contents

As for my thesis, I asked today here but I still cannot use it because there are other packages and commands I need to modify the tables of contents. So here is the full minimum working template. I just want to make the chapter title in tocs to be All capital letters like "IV. TEST". Sorry for the long one.

 %!TEX TS-program = pdflatex
 \documentclass[fontsize=12pt]{report}
 \usepackage{mathptmx}
\usepackage{graphicx}
\usepackage[svgnames]{xcolor}
\usepackage{amssymb}
\usepackage{tocloft}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{indentfirst}
\usepackage[showframe,paperwidth=8.5in,paperheight=11in,top=1in,textwidth=5.8in,bottom=1in,left=1.25in,right=1.25in,footskip=0.3in]{geometry}% This is the page layout.
\usepackage{titling}
\usepackage{setspace}
\usepackage{afterpage}

\newif\ifintoc

\newcommand*{\PrintChapterTocHeadline}
{\hbox to \linewidth{\textbf{Chapter}\hfill\textbf{Page}}\bigskip
        \SetupNextPageOne}

\newcommand*{\SetupNextPageOne}
{\afterpage {\ifintoc\PrintChapterTocHeadline\fi}}

\addtocontents{toc}{\protect\PrintChapterTocHeadline}

\newif\ifinlof

\newcommand*{\PrintChapterLofHeadline}
    {\hbox to \linewidth{\textbf{Figure}\hfill\textbf{Page}}\bigskip
     \SetupNextPage}

\newcommand*{\SetupNextPage}
    {\afterpage {\ifinlof\PrintChapterLofHeadline\fi}}

\addtocontents{lof}{\protect\PrintChapterLofHeadline}


\renewcommand{\contentsname}{\fontsize{16pt}{18pt}\selectfont {\centerline{TABLE OF CONTENTS}}}
\renewcommand{\listfigurename}{\fontsize{16pt}{18pt}\selectfont {\centerline{LIST OF FIGURES}}}
\renewcommand{\cftchapfont}{\bfseries\MakeUppercase}
\makeatletter
\renewcommand*\l@chapter{\@dottedtocline{0}{1em}{2.3em}}
\renewcommand*\l@section{\@dottedtocline{1}{3.3em}{2.3em}}
\renewcommand*\l@subsection{\@dottedtocline{2}{5.6em}{2.3em}}
\renewcommand*\l@subsubsection{\@dottedtocline{3}{7.0em}{4.1em}}
\makeatother     \usepackage[pdftex,colorlinks,bookmarksnumbered,citecolor=blue,linkcolor=magenta,menucolor=black,pdftoolbar=false,urlcolor=DeepSkyBlue,pdftitle={Comprehensive Exam},pdfauthor={Thein Htay Oo},pdfsubject={Physics},pdfstartview=Fit,pdfdisplaydoctitle=true,pdfpagelayout=SinglePage]{hyperref}


\usepackage{titlesec}
\makeatletter
\def\ttl@mkchap@i#1#2#3#4#5#6#7{%
      \ttl@assign\@tempskipa#3\relax\beforetitleunit
      \vspace{-\@tempskipa}%<<<<<< REMOVE THE * AFTER \vspace
      \global\@afterindenttrue
      \ifcase#5 \global\@afterindentfalse\fi
      \ttl@assign\@tempskipb#4\relax\aftertitleunit
      \ttl@topmode{\@tempskipb}{%
          \ttl@select{#6}{#1}{#2}{#7}}%
      \ttl@finmarks  % Outside the box!
      \@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}}
\makeatother
   \usepackage{etoolbox}

\makeatletter
\pretocmd{\@sect}{\singlespacing}{}{}
\pretocmd{\@ssect}{\singlespacing}{}{}
\apptocmd{\@sect}{\doublespacing}{}{}
\apptocmd{\@ssect}{\doublespacing}{}{}
\makeatother


\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand \thesection{\arabic{chapter}.\arabic{section}}
\renewcommand \thesubsection{\arabic{chapter}.\arabic{section}.\arabic{subsection}}


   \renewcommand{\familydefault}{\rmdefault}
 \titleformat*{\section}{\singlespacing\fontsize{14}{18}\bfseries\rmfamily} 
 \titleformat*{\subsection}{\singlespacing\fontsize{12}{14}\bfseries\rmfamily}


 \titleformat{\chapter}[display] {\singlespacing\rmfamily\fontsize{16pt}{19pt}\bfseries}
    {\MakeUppercase{\chaptertitlename\ \thechapter}\filcenter}{10pt}{\centering\uppercase}
    {\fontsize{14pt}{16pt}\filcenter}   

 \titlespacing*{\chapter}{0pt}{0pt}{30pt}



\doublespacing


\renewcommand\thefigure{\arabic{chapter}.\arabic{figure}}


\begin{document}
\pagenumbering{Roman}
\begin{center}
\topskip0pt
\vspace*{\fill}
   ype dedication here, if any. Otherwise, delete this page.
\vspace*{\fill}
\end{center}
\pagebreak
\restoregeometry


\begingroup\intoctrue
\setlength{\cftbeforetoctitleskip}{-2.5em}
\tableofcontents
\endgroup

\begingroup\inloftrue
\newpage
\setlength{\cftbeforeloftitleskip}{-2.5em}
\listoffigures
\endgroup

\restoregeometry
\newpage

\setcounter{page}{1}
\pagenumbering{arabic}

\chapter{test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\begin{figure}
\caption{ms expected.}
\end{figure}
\begin{figure}
\caption{ms expected.}
\end{figure}
\begin{figure}
\caption{ms expected.}
\end{figure}
\chapter{Test}
\section{Test}
\section{Test}
\section{Test}
\chapter{test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\end{document}

Best Answer

You need to redefine the macro \@chapter in this way (since you're loading hyperref)

\makeatletter      
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \addcontentsline{toc}{chapter}%
                                   {\protect\numberline{\thechapter}\texorpdfstring{\uppercase{#1}}{#1}}%
                    \else
                      \addcontentsline{toc}{chapter}{\texorpdfstring{\uppercase{#1}}{#1}}%
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \fi}
\makeatother

(Not so) minimal example:

 %!TEX TS-program = pdflatex
 \documentclass[12pt]{report}
 \usepackage{mathptmx}
\usepackage{graphicx}
\usepackage[svgnames]{xcolor}
\usepackage{amssymb}
\usepackage{tocloft}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{indentfirst}
\usepackage[showframe,paperwidth=8.5in,paperheight=11in,top=1in,textwidth=5.8in,bottom=1in,left=1.25in,right=1.25in,footskip=0.3in]{geometry}% This is the page layout.
\usepackage{titling}
\usepackage{setspace}
\usepackage{afterpage}

\newif\ifintoc

\newcommand*{\PrintChapterTocHeadline}
{\hbox to \linewidth{\textbf{Chapter}\hfill\textbf{Page}}\bigskip
        \SetupNextPageOne}

\newcommand*{\SetupNextPageOne}
{\afterpage {\ifintoc\PrintChapterTocHeadline\fi}}

\addtocontents{toc}{\protect\PrintChapterTocHeadline}

\newif\ifinlof

\newcommand*{\PrintChapterLofHeadline}
    {\hbox to \linewidth{\textbf{Figure}\hfill\textbf{Page}}\bigskip
     \SetupNextPage}

\newcommand*{\SetupNextPage}
    {\afterpage {\ifinlof\PrintChapterLofHeadline\fi}}

\addtocontents{lof}{\protect\PrintChapterLofHeadline}


\renewcommand{\contentsname}{\fontsize{16pt}{18pt}\selectfont {\centerline{TABLE OF CONTENTS}}}
\renewcommand{\listfigurename}{\fontsize{16pt}{18pt}\selectfont {\centerline{LIST OF FIGURES}}}
\renewcommand{\cftchapfont}{\bfseries\MakeUppercase}
\makeatletter
\renewcommand*\l@chapter{\@dottedtocline{0}{1em}{2.3em}}
\renewcommand*\l@section{\@dottedtocline{1}{3.3em}{2.3em}}
\renewcommand*\l@subsection{\@dottedtocline{2}{5.6em}{2.3em}}
\renewcommand*\l@subsubsection{\@dottedtocline{3}{7.0em}{4.1em}}
\makeatother     \usepackage[pdftex,colorlinks,bookmarksnumbered,citecolor=blue,linkcolor=magenta,menucolor=black,pdftoolbar=false,urlcolor=DeepSkyBlue,pdftitle={Comprehensive Exam},pdfauthor={Thein Htay Oo},pdfsubject={Physics},pdfstartview=Fit,pdfdisplaydoctitle=true,pdfpagelayout=SinglePage]{hyperref}


\usepackage{titlesec}
\makeatletter
\def\ttl@mkchap@i#1#2#3#4#5#6#7{%
      \ttl@assign\@tempskipa#3\relax\beforetitleunit
      \vspace{-\@tempskipa}%<<<<<< REMOVE THE * AFTER \vspace
      \global\@afterindenttrue
      \ifcase#5 \global\@afterindentfalse\fi
      \ttl@assign\@tempskipb#4\relax\aftertitleunit
      \ttl@topmode{\@tempskipb}{%
          \ttl@select{#6}{#1}{#2}{#7}}%
      \ttl@finmarks  % Outside the box!
      \@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}}
\makeatother
   \usepackage{etoolbox}

\makeatletter
\pretocmd{\@sect}{\singlespacing}{}{}
\pretocmd{\@ssect}{\singlespacing}{}{}
\apptocmd{\@sect}{\doublespacing}{}{}
\apptocmd{\@ssect}{\doublespacing}{}{}
\makeatother


\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand \thesection{\arabic{chapter}.\arabic{section}}
\renewcommand \thesubsection{\arabic{chapter}.\arabic{section}.\arabic{subsection}}


   \renewcommand{\familydefault}{\rmdefault}
 \titleformat*{\section}{\singlespacing\fontsize{14}{18}\bfseries\rmfamily}
 \titleformat*{\subsection}{\singlespacing\fontsize{12}{14}\bfseries\rmfamily}


 \titleformat{\chapter}[display] {\singlespacing\rmfamily\fontsize{16pt}{19pt}\bfseries}
    {\MakeUppercase{\chaptertitlename\ \thechapter}\filcenter}{10pt}{\centering\uppercase}
    {\fontsize{14pt}{16pt}\filcenter}

 \titlespacing*{\chapter}{0pt}{0pt}{30pt}



\doublespacing


\renewcommand\thefigure{\arabic{chapter}.\arabic{figure}}

\makeatletter
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \addcontentsline{toc}{chapter}%
                                   {\protect\numberline{\thechapter}\texorpdfstring{\uppercase{#1}}{#1}}%
                    \else
                      \addcontentsline{toc}{chapter}{\texorpdfstring{\uppercase{#1}}{#1}}%
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \fi}
\makeatother

\begin{document}
\pagenumbering{Roman}
\begin{center}
\topskip0pt
\vspace*{\fill}
   ype dedication here, if any. Otherwise, delete this page.
\vspace*{\fill}
\end{center}
\pagebreak
\restoregeometry


\begingroup\intoctrue
\setlength{\cftbeforetoctitleskip}{-2.5em}
\tableofcontents
\endgroup

\begingroup\inloftrue
\newpage
\setlength{\cftbeforeloftitleskip}{-2.5em}
\listoffigures
\endgroup

\restoregeometry
\newpage

\setcounter{page}{1}
\pagenumbering{arabic}

\chapter{test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\begin{figure}
\caption{ms expected.}
\end{figure}
\begin{figure}
\caption{ms expected.}
\end{figure}
\begin{figure}
\caption{ms expected.}
\end{figure}
\chapter{Test}
\section{Test}
\section{Test}
\section{Test}
\chapter{test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\end{document} 

Output (ToC):

enter image description here