create a common test harness
authorU. Artie Eoff <ullysses.a.eoff@intel.com>
Thu, 31 Jan 2013 23:56:45 +0000 (15:56 -0800)
committerU. Artie Eoff <ullysses.a.eoff@intel.com>
Thu, 31 Jan 2013 23:56:45 +0000 (15:56 -0800)
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
src/common/Makefile.am
src/common/harness.cpp [new file with mode: 0644]
src/common/harness.h [new file with mode: 0644]
src/core/harness.cpp
src/core/harness.h
src/core/test_bind_interface.cpp
src/core/test_cursor.cpp
src/core/test_data.cpp

index d700e18..dfccd9b 100644 (file)
@@ -1,6 +1,8 @@
 lib_LTLIBRARIES = libwfits-common.la
 
-libwfits_common_la_SOURCES = test.cpp
+libwfits_common_la_SOURCES =   \
+       test.cpp                \
+       harness.cpp
 
 libwfits_common_la_LIBADD = \
        @CHECK_LIBS@
diff --git a/src/common/harness.cpp b/src/common/harness.cpp
new file mode 100644 (file)
index 0000000..aa1eab0
--- /dev/null
@@ -0,0 +1,38 @@
+#include "harness.h"
+
+TestHarness::TestHarness()
+       : steps_()
+{
+       return;
+}
+
+TestHarness::~TestHarness()
+{
+       return;
+}
+
+void TestHarness::queueStep(TestStep step)
+{
+       steps_.push_back(step);
+}
+
+void TestHarness::run()
+{
+       setup();
+
+       while (haveStep())
+               runNextStep();
+
+       teardown();
+}
+
+bool TestHarness::haveStep() const
+{
+       return not steps_.empty();
+}
+
+void TestHarness::runNextStep()
+{
+       steps_.front()();
+       steps_.pop_front();
+}
diff --git a/src/common/harness.h b/src/common/harness.h
new file mode 100644 (file)
index 0000000..9575e2b
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef __WFITS_COMMON_HARNESS_H__
+#define __WFITS_COMMON_HARNESS_H__
+
+#include <boost/function.hpp>
+#include <boost/bind.hpp>
+#include <deque>
+
+class TestHarness
+{
+public:
+       typedef boost::function<void()> TestStep;
+       typedef std::deque<TestStep>    TestSteps;
+
+       TestHarness();
+
+       virtual ~TestHarness();
+
+       virtual void queueStep(TestStep);
+
+       void run();
+       virtual void setup() { };
+       virtual void teardown() { };
+
+       void runNextStep();
+       bool haveStep() const;
+
+private:
+       TestSteps       steps_;
+};
+
+#define HARNESS_TEST(HarnessClass, suite) \
+\
+TEST(HarnessClass, suite) \
+{ \
+       HarnessClass().run(); \
+}
+
+#endif
index c0e5451..0aacd48 100644 (file)
@@ -2,8 +2,8 @@
 #include "harness.h"
 
 CoreTestHarness::CoreTestHarness()
-       : display_()
-       , tests_()
+       : TestHarness::TestHarness()
+       , display_()
 {
        return;
 }
@@ -13,23 +13,16 @@ CoreTestHarness::~CoreTestHarness()
        return;
 }
 
-void CoreTestHarness::queueTest(Test test)
+void CoreTestHarness::runStep(CoreTestHarness::TestStep step) const
 {
-       tests_.push_back(test);
+       step();
+       display().yield();
 }
 
-void CoreTestHarness::run()
+void CoreTestHarness::queueStep(TestStep step)
 {
-       setup();
-
-       while (not tests_.empty())
-       {
-               tests_.front()(); // call test
-               tests_.pop_front(); // remove test
-               display().roundtrip();
-       }
-
-       teardown();
+       TestHarness::queueStep(
+               boost::bind(&CoreTestHarness::runStep, boost::ref(*this), step));
 }
 
 class SimpleTest : public CoreTestHarness
@@ -44,14 +37,14 @@ public:
 
        void setup()
        {
-               queueTest(boost::bind(&SimpleTest::test, boost::ref(*this)));
+               queueStep(boost::bind(&SimpleTest::test, boost::ref(*this)));
        }
 
        void test()
        {
                if (++tested < 10)
                {
-                       queueTest(boost::bind(&SimpleTest::test, boost::ref(*this)));
+                       queueStep(boost::bind(&SimpleTest::test, boost::ref(*this)));
                }
        }
 
index 216b362..cf8cbb5 100644 (file)
@@ -1,51 +1,27 @@
 #ifndef __WFITS_CORE_HARNESS_H__
 #define __WFITS_CORE_HARNESS_H__
 
-#include <boost/function.hpp>
-#include <boost/bind.hpp>
-#include <deque>
-#include <string>
-
+#include "common/harness.h"
 #include "display.h"
 
-class CoreTestHarness
+class CoreTestHarness : public TestHarness
 {
 public:
-       typedef boost::function<void()> Test;
-       typedef std::deque<Test>        Tests;
-
        CoreTestHarness();
 
        virtual ~CoreTestHarness();
        
-       void queueTest(Test);
-       void run();
-
-       /**
-        * Optionally override this to do any special
-        * setup before processing Tests.
-        * i.e. you can queue all your tests from here.
-        **/
-       virtual void setup() { };
-       
-       /**
-        * Optionally override teardown to do any special
-        * cleanup before the test exits.
-        **/
-       virtual void teardown() { };
+       void queueStep(TestStep);
 
        const Display& display() const { return display_; }
 
 private:
+       void runStep(TestStep step) const;
+
        Display display_;
-       Tests   tests_;
 };
 
 #define WFITS_CORE_HARNESS_TEST_CASE(HarnessClass, suite) \
-\
-TEST(HarnessClass, "Core/" suite) \
-{ \
-       HarnessClass().run(); \
-}
+       HARNESS_TEST(HarnessClass, "Core/" suite)
 
 #endif
index 59745f5..de9e41c 100644 (file)
@@ -15,7 +15,7 @@ public:
        {
                object_ = display().template bind<O>(str_interface, &interface);
        }
-       
+
        void teardown()
        {
                FAIL_IF(object_ == NULL);
index 7e7ec29..b2df1b1 100644 (file)
@@ -24,10 +24,10 @@ public:
 
        void setup()
        {
-               queueTest(
+               queueStep(
                        boost::bind(&ThemeLoadTest::test, boost::ref(*this), "default", "default")
                );
-               queueTest(
+               queueStep(
                        boost::bind(&ThemeLoadTest::test, boost::ref(*this), "this_theme_does_not_exist", "default")
                );
        }
index ef94575..4948c61 100644 (file)
@@ -7,7 +7,7 @@ class DataTest : public CoreTestHarness
 public:
        virtual void setup()
        {
-               queueTest(
+               queueStep(
                        boost::bind(&DataTest<O>::test, boost::ref(*this))
                );
        }