Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
query-resolver-test.cpp
Go to the documentation of this file.
1/*
2 QueryResolver(Test) - issuing typed queries over a generic interface
3
4 Copyright (C)
5 2009, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
19#include "lib/test/run.hpp"
21#include "lib/format-cout.hpp"
22#include "lib/depend.hpp"
23
25
26#include <string>
27
28
29
30namespace lumiera {
31namespace test{
32
34 using std::string;
35
36
37
38
39 namespace { // providing a test query resolving facility...
40
41 typedef Goal::QueryID const& QID;
42
44 template<typename TY>
46
47 template<>
48 class DummySolutions<int>
49 {
50 int resNr_;
51
52 public:
53 DummySolutions() : resNr_(7) {}
54
55 int* next () { --resNr_; return &resNr_; }
56 bool exhausted() { return !bool(resNr_); }
57 };
58
59 template<>
60 class DummySolutions<string>
61 : public DummySolutions<int>
62 {
64
65 public:
66 string*
68 {
69 static Literal lumi{"Lumiera"};
70 currentText_ = string (lumi + *DummySolutions<int>::next());
71 return &currentText_;
72 }
73 };
74
75
83 template<typename TY>
86 {
88
90
91 Result
93 {
94 Cursor cursor;
95 cursor.point_at (solutions_.next());
96 return cursor;
97 }
98
99 void
101 {
102 Cursor& cursor = static_cast<Cursor&> (pos);
103
104 if (solutions_.exhausted())
105 cursor.point_at (0);
106 else
107 cursor.point_at (solutions_.next());
108 }
109 };
110
111
112
119 : public QueryResolver
120 {
121 bool
122 canHandleQuery (QID qID) const
123 {
124 return Goal::GENERIC == qID.kind
125 and ( wantResultType<int> (qID)
126 or wantResultType<string>(qID));
127 }
128
129 template<typename TY>
130 bool
131 wantResultType (QID qID) const
132 {
133 return qID.type == getResultTypeID<TY>();
134 }
135
136
137 template<typename TY>
138 static Resolution*
140 {
141 QID qID = goal.getQID();
142 REQUIRE (qID.kind == Goal::GENERIC
143 and qID.type == getResultTypeID<TY>());
144
145 return new DummyResultSet<TY>();
146 }
147
148 operator string() const { return "Test-DummyQueryResolver"; }
149
150 public:
152 : QueryResolver()
153 {
154 Goal::QueryID case1(Goal::GENERIC, getResultTypeID<int>());
155 Goal::QueryID case2(Goal::GENERIC, getResultTypeID<string>());
156
157 installResolutionCase(case1, &resolutionFunction<int> );
158 installResolutionCase(case2, &resolutionFunction<string> );
159 }
160 };
161
162
164
167 {
168 return testResolver();
169 }
170
171 } // (END) implementation of a test query resolving facility
172
173
174
175
176
177
178 /*******************************************************************************/
188 class QueryResolver_test : public Test
189 {
190
191 virtual void
192 run (Arg)
193 {
194 QueryResolver& resolver = buildTestQueryResolver();
195 Query<int> firstQuery("");
196 explore (firstQuery.resolveBy (resolver));
197
198 Query<string> secondQuery("");
199 explore (secondQuery.resolveBy(resolver));
200 }
201
202 template<typename ITER>
203 static void
204 explore (ITER ii)
205 {
206 cout << "Query-Results: " << showSizeof(ii) << endl;
207 for ( ; ii; ++ii )
208 cout << *ii << endl;
209 }
210
211 };
212
213
215 LAUNCHER (QueryResolver_test, "unit session");
216
217
218}} // namespace lumiera::test
Access point to singletons and other kinds of dependencies designated by type.
Definition depend.hpp:281
Inline string literal.
Definition symbol.hpp:78
Single Solution, possibly part of a result set.
Definition query.hpp:157
Query ABC: unspecific goal for resolution or retrieval.
Definition query.hpp:118
QueryID const & getQID() const
Definition query.hpp:144
Interface: a facility for resolving (some kind of) queries A concrete subclass has the ability to cre...
void point_at(RES *r)
Definition query.hpp:344
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition query.hpp:254
iterator resolveBy(QueryResolver const &resolver) const
ABC representing the result set of an individual query resolution.
Singleton services and Dependency Injection.
Automatically use custom string conversion in C++ stream output.
string showSizeof(size_t siz, string name)
for printing sizeof().
Lumiera public interface.
Definition advice.hpp:102
Goal::QueryID const & QID
Test runner and basic definitions for tests.
framework and to resolve logical queries.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
a concrete "resolution" of the query is a set of "solutions", which can be explored by iteration.
A collection of frequently used helper functions to support unit testing.