diff options
author | Dan Goodliffe <daniel.goodliffe@pressassociation.com> | 2014-11-28 10:55:53 +0000 |
---|---|---|
committer | Dan Goodliffe <daniel.goodliffe@pressassociation.com> | 2014-11-28 10:55:53 +0000 |
commit | bf8a25ccb30ef0b2d9af4b0ada8020a7540bde04 (patch) | |
tree | b147362e32293f2d3ba9a570cd79b89f2d6cf263 | |
parent | Sorts out unique paths for tests, fixes test names, adds basics of daemon test (diff) | |
parent | Add a unit test over config variable (diff) | |
download | project2-bf8a25ccb30ef0b2d9af4b0ada8020a7540bde04.tar.bz2 project2-bf8a25ccb30ef0b2d9af4b0ada8020a7540bde04.tar.xz project2-bf8a25ccb30ef0b2d9af4b0ada8020a7540bde04.zip |
Merge remote-tracking branch 'origin/master' into slicer
-rw-r--r-- | project2/common/Jamfile.jam | 4 | ||||
-rw-r--r-- | project2/common/unittests/Jamfile.jam | 9 | ||||
-rw-r--r-- | project2/common/unittests/testConfig.cpp | 18 | ||||
-rw-r--r-- | project2/common/variables/config.cpp | 1 | ||||
-rw-r--r-- | project2/ut/testScriptNode.cpp | 83 | ||||
-rw-r--r-- | project2/ut/testScriptNode.h | 28 |
6 files changed, 142 insertions, 1 deletions
diff --git a/project2/common/Jamfile.jam b/project2/common/Jamfile.jam index 93c9754..6514b1e 100644 --- a/project2/common/Jamfile.jam +++ b/project2/common/Jamfile.jam @@ -7,6 +7,8 @@ lib boost_system : : <name>boost_system ; lib boost_filesystem : : <name>boost_filesystem ; lib boost_date_time : : <name>boost_date_time ; +build-project unittests ; + cpp-pch pch : pch.hpp : <include>../../libmisc <library>../lib//p2lib @@ -15,7 +17,7 @@ cpp-pch pch : pch.hpp : lib p2common : pch - [ glob-tree *.cpp ] + [ glob-tree *.cpp : unittests ] : <include>. <library>glibmm diff --git a/project2/common/unittests/Jamfile.jam b/project2/common/unittests/Jamfile.jam new file mode 100644 index 0000000..540c1e0 --- /dev/null +++ b/project2/common/unittests/Jamfile.jam @@ -0,0 +1,9 @@ +import testing ; + +unit-test testConfig : + testConfig.cpp + : + <library>../../ut//p2ut + <library>..//p2common + ; + diff --git a/project2/common/unittests/testConfig.cpp b/project2/common/unittests/testConfig.cpp new file mode 100644 index 0000000..8c25394 --- /dev/null +++ b/project2/common/unittests/testConfig.cpp @@ -0,0 +1,18 @@ +#define BOOST_TEST_MODULE Config +#include <boost/test/unit_test.hpp> +#include <testOptionsSource.h> +#include <testScriptNode.h> +#include <variables.h> + +BOOST_AUTO_TEST_CASE( config_application_value ) +{ + TestOptionsSource::LoadTestOptions({ + { "application.data", "testvalue" } + }); + Variable::VariableImplPtr c = VariableLoader::createNew("config", new TestScriptNode({ + { "name", VariableType("data") } + })); + BOOST_REQUIRE(c); + BOOST_REQUIRE_EQUAL("testvalue", c->value(NULL).as<std::string>()); +} + diff --git a/project2/common/variables/config.cpp b/project2/common/variables/config.cpp index 9b4cccb..5b36f6e 100644 --- a/project2/common/variables/config.cpp +++ b/project2/common/variables/config.cpp @@ -72,6 +72,7 @@ class VariableConfigLoader : public VariableLoader::For<VariableConfig> { opts("Variables - ModConfig options") { opts(new AppSettings()); + OptionsSets::Add(typeid(AppSettings).name(), &opts); } const Options * options() const { diff --git a/project2/ut/testScriptNode.cpp b/project2/ut/testScriptNode.cpp new file mode 100644 index 0000000..fb54c12 --- /dev/null +++ b/project2/ut/testScriptNode.cpp @@ -0,0 +1,83 @@ +#include "testScriptNode.h" +#include "variables/literal.h" +#include <logger.h> + +TestScriptNode::TestScriptNode(const Vars & v) : + ScriptNode(NULL), + vars(v) +{ +} + +bool TestScriptNode::componentNamespace() const +{ + return false; +} + +std::string TestScriptNode::get_name() const +{ + Logger()->messagebf(LOG_DEBUG, "%s", __PRETTY_FUNCTION__); + return std::string(); +} + +ScriptNodePtr TestScriptNode::child(const Glib::ustring & name, bool required) const +{ + Logger()->messagebf(LOG_DEBUG, "%s", __PRETTY_FUNCTION__); + if (required) { + throw ValueNotFound(name); + } + return NULL; +} + +ScriptNode::ScriptNodes TestScriptNode::children() const +{ + Logger()->messagebf(LOG_DEBUG, "%s", __PRETTY_FUNCTION__); + return ScriptNode::ScriptNodes(); +} + +ScriptNode::ScriptNodes TestScriptNode::childrenIn(const Glib::ustring & sub) const +{ + Logger()->messagebf(LOG_DEBUG, "%s", __PRETTY_FUNCTION__); + (void)sub; + return ScriptNode::ScriptNodes(); +} + +bool TestScriptNode::valueExists(const Glib::ustring & name) const +{ + Logger()->messagebf(LOG_DEBUG, "%s", __PRETTY_FUNCTION__); + return vars.find(name.collate_key()) != vars.end(); +} + +bool TestScriptNode::applyValue(const Glib::ustring & name, VariableType & target, ExecContext *) const +{ + Logger()->messagebf(LOG_DEBUG, "%s: %s", __PRETTY_FUNCTION__, name); + auto i = vars.find(name.collate_key()); + if (i != vars.end()) { + target = i->second; + Logger()->messagebf(LOG_DEBUG, "%s -> %s", __PRETTY_FUNCTION__, target); + return true; + } + return false; +} + +VariableImpl * TestScriptNode::variable(const boost::optional<Glib::ustring> & defaultSource) const +{ + Logger()->messagebf(LOG_DEBUG, "%s: defaultSource = %s", __PRETTY_FUNCTION__, + defaultSource ? *defaultSource : "NULL"); + (void)defaultSource; + return NULL; +} + +VariableImpl * TestScriptNode::variable(const Glib::ustring & name) const +{ + Logger()->messagebf(LOG_DEBUG, "%s: %s", __PRETTY_FUNCTION__, name); + auto i = vars.find(name.collate_key()); + if (i != vars.end()) { + return new VariableLiteral(i->second); + } + throw ValueNotFound(name); +} + +void TestScriptNode::composeWithCallbacks(const LiteralCallback &, const NodeCallback &) const +{ +} + diff --git a/project2/ut/testScriptNode.h b/project2/ut/testScriptNode.h new file mode 100644 index 0000000..d85f6db --- /dev/null +++ b/project2/ut/testScriptNode.h @@ -0,0 +1,28 @@ +#ifndef TESTSCRIPTNODE_H +#define TESTSCRIPTNODE_H + +#include <scripts.h> + +class TestScriptNode : public ScriptNode { + public: + typedef std::map<std::string, VariableType> Vars; + + TestScriptNode(const Vars &); + + bool componentNamespace() const; + std::string get_name() const; + ScriptNodePtr child(const Glib::ustring & name, bool required = true) const; + ScriptNodes children() const; + ScriptNodes childrenIn(const Glib::ustring & sub) const; + bool valueExists(const Glib::ustring & name) const; + bool applyValue(const Glib::ustring & name, VariableType & target, ExecContext *) const; + VariableImpl * variable(const boost::optional<Glib::ustring> & defaultSource = boost::optional<Glib::ustring>()) const; + VariableImpl * variable(const Glib::ustring & name) const; + void composeWithCallbacks(const LiteralCallback &, const NodeCallback &) const; + + private: + Vars vars; +}; + +#endif + |