Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

TestComponent.cc

Go to the documentation of this file.
00001 #include "TestComponent.hh"
00002 
00003 namespace ccunit {
00004 
00005 ostream &
00006 operator<<(ostream &ostr, const TestComponent::ErrorReport &my_error_report)
00007 {
00008   ostr << my_error_report.m_fname
00009        << ":" << my_error_report.m_lineno 
00010        << ": failure: (" << my_error_report.m_lbl << "), "
00011        << " in \"" << my_error_report.m_fnt_name << "\"";
00012 
00013   return ostr;
00014 }
00015 
00016 
00017 
00018 TestComponent::TestComponent(const string &name) : 
00019   m_nPass(0),
00020   m_nFail(0),
00021   m_hasRun(false),
00022   m_name(name)
00023 {
00024 }
00025 
00026 // Destructor (does nothing)
00027 TestComponent::~TestComponent()
00028 {
00029   // wheeeee
00030 }
00031 
00032 TestComponent::ErrorReport::ErrorReport(const char* type_name, 
00033                                         const string& lbl,
00034                                         const char* fname,
00035                                         const char* fnt_name,                                   
00036                                         long lineno) :
00037   m_to_name(type_name),
00038   m_lbl(lbl),
00039   m_fname(fname),
00040   m_fnt_name(fnt_name),
00041   m_lineno(lineno)
00042 {
00043 }
00044 
00045 void
00046 TestComponent::run()
00047 {
00048   reset();
00049   this->run_tests();
00050   m_hasRun = true;
00051 }
00052 
00053 
00054 bool
00055 TestComponent::hasRun()
00056 {
00057   return m_hasRun;
00058 }
00059 
00060 void
00061 TestComponent::checkRun()
00062 {
00063   if(!m_hasRun) {
00064     run();
00065   }
00066 
00067   // This had better be true, otherwise the run method failed completely
00068   assert(m_hasRun == true);
00069 }
00070 
00071 unsigned long
00072 TestComponent::getNumPassed()
00073 {
00074   checkRun();
00075   return m_nPass;
00076 }
00077 
00078 unsigned long
00079 TestComponent::getNumFailed()
00080 {
00081   checkRun();
00082   return m_nFail;
00083 }
00084 
00085 void
00086 TestComponent::reset()
00087 {
00088   m_nPass = m_nFail = 0;
00089   m_hasRun = false;
00090 
00091   // Discard any errors from previous run
00092   m_failures.erase(m_failures.begin(), m_failures.end());
00093 }
00094 
00095 ostream &
00096 operator<<(ostream &ostr, TestComponentPtr my_test_component)
00097 {
00098   my_test_component->report(ostr);
00099   return ostr;
00100 }
00101 
00103 ostream &
00104 operator<<(ostream &ostr, TestComponent& my_test_component)
00105 {
00106   my_test_component.report(ostr);
00107   return ostr;
00108 }
00109 
00110 } // namespace ccunit

Generated on Tue Apr 2 15:33:22 2002 for libccunit by doxygen 1.2.14 written by Dimitri van Heesch, © 1997-2002

Project hosted on sourceforge SourceForge Logo