36 using std::unique_ptr;
48 _Fmt instancePatt (
"obj_%s_%i");
55 return instancePatt % prefix %
rani(10
'000); 65 operator string () const { return instanceID; } 66 bool operator== (const Dummy& odu) const { return this == &odu; } 69 Dummy () : instanceID (newID (name)) {} 73 string Dummy<I>::name = _Fmt("Dummy<%2i>") % I; 79 return P<Dummy<I>>(new Dummy<I>); 84 using lib::query::test::garbage_query; 90 /********************************************************************//** 91 * @test build an registry table (just for this test) configured for 92 * some artificial test Types. Register some entries and verify 93 * the intended behaviour of the storage structure. 94 * @see DefsManagerImpl_test for checking the implementation details 95 * in the actual context used in Lumiera. 97 class DefsRegistryImpl_test : public Test 99 unique_ptr<DefsRegistry> reg_; 101 typedef P<Dummy<13>> Obj; 102 typedef P<Dummy<23>> Pra; 104 typedef Query<Dummy<13>> Q13; 105 typedef Query<Dummy<23>> Q23; 107 typedef DefsRegistry::Iter<Dummy<13>> Iter13; 108 typedef DefsRegistry::Iter<Dummy<23>> Iter23; 111 // some test objects... 113 Q13 q1, q2, q3, q4, q5; 114 map<QueryKey, Pra> ps; 117 DefsRegistryImpl_test () 118 : o1 (fabricate<13>()) 119 , o2 (fabricate<13>()) 120 , o3 (fabricate<13>()) 121 , q1 (garbage_query (1)) 122 , q2 (garbage_query (2)) 123 , q3 (garbage_query (3)) 124 , q4 (garbage_query (4)) 125 , q5 (garbage_query (5)) 133 this->reg_.reset (new DefsRegistry); 146 // at start the registry is indeed empty 147 // thus a query doesn't yield any results....
148 CHECK ( ! *(reg_->candidates(
Q13 (
"something"))) );
155 reg_->put (o1,
Q13());
158 for (
int i=0; i<100; ++i)
160 Pra px (fabricate<23>());
161 Q23 qx (garbage_query());
165 px->instanceID =
QueryKey(qx).getQueryString();
174 Iter13 i (reg_->candidates(
Q13 (
"irrelevant query")));
175 CHECK ( i.hasNext());
176 CHECK ( *i == o1); ++i;
177 CHECK ( *i == o2); ++i;
178 CHECK ( *i == o3); ++i;
179 CHECK ( *i == o2); ++i;
180 CHECK ( *i == o2); ++i;
182 CHECK (!i.hasNext());
185 i = reg_->candidates(q2);
186 CHECK ( *i == o3); ++i;
187 CHECK ( *i == o1); ++i;
188 CHECK ( *i == o2); ++i;
189 CHECK ( *i == o3); ++i;
190 CHECK ( *i == o2); ++i;
191 CHECK ( *i == o2); ++i;
192 CHECK ( *i == o1); ++i;
193 CHECK (!i.hasNext());
195 i = reg_->candidates(
Q13());
196 CHECK ( *i == o1); ++i;
197 CHECK ( *i == o1); ++i;
198 CHECK ( *i == o2); ++i;
199 CHECK ( *i == o3); ++i;
200 CHECK ( *i == o2); ++i;
201 CHECK ( *i == o2); ++i;
202 CHECK ( *i == o1); ++i;
203 CHECK (!i.hasNext());
207 Iter23 j = reg_->candidates(
Q23 (
"some crap"));
211 Q23 qx ((*j)->instanceID);
212 CHECK ( ps[qx] == (*j));
214 CHECK ( d_prev <= d );
217 CHECK (!j.hasNext());
221 Q23 someQuery(ps.begin()->first);
222 j = reg_->candidates(someQuery);
223 CHECK ( *j == ps.begin()->second);
233 Iter13 i (reg_->candidates(q4));
234 CHECK ( i.hasNext());
235 CHECK ( *i == o1); ++i;
237 CHECK ( *i == o3); ++i;
241 CHECK (!i.hasNext());
246 i = reg_->candidates(
Q13 (
"something"));
247 CHECK ( i.hasNext());
248 CHECK ( *i == o1); ++i;
251 CHECK (!i.hasNext());
253 CHECK ( reg_->put (o1, q5));
255 i = reg_->candidates(q5);
256 CHECK ( *i == o1); ++i;
257 CHECK ( *i == o1); ++i;
258 CHECK ( *i == o1); ++i;
259 CHECK (!i.hasNext());
261 CHECK (!reg_->put (o2, q5));
263 i = reg_->candidates(q5);
264 CHECK ( *i == o1); ++i;
265 CHECK ( *i == o1); ++i;
266 CHECK ( *i == o1); ++i;
267 CHECK (!i.hasNext());
269 CHECK ( reg_->put (o2, q2));
270 i = reg_->candidates(q2);
271 CHECK ( *i == o2); ++i;
272 CHECK ( *i == o1); ++i;
273 CHECK ( *i == o2); ++i;
274 CHECK ( *i == o1); ++i;
275 CHECK (!i.hasNext());
277 CHECK ( reg_->forget (o1));
278 CHECK (!reg_->forget (o1));
279 CHECK ( reg_->forget (o2));
281 o3 = fabricate<13>();
283 i = reg_->candidates(q2);
used for enumerating solutions
Basic and generic representation of an internal query.
string newID(string prefix)
create a random new ID
int rani(uint bound=_iBOUND())
Customised refcounting smart pointer.
A front-end for using printf-style formatting.
A piece of implementation code factored out into a separate header (include).
Simplistic test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
diagnostic helpers to support test related to predicate queries
Wrapper for indexing and ordering.
Lumiera public interface.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...