Changeset - b74fb0544e32
[Not reviewed]
0 1 4
Jan Kaluza - 14 years ago 2011-06-07 15:31:52
hanzz.k@gmail.com
Simple tests for basic usage
5 files changed with 107 insertions and 0 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -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")
tests/CMakeLists.txt
Show inline comments
 
new file 100644
 
ADD_SUBDIRECTORY(login)
 

	
 
add_custom_target(tests python runtests.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
tests/login/CMakeLists.txt
Show inline comments
 
new file 100644
 
FILE(GLOB SRC *.cpp)
 
 
ADD_EXECUTABLE(login_test ${SRC})
 
 
TARGET_LINK_LIBRARIES(login_test transport ${SWIFTEN_LIBRARIES})
 
tests/login/main.cpp
Show inline comments
 
new file 100644
 
#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;
 
}
tests/runtests.py
Show inline comments
 
new file 100644
 
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")
 

	
 

	
0 comments (0 inline, 0 general)