diff options
author | Gordon Sim <gsim@apache.org> | 2008-05-30 08:13:21 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2008-05-30 08:13:21 +0000 |
commit | 5d2f67ee3918516feebc4994d5b21a893ef97a5b (patch) | |
tree | 4c13e462ca37f7ce5e8a9564cec5f1e92410e5ab /cpp/src/tests/TimerTest.cpp | |
parent | 162cb3879f3e25cbd13a777b40e374196ab531c9 (diff) | |
download | qpid-python-5d2f67ee3918516feebc4994d5b21a893ef97a5b.tar.gz |
Convert remaining cppunit tests to boost test framework to reduce dependencies.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@661587 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests/TimerTest.cpp')
-rw-r--r-- | cpp/src/tests/TimerTest.cpp | 154 |
1 files changed, 72 insertions, 82 deletions
diff --git a/cpp/src/tests/TimerTest.cpp b/cpp/src/tests/TimerTest.cpp index 2693d4a787..50712ff79c 100644 --- a/cpp/src/tests/TimerTest.cpp +++ b/cpp/src/tests/TimerTest.cpp @@ -21,7 +21,7 @@ */ #include "qpid/broker/Timer.h" #include "qpid/sys/Monitor.h" -#include "qpid_test_plugin.h" +#include "unit_test.h" #include <math.h> #include <iostream> #include <memory> @@ -33,98 +33,88 @@ using namespace qpid::sys; using boost::intrusive_ptr; using boost::dynamic_pointer_cast; -class TimerTest : public CppUnit::TestCase +class Counter { - CPPUNIT_TEST_SUITE(TimerTest); - CPPUNIT_TEST(testGeneral); - CPPUNIT_TEST_SUITE_END(); - - class Counter + Mutex lock; + uint counter; + public: + Counter() : counter(0) {} + uint next() { - Mutex lock; - uint counter; - public: - Counter() : counter(0) {} - uint next() - { - Mutex::ScopedLock l(lock); - return ++counter; - } - }; + Mutex::ScopedLock l(lock); + return ++counter; + } +}; - class TestTask : public TimerTask - { - const AbsTime start; - const Duration expected; - AbsTime end; - bool fired; - uint position; - Monitor monitor; - Counter& counter; - - public: - TestTask(Duration timeout, Counter& _counter) - : TimerTask(timeout), start(now()), expected(timeout), end(start), fired(false), counter(_counter) {} +class TestTask : public TimerTask +{ + const AbsTime start; + const Duration expected; + AbsTime end; + bool fired; + uint position; + Monitor monitor; + Counter& counter; - void fire() - { - Monitor::ScopedLock l(monitor); - fired = true; - position = counter.next(); - end = now(); - monitor.notify(); - } + public: + TestTask(Duration timeout, Counter& _counter) + : TimerTask(timeout), start(now()), expected(timeout), end(start), fired(false), counter(_counter) {} - void check(uint expected_position, uint64_t tolerance = 500 * TIME_MSEC) - { - Monitor::ScopedLock l(monitor); - CPPUNIT_ASSERT(fired); - CPPUNIT_ASSERT_EQUAL(expected_position, position); - Duration actual(start, end); - uint64_t difference = abs(expected - actual); - std::string msg(boost::lexical_cast<std::string>(boost::format("tolerance = %1%, difference = %2%") % tolerance % difference)); - CPPUNIT_ASSERT_MESSAGE(msg, difference < tolerance); - } + void fire() + { + Monitor::ScopedLock l(monitor); + fired = true; + position = counter.next(); + end = now(); + monitor.notify(); + } - void wait(Duration d) - { - Monitor::ScopedLock l(monitor); - monitor.wait(AbsTime(now(), d)); - } - }; + void check(uint expected_position, uint64_t tolerance = 500 * TIME_MSEC) + { + Monitor::ScopedLock l(monitor); + BOOST_CHECK(fired); + BOOST_CHECK_EQUAL(expected_position, position); + Duration actual(start, end); + uint64_t difference = abs(expected - actual); + std::string msg(boost::lexical_cast<std::string>(boost::format("tolerance = %1%, difference = %2%") % tolerance % difference)); + BOOST_CHECK_MESSAGE(difference < tolerance, msg); + } - class DummyRunner : public Runnable + void wait(Duration d) { - public: - void run() {} - }; + Monitor::ScopedLock l(monitor); + monitor.wait(AbsTime(now(), d)); + } +}; -public: +class DummyRunner : public Runnable +{ + public: + void run() {} +}; - void testGeneral() - { - Counter counter; - Timer timer; - intrusive_ptr<TestTask> task1(new TestTask(Duration(3 * TIME_SEC), counter)); - intrusive_ptr<TestTask> task2(new TestTask(Duration(1 * TIME_SEC), counter)); - intrusive_ptr<TestTask> task3(new TestTask(Duration(4 * TIME_SEC), counter)); - intrusive_ptr<TestTask> task4(new TestTask(Duration(2 * TIME_SEC), counter)); +QPID_AUTO_TEST_SUITE(TimerTestSuite) + +QPID_AUTO_TEST_CASE(testGeneral) +{ + Counter counter; + Timer timer; + intrusive_ptr<TestTask> task1(new TestTask(Duration(3 * TIME_SEC), counter)); + intrusive_ptr<TestTask> task2(new TestTask(Duration(1 * TIME_SEC), counter)); + intrusive_ptr<TestTask> task3(new TestTask(Duration(4 * TIME_SEC), counter)); + intrusive_ptr<TestTask> task4(new TestTask(Duration(2 * TIME_SEC), counter)); - timer.add(task1); - timer.add(task2); - timer.add(task3); - timer.add(task4); + timer.add(task1); + timer.add(task2); + timer.add(task3); + timer.add(task4); - dynamic_pointer_cast<TestTask>(task3)->wait(Duration(6 * TIME_SEC)); + dynamic_pointer_cast<TestTask>(task3)->wait(Duration(6 * TIME_SEC)); - dynamic_pointer_cast<TestTask>(task1)->check(3); - dynamic_pointer_cast<TestTask>(task2)->check(1); - dynamic_pointer_cast<TestTask>(task3)->check(4); - dynamic_pointer_cast<TestTask>(task4)->check(2); - } -}; - -// Make this test suite a plugin. -CPPUNIT_PLUGIN_IMPLEMENT(); -CPPUNIT_TEST_SUITE_REGISTRATION(TimerTest); + dynamic_pointer_cast<TestTask>(task1)->check(3); + dynamic_pointer_cast<TestTask>(task2)->check(1); + dynamic_pointer_cast<TestTask>(task3)->check(4); + dynamic_pointer_cast<TestTask>(task4)->check(2); +} +QPID_AUTO_TEST_SUITE_END() |