diff options
Diffstat (limited to 'Swiften/LinkLocal/UnitTest')
4 files changed, 599 insertions, 599 deletions
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp index 617e625..3511f90 100644 --- a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp +++ b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp @@ -20,124 +20,124 @@ using namespace Swift; class LinkLocalConnectorTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(LinkLocalConnectorTest); - CPPUNIT_TEST(testConnect); - CPPUNIT_TEST(testConnect_UnableToResolve); - CPPUNIT_TEST(testConnect_UnableToConnect); - CPPUNIT_TEST(testCancel_DuringResolve); - CPPUNIT_TEST(testCancel_DuringConnect); - CPPUNIT_TEST_SUITE_END(); - - public: - void setUp() { - eventLoop = new DummyEventLoop(); - querier = boost::make_shared<FakeDNSSDQuerier>("rabbithole.local", eventLoop); - connection = boost::make_shared<FakeConnection>(eventLoop); - connectFinished = false; - } - - void tearDown() { - querier->clearAllQueriesEverRun(); - delete eventLoop; - } - - void testConnect() { - boost::shared_ptr<LinkLocalConnector> - testling(createConnector("rabbithole.local", 1234)); - querier->setAddress("rabbithole.local", HostAddress("192.168.1.1")); - - testling->connect(); - eventLoop->processEvents(); - - CPPUNIT_ASSERT(connectFinished); - CPPUNIT_ASSERT(!connectError); - CPPUNIT_ASSERT(connection->connectedTo); - CPPUNIT_ASSERT_EQUAL(std::string(connection->connectedTo->getAddress().toString()), std::string("192.168.1.1")); - CPPUNIT_ASSERT_EQUAL(connection->connectedTo->getPort(), 1234); - } - - void testConnect_UnableToResolve() { - boost::shared_ptr<LinkLocalConnector> - testling(createConnector("rabbithole.local", 1234)); - querier->setAddress("rabbithole.local", boost::optional<HostAddress>()); - - testling->connect(); - eventLoop->processEvents(); - - CPPUNIT_ASSERT(connectFinished); - CPPUNIT_ASSERT(connectError); - CPPUNIT_ASSERT(!connection->connectedTo); - } - - void testConnect_UnableToConnect() { - boost::shared_ptr<LinkLocalConnector> - testling(createConnector("rabbithole.local", 1234)); - querier->setAddress("rabbithole.local", HostAddress("192.168.1.1")); - connection->setError(Connection::ReadError); - - testling->connect(); - eventLoop->processEvents(); - - CPPUNIT_ASSERT(connectFinished); - CPPUNIT_ASSERT(connectError); - CPPUNIT_ASSERT(!connection->connectedTo); - } - - void testCancel_DuringResolve() { - boost::shared_ptr<LinkLocalConnector> - testling(createConnector("rabbithole.local", 1234)); - testling->connect(); - eventLoop->processEvents(); - CPPUNIT_ASSERT(!connectFinished); - - testling->cancel(); - eventLoop->processEvents(); - querier->setAddress("rabbithole.local", HostAddress("192.168.1.1")); - eventLoop->processEvents(); - - CPPUNIT_ASSERT(FakeConnection::Disconnected == connection->state); - } - - void testCancel_DuringConnect() { - boost::shared_ptr<LinkLocalConnector> - testling(createConnector("rabbithole.local", 1234)); - querier->setAddress("rabbithole.local", HostAddress("192.168.1.1")); - connection->setDelayConnect(); - testling->connect(); - eventLoop->processEvents(); - CPPUNIT_ASSERT(FakeConnection::Connecting == connection->state); - - testling->cancel(); - eventLoop->processEvents(); - - CPPUNIT_ASSERT(FakeConnection::Disconnected == connection->state); - } - - private: - boost::shared_ptr<LinkLocalConnector> createConnector(const std::string& hostname, int port) { - LinkLocalService service( - DNSSDServiceID("myname", "local."), - DNSSDResolveServiceQuery::Result( - "myname._presence._tcp.local", hostname, port, - LinkLocalServiceInfo().toTXTRecord())); - boost::shared_ptr<LinkLocalConnector> result( - new LinkLocalConnector(service, querier, connection)); - result->onConnectFinished.connect( - boost::bind(&LinkLocalConnectorTest::handleConnected, this, _1)); - return result; - } - - void handleConnected(bool e) { - connectFinished = true; - connectError = e; - } - - private: - DummyEventLoop* eventLoop; - boost::shared_ptr<FakeDNSSDQuerier> querier; - boost::shared_ptr<FakeConnection> connection; - bool connectFinished; - bool connectError; + CPPUNIT_TEST_SUITE(LinkLocalConnectorTest); + CPPUNIT_TEST(testConnect); + CPPUNIT_TEST(testConnect_UnableToResolve); + CPPUNIT_TEST(testConnect_UnableToConnect); + CPPUNIT_TEST(testCancel_DuringResolve); + CPPUNIT_TEST(testCancel_DuringConnect); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + eventLoop = new DummyEventLoop(); + querier = boost::make_shared<FakeDNSSDQuerier>("rabbithole.local", eventLoop); + connection = boost::make_shared<FakeConnection>(eventLoop); + connectFinished = false; + } + + void tearDown() { + querier->clearAllQueriesEverRun(); + delete eventLoop; + } + + void testConnect() { + boost::shared_ptr<LinkLocalConnector> + testling(createConnector("rabbithole.local", 1234)); + querier->setAddress("rabbithole.local", HostAddress("192.168.1.1")); + + testling->connect(); + eventLoop->processEvents(); + + CPPUNIT_ASSERT(connectFinished); + CPPUNIT_ASSERT(!connectError); + CPPUNIT_ASSERT(connection->connectedTo); + CPPUNIT_ASSERT_EQUAL(std::string(connection->connectedTo->getAddress().toString()), std::string("192.168.1.1")); + CPPUNIT_ASSERT_EQUAL(connection->connectedTo->getPort(), 1234); + } + + void testConnect_UnableToResolve() { + boost::shared_ptr<LinkLocalConnector> + testling(createConnector("rabbithole.local", 1234)); + querier->setAddress("rabbithole.local", boost::optional<HostAddress>()); + + testling->connect(); + eventLoop->processEvents(); + + CPPUNIT_ASSERT(connectFinished); + CPPUNIT_ASSERT(connectError); + CPPUNIT_ASSERT(!connection->connectedTo); + } + + void testConnect_UnableToConnect() { + boost::shared_ptr<LinkLocalConnector> + testling(createConnector("rabbithole.local", 1234)); + querier->setAddress("rabbithole.local", HostAddress("192.168.1.1")); + connection->setError(Connection::ReadError); + + testling->connect(); + eventLoop->processEvents(); + + CPPUNIT_ASSERT(connectFinished); + CPPUNIT_ASSERT(connectError); + CPPUNIT_ASSERT(!connection->connectedTo); + } + + void testCancel_DuringResolve() { + boost::shared_ptr<LinkLocalConnector> + testling(createConnector("rabbithole.local", 1234)); + testling->connect(); + eventLoop->processEvents(); + CPPUNIT_ASSERT(!connectFinished); + + testling->cancel(); + eventLoop->processEvents(); + querier->setAddress("rabbithole.local", HostAddress("192.168.1.1")); + eventLoop->processEvents(); + + CPPUNIT_ASSERT(FakeConnection::Disconnected == connection->state); + } + + void testCancel_DuringConnect() { + boost::shared_ptr<LinkLocalConnector> + testling(createConnector("rabbithole.local", 1234)); + querier->setAddress("rabbithole.local", HostAddress("192.168.1.1")); + connection->setDelayConnect(); + testling->connect(); + eventLoop->processEvents(); + CPPUNIT_ASSERT(FakeConnection::Connecting == connection->state); + + testling->cancel(); + eventLoop->processEvents(); + + CPPUNIT_ASSERT(FakeConnection::Disconnected == connection->state); + } + + private: + boost::shared_ptr<LinkLocalConnector> createConnector(const std::string& hostname, int port) { + LinkLocalService service( + DNSSDServiceID("myname", "local."), + DNSSDResolveServiceQuery::Result( + "myname._presence._tcp.local", hostname, port, + LinkLocalServiceInfo().toTXTRecord())); + boost::shared_ptr<LinkLocalConnector> result( + new LinkLocalConnector(service, querier, connection)); + result->onConnectFinished.connect( + boost::bind(&LinkLocalConnectorTest::handleConnected, this, _1)); + return result; + } + + void handleConnected(bool e) { + connectFinished = true; + connectError = e; + } + + private: + DummyEventLoop* eventLoop; + boost::shared_ptr<FakeDNSSDQuerier> querier; + boost::shared_ptr<FakeConnection> connection; + bool connectFinished; + bool connectError; }; CPPUNIT_TEST_SUITE_REGISTRATION(LinkLocalConnectorTest); diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp index 8533b33..6d8ba97 100644 --- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp +++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp @@ -23,392 +23,392 @@ using namespace Swift; class LinkLocalServiceBrowserTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(LinkLocalServiceBrowserTest); - CPPUNIT_TEST(testConstructor); - CPPUNIT_TEST(testStart); - CPPUNIT_TEST(testServiceAdded); - CPPUNIT_TEST(testServiceAdded_NoServiceInfo); - CPPUNIT_TEST(testServiceAdded_RegisteredService); - CPPUNIT_TEST(testServiceAdded_UnregisteredService); - CPPUNIT_TEST(testServiceAdded_Twice); - CPPUNIT_TEST(testServiceChanged); - CPPUNIT_TEST(testServiceRemoved); - CPPUNIT_TEST(testServiceRemoved_UnregisteredService); - CPPUNIT_TEST(testError_BrowseErrorAfterStart); - CPPUNIT_TEST(testError_BrowseErrorAfterResolve); - CPPUNIT_TEST(testRegisterService); - CPPUNIT_TEST(testRegisterService_Error); - CPPUNIT_TEST(testRegisterService_Reregister); - CPPUNIT_TEST(testUpdateService); - CPPUNIT_TEST_SUITE_END(); - - public: - void setUp() { - eventLoop = new DummyEventLoop(); - querier = boost::make_shared<FakeDNSSDQuerier>("wonderland.lit", eventLoop); - 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() { - querier->clearAllQueriesEverRun(); - addedServices.clear(); - removedServices.clear(); - changedServices.clear(); - - delete aliceServiceID; - delete aliceServiceInfo; - delete testServiceInfo2; - delete testServiceInfo; - delete testServiceID; - delete eventLoop; - } - - void testConstructor() { - boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); - - CPPUNIT_ASSERT(!testling->isRunning()); - CPPUNIT_ASSERT(!testling->hasError()); - } - - void testStart() { - boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); - testling->start(); - - CPPUNIT_ASSERT(testling->isRunning()); - CPPUNIT_ASSERT(!testling->hasError()); - - testling->stop(); - } - - void testServiceAdded() { - boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); - testling->start(); - eventLoop->processEvents(); - - querier->setServiceInfo(*testServiceID,*testServiceInfo); - querier->addService(*testServiceID); - eventLoop->processEvents(); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size())); - CPPUNIT_ASSERT(addedServices[0].getID() == *testServiceID); - 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(1, static_cast<int>(services.size())); - CPPUNIT_ASSERT(*testServiceID == services[0].getID()); - CPPUNIT_ASSERT(testServiceInfo->port == services[0].getPort()); - CPPUNIT_ASSERT(testServiceInfo->host == services[0].getHostname()); - - testling->stop(); - } - - void testServiceAdded_NoServiceInfo() { - boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); - testling->start(); - eventLoop->processEvents(); - - querier->addService(*testServiceID); - 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].getID() == *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(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(); - } - - void testServiceRemoved_UnregisteredService() { - boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); - testling->start(); - eventLoop->processEvents(); - testling->registerService("alice", 1234, LinkLocalServiceInfo()); - eventLoop->processEvents(); - testling->unregisterService(); - eventLoop->processEvents(); - - querier->removeService(*aliceServiceID); - eventLoop->processEvents(); - - CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(removedServices.size())); - - testling->stop(); - } - - void testServiceAdded_Twice() { - boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); - testling->start(); - eventLoop->processEvents(); - - querier->setServiceInfo(*testServiceID,*testServiceInfo); - querier->addService(*testServiceID); - querier->addService(*testServiceID); - eventLoop->processEvents(); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(querier->getAllQueriesEverRun<FakeDNSSDResolveServiceQuery>().size())); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size())); - CPPUNIT_ASSERT(addedServices[0].getID() == *testServiceID); - 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(1, static_cast<int>(services.size())); - CPPUNIT_ASSERT(*testServiceID == services[0].getID()); - CPPUNIT_ASSERT(testServiceInfo->port == services[0].getPort()); - CPPUNIT_ASSERT(testServiceInfo->host == services[0].getHostname()); - - testling->stop(); - } - - - void testServiceChanged() { - boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); - testling->start(); - querier->setServiceInfo(*testServiceID,*testServiceInfo); - querier->addService(*testServiceID); - eventLoop->processEvents(); - - querier->setServiceInfo(*testServiceID,*testServiceInfo2); - eventLoop->processEvents(); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size())); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changedServices.size())); - CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(removedServices.size())); - CPPUNIT_ASSERT(changedServices[0].getID() == *testServiceID); - std::vector<LinkLocalService> services = testling->getServices(); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(services.size())); - CPPUNIT_ASSERT(*testServiceID == services[0].getID()); - CPPUNIT_ASSERT(testServiceInfo2->port == services[0].getPort()); - CPPUNIT_ASSERT(testServiceInfo2->host == services[0].getHostname()); - - testling->stop(); - } - - void testServiceRemoved() { - boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); - testling->start(); - querier->setServiceInfo(*testServiceID,*testServiceInfo); - querier->addService(*testServiceID); - eventLoop->processEvents(); - - querier->removeService(*testServiceID); - eventLoop->processEvents(); - querier->setServiceInfo(*testServiceID,*testServiceInfo2); - eventLoop->processEvents(); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size())); - CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changedServices.size())); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(removedServices.size())); - CPPUNIT_ASSERT(removedServices[0].getID() == *testServiceID); - CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling->getServices().size())); - - testling->stop(); - } - - void testError_BrowseErrorAfterStart() { - boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); - testling->start(); - - querier->setBrowseError(); - eventLoop->processEvents(); - - CPPUNIT_ASSERT(!testling->isRunning()); - CPPUNIT_ASSERT(testling->hasError()); - CPPUNIT_ASSERT(errorStopReceived); - } - - void testError_BrowseErrorAfterResolve() { - boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); - testling->start(); - querier->setServiceInfo(*testServiceID,*testServiceInfo); - querier->addService(*testServiceID); - eventLoop->processEvents(); - - querier->setBrowseError(); - eventLoop->processEvents(); - querier->setServiceInfo(*testServiceID,*testServiceInfo2); - eventLoop->processEvents(); - - CPPUNIT_ASSERT(!testling->isRunning()); - 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() { - boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); - 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())); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(registeredServices.size())); - CPPUNIT_ASSERT(registeredServices[0] == DNSSDServiceID("foo@bar", "wonderland.lit")); - testling->stop(); - } - - void testRegisterService_Error() { - boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); - testling->start(); - LinkLocalServiceInfo info; - testling->registerService("foo@bar", 1234, info); - eventLoop->processEvents(); - - querier->setRegisterError(); - eventLoop->processEvents(); - - 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(); - } - - void testUpdateService() { - boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); - testling->start(); - eventLoop->processEvents(); - - LinkLocalServiceInfo info; - info.setFirstName("Foo"); - testling->registerService("foo@bar", 1234, info); - eventLoop->processEvents(); - info.setFirstName("Bar"); - testling->updateService(info); - - CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, info.toTXTRecord())); - - testling->stop(); - } - - private: - boost::shared_ptr<LinkLocalServiceBrowser> createTestling() { - boost::shared_ptr<LinkLocalServiceBrowser> testling( - new LinkLocalServiceBrowser(querier)); - testling->onServiceAdded.connect(boost::bind( - &LinkLocalServiceBrowserTest::handleServiceAdded, this, _1)); - testling->onServiceChanged.connect(boost::bind( - &LinkLocalServiceBrowserTest::handleServiceChanged, this, _1)); - testling->onServiceRemoved.connect(boost::bind( - &LinkLocalServiceBrowserTest::handleServiceRemoved, this, _1)); - testling->onServiceRegistered.connect(boost::bind( - &LinkLocalServiceBrowserTest::handleServiceRegistered, this, _1)); - testling->onStopped.connect(boost::bind( - &LinkLocalServiceBrowserTest::handleStopped, this, _1)); - return testling; - } - - void handleServiceAdded(const LinkLocalService& service) { - addedServices.push_back(service); - } - - void handleServiceRemoved(const LinkLocalService& service) { - removedServices.push_back(service); - } - - void handleServiceChanged(const LinkLocalService& service) { - changedServices.push_back(service); - } - - void handleServiceRegistered(const DNSSDServiceID& service) { - registeredServices.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<LinkLocalService> addedServices; - std::vector<LinkLocalService> changedServices; - std::vector<LinkLocalService> removedServices; - std::vector<DNSSDServiceID> registeredServices; - DNSSDServiceID* aliceServiceID; - DNSSDResolveServiceQuery::Result* aliceServiceInfo; - DNSSDServiceID* testServiceID; - DNSSDResolveServiceQuery::Result* testServiceInfo; - DNSSDResolveServiceQuery::Result* testServiceInfo2; - bool errorStopReceived; - bool normalStopReceived; + CPPUNIT_TEST_SUITE(LinkLocalServiceBrowserTest); + CPPUNIT_TEST(testConstructor); + CPPUNIT_TEST(testStart); + CPPUNIT_TEST(testServiceAdded); + CPPUNIT_TEST(testServiceAdded_NoServiceInfo); + CPPUNIT_TEST(testServiceAdded_RegisteredService); + CPPUNIT_TEST(testServiceAdded_UnregisteredService); + CPPUNIT_TEST(testServiceAdded_Twice); + CPPUNIT_TEST(testServiceChanged); + CPPUNIT_TEST(testServiceRemoved); + CPPUNIT_TEST(testServiceRemoved_UnregisteredService); + CPPUNIT_TEST(testError_BrowseErrorAfterStart); + CPPUNIT_TEST(testError_BrowseErrorAfterResolve); + CPPUNIT_TEST(testRegisterService); + CPPUNIT_TEST(testRegisterService_Error); + CPPUNIT_TEST(testRegisterService_Reregister); + CPPUNIT_TEST(testUpdateService); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + eventLoop = new DummyEventLoop(); + querier = boost::make_shared<FakeDNSSDQuerier>("wonderland.lit", eventLoop); + 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() { + querier->clearAllQueriesEverRun(); + addedServices.clear(); + removedServices.clear(); + changedServices.clear(); + + delete aliceServiceID; + delete aliceServiceInfo; + delete testServiceInfo2; + delete testServiceInfo; + delete testServiceID; + delete eventLoop; + } + + void testConstructor() { + boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); + + CPPUNIT_ASSERT(!testling->isRunning()); + CPPUNIT_ASSERT(!testling->hasError()); + } + + void testStart() { + boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); + testling->start(); + + CPPUNIT_ASSERT(testling->isRunning()); + CPPUNIT_ASSERT(!testling->hasError()); + + testling->stop(); + } + + void testServiceAdded() { + boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); + testling->start(); + eventLoop->processEvents(); + + querier->setServiceInfo(*testServiceID,*testServiceInfo); + querier->addService(*testServiceID); + eventLoop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size())); + CPPUNIT_ASSERT(addedServices[0].getID() == *testServiceID); + 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(1, static_cast<int>(services.size())); + CPPUNIT_ASSERT(*testServiceID == services[0].getID()); + CPPUNIT_ASSERT(testServiceInfo->port == services[0].getPort()); + CPPUNIT_ASSERT(testServiceInfo->host == services[0].getHostname()); + + testling->stop(); + } + + void testServiceAdded_NoServiceInfo() { + boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); + testling->start(); + eventLoop->processEvents(); + + querier->addService(*testServiceID); + 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].getID() == *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(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(); + } + + void testServiceRemoved_UnregisteredService() { + boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); + testling->start(); + eventLoop->processEvents(); + testling->registerService("alice", 1234, LinkLocalServiceInfo()); + eventLoop->processEvents(); + testling->unregisterService(); + eventLoop->processEvents(); + + querier->removeService(*aliceServiceID); + eventLoop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(removedServices.size())); + + testling->stop(); + } + + void testServiceAdded_Twice() { + boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); + testling->start(); + eventLoop->processEvents(); + + querier->setServiceInfo(*testServiceID,*testServiceInfo); + querier->addService(*testServiceID); + querier->addService(*testServiceID); + eventLoop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(querier->getAllQueriesEverRun<FakeDNSSDResolveServiceQuery>().size())); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size())); + CPPUNIT_ASSERT(addedServices[0].getID() == *testServiceID); + 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(1, static_cast<int>(services.size())); + CPPUNIT_ASSERT(*testServiceID == services[0].getID()); + CPPUNIT_ASSERT(testServiceInfo->port == services[0].getPort()); + CPPUNIT_ASSERT(testServiceInfo->host == services[0].getHostname()); + + testling->stop(); + } + + + void testServiceChanged() { + boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); + testling->start(); + querier->setServiceInfo(*testServiceID,*testServiceInfo); + querier->addService(*testServiceID); + eventLoop->processEvents(); + + querier->setServiceInfo(*testServiceID,*testServiceInfo2); + eventLoop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size())); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changedServices.size())); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(removedServices.size())); + CPPUNIT_ASSERT(changedServices[0].getID() == *testServiceID); + std::vector<LinkLocalService> services = testling->getServices(); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(services.size())); + CPPUNIT_ASSERT(*testServiceID == services[0].getID()); + CPPUNIT_ASSERT(testServiceInfo2->port == services[0].getPort()); + CPPUNIT_ASSERT(testServiceInfo2->host == services[0].getHostname()); + + testling->stop(); + } + + void testServiceRemoved() { + boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); + testling->start(); + querier->setServiceInfo(*testServiceID,*testServiceInfo); + querier->addService(*testServiceID); + eventLoop->processEvents(); + + querier->removeService(*testServiceID); + eventLoop->processEvents(); + querier->setServiceInfo(*testServiceID,*testServiceInfo2); + eventLoop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size())); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changedServices.size())); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(removedServices.size())); + CPPUNIT_ASSERT(removedServices[0].getID() == *testServiceID); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling->getServices().size())); + + testling->stop(); + } + + void testError_BrowseErrorAfterStart() { + boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); + testling->start(); + + querier->setBrowseError(); + eventLoop->processEvents(); + + CPPUNIT_ASSERT(!testling->isRunning()); + CPPUNIT_ASSERT(testling->hasError()); + CPPUNIT_ASSERT(errorStopReceived); + } + + void testError_BrowseErrorAfterResolve() { + boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); + testling->start(); + querier->setServiceInfo(*testServiceID,*testServiceInfo); + querier->addService(*testServiceID); + eventLoop->processEvents(); + + querier->setBrowseError(); + eventLoop->processEvents(); + querier->setServiceInfo(*testServiceID,*testServiceInfo2); + eventLoop->processEvents(); + + CPPUNIT_ASSERT(!testling->isRunning()); + 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() { + boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); + 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())); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(registeredServices.size())); + CPPUNIT_ASSERT(registeredServices[0] == DNSSDServiceID("foo@bar", "wonderland.lit")); + testling->stop(); + } + + void testRegisterService_Error() { + boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); + testling->start(); + LinkLocalServiceInfo info; + testling->registerService("foo@bar", 1234, info); + eventLoop->processEvents(); + + querier->setRegisterError(); + eventLoop->processEvents(); + + 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(); + } + + void testUpdateService() { + boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling(); + testling->start(); + eventLoop->processEvents(); + + LinkLocalServiceInfo info; + info.setFirstName("Foo"); + testling->registerService("foo@bar", 1234, info); + eventLoop->processEvents(); + info.setFirstName("Bar"); + testling->updateService(info); + + CPPUNIT_ASSERT(querier->isServiceRegistered("foo@bar", 1234, info.toTXTRecord())); + + testling->stop(); + } + + private: + boost::shared_ptr<LinkLocalServiceBrowser> createTestling() { + boost::shared_ptr<LinkLocalServiceBrowser> testling( + new LinkLocalServiceBrowser(querier)); + testling->onServiceAdded.connect(boost::bind( + &LinkLocalServiceBrowserTest::handleServiceAdded, this, _1)); + testling->onServiceChanged.connect(boost::bind( + &LinkLocalServiceBrowserTest::handleServiceChanged, this, _1)); + testling->onServiceRemoved.connect(boost::bind( + &LinkLocalServiceBrowserTest::handleServiceRemoved, this, _1)); + testling->onServiceRegistered.connect(boost::bind( + &LinkLocalServiceBrowserTest::handleServiceRegistered, this, _1)); + testling->onStopped.connect(boost::bind( + &LinkLocalServiceBrowserTest::handleStopped, this, _1)); + return testling; + } + + void handleServiceAdded(const LinkLocalService& service) { + addedServices.push_back(service); + } + + void handleServiceRemoved(const LinkLocalService& service) { + removedServices.push_back(service); + } + + void handleServiceChanged(const LinkLocalService& service) { + changedServices.push_back(service); + } + + void handleServiceRegistered(const DNSSDServiceID& service) { + registeredServices.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<LinkLocalService> addedServices; + std::vector<LinkLocalService> changedServices; + std::vector<LinkLocalService> removedServices; + std::vector<DNSSDServiceID> registeredServices; + DNSSDServiceID* aliceServiceID; + DNSSDResolveServiceQuery::Result* aliceServiceInfo; + DNSSDServiceID* testServiceID; + DNSSDResolveServiceQuery::Result* testServiceInfo; + DNSSDResolveServiceQuery::Result* testServiceInfo2; + bool errorStopReceived; + bool normalStopReceived; }; CPPUNIT_TEST_SUITE_REGISTRATION(LinkLocalServiceBrowserTest); diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp index 55fdfb3..0a94a98 100644 --- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp +++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp @@ -15,58 +15,58 @@ using namespace Swift; class LinkLocalServiceInfoTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(LinkLocalServiceInfoTest); - CPPUNIT_TEST(testGetTXTRecord); - CPPUNIT_TEST(testCreateFromTXTRecord); - CPPUNIT_TEST(testCreateFromTXTRecord_InvalidSize); - CPPUNIT_TEST(testGetTXTRecordCreateFromTXTRecord_RoundTrip); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(LinkLocalServiceInfoTest); + CPPUNIT_TEST(testGetTXTRecord); + CPPUNIT_TEST(testCreateFromTXTRecord); + CPPUNIT_TEST(testCreateFromTXTRecord_InvalidSize); + CPPUNIT_TEST(testGetTXTRecordCreateFromTXTRecord_RoundTrip); + CPPUNIT_TEST_SUITE_END(); - public: - void testGetTXTRecord() { - LinkLocalServiceInfo info; - info.setFirstName("Remko"); - info.setLastName("Tron\xc3\xe7on"); - info.setStatus(LinkLocalServiceInfo::Away); + public: + void testGetTXTRecord() { + LinkLocalServiceInfo info; + info.setFirstName("Remko"); + info.setLastName("Tron\xc3\xe7on"); + info.setStatus(LinkLocalServiceInfo::Away); - CPPUNIT_ASSERT_EQUAL(createByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away")), info.toTXTRecord()); - } + CPPUNIT_ASSERT_EQUAL(createByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away")), info.toTXTRecord()); + } - void testCreateFromTXTRecord() { - LinkLocalServiceInfo info = LinkLocalServiceInfo::createFromTXTRecord(createByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away"))); + void testCreateFromTXTRecord() { + LinkLocalServiceInfo info = LinkLocalServiceInfo::createFromTXTRecord(createByteArray("\x09txtvers=1\x09" + std::string("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away"))); - CPPUNIT_ASSERT_EQUAL(std::string("Remko"), info.getFirstName()); - CPPUNIT_ASSERT_EQUAL(std::string("Tron\xc3\xe7on"), info.getLastName()); - CPPUNIT_ASSERT_EQUAL(LinkLocalServiceInfo::Away, info.getStatus()); - } + CPPUNIT_ASSERT_EQUAL(std::string("Remko"), info.getFirstName()); + CPPUNIT_ASSERT_EQUAL(std::string("Tron\xc3\xe7on"), info.getLastName()); + CPPUNIT_ASSERT_EQUAL(LinkLocalServiceInfo::Away, info.getStatus()); + } - void testCreateFromTXTRecord_InvalidSize() { - LinkLocalServiceInfo info = LinkLocalServiceInfo::createFromTXTRecord(createByteArray("\x10last=a")); + void testCreateFromTXTRecord_InvalidSize() { + LinkLocalServiceInfo info = LinkLocalServiceInfo::createFromTXTRecord(createByteArray("\x10last=a")); - CPPUNIT_ASSERT_EQUAL(std::string("a"), info.getLastName()); - } + CPPUNIT_ASSERT_EQUAL(std::string("a"), info.getLastName()); + } - void testGetTXTRecordCreateFromTXTRecord_RoundTrip() { - LinkLocalServiceInfo info; - info.setFirstName("Remko"); - info.setLastName("Tron\xc3\xe7on"); - info.setEMail("remko-email@swift.im"); - info.setJID(JID("remko-jid@swift.im")); - info.setMessage("I'm busy"); - info.setNick("el-tramo"); - info.setStatus(LinkLocalServiceInfo::DND); - info.setPort(1234); + void testGetTXTRecordCreateFromTXTRecord_RoundTrip() { + LinkLocalServiceInfo info; + info.setFirstName("Remko"); + info.setLastName("Tron\xc3\xe7on"); + info.setEMail("remko-email@swift.im"); + info.setJID(JID("remko-jid@swift.im")); + info.setMessage("I'm busy"); + info.setNick("el-tramo"); + info.setStatus(LinkLocalServiceInfo::DND); + info.setPort(1234); - LinkLocalServiceInfo info2 = LinkLocalServiceInfo::createFromTXTRecord(info.toTXTRecord()); - CPPUNIT_ASSERT_EQUAL(info.getFirstName(), info2.getFirstName()); - CPPUNIT_ASSERT_EQUAL(info.getLastName(), info2.getLastName()); - CPPUNIT_ASSERT_EQUAL(info.getEMail(), info2.getEMail()); - CPPUNIT_ASSERT_EQUAL(info.getJID(), info2.getJID()); - CPPUNIT_ASSERT_EQUAL(info.getMessage(), info2.getMessage()); - CPPUNIT_ASSERT_EQUAL(info.getNick(), info2.getNick()); - CPPUNIT_ASSERT(info.getStatus() == info2.getStatus()); - CPPUNIT_ASSERT(info.getPort() == info2.getPort()); - } + LinkLocalServiceInfo info2 = LinkLocalServiceInfo::createFromTXTRecord(info.toTXTRecord()); + CPPUNIT_ASSERT_EQUAL(info.getFirstName(), info2.getFirstName()); + CPPUNIT_ASSERT_EQUAL(info.getLastName(), info2.getLastName()); + CPPUNIT_ASSERT_EQUAL(info.getEMail(), info2.getEMail()); + CPPUNIT_ASSERT_EQUAL(info.getJID(), info2.getJID()); + CPPUNIT_ASSERT_EQUAL(info.getMessage(), info2.getMessage()); + CPPUNIT_ASSERT_EQUAL(info.getNick(), info2.getNick()); + CPPUNIT_ASSERT(info.getStatus() == info2.getStatus()); + CPPUNIT_ASSERT(info.getPort() == info2.getPort()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(LinkLocalServiceInfoTest); diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp index 0eb2464..206d824 100644 --- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp +++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp @@ -12,57 +12,57 @@ using namespace Swift; class LinkLocalServiceTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(LinkLocalServiceTest); - CPPUNIT_TEST(testGetDescription_WithNick); - CPPUNIT_TEST(testGetDescription_WithFirstName); - CPPUNIT_TEST(testGetDescription_WithLastName); - CPPUNIT_TEST(testGetDescription_WithFirstAndLastName); - CPPUNIT_TEST(testGetDescription_NoInfo); - CPPUNIT_TEST_SUITE_END(); - - public: - void testGetDescription_WithNick() { - LinkLocalService testling = createService("alice@wonderland", "Alice", "Alice In", "Wonderland"); - - CPPUNIT_ASSERT_EQUAL(std::string("Alice"), testling.getDescription()); - } - - void testGetDescription_WithFirstName() { - LinkLocalService testling = createService("alice@wonderland", "", "Alice In"); - - CPPUNIT_ASSERT_EQUAL(std::string("Alice In"), testling.getDescription()); - } - - void testGetDescription_WithLastName() { - LinkLocalService testling = createService("alice@wonderland", "", "", "Wonderland"); - - CPPUNIT_ASSERT_EQUAL(std::string("Wonderland"), testling.getDescription()); - } - - void testGetDescription_WithFirstAndLastName() { - LinkLocalService testling = createService("alice@wonderland", "", "Alice In", "Wonderland"); - - CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland"), testling.getDescription()); - } - - void testGetDescription_NoInfo() { - LinkLocalService testling = createService("alice@wonderland"); - - CPPUNIT_ASSERT_EQUAL(std::string("alice@wonderland"), testling.getDescription()); - } - - private: - LinkLocalService createService(const std::string& name, const std::string& nickName = std::string(), const std::string& firstName = std::string(), const std::string& lastName = std::string()) { - DNSSDServiceID service(name, "local."); - LinkLocalServiceInfo info; - info.setFirstName(firstName); - info.setLastName(lastName); - info.setNick(nickName); - return LinkLocalService(service, - DNSSDResolveServiceQuery::Result( - name + "._presence._tcp.local", "rabbithole.local", 1234, - info.toTXTRecord())); - } + CPPUNIT_TEST_SUITE(LinkLocalServiceTest); + CPPUNIT_TEST(testGetDescription_WithNick); + CPPUNIT_TEST(testGetDescription_WithFirstName); + CPPUNIT_TEST(testGetDescription_WithLastName); + CPPUNIT_TEST(testGetDescription_WithFirstAndLastName); + CPPUNIT_TEST(testGetDescription_NoInfo); + CPPUNIT_TEST_SUITE_END(); + + public: + void testGetDescription_WithNick() { + LinkLocalService testling = createService("alice@wonderland", "Alice", "Alice In", "Wonderland"); + + CPPUNIT_ASSERT_EQUAL(std::string("Alice"), testling.getDescription()); + } + + void testGetDescription_WithFirstName() { + LinkLocalService testling = createService("alice@wonderland", "", "Alice In"); + + CPPUNIT_ASSERT_EQUAL(std::string("Alice In"), testling.getDescription()); + } + + void testGetDescription_WithLastName() { + LinkLocalService testling = createService("alice@wonderland", "", "", "Wonderland"); + + CPPUNIT_ASSERT_EQUAL(std::string("Wonderland"), testling.getDescription()); + } + + void testGetDescription_WithFirstAndLastName() { + LinkLocalService testling = createService("alice@wonderland", "", "Alice In", "Wonderland"); + + CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland"), testling.getDescription()); + } + + void testGetDescription_NoInfo() { + LinkLocalService testling = createService("alice@wonderland"); + + CPPUNIT_ASSERT_EQUAL(std::string("alice@wonderland"), testling.getDescription()); + } + + private: + LinkLocalService createService(const std::string& name, const std::string& nickName = std::string(), const std::string& firstName = std::string(), const std::string& lastName = std::string()) { + DNSSDServiceID service(name, "local."); + LinkLocalServiceInfo info; + info.setFirstName(firstName); + info.setLastName(lastName); + info.setNick(nickName); + return LinkLocalService(service, + DNSSDResolveServiceQuery::Result( + name + "._presence._tcp.local", "rabbithole.local", 1234, + info.toTXTRecord())); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(LinkLocalServiceTest); |