libdballe  7.7
core/tests.h
1 #include <wreport/tests.h>
2 #include <dballe/file.h>
3 #include <dballe/record.h>
4 #include <dballe/core/query.h>
5 #include <dballe/core/values.h>
6 #include <dballe/core/defs.h>
7 #include <cstdlib>
8 #include <climits>
9 #include <string>
10 #include <vector>
11 #include <iostream>
12 #include <memory>
13 
14 namespace dballe {
15 namespace tests {
16 
17 using namespace wreport::tests;
18 
25 bool test_can_run(const std::string& group_name, const std::string& test_name);
26 
27 #if 0
28 // Some utility random generator functions
29 
30 static inline int rnd(int min, int max)
31 {
32  return min + (int) ((max - min) * (rand() / (RAND_MAX + 1.0)));
33 }
34 
35 static inline double rnd(double min, double max)
36 {
37  return min + (int) ((max - min) * (rand() / (RAND_MAX + 1.0)));
38 }
39 
40 static inline std::string rnd(int len)
41 {
42  std::string res;
43  int max = rnd(1, len);
44  for (int i = 0; i < max; i++)
45  res += (char)rnd('a', 'z');
46  return res;
47 }
48 
49 static inline bool rnd(double prob)
50 {
51  return (rnd(0, 100) < prob*100) ? true : false;
52 }
53 #endif
54 
55 // Message reading functions
56 
58 std::string datafile(const std::string& fname);
59 
60 std::unique_ptr<File> open_test_data(const char* filename, File::Encoding type);
61 
62 BinaryMessage read_rawmsg(const char* filename, File::Encoding type);
63 
64 #if 0
65 struct TestRecordValEqual
67 {
68  const dballe::Record& actual;
69  const dballe::Record& expected;
70  const char* name;
71  bool with_missing_int;
72 
73  TestRecordValEqual(const dballe::Record& actual, const dballe::Record& expected, const char* name, bool with_missing_int=false)
74  : actual(actual), expected(expected), name(name), with_missing_int(with_missing_int) {}
75 
76  void check() const;
77 };
78 
79 struct TestRecordVarsEqual
80 {
81  const dballe::Record& actual;
82  dballe::Values expected;
83 
84  TestRecordVarsEqual(const dballe::Record& actual, const dballe::Record& expected) : actual(actual), expected(expected) {}
85  TestRecordVarsEqual(const dballe::Record& actual, const dballe::Values& expected) : actual(actual), expected(expected) {}
86 
87  void check() const;
88 };
89 #endif
90 
91 struct ActualRecord : public wreport::tests::Actual<const dballe::Record&>
92 {
93  ActualRecord(const dballe::Record& actual) : wreport::tests::Actual<const dballe::Record&>(actual) {}
94 
95 #if 0
96  TestRecordValEqual equals(const Record& expected, const char* name) { return TestRecordValEqual(this->actual, expected, name); }
97  TestRecordValEqual equals_with_missing_int(const Record& expected, const char* name)
98  {
99  return TestRecordValEqual(this->actual, expected, name, true);
100  }
101 #endif
102  void vars_equal(const Record& expected) const { vars_equal(Values(expected)); }
105  void vars_equal(const Values& expected) const;
106 };
107 
108 // Set a record from a ", "-separated string of assignments
109 void set_record_from_string(Record& rec, const std::string& s);
110 std::unique_ptr<Record> record_from_string(const std::string& s);
111 std::unique_ptr<Query> query_from_string(const std::string& s);
112 core::Query core_query_from_string(const std::string& s);
113 
114 struct ActualMatcherResult : public Actual<int>
115 {
116  using Actual::Actual;
117 
118  void operator==(int expected) const;
119  void operator!=(int expected) const;
120 };
121 
122 inline ActualMatcherResult actual_matcher_result(int actual) { return ActualMatcherResult(actual); }
123 
124 using wreport::tests::actual;
125 
126 inline dballe::tests::ActualRecord actual(const dballe::Record& actual) { return dballe::tests::ActualRecord(actual); }
127 
128 inline ActualCString actual(const dballe::Ident& ident) { return ActualCString(ident); }
129 
130 }
131 }
Encoding
Supported encodings.
Definition: file.h:20
Key/value store where keys are strings and values are wreport variables.
Definition: record.h:16
Standard dballe::Query implementation.
Definition: core/query.h:29
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
A station identifier, that can be any string (including the empty string) or a missing value...
Definition: core/defs.h:19
Definition: core/tests.h:91
Definition: core/tests.h:114
Common definitions.
Definition: values.h:106