summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/EventLoop/UnitTest/EventLoopTest.cpp')
-rw-r--r--Swiften/EventLoop/UnitTest/EventLoopTest.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/Swiften/EventLoop/UnitTest/EventLoopTest.cpp b/Swiften/EventLoop/UnitTest/EventLoopTest.cpp
index b6023ff..b777c1b 100644
--- a/Swiften/EventLoop/UnitTest/EventLoopTest.cpp
+++ b/Swiften/EventLoop/UnitTest/EventLoopTest.cpp
@@ -11,20 +11,19 @@
#include "Swiften/EventLoop/EventOwner.h"
#include "Swiften/EventLoop/SimpleEventLoop.h"
+#include "Swiften/EventLoop/DummyEventLoop.h"
#include "Swiften/Base/sleep.h"
using namespace Swift;
-class EventLoopTest : public CppUnit::TestFixture
-{
+class EventLoopTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(EventLoopTest);
CPPUNIT_TEST(testPost);
CPPUNIT_TEST(testRemove);
+ CPPUNIT_TEST(testHandleEvent_Recursive);
CPPUNIT_TEST_SUITE_END();
public:
- EventLoopTest() {}
-
void setUp() {
events_.clear();
}
@@ -59,12 +58,30 @@ class EventLoopTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL(1, events_[0]);
CPPUNIT_ASSERT_EQUAL(3, events_[1]);
}
+
+ void testHandleEvent_Recursive() {
+ DummyEventLoop testling;
+ boost::shared_ptr<MyEventOwner> eventOwner(new MyEventOwner());
+
+ testling.postEvent(boost::bind(&EventLoopTest::runEventLoop, this, &testling, eventOwner), eventOwner);
+ testling.postEvent(boost::bind(&EventLoopTest::logEvent, this, 0), eventOwner);
+ testling.processEvents();
+
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(events_.size()));
+ CPPUNIT_ASSERT_EQUAL(0, events_[0]);
+ CPPUNIT_ASSERT_EQUAL(1, events_[1]);
+ }
private:
struct MyEventOwner : public EventOwner {};
void logEvent(int i) {
events_.push_back(i);
}
+ void runEventLoop(DummyEventLoop* loop, boost::shared_ptr<MyEventOwner> eventOwner) {
+ loop->processEvents();
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(events_.size()));
+ loop->postEvent(boost::bind(&EventLoopTest::logEvent, this, 1), eventOwner);
+ }
private:
std::vector<int> events_;