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@
--- /dev/null
+#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();
+}
--- /dev/null
+#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
#include "harness.h"
CoreTestHarness::CoreTestHarness()
- : display_()
- , tests_()
+ : TestHarness::TestHarness()
+ , display_()
{
return;
}
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
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)));
}
}
#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
{
object_ = display().template bind<O>(str_interface, &interface);
}
-
+
void teardown()
{
FAIL_IF(object_ == NULL);
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")
);
}
public:
virtual void setup()
{
- queueTest(
+ queueStep(
boost::bind(&DataTest<O>::test, boost::ref(*this))
);
}