diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-06-01 08:48:42 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-06-01 09:24:28 (GMT) |
commit | 2812bddd81f8a1b804c7460f4e14cd0aa393d129 (patch) | |
tree | d46294f35150c4f0f43deaf2d31fceaf945ae715 /Swiften/QA/NetworkTest | |
download | swift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.zip swift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.tar.bz2 |
Import.
Diffstat (limited to 'Swiften/QA/NetworkTest')
-rw-r--r-- | Swiften/QA/NetworkTest/BoostConnectionTest.cpp | 51 | ||||
-rw-r--r-- | Swiften/QA/NetworkTest/DomainNameResolverTest.cpp | 64 | ||||
-rw-r--r-- | Swiften/QA/NetworkTest/Makefile.inc | 18 |
3 files changed, 133 insertions, 0 deletions
diff --git a/Swiften/QA/NetworkTest/BoostConnectionTest.cpp b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp new file mode 100644 index 0000000..639097a --- /dev/null +++ b/Swiften/QA/NetworkTest/BoostConnectionTest.cpp @@ -0,0 +1,51 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Base/String.h" +#include "Swiften/Base/sleep.h" +#include "Swiften/Network/BoostConnection.h" +#include "Swiften/EventLoop/DummyEventLoop.h" + +using namespace Swift; + +class BoostConnectionTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(BoostConnectionTest); + CPPUNIT_TEST(testDestructor); + CPPUNIT_TEST(testDestructor_PendingEvents); + CPPUNIT_TEST_SUITE_END(); + + public: + BoostConnectionTest() {} + + void setUp() { + eventLoop_ = new DummyEventLoop(); + } + + void tearDown() { + delete eventLoop_; + } + + void testDestructor() { + { + std::string domain("el-tramo.be"); + std::auto_ptr<BoostConnection> testling(new BoostConnection(domain)); + testling->connect(); + } + } + + void testDestructor_PendingEvents() { + { + std::auto_ptr<BoostConnection> testling(new BoostConnection("el-tramo.be")); + testling->connect(); + while (!eventLoop_->hasEvents()) { + Swift::sleep(10); + } + } + eventLoop_->processEvents(); + } + + private: + DummyEventLoop* eventLoop_; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(BoostConnectionTest); diff --git a/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp b/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp new file mode 100644 index 0000000..8968efd --- /dev/null +++ b/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp @@ -0,0 +1,64 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/Base/String.h" +#include "Swiften/Network/DomainNameResolver.h" +#include "Swiften/Network/DomainNameResolveException.h" + +using namespace Swift; + +class DomainNameResolverTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(DomainNameResolverTest); + CPPUNIT_TEST(testResolve_NoSRV); + CPPUNIT_TEST(testResolve_SRV); + CPPUNIT_TEST(testResolve_Invalid); + //CPPUNIT_TEST(testResolve_IPv6); + CPPUNIT_TEST(testResolve_International); + CPPUNIT_TEST_SUITE_END(); + + public: + DomainNameResolverTest() {} + + void setUp() { + resolver_ = new DomainNameResolver(); + } + + void tearDown() { + delete resolver_; + } + + void testResolve_NoSRV() { + HostAddressPort result = resolver_->resolve("xmpp.test.swift.im"); + + CPPUNIT_ASSERT_EQUAL(std::string("10.0.0.0"), result.getAddress().toString()); + CPPUNIT_ASSERT_EQUAL(5222, result.getPort()); + } + + void testResolve_SRV() { + HostAddressPort result = resolver_->resolve("xmpp-srv.test.swift.im"); + + CPPUNIT_ASSERT_EQUAL(std::string("10.0.0.1"), result.getAddress().toString()); + CPPUNIT_ASSERT_EQUAL(5000, result.getPort()); + } + + void testResolve_Invalid() { + CPPUNIT_ASSERT_THROW(resolver_->resolve("invalid.test.swift.im"), DomainNameResolveException); + } + + void testResolve_IPv6() { + HostAddressPort result = resolver_->resolve("xmpp-ipv6.test.swift.im"); + CPPUNIT_ASSERT_EQUAL(std::string("0000:0000:0000:0000:0000:ffff:0a00:0104"), result.getAddress().toString()); + CPPUNIT_ASSERT_EQUAL(5222, result.getPort()); + } + + void testResolve_International() { + HostAddressPort result = resolver_->resolve("tron\xc3\xa7on.test.swift.im"); + CPPUNIT_ASSERT_EQUAL(std::string("10.0.0.3"), result.getAddress().toString()); + CPPUNIT_ASSERT_EQUAL(5222, result.getPort()); + } + + private: + DomainNameResolver* resolver_; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(DomainNameResolverTest); diff --git a/Swiften/QA/NetworkTest/Makefile.inc b/Swiften/QA/NetworkTest/Makefile.inc new file mode 100644 index 0000000..6924a70 --- /dev/null +++ b/Swiften/QA/NetworkTest/Makefile.inc @@ -0,0 +1,18 @@ +NETWORKTEST_TARGET += Swiften/QA/NetworkTest/checker +NETWORKTEST_SOURCES += \ + Swiften/QA/NetworkTest/DomainNameResolverTest.cpp \ + Swiften/QA/NetworkTest/BoostConnectionTest.cpp \ + Swiften/QA/UnitTest/checker.cpp +NETWORKTEST_OBJECTS = \ + $(NETWORKTEST_SOURCES:.cpp=.o) + +TEST_TARGETS += NetworkTest + +CLEANFILES += $(NETWORKTEST_OBJECTS) $(NETWORKTEST_TARGET) + +$(NETWORKTEST_TARGET): $(SWIFTEN_TARGET) $(CPPUNIT_TARGET) $(NETWORKTEST_OBJECTS) + $(QUIET_LINK)$(CXX) -o $(NETWORKTEST_TARGET) $(NETWORKTEST_OBJECTS) $(LDFLAGS) $(CPPNETWORK_LDFLAGS) $(SWIFTEN_TARGET) $(CPPUNIT_TARGET) $(LIBS) + +.PHONY: NetworkTest +NetworkTest: $(NETWORKTEST_TARGET) + $(TEST_RUNNER) $(NETWORKTEST_TARGET) |