summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-26 15:23:28 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-26 16:43:18 (GMT)
commit81ea0a6b0ea85c55c2f166b69da652aaab2ef79a (patch)
tree23ddd1388c3589bfd7d25650f4da3a1a4ab59723 /Swiften/LinkLocal/UnitTest
parente7ab68e8daf120d932d9eefc9053e9e064ca29af (diff)
downloadswift-contrib-81ea0a6b0ea85c55c2f166b69da652aaab2ef79a.zip
swift-contrib-81ea0a6b0ea85c55c2f166b69da652aaab2ef79a.tar.bz2
Test LinkLocal service registration.
Diffstat (limited to 'Swiften/LinkLocal/UnitTest')
-rw-r--r--Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp95
1 files changed, 92 insertions, 3 deletions
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
index ab42834..4b66398 100644
--- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
+++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
@@ -18,6 +18,8 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testStart);
CPPUNIT_TEST(testServiceAdded);
CPPUNIT_TEST(testServiceAdded_NoServiceInfo);
+ CPPUNIT_TEST(testServiceAdded_RegisteredService);
+ CPPUNIT_TEST(testServiceAdded_UnregisteredService);
CPPUNIT_TEST(testServiceChanged);
CPPUNIT_TEST(testServiceRemoved);
CPPUNIT_TEST(testError_BrowseErrorAfterStart);
@@ -32,10 +34,14 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
void setUp() {
eventLoop = new DummyEventLoop();
- querier = boost::shared_ptr<FakeDNSSDQuerier>(new FakeDNSSDQuerier());
+ querier = boost::shared_ptr<FakeDNSSDQuerier>(new FakeDNSSDQuerier("wonderland.lit"));
+ aliceServiceID = new DNSSDServiceID("alice", "wonderland.lit");
+ aliceServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.wonderland.lit", "xmpp.wonderland.lit", 1234, LinkLocalServiceInfo().toTXTRecord());
testServiceID = new DNSSDServiceID("foo", "bar.local");
testServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.bar.local", "xmpp.bar.local", 1234, LinkLocalServiceInfo().toTXTRecord());
testServiceInfo2 = new DNSSDResolveServiceQuery::Result("_presence.tcp.bar.local", "xmpp.foo.local", 2345, LinkLocalServiceInfo().toTXTRecord());
+ errorStopReceived = false;
+ normalStopReceived = false;
}
void tearDown() {
@@ -97,8 +103,50 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(addedServices.size()));
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling->getServices().size()));
+
+ testling->stop();
+ }
+
+ void testServiceAdded_RegisteredService() {
+ boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
+ testling->start();
+ eventLoop->processEvents();
+
+ testling->registerService("alice", 1234, LinkLocalServiceInfo());
+ eventLoop->processEvents();
+ querier->setServiceInfo(*aliceServiceID, *aliceServiceInfo);
+ querier->addService(*aliceServiceID);
+ eventLoop->processEvents();
+
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(addedServices.size()));
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling->getServices().size()));
+
+ testling->stop();
+ }
+
+ void testServiceAdded_UnregisteredService() {
+ boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
+ testling->start();
+ eventLoop->processEvents();
+ testling->registerService("alice", 1234, LinkLocalServiceInfo());
+ eventLoop->processEvents();
+ testling->unregisterService();
+ eventLoop->processEvents();
+
+ querier->setServiceInfo(*aliceServiceID, *aliceServiceInfo);
+ querier->addService(*aliceServiceID);
+ eventLoop->processEvents();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size()));
+ CPPUNIT_ASSERT(addedServices[0] == *aliceServiceID);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changedServices.size()));
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(removedServices.size()));
std::vector<LinkLocalService> services = testling->getServices();
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(services.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(services.size()));
+ CPPUNIT_ASSERT(*aliceServiceID == services[0].getID());
+ CPPUNIT_ASSERT(aliceServiceInfo->port == services[0].getPort());
+ CPPUNIT_ASSERT(aliceServiceInfo->host == services[0].getHostname());
testling->stop();
}
@@ -156,6 +204,7 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(!testling->isRunning());
CPPUNIT_ASSERT(testling->hasError());
+ CPPUNIT_ASSERT(errorStopReceived);
}
void testError_BrowseErrorAfterResolve() {
@@ -174,6 +223,7 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(testling->hasError());
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling->getServices().size()));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changedServices.size()));
+ CPPUNIT_ASSERT(errorStopReceived);
}
void testRegisterService() {
@@ -181,13 +231,21 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
testling->start();
eventLoop->processEvents();
+ LinkLocalServiceInfo info;
+ info.setFirstName("Foo");
+ testling->registerService("foo@bar", 1234, info);
+ eventLoop->processEvents();
+
+ CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, info.toTXTRecord()));
+
testling->stop();
}
void testRegisterService_Error() {
boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
testling->start();
- testling->registerService("", 1234);
+ LinkLocalServiceInfo info;
+ testling->registerService("foo@bar", 1234, info);
eventLoop->processEvents();
querier->setRegisterError();
@@ -195,12 +253,26 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(!testling->isRunning());
CPPUNIT_ASSERT(testling->hasError());
+ CPPUNIT_ASSERT(errorStopReceived);
+ CPPUNIT_ASSERT(!querier->isServiceRegistered("foo@bar", 1234, info.toTXTRecord()));
}
void testRegisterService_Reregister() {
boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
testling->start();
eventLoop->processEvents();
+ LinkLocalServiceInfo info;
+ info.setFirstName("Foo");
+ testling->registerService("foo@bar", 1234, info);
+ eventLoop->processEvents();
+ testling->unregisterService();
+ eventLoop->processEvents();
+
+ info.setFirstName("Bar");
+ testling->registerService("bar@baz", 3456, info);
+ eventLoop->processEvents();
+
+ CPPUNIT_ASSERT(querier->isServiceRegistered("bar@baz", 3456, info.toTXTRecord()));
testling->stop();
}
@@ -215,6 +287,8 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
&LinkLocalServiceBrowserTest::handleServiceChanged, this, _1));
testling->onServiceRemoved.connect(boost::bind(
&LinkLocalServiceBrowserTest::handleServiceRemoved, this, _1));
+ testling->onStopped.connect(boost::bind(
+ &LinkLocalServiceBrowserTest::handleStopped, this, _1));
return testling;
}
@@ -230,15 +304,30 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
changedServices.push_back(service);
}
+ void handleStopped(bool error) {
+ CPPUNIT_ASSERT(!errorStopReceived);
+ CPPUNIT_ASSERT(!normalStopReceived);
+ if (error) {
+ errorStopReceived = true;
+ }
+ else {
+ normalStopReceived = true;
+ }
+ }
+
private:
DummyEventLoop* eventLoop;
boost::shared_ptr<FakeDNSSDQuerier> querier;
std::vector<DNSSDServiceID> addedServices;
std::vector<DNSSDServiceID> changedServices;
std::vector<DNSSDServiceID> removedServices;
+ DNSSDServiceID* aliceServiceID;
+ DNSSDResolveServiceQuery::Result* aliceServiceInfo;
DNSSDServiceID* testServiceID;
DNSSDResolveServiceQuery::Result* testServiceInfo;
DNSSDResolveServiceQuery::Result* testServiceInfo2;
+ bool errorStopReceived;
+ bool normalStopReceived;
};
CPPUNIT_TEST_SUITE_REGISTRATION(LinkLocalServiceBrowserTest);