From 959fa50e4a63daafb938181548e8154beabe9a24 Mon Sep 17 00:00:00 2001 From: randomdan Date: Sat, 8 Nov 2014 19:09:41 +0000 Subject: Assert on attempt to load components of the same name into the same instance store Unit tests over load/unload libraries --- project2/Jamfile.jam | 4 ++++ project2/basics/Jamfile.jam | 4 +++- project2/basics/options/preload.cpp | 1 + project2/basics/unittests/Jamfile.jam | 18 +++++++++++++++++ project2/basics/unittests/dummylib.cpp | 17 +++++++++++++++++ project2/basics/unittests/libraries.cpp | 34 +++++++++++++++++++++++++++++++++ project2/common/instanceStore.impl.h | 3 +++ project2/common/library.h | 2 ++ project2/daemon/p2daemonMain.cpp | 1 + 9 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 project2/basics/unittests/Jamfile.jam create mode 100644 project2/basics/unittests/dummylib.cpp create mode 100644 project2/basics/unittests/libraries.cpp 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 : : boost_filesystem ; lib dl ; +build-project unittests ; + cpp-pch pch : pch.hpp : ../../libmisc glibmm @@ -12,7 +14,7 @@ cpp-pch pch : pch.hpp : ; lib p2basics : - [ glob-tree *.cpp ] + [ glob-tree *.cpp : unittests ] : . ../../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 #include #include +#include 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 + : + ../../common//p2common + ; + +unit-test libraries : + libraries.cpp + : + dummylib + ../../common//p2common + ..//p2basics + ../../ut//p2ut + ..//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 + +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 +#include +#include +#include +#include + +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 +#include template const StoreType & @@ -41,6 +42,7 @@ template void InstanceMap::Add(const KeyType & k, Type * p) { + BOOST_ASSERT(IStore::getInstances()->find(k) == IStore::getInstances()->end()); IStore::Add(Value(k, boost::shared_ptr(p))); } @@ -48,6 +50,7 @@ template void InstanceMap::Add(const KeyType & k, const boost::shared_ptr & 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 #include +#include SimpleMessageException(UnsupportedArguments); -- cgit v1.2.3