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

UnitTest.hh

Go to the documentation of this file.
00001 /* -*-Mode:C++ -*- */
00002 #ifndef UNITTEST_HH
00003 #define UNITTEST_HH
00004 
00005 #include "TestForward.hh"
00006 #include "TestComponent.hh"
00007 
00008 // Grab all the iostream forward declarations
00009 #include <iosfwd>
00010 
00011 #include <string>
00012 
00013 
00014 namespace ccunit {
00015 
00016 // The following have underscores because they are macros
00017 // (and it's impolite to usurp other users' functions!).
00018 // For consistency, _succeed() also has an underscore.
00019 
00020 
00021 
00022 #ifdef __GNUC__
00023 
00027 #  define _test(cond) do_test(cond, #cond, __FILE__, __PRETTY_FUNCTION__, __LINE__)
00028 
00032 #  define _fail(str) do_fail(str, __FILE__, __PRETTY_FUNCTION__,  __LINE__)
00033 #else
00034 
00038 #  define _test(cond) do_test(cond, #cond, __FILE__, __FUNCTION__, __LINE__)
00039 
00043 #  define _fail(str) do_fail(str, __FILE__, __FUNCTION__,  __LINE__)
00044 #endif
00045 
00079 class UnitTest : public TestComponent
00080 {
00081 public:
00083   UnitTest(const string &name = "(no name)");
00084 
00086   virtual ~UnitTest() {}
00087 
00088   // ********** TestComponent Methods **********
00090   virtual void report(ostream &ostr);
00091 
00093   void _succeed();
00094 
00095 protected:
00105   bool do_test(bool cond, const std::string& lbl,
00106                const char* fname, const char* fnt_name, long lineno);
00107 
00116   void do_fail(const std::string& lbl,
00117                const char* fname, const char* fnt_name, long lineno);
00118 
00120   virtual void run_tests() = 0;
00121 
00122 private:
00123 
00124   // Disallowed:
00125   UnitTest(const UnitTest&);
00126   UnitTest& operator=(const UnitTest&);
00127 
00128 };
00129 
00130 inline
00131 UnitTest::UnitTest(const string &name = "(no name)") :
00132   TestComponent(name)
00133 {
00134 }
00135 
00136 inline
00137 void
00138 UnitTest::_succeed()
00139 {
00140     ++m_nPass;
00141 }
00142 
00143 } // namespace ccunit
00144 
00145 #endif /* UNITTEST_HH */

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

Project hosted on sourceforge SourceForge Logo