summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-06-16 20:41:48 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-06-17 16:33:34 (GMT)
commitf2e3bfbe2ed1b8f35aa958041ee766f9d8ddf31e (patch)
treea6d28ee7ef03dd4538154c29b988e33b01ceb6ed /Swiften/Queries/UnitTest
parentf1c690a5352ee77282bbbd145a3fe0137aceb160 (diff)
downloadswift-contrib-f2e3bfbe2ed1b8f35aa958041ee766f9d8ddf31e.zip
swift-contrib-f2e3bfbe2ed1b8f35aa958041ee766f9d8ddf31e.tar.bz2
Delay IQHandler removal in IQRouter during IQ handling.
Diffstat (limited to 'Swiften/Queries/UnitTest')
-rw-r--r--Swiften/Queries/UnitTest/IQRouterTest.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/Swiften/Queries/UnitTest/IQRouterTest.cpp b/Swiften/Queries/UnitTest/IQRouterTest.cpp
index 8fa8d2a..94b7de8 100644
--- a/Swiften/Queries/UnitTest/IQRouterTest.cpp
+++ b/Swiften/Queries/UnitTest/IQRouterTest.cpp
@@ -12,6 +12,8 @@ using namespace Swift;
class IQRouterTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(IQRouterTest);
+ CPPUNIT_TEST(testRemoveHandler);
+ CPPUNIT_TEST(testRemoveHandler_AfterHandleIQ);
CPPUNIT_TEST(testHandleIQ_SuccesfulHandlerFirst);
CPPUNIT_TEST(testHandleIQ_SuccesfulHandlerLast);
CPPUNIT_TEST(testHandleIQ_NoSuccesfulHandler);
@@ -29,6 +31,31 @@ class IQRouterTest : public CppUnit::TestFixture
delete channel_;
}
+ void testRemoveHandler() {
+ IQRouter testling(channel_);
+ DummyIQHandler handler1(true, &testling);
+ DummyIQHandler handler2(true, &testling);
+ testling.removeHandler(&handler1);
+
+ channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
+
+ CPPUNIT_ASSERT_EQUAL(0, handler1.called);
+ CPPUNIT_ASSERT_EQUAL(1, handler2.called);
+ }
+
+ void testRemoveHandler_AfterHandleIQ() {
+ IQRouter testling(channel_);
+ DummyIQHandler handler1(true, &testling);
+ DummyIQHandler handler2(true, &testling);
+
+ channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
+ testling.removeHandler(&handler1);
+ channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
+
+ CPPUNIT_ASSERT_EQUAL(1, handler1.called);
+ CPPUNIT_ASSERT_EQUAL(1, handler2.called);
+ }
+
void testHandleIQ_SuccesfulHandlerFirst() {
IQRouter testling(channel_);
DummyIQHandler handler1(true, &testling);
@@ -75,7 +102,7 @@ class IQRouterTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL(1, handler1.called);
CPPUNIT_ASSERT_EQUAL(2, handler2.called);
}
-
+
private:
struct DummyIQHandler : public IQHandler {
DummyIQHandler(bool handle, IQRouter* router) : handle(handle), router(router), called(0) {