MsgOStreamServiceValidate Class Reference

#include <MsgOStreamServiceValidate.h>

List of all members.

Public Member Functions

 MsgOStreamServiceValidate ()
 ~MsgOStreamServiceValidate ()
bool RunAllTests ()

Private Member Functions

bool TestMsgStandardOStream ()
bool TestMsgFileOStream ()
bool TestMsgOStreamService ()
bool TestMsgCustonStream ()


Detailed Description

Definition at line 10 of file MsgOStreamServiceValidate.h.


Constructor & Destructor Documentation

MsgOStreamServiceValidate::MsgOStreamServiceValidate (  ) 

Definition at line 96 of file MsgOStreamServiceValidate.cxx.

00096 {}

MsgOStreamServiceValidate::~MsgOStreamServiceValidate (  ) 

Definition at line 100 of file MsgOStreamServiceValidate.cxx.

00100 {}


Member Function Documentation

bool MsgOStreamServiceValidate::RunAllTests (  ) 

Definition at line 340 of file MsgOStreamServiceValidate.cxx.

References TestMsgCustonStream(), TestMsgFileOStream(), TestMsgOStreamService(), and TestMsgStandardOStream().

Referenced by main(), and MsgServiceValidate::RunAllTests().

00341 {
00342   bool passed = true;
00343 
00344   passed &= this->TestMsgStandardOStream();
00345   passed &= this->TestMsgFileOStream();
00346   passed &= this->TestMsgOStreamService();
00347   passed &= this->TestMsgCustonStream();
00348   
00349   return passed;
00350 }

bool MsgOStreamServiceValidate::TestMsgCustonStream (  )  [private]

Definition at line 288 of file MsgOStreamServiceValidate.cxx.

References MsgOStreamService::GetStream(), MsgOStreamService::Instance(), and MsgOStream::Os().

Referenced by RunAllTests().

00289 {
00290 //======================================================================
00291 // Test if we can use the custon stream defined at the top of this file
00292 //======================================================================
00293   int passed = 1;
00294   MsgOStream *s1a, *s1b;
00295   MsgOStream *s2a, *s2b;
00296 
00297   cout << "===== testMsgCustomStream\n";
00298   
00299   s1a = MsgOStreamService::Instance()->GetStream("G4cout");
00300   if (s1a == 0) {
00301     cout << "testMsgCustonStream:: Failed to get stream s1a G4cout\n";
00302     passed &= 0;
00303   }
00304   s1b = MsgOStreamService::Instance()->GetStream("G4cout");
00305   if (s1b == 0) {
00306     cout << "testMsgCustonStream:: Failed to get stream s1b G4cout\n";
00307     passed &=0;
00308   }
00309   if (s1a != s1b) {
00310     cout << "testMsgCustonStream:: Failed to get same stream for G4cout\n";
00311     passed &=0;
00312   }
00313 
00314   s2a = MsgOStreamService::Instance()->GetStream("G4cerr");
00315   if (s2a == 0) {
00316     cout << "testMsgCustonStream:: Failed to get stream s2a G4cerr\n";
00317     passed &=0;
00318   }
00319   s2b = MsgOStreamService::Instance()->GetStream("G4cerr");
00320   if (s2b == 0) {
00321     cout << "testMsgCustonStream:: Failed to get stream s2a G4cerr\n";
00322     passed &=0;
00323   }
00324   if (s2a != s2b) {
00325     cout << "testMsgCustonStream:: Failed to get same stream for G4cerr\n";
00326     passed &=0;
00327   }
00328 
00329   s1a->Os() << "This is a message to G4cout\n";
00330   s1b->Os() << "This is a message to G4cerr\n";
00331   
00332   if (!passed) {
00333     cout << "===== testMsgCustomStream FAILED!!\n";
00334   }
00335   return passed;
00336 }

bool MsgOStreamServiceValidate::TestMsgFileOStream (  )  [private]

Definition at line 168 of file MsgOStreamServiceValidate.cxx.

References MsgOStream::AddReference(), MsgFileOStream::Close(), MsgOStream::Flush(), MsgFileOStream::GetName(), MsgOStream::GetNreference(), MsgFileOStream::Os(), and MsgOStream::SubtractReference().

Referenced by RunAllTests().

00169 {
00170   int passed = 1;
00171   MsgFileOStream msgFile1("osfile1.txt", ios::out);
00172   MsgFileOStream msgFile2("osfile2.txt", ios::out);
00173   MsgFileOStream msgFile3("osfile3.txt", ios::out);
00174 
00175   cout << "===== testMsgFileOStream()\n";
00176   /*
00177   // GCC 4.5.0 warns that address of these will never be NULL
00178   // they're built on the stack, not on the heap
00179   cout << "Test creators...";
00180   if (&msgFile1==0 || &msgFile2==0 || &msgFile3==0) {
00181     passed &= 0;
00182     cout << "Failed!!!\n";
00183   }
00184   else {
00185     cout << "Done.\n";
00186   }
00187   */
00188 
00189   msgFile1.Os() << "This message should go to osfile1.txt\n";
00190   msgFile2.Os() << "This message should go to osfile2.txt\n";
00191   msgFile3.Os() << "This message should go to osfile3.txt\n";
00192   cout << "Check files osfile[123].txt for correct output\n";
00193 
00194   cout << "Check names : "
00195        << "<msgFile1 : " << msgFile1.GetName() << "> "
00196        << "<msgFile2 : " << msgFile2.GetName() << "> "
00197        << "<msgFile3 : " << msgFile3.GetName() << ">\n";
00198 
00199   cout << "Check reference counting:\n";
00200   cout << " Add      " << msgFile1.AddReference() << "\n";
00201   cout << " Add      " << msgFile1.AddReference() << "\n";
00202   if (msgFile1.GetNreference() != 2) {
00203     cout << "Failed!!";
00204     passed &= 0;
00205   }
00206   cout << " Subtract " << msgFile1.SubtractReference() << "\n";
00207   cout << " Subtract " << msgFile1.SubtractReference() << "\n";
00208   if (msgFile1.GetNreference() != 0) {
00209     cout << "Failed!!";
00210     passed &= 0;
00211   }
00212 
00213   msgFile1.Flush();
00214   msgFile2.Flush();
00215   msgFile3.Flush();
00216 
00217   msgFile1.Close();
00218   msgFile2.Close();
00219   msgFile3.Close();
00220 
00221   return passed;
00222 }

bool MsgOStreamServiceValidate::TestMsgOStreamService (  )  [private]

Definition at line 226 of file MsgOStreamServiceValidate.cxx.

References MsgOStream::GetNreference(), MsgOStreamService::GetStream(), and MsgOStreamService::Instance().

Referenced by RunAllTests().

00227 {
00228   int passed = 1;
00229   MsgOStreamService* msgOStreamService;
00230   MsgOStreamService* msgOStreamService2;
00231   MsgOStream* s1;
00232   MsgOStream* s2;
00233   MsgOStream* s3;
00234   MsgOStream* s4;
00235   
00236   msgOStreamService  = MsgOStreamService::Instance();
00237   msgOStreamService2 = MsgOStreamService::Instance();
00238   
00239   cout << "Check singleton behavior...";
00240   if (msgOStreamService != msgOStreamService2) {
00241     cout << "Singleton Behavior Failed\n";
00242     passed &= 0;
00243   }
00244   else {
00245     cout << "Done.\n";
00246   }
00247   
00248   cout << "Check stream fetching for cout...";
00249   s1 = msgOStreamService->GetStream("cout");
00250   s2 = msgOStreamService->GetStream("cout");
00251   if (s1 != s2) {
00252     cout << "Failed to give identical streams for cout\n";
00253     passed &= 0;
00254   }
00255   else {
00256     cout << "Done.\n";
00257   }
00258 
00259   cout << "Check stream fetching for afile.txt...";
00260   s3 = msgOStreamService->GetStream("afile.txt");
00261   s4 = msgOStreamService->GetStream("afile.txt");
00262   if (s3 != s4) {
00263     cout << "Failed to give identical streams for afile.txt\n";
00264     passed &= 0;
00265   }
00266   else {
00267     cout << "Done.\n";
00268   }
00269 
00270   cout << "Check reference counting...";
00271   if (s1->GetNreference() != 2) {
00272     cout << " N = " 
00273          << s1->GetNreference();
00274     cout << "Failed to count references for cout\n";
00275   }
00276   if (s3->GetNreference() != 2) {
00277     cout << " N = " 
00278          << s3->GetNreference();
00279     cout << "Failed to count references for afile.txt\n";
00280   }
00281   cout << "Done.\n";
00282   
00283   return passed;
00284 }

bool MsgOStreamServiceValidate::TestMsgStandardOStream (  )  [private]

Definition at line 104 of file MsgOStreamServiceValidate.cxx.

References MsgOStream::AddReference(), MsgStandardOStream::Close(), MsgOStream::Flush(), MsgStandardOStream::GetName(), MsgOStream::GetNreference(), MsgStandardOStream::Os(), and MsgOStream::SubtractReference().

Referenced by RunAllTests().

00105 {
00106   int passed = 1;
00107   MsgStandardOStream msgCout("cout");
00108   MsgStandardOStream msgCerr("cerr");
00109   MsgStandardOStream msgClog("clog");
00110 
00111   cout << "===== testMsgStandardOStream()\n";
00112   /*
00113   // GCC 4.5.0 warns that address of these will never be NULL 
00114   // they're built on the stack, not on the heap
00115  cout << "Test creators...";
00116   if (&msgCout==0 || &msgCerr==0 || &msgClog==0) {
00117     passed &= 0;
00118     cout << "Failed!!!\n";
00119   }
00120   else {
00121     cout << "Done.\n";
00122   }
00123   */
00124 
00125   cout << "Test output streams are correct...";
00126   if ((&msgCout.Os()==&cout) && 
00127       (&msgCerr.Os()==&cerr) && 
00128       (&msgClog.Os()==&clog)) {
00129     cout << "Done.\n";
00130   }
00131   else {
00132     cout << "Failed!!!\n";
00133     passed &= 0;
00134   }
00135 
00136   cout << "Check names : "
00137        << "<msgCout : " << msgCout.GetName() << "> "
00138        << "<msgCerr : " << msgCerr.GetName() << "> "
00139        << "<msgClog : " << msgClog.GetName() << ">\n";
00140 
00141   cout << "Check reference counting:\n";
00142   cout << " Add      " << msgCout.AddReference() << "\n";
00143   cout << " Add      " << msgCout.AddReference() << "\n";
00144   if (msgCout.GetNreference() != 2) {
00145     cout << "Failed!!";
00146     passed &= 0;
00147   }
00148   cout << " Subtract " << msgCout.SubtractReference() << "\n";
00149   cout << " Subtract " << msgCout.SubtractReference() << "\n";
00150   if (msgCout.GetNreference() != 0) {
00151     cout << "Failed!!";
00152     passed &= 0;
00153   }
00154 
00155   msgCout.Flush();
00156   msgCerr.Flush();
00157   msgClog.Flush();
00158 
00159   msgCout.Close();
00160   msgCerr.Close();
00161   msgClog.Close();
00162 
00163   return passed;
00164 }


The documentation for this class was generated from the following files:
Generated on Mon Aug 11 01:06:16 2014 for loon by  doxygen 1.4.7