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