From c8820d9e144275c36a0b45ac82f7665b48960165 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 21 Dec 2014 17:32:12 +0000 Subject: Allow specifying no columns in row view and covering tests --- project2/basics/unittests/Jamfile.jam | 13 +++++++ project2/basics/unittests/data/unittest-data.xml | 24 +++++++++++++ .../unittests/expected/test_rowview_columns.log | 17 +++++++++ .../unittests/expected/test_rowview_nocolumns.log | 13 +++++++ .../expected/test_rowview_unsetcolumns.log | 21 ++++++++++++ project2/basics/unittests/lib/testrows.xml | 32 +++++++++++++++++ project2/basics/unittests/testViews.cpp | 40 ++++++++++++++++++++++ project2/basics/unittests/test_rowview_columns.xml | 9 +++++ .../basics/unittests/test_rowview_nocolumns.xml | 7 ++++ .../basics/unittests/test_rowview_unsetcolumns.xml | 5 +++ project2/basics/views/rowView.cpp | 12 ++++--- project2/basics/views/rowView.h | 4 ++- project2/ut/Jamfile.jam | 2 ++ project2/ut/definedDirs.h | 16 +++++++++ project2/ut/testScriptHost.cpp | 5 ++- 15 files changed, 214 insertions(+), 6 deletions(-) create mode 100644 project2/basics/unittests/data/unittest-data.xml create mode 100644 project2/basics/unittests/expected/test_rowview_columns.log create mode 100644 project2/basics/unittests/expected/test_rowview_nocolumns.log create mode 100644 project2/basics/unittests/expected/test_rowview_unsetcolumns.log create mode 100644 project2/basics/unittests/lib/testrows.xml create mode 100644 project2/basics/unittests/testViews.cpp create mode 100644 project2/basics/unittests/test_rowview_columns.xml create mode 100644 project2/basics/unittests/test_rowview_nocolumns.xml create mode 100644 project2/basics/unittests/test_rowview_unsetcolumns.xml create mode 100644 project2/ut/definedDirs.h diff --git a/project2/basics/unittests/Jamfile.jam b/project2/basics/unittests/Jamfile.jam index 76dc5ff..167c7c6 100644 --- a/project2/basics/unittests/Jamfile.jam +++ b/project2/basics/unittests/Jamfile.jam @@ -16,3 +16,16 @@ unit-test testLibraries : ..//boost_filesystem ; +path-constant me : . ; + +unit-test standardTests : + [ glob *.cpp : testLibraries.cpp dummylib.cpp ] + : + ROOT=\"$(me)\" + ../../common//p2common + ..//p2basics + ../../ut//p2ut + ../../xml//p2xml + ..//boost_filesystem + ; + diff --git a/project2/basics/unittests/data/unittest-data.xml b/project2/basics/unittests/data/unittest-data.xml new file mode 100644 index 0000000..9b4b474 --- /dev/null +++ b/project2/basics/unittests/data/unittest-data.xml @@ -0,0 +1,24 @@ + + + + 4 + complex + 1980-07-09 01:02:03 + + + 1 + first + + + 2 + second + + + 1 + third + + + 2 + first + + diff --git a/project2/basics/unittests/expected/test_rowview_columns.log b/project2/basics/unittests/expected/test_rowview_columns.log new file mode 100644 index 0000000..5fca0fc --- /dev/null +++ b/project2/basics/unittests/expected/test_rowview_columns.log @@ -0,0 +1,17 @@ +init +addNewRowSet: row +addNewArray: rec(1) +addNewRow: rec +addNamedValue: a=1 +finishRow +addNewRow: rec +addNamedValue: a=2 +finishRow +addNewRow: rec +addNamedValue: a=1 +finishRow +addNewRow: rec +addNamedValue: a=2 +finishRow +finishArray: (1) +finishRowSet diff --git a/project2/basics/unittests/expected/test_rowview_nocolumns.log b/project2/basics/unittests/expected/test_rowview_nocolumns.log new file mode 100644 index 0000000..0c02711 --- /dev/null +++ b/project2/basics/unittests/expected/test_rowview_nocolumns.log @@ -0,0 +1,13 @@ +init +addNewRowSet: row +addNewArray: rec(1) +addNewRow: rec +finishRow +addNewRow: rec +finishRow +addNewRow: rec +finishRow +addNewRow: rec +finishRow +finishArray: (1) +finishRowSet diff --git a/project2/basics/unittests/expected/test_rowview_unsetcolumns.log b/project2/basics/unittests/expected/test_rowview_unsetcolumns.log new file mode 100644 index 0000000..9fcf974 --- /dev/null +++ b/project2/basics/unittests/expected/test_rowview_unsetcolumns.log @@ -0,0 +1,21 @@ +init +addNewRowSet: row +addNewArray: rec(1) +addNewRow: rec +addNamedValue: a=1 +addNamedValue: b=first +finishRow +addNewRow: rec +addNamedValue: a=2 +addNamedValue: b=second +finishRow +addNewRow: rec +addNamedValue: a=1 +addNamedValue: b=third +finishRow +addNewRow: rec +addNamedValue: a=2 +addNamedValue: b=first +finishRow +finishArray: (1) +finishRowSet diff --git a/project2/basics/unittests/lib/testrows.xml b/project2/basics/unittests/lib/testrows.xml new file mode 100644 index 0000000..1d05c6e --- /dev/null +++ b/project2/basics/unittests/lib/testrows.xml @@ -0,0 +1,32 @@ + + + /unittest-data.xml + + + + + + + + + + + + + + + + + + + + + + /root/record[a= or b=''] + + + + + + + diff --git a/project2/basics/unittests/testViews.cpp b/project2/basics/unittests/testViews.cpp new file mode 100644 index 0000000..8230ab9 --- /dev/null +++ b/project2/basics/unittests/testViews.cpp @@ -0,0 +1,40 @@ +#define BOOST_TEST_MODULE Views +#include +#include +#include +#include +#include +#include + +boost::intrusive_ptr +executeRowViewTest(const boost::filesystem::path & script, const boost::filesystem::path & expected) +{ + TestOptionsSource::LoadTestOptions({ + { "common.datasourceRoot", RootDir.string() }, + { "application.dataroot", ("file://" / RootDir / "data").string() }, + }); + BOOST_TEST_CHECKPOINT("Load"); + ScriptReaderPtr r = new XmlScriptParser(script); + boost::intrusive_ptr sr = new TestScriptHost(r); + BOOST_TEST_CHECKPOINT("Execute"); + sr->process(NULL); + BOOST_TEST_CHECKPOINT("Compare"); + BOOST_REQUIRE_EQUAL(sr->GetPresenterData(), expected); + return sr; +} + +BOOST_AUTO_TEST_CASE( test_rowview_unsetcolumns ) +{ + executeRowViewTest(RootDir / "test_rowview_unsetcolumns.xml", RootDir / "expected" / "test_rowview_unsetcolumns.log"); +} + +BOOST_AUTO_TEST_CASE( test_rowview_nocolumns ) +{ + executeRowViewTest(RootDir / "test_rowview_nocolumns.xml", RootDir / "expected" / "test_rowview_nocolumns.log"); +} + +BOOST_AUTO_TEST_CASE( test_rowview_columns ) +{ + executeRowViewTest(RootDir / "test_rowview_columns.xml", RootDir / "expected" / "test_rowview_columns.log"); +} + diff --git a/project2/basics/unittests/test_rowview_columns.xml b/project2/basics/unittests/test_rowview_columns.xml new file mode 100644 index 0000000..c69a29e --- /dev/null +++ b/project2/basics/unittests/test_rowview_columns.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/project2/basics/unittests/test_rowview_nocolumns.xml b/project2/basics/unittests/test_rowview_nocolumns.xml new file mode 100644 index 0000000..3d4a357 --- /dev/null +++ b/project2/basics/unittests/test_rowview_nocolumns.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/project2/basics/unittests/test_rowview_unsetcolumns.xml b/project2/basics/unittests/test_rowview_unsetcolumns.xml new file mode 100644 index 0000000..643898e --- /dev/null +++ b/project2/basics/unittests/test_rowview_unsetcolumns.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/project2/basics/views/rowView.cpp b/project2/basics/views/rowView.cpp index b9508bd..07917ff 100644 --- a/project2/basics/views/rowView.cpp +++ b/project2/basics/views/rowView.cpp @@ -18,8 +18,12 @@ RowView::RowView(ScriptNodePtr p) : required(p, "required", false), isObject(p, "isobject", true) { - BOOST_FOREACH(ScriptNodePtr node, p->childrenIn("columns")) { - viewColumns.insert(Columns::value_type(node->get_name(), Variable(node))); + auto userColumns = p->child("columns", false); + if (userColumns) { + viewColumns = Columns(); + BOOST_FOREACH(ScriptNodePtr node, userColumns->children()) { + viewColumns->insert(Columns::value_type(node->get_name(), Variable(node))); + } } p->script->loader.addLoadTarget(p, Storer::into(&subViews)); p->script->loader.addLoadTarget(p, Storer::into(&valueAggregates)); @@ -43,11 +47,11 @@ RowView::rowReady(const RowState * rs, const MultiRowSetPresenter * presenter, E if (isObject(ec)) { presenter->addNewRow(recordName(ec)); } - if (viewColumns.empty()) { + if (!viewColumns) { rs->foreachColumn(ec, boost::bind(&RowSetPresenter::addNamedValue, presenter, _2, _3)); } else { - BOOST_FOREACH(const Columns::value_type & col, viewColumns) { + BOOST_FOREACH(const Columns::value_type & col, *viewColumns) { presenter->addNamedValue(col.first, col.second(ec)); } } diff --git a/project2/basics/views/rowView.h b/project2/basics/views/rowView.h index d2745db..a65ea69 100644 --- a/project2/basics/views/rowView.h +++ b/project2/basics/views/rowView.h @@ -2,6 +2,7 @@ #define ROWVIEW_H #include +#include #include "rowProcessor.h" #include "view.h" #include "aggregate.h" @@ -23,7 +24,8 @@ class RowView : public View, public RowProcessor { protected: typedef std::map Columns; - Columns viewColumns; + typedef boost::optional OptionalColumns; + OptionalColumns viewColumns; void executeChildren(const MultiRowSetPresenter * presenter, ExecContext *) const; typedef ANONORDEREDSTORAGEOF(View) SubViews; diff --git a/project2/ut/Jamfile.jam b/project2/ut/Jamfile.jam index dc0d734..335294f 100644 --- a/project2/ut/Jamfile.jam +++ b/project2/ut/Jamfile.jam @@ -1,10 +1,12 @@ lib boost_utf : : boost_unit_test_framework ; +lib boost_fs : : boost_filesystem ; lib p2ut : [ glob *.cpp ] : ../common//p2common boost_utf + boost_fs : : BOOST_TEST_DYN_LINK boost_utf diff --git a/project2/ut/definedDirs.h b/project2/ut/definedDirs.h new file mode 100644 index 0000000..fff408a --- /dev/null +++ b/project2/ut/definedDirs.h @@ -0,0 +1,16 @@ +#ifndef P2_UT_DEFINEDDIRS +#define P2_UT_DEFINEDDIRS + +#include + +#ifndef ROOT +#error "ROOT needs to be defined at compilation time" +#endif + +#define XSTR(s) STR(s) +#define STR(s) #s +const auto BinDir = boost::filesystem::canonical("/proc/self/exe").parent_path(); +const boost::filesystem::path RootDir(XSTR(ROOT)); + +#endif + diff --git a/project2/ut/testScriptHost.cpp b/project2/ut/testScriptHost.cpp index dfdb6ed..4dabd39 100644 --- a/project2/ut/testScriptHost.cpp +++ b/project2/ut/testScriptHost.cpp @@ -1,4 +1,6 @@ #include "testScriptHost.h" +#include +#include #include #include #include @@ -99,7 +101,7 @@ namespace std { while (true) { char buf[BUFSIZ]; s.getline(buf, sizeof(buf)); - if (!s.eof()) { + if (s.good()) { v.push_back(buf); } else { @@ -122,6 +124,7 @@ namespace std { 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); -- cgit v1.2.3