summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/EventLoop')
-rw-r--r--Swiften/EventLoop/MainEventLoop.h2
-rw-r--r--Swiften/EventLoop/UnitTest/EventLoopTest.cpp18
-rw-r--r--Swiften/EventLoop/UnitTest/SimpleEventLoopTest.cpp4
3 files changed, 14 insertions, 10 deletions
diff --git a/Swiften/EventLoop/MainEventLoop.h b/Swiften/EventLoop/MainEventLoop.h
index 0046546..fbb7079 100644
--- a/Swiften/EventLoop/MainEventLoop.h
+++ b/Swiften/EventLoop/MainEventLoop.h
@@ -19,7 +19,7 @@ namespace Swift {
* If the owner is destroyed, all events should be removed from the
* loop using removeEventsFromOwner().
*/
- static void postEvent(boost::function<void ()> event, boost::shared_ptr<EventOwner> owner = 0);
+ static void postEvent(boost::function<void ()> event, boost::shared_ptr<EventOwner> owner = boost::shared_ptr<EventOwner>());
static void removeEventsFromOwner(boost::shared_ptr<EventOwner> owner);
diff --git a/Swiften/EventLoop/UnitTest/EventLoopTest.cpp b/Swiften/EventLoop/UnitTest/EventLoopTest.cpp
index c64d1ad..9475ac9 100644
--- a/Swiften/EventLoop/UnitTest/EventLoopTest.cpp
+++ b/Swiften/EventLoop/UnitTest/EventLoopTest.cpp
@@ -3,6 +3,7 @@
#include <boost/thread.hpp>
#include <boost/bind.hpp>
+#include "Swiften/EventLoop/EventOwner.h"
#include "Swiften/EventLoop/SimpleEventLoop.h"
#include "Swiften/Base/sleep.h"
@@ -25,8 +26,8 @@ class EventLoopTest : public CppUnit::TestFixture
void testPost() {
SimpleEventLoop testling;
- testling.postEvent(boost::bind(&EventLoopTest::logEvent, this, 1), 0);
- testling.postEvent(boost::bind(&EventLoopTest::logEvent, this, 2), 0);
+ testling.postEvent(boost::bind(&EventLoopTest::logEvent, this, 1));
+ testling.postEvent(boost::bind(&EventLoopTest::logEvent, this, 2));
testling.stop();
testling.run();
@@ -37,12 +38,14 @@ class EventLoopTest : public CppUnit::TestFixture
void testRemove() {
SimpleEventLoop testling;
+ boost::shared_ptr<MyEventOwner> eventOwner1(new MyEventOwner());
+ boost::shared_ptr<MyEventOwner> eventOwner2(new MyEventOwner());
- testling.postEvent(boost::bind(&EventLoopTest::logEvent, this, 1), &testling);
- testling.postEvent(boost::bind(&EventLoopTest::logEvent, this, 2), this);
- testling.postEvent(boost::bind(&EventLoopTest::logEvent, this, 3), &testling);
- testling.postEvent(boost::bind(&EventLoopTest::logEvent, this, 4), this);
- testling.removeEventsFromOwner(this);
+ testling.postEvent(boost::bind(&EventLoopTest::logEvent, this, 1), eventOwner1);
+ testling.postEvent(boost::bind(&EventLoopTest::logEvent, this, 2), eventOwner2);
+ testling.postEvent(boost::bind(&EventLoopTest::logEvent, this, 3), eventOwner1);
+ testling.postEvent(boost::bind(&EventLoopTest::logEvent, this, 4), eventOwner2);
+ testling.removeEventsFromOwner(eventOwner2);
testling.stop();
testling.run();
@@ -52,6 +55,7 @@ class EventLoopTest : public CppUnit::TestFixture
}
private:
+ struct MyEventOwner : public EventOwner {};
void logEvent(int i) {
events_.push_back(i);
}
diff --git a/Swiften/EventLoop/UnitTest/SimpleEventLoopTest.cpp b/Swiften/EventLoop/UnitTest/SimpleEventLoopTest.cpp
index a39aa9a..b6c2da8 100644
--- a/Swiften/EventLoop/UnitTest/SimpleEventLoopTest.cpp
+++ b/Swiften/EventLoop/UnitTest/SimpleEventLoopTest.cpp
@@ -32,7 +32,7 @@ class SimpleEventLoopTest : public CppUnit::TestFixture
void testPostFromMainThread() {
SimpleEventLoop testling;
- testling.postEvent(boost::bind(&SimpleEventLoopTest::incrementCounterAndStop, this, &testling), 0);
+ testling.postEvent(boost::bind(&SimpleEventLoopTest::incrementCounterAndStop, this, &testling));
testling.run();
CPPUNIT_ASSERT_EQUAL(1, counter_);
@@ -42,7 +42,7 @@ class SimpleEventLoopTest : public CppUnit::TestFixture
void runIncrementingThread(SimpleEventLoop* loop) {
for (unsigned int i = 0; i < 10; ++i) {
Swift::sleep(1);
- loop->postEvent(boost::bind(&SimpleEventLoopTest::incrementCounter, this), 0);
+ loop->postEvent(boost::bind(&SimpleEventLoopTest::incrementCounter, this));
}
loop->stop();
}