From 45eec1d00d5b9fabee1ce44f7dd8addd7d0cf6b3 Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Thu, 12 Feb 2015 13:18:02 +0100
Subject: Run FileTransferTest correctly as part of the system integration
 tests

If Scons is configured to run system unit tests, it will run
FileTransferTest and test for working IBB transfer, direct S5B transfer
and proxied S5B transfer.

Test-Information:

Tested ./scons test=all is working on Linux and OS X.

Change-Id: Id70c9e1e9db9c897d9bfc7dd03b874afe5262207

diff --git a/Swiften/QA/FileTransferTest/FileTransferTest.cpp b/Swiften/QA/FileTransferTest/FileTransferTest.cpp
index 764dffb..2d2d6c8 100644
--- a/Swiften/QA/FileTransferTest/FileTransferTest.cpp
+++ b/Swiften/QA/FileTransferTest/FileTransferTest.cpp
@@ -6,6 +6,7 @@
 
 #include <fstream>
 
+#include <boost/algorithm/string.hpp>
 #include <boost/numeric/conversion/cast.hpp>
 #include <boost/filesystem.hpp>
 
@@ -299,19 +300,46 @@ int main(int argc, char** argv) {
 	std::vector<std::pair<int, int> > failedTestPairs;
 	std::cout << "Swiften File-Transfer Connectivity Test Suite" << std::endl;
 	if (argc == 1) {
-		for (int n = 0; n < (1 << 7); n++) {
-			int senderCandidates = n & 0xF;
-			int receiverCandidates = (n >> 4) & 0xF;
-			std::cout << "Run test " << n + 1 << " of " << (1 << 7) << ", (" << senderCandidates << ", " << receiverCandidates << ")" << std::endl;
-			if (!runTest(senderCandidates, receiverCandidates)) {
-				failedTests++;
-				failedTestPairs.push_back(std::pair<int, int>(senderCandidates, receiverCandidates));
+		if (getenv("SWIFT_FILETRANSFERTEST_CONFIG")) {
+			// test configuration described in SWIFT_FILETRANSFERTEST_CONFIG environment variable, e.g. "1:1|2:2"
+			std::vector<std::string> configurations;
+			std::string configs_env = std::string(getenv("SWIFT_FILETRANSFERTEST_CONFIG"));
+			boost::split(configurations, configs_env, boost::is_any_of("|"));
+			foreach(const std::string& config, configurations) {
+				std::vector<std::string> split_config;
+				boost::split(split_config, config, boost::is_any_of(":"));
+				assert(split_config.size() == 2);
+
+				int senderCandidates = atoi(split_config[0].c_str());
+				int receiverCandidates = atoi(split_config[1].c_str());
+
+				if (!runTest(senderCandidates, receiverCandidates)) {
+					failedTests++;
+					failedTestPairs.push_back(std::pair<int, int>(senderCandidates, receiverCandidates));
+				}
+			}
+
+			typedef std::pair<int, int> IntPair;
+			foreach(IntPair failedTest, failedTestPairs) {
+				std::cout << "Failed test: " << "( " << failedTest.first << ", " << failedTest.second << ") " << std::endl;
 			}
 		}
+		else {
+			// test all configurations
+			for (int n = 0; n < (1 << 7); n++) {
+				int senderCandidates = n & 0xF;
+				int receiverCandidates = (n >> 4) & 0xF;
+				std::cout << "Run test " << n + 1 << " of " << (1 << 7) << ", (" << senderCandidates << ", " << receiverCandidates << ")" << std::endl;
+				if (!runTest(senderCandidates, receiverCandidates)) {
+					failedTests++;
+					failedTestPairs.push_back(std::pair<int, int>(senderCandidates, receiverCandidates));
+				}
+			}
 
-		typedef std::pair<int, int> IntPair;
-		foreach(IntPair failedTest, failedTestPairs) {
-			std::cout << "Failed test: " << "( " << failedTest.first << ", " << failedTest.second << ") " << std::endl;
+			typedef std::pair<int, int> IntPair;
+			foreach(IntPair failedTest, failedTestPairs) {
+				std::cout << "Failed test: " << "( " << failedTest.first << ", " << failedTest.second << ") " << std::endl;
+			}
 		}
 	}
 	else if (argc == 3) {
diff --git a/Swiften/QA/FileTransferTest/SConscript b/Swiften/QA/FileTransferTest/SConscript
index d17b12a..3275985 100644
--- a/Swiften/QA/FileTransferTest/SConscript
+++ b/Swiften/QA/FileTransferTest/SConscript
@@ -13,5 +13,8 @@ if env["TEST"] :
 		elif os.environ.get(i, "") :
 			myenv["ENV"][i] = os.environ[i]
 
+	# test in-band transfers, direct SOCKS5 bytestream transfers and proxied SOCKS5 bytestream transfers
+	myenv["ENV"]["SWIFT_FILETRANSFERTEST_CONFIG"] = "1:1|2:2|4:4"
+
 	tester = myenv.Program("FileTransferTest", ["FileTransferTest.cpp"])
 	myenv.Test(tester, "system")
-- 
cgit v0.10.2-6-g49f6