00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #pragma once
00012
00013 #include "TestToolBox/CommonSources/CommonDefinitions.h"
00014 #include "TestToolBox/TestTime.h"
00015 #include <time.h>
00016 #include <iomanip>
00017
00018
00019
00020
00021 namespace TestToolBox
00022 {
00023
00024
00025
00026
00027
00028 TTB_INLINE TestTime::TestTime():
00029 m_startTimeMs (0),
00030 m_startTimeDateStr ("unknown"),
00031 m_stopTimeDateStr ("unknown"),
00032 m_testDurationStr ("unknown")
00033 {
00034 StoreStartTime();
00035
00036 }
00037
00038
00039
00040
00041
00042
00043 TTB_INLINE void TestTime::StoreStartTime()
00044 {
00045
00046 m_startTimeMs = ::GetTickCount();
00047
00048
00049 time_t timeStartOfTest = time(0);
00050 struct tm localTimeStartOfTest;
00051 localtime_s(&localTimeStartOfTest,&timeStartOfTest);
00052 m_startTimeDateStr = FormatTimeAndDate (&localTimeStartOfTest);
00053
00054 }
00055
00056
00057
00058
00059
00060
00061 TTB_INLINE void TestTime::StoreStopTime()
00062 {
00063
00064 long stopTimeMs = ::GetTickCount();
00065 m_testDurationStr = FormatTestDuration (stopTimeMs - m_startTimeMs);
00066
00067
00068 time_t timeStopOfTest = time(0);
00069 struct tm localTimeStopOfTest;
00070 localtime_s(&localTimeStopOfTest,&timeStopOfTest);
00071 m_stopTimeDateStr = FormatTimeAndDate (&localTimeStopOfTest);
00072
00073 }
00074
00075
00076
00077
00078
00079
00080 TTB_INLINE void TestTime::ResetStopTime()
00081 {
00082 m_stopTimeDateStr = "unknown";
00083 m_testDurationStr = "unknown";
00084 }
00085
00086
00087
00088
00089
00090 TTB_INLINE std::string TestTime::GetStartTimeDateStr (void)
00091 {return m_startTimeDateStr;}
00092
00093 TTB_INLINE std::string TestTime::GetStopTimeDateStr (void)
00094 {
00095 if (m_testDurationStr == "unknown")
00096 {
00097 StoreStopTime();
00098 }
00099 return m_stopTimeDateStr;
00100 }
00101
00102 TTB_INLINE std::string TestTime::GetCurTimeDateStr(void)
00103 {
00104
00105 time_t timeNow = time(0);
00106 struct tm localTimeNow;
00107 localtime_s(&localTimeNow,&timeNow);
00108 return FormatTimeAndDate (&localTimeNow);
00109
00110 }
00111
00112 TTB_INLINE std::string TestTime::GetTestDurationStr (void)
00113 {
00114 if (m_stopTimeDateStr == "unknown")
00115 {
00116 StoreStopTime();
00117 }
00118 return m_testDurationStr;
00119 }
00120
00121 TTB_INLINE long TestTime::GetCurTimeMs (void)
00122 {return ::GetTickCount() - m_startTimeMs;}
00123
00124 TTB_INLINE long TestTime::GetCurTimeSec (void)
00125 {return GetCurTimeMs() / 1000;}
00126
00127 TTB_INLINE std::string TestTime::GetCurTimeStr (void)
00128 {return FormatTestDuration (::GetTickCount() - m_startTimeMs);}
00129
00130
00131
00132
00133
00134
00135 TTB_INLINE std::string TestTime::FormatTimeAndDate (
00136 struct tm* in_pTime)
00137 {
00138 std::ostringstream tmpStr;
00139 tmpStr << std::setw(2) << std::setfill('0') << in_pTime-> tm_mday << ".";
00140 tmpStr << std::setw(2) << std::setfill('0') << in_pTime-> tm_mon + 1 << ".";
00141 tmpStr << in_pTime-> tm_year + 1900 << " ";
00142 tmpStr << std::setw(2) << std::setfill('0') << in_pTime-> tm_hour << ":";
00143 tmpStr << std::setw(2) << std::setfill('0') << in_pTime-> tm_min << ":";
00144 tmpStr << std::setw(2) << std::setfill('0') << in_pTime-> tm_sec;
00145
00146 return tmpStr.str();
00147
00148 }
00149
00150
00151
00152
00153
00154
00155
00156 TTB_INLINE std::string TestTime::FormatTestDuration (
00157 long in_durationMs)
00158 {
00159 long hours = in_durationMs / 3600000;
00160 long minutes = in_durationMs % 3600000 / 60000;
00161 long seconds = in_durationMs % 60000 / 1000;
00162 long ms = in_durationMs % 1000;
00163
00164 std::ostringstream tmpStr;
00165 tmpStr << std::setw(2) << std::setfill('0') << hours << ":";
00166 tmpStr << std::setw(2) << std::setfill('0') << minutes << ":";
00167 tmpStr << std::setw(2) << std::setfill('0') << seconds << ",";
00168 tmpStr << std::setw(3) << std::setfill('0') << ms;
00169
00170 return tmpStr.str();
00171
00172 }
00173
00174
00175
00176
00177
00178
00179 };
00180
00181