/usr/include/wreport/tests.h is in libwreport-dev 3.6-1build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | /*
* wreport/test-utils-wreport - Unit test utilities, not included in the library
*
* Copyright (C) 2005--2011 ARPA-SIM <urpsim@smr.arpa.emr.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Enrico Zini <enrico@enricozini.com>
*/
#ifndef WREPORT_TESTS_UTILS
#define WREPORT_TESTS_UTILS
#include <wreport/utils/tests.h>
#include <wreport/varinfo.h>
#include <wreport/bulletin.h>
#include <wreport/tests.h>
#include <wreport/notes.h>
#include <string>
#include <vector>
#include <memory>
#include <iostream>
#include <cstdlib>
namespace wreport {
struct Var;
namespace tests {
/// Return the pathname of a test file
std::string datafile(const std::string& fname);
/**
* Read the entire contents of a test file into a string
*
* The file name will be resolved through datafile
*/
std::string slurpfile(const std::string& name);
/**
* Get a list of all test files for the given encoding
*/
std::vector<std::string> all_test_files(const std::string& encoding);
void track_bulletin(Bulletin& b, const char* tag, const char* fname);
template<typename BULLETIN>
std::unique_ptr<BULLETIN> decode_checked(const std::string& buf, const char* name)
{
try {
return BULLETIN::decode(buf, name);
} catch (wreport::error_parse& e) {
try {
auto h = BULLETIN::decode_header(buf, name);
h->print_structured(stderr);
} catch (wreport::error& e) {
std::cerr << "Dump interrupted: " << e.what();
}
throw;
}
}
template<typename BULLETIN>
struct TestCodec
{
std::string fname;
std::function<void(const BULLETIN&)> check_contents = [](const BULLETIN&) {};
TestCodec(const std::string& fname) : fname(fname) {}
virtual ~TestCodec() {}
void run();
};
void assert_var_equal(const Var& actual, const Var& expected);
void assert_var_not_equal(const Var& actual, const Var& expected);
template<typename Val>
void assert_var_value_equal(const Var& actual, Val expected);
template<typename Val>
void assert_var_value_not_equal(const Var& actual, Val expected);
struct ActualVar : public Actual<Var>
{
ActualVar(const Var& actual) : Actual<Var>(actual) {}
void operator==(const Var& expected) const { assert_var_equal(_actual, expected); }
void operator!=(const Var& expected) const { assert_var_not_equal(_actual, expected); }
template<typename Val>
void operator==(Val expected) const { assert_var_value_equal(_actual, expected); }
template<typename Val>
void operator!=(Val expected) const { assert_var_value_not_equal(_actual, expected); }
void isset() const;
void isunset() const;
};
inline ActualVar actual(const wreport::Var& actual) { return ActualVar(actual); }
struct ActualVarcode : public Actual<Varcode>
{
using Actual::Actual;
void operator==(Varcode expected) const;
void operator!=(Varcode expected) const;
};
inline ActualVarcode actual_varcode(Varcode actual) { return ActualVarcode(actual); }
}
}
#endif
|