summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-05-19 21:19:50 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-05-19 21:19:50 +0100
commit4efe7293b698f3eb413651a59c89dd5e31e9d0a3 (patch)
tree099dd8fc7ae7a80bbdb6ae7196593081c50eea56
parentPersist a table containing some environmental things during mock setup (diff)
downloadproject2-4efe7293b698f3eb413651a59c89dd5e31e9d0a3.tar.bz2
project2-4efe7293b698f3eb413651a59c89dd5e31e9d0a3.tar.xz
project2-4efe7293b698f3eb413651a59c89dd5e31e9d0a3.zip
Split test presenter into its own class, not rolled into the script host
-rw-r--r--project2/ut/testPresenter.cpp109
-rw-r--r--project2/ut/testPresenter.h38
-rw-r--r--project2/ut/testScriptHost.cpp106
-rw-r--r--project2/ut/testScriptHost.h24
4 files changed, 159 insertions, 118 deletions
diff --git a/project2/ut/testPresenter.cpp b/project2/ut/testPresenter.cpp
new file mode 100644
index 0000000..e93d7aa
--- /dev/null
+++ b/project2/ut/testPresenter.cpp
@@ -0,0 +1,109 @@
+#include "testPresenter.h"
+#include "misc.h"
+#include <boost/filesystem/operations.hpp>
+#include <boost/test/test_tools.hpp>
+#include <fstream>
+#include <boost/format.hpp>
+
+TestPresenter::TestPresenter() :
+ MultiRowSetPresenter(Default)
+{
+}
+
+void
+TestPresenter::addNamedValue(const Glib::ustring & name, const VariableType & value) const
+{
+ presenterData.push_back(stringbf("%s: %s=%s", __FUNCTION__, name, value));
+}
+
+void
+TestPresenter::addNewRow(const Glib::ustring & name) const
+{
+ presenterData.push_back(stringbf("%s: %s", __FUNCTION__, name));
+}
+
+void
+TestPresenter::finishRow() const
+{
+ presenterData.push_back(stringbf("%s", __FUNCTION__));
+}
+
+void
+TestPresenter::addNewRowSet(const Glib::ustring & name) const
+{
+ presenterData.push_back(stringbf("%s: %s", __FUNCTION__, name));
+}
+
+void
+TestPresenter::addNewRowSet(const Glib::ustring & name, const Glib::ustring & ns) const
+{
+ presenterData.push_back(stringbf("%s: %s:%s", __FUNCTION__, ns, name));
+}
+
+void
+TestPresenter::finishRowSet() const
+{
+ presenterData.push_back(stringbf("%s", __FUNCTION__));
+}
+
+void
+TestPresenter::addNewArray(const Glib::ustring & name, bool objects) const
+{
+ presenterData.push_back(stringbf("%s: %s(%s)", __FUNCTION__, name, objects));
+}
+
+void
+TestPresenter::finishArray(bool objects) const
+{
+ presenterData.push_back(stringbf("%s: (%s)", __FUNCTION__, objects));
+}
+
+void
+TestPresenter::init(ExecContext *)
+{
+ presenterData.push_back(stringbf("%s", __FUNCTION__));
+}
+
+const PresenterData &
+TestPresenter::GetPresenterData() const
+{
+ return presenterData;
+}
+
+namespace std {
+ std::istream &
+ operator>>(std::istream & s, PresenterData & v)
+ {
+ while (true) {
+ char buf[BUFSIZ];
+ s.getline(buf, sizeof(buf));
+ if (s.good()) {
+ v.push_back(buf);
+ }
+ else {
+ break;
+ }
+ }
+ return s;
+ }
+
+ std::ostream &
+ operator<<(std::ostream & s, const PresenterData & v)
+ {
+ for (const auto & e : v) {
+ s << "[" << e << "]" << std::endl;
+ }
+ return s;
+ }
+
+ bool
+ operator==(const PresenterData & left, const boost::filesystem::path & rightPath)
+ {
+ PresenterData right;
+ BOOST_REQUIRE(boost::filesystem::exists(rightPath));
+ fstream strm(rightPath.string());
+ strm >> right;
+ return (left == right);
+ }
+}
+
diff --git a/project2/ut/testPresenter.h b/project2/ut/testPresenter.h
new file mode 100644
index 0000000..a6772ea
--- /dev/null
+++ b/project2/ut/testPresenter.h
@@ -0,0 +1,38 @@
+#ifndef TESTPRESENTER_H
+#define TESTPRESENTER_H
+
+#include <string>
+#include <vector>
+#include <boost/filesystem/path.hpp>
+#include <presenter.h>
+
+typedef std::vector<std::string> PresenterData;
+
+class TestPresenter : public MultiRowSetPresenter {
+ public:
+ TestPresenter();
+
+ void addNamedValue(const Glib::ustring & name, const VariableType & value) const override;
+ void addNewRow(const Glib::ustring & name) const override;
+ void finishRow() const override;
+ void addNewRowSet(const Glib::ustring & name) const override;
+ void addNewRowSet(const Glib::ustring & name, const Glib::ustring & ns) const override;
+ void finishRowSet() const override;
+ void addNewArray(const Glib::ustring & name, bool objects) const override;
+ void finishArray(bool objects) const override;
+ void init(ExecContext *) override;
+
+ const PresenterData & GetPresenterData() const;
+
+ private:
+ mutable PresenterData presenterData;
+};
+
+namespace std {
+ bool operator==(const PresenterData &, const boost::filesystem::path &);
+ std::ostream & operator<<(std::ostream & s, const PresenterData & v);
+ std::istream & operator>>(std::istream & s, PresenterData & v);
+}
+
+#endif
+
diff --git a/project2/ut/testScriptHost.cpp b/project2/ut/testScriptHost.cpp
index 7d456b9..69ee39b 100644
--- a/project2/ut/testScriptHost.cpp
+++ b/project2/ut/testScriptHost.cpp
@@ -1,18 +1,14 @@
#include "testScriptHost.h"
-#include <boost/test/test_tools.hpp>
-#include <boost/filesystem/operations.hpp>
#include <glibmm/exception.h>
#include <cxxabi.h>
#include <logger.h>
-#include <fstream>
TestScriptHost::TestScriptHost(ScriptReaderPtr script) :
SourceObject(script->root()),
CommonObjects(script->root()),
CheckHost(script->root()),
TaskHost(script->root()),
- ViewHost(script->root()),
- MultiRowSetPresenter(Default)
+ ViewHost(script->root())
{
Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
}
@@ -24,7 +20,10 @@ TestScriptHost::~TestScriptHost()
MultiRowSetPresenterPtr TestScriptHost::getPresenter(ExecContext *) const
{
- return const_cast<TestScriptHost *>(this);
+ if (!presenter) {
+ presenter = new TestPresenter();
+ }
+ return presenter;
}
void TestScriptHost::process(ExecContext * ec)
@@ -34,100 +33,13 @@ void TestScriptHost::process(ExecContext * ec)
executeViews(ec);
}
-void
-TestScriptHost::addNamedValue(const Glib::ustring & name, const VariableType & value) const
-{
- presenterData.push_back(stringbf("%s: %s=%s", __FUNCTION__, name, value));
-}
-
-void
-TestScriptHost::addNewRow(const Glib::ustring & name) const
-{
- presenterData.push_back(stringbf("%s: %s", __FUNCTION__, name));
-}
-
-void
-TestScriptHost::finishRow() const
-{
- presenterData.push_back(stringbf("%s", __FUNCTION__));
-}
-
-void
-TestScriptHost::addNewRowSet(const Glib::ustring & name) const
-{
- presenterData.push_back(stringbf("%s: %s", __FUNCTION__, name));
-}
-
-void
-TestScriptHost::addNewRowSet(const Glib::ustring & name, const Glib::ustring & ns) const
-{
- presenterData.push_back(stringbf("%s: %s:%s", __FUNCTION__, ns, name));
-}
-
-void
-TestScriptHost::finishRowSet() const
-{
- presenterData.push_back(stringbf("%s", __FUNCTION__));
-}
-
-void
-TestScriptHost::addNewArray(const Glib::ustring & name, bool objects) const
-{
- presenterData.push_back(stringbf("%s: %s(%s)", __FUNCTION__, name, objects));
-}
-
-void
-TestScriptHost::finishArray(bool objects) const
-{
- presenterData.push_back(stringbf("%s: (%s)", __FUNCTION__, objects));
-}
-
-void
-TestScriptHost::init(ExecContext *)
-{
- presenterData.push_back(stringbf("%s", __FUNCTION__));
-}
-
const PresenterData &
TestScriptHost::GetPresenterData() const
{
- return presenterData;
-}
-
-namespace std {
- std::istream &
- operator>>(std::istream & s, PresenterData & v)
- {
- while (true) {
- char buf[BUFSIZ];
- s.getline(buf, sizeof(buf));
- if (s.good()) {
- v.push_back(buf);
- }
- else {
- break;
- }
- }
- return s;
- }
-
- std::ostream &
- operator<<(std::ostream & s, const PresenterData & v)
- {
- for (const auto & e : v) {
- s << "[" << e << "]" << std::endl;
- }
- return s;
- }
-
- bool
- operator==(const PresenterData & left, const boost::filesystem::path & rightPath)
- {
- PresenterData right;
- BOOST_REQUIRE(boost::filesystem::exists(rightPath));
- fstream strm(rightPath.string());
- strm >> right;
- return (left == right);
+ auto tp = boost::dynamic_pointer_cast<TestPresenter>(presenter);
+ if (!tp) {
+ throw std::runtime_error("Not using the TestPresenter");
}
+ return tp->GetPresenterData();
}
diff --git a/project2/ut/testScriptHost.h b/project2/ut/testScriptHost.h
index a843a4a..c838f9c 100644
--- a/project2/ut/testScriptHost.h
+++ b/project2/ut/testScriptHost.h
@@ -3,12 +3,9 @@
#include <taskHost.h>
#include <viewHost.h>
-#include <presenter.h>
-#include <boost/filesystem/path.hpp>
+#include "testPresenter.h"
-typedef std::vector<std::string> PresenterData;
-
-class TestScriptHost : public TaskHost, public ViewHost, public MultiRowSetPresenter {
+class TestScriptHost : public TaskHost, public ViewHost {
public:
TestScriptHost(ScriptReaderPtr script);
~TestScriptHost();
@@ -16,27 +13,12 @@ class TestScriptHost : public TaskHost, public ViewHost, public MultiRowSetPrese
MultiRowSetPresenterPtr getPresenter(ExecContext *) const override;
void process(ExecContext * ec);
- void addNamedValue(const Glib::ustring & name, const VariableType & value) const override;
- void addNewRow(const Glib::ustring & name) const override;
- void finishRow() const override;
- void addNewRowSet(const Glib::ustring & name) const override;
- void addNewRowSet(const Glib::ustring & name, const Glib::ustring & ns) const override;
- void finishRowSet() const override;
- void addNewArray(const Glib::ustring & name, bool objects) const override;
- void finishArray(bool objects) const override;
- void init(ExecContext *) override;
const PresenterData & GetPresenterData() const;
private:
- mutable PresenterData presenterData;
+ mutable MultiRowSetPresenterPtr presenter;
};
-namespace std {
- bool operator==(const PresenterData &, const boost::filesystem::path &);
- std::ostream & operator<<(std::ostream & s, const PresenterData & v);
- std::istream & operator>>(std::istream & s, PresenterData & v);
-}
-
#endif