libdballe 9.6
core/tests.h
1#include <wreport/tests.h>
2#include <dballe/file.h>
3#include <dballe/values.h>
4#include <dballe/core/query.h>
5#include <dballe/core/defs.h>
6#include <dballe/core/csv.h>
7#include <cstdlib>
8#include <climits>
9#include <string>
10#include <vector>
11#include <sstream>
12#include <iostream>
13#include <memory>
14
15namespace dballe {
16namespace tests {
17
18using namespace wreport::tests;
19
20#if 0
21// Some utility random generator functions
22
23static inline int rnd(int min, int max)
24{
25 return min + (int) ((max - min) * (rand() / (RAND_MAX + 1.0)));
26}
27
28static inline double rnd(double min, double max)
29{
30 return min + (int) ((max - min) * (rand() / (RAND_MAX + 1.0)));
31}
32
33static inline std::string rnd(int len)
34{
35 std::string res;
36 int max = rnd(1, len);
37 for (int i = 0; i < max; i++)
38 res += (char)rnd('a', 'z');
39 return res;
40}
41
42static inline bool rnd(double prob)
43{
44 return (rnd(0, 100) < prob*100) ? true : false;
45}
46#endif
47
48// Message reading functions
49
51std::string datafile(const std::string& fname);
52
53std::unique_ptr<File> open_test_data(const char* filename, Encoding type);
54
55BinaryMessage read_rawmsg(const char* filename, Encoding type);
56
58{
59public:
60 std::stringstream buf;
61
62 void flush_row() override
63 {
64 buf << row << std::endl;
65 row.clear();
66 }
67};
68
69#if 0
71struct TestRecordValEqual
72{
73 const dballe::Record& actual;
74 const dballe::Record& expected;
75 const char* name;
76 bool with_missing_int;
77
78 TestRecordValEqual(const dballe::Record& actual, const dballe::Record& expected, const char* name, bool with_missing_int=false)
79 : actual(actual), expected(expected), name(name), with_missing_int(with_missing_int) {}
80
81 void check() const;
82};
83
84struct TestRecordVarsEqual
85{
86 const dballe::Record& actual;
87 dballe::Values expected;
88
89 TestRecordVarsEqual(const dballe::Record& actual, const dballe::Record& expected) : actual(actual), expected(expected) {}
90 TestRecordVarsEqual(const dballe::Record& actual, const dballe::Values& expected) : actual(actual), expected(expected) {}
91
92 void check() const;
93};
94#endif
95
96// Set a query from a ", "-separated string of assignments
97std::unique_ptr<Query> query_from_string(const std::string& s);
98core::Query core_query_from_string(const std::string& s);
99
100struct ActualMatcherResult : public Actual<int>
101{
102 using Actual::Actual;
103
104 void operator==(int expected) const;
105 void operator!=(int expected) const;
106};
107
108inline ActualMatcherResult actual_matcher_result(int actual) { return ActualMatcherResult(actual); }
109
110using wreport::tests::actual;
111
112inline ActualCString actual(const dballe::Ident& ident) { return ActualCString(ident); }
113
114}
115}
Definition: csv.h:141
A station identifier, that can be any string (including the empty string) or a missing value.
Definition: types.h:748
Definition: core/tests.h:58
void flush_row() override
Write the current line to the output file, and start a new one.
Definition: core/tests.h:62
Common definitions.
Routines to parse data in CSV format.
Collection of Value objects, indexed by wreport::Varcode.
Definition: values.h:177
Definition: core/tests.h:101
Structures used as input to database insert functions.