Simple tests for basic usage
This commit is contained in:
parent
62fcb14192
commit
b74fb0544e
5 changed files with 107 additions and 0 deletions
|
@ -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")
|
||||
|
|
3
tests/CMakeLists.txt
Normal file
3
tests/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
ADD_SUBDIRECTORY(login)
|
||||
|
||||
add_custom_target(tests python runtests.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
6
tests/login/CMakeLists.txt
Normal file
6
tests/login/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
FILE(GLOB SRC *.cpp)
|
||||
|
||||
ADD_EXECUTABLE(login_test ${SRC})
|
||||
|
||||
TARGET_LINK_LIBRARIES(login_test transport ${SWIFTEN_LIBRARIES})
|
||||
|
44
tests/login/main.cpp
Normal file
44
tests/login/main.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <iostream>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include <Swiften/Swiften.h>
|
||||
|
||||
using namespace Swift;
|
||||
using namespace boost;
|
||||
|
||||
Client* client;
|
||||
|
||||
static void handleDisconnected(const boost::optional<ClientError> &) {
|
||||
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;
|
||||
}
|
53
tests/runtests.py
Normal file
53
tests/runtests.py
Normal file
|
@ -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")
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue