TVldValidate is a test harness for Validity package. More...
#include <TVldValidate.hxx>
Public Member Functions | |
TVldValidate () | |
virtual | ~TVldValidate () |
Bool_t | RunAllTests () |
Bool_t | TestTimeStamp (void) |
Bool_t | TestContext (void) |
Bool_t | TestRange (void) |
Bool_t | TestFileIO (void) |
Protected Member Functions | |
Bool_t | CompareTimeStamps (const char *label, TVldTimeStamp &test, TVldTimeStamp &std) |
TVldValidate is a test harness for Validity package.
Author: R. Hatcher 2001.01.03
Definition at line 21 of file TVldValidate.hxx.
TVldValidate::TVldValidate | ( | ) |
TVldValidate::~TVldValidate | ( | ) | [virtual] |
Definition at line 40 of file TVldValidate.cxx.
Bool_t TVldValidate::CompareTimeStamps | ( | const char * | label, | |
TVldTimeStamp & | test, | |||
TVldTimeStamp & | std | |||
) | [protected] |
Definition at line 218 of file TVldValidate.cxx.
References TVldTimeStamp::AsString(), and SK_DBI_Info.
Referenced by TestTimeStamp().
00220 { 00221 if (test == std) { 00222 SK_DBI_Info( " exact match " << " "); 00223 return kTRUE; 00224 } 00225 else { 00226 SK_DBI_Info( " ** mismatch ** " << " "); 00227 SK_DBI_Info( " " << test.AsString() << " "); 00228 SK_DBI_Info( " " << std.AsString() << " "); 00229 return kFALSE; 00230 } 00231 }
Bool_t TVldValidate::RunAllTests | ( | ) |
Definition at line 47 of file TVldValidate.cxx.
References SK_DBI_Info, TestContext(), TestFileIO(), TestRange(), and TestTimeStamp().
00048 { 00049 Int_t fail = 0; 00050 Int_t tests = 0; 00051 00052 tests++; 00053 if (!TestTimeStamp()) fail++; 00054 00055 tests++; 00056 if (!TestContext()) fail++; 00057 00058 tests++; 00059 if (!TestRange()) fail++; 00060 00061 tests++; 00062 if (!TestFileIO()) fail++; 00063 00064 SK_DBI_Info( "VldValidate::RunAllTests had " << fail 00065 << " failures in " << tests << " tests" 00066 << " " << endl); 00067 00068 return (!fail); 00069 00070 }
Bool_t TVldValidate::TestContext | ( | void | ) |
Definition at line 234 of file TVldValidate.cxx.
References TVldContext::AsString(), and SK_DBI_Info.
Referenced by RunAllTests().
00235 { 00236 // Test TVldContext 00237 00238 cout << "Test TVldContext" << endl << endl; 00239 00240 Int_t fail = 0; 00241 00242 map<TVldContext,long> vldc_map; 00243 long int entry = 0; 00244 00245 TVldContext defctor; 00246 SK_DBI_Info( "VldContext default ctor: " 00247 << defctor.AsString("") << " "); 00248 vldc_map[defctor] = entry++; 00249 // gSystem->Sleep(2000); // sleep for 2 sec so timestamp advances 00250 00251 TVldContext defctor2; 00252 vldc_map[defctor2] = entry++; 00253 // gSystem->Sleep(2000); // sleep for 2 sec so timestamp advances 00254 00255 // for the same timestamp try different combinations of detector & simflag 00256 // in the expected order that it will sort 00257 // (detector primary over simflag --> detector in outer loop) 00258 SK_DBI_Info( "VldContext test map<TVldContext,long>" << " "); 00259 TVldTimeStamp now; 00260 for (Int_t ibit_det = 0; ibit_det<3; ibit_det++) { 00261 DbiDetector::Detector_t det = 00262 (DbiDetector::Detector_t) (1<<ibit_det); 00263 for (Int_t ibit_sim = 0; ibit_sim<4; ibit_sim++) { 00264 DbiSimFlag::SimFlag_t sim = (DbiSimFlag::SimFlag_t) (1<<ibit_sim); 00265 00266 TVldContext vldc(det,sim,now); 00267 // MSG("Vld",Msg::kInfo) 00268 // << " entry " << setw(2) << entry << " : " 00269 // << vldc.AsString() 00270 // << endl; 00271 vldc_map[vldc] = entry++; 00272 00273 } 00274 } 00275 typedef map<TVldContext,long>::const_iterator vcl_itr; 00276 int expect = 0; 00277 bool pass = true; 00278 for (vcl_itr p = vldc_map.begin(); p != vldc_map.end(); ++p, ++expect) { 00279 TVldContext ac = p->first; 00280 long al = p->second; 00281 if (al != expect) pass = false; 00282 SK_DBI_Info( " " << setw(2) << expect << " ? " << setw(2) << al << " : " 00283 << ac.AsString() 00284 << " "); 00285 } 00286 if (!pass) fail++; 00287 00288 00289 SK_DBI_Info( " Test output to MSG service: " << defctor << " "); 00290 00291 SK_DBI_Info( "VldValidate::TestContext had " << fail << " failures " 00292 << " " << endl); 00293 00294 return (!fail); 00295 }
Bool_t TVldValidate::TestFileIO | ( | void | ) |
Definition at line 320 of file TVldValidate.cxx.
References SK_DBI_Info.
Referenced by RunAllTests().
00321 { 00322 // Test write/read Validity objects to/from a file 00323 00324 cout << "Test file IO" << endl << endl; 00325 00326 // UInt_t sleep_msec = 2000; 00327 00328 // ****************** OUTPUT ******************************* 00329 00330 TFile fout("vld_io.root","RECREATE"); 00331 00332 TVldTimeStamp out_ts; 00333 TVldContext out_c; 00334 TVldRange out_r; 00335 00336 //VldTimeStamp not derived from TObject 00337 // out_ts.Write(); 00338 out_c.Write(); 00339 out_r.Write(); 00340 00341 fout.ls(); 00342 fout.Close(); 00343 00344 // ****************** Pause ******************************* 00345 00346 SK_DBI_Info( " " << endl); 00347 // gSystem->Sleep(sleep_msec); 00348 TVldContext pause_c; 00349 00350 // ****************** INPUT ******************************* 00351 00352 TFile fin("vld_io.root","READ"); 00353 fin.ls(); 00354 00355 // TVldTimeStamp *in_ts = dynamic_cast<VldTimeStamp*>(fin.Get("VldTimeStamp")); 00356 TVldContext *in_c = dynamic_cast<TVldContext*>(fin.Get("VldContext")); 00357 00358 fin.Close(); 00359 00360 // ****************** Comparison ******************************* 00361 00362 SK_DBI_Info( " " << endl); 00363 00364 // gSystem->Sleep(sleep_msec); 00365 TVldContext final_c; 00366 00367 // out_ts.Print(); 00368 // in_ts->Print(); 00369 00370 SK_DBI_Info( " wrote TVldContext: " << out_c << " "); 00371 SK_DBI_Info( " interm TVldContext: " << pause_c << " "); 00372 SK_DBI_Info( " read TVldContext: " << (*in_c) << " "); 00373 SK_DBI_Info( " final TVldContext: " << final_c << " "); 00374 00375 Int_t fail = 0; 00376 00377 // cout << "default ctor: "; 00378 // TVldRange defctor; 00379 // defctor.Print(""); 00380 00381 00382 SK_DBI_Info( "VldValidate::TestRange had " << fail << " failures " 00383 << " " << endl); 00384 00385 return (!fail); 00386 00387 }
Bool_t TVldValidate::TestRange | ( | void | ) |
Definition at line 298 of file TVldValidate.cxx.
References TVldRange::Print(), and SK_DBI_Info.
Referenced by RunAllTests().
00299 { 00300 // Test TVldRange 00301 00302 cout << "Test TVldRange" << endl << endl; 00303 00304 Int_t fail = 0; 00305 00306 cout << "default ctor: "; 00307 TVldRange defctor; 00308 defctor.Print(""); 00309 00310 SK_DBI_Info( " Test output to MSG service: " << defctor << " "); 00311 00312 SK_DBI_Info( "VldValidate::TestRange had " << fail << " failures " 00313 << " " << endl); 00314 00315 return (!fail); 00316 00317 }
Bool_t TVldValidate::TestTimeStamp | ( | void | ) |
Definition at line 73 of file TVldValidate.cxx.
References TVldTimeStamp::AsString(), CompareTimeStamps(), TVldTimeStamp::GetDate(), TVldTimeStamp::GetTime(), TVldTimeStamp::GetTimeSpec(), TVldTimeStamp::GetZoneOffset(), TVldTimeStamp::Print(), SK_DBI_Info, and SK_DBI_Log.
Referenced by RunAllTests().
00074 { 00075 // Test TVldTimeStamp behaviour 00076 00077 cout << "Test TVldTimeStamp" << endl << endl; 00078 00079 Int_t fail = 0; 00080 Int_t tests = 0; 00081 00082 cout << "default ctor: " << flush; 00083 TVldTimeStamp defctor; 00084 defctor.Print(""); 00085 00086 SK_DBI_Info( " Test output to MSG service: " << defctor << " " << endl); 00087 00088 time_t nowtime; 00089 time(&nowtime); 00090 long int nsec = 12345; 00091 00092 struct timespec nowts; 00093 nowts.tv_sec = nowtime; 00094 nowts.tv_nsec = nsec; 00095 00096 SK_DBI_Info( " original timespec: {" << nowtime << "," << nsec << "} " << " "); 00097 00098 TVldTimeStamp vldnow(nowts); 00099 // do these as separate // reuses a common buffer space 00100 SK_DBI_Log( " vldnow as timespec: " << vldnow.AsString("2") << " "); 00101 SK_DBI_Info( " vldnow default AsString: " << vldnow.AsString("") << " "); 00102 SK_DBI_Info( " vldnow local AsString: " << vldnow.AsString("l") << " "); 00103 00104 struct timespec thents = vldnow.GetTimeSpec(); 00105 00106 SK_DBI_Info( " recovered timespec: {" << thents.tv_sec << "," << thents.tv_nsec << "} " << " "); 00107 00108 tests++; 00109 if (nowts.tv_sec != thents.tv_sec || nowts.tv_nsec != thents.tv_nsec) fail++; 00110 00111 00112 // test various ctor's 00113 // all should map to Jan 04 2001, 01:26:03 GMT 00114 time_t mytime = 978571563; 00115 Long_t arbitrary = 123456; // fake nsec part 00116 00117 timespec mytimespec = {mytime,arbitrary}; 00118 TVldTimeStamp vtr(mytime,arbitrary); 00119 TVldTimeStamp vtsr(mytimespec); 00120 00121 Int_t year = 2001; 00122 Int_t month = 1; 00123 Int_t day = 4; 00124 Int_t hour = 1; 00125 Int_t min = 26; 00126 Int_t sec = 3; 00127 Int_t secOffset = vtr.GetZoneOffset(); 00128 00129 TVldTimeStamp vl1(year,month,day,hour,min,sec,arbitrary); 00130 TVldTimeStamp vl2(year,month,day,hour,min,sec,arbitrary,kFALSE,-secOffset); 00131 TVldTimeStamp vl3(year,month,day,hour-8,min,sec,arbitrary,kTRUE,8*60*60); 00132 TVldTimeStamp vl4(year,month,day-1,hour+16,min,sec,arbitrary,kTRUE,8*60*60); 00133 // this will only give correct results in PST zone 00134 TVldTimeStamp vlpst(year,month,day,hour-8,min,sec,arbitrary,kFALSE); 00135 00136 TVldTimeStamp vly1(year-1900,month,day,hour,min,sec,arbitrary); 00137 TVldTimeStamp vly2(year-2000,month,day,hour,min,sec,arbitrary); 00138 00139 Int_t date = year*10000 + month*100 + day; 00140 Int_t time = hour*10000 + min*100 + sec; 00141 00142 TVldTimeStamp vs1(date,time,arbitrary); 00143 TVldTimeStamp vs2(date,time,arbitrary,kFALSE,-secOffset); 00144 // these next two aren't a smart way of dealing with local time 00145 TVldTimeStamp vs3(date-1,time+160000,arbitrary,kTRUE,8*60*60); 00146 TVldTimeStamp vs4(date,time-80000,arbitrary,kTRUE,8*60*60); 00147 // the next two will only give correct results in PST zone 00148 TVldTimeStamp vspst1(date,time-80000,arbitrary,kFALSE); 00149 TVldTimeStamp vspst2(date-1,time+160000,arbitrary,kFALSE); 00150 TVldTimeStamp vsy1(date-19000000,time,arbitrary); 00151 TVldTimeStamp vsy2(date-20000000,time,arbitrary); 00152 00153 SK_DBI_Info( " current TimeOffset is " << vtr.GetZoneOffset() << " "); 00154 00155 SK_DBI_Info( " "); 00156 SK_DBI_Info( " std (vtr) " << vtr.AsString() << " "); 00157 00158 TString byhand = "Thu, 04 Jan 2001 01:26:03 +0000 (GMT) + 123456 nsec"; 00159 TString byclass = vtr.AsString(); 00160 tests++; 00161 if (byhand != byclass) { 00162 SK_DBI_Info( " strings don't match!" << " "); 00163 fail++; 00164 } 00165 else { 00166 SK_DBI_Info( " strings match as they should " << " "); 00167 } 00168 00169 tests++; if (!CompareTimeStamps(" vtsr ",vtsr,vtr)) fail++; 00170 tests++; if (!CompareTimeStamps(" vl1 ",vl1,vtr)) fail++; 00171 tests++; if (!CompareTimeStamps(" vl2 ",vl2,vtr)) fail++; 00172 tests++; if (!CompareTimeStamps(" vl3 ",vl3,vtr)) fail++; 00173 tests++; if (!CompareTimeStamps(" vl4 ",vl4,vtr)) fail++; 00174 tests++; if (!CompareTimeStamps(" vly1 ",vly1,vtr)) fail++; 00175 tests++; if (!CompareTimeStamps(" vly2 ",vly2,vtr)) fail++; 00176 tests++; if (!CompareTimeStamps(" vs1 ",vs1,vtr)) fail++; 00177 tests++; if (!CompareTimeStamps(" vs2 ",vs2,vtr)) fail++; 00178 tests++; if (!CompareTimeStamps(" vs3 ",vs3,vtr)) fail++; 00179 tests++; if (!CompareTimeStamps(" vs4 ",vs4,vtr)) fail++; 00180 tests++; if (!CompareTimeStamps(" vsy1 ",vsy1,vtr)) fail++; 00181 tests++; if (!CompareTimeStamps(" vsy2 ",vsy2,vtr)) fail++; 00182 00183 if (secOffset == 28800) { 00184 tests++; if (!CompareTimeStamps(" vlpst ",vlpst,vtr)) fail++; 00185 tests++; if (!CompareTimeStamps(" vspst1 ",vspst1,vtr)) fail++; 00186 tests++; if (!CompareTimeStamps(" vspst2 ",vspst2,vtr)) fail++; 00187 } 00188 00189 SK_DBI_Info( " next test expects to be a mismatch" << " "); 00190 CompareTimeStamps(" now is unlikely to match arbitrary time ",vldnow,vtr); 00191 00192 SK_DBI_Info( " Alternative formats" << " "); 00193 SK_DBI_Info( " \"\" " << vtr.AsString("") << " "); 00194 SK_DBI_Info( " \"l\" " << vtr.AsString("l") << " "); 00195 SK_DBI_Info( " \"c\" " << vtr.AsString("c") << " "); 00196 SK_DBI_Info( " \"lc\" " << vtr.AsString("lc") << " "); 00197 SK_DBI_Info( " \"2\" " << vtr.AsString("2") << " "); 00198 00199 tests++; if (vtr.GetDate() != date) fail++; 00200 tests++; if (vtr.GetTime() != time) fail++; 00201 00202 MsgFormat i6("%6d"); 00203 00204 SK_DBI_Info( " GMT GetDate: " << vtr.GetDate() 00205 << " GetTime: " << i6(vtr.GetTime()) << " "); 00206 SK_DBI_Info( " local GetDate: " << vtr.GetDate(kFALSE) 00207 << " GetTime: " << i6(vtr.GetTime(kFALSE)) << " "); 00208 00209 SK_DBI_Info( "VldValidate::TestTimeStamp had " << fail 00210 << " failures in " << tests << " tests" 00211 << " " << endl); 00212 00213 return (!fail); 00214 00215 }