From 248f1fe188fe2307b9dcf2c87a83b653eaa1920c Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Sat, 26 Dec 2009 12:42:57 +0000 Subject: synchronized with trunk except for ruby dir git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/qpid.rnr@893970 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/tests/TimerTest.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'cpp/src/tests/TimerTest.cpp') diff --git a/cpp/src/tests/TimerTest.cpp b/cpp/src/tests/TimerTest.cpp index 50712ff79c..1552421ba0 100644 --- a/cpp/src/tests/TimerTest.cpp +++ b/cpp/src/tests/TimerTest.cpp @@ -8,9 +8,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -19,7 +19,7 @@ * under the License. * */ -#include "qpid/broker/Timer.h" +#include "qpid/sys/Timer.h" #include "qpid/sys/Monitor.h" #include "unit_test.h" #include @@ -28,11 +28,13 @@ #include #include -using namespace qpid::broker; using namespace qpid::sys; using boost::intrusive_ptr; using boost::dynamic_pointer_cast; +namespace qpid { +namespace tests { + class Counter { Mutex lock; @@ -45,7 +47,7 @@ class Counter return ++counter; } }; - + class TestTask : public TimerTask { const AbsTime start; @@ -57,7 +59,7 @@ class TestTask : public TimerTask Counter& counter; public: - TestTask(Duration timeout, Counter& _counter) + TestTask(Duration timeout, Counter& _counter) : TimerTask(timeout), start(now()), expected(timeout), end(start), fired(false), counter(_counter) {} void fire() @@ -75,7 +77,11 @@ class TestTask : public TimerTask BOOST_CHECK(fired); BOOST_CHECK_EQUAL(expected_position, position); Duration actual(start, end); +#ifdef _WIN32 + uint64_t difference = _abs64(expected - actual); +#else uint64_t difference = abs(expected - actual); +#endif std::string msg(boost::lexical_cast(boost::format("tolerance = %1%, difference = %2%") % tolerance % difference)); BOOST_CHECK_MESSAGE(difference < tolerance, msg); } @@ -103,14 +109,14 @@ QPID_AUTO_TEST_CASE(testGeneral) intrusive_ptr task2(new TestTask(Duration(1 * TIME_SEC), counter)); intrusive_ptr task3(new TestTask(Duration(4 * TIME_SEC), counter)); intrusive_ptr task4(new TestTask(Duration(2 * TIME_SEC), counter)); - + timer.add(task1); timer.add(task2); timer.add(task3); timer.add(task4); - + dynamic_pointer_cast(task3)->wait(Duration(6 * TIME_SEC)); - + dynamic_pointer_cast(task1)->check(3); dynamic_pointer_cast(task2)->check(1); dynamic_pointer_cast(task3)->check(4); @@ -118,3 +124,5 @@ QPID_AUTO_TEST_CASE(testGeneral) } QPID_AUTO_TEST_SUITE_END() + +}} // namespace qpid::tests -- cgit v1.2.1