+// ---\r
+//\r
+// $Id: cpptest-suite.h,v 1.4 2010/03/26 04:45:14 hartwork Exp $\r
+//\r
+// CppTest - A C++ Unit Testing Framework\r
+// Copyright (c) 2003 Niklas Lundell\r
+//\r
+// ---\r
+//\r
+// This library is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU Lesser General Public\r
+// License as published by the Free Software Foundation; either\r
+// version 2 of the License, or (at your option) any later version.\r
+//\r
+// This library is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+// Lesser General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU Lesser General Public\r
+// License along with this library; if not, write to the\r
+// Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
+// Boston, MA 02111-1307, USA.\r
+//\r
+// ---\r
+\r
+/** \file */\r
+\r
+#ifndef CPPTEST_SUITE_H\r
+#define CPPTEST_SUITE_H\r
+\r
+#include <list>\r
+#include <memory>\r
+#include <string>\r
+\r
+#include "cpptest-time.h"\r
+#include "cpptest-source.h"\r
+\r
+namespace Test\r
+{\r
+ class Output;\r
+ \r
+ /// \brief Unit testing suite.\r
+ ///\r
+ /// Base class for all suites. Derive from this class to create own\r
+ /// test suites.\r
+ ///\r
+ /// %Test functions in derived classes are registered as tests using the\r
+ /// TEST_ADD(func). Testing is started by run(). Note that suites may be\r
+ /// embedded in other suites using add().\r
+ ///\r
+ class Suite\r
+ {\r
+ public: \r
+ Suite();\r
+ virtual ~Suite();\r
+ \r
+ void add(std::auto_ptr<Suite> suite);\r
+ \r
+ bool run(Output& output, bool cont_after_fail = true);\r
+ \r
+ protected:\r
+ /// Pointer to a test function.\r
+ ///\r
+ typedef void (Suite::*Func)();\r
+ \r
+ bool continue_after_failure() const { return _continue; }\r
+ \r
+ virtual void setup() {}\r
+ virtual void tear_down() {}\r
+ \r
+ void register_test(Func func, const std::string& name);\r
+ void assertment(Source s);\r
+ \r
+ private:\r
+ struct DoRun;\r
+ struct ExecTests;\r
+ struct SubSuiteTests;\r
+ struct SuiteTime;\r
+ struct SubSuiteTime;\r
+ \r
+ friend struct DoRun;\r
+ friend struct ExecTests;\r
+ friend struct SubSuiteTests;\r
+ friend struct SubSuiteTime;\r
+ \r
+ struct Data\r
+ {\r
+ Func _func;\r
+ std::string _name;\r
+ Time _time;\r
+ \r
+ Data(Func func, const std::string& name)\r
+ : _func(func), _name(name) {}\r
+ };\r
+ \r
+ typedef std::list<Data> Tests;\r
+ typedef std::list<Suite*> Suites;\r
+ \r
+ std::string _name; // Suite name\r
+ const std::string* _cur_test; // Current test func name\r
+ Suites _suites; // External test suites\r
+ Tests _tests; // All tests\r
+ Output* _output; // Output handler\r
+ bool _result : 1; // Test result\r
+ bool _success : 1; // Set if no test failed\r
+ bool _continue : 1; // Continue func after failures\r
+ \r
+ void do_run(Output* os, bool cont_after_fail);\r
+ int total_tests() const;\r
+ Time total_time(bool recursive) const;\r
+ \r
+ // Disable\r
+ //\r
+ Suite(const Suite&);\r
+ Suite& operator=(const Suite&);\r
+ };\r
+\r
+ /// Adds a test function to the enclosing suite. Note that test functions\r
+ /// should be added in the suites constructor.\r
+ ///\r
+ /// \param func Function to add, must be of type Suite::Func.\r
+ ///\r
+ /// \par Example:\r
+ /// \code\r
+ /// MySuite::MySuite()\r
+ /// {\r
+ /// TEST_ADD(&MySuite::test_1)\r
+ /// TEST_ADD(&MySuite::test_2)\r
+ /// ...\r
+ /// }\r
+ /// \endcode\r
+ ///\r
+ #define TEST_ADD(func)\\r
+ register_test(static_cast<Func>(&func), #func);\r
+ \r
+} // namespace Test\r
+\r
+#endif // #ifndef CPPTEST_SUITE_H\r
+\r