summaryrefslogtreecommitdiffstats
path: root/QA
diff options
context:
space:
mode:
Diffstat (limited to 'QA')
-rw-r--r--QA/SConscript5
-rw-r--r--QA/Swiften/ClientTest/ClientTest.cpp56
-rw-r--r--QA/Swiften/ClientTest/SConscript22
-rw-r--r--QA/Swiften/NetworkTest/.gitignore1
-rw-r--r--QA/Swiften/NetworkTest/BoostConnectionServerTest.cpp72
-rw-r--r--QA/Swiften/NetworkTest/BoostConnectionTest.cpp59
-rw-r--r--QA/Swiften/NetworkTest/DomainNameResolverTest.cpp64
-rw-r--r--QA/Swiften/NetworkTest/SConscript18
-rw-r--r--QA/Swiften/SConscript10
-rw-r--r--QA/UnitTest/SConscript12
10 files changed, 317 insertions, 2 deletions
diff --git a/QA/SConscript b/QA/SConscript
index 32aece4..feafb0c 100644
--- a/QA/SConscript
+++ b/QA/SConscript
@@ -1 +1,4 @@
-SConscript("UnitTest/SConscript")
+SConscript(dirs = [
+ "UnitTest",
+ "Swiften"
+ ])
diff --git a/QA/Swiften/ClientTest/ClientTest.cpp b/QA/Swiften/ClientTest/ClientTest.cpp
new file mode 100644
index 0000000..b628a8d
--- /dev/null
+++ b/QA/Swiften/ClientTest/ClientTest.cpp
@@ -0,0 +1,56 @@
+#include <boost/bind.hpp>
+#include <boost/thread.hpp>
+
+#include "Swiften/Client/Client.h"
+#include "Swiften/Network/Timer.h"
+#include "Swiften/EventLoop/MainEventLoop.h"
+#include "Swiften/EventLoop/SimpleEventLoop.h"
+#include "Swiften/Queries/Requests/GetRosterRequest.h"
+#include "Swiften/Client/ClientXMLTracer.h"
+
+using namespace Swift;
+
+SimpleEventLoop eventLoop;
+
+Client* client = 0;
+bool rosterReceived = false;
+
+void handleRosterReceived(boost::shared_ptr<Payload>) {
+ rosterReceived = true;
+ eventLoop.stop();
+}
+
+void handleConnected() {
+ boost::shared_ptr<GetRosterRequest> rosterRequest(new GetRosterRequest(client));
+ rosterRequest->onResponse.connect(boost::bind(&handleRosterReceived, _1));
+ rosterRequest->send();
+}
+
+int main(int, char**) {
+ char* jid = getenv("SWIFT_CLIENTTEST_JID");
+ if (!jid) {
+ std::cerr << "Please set the SWIFT_CLIENTTEST_JID environment variable" << std::endl;
+ return -1;
+ }
+ char* pass = getenv("SWIFT_CLIENTTEST_PASS");
+ if (!pass) {
+ std::cerr << "Please set the SWIFT_CLIENTTEST_PASS environment variable" << std::endl;
+ return -1;
+ }
+
+ client = new Swift::Client(JID(jid), String(pass));
+ ClientXMLTracer* tracer = new ClientXMLTracer(client);
+ client->onConnected.connect(&handleConnected);
+ client->connect();
+
+ {
+ boost::shared_ptr<Timer> timer(new Timer(10000));
+ timer->onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
+ timer->start();
+
+ eventLoop.run();
+ }
+ delete tracer;
+ delete client;
+ return !rosterReceived;
+}
diff --git a/QA/Swiften/ClientTest/SConscript b/QA/Swiften/ClientTest/SConscript
new file mode 100644
index 0000000..164de57
--- /dev/null
+++ b/QA/Swiften/ClientTest/SConscript
@@ -0,0 +1,22 @@
+import os
+
+Import("env")
+
+myenv = env.Clone()
+myenv.MergeFlags(env["SWIFTEN_FLAGS"])
+myenv.MergeFlags(env["CPPUNIT_FLAGS"])
+myenv.MergeFlags(env["LIBIDN_FLAGS"])
+myenv.MergeFlags(env["BOOST_FLAGS"])
+myenv.MergeFlags(env["SQLITE_FLAGS"])
+myenv.MergeFlags(env["ZLIB_FLAGS"])
+myenv.MergeFlags(env["OPENSSL_FLAGS"])
+myenv.MergeFlags(env.get("LIBXML_FLAGS", ""))
+myenv.MergeFlags(env.get("EXPAT_FLAGS", ""))
+
+for i in ["SWIFT_CLIENTTEST_JID", "SWIFT_CLIENTTEST_PASS"]:
+ if os.environ.get(i, "") :
+ myenv["ENV"][i] = os.environ[i]
+
+tester = myenv.Program("ClientTest", ["ClientTest.cpp"])
+clientTest = myenv.Alias("ClientTest", tester, env.get("TEST_RUNNER", "") + tester[0].abspath)
+env.AlwaysBuild(clientTest)
diff --git a/QA/Swiften/NetworkTest/.gitignore b/QA/Swiften/NetworkTest/.gitignore
new file mode 100644
index 0000000..5a3caca
--- /dev/null
+++ b/QA/Swiften/NetworkTest/.gitignore
@@ -0,0 +1 @@
+NetworkTest
diff --git a/QA/Swiften/NetworkTest/BoostConnectionServerTest.cpp b/QA/Swiften/NetworkTest/BoostConnectionServerTest.cpp
new file mode 100644
index 0000000..a5c51aa
--- /dev/null
+++ b/QA/Swiften/NetworkTest/BoostConnectionServerTest.cpp
@@ -0,0 +1,72 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <boost/shared_ptr.hpp>
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Network/BoostConnectionServer.h"
+#include "Swiften/Network/BoostIOServiceThread.h"
+#include "Swiften/EventLoop/DummyEventLoop.h"
+
+using namespace Swift;
+
+class BoostConnectionServerTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(BoostConnectionServerTest);
+ CPPUNIT_TEST(testConstructor_TwoServersOnSamePort);
+ CPPUNIT_TEST(testStart_Conflict);
+ CPPUNIT_TEST(testStop);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ boostIOServiceThread_ = new BoostIOServiceThread();
+ eventLoop_ = new DummyEventLoop();
+ stopped = false;
+ stoppedError.reset();
+ }
+
+ void tearDown() {
+ delete eventLoop_;
+ delete boostIOServiceThread_;
+ }
+
+ void testConstructor_TwoServersOnSamePort() {
+ boost::shared_ptr<BoostConnectionServer> testling(new BoostConnectionServer(9999, &boostIOServiceThread_->getIOService()));
+ boost::shared_ptr<BoostConnectionServer> testling2(new BoostConnectionServer(9999, &boostIOServiceThread_->getIOService()));
+ }
+
+ void testStart_Conflict() {
+ boost::shared_ptr<BoostConnectionServer> testling(new BoostConnectionServer(9999, &boostIOServiceThread_->getIOService()));
+ testling->start();
+
+ boost::shared_ptr<BoostConnectionServer> testling2(new BoostConnectionServer(9999, &boostIOServiceThread_->getIOService()));
+ testling2->onStopped.connect(
+ boost::bind(&BoostConnectionServerTest::handleStopped, this, _1));
+
+ testling->stop();
+ }
+
+ void testStop() {
+ boost::shared_ptr<BoostConnectionServer> testling(new BoostConnectionServer(9999, &boostIOServiceThread_->getIOService()));
+ testling->start();
+
+ testling->stop();
+
+ boost::shared_ptr<BoostConnectionServer> testling2(new BoostConnectionServer(9999, &boostIOServiceThread_->getIOService()));
+ testling2->start();
+
+ testling2->stop();
+ }
+
+ void handleStopped(boost::optional<BoostConnectionServer::Error> e) {
+ stopped = true;
+ stoppedError = e;
+ }
+
+ private:
+ BoostIOServiceThread* boostIOServiceThread_;
+ DummyEventLoop* eventLoop_;
+ bool stopped;
+ boost::optional<BoostConnectionServer::Error> stoppedError;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(BoostConnectionServerTest);
diff --git a/QA/Swiften/NetworkTest/BoostConnectionTest.cpp b/QA/Swiften/NetworkTest/BoostConnectionTest.cpp
new file mode 100644
index 0000000..9929eaa
--- /dev/null
+++ b/QA/Swiften/NetworkTest/BoostConnectionTest.cpp
@@ -0,0 +1,59 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <boost/shared_ptr.hpp>
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Base/sleep.h"
+#include "Swiften/Network/BoostConnection.h"
+#include "Swiften/Network/HostAddress.h"
+#include "Swiften/Network/HostAddressPort.h"
+#include "Swiften/Network/BoostIOServiceThread.h"
+#include "Swiften/EventLoop/DummyEventLoop.h"
+
+const unsigned char* address = reinterpret_cast<const unsigned char*>("\x41\x63\xde\x89");
+
+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() {
+ boostIOServiceThread_ = new BoostIOServiceThread();
+ eventLoop_ = new DummyEventLoop();
+ }
+
+ void tearDown() {
+ delete eventLoop_;
+ delete boostIOServiceThread_;
+ }
+
+ void testDestructor() {
+ {
+ boost::shared_ptr<BoostConnection> testling(new BoostConnection(&boostIOServiceThread_->getIOService()));
+ testling->connect(HostAddressPort(HostAddress(address, 4), 5222));
+ }
+ }
+
+ void testDestructor_PendingEvents() {
+ {
+ boost::shared_ptr<BoostConnection> testling(new BoostConnection(&boostIOServiceThread_->getIOService()));
+ testling->connect(HostAddressPort(HostAddress(address, 4), 5222));
+ while (!eventLoop_->hasEvents()) {
+ Swift::sleep(10);
+ }
+ }
+ eventLoop_->processEvents();
+ }
+
+ private:
+ BoostIOServiceThread* boostIOServiceThread_;
+ DummyEventLoop* eventLoop_;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(BoostConnectionTest);
diff --git a/QA/Swiften/NetworkTest/DomainNameResolverTest.cpp b/QA/Swiften/NetworkTest/DomainNameResolverTest.cpp
new file mode 100644
index 0000000..8968efd
--- /dev/null
+++ b/QA/Swiften/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/QA/Swiften/NetworkTest/SConscript b/QA/Swiften/NetworkTest/SConscript
new file mode 100644
index 0000000..fa5122b
--- /dev/null
+++ b/QA/Swiften/NetworkTest/SConscript
@@ -0,0 +1,18 @@
+import os
+
+Import("env")
+
+myenv = env.Clone()
+myenv.MergeFlags(env["CHECKER_FLAGS"])
+myenv.MergeFlags(env["SWIFTEN_FLAGS"])
+myenv.MergeFlags(env["CPPUNIT_FLAGS"])
+myenv.MergeFlags(env["BOOST_FLAGS"])
+myenv.MergeFlags(env["LIBIDN_FLAGS"])
+
+tester = myenv.Program("NetworkTest", [
+ "BoostConnectionServerTest.cpp",
+ "BoostConnectionTest.cpp",
+ "DomainNameResolverTest.cpp",
+ ])
+clientTest = myenv.Alias("NetworkTest", tester, env.get("TEST_RUNNER", "") + tester[0].abspath)
+env.AlwaysBuild(clientTest)
diff --git a/QA/Swiften/SConscript b/QA/Swiften/SConscript
new file mode 100644
index 0000000..6ee7365
--- /dev/null
+++ b/QA/Swiften/SConscript
@@ -0,0 +1,10 @@
+Import("env")
+
+tests = ["NetworkTest", "ClientTest"]
+if "test" in COMMAND_LINE_TARGETS or env.GetOption("clean") or len(set(tests) & set(COMMAND_LINE_TARGETS)):
+ SConscript([
+ "NetworkTest/SConscript",
+ "ClientTest/SConscript",
+ ])
+
+ test = env.Alias("test", tests)
diff --git a/QA/UnitTest/SConscript b/QA/UnitTest/SConscript
index 4e82443..5480420 100644
--- a/QA/UnitTest/SConscript
+++ b/QA/UnitTest/SConscript
@@ -2,8 +2,18 @@ import os
Import("env")
+# The checker
+checker_env = env.Clone()
+checker_env.MergeFlags(env["CPPUNIT_FLAGS"])
+checker_env.Library("Checker", "checker.cpp")
+env["CHECKER_FLAGS"] = {
+ "LIBS": ["Checker"],
+ "LIBPATH": [Dir(".")]
+ }
+
if "check" in COMMAND_LINE_TARGETS or env.GetOption("clean") :
myenv = env.Clone()
+ myenv.MergeFlags(env["CHECKER_FLAGS"])
myenv.MergeFlags(env["SLIMBER_FLAGS"])
myenv.MergeFlags(env["SWIFT_CONTROLLERS_FLAGS"])
myenv.MergeFlags(env["SWIFTEN_FLAGS"])
@@ -18,7 +28,7 @@ if "check" in COMMAND_LINE_TARGETS or env.GetOption("clean") :
myenv.Append(CPPDEFINES = ["HAVE_LIBXML"])
if env.get("HAVE_EXPAT") :
myenv.Append(CPPDEFINES = ["HAVE_EXPAT"])
- checker = myenv.Program("checker", ["checker.cpp"] + env["UNITTEST_SOURCES"])
+ checker = myenv.Program("checker", env["UNITTEST_SOURCES"])
for i in ["HOME", "USERPROFILE", "APPDATA"]:
if os.environ.get(i, "") :
myenv["ENV"][i] = os.environ[i]