From b74fb0544e32e5fb91d867fd6397dae091d37901 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Tue, 7 Jun 2011 15:31:52 +0200 Subject: [PATCH] Simple tests for basic usage --- CMakeLists.txt | 1 + tests/CMakeLists.txt | 3 +++ tests/login/CMakeLists.txt | 6 +++++ tests/login/main.cpp | 44 +++++++++++++++++++++++++++++++ tests/runtests.py | 53 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/login/CMakeLists.txt create mode 100644 tests/login/main.cpp create mode 100644 tests/runtests.py diff --git a/CMakeLists.txt b/CMakeLists.txt index aa73cafe..9b67004d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,6 +110,7 @@ ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(examples) ADD_SUBDIRECTORY(spectrum) ADD_SUBDIRECTORY(backends) +ADD_SUBDIRECTORY(tests) if(DOXYGEN_FOUND) message("Docs : yes") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..bdbd3c65 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,3 @@ +ADD_SUBDIRECTORY(login) + +add_custom_target(tests python runtests.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/tests/login/CMakeLists.txt b/tests/login/CMakeLists.txt new file mode 100644 index 00000000..9c129973 --- /dev/null +++ b/tests/login/CMakeLists.txt @@ -0,0 +1,6 @@ +FILE(GLOB SRC *.cpp) + +ADD_EXECUTABLE(login_test ${SRC}) + +TARGET_LINK_LIBRARIES(login_test transport ${SWIFTEN_LIBRARIES}) + diff --git a/tests/login/main.cpp b/tests/login/main.cpp new file mode 100644 index 00000000..d303b6fe --- /dev/null +++ b/tests/login/main.cpp @@ -0,0 +1,44 @@ +#include +#include + +#include + +using namespace Swift; +using namespace boost; + +Client* client; + +static void handleDisconnected(const boost::optional &) { + std::cout << "Disconnected..." << std::endl; + exit(1); +} + +static void handleConnected() { + std::cout << "Connected..." << std::endl; + exit(0); +} + +static void handleMessageReceived(Message::ref message) { + // Echo back the incoming message + message->setTo(message->getFrom()); + message->setFrom(JID()); + client->sendMessage(message); +} + +int main(int, char **argv) { + SimpleEventLoop eventLoop; + BoostNetworkFactories networkFactories(&eventLoop); + + client = new Client(argv[1], argv[2], &networkFactories); + client->setAlwaysTrustCertificates(); + client->setAllowPLAINOverNonTLS(true); + client->onConnected.connect(&handleConnected); + client->onDisconnected.connect(bind(&handleDisconnected, _1)); + client->onMessageReceived.connect(bind(&handleMessageReceived, _1)); + client->connect(); + + eventLoop.run(); + + delete client; + return 0; +} diff --git a/tests/runtests.py b/tests/runtests.py new file mode 100644 index 00000000..014a45e5 --- /dev/null +++ b/tests/runtests.py @@ -0,0 +1,53 @@ +import os +import sys +from subprocess import * +import time + +def run_spectrum(backend): + f = open("sample.cfg", "w") + f.write("\ + [service]\n\ + jid = localhost\n\ + password = secret\n\ + server = 127.0.0.1\n\ + port = 5222\n\ + server_mode = 1\n\ + backend=../backends/%s/%s_backend\n\ + protocol=prpl-jabber\n\ +\ + [database]\n\ + database = test.sql\n\ + prefix=icq\n\ + " % (backend, backend) + ) + f.close() + p = Popen("../spectrum/src/spectrum sample.cfg > /dev/null 2> /dev/null", shell=True) + time.sleep(1) + return p + + +os.system("killall spectrum 2> /dev/null") + +for backend in os.listdir("../backends"): + if not os.path.isdir("../backends/" + backend) or backend == "CMakeFiles": + continue + + for d in os.listdir("."): + binary = d + "/" + d + "_test" + if not os.path.exists(binary): + continue + + p = run_spectrum(backend); + + if backend.find("purple") >= 0: + ret = os.system(binary + " pyjim%jabber.cz@localhost test") + else: + ret = os.system(binary + " testnickname%irc.freenode.net@localhost test") + if ret == 0: + print "[ PASS ]", backend, binary + else: + print "[ FAIL ]", backend, binary + + os.system("killall spectrum 2> /dev/null") + +