diff options
-rw-r--r-- | project2/ice/unittests/expected/clientPresenter.log | 29 | ||||
-rw-r--r-- | project2/ice/unittests/testClient.cpp | 14 | ||||
-rw-r--r-- | project2/ut/testScriptHost.cpp | 87 | ||||
-rw-r--r-- | project2/ut/testScriptHost.h | 13 |
4 files changed, 108 insertions, 35 deletions
diff --git a/project2/ice/unittests/expected/clientPresenter.log b/project2/ice/unittests/expected/clientPresenter.log new file mode 100644 index 0000000..cda61fc --- /dev/null +++ b/project2/ice/unittests/expected/clientPresenter.log @@ -0,0 +1,29 @@ +init +addNewRowSet: somerows +addNewArray: rec(1) +addNewRow: rec +addNamedValue: a=1 +addNamedValue: b=test a +finishRow +addNewRow: rec +addNamedValue: a=2 +addNamedValue: b=test b +finishRow +finishArray: (1) +finishRowSet +addNewRowSet: somerowsparams +addNewArray: rec(1) +addNewRow: rec +addNamedValue: a=0 +addNamedValue: b=before +finishRow +addNewRow: rec +addNamedValue: a=2 +addNamedValue: b=second +finishRow +addNewRow: rec +addNamedValue: a=2 +addNamedValue: b=after +finishRow +finishArray: (1) +finishRowSet diff --git a/project2/ice/unittests/testClient.cpp b/project2/ice/unittests/testClient.cpp index ee87f1b..bade1b2 100644 --- a/project2/ice/unittests/testClient.cpp +++ b/project2/ice/unittests/testClient.cpp @@ -26,14 +26,21 @@ class Dummy : public UnitTest::SimpleInterface { UnitTest::Simples SomeRows(const Ice::Current&) { - UnitTest::Simples rtn; + UnitTest::Simples rtn { + new UnitTest::Simple { 1, "test a" }, + new UnitTest::Simple { 2, "test b" } + }; execCount += 1; return rtn; } - UnitTest::Simples SomeRowsParams(Ice::Int, const std::string&, const Ice::Current&) + UnitTest::Simples SomeRowsParams(Ice::Int pi, const std::string & ps, const Ice::Current&) { - UnitTest::Simples rtn; + UnitTest::Simples rtn { + new UnitTest::Simple { 0, "before" }, + new UnitTest::Simple { pi, ps }, + new UnitTest::Simple { 2, "after" } + }; execCount += 1; return rtn; } @@ -79,6 +86,7 @@ commonTests() BOOST_REQUIRE_EQUAL(dummy->execCount, 0); sr->process(NULL); BOOST_REQUIRE_EQUAL(dummy->execCount, 4); + BOOST_REQUIRE_EQUAL(sr->GetPresenterData(), iceroot / "expected" / "clientPresenter.log"); } static diff --git a/project2/ut/testScriptHost.cpp b/project2/ut/testScriptHost.cpp index 1161ba6..dfdb6ed 100644 --- a/project2/ut/testScriptHost.cpp +++ b/project2/ut/testScriptHost.cpp @@ -2,6 +2,7 @@ #include <glibmm/exception.h> #include <cxxabi.h> #include <logger.h> +#include <fstream> TestScriptHost::TestScriptHost(ScriptReaderPtr script) : SourceObject(script->root()), @@ -26,82 +27,104 @@ MultiRowSetPresenterPtr TestScriptHost::getPresenter(ExecContext *) const void TestScriptHost::process(ExecContext * ec) { - Logger()->messagef(LOG_DEBUG, "> %s", __PRETTY_FUNCTION__); - try { - runChecks(ec); - execute(ec); - executeViews(ec); - } - catch (const std::exception & e) { - char * buf = __cxxabiv1::__cxa_demangle(typeid(e).name(), NULL, NULL, NULL); - Logger()->messagef(LOG_ERR, "%s: Script errored: %s: %s", __FUNCTION__, buf, e.what()); - free(buf); - throw; - } - catch (const Glib::Exception & e) { - char * buf = __cxxabiv1::__cxa_demangle(typeid(e).name(), NULL, NULL, NULL); - Logger()->messagebf(LOG_ERR, "%s: Script errored: %s: %s", __FUNCTION__, buf, e.what()); - free(buf); - throw; - } - catch (...) { - Logger()->messagebf(LOG_ERR, "%s: Script errored (nobody knows why!)", __FUNCTION__); - throw; - } - Logger()->messagef(LOG_DEBUG, "< %s", __PRETTY_FUNCTION__); + runChecks(ec); + execute(ec); + executeViews(ec); } void TestScriptHost::addNamedValue(const Glib::ustring & name, const VariableType & value) const { - (void)name; - (void)value; + presenterData.push_back(stringbf("%s: %s=%s", __FUNCTION__, name, value)); } void TestScriptHost::addNewRow(const Glib::ustring & name) const { - (void)name; + 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 { - (void)name; + presenterData.push_back(stringbf("%s: %s", __FUNCTION__, name)); } void TestScriptHost::addNewRowSet(const Glib::ustring & name, const Glib::ustring & ns) const { - (void)name; - (void)ns; + 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 { - (void)name; - (void)objects; + presenterData.push_back(stringbf("%s: %s(%s)", __FUNCTION__, name, objects)); } void TestScriptHost::finishArray(bool objects) const { - (void)objects; + 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.eof()) { + v.push_back(buf); + } + else { + break; + } + } + return s; + } + + std::ostream & + operator<<(std::ostream & s, const PresenterData & v) + { + BOOST_FOREACH(const auto & e, v) { + s << "[" << e << "]" << std::endl; + } + return s; + } + + bool + operator==(const PresenterData & left, const boost::filesystem::path & rightPath) + { + PresenterData right; + fstream strm(rightPath.string()); + strm >> right; + return (left == right); + } } diff --git a/project2/ut/testScriptHost.h b/project2/ut/testScriptHost.h index 43dcd90..a843a4a 100644 --- a/project2/ut/testScriptHost.h +++ b/project2/ut/testScriptHost.h @@ -4,6 +4,9 @@ #include <taskHost.h> #include <viewHost.h> #include <presenter.h> +#include <boost/filesystem/path.hpp> + +typedef std::vector<std::string> PresenterData; class TestScriptHost : public TaskHost, public ViewHost, public MultiRowSetPresenter { public: @@ -22,8 +25,18 @@ class TestScriptHost : public TaskHost, public ViewHost, public MultiRowSetPrese 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 |