Lumiera  0.pre.03
»edit your freedom«
query-diagnostics.hpp
Go to the documentation of this file.
1 /*
2  QUERY-DIAGNOSTICS.hpp - helpers for writing tests covering config queries
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
29 #ifndef LIB_QUERY_DIAGNOSTICS_H
30 #define LIB_QUERY_DIAGNOSTICS_H
31 
32 
33 #include "lib/format-string.hpp"
34 
35 using util::_Fmt;
36 using std::string;
37 using std::rand;
38 
39 
40 
41 namespace lib {
42 namespace query{
43 namespace test {
44 
45  namespace {// implementation constants
46 
47  _Fmt predicatePattern ("%s_%02i( %s )");
48  const string garbage ("asanisimasabibeddiboom");
49 
50  const uint MAX_DEGREE_RAND = 9;
51 
52  }
53 
54 
55 
56  inline string
57  garbage_term ()
58  {
59  return predicatePattern
60  % char ('a'+ rand() % 26)
61  % (rand() % 100)
62  % garbage.substr(rand() % 19 , 3);
63  }
64 
65  inline string
66  garbage_query (int degree=0)
67  {
68  string fake;
69  if (!degree)
70  degree = 1 + rand() % MAX_DEGREE_RAND;
71  while (0 < --degree)
72  fake += garbage_term() + ", ";
73  fake += garbage_term() + ".";
74  return fake;
75  }
76 
77 
78 
79 
80 }}} // namespace lib::query::test
81 #endif
Definition: run.hpp:49
Front-end for printf-style string template interpolation.
A front-end for using printf-style formatting.
Implementation namespace for support and library code.
string garbage_query(int degree=0)