21#ifndef WREPORT_TESTS_UTILS
22#define WREPORT_TESTS_UTILS
30#include <wreport/bulletin.h>
31#include <wreport/fwd.h>
32#include <wreport/notes.h>
33#include <wreport/tests.h>
34#include <wreport/utils/tests.h>
41std::filesystem::path
datafile(
const std::filesystem::path& fname);
52 const char* deflt =
nullptr);
59std::string
slurpfile(
const std::filesystem::path& name);
64std::vector<std::filesystem::path>
all_test_files(
const std::string& encoding);
74void track_bulletin(
Bulletin& b,
const char* tag,
75 const std::filesystem::path& fname);
77template <
typename BULLETIN>
78std::unique_ptr<BULLETIN> decode_checked(
const std::string& buf,
83 return BULLETIN::decode(buf, name);
89 auto h = BULLETIN::decode_header(buf, name);
90 h->print_structured(stderr);
94 std::cerr <<
"Dump interrupted: " << e.
what();
100template <
typename BULLETIN>
101std::unique_ptr<BULLETIN> decode_checked(
const std::string& buf,
102 const char* name, FILE* verbose)
106 return BULLETIN::decode_verbose(buf, verbose, name);
108 catch (wreport::error_parse& e1)
112 auto h = BULLETIN::decode_header(buf, name);
113 h->print_structured(stderr);
115 catch (wreport::error& e2)
117 std::cerr <<
"Dump interrupted: " << e2.
what();
123template <
typename BULLETIN>
struct TestCodec
125 std::filesystem::path fname;
126 std::function<void(
const BULLETIN&)> check_contents =
127 [](
const BULLETIN&)
noexcept {};
129 explicit TestCodec(
const std::filesystem::path& fname) : fname(fname) {}
130 virtual ~TestCodec() {}
135void assert_var_equal(
const Var& actual,
const Var& expected);
136void assert_var_not_equal(
const Var& actual,
const Var& expected);
137template <
typename Val>
138void assert_var_value_equal(
const Var& actual, Val expected);
139template <
typename Val>
140void assert_var_value_not_equal(
const Var& actual, Val expected);
142struct ActualVar :
public Actual<Var>
144 explicit ActualVar(
const Var& actual) : Actual<Var>(actual) {}
146 void operator==(
const Var& expected)
const
148 assert_var_equal(_actual, expected);
150 void operator!=(
const Var& expected)
const
152 assert_var_not_equal(_actual, expected);
154 template <
typename Val>
void operator==(Val expected)
const
156 assert_var_value_equal(_actual, expected);
158 template <
typename Val>
void operator!=(Val expected)
const
160 assert_var_value_not_equal(_actual, expected);
163 void isunset()
const;
173 using Actual::Actual;
175 void operator==(Varcode expected)
const;
176 void operator!=(Varcode expected)
const;
Storage for the decoded data of a BUFR or CREX message.
Definition bulletin.h:30
A physical variable.
Definition var.h:25
Report an error when parsing informations.
Definition error.h:201
Base class for DB-All.e exceptions.
Definition error.h:61
const char * what() const noexcept override=0
Error message.
The bulletin namespace contains bulletin implementation details, internals and utility functions.
Definition input.h:13
Utility functions for the unit tests.
Definition tests.h:38
void dump_jsonl(const Bulletin &bulletin, std::stringstream &out)
Dump a bulletin to a simple but deterministic JSON line.
std::vector< std::filesystem::path > all_test_files(const std::string &encoding)
Get a list of all test files for the given encoding.
std::string slurpfile(const std::filesystem::path &name)
Read the entire contents of a test file into a string.
std::filesystem::path path_from_env(const char *varname, const char *deflt=nullptr)
Return a path from an envirnment variable.
std::filesystem::path datafile(const std::filesystem::path &fname)
Return the pathname of a test file.
Implement fast access to information about WMO variables.