From 9ad0dd9918db5e5f2b2013956ca2910f71d09169 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 11 Aug 2017 18:34:23 +0200 Subject: [PATCH] DiffMessage: start with drafting the most simple test case damn it! why the hell is the C++ language so tedious to write.... even after years of practice you need hours to get the most basic stuff to fly --- src/lib/iter-adapter-stl.hpp | 2 +- src/lib/iter-source.hpp | 4 +-- tests/library/diff/diff-message-test.cpp | 45 ++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/lib/iter-adapter-stl.hpp b/src/lib/iter-adapter-stl.hpp index 13b91a17d..90ecfbe89 100644 --- a/src/lib/iter-adapter-stl.hpp +++ b/src/lib/iter-adapter-stl.hpp @@ -411,7 +411,7 @@ namespace iter_stl { * materialised iterator contents. * At construction, the given source iterator * is immediately discharged into an internal buffer (vector). - * This captured value sequence can be retrieved once as + * This captured value sequence can then be retrieved _once_ as * Lumiera Forward Iterator */ template diff --git a/src/lib/iter-source.hpp b/src/lib/iter-source.hpp index 5f8a54eac..49178ac52 100644 --- a/src/lib/iter-source.hpp +++ b/src/lib/iter-source.hpp @@ -224,8 +224,8 @@ namespace lib { : public IterSource , boost::noncopyable { - typedef IterSource _Base; - typedef typename _Base::Pos Pos; + using _Base = IterSource; + using Pos = typename _Base::Pos; IT src_; diff --git a/tests/library/diff/diff-message-test.cpp b/tests/library/diff/diff-message-test.cpp index a43b31ec6..c17e0bd23 100644 --- a/tests/library/diff/diff-message-test.cpp +++ b/tests/library/diff/diff-message-test.cpp @@ -27,6 +27,7 @@ #include "lib/test/run.hpp" #include "lib/format-util.hpp" +#include "lib/diff/diff-message.hpp" #include "lib/diff/tree-diff-application.hpp" #include "lib/iter-adapter-stl.hpp" #include "lib/time/timevalue.hpp" @@ -36,6 +37,7 @@ #include #include +using lib::iter_stl::IterSnapshot; using lib::iter_stl::snapshot; using util::isnil; using util::join; @@ -65,6 +67,9 @@ namespace test{ ATTRIB_NODE = MakeRec().genNode("δ"), // empty named node to be attached as attribute δ CHILD_NODE = SUB_NODE; // yet another child node, same ID as SUB_NODE (!) + + int instances = 0; ///< verify instance management + }//(End)Test fixture @@ -122,11 +127,47 @@ namespace test{ demonstrate_treeApplication(); } - + + /** @test demonstrate the intended usage pattern + * - a diff generation context is allocated + * - the MutationMessage takes ownership + * - and exposes the generated diff sequence + * - which is pulled during iteration + */ void demonstrate_simpleUsage() { - UNIMPLEMENTED("generate and iterate, everything right here"); + using Source = WrappedLumieraIter>; + + /* opaque generation context */ + struct Generator + : TreeDiffLanguage + , Source + { + Generator() + : Source{snapshot({ins(TYPE_X) + ,set(ATTRIB1) + ,del(CHILD_T)})} + { + ++instances; + } + + ~Generator() + { + --instances; + } + }; + + + CHECK (0 == instances); + { + DiffMessage diffMsg{new Generator}; + CHECK (!isnil (diffMsg)); + CHECK (1 == instances); + + CHECK ("ins" == string(diffMsg->verb())); + } + CHECK (0 == instances); }