From 0d9e14a134cba4ce19f40103e9c9615e1b0a7a86 Mon Sep 17 00:00:00 2001 From: Benoit Foucher Date: Mon, 21 Apr 2008 17:57:07 +0200 Subject: Fixed bug 2972 & 3013 --- cpp/test/IceUtil/timer/Client.cpp | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'cpp/test/IceUtil/timer/Client.cpp') diff --git a/cpp/test/IceUtil/timer/Client.cpp b/cpp/test/IceUtil/timer/Client.cpp index 1af264b6120..49d6947869d 100644 --- a/cpp/test/IceUtil/timer/Client.cpp +++ b/cpp/test/IceUtil/timer/Client.cpp @@ -98,6 +98,44 @@ private: }; typedef IceUtil::Handle TestTaskPtr; + +class DestroyTask : public IceUtil::TimerTask, IceUtil::Monitor +{ +public: + + DestroyTask(const IceUtil::TimerPtr& timer) : _timer(timer), _run(false) + { + } + + virtual void + runTimerTask() + { + Lock sync(*this); + _timer->destroy(); + _run = true; + notify(); + } + + virtual void + waitForRun() + { + Lock sync(*this); + while(!_run) + { + if(!timedWait(IceUtil::Time::seconds(10))) + { + test(false); // Timeout. + } + } + } + +private: + + IceUtil::TimerPtr _timer; + bool _run; +}; +typedef IceUtil::Handle DestroyTaskPtr; + int main(int argc, char* argv[]) { cout << "testing timer... " << flush; @@ -183,5 +221,39 @@ int main(int argc, char* argv[]) timer->destroy(); } cout << "ok" << endl; + + cout << "testing timer destroy... " << flush; + { + { + IceUtil::TimerPtr timer = new IceUtil::Timer(); + DestroyTaskPtr destroyTask = new DestroyTask(timer); + timer->schedule(destroyTask, IceUtil::Time()); + destroyTask->waitForRun(); + try + { + timer->schedule(destroyTask, IceUtil::Time()); + } + catch(const IceUtil::IllegalArgumentException&) + { + // Expected; + } + } + { + IceUtil::TimerPtr timer = new IceUtil::Timer(); + TestTaskPtr testTask = new TestTask(); + timer->schedule(testTask, IceUtil::Time()); + timer->destroy(); + try + { + timer->schedule(testTask, IceUtil::Time()); + } + catch(const IceUtil::IllegalArgumentException&) + { + // Expected; + } + } + } + cout << "ok" << endl; + return EXIT_SUCCESS; } -- cgit v1.2.3