summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-23 19:03:11 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-23 19:03:11 (GMT)
commit3a0309d2d897bf4f399610e52ad439c002e16f9c (patch)
tree47bff40c767b95b7b395393186769e0fb68badc1 /Swiften/LinkLocal/UnitTest
parent1c1491cbbe9fca509ddc292dbeaedbba7b6a2b14 (diff)
downloadswift-3a0309d2d897bf4f399610e52ad439c002e16f9c.zip
swift-3a0309d2d897bf4f399610e52ad439c002e16f9c.tar.bz2
Add DNS service factory.
Diffstat (limited to 'Swiften/LinkLocal/UnitTest')
-rw-r--r--Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp34
-rw-r--r--Swiften/LinkLocal/UnitTest/MockDNSSDService.h15
2 files changed, 35 insertions, 14 deletions
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
index 59a113d..34f797c 100644
--- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
+++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
@@ -9,7 +9,7 @@
#include "Swiften/LinkLocal/DNSSDService.h"
#include "Swiften/EventLoop/DummyEventLoop.h"
-// Test IP address change
+// Test canCreate() == false
using namespace Swift;
@@ -26,7 +26,7 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
void setUp() {
eventLoop = new DummyEventLoop();
- dnsSDService = boost::shared_ptr<MockDNSSDService>(new MockDNSSDService());
+ dnsSDServiceFactory = new MockDNSSDServiceFactory();
testServiceID = new LinkLocalServiceID("foo", "bar.local");
testServiceInfo = new DNSSDService::ResolveResult("xmpp.bar.local", 1234, LinkLocalServiceInfo());
testServiceInfo2 = new DNSSDService::ResolveResult("xmpp.foo.local", 2345, LinkLocalServiceInfo());
@@ -40,14 +40,15 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
delete testServiceInfo2;
delete testServiceInfo;
delete testServiceID;
+ delete dnsSDServiceFactory;
delete eventLoop;
}
void testServiceAdded() {
boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
- dnsSDService->setServiceInfo(*testServiceID,*testServiceInfo);
- dnsSDService->addService(*testServiceID);
+ dnsSDService()->setServiceInfo(*testServiceID,*testServiceInfo);
+ dnsSDService()->addService(*testServiceID);
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size()));
@@ -64,7 +65,7 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
void testServiceAdded_NoServiceInfo() {
boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
- dnsSDService->addService(*testServiceID);
+ dnsSDService()->addService(*testServiceID);
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(addedServices.size()));
@@ -74,11 +75,11 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
void testServiceChanged() {
boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
- dnsSDService->setServiceInfo(*testServiceID,*testServiceInfo);
- dnsSDService->addService(*testServiceID);
+ dnsSDService()->setServiceInfo(*testServiceID,*testServiceInfo);
+ dnsSDService()->addService(*testServiceID);
eventLoop->processEvents();
- dnsSDService->setServiceInfo(*testServiceID,*testServiceInfo2);
+ dnsSDService()->setServiceInfo(*testServiceID,*testServiceInfo2);
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size()));
@@ -94,13 +95,13 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
void testServiceRemoved() {
boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
- dnsSDService->setServiceInfo(*testServiceID,*testServiceInfo);
- dnsSDService->addService(*testServiceID);
+ dnsSDService()->setServiceInfo(*testServiceID,*testServiceInfo);
+ dnsSDService()->addService(*testServiceID);
eventLoop->processEvents();
- dnsSDService->removeService(*testServiceID);
+ dnsSDService()->removeService(*testServiceID);
eventLoop->processEvents();
- dnsSDService->setServiceInfo(*testServiceID,*testServiceInfo2);
+ dnsSDService()->setServiceInfo(*testServiceID,*testServiceInfo2);
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size()));
@@ -114,7 +115,7 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
private:
boost::shared_ptr<LinkLocalServiceBrowser> createTestling() {
boost::shared_ptr<LinkLocalServiceBrowser> testling(
- new LinkLocalServiceBrowser(dnsSDService));
+ new LinkLocalServiceBrowser(dnsSDServiceFactory));
testling->onServiceAdded.connect(boost::bind(
&LinkLocalServiceBrowserTest::handleServiceAdded, this, _1));
testling->onServiceChanged.connect(boost::bind(
@@ -136,9 +137,14 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
changedServices.push_back(service);
}
+ boost::shared_ptr<MockDNSSDService> dnsSDService() const {
+ CPPUNIT_ASSERT(dnsSDServiceFactory->services.size() > 0);
+ return dnsSDServiceFactory->services[0];
+ }
+
private:
DummyEventLoop* eventLoop;
- boost::shared_ptr<MockDNSSDService> dnsSDService;
+ MockDNSSDServiceFactory* dnsSDServiceFactory;
std::vector<LinkLocalServiceID> addedServices;
std::vector<LinkLocalServiceID> changedServices;
std::vector<LinkLocalServiceID> removedServices;
diff --git a/Swiften/LinkLocal/UnitTest/MockDNSSDService.h b/Swiften/LinkLocal/UnitTest/MockDNSSDService.h
index 56661ee..69ac06d 100644
--- a/Swiften/LinkLocal/UnitTest/MockDNSSDService.h
+++ b/Swiften/LinkLocal/UnitTest/MockDNSSDService.h
@@ -6,6 +6,7 @@
#include "Swiften/EventLoop/MainEventLoop.h"
#include "Swiften/LinkLocal/DNSSDService.h"
+#include "Swiften/LinkLocal/DNSSDServiceFactory.h"
namespace Swift {
class MockDNSSDService : public DNSSDService {
@@ -78,5 +79,19 @@ namespace Swift {
std::vector<LinkLocalServiceID> resolvingServices;
};
+ class MockDNSSDServiceFactory : public DNSSDServiceFactory {
+ public:
+ boost::shared_ptr<DNSSDService> createDNSSDService() {
+ boost::shared_ptr<MockDNSSDService> result(new MockDNSSDService());
+ services.push_back(result);
+ return result;
+ }
+
+ bool canCreate() const {
+ return true;
+ }
+
+ std::vector<boost::shared_ptr<MockDNSSDService> > services;
+ };
}