summaryrefslogtreecommitdiff
path: root/include/cppunit/extensions
diff options
context:
space:
mode:
authorBastiaan Bakker <bastiaan.bakker@lifeline.nl>2001-04-22 22:09:57 +0000
committerBastiaan Bakker <bastiaan.bakker@lifeline.nl>2001-04-22 22:09:57 +0000
commitc910c4cc5cde77b7ef034c50058d8d5f11bd4b71 (patch)
treeb6150386cb0a000c96ac573ac161e262231ba42e /include/cppunit/extensions
parent788f81ef8dac04bb5fd0b88cc6d0ef150c4c5a6f (diff)
downloadcppunit-c910c4cc5cde77b7ef034c50058d8d5f11bd4b71.tar.gz
Merged extension headers back in from Micheal Feathers version.
Diffstat (limited to 'include/cppunit/extensions')
-rw-r--r--include/cppunit/extensions/Makefile.am7
-rw-r--r--include/cppunit/extensions/Orthodox.h95
-rw-r--r--include/cppunit/extensions/RepeatedTest.h62
-rw-r--r--include/cppunit/extensions/TestDecorator.h67
-rw-r--r--include/cppunit/extensions/TestSetUp.h38
5 files changed, 269 insertions, 0 deletions
diff --git a/include/cppunit/extensions/Makefile.am b/include/cppunit/extensions/Makefile.am
new file mode 100644
index 0000000..1388d9d
--- /dev/null
+++ b/include/cppunit/extensions/Makefile.am
@@ -0,0 +1,7 @@
+libcppunitincludedir = $(includedir)/cppunit/extensions
+
+libcppunitinclude_HEADERS = \
+ Orthodox.h \
+ RepeatedTest.h \
+ TestDecorator.h \
+ TestSetup.h
diff --git a/include/cppunit/extensions/Orthodox.h b/include/cppunit/extensions/Orthodox.h
new file mode 100644
index 0000000..a7778e3
--- /dev/null
+++ b/include/cppunit/extensions/Orthodox.h
@@ -0,0 +1,95 @@
+
+#ifndef CPPUNIT_ORTHODOX_H
+#define CPPUNIT_ORTHODOX_H
+
+#ifndef CPPUNIT_TESTCASE_H
+#include "TestCase.h"
+#endif
+
+namespace CppUnit {
+
+/*
+ * Orthodox performs a simple set of tests on an arbitary
+ * class to make sure that it supports at least the
+ * following operations:
+ *
+ * default construction - constructor
+ * equality/inequality - operator== && operator!=
+ * assignment - operator=
+ * negation - operator!
+ * safe passage - copy construction
+ *
+ * If operations for each of these are not declared
+ * the template will not instantiate. If it does
+ * instantiate, tests are performed to make sure
+ * that the operations have correct semantics.
+ *
+ * Adding an orthodox test to a suite is very
+ * easy:
+ *
+ * public: Test *suite () {
+ * TestSuite *suiteOfTests = new TestSuite;
+ * suiteOfTests->addTest (new ComplexNumberTest ("testAdd");
+ * suiteOfTests->addTest (new TestCaller<Orthodox<Complex> > ());
+ * return suiteOfTests;
+ * }
+ *
+ * Templated test cases be very useful when you are want to
+ * make sure that a group of classes have the same form.
+ *
+ * see TestSuite
+ */
+
+
+template <class ClassUnderTest> class Orthodox : public TestCase
+{
+public:
+ Orthodox () : TestCase ("Orthodox") {}
+
+protected:
+ ClassUnderTest call (ClassUnderTest object);
+ void runTest ();
+
+
+};
+
+
+// Run an orthodoxy test
+template <class ClassUnderTest> void Orthodox<ClassUnderTest>::runTest ()
+{
+ // make sure we have a default constructor
+ ClassUnderTest a, b, c;
+
+ // make sure we have an equality operator
+ assert (a == b);
+
+ // check the inverse
+ b.operator= (a.operator! ());
+ assert (a != b);
+
+ // double inversion
+ b = !!a;
+ assert (a == b);
+
+ // invert again
+ b = !a;
+
+ // check calls
+ c = a;
+ assert (c == call (a));
+
+ c = b;
+ assert (c == call (b));
+
+}
+
+
+// Exercise a call
+template <class ClassUnderTest> ClassUnderTest Orthodox<ClassUnderTest>::call (ClassUnderTest object)
+{
+ return object;
+}
+
+} // namespace CppUnit
+
+#endif \ No newline at end of file
diff --git a/include/cppunit/extensions/RepeatedTest.h b/include/cppunit/extensions/RepeatedTest.h
new file mode 100644
index 0000000..a8c3246
--- /dev/null
+++ b/include/cppunit/extensions/RepeatedTest.h
@@ -0,0 +1,62 @@
+
+#ifndef CPPUNIT_REPEATEDTEST_H
+#define CPPUNIT_REPEATEDTEST_H
+
+#ifndef CPPUNIT_TESTDECORATOR_H
+#include "TestDecorator.h"
+#endif
+
+namespace CppUnit {
+
+class Test;
+class TestResult;
+
+
+/*
+ * A decorator that runs a test repeatedly.
+ * Does not assume ownership of the test it decorates
+ *
+ */
+
+class RepeatedTest : public TestDecorator
+{
+public:
+ RepeatedTest (Test *test, int timesRepeat)
+ : TestDecorator (test), m_timesRepeat (timesRepeat) {}
+
+ int countTestCases ();
+ std::string toString ();
+ void run (TestResult *result);
+
+private:
+ RepeatedTest( const RepeatedTest & );
+ void operator( const RepeatedTest & );
+
+ const int m_timesRepeat;
+};
+
+
+// Counts the number of test cases that will be run by this test.
+inline RepeatedTest::countTestCases ()
+{ return TestDecorator::countTestCases () * m_timesRepeat; }
+
+// Returns the name of the test instance.
+inline std::string RepeatedTest::toString ()
+{ return TestDecorator::toString () + " (repeated)"; }
+
+// Runs a repeated test
+inline void RepeatedTest::run (TestResult *result)
+{
+ for (int n = 0; n < m_timesRepeat; n++) {
+ if (result->shouldStop ())
+ break;
+
+ TestDecorator::run (result);
+ }
+}
+
+
+
+} // namespace CppUnit
+
+#endif \ No newline at end of file
diff --git a/include/cppunit/extensions/TestDecorator.h b/include/cppunit/extensions/TestDecorator.h
new file mode 100644
index 0000000..54494f3
--- /dev/null
+++ b/include/cppunit/extensions/TestDecorator.h
@@ -0,0 +1,67 @@
+
+
+#ifndef CPPUNIT_TESTDECORATOR_H
+#define CPPUNIT_TESTDECORATOR_H
+
+#ifndef CPPUNIT_TEST_H
+#include "../Test.h"
+#endif
+
+namespace CppUnit {
+
+class TestResult;
+
+/*
+ * A Decorator for Tests
+ *
+ * Does not assume ownership of the test it decorates
+ *
+ */
+
+class TestDecorator : public Test
+{
+public:
+ TestDecorator (Test *test);
+ ~TestDecorator ();
+
+ int countTestCases () const;
+ void run (TestResult *result) const;
+ std::string toString () const;
+ std::string getName () const;
+
+protected:
+ Test *m_test;
+
+private:
+ TestDecorator( const TestDecorator &);
+ void operator =( const TestDecorator & );
+};
+
+
+inline TestDecorator::TestDecorator (Test *test)
+{ m_test = test; }
+
+
+inline TestDecorator::~TestDecorator ()
+{}
+
+
+inline TestDecorator::countTestCases () const
+{ return m_test->countTestCases (); }
+
+
+inline void TestDecorator::run (TestResult *result) const
+{ m_test->run (result); }
+
+
+inline std::string TestDecorator::toString () const
+{ return m_test->toString (); }
+
+
+inline std::string TestDecorator::getName () const
+{ return m_test->getName(); }
+
+} // namespace CppUnit
+
+#endif
+
diff --git a/include/cppunit/extensions/TestSetUp.h b/include/cppunit/extensions/TestSetUp.h
new file mode 100644
index 0000000..bcd47d0
--- /dev/null
+++ b/include/cppunit/extensions/TestSetUp.h
@@ -0,0 +1,38 @@
+
+#ifndef CPP_UINT_TESTSETUP_H
+#define CPP_UINT_TESTSETUP_H
+
+#ifndef CPPUNIT_TESTDECORATOR_H
+#include "TestDecorator.h"
+#endif
+
+namespace CppUnit {
+
+class Test;
+class TestResult;
+
+
+class TestSetup : public TestDecorator
+{
+public:
+ TestSetup (Test *test) : TestDecorator (test) {}
+ run (TestResult *result);
+
+protected:
+ void setUp () {}
+ void tearDown () {}
+
+private:
+ TestSetup( const TestSetup & );
+ void operator =( const TestSetup & );
+};
+
+
+inline TestSetup::run (TestResult *result)
+{ setUp (); TestDecorator::run (result); tearDown (); }
+
+
+} // namespace CppUnit
+
+#endif
+