diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-03-28 13:40:14 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-03-28 13:40:43 (GMT) |
commit | b61486fefe602e0d18fa5279021006f87b965307 (patch) | |
tree | 437585cbef1179e1ec31f79789591d5610200c29 /Swiften/LinkLocal/UnitTest | |
parent | dae28dd45e43fc6e6ef2ec4c6c65d5d736ed86f8 (diff) | |
download | swift-b61486fefe602e0d18fa5279021006f87b965307.zip swift-b61486fefe602e0d18fa5279021006f87b965307.tar.bz2 |
Moved Swiften to a separate module.
Diffstat (limited to 'Swiften/LinkLocal/UnitTest')
m--------- | Swiften | 0 | ||||
-rw-r--r-- | Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp | 135 | ||||
-rw-r--r-- | Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp | 379 | ||||
-rw-r--r-- | Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp | 63 | ||||
-rw-r--r-- | Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp | 62 |
5 files changed, 0 insertions, 639 deletions
diff --git a/Swiften b/Swiften new file mode 160000 +Subproject 8213ba16d0043d2461f4b031c881d61dda5a38c diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp deleted file mode 100644 index ee5e414..0000000 --- a/Swiften/LinkLocal/UnitTest/LinkLocalConnectorTest.cpp +++ /dev/null @@ -1,135 +0,0 @@ -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/extensions/TestFactoryRegistry.h> - -#include "Swiften/LinkLocal/LinkLocalConnector.h" -#include "Swiften/LinkLocal/LinkLocalService.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveHostnameQuery.h" -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h" -#include "Swiften/EventLoop/DummyEventLoop.h" -#include "Swiften/Network/FakeConnection.h" - -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::shared_ptr<FakeDNSSDQuerier>( - new FakeDNSSDQuerier("rabbithole.local")); - connection = boost::shared_ptr<FakeConnection>(new FakeConnection()); - connectFinished = false; - } - - void tearDown() { - 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(String(connection->connectedTo->getAddress().toString()), 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 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 deleted file mode 100644 index 9f91269..0000000 --- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp +++ /dev/null @@ -1,379 +0,0 @@ -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/extensions/TestFactoryRegistry.h> -#include <boost/bind.hpp> -#include <map> - -#include "Swiften/LinkLocal/LinkLocalServiceBrowser.h" -#include "Swiften/LinkLocal/LinkLocalService.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h" -#include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h" -#include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h" -#include "Swiften/EventLoop/DummyEventLoop.h" - -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(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: - LinkLocalServiceBrowserTest() {} - - void setUp() { - eventLoop = new DummyEventLoop(); - 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() { - 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 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 deleted file mode 100644 index b5d7ef5..0000000 --- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceInfoTest.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/extensions/TestFactoryRegistry.h> - -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" - -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(); - - public: - void testGetTXTRecord() { - LinkLocalServiceInfo info; - info.setFirstName("Remko"); - info.setLastName("Tron\xc3\xe7on"); - info.setStatus(LinkLocalServiceInfo::Away); - - CPPUNIT_ASSERT_EQUAL(ByteArray("\x09txtvers=1\x09" + String("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away")), info.toTXTRecord()); - } - - void testCreateFromTXTRecord() { - LinkLocalServiceInfo info = LinkLocalServiceInfo::createFromTXTRecord(ByteArray("\x09txtvers=1\x09" + String("1st=Remko\x0dlast=Tron\xc3\xe7on\x0bstatus=away"))); - - CPPUNIT_ASSERT_EQUAL(String("Remko"), info.getFirstName()); - CPPUNIT_ASSERT_EQUAL(String("Tron\xc3\xe7on"), info.getLastName()); - CPPUNIT_ASSERT_EQUAL(LinkLocalServiceInfo::Away, info.getStatus()); - } - - void testCreateFromTXTRecord_InvalidSize() { - LinkLocalServiceInfo info = LinkLocalServiceInfo::createFromTXTRecord(ByteArray("\x10last=a")); - - CPPUNIT_ASSERT_EQUAL(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); - - 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 deleted file mode 100644 index 69ec718..0000000 --- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceTest.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/extensions/TestFactoryRegistry.h> - -#include "Swiften/LinkLocal/LinkLocalService.h" - -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(String("Alice"), testling.getDescription()); - } - - void testGetDescription_WithFirstName() { - LinkLocalService testling = createService("alice@wonderland", "", "Alice In"); - - CPPUNIT_ASSERT_EQUAL(String("Alice In"), testling.getDescription()); - } - - void testGetDescription_WithLastName() { - LinkLocalService testling = createService("alice@wonderland", "", "", "Wonderland"); - - CPPUNIT_ASSERT_EQUAL(String("Wonderland"), testling.getDescription()); - } - - void testGetDescription_WithFirstAndLastName() { - LinkLocalService testling = createService("alice@wonderland", "", "Alice In", "Wonderland"); - - CPPUNIT_ASSERT_EQUAL(String("Alice In Wonderland"), testling.getDescription()); - } - - void testGetDescription_NoInfo() { - LinkLocalService testling = createService("alice@wonderland"); - - CPPUNIT_ASSERT_EQUAL(String("alice@wonderland"), testling.getDescription()); - } - - private: - LinkLocalService createService(const String& name, const String& nickName = String(), const String& firstName = String(), const String& lastName = 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); |