From 9369709a4614dce1155196ffcf3077b07e21536b Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 24 Dec 2012 03:20:52 +0100 Subject: [PATCH] fix breakage uncovered by unit-test --- src/common/query.hpp | 11 +- src/common/query/defs-registry.hpp | 12 +-- src/lib/query-util.cpp | 4 +- .../session/defs-registry-impl-test.cpp | 102 +++++++++--------- tests/lib/query/querydiagnostics.hpp | 2 +- 5 files changed, 70 insertions(+), 61 deletions(-) diff --git a/src/common/query.hpp b/src/common/query.hpp index db6b454b8..3fbe028e6 100644 --- a/src/common/query.hpp +++ b/src/common/query.hpp @@ -324,7 +324,7 @@ namespace lumiera { operator Query() const { REQUIRE (getResultTypeID() == id_.type); - return Query::build(id_.kind).withConditions(def_); + return Query::build(id_.kind).fromText(def_); } string @@ -335,6 +335,12 @@ namespace lumiera { +",def=" + string(def_); } + string + getQueryString() const + { + return string(def_); + } + uint degree() const @@ -428,7 +434,8 @@ namespace lumiera { Builder& withConditions (string additionalQueryPredicates) { - lib::query::appendTerms(this->predicateForm_, additionalQueryPredicates); + this->predicateForm_ = + lib::query::appendTerms(this->predicateForm_, additionalQueryPredicates); return *this; } diff --git a/src/common/query/defs-registry.hpp b/src/common/query/defs-registry.hpp index 58d1791dd..25df50734 100644 --- a/src/common/query/defs-registry.hpp +++ b/src/common/query/defs-registry.hpp @@ -280,14 +280,14 @@ namespace query { /** register the object as being "default" when searching something * similar as designated by the given query. Only a weak ref is stored. - * @param obj Will be rebound, if another object is already stored. - * @return true if object has actually been stored, false if another - * object is registered for exactly the same query. In this - * case, also the param obj shared-ptr is rebound! + * @param obj to be recorded as "default". Only a weak pointer will be stored + * @retval true if object has actually been stored + * @retval false if another object is registered for exactly the same query + * Nothing is changed in this case */ template bool - put (P& obj, Query const& query) + put (P const& obj, Query const& query) { Record entry (query, obj); typedef typename Slot::Registry Registry; @@ -302,7 +302,7 @@ namespace query { if (storedObj) return (storedObj == obj); else - // use the opportunity and purge the expired entry + // use the opportunity to purge the expired entry registry.erase(pos++); } // no existing entry.... diff --git a/src/lib/query-util.cpp b/src/lib/query-util.cpp index bd5899425..7fea96829 100644 --- a/src/lib/query-util.cpp +++ b/src/lib/query-util.cpp @@ -145,8 +145,8 @@ namespace lib { string appendTerms (string const& pred1, string const& pred2) { - string res(pred1); - return res + ", " + pred2; + return isnil(pred1)? pred2 + : pred1 + ", " + pred2; } diff --git a/tests/components/proc/mobject/session/defs-registry-impl-test.cpp b/tests/components/proc/mobject/session/defs-registry-impl-test.cpp index 0d35f95ab..24d312656 100644 --- a/tests/components/proc/mobject/session/defs-registry-impl-test.cpp +++ b/tests/components/proc/mobject/session/defs-registry-impl-test.cpp @@ -26,19 +26,19 @@ #include "common/query.hpp" #include "common/query/defs-registry.hpp" +#include "lib/format-string.hpp" #include "lib/p.hpp" #include "../lib/query/querydiagnostics.hpp" #include -#include #include using util::isnil; +using util::_Fmt; using lib::P; using boost::scoped_ptr; -using boost::format; using std::string; using std::rand; using std::map; @@ -49,43 +49,45 @@ namespace lumiera { namespace query { namespace test { - format typePatt ("Dummy<%2i>"); - format instancePatt ("obj_%s_%i"); - format predicatePatt ("%s_%2i( %s )"); - - - - /** create a random new ID */ - string - newID (string prefix) - { - return str (instancePatt % prefix % rand()); - } - - - /** template for generating some different test types */ - template - struct Dummy + namespace { // Test helpers... + + _Fmt typePatt ("Dummy<%2i>"); + _Fmt instancePatt ("obj_%s_%i"); + + + + /** create a random new ID */ + string + newID (string prefix) { - static string name; - string instanceID; - operator string () const { return instanceID; } - bool operator== (const Dummy& odu) const { return this == &odu; } - - - Dummy () : instanceID (newID (name)) {} - }; - - template - string Dummy::name = str (typePatt % I); - - template - inline P > - fabricate() - { - return P >(new Dummy); - } - + return instancePatt % prefix % rand(); + } + + + /** template for generating some different test types */ + template + struct Dummy + { + static string name; + string instanceID; + operator string () const { return instanceID; } + bool operator== (const Dummy& odu) const { return this == &odu; } + + + Dummy () : instanceID (newID (name)) {} + }; + + template + string Dummy::name = (typePatt % I); + + template + inline P > + fabricate() + { + return P >(new Dummy); + } + + }//(End)Test helpers using lib::query::test::garbage_query; @@ -154,7 +156,7 @@ namespace test { reg_->put (o1, q5); reg_->put (o2, q4); - reg_->put (o3, q3); + reg_->put (o2, q3); reg_->put (o3, q2); reg_->put (o2, q1); reg_->put (o1, Q13()); // the empty query @@ -167,7 +169,7 @@ namespace test { reg_->put (px, qx); // store for verification.... - px->instanceID = QueryKey(qx).display(); + px->instanceID = QueryKey(qx).getQueryString(); ps[qx] = px; } } @@ -179,20 +181,20 @@ namespace test { Iter13 i (reg_->candidates(Q13 ("irrelevant query"))); CHECK ( i.hasNext()); CHECK ( *i == o1); ++i; // ordered according to the degree of the queries - CHECK ( *i == o2); ++i; - CHECK ( *i == o3); ++i; - CHECK ( *i == o3); ++i; + CHECK ( *i == o2); ++i; // degree == 1 + CHECK ( *i == o3); ++i; // degree == 2 + CHECK ( *i == o2); ++i; // ... CHECK ( *i == o2); ++i; CHECK ( *i == o1); CHECK (!i.hasNext()); CHECK (! *++i ); // null after end - i = reg_->candidates(q3); + i = reg_->candidates(q2); CHECK ( *i == o3); ++i; // found by direct match CHECK ( *i == o1); ++i; // followed by the ordered enumeration CHECK ( *i == o2); ++i; CHECK ( *i == o3); ++i; - CHECK ( *i == o3); ++i; + CHECK ( *i == o2); ++i; CHECK ( *i == o2); ++i; CHECK ( *i == o1); ++i; CHECK (!i.hasNext()); @@ -202,7 +204,7 @@ namespace test { CHECK ( *i == o1); ++i; CHECK ( *i == o2); ++i; CHECK ( *i == o3); ++i; - CHECK ( *i == o3); ++i; + CHECK ( *i == o2); ++i; CHECK ( *i == o2); ++i; CHECK ( *i == o1); ++i; CHECK (!i.hasNext()); @@ -240,8 +242,8 @@ namespace test { CHECK ( *i == o1); ++i; // ordered according to the degree of the queries // but the o2 entries are missing CHECK ( *i == o3); ++i; - CHECK ( *i == o3); ++i; - // missing + // o2 missing + // o2 missing CHECK ( *i == o1); CHECK (!i.hasNext()); @@ -251,7 +253,7 @@ namespace test { i = reg_->candidates(Q13 ("something")); CHECK ( i.hasNext()); CHECK ( *i == o1); ++i; // ordered according to the degree of the queries - // but now also the o3 entries are missing... + // but now also the o3 entry is missing... CHECK ( *i == o1); CHECK (!i.hasNext()); @@ -275,7 +277,7 @@ namespace test { i = reg_->candidates(q2); CHECK ( *i == o2); ++i; // direct match CHECK ( *i == o1); ++i; - CHECK ( *i == o2); ++i; // inserted here in the dataset + CHECK ( *i == o2); ++i; // inserted here in the dataset, since q2 has degree 2 CHECK ( *i == o1); ++i; CHECK (!i.hasNext()); diff --git a/tests/lib/query/querydiagnostics.hpp b/tests/lib/query/querydiagnostics.hpp index ddcad83ef..269ef2d80 100644 --- a/tests/lib/query/querydiagnostics.hpp +++ b/tests/lib/query/querydiagnostics.hpp @@ -39,7 +39,7 @@ namespace test { namespace {// implementation constants - _Fmt predicatePattern ("%s_%2i( %s )"); + _Fmt predicatePattern ("%s_%02i( %s )"); const string garbage ("asanisimasabibeddiboom"); const uint MAX_DEGREE_RAND = 9;