From e67eb946a93f2217291e1dd27e287e1b1f2f030a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sat, 26 Feb 2011 10:55:37 +0100 Subject: Moving tests around. diff --git a/BuildTools/SCons/Tools/Test.py b/BuildTools/SCons/Tools/Test.py index 883da45..40eaeb1 100644 --- a/BuildTools/SCons/Tools/Test.py +++ b/BuildTools/SCons/Tools/Test.py @@ -16,7 +16,12 @@ def generate(env) : env.Command("**dummy**", target, SCons.Action.Action(ignore_prefix + env.get("TEST_RUNNER", "") + cmd + " " + params, cmdstr = "$TESTCOMSTR")) + def registerScriptTests(env, scripts, name, type) : + if env["TEST_TYPE"] == "all" or env["TEST_TYPE"] == type : + pass + env.AddMethod(registerTest, "Test") + env.AddMethod(registerScriptTests, "ScriptTests") def exists(env) : return True diff --git a/Sluift/README b/Sluift/README new file mode 100644 index 0000000..2d9c2e2 --- /dev/null +++ b/Sluift/README @@ -0,0 +1 @@ +For example scripts, see Swiften/QA/ScriptedTests diff --git a/Sluift/SConscript b/Sluift/SConscript index 49d6de3..e00d32e 100644 --- a/Sluift/SConscript +++ b/Sluift/SConscript @@ -21,7 +21,7 @@ if env["SCONS_STAGE"] == "build" : if sluift_bin_env.get("HAVE_READLINE", False) : sluift_bin_env.Append(CPPDEFINES = ["LUA_USE_READLINE"]) sluift_bin_env.MergeFlags(sluift_bin_env["READLINE_FLAGS"]) - sluift_bin_env.Program("sluift", [ + env["SLUIFT"] = sluift_bin_env.Program("sluift", [ "sluift.cpp", "lua.c", "linit.c", diff --git a/Sluift/client_test.lua b/Sluift/client_test.lua deleted file mode 100644 index 1652083..0000000 --- a/Sluift/client_test.lua +++ /dev/null @@ -1,38 +0,0 @@ -require "sluift" - --- sluift.debug = true -client1_jid = os.getenv("SWIFT_CLIENTTEST_JID") .. "/Client1" -client2_jid = os.getenv("SWIFT_CLIENTTEST_JID") .. "/Client2" -password = os.getenv("SWIFT_CLIENTTEST_PASS") - -print "Connecting client 1" -client1 = sluift.new_client(client1_jid, password) -client1:connect() -client1:send_presence("I'm here") - -print "Connecting client 2" -client2 = sluift.new_client(client2_jid, password) -client2:connect() -client2:send_presence("I'm here") - -print "Checking version of client 2 from client 1" -client2:set_version({name = "Sluift Test", version = "1.0"}) -client2_version = client1:get_version(client2_jid) -assert(client2_version["name"] == "Sluift Test") -assert(client2_version["version"] == "1.0") - -print "Sending message from client 1 to client 2" -client1:send_message(client2_jid, "Hello") -received_message = client2:for_event(function(event) - if event["type"] == "message" and event["from"] == client1_jid then - return event["body"] - end - end) -assert(received_message == "Hello") - -print "Retrieving the roster" -roster = client1:get_roster() -table.foreach(roster, print) - -client1:disconnect() -client2:disconnect() diff --git a/Sluift/multiple_client_test.lua b/Sluift/multiple_client_test.lua deleted file mode 100644 index d2b2cd7..0000000 --- a/Sluift/multiple_client_test.lua +++ /dev/null @@ -1,26 +0,0 @@ -require "sluift" - --- sluift.debug = true -num_clients = 10 - -print("Connecting clients") -clients = {} -for i = 1, num_clients do - jid = os.getenv("SWIFT_CLIENTTEST_JID") .. "/Client" .. i - client = sluift.new_client(jid, os.getenv("SWIFT_CLIENTTEST_PASS")) - client:async_connect() - table.insert(clients, client) -end - -print("Waiting for clients to be connected") -for i, client in ipairs(clients) do - client:wait_connected() - client:send_presence("Hello") -end - -print("Disconnecting clients") -for i, client in ipairs(clients) do - client:disconnect() -end - -print("Done") diff --git a/Swiften/QA/SConscript b/Swiften/QA/SConscript index 4638d6c..25ba814 100644 --- a/Swiften/QA/SConscript +++ b/Swiften/QA/SConscript @@ -7,4 +7,5 @@ SConscript(dirs = [ # "DNSSDTest", "StorageTest", "TLSTest", + "ScriptedTests", ]) diff --git a/Swiften/QA/ScriptedTests/MultipleClients.lua b/Swiften/QA/ScriptedTests/MultipleClients.lua new file mode 100644 index 0000000..76eba74 --- /dev/null +++ b/Swiften/QA/ScriptedTests/MultipleClients.lua @@ -0,0 +1,32 @@ +-- +-- Copyright (c) 2010 Remko Tronçon +-- Licensed under the GNU General Public License v3. +-- See Documentation/Licenses/GPLv3.txt for more information. +-- + +require "sluift" + +-- sluift.debug = true +num_clients = 10 + +print("Connecting clients") +clients = {} +for i = 1, num_clients do + jid = os.getenv("SWIFT_CLIENTTEST_JID") .. "/Client" .. i + client = sluift.new_client(jid, os.getenv("SWIFT_CLIENTTEST_PASS")) + client:async_connect() + table.insert(clients, client) +end + +print("Waiting for clients to be connected") +for i, client in ipairs(clients) do + client:wait_connected() + client:send_presence("Hello") +end + +print("Disconnecting clients") +for i, client in ipairs(clients) do + client:disconnect() +end + +print("Done") diff --git a/Swiften/QA/ScriptedTests/SConscript b/Swiften/QA/ScriptedTests/SConscript new file mode 100644 index 0000000..298c455 --- /dev/null +++ b/Swiften/QA/ScriptedTests/SConscript @@ -0,0 +1,7 @@ +Import("env") + +if env["TEST"] : + env.ScriptTests([ + "SendMessage.lua", + "MultipleClients.lua", + ], "Swiften.QA.ScriptedTests", "system") diff --git a/Swiften/QA/ScriptedTests/SendMessage.lua b/Swiften/QA/ScriptedTests/SendMessage.lua new file mode 100644 index 0000000..a3f1917 --- /dev/null +++ b/Swiften/QA/ScriptedTests/SendMessage.lua @@ -0,0 +1,44 @@ +-- +-- Copyright (c) 2010 Remko Tronçon +-- Licensed under the GNU General Public License v3. +-- See Documentation/Licenses/GPLv3.txt for more information. +-- + +require "sluift" + +-- sluift.debug = true +client1_jid = os.getenv("SWIFT_CLIENTTEST_JID") .. "/Client1" +client2_jid = os.getenv("SWIFT_CLIENTTEST_JID") .. "/Client2" +password = os.getenv("SWIFT_CLIENTTEST_PASS") + +print "Connecting client 1" +client1 = sluift.new_client(client1_jid, password) +client1:connect() +client1:send_presence("I'm here") + +print "Connecting client 2" +client2 = sluift.new_client(client2_jid, password) +client2:connect() +client2:send_presence("I'm here") + +print "Checking version of client 2 from client 1" +client2:set_version({name = "Sluift Test", version = "1.0"}) +client2_version = client1:get_version(client2_jid) +assert(client2_version["name"] == "Sluift Test") +assert(client2_version["version"] == "1.0") + +print "Sending message from client 1 to client 2" +client1:send_message(client2_jid, "Hello") +received_message = client2:for_event(function(event) + if event["type"] == "message" and event["from"] == client1_jid then + return event["body"] + end + end) +assert(received_message == "Hello") + +print "Retrieving the roster" +roster = client1:get_roster() +table.foreach(roster, print) + +client1:disconnect() +client2:disconnect() -- cgit v0.10.2-6-g49f6