summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2014-11-04 20:42:34 +0000
committerrandomdan <randomdan@localhost>2014-11-04 20:42:34 +0000
commit65bb386107c535d639e5aa9de60d7cc6fbbdd39f (patch)
tree0ce1167fcbc52e7668d0bbc49879a7818ecb69be
parentSwitch to external jsonpp library (diff)
downloadproject2-65bb386107c535d639e5aa9de60d7cc6fbbdd39f.tar.bz2
project2-65bb386107c535d639e5aa9de60d7cc6fbbdd39f.tar.xz
project2-65bb386107c535d639e5aa9de60d7cc6fbbdd39f.zip
Add beginnings of UT toolkit and a few tiny UTs over the ice client/compiler
-rw-r--r--project2/common/optionsSource.cpp12
-rw-r--r--project2/common/optionsSource.h5
-rw-r--r--project2/common/plugable.cpp8
-rw-r--r--project2/common/plugable.h2
-rw-r--r--project2/daemon/p2daemonAppEngine.cpp2
-rw-r--r--project2/ice/Jamfile.jam24
-rw-r--r--project2/ice/test.ice9
-rw-r--r--project2/ice/testClient.cpp32
-rw-r--r--project2/ut/Jamfile.jam12
-rw-r--r--project2/ut/testOptionsSource.cpp30
-rw-r--r--project2/ut/testOptionsSource.h22
11 files changed, 155 insertions, 3 deletions
diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp
index 58c9b1f..85aebb1 100644
--- a/project2/common/optionsSource.cpp
+++ b/project2/common/optionsSource.cpp
@@ -43,5 +43,17 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform)
}
}
+void
+OptionsSource::loadSource(const Options::CurrentPlatform & platform, OptionsSourcePtr opts)
+{
+ InstanceSet<Options>::OnAll(boost::bind(&Options::reset, _1));
+
+ DefaultConfigConsumer dcc;
+ opts->loadInto(dcc, platform);
+ Plugable::onAllComponents(boost::bind(&ComponentLoader::onConfigLoad, _1));
+
+ Logger()->message(LOG_DEBUG, "Loaded configuration");
+}
+
INSTANTIATESTORE(std::string, OptionsSource);
diff --git a/project2/common/optionsSource.h b/project2/common/optionsSource.h
index 97a3566..6cfbce9 100644
--- a/project2/common/optionsSource.h
+++ b/project2/common/optionsSource.h
@@ -13,6 +13,9 @@ class ConfigConsumer {
virtual const Options::Option * get(const Glib::ustring & name) const = 0;
};
+class OptionsSource;
+typedef boost::shared_ptr<OptionsSource> OptionsSourcePtr;
+
/// Base class of things that load options
class OptionsSource {
public:
@@ -20,8 +23,8 @@ class OptionsSource {
virtual bool needReload() const = 0;
static void loadSources(const Options::CurrentPlatform & platform);
+ static void loadSource(const Options::CurrentPlatform & platform, OptionsSourcePtr opts);
};
-typedef boost::intrusive_ptr<OptionsSource> OptionsSourcePtr;
typedef PluginsSameBase<OptionsSource, std::string> OptionsSources;
#define DECLARE_OPTIONSSOURCE(Id, Inst) \
diff --git a/project2/common/plugable.cpp b/project2/common/plugable.cpp
new file mode 100644
index 0000000..83d0cc5
--- /dev/null
+++ b/project2/common/plugable.cpp
@@ -0,0 +1,8 @@
+#include "plugable.h"
+
+void
+Plugable::onAllComponents(const boost::function<void(ComponentLoader *)> & func, bool coe)
+{
+ InstanceSet<ComponentLoader>::OnAll(func, coe);
+}
+
diff --git a/project2/common/plugable.h b/project2/common/plugable.h
index af7f91f..ce3439a 100644
--- a/project2/common/plugable.h
+++ b/project2/common/plugable.h
@@ -10,7 +10,7 @@ class ComponentLoader;
class Plugable : public InstanceSet<ComponentLoader> {
public:
- static void onAllComponents(const boost::function<void(ComponentLoader *)> & func) { InstanceSet<ComponentLoader>::OnAll(func, true); }
+ static void onAllComponents(const boost::function<void(ComponentLoader *)> & func, bool coe = false);
};
/// All loaders, keyed by string, enum, int, etc
diff --git a/project2/daemon/p2daemonAppEngine.cpp b/project2/daemon/p2daemonAppEngine.cpp
index b48b75b..7a1c602 100644
--- a/project2/daemon/p2daemonAppEngine.cpp
+++ b/project2/daemon/p2daemonAppEngine.cpp
@@ -120,7 +120,7 @@ bool
DaemonAppEngine::periodicCallback()
{
Logger()->messagebf(LOG_DEBUG, "%s: firing component periodics.", __PRETTY_FUNCTION__);
- Plugable::onAllComponents(boost::bind(&ComponentLoader::onPeriodic, _1));
+ Plugable::onAllComponents(boost::bind(&ComponentLoader::onPeriodic, _1), true);
return true;
}
diff --git a/project2/ice/Jamfile.jam b/project2/ice/Jamfile.jam
index 1376c34..d6cf16f 100644
--- a/project2/ice/Jamfile.jam
+++ b/project2/ice/Jamfile.jam
@@ -1,3 +1,5 @@
+import testing ;
+
alias glibmm : : : :
<cflags>"`pkg-config --cflags glibmm-2.4`"
<linkflags>"`pkg-config --libs glibmm-2.4`"
@@ -33,6 +35,7 @@ lib p2iceclient :
<library>pthread
: :
<library>p2ice
+ <library>../common//p2common
;
lib p2icedaemon :
@@ -68,3 +71,24 @@ lib p2ice :
<library>IceUtil
<library>boost_filesystem
;
+
+lib test :
+ test.ice
+ :
+ <library>Ice
+ <library>IceUtil
+ <library>pthread
+ ;
+
+unit-test testClient :
+ [ glob testClient.cpp ]
+ :
+ <dependency>test.ice
+ <library>p2iceclient
+ <library>../ut//p2ut
+ <library>../basics//p2basics
+ <library>Ice
+ <library>IceUtil
+ <library>boost_filesystem
+ ;
+
diff --git a/project2/ice/test.ice b/project2/ice/test.ice
new file mode 100644
index 0000000..3c18999
--- /dev/null
+++ b/project2/ice/test.ice
@@ -0,0 +1,9 @@
+module test {
+ interface a
+ {
+ ["project2:task"]
+ void someTask();
+
+ };
+};
+
diff --git a/project2/ice/testClient.cpp b/project2/ice/testClient.cpp
new file mode 100644
index 0000000..d7256ae
--- /dev/null
+++ b/project2/ice/testClient.cpp
@@ -0,0 +1,32 @@
+#define BOOST_TEST_MODULE Client
+#include <boost/test/unit_test.hpp>
+#include <boost/filesystem/operations.hpp>
+#include "iceClient.h"
+#include <testOptionsSource.h>
+
+const auto self = boost::filesystem::canonical("/proc/self/exe");
+const Glib::ustring testPlatform;
+
+BOOST_AUTO_TEST_CASE( compile_client_full )
+{
+ const std::string tmpdir = "/tmp/ut/project2.slice/full";
+ boost::filesystem::remove_all(tmpdir);
+
+ TestOptionsSource::LoadTestOptions({
+ { "ice.compile.tmpdir", tmpdir },
+ { "ice.client.slice", "test.ice" }
+ });
+}
+
+BOOST_AUTO_TEST_CASE( compile_client_clientOnly )
+{
+ const std::string tmpdir = "/tmp/ut/project2.slice/clientOnly";
+ boost::filesystem::remove_all(tmpdir);
+
+ TestOptionsSource::LoadTestOptions({
+ { "library", (self.parent_path() / "libtest.so").string() },
+ { "ice.compile.tmpdir", tmpdir },
+ { "ice.client.sliceclient", "test.ice" }
+ });
+}
+
diff --git a/project2/ut/Jamfile.jam b/project2/ut/Jamfile.jam
new file mode 100644
index 0000000..0c7aa08
--- /dev/null
+++ b/project2/ut/Jamfile.jam
@@ -0,0 +1,12 @@
+lib boost_utf : : <name>boost_unit_test_framework ;
+
+lib p2ut :
+ [ glob *.cpp ]
+ :
+ <library>../common//p2common
+ : :
+ <define>BOOST_TEST_DYN_LINK
+ <library>boost_utf
+ <include>.
+ ;
+
diff --git a/project2/ut/testOptionsSource.cpp b/project2/ut/testOptionsSource.cpp
new file mode 100644
index 0000000..59dc882
--- /dev/null
+++ b/project2/ut/testOptionsSource.cpp
@@ -0,0 +1,30 @@
+#include "testOptionsSource.h"
+
+const Glib::ustring testPlatform;
+
+TestOptionsSource::TestOptionsSource(const Opts & o) :
+ opts(o)
+{
+}
+
+void
+TestOptionsSource::loadInto(const ConfigConsumer & consume, const Options::CurrentPlatform & platform) const
+{
+ BOOST_FOREACH(const auto & opt, opts) {
+ consume(opt.first, testPlatform, opt.second, platform);
+ }
+}
+
+bool
+TestOptionsSource::needReload() const
+{
+ return true;
+}
+
+void
+TestOptionsSource::LoadTestOptions(const Opts & o)
+{
+ OptionsSource::loadSource(boost::bind<const Glib::ustring &>([]{ return testPlatform; }),
+ OptionsSourcePtr(new TestOptionsSource(o)));
+}
+
diff --git a/project2/ut/testOptionsSource.h b/project2/ut/testOptionsSource.h
new file mode 100644
index 0000000..9bc2101
--- /dev/null
+++ b/project2/ut/testOptionsSource.h
@@ -0,0 +1,22 @@
+#ifndef P2_TEST_OPTIONSSOURCE_H
+#define P2_TEST_OPTIONSSOURCE_H
+
+#include <optionsSource.h>
+
+class TestOptionsSource : public OptionsSource {
+ public:
+ typedef std::list<std::pair<std::string, std::string>> Opts;
+
+ void loadInto(const ConfigConsumer & consume, const Options::CurrentPlatform & platform) const override;
+ bool needReload() const override;
+
+ static void LoadTestOptions(const Opts & o);
+
+ private:
+ TestOptionsSource(const Opts & o);
+
+ const Opts opts;
+};
+
+#endif
+