summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/QA')
-rw-r--r--Swiften/QA/ClientTest/ClientTest.cpp63
-rw-r--r--Swiften/QA/ClientTest/Makefile.inc16
-rw-r--r--Swiften/QA/Makefile.inc11
-rw-r--r--Swiften/QA/NetworkTest/BoostConnectionTest.cpp51
-rw-r--r--Swiften/QA/NetworkTest/DomainNameResolverTest.cpp64
-rw-r--r--Swiften/QA/NetworkTest/Makefile.inc18
-rw-r--r--Swiften/QA/UnitTest/Makefile.inc17
-rw-r--r--Swiften/QA/UnitTest/checker.cpp16
-rw-r--r--Swiften/QA/UnitTest/template/FooTest.cpp24
-rw-r--r--Swiften/QA/valgrind.supp51
10 files changed, 331 insertions, 0 deletions
diff --git a/Swiften/QA/ClientTest/ClientTest.cpp b/Swiften/QA/ClientTest/ClientTest.cpp
new file mode 100644
index 0000000..20a03a4
--- /dev/null
+++ b/Swiften/QA/ClientTest/ClientTest.cpp
@@ -0,0 +1,63 @@
+#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"
+
+using namespace Swift;
+
+SimpleEventLoop eventLoop;
+
+Client* client = 0;
+bool rosterReceived = false;
+
+void printIncomingData(const String& data) {
+ std::cout << "<- " << data << std::endl;
+}
+
+void printOutgoingData(const String& data) {
+ std::cout << "-> " << data << std::endl;
+}
+
+void handleRosterReceived(boost::shared_ptr<Payload>) {
+ rosterReceived = true;
+ eventLoop.stop();
+}
+
+void handleConnected() {
+ GetRosterRequest* rosterRequest = new GetRosterRequest(client, Request::AutoDeleteAfterResponse);
+ 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));
+ client->onConnected.connect(&handleConnected);
+ client->onDataRead.connect(&printIncomingData);
+ client->onDataWritten.connect(&printOutgoingData);
+ client->connect();
+
+ {
+ Timer timer(10000);
+ timer.onTick.connect(boost::bind(&SimpleEventLoop::stop, &eventLoop));
+ timer.start();
+
+ eventLoop.run();
+ }
+ delete client;
+ return !rosterReceived;
+}
diff --git a/Swiften/QA/ClientTest/Makefile.inc b/Swiften/QA/ClientTest/Makefile.inc
new file mode 100644
index 0000000..d01ccf8
--- /dev/null
+++ b/Swiften/QA/ClientTest/Makefile.inc
@@ -0,0 +1,16 @@
+CLIENTTEST_TARGET = Swiften/QA/ClientTest/ClientTest
+CLIENTTEST_SOURCES += \
+ Swiften/QA/ClientTest/ClientTest.cpp
+CLIENTTEST_OBJECTS = \
+ $(CLIENTTEST_SOURCES:.cpp=.o)
+
+TEST_TARGETS += ClientTest
+
+CLEANFILES += $(CLIENTTEST_OBJECTS) $(CLIENTTEST_TARGET)
+
+$(CLIENTTEST_TARGET): $(SWIFTEN_TARGET) $(CLIENTTEST_OBJECTS)
+ $(QUIET_LINK)$(CXX) -o $(CLIENTTEST_TARGET) $(CLIENTTEST_OBJECTS) $(LDFLAGS) $(CPPCLIENT_LDFLAGS) $(SWIFTEN_TARGET) $(LIBS)
+
+.PHONY: ClientTest
+ClientTest: $(CLIENTTEST_TARGET)
+ $(TEST_RUNNER) $(CLIENTTEST_TARGET)
diff --git a/Swiften/QA/Makefile.inc b/Swiften/QA/Makefile.inc
new file mode 100644
index 0000000..dc3a0bf
--- /dev/null
+++ b/Swiften/QA/Makefile.inc
@@ -0,0 +1,11 @@
+ifdef USE_VALGRIND
+# Not enabled: --show-reachable=yes
+TEST_RUNNER=valgrind --suppressions=Swiften/QA/valgrind.supp -q --leak-check=full --track-origins=yes
+endif
+
+include Swiften/QA/UnitTest/Makefile.inc
+include Swiften/QA/NetworkTest/Makefile.inc
+include Swiften/QA/ClientTest/Makefile.inc
+
+.PHONY: test
+test: $(TEST_TARGETS)
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)
diff --git a/Swiften/QA/UnitTest/Makefile.inc b/Swiften/QA/UnitTest/Makefile.inc
new file mode 100644
index 0000000..5b456db
--- /dev/null
+++ b/Swiften/QA/UnitTest/Makefile.inc
@@ -0,0 +1,17 @@
+UNITTEST_TARGET = Swiften/QA/UnitTest/checker
+UNITTEST_SOURCES += \
+ Swiften/QA/UnitTest/checker.cpp
+UNITTEST_OBJECTS = \
+ $(UNITTEST_SOURCES:.cpp=.o)
+
+TEST_TARGETS += check
+
+CLEANFILES += $(UNITTEST_OBJECTS) $(UNITTEST_TARGET)
+
+.PHONY: check
+check: $(UNITTEST_TARGET)
+ $(TEST_RUNNER) ./$(UNITTEST_TARGET)
+
+$(UNITTEST_TARGET): $(SWIFTEN_TARGET) $(CPPUNIT_TARGET) $(UNITTEST_OBJECTS)
+ $(QUIET_LINK)$(CXX) -o $(UNITTEST_TARGET) $(UNITTEST_OBJECTS) $(LDFLAGS) $(SWIFTEN_TARGET) $(CPPUNIT_TARGET) $(LIBS)
+
diff --git a/Swiften/QA/UnitTest/checker.cpp b/Swiften/QA/UnitTest/checker.cpp
new file mode 100644
index 0000000..ea4f0d9
--- /dev/null
+++ b/Swiften/QA/UnitTest/checker.cpp
@@ -0,0 +1,16 @@
+#include <string>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/XmlOutputter.h>
+#include <cppunit/TextTestResult.h>
+
+int main(int argc, char* argv[])
+{
+ CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
+ CppUnit::TextUi::TestRunner runner;
+ runner.addTest( registry.makeTest() );
+ if (argc >= 2 && std::string(argv[1]) != std::string("--xml")) {
+ runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), std::cout));
+ }
+ return (runner.run("") ? 0 : 1);
+}
diff --git a/Swiften/QA/UnitTest/template/FooTest.cpp b/Swiften/QA/UnitTest/template/FooTest.cpp
new file mode 100644
index 0000000..b6b9abf
--- /dev/null
+++ b/Swiften/QA/UnitTest/template/FooTest.cpp
@@ -0,0 +1,24 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+using namespace Swift;
+
+class FooTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(FooTest);
+ CPPUNIT_TEST(testBar);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ FooTest() {}
+
+ void setUp() {
+ }
+
+ void tearDown() {
+ }
+
+ void testBar() {
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(FooTest);
diff --git a/Swiften/QA/valgrind.supp b/Swiften/QA/valgrind.supp
new file mode 100644
index 0000000..5e2ee00
--- /dev/null
+++ b/Swiften/QA/valgrind.supp
@@ -0,0 +1,51 @@
+{
+ ZLib doesn't allocate its buffer. This is no bug according to the FAQ.
+ Memcheck:Cond
+ fun:longest_match
+ fun:deflate_slow
+ fun:deflate
+}
+
+{
+ Not sure why this happens.
+ Memcheck:Leak
+ fun:calloc
+ fun:_dl_allocate_tls
+ fun:pthread_create@@GLIBC_2.1
+ fun:_ZN5boost6thread12start_threadEv
+}
+
+{
+ <insert a suppression name here>
+ Memcheck:Param
+ socketcall.sendto(msg)
+ fun:sendto
+ fun:getaddrinfo
+}
+
+{
+ <insert a suppression name here>
+ Memcheck:Cond
+ fun:BN_bin2bn
+}
+
+{
+ <insert a suppression name here>
+ Memcheck:Cond
+ fun:BN_num_bits_word
+}
+
+{
+ <insert a suppression name here>
+ Memcheck:Value4
+ fun:BN_mod_exp_mont_consttime
+ fun:BN_mod_exp_mont
+}
+
+{
+ <insert a suppression name here>
+ Memcheck:Value4
+ fun:BN_num_bits_word
+ fun:BN_mod_exp_mont_consttime
+ fun:BN_mod_exp_mont
+}