summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2014-11-08 19:09:41 +0000
committerrandomdan <randomdan@localhost>2014-11-08 19:09:41 +0000
commit613cfdf62fac50366e98a272a9e7d80cd3ff0bae (patch)
treebcba157675dc1b331ce0f967172b7a3edb7a57aa
parentAdd a Boost UTF Project2 logger (diff)
downloadproject2-613cfdf62fac50366e98a272a9e7d80cd3ff0bae.tar.bz2
project2-613cfdf62fac50366e98a272a9e7d80cd3ff0bae.tar.xz
project2-613cfdf62fac50366e98a272a9e7d80cd3ff0bae.zip
Assert on attempt to load components of the same name into the same instance store
Unit tests over load/unload libraries
-rw-r--r--project2/Jamfile.jam4
-rw-r--r--project2/basics/Jamfile.jam4
-rw-r--r--project2/basics/options/preload.cpp1
-rw-r--r--project2/basics/unittests/Jamfile.jam18
-rw-r--r--project2/basics/unittests/dummylib.cpp17
-rw-r--r--project2/basics/unittests/libraries.cpp34
-rw-r--r--project2/common/instanceStore.impl.h3
-rw-r--r--project2/common/library.h2
-rw-r--r--project2/daemon/p2daemonMain.cpp1
9 files changed, 83 insertions, 1 deletions
diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam
index 2aca8d7..8b17299 100644
--- a/project2/Jamfile.jam
+++ b/project2/Jamfile.jam
@@ -29,6 +29,10 @@ build-project console ;
build-project cgi ;
build-project daemon ;
+# Ensure tests are run (final targets don't reference projects, but specific libraries)
+build-project basics//unittests ;
+build-project ice//tests ;
+
explicit install installp2con installp2cgi installp2fcgi ;
package.install install : : console//p2console cgi//p2cgi cgi//p2fcgi daemon//p2daemon ;
package.install installp2con : : console//p2console ;
diff --git a/project2/basics/Jamfile.jam b/project2/basics/Jamfile.jam
index d64a617..19726d9 100644
--- a/project2/basics/Jamfile.jam
+++ b/project2/basics/Jamfile.jam
@@ -5,6 +5,8 @@ alias glibmm : : : :
lib boost_filesystem : : <name>boost_filesystem ;
lib dl ;
+build-project unittests ;
+
cpp-pch pch : pch.hpp :
<include>../../libmisc
<library>glibmm
@@ -12,7 +14,7 @@ cpp-pch pch : pch.hpp :
;
lib p2basics :
- [ glob-tree *.cpp ]
+ [ glob-tree *.cpp : unittests ]
:
<include>.
<include>../../libmisc
diff --git a/project2/basics/options/preload.cpp b/project2/basics/options/preload.cpp
index 03f275b..006391d 100644
--- a/project2/basics/options/preload.cpp
+++ b/project2/basics/options/preload.cpp
@@ -4,6 +4,7 @@
#include <boost/filesystem/path.hpp>
#include <map>
#include <dlfcn.h>
+#include <logger.h>
using namespace boost::filesystem;
diff --git a/project2/basics/unittests/Jamfile.jam b/project2/basics/unittests/Jamfile.jam
new file mode 100644
index 0000000..253cff5
--- /dev/null
+++ b/project2/basics/unittests/Jamfile.jam
@@ -0,0 +1,18 @@
+import testing ;
+
+lib dummylib :
+ dummylib.cpp
+ :
+ <library>../../common//p2common
+ ;
+
+unit-test libraries :
+ libraries.cpp
+ :
+ <dependency>dummylib
+ <library>../../common//p2common
+ <library>..//p2basics
+ <library>../../ut//p2ut
+ <library>..//boost_filesystem
+ ;
+
diff --git a/project2/basics/unittests/dummylib.cpp b/project2/basics/unittests/dummylib.cpp
new file mode 100644
index 0000000..2e919a0
--- /dev/null
+++ b/project2/basics/unittests/dummylib.cpp
@@ -0,0 +1,17 @@
+#include <task.h>
+
+class DummyTask : public Task {
+ public:
+ DummyTask(ScriptNodePtr p) :
+ SourceObject(p),
+ Task(p)
+ {
+ }
+
+ void execute(ExecContext *) const
+ {
+ }
+
+};
+DECLARE_LOADER("DummyTask", DummyTask);
+
diff --git a/project2/basics/unittests/libraries.cpp b/project2/basics/unittests/libraries.cpp
new file mode 100644
index 0000000..c7aac5a
--- /dev/null
+++ b/project2/basics/unittests/libraries.cpp
@@ -0,0 +1,34 @@
+#define BOOST_TEST_MODULE Client
+#include <boost/test/unit_test.hpp>
+#include <boost/filesystem/convenience.hpp>
+#include <testOptionsSource.h>
+#include <exceptions.h>
+#include <library.h>
+
+const auto self = boost::filesystem::canonical("/proc/self/exe");
+
+BOOST_AUTO_TEST_CASE( load_missing_library )
+{
+ BOOST_TEST_CHECKPOINT("Configure (load)");
+ BOOST_REQUIRE_THROW(
+ TestOptionsSource::LoadTestOptions({
+ { "library", (self.parent_path() / "nosuchlibrary.so").string() }
+ }), LoadLibraryFailed);
+}
+
+BOOST_AUTO_TEST_CASE( load_and_unload_library )
+{
+ BOOST_REQUIRE_THROW(ElementLoader::getFor("DummyTask"), NotSupported);
+
+ BOOST_TEST_CHECKPOINT("Configure (load)");
+ TestOptionsSource::LoadTestOptions({
+ { "library", (self.parent_path() / "libdummylib.so").string() }
+ });
+ BOOST_TEST_CHECKPOINT("Verify");
+ BOOST_REQUIRE(ElementLoader::getFor("DummyTask"));
+
+ BOOST_TEST_CHECKPOINT("Configure (empty)");
+ TestOptionsSource::LoadTestOptions({ });
+ BOOST_REQUIRE_THROW(ElementLoader::getFor("DummyTask"), NotSupported);
+}
+
diff --git a/project2/common/instanceStore.impl.h b/project2/common/instanceStore.impl.h
index f626d47..4152aba 100644
--- a/project2/common/instanceStore.impl.h
+++ b/project2/common/instanceStore.impl.h
@@ -1,5 +1,6 @@
#include "instanceStore.h"
#include <boost/foreach.hpp>
+#include <boost/assert.hpp>
template <class Type, class StoreType>
const StoreType &
@@ -41,6 +42,7 @@ template <class Type, class KeyType>
void
InstanceMap<Type, KeyType>::Add(const KeyType & k, Type * p)
{
+ BOOST_ASSERT(IStore::getInstances()->find(k) == IStore::getInstances()->end());
IStore::Add(Value(k, boost::shared_ptr<Type>(p)));
}
@@ -48,6 +50,7 @@ template <class Type, class KeyType>
void
InstanceMap<Type, KeyType>::Add(const KeyType & k, const boost::shared_ptr<Type> & p)
{
+ BOOST_ASSERT(IStore::getInstances()->find(k) == IStore::getInstances()->end());
IStore::Add(Value(k, p));
}
diff --git a/project2/common/library.h b/project2/common/library.h
index 7db730b..da7a43a 100644
--- a/project2/common/library.h
+++ b/project2/common/library.h
@@ -3,6 +3,8 @@
#include "scriptLoader.h"
#include "exceptions.h"
+#include "scriptStorage.h"
+#include "variables.h"
SimpleMessage2Exception(LoadLibraryFailed);
SimpleMessage2Exception(UnloadLibraryFailed);
diff --git a/project2/daemon/p2daemonMain.cpp b/project2/daemon/p2daemonMain.cpp
index 98dc7ac..8feada2 100644
--- a/project2/daemon/p2daemonMain.cpp
+++ b/project2/daemon/p2daemonMain.cpp
@@ -4,6 +4,7 @@
#include "claOptions.h"
#include <boost/bind.hpp>
#include <options.h>
+#include <logger.h>
SimpleMessageException(UnsupportedArguments);