00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #pragma once
00012
00013 #include "TestToolBox/CommonSources/CommonDefinitions.h"
00014 #include "TestToolBox/Protocol.h"
00015 #include "TestToolBox/TestTime.h"
00016 #include "TestToolBox/TestStream.h"
00017
00018
00019
00020
00021 namespace TestToolBox
00022 {
00023
00024
00025
00026
00027
00028
00029
00030 TTB_INLINE void Protocol::Write (
00031 std::string const & in_text)
00032 {
00033 AutoLock o (this);
00034 Write(OutputLevel::eREGULAR, TS().GetMode(), in_text);
00035
00036 }
00037
00038
00039
00040
00041
00042
00043 TTB_INLINE void Protocol::Writeln (
00044 std::string const & in_text)
00045 {
00046 AutoLock o (this);
00047 TS() << in_text.c_str() << std::endl;
00048
00049 }
00050
00051
00052
00053
00054
00055
00056 TTB_INLINE void Protocol::Write (
00057 OutputLevel::Enum in_outputLevel,
00058 unsigned char in_outputMode,
00059 std::string const & in_text)
00060 {
00061 AutoLock o (this);
00062 unsigned char oldMode = AdjustOutputMode(in_outputLevel, in_outputMode);
00063
00064 TS() << in_text.c_str();
00065
00066
00067 TS().SetMode(oldMode);
00068
00069 }
00070
00071
00072
00073
00074
00075 TTB_INLINE void Protocol::Writeln (
00076 OutputLevel::Enum in_outputLevel,
00077 unsigned char in_outputMode,
00078 std::string const & in_text)
00079 {
00080 AutoLock o (this);
00081 unsigned char oldMode = AdjustOutputMode(in_outputLevel, in_outputMode);
00082
00083 TS() << in_text.c_str() << std::endl;
00084
00085
00086 TS().SetMode(oldMode);
00087
00088 }
00089
00090
00091
00092
00093
00094 TTB_INLINE void Protocol::WriteFooter(unsigned char m)
00095 {
00096 OutputLevel::Enum o = OutputLevel::eREGULAR;
00097 Writeln(o,m,S_SEPARATOR_LINE);
00098 Writeln(o,m,"");
00099 Writeln(o,m,"Test started : " + TestTime::Get()->GetStartTimeDateStr());
00100 Writeln(o,m,"Test ended : " + TestTime::Get()->GetStopTimeDateStr());
00101 Writeln(o,m,"Duration : " + TestTime::Get()->GetTestDurationStr());
00102
00103 m_footerAlreadyWritten = true;
00104
00105 }
00106
00107
00108
00109
00110
00111
00112 TTB_INLINE void Protocol::SetMode (
00113 unsigned char in_newMode)
00114 {
00115 TS().SetMode(in_newMode);
00116 }
00117
00118 TTB_INLINE void Protocol::ResetMode (void)
00119 {
00120 TS().ResetMode();
00121 }
00122
00123 TTB_INLINE void Protocol::SetStreamActivation (
00124 unsigned char in_streamsToActivate)
00125 {
00126 TS().SetStreamActivation(in_streamsToActivate);
00127 }
00128
00129
00130
00131
00132
00133
00134 TTB_INLINE void Protocol::SwitchLogfiles (
00135 std::string const & in_postFixNewFileName,
00136 std::string const & in_msgClose,
00137 std::string const & in_msgOpen)
00138 {
00139
00140
00141 OutputLevel::Enum o = OutputLevel::eREGULAR;
00142 unsigned char m = OutputMode::M_OUTFILE | OutputMode::M_RPTFILE;
00143 Writeln(o,m,in_msgClose);
00144 if (m_outF.rdbuf()->is_open())
00145 {
00146 if (!m_footerAlreadyWritten)
00147 {
00148 WriteFooter(m);
00149 m_footerAlreadyWritten = false;
00150 }
00151
00152 m_outF.flush();
00153 m_outF.close();
00154
00155 m_rptF.flush();
00156 m_rptF.close();
00157 }
00158
00159
00160
00161
00162 TestTime::Get()->ResetStopTime();
00163 unsigned char allowedStreams = TS().GetStreamActivation();
00164
00165 std::string outFileName =
00166 TheEnvironment()->GetOutputDir() + "\\" +
00167 TheEnvironment()->GetAppName() + in_postFixNewFileName + ".out";
00168 if (allowedStreams & M_OUTFILE)
00169 {
00170 m_outF.open (outFileName.c_str(), std::ios::out);
00171 }
00172
00173 std::string rptFileName =
00174 TheEnvironment()->GetOutputDir() + "\\" +
00175 TheEnvironment()->GetAppName() + in_postFixNewFileName + ".rpt";
00176 if (allowedStreams & M_RPTFILE)
00177 {
00178 m_rptF.open (rptFileName.c_str(), std::ios::out);
00179 }
00180
00181 Writeln(o,m,in_msgOpen);
00182
00183 }
00184
00185
00186
00187
00188
00189
00190 TTB_INLINE void Protocol::SetOutputLevelForStdOut (
00191 OutputLevel::Enum in_outputLevel)
00192 {
00193 AutoLock o (this);
00194 m_activeOutputLevelForStdOut = in_outputLevel;
00195 }
00196
00197
00198
00199
00200
00201
00202 TTB_INLINE void Protocol::WriteHeader(void)
00203 {
00204 std::string outFileName =
00205 TheEnvironment()->GetOutputDir() + "\\" +
00206 TheEnvironment()->GetAppName() + ".out";
00207
00208 std::string rptFileName =
00209 TheEnvironment()->GetOutputDir() + "\\" +
00210 TheEnvironment()->GetAppName() + ".rpt";
00211
00212 OutputLevel::Enum o = OutputLevel::eREGULAR;
00213 unsigned char m = M_ALL;
00214 Writeln(o,m,"Generic test protocol template / TestToolBox (TTB) 2010\n\n");
00215 Writeln(o,m," T E S T P R O T O C O L\n");
00216 Writeln(o,m,"Date : " + TestTime::Get()->GetStartTimeDateStr());
00217 Writeln(o,m,"Test application : " + TheEnvironment()->GetExeFileFullPath());
00218 Writeln(o,m,"Test protocol : " + outFileName);
00219 Writeln(o,m,"Test report : " + rptFileName);
00220 Writeln(o,m,"Source path : " + TheEnvironment()->GetSourceDir());
00221 Writeln(o,m,"Command line args : " + TheEnvironment()->GetArgsStr());
00222 Writeln(o,m,"Run on computer : " + Environment::GetNameOfComputer());
00223 Writeln(o,m,"Run by : " + Environment::GetNameOfUser());
00224 Writeln(o,m,S_SEPARATOR_LINE);
00225
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 TTB_INLINE Protocol::Protocol(
00237 unsigned int in_allowedStreams,
00238 OutputLevel::Enum in_outputLevel)
00239 : m_footerAlreadyWritten (false)
00240 , m_pTestStream (0)
00241 , S_SEPARATOR_LINE ("________________________________________________________________________________")
00242 , m_activeOutputLevelForStdOut (in_outputLevel)
00243 {
00244 TRCF("Protocol::Protocol");
00245
00246 std::string outFileName =
00247 TheEnvironment()->GetOutputDir() + "\\" +
00248 TheEnvironment()->GetAppName() + ".out";
00249 if (in_allowedStreams & M_OUTFILE)
00250 {
00251 m_outF.open (outFileName.c_str(), std::ios::out);
00252 }
00253
00254 std::string rptFileName =
00255 TheEnvironment()->GetOutputDir() + "\\" +
00256 TheEnvironment()->GetAppName() + ".rpt";
00257 if (in_allowedStreams & M_RPTFILE)
00258 {
00259 m_rptF.open (rptFileName.c_str(), std::ios::out);
00260 }
00261
00262 m_pTestStream = new TestStream(
00263 &m_outF, &m_rptF);
00264
00265 TS().SetStreamActivation(in_allowedStreams);
00266
00267 TRC(TL_PROD,"Opened protocol: %s", outFileName.c_str());
00268
00269 WriteHeader();
00270
00271 }
00272
00273
00274
00275
00276
00277
00278 TTB_INLINE Protocol::~Protocol()
00279 {
00280 TRCF("Protocol::~Protocol");
00281 TRC(TL_DEBUG, "Destructor");
00282
00283 if (m_outF.rdbuf()->is_open())
00284 {
00285 if (!m_footerAlreadyWritten)
00286 {
00287 WriteFooter();
00288 }
00289
00290 m_outF.flush();
00291 m_outF.close();
00292
00293 m_rptF.flush();
00294 m_rptF.close();
00295 }
00296
00297 delete m_pTestStream;
00298 m_pTestStream = 0;
00299
00300 }
00301
00302
00303
00304
00305
00306
00307 TTB_INLINE TestStream& Protocol::TS (void)
00308 {return *m_pTestStream;}
00309
00310
00311
00312
00313
00314
00315 TTB_INLINE unsigned char Protocol::AdjustOutputMode(
00316 OutputLevel::Enum in_outputLevel,
00317 unsigned char in_outputMode)
00318 {
00319 unsigned char oldMode = TS().GetMode();
00320 unsigned char newMode = in_outputMode;
00321 if (in_outputLevel > m_activeOutputLevelForStdOut)
00322 {
00323
00324 newMode = newMode & (~M_STDOUT);
00325 }
00326
00327
00328
00329
00330 if ( in_outputLevel == OutputLevel::eVERBOUS
00331 && m_activeOutputLevelForStdOut < OutputLevel::eVERBOUS)
00332 {
00333
00334 newMode = newMode & (~M_OUTFILE);
00335 }
00336 TS().SetMode(newMode);
00337
00338 return oldMode;
00339
00340 }
00341
00342
00343
00344
00345
00346
00347 };
00348
00349