From 283a6801fd11aeaf38b2298399c2bf622f743cf4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Wed, 12 Aug 2009 19:59:10 +0200
Subject: Added Slimber & valgrind testing to SCons.


diff --git a/3rdParty/Boost/SConscript b/3rdParty/Boost/SConscript
index 769a67d..d828edc 100644
--- a/3rdParty/Boost/SConscript
+++ b/3rdParty/Boost/SConscript
@@ -46,7 +46,7 @@ sources = [
 		"libs/regex/src/winstances.cpp",
 		"libs/regex/src/usinstances.cpp"]
 
-if env.get("HAVE_PTHREAD", 0) :
+if env["PLATFORM"] != "win32" :
 	sources += [
 			"libs/thread/src/pthread/exceptions.cpp",
 			"libs/thread/src/pthread/once.cpp",
diff --git a/QA/UnitTest/SConscript b/QA/UnitTest/SConscript
index 6382d56..505b633 100644
--- a/QA/UnitTest/SConscript
+++ b/QA/UnitTest/SConscript
@@ -4,6 +4,7 @@ Import("env")
 
 if "check" in COMMAND_LINE_TARGETS or env.GetOption("clean") :
 	myenv = env.Clone()
+	myenv.MergeFlags(env["SLIMBER_FLAGS"])
 	myenv.MergeFlags(env["SWIFT_CONTROLLERS_FLAGS"])
 	myenv.MergeFlags(env["SWIFTEN_FLAGS"])
 	myenv.MergeFlags(env["CPPUNIT_FLAGS"])
@@ -16,5 +17,5 @@ if "check" in COMMAND_LINE_TARGETS or env.GetOption("clean") :
 	for i in ["HOME", "USERPROFILE", "APPDATA"]:
 		if os.environ.get(i, "") :
 			myenv["ENV"][i] = os.environ[i]
-	check = myenv.Alias("check", checker, checker[0].abspath)
+	check = myenv.Alias("check", checker, env.get("TEST_RUNNER", "") + checker[0].abspath)
 	myenv.AlwaysBuild(check)
diff --git a/SConstruct b/SConstruct
index 463dc0b..2feadd0 100644
--- a/SConstruct
+++ b/SConstruct
@@ -11,6 +11,8 @@ vars.Add(BoolVariable("warnings", "Compile with warnings turned on",
     "yes" if os.name != "nt" else "no"))
 if os.name != "nt" :
   vars.Add(BoolVariable("coverage", "Compile with coverage information", "no"))
+if os.name == "posix" :
+  vars.Add(BoolVariable("valgrind", "Run tests with valgrind", "no"))
 if os.name == "mac" :
   vars.Add(BoolVariable("universal", "Create universal binaries", "no"))
 if os.name == "nt" :
@@ -60,6 +62,9 @@ if env.get("coverage", 0) :
 	env.Append(CCFLAGS = ["-fprofile-arcs", "-ftest-coverage"])
 	env.Append(LINKFLAGS = ["-fprofile-arcs", "-ftest-coverage"])
 
+if env.get("valgrind", 0) :
+  env["TEST_RUNNER"] = "valgrind --suppressions=QA/valgrind.supp -q --leak-check=full --track-origins=yes "
+
 if env["PLATFORM"] == "win32" :
 	env.Append(LIBS = ["dnsapi", "ws2_32", "wsock32"])
 	env.Append(CCFLAGS = "/EHsc")
@@ -126,9 +131,6 @@ if env["PLATFORM"] == "win32" :
 
 conf = Configure(conf_env)
 
-if conf.CheckCHeader("pthread.h") :
-	env["HAVE_PTHREAD"] = 1
-
 if conf.CheckLib("z") :
 	env.Append(LIBS = "z")
 	env["ZLIB_FLAGS"] = ""
diff --git a/Slimber/CLI/Makefile.inc b/Slimber/CLI/Makefile.inc
deleted file mode 100644
index 974b835..0000000
--- a/Slimber/CLI/Makefile.inc
+++ /dev/null
@@ -1,15 +0,0 @@
-SLIMBER_CLI_TARGET = Slimber/CLI/slimber
-SLIMBER_CLI_SOURCES = \
-	Slimber/CLI/main.cpp
-SLIMBER_CLI_OBJECTS = \
-	$(SLIMBER_CLI_SOURCES:.cpp=.o)
-
-$(SLIMBER_CLI_TARGET): $(SWIFTEN_TARGET) $(SLIMBER_TARGET) $(SLIMBER_CLI_OBJECTS)
-	$(QUIET_LINK)$(CXX) -o $(SLIMBER_CLI_TARGET) $(SLIMBER_CLI_OBJECTS) $(LDFLAGS) $(SLIMBER_TARGET) $(SWIFTEN_TARGET) $(LIBS)
-
-#TARGETS += $(SLIMBER_CLI_TARGET)
-SLIMBER_TARGETS += $(SLIMBER_CLI_TARGET)
-CLEANFILES += \
-	$(SLIMBER_CLI_TARGET)
-DEPS += \
-	$(SLIMBER_CLI_SOURCES:.cpp=.dep) \
diff --git a/Slimber/CLI/SConscript b/Slimber/CLI/SConscript
new file mode 100644
index 0000000..b65843d
--- /dev/null
+++ b/Slimber/CLI/SConscript
@@ -0,0 +1,8 @@
+Import("env")
+
+myenv = env.Clone()
+myenv.MergeFlags(env["SLIMBER_FLAGS"])
+myenv.MergeFlags(env["SWIFTEN_FLAGS"])
+myenv.MergeFlags(env["BOOST_FLAGS"])
+
+myenv.Program("slimber", ["main.cpp"])
diff --git a/Slimber/CLI/main.cpp b/Slimber/CLI/main.cpp
index b82ffcd..0dd2c04 100644
--- a/Slimber/CLI/main.cpp
+++ b/Slimber/CLI/main.cpp
@@ -7,7 +7,7 @@
 #include "Swiften/LinkLocal/LinkLocalServiceBrowser.h"
 #include "Swiften/LinkLocal/DNSSD/DNSSDBrowseQuery.h"
 #include "Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h"
-#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h"
+//#include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h"
 #include "Swiften/EventLoop/SimpleEventLoop.h"
 #include "Swiften/Application/Platform/PlatformApplication.h"
 
@@ -15,10 +15,12 @@ using namespace Swift;
 
 int main() {
 	SimpleEventLoop eventLoop;
+  /*
 	boost::shared_ptr<BonjourQuerier> querier(new BonjourQuerier());
 	querier->start();
 	LinkLocalServiceBrowser browser(querier);
 	browser.start();
+  */
 
 /*
 	FileVCardCollection vCardCollection(PlatformApplication("Slimber").getSettingsDir());
diff --git a/Slimber/Makefile.inc b/Slimber/Makefile.inc
deleted file mode 100644
index 2821d18..0000000
--- a/Slimber/Makefile.inc
+++ /dev/null
@@ -1,26 +0,0 @@
-SLIMBER_TARGET = Slimber/Slimber.a
-SLIMBER_SOURCES = \
-	Slimber/LinkLocalPresenceManager.cpp \
-	Slimber/FileVCardCollection.cpp \
-	Slimber/VCardCollection.cpp \
-	Slimber/Server.cpp \
-	Slimber/MainController.cpp \
-	Slimber/MenuletController.cpp \
-	Slimber/Menulet.cpp
-SLIMBER_OBJECTS = \
-	$(SLIMBER_SOURCES:.cpp=.o)
-
-DEPS += $(SLIMBER_SOURCES:.cpp=.dep)
-UNITTEST_LIBS += $(SLIMBER_TARGET)
-
-include Slimber/UnitTest/Makefile.inc
-include Slimber/CLI/Makefile.inc
-ifeq ($(MACOSX),1)
-include Slimber/Cocoa/Makefile.inc
-endif
-
-.PHONY: slimber
-slimber: $(SLIMBER_TARGETS)
-
-$(SLIMBER_TARGET): $(SLIMBER_OBJECTS)
-	$(QUIET_AR)$(AR) $(ARFLAGS) $@ $(SLIMBER_OBJECTS)
diff --git a/Slimber/SConscript b/Slimber/SConscript
new file mode 100644
index 0000000..504aa1b
--- /dev/null
+++ b/Slimber/SConscript
@@ -0,0 +1,28 @@
+Import("env")
+
+env["SLIMBER_FLAGS"] = {
+		"LIBPATH": [Dir(".")],
+		"LIBS": ["Slimber"]
+	}
+
+myenv = env.Clone()
+myenv.MergeFlags(env["BOOST_FLAGS"])
+myenv.MergeFlags(env["SWIFTEN_FLAGS"])
+myenv.StaticLibrary("Slimber", [
+    "LinkLocalPresenceManager.cpp",
+    "FileVCardCollection.cpp",
+    "VCardCollection.cpp",
+    "Server.cpp",
+    "MainController.cpp",
+    "MenuletController.cpp",
+    "Menulet.cpp"
+	])
+
+env.Append(UNITTEST_SOURCES = [
+    File("UnitTest/LinkLocalPresenceManagerTest.cpp"),
+    File("UnitTest/MenuletControllerTest.cpp")
+	])
+
+SConscript("CLI/SConscript")
+if env["PLATFORM"] == "darwin" :
+  SConscript("Cocoa/SConscript")
diff --git a/Slimber/UnitTest/Makefile.inc b/Slimber/UnitTest/Makefile.inc
deleted file mode 100644
index 5bc0c8a..0000000
--- a/Slimber/UnitTest/Makefile.inc
+++ /dev/null
@@ -1,3 +0,0 @@
-UNITTEST_SOURCES += \
-	Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp \
-	Slimber/UnitTest/MenuletControllerTest.cpp
diff --git a/Swiften/QA/ClientTest/SConscript b/Swiften/QA/ClientTest/SConscript
index 6da8705..cd48169 100644
--- a/Swiften/QA/ClientTest/SConscript
+++ b/Swiften/QA/ClientTest/SConscript
@@ -17,5 +17,5 @@ for i in ["SWIFT_CLIENTTEST_JID", "SWIFT_CLIENTTEST_PASS"]:
 		myenv["ENV"][i] = os.environ[i]
 
 tester = myenv.Program("ClientTest", ["ClientTest.cpp"])
-clientTest = myenv.Alias("ClientTest", tester, tester[0].abspath)
+clientTest = myenv.Alias("ClientTest", tester, env.get("TEST_RUNNER", "") + tester[0].abspath)
 env.AlwaysBuild(clientTest)
diff --git a/Swiften/QA/NetworkTest/.gitignore b/Swiften/QA/NetworkTest/.gitignore
new file mode 100644
index 0000000..5a3caca
--- /dev/null
+++ b/Swiften/QA/NetworkTest/.gitignore
@@ -0,0 +1 @@
+NetworkTest
diff --git a/Swiften/QA/NetworkTest/SConscript b/Swiften/QA/NetworkTest/SConscript
index f12c28d..606c02e 100644
--- a/Swiften/QA/NetworkTest/SConscript
+++ b/Swiften/QA/NetworkTest/SConscript
@@ -14,5 +14,5 @@ tester = myenv.Program("NetworkTest", [
 		"DomainNameResolverTest.cpp",
 		"#/QA/UnitTest/checker.cpp"
 	])
-clientTest = myenv.Alias("NetworkTest", tester, tester[0].abspath)
+clientTest = myenv.Alias("NetworkTest", tester, env.get("TEST_RUNNER", "") + tester[0].abspath)
 env.AlwaysBuild(clientTest)
diff --git a/Swiften/QA/SConscript b/Swiften/QA/SConscript
index 89d8285..6ee7365 100644
--- a/Swiften/QA/SConscript
+++ b/Swiften/QA/SConscript
@@ -1,9 +1,10 @@
 Import("env")
 
-if "test" in COMMAND_LINE_TARGETS or env.GetOption("clean") :
+tests = ["NetworkTest", "ClientTest"]
+if "test" in COMMAND_LINE_TARGETS or env.GetOption("clean") or len(set(tests) & set(COMMAND_LINE_TARGETS)):
 	SConscript([
 			"NetworkTest/SConscript",
 			"ClientTest/SConscript",
 		])
 
-	test = env.Alias("test", ["NetworkTest", "ClientTest"])
+	test = env.Alias("test", tests)
-- 
cgit v0.10.2-6-g49f6