summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2014-12-21 17:32:12 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2014-12-21 17:32:12 +0000
commitc4d99464467c307d1649b40321d801dc818eaeda (patch)
tree0ca5089a2becc655f963cd7750805ea694928a48
parentAdd missing includes highlighted when precompiled headers are disabled (diff)
downloadproject2-c4d99464467c307d1649b40321d801dc818eaeda.tar.bz2
project2-c4d99464467c307d1649b40321d801dc818eaeda.tar.xz
project2-c4d99464467c307d1649b40321d801dc818eaeda.zip
Allow specifying no columns in row view and covering tests
-rw-r--r--project2/basics/unittests/Jamfile.jam13
-rw-r--r--project2/basics/unittests/data/unittest-data.xml24
-rw-r--r--project2/basics/unittests/expected/test_rowview_columns.log17
-rw-r--r--project2/basics/unittests/expected/test_rowview_nocolumns.log13
-rw-r--r--project2/basics/unittests/expected/test_rowview_unsetcolumns.log21
-rw-r--r--project2/basics/unittests/lib/testrows.xml32
-rw-r--r--project2/basics/unittests/testViews.cpp40
-rw-r--r--project2/basics/unittests/test_rowview_columns.xml9
-rw-r--r--project2/basics/unittests/test_rowview_nocolumns.xml7
-rw-r--r--project2/basics/unittests/test_rowview_unsetcolumns.xml5
-rw-r--r--project2/basics/views/rowView.cpp12
-rw-r--r--project2/basics/views/rowView.h4
-rw-r--r--project2/ut/Jamfile.jam2
-rw-r--r--project2/ut/definedDirs.h16
-rw-r--r--project2/ut/testScriptHost.cpp5
15 files changed, 214 insertions, 6 deletions
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 :
<library>..//boost_filesystem
;
+path-constant me : . ;
+
+unit-test standardTests :
+ [ glob *.cpp : testLibraries.cpp dummylib.cpp ]
+ :
+ <define>ROOT=\"$(me)\"
+ <library>../../common//p2common
+ <library>..//p2basics
+ <library>../../ut//p2ut
+ <library>../../xml//p2xml
+ <library>..//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 @@
+<?xml version="1.0"?>
+<root>
+ <complex>
+ <a>4</a>
+ <b>complex</b>
+ <d>1980-07-09 01:02:03</d>
+ </complex>
+ <record>
+ <a>1</a>
+ <b>first</b>
+ </record>
+ <record>
+ <a>2</a>
+ <b>second</b>
+ </record>
+ <record>
+ <a>1</a>
+ <b>third</b>
+ </record>
+ <record>
+ <a>2</a>
+ <b>first</b>
+ </record>
+</root>
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 @@
+<?xml version="1.0"?>
+<p2:xpathrows xmlns:p2="http://project2.randomdan.homeip.net" name="testrows">
+ <url><root source="config" name="dataroot"/>/unittest-data.xml</url>
+ <filterviews>
+ <complex root="/root/complex[1]">
+ <fields>
+ <a xpath="a"/>
+ <b xpath="b"/>
+ <d xpath="d"/>
+ </fields>
+ </complex>
+ <single root="/root/record[3]">
+ <fields>
+ <a xpath="a"/>
+ <b xpath="b"/>
+ </fields>
+ </single>
+ <default root="/root/record">
+ <fields>
+ <a xpath="a"/>
+ <b xpath="b"/>
+ </fields>
+ </default>
+ <params>
+ <root>/root/record[a=<a source="param" name="a"/> or b='<b source="param" name="b"/>']</root>
+ <fields>
+ <a xpath="a"/>
+ <b xpath="b"/>
+ </fields>
+ </params>
+ </filterviews>
+</p2:xpathrows>
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 <boost/test/unit_test.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <xmlScriptParser.h>
+#include <testOptionsSource.h>
+#include <testScriptHost.h>
+#include <definedDirs.h>
+
+boost::intrusive_ptr<TestScriptHost>
+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<TestScriptHost> 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 @@
+<?xml version="1.0"?>
+<test xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:p2="http://project2.randomdan.homeip.net">
+ <xi:include href="lib/testrows.xml"/>
+ <p2:view source="testrows" recordname="rec" rootname="row" filter="default">
+ <columns>
+ <a source="parent" name="a" />
+ </columns>
+ </p2:view>
+</test>
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 @@
+<?xml version="1.0"?>
+<test xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:p2="http://project2.randomdan.homeip.net">
+ <xi:include href="lib/testrows.xml"/>
+ <p2:view source="testrows" recordname="rec" rootname="row" filter="default">
+ <columns/>
+ </p2:view>
+</test>
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 @@
+<?xml version="1.0"?>
+<test xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:p2="http://project2.randomdan.homeip.net">
+ <xi:include href="lib/testrows.xml"/>
+ <p2:view source="testrows" recordname="rec" rootname="row" filter="default"/>
+</test>
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<ElementLoader>(&subViews));
p->script->loader.addLoadTarget(p, Storer::into<ElementLoader>(&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 <boost/intrusive_ptr.hpp>
+#include <boost/optional.hpp>
#include "rowProcessor.h"
#include "view.h"
#include "aggregate.h"
@@ -23,7 +24,8 @@ class RowView : public View, public RowProcessor {
protected:
typedef std::map<Glib::ustring, Variable> Columns;
- Columns viewColumns;
+ typedef boost::optional<Columns> 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 : : <name>boost_unit_test_framework ;
+lib boost_fs : : <name>boost_filesystem ;
lib p2ut :
[ glob *.cpp ]
:
<library>../common//p2common
<library>boost_utf
+ <library>boost_fs
: :
<define>BOOST_TEST_DYN_LINK
<library>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 <boost/filesystem/path.hpp>
+
+#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 <boost/test/test_tools.hpp>
+#include <boost/filesystem/operations.hpp>
#include <glibmm/exception.h>
#include <cxxabi.h>
#include <logger.h>
@@ -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);