matchers.hpp
Go to the documentation of this file.
1#ifndef ECL_TEST_MATCHERS_HPP
2#define ECL_TEST_MATCHERS_HPP
3
4#include <vector>
5#include <string>
6
7#include <catch/catch.hpp>
8
9class FstreamCount : public Catch::MatcherBase< int > {
10 public:
11 FstreamCount( int ex ) : expected( ex ) {}
12
13 virtual bool match( const int& count ) const override {
14 return count == this->expected;
15 }
16
17 protected:
19};
20
21struct FreadCount : public FstreamCount {
23 virtual std::string describe() const override {
24 return "elems read, expected " + std::to_string( this->expected );
25 }
26};
27
28struct FwriteCount : public FstreamCount {
30
31 virtual std::string describe() const override {
32 return "elems written, expected " + std::to_string( this->expected );
33 }
34};
35
36struct Err {
37 Err( int ex ) : expected( ex ) {}
38
39 bool operator == ( Err other ) const {
40 return this->expected == other.expected;
41 }
42 bool operator != ( Err other ) const {
43 return !(*this == other);
44 }
45
46 static Err ok() { return ECL_OK; }
48 static Err read() { return ECL_ERR_READ; }
49
51};
52
53namespace Catch {
54template<>
55struct StringMaker< Err > {
56 static std::string convert( const Err& err ) {
57 switch( err.expected ) {
58 case ECL_OK: return "OK";
59 case ECL_ERR_SEEK: return "SEEK";
60 case ECL_ERR_READ: return "READ";
61 case ECL_ERR_WRITE: return "WRITE";
62 case ECL_INVALID_RECORD: return "INVALID RECORD";
63 case ECL_EINVAL: return "INVALID ARGUMENT";
64 case ECL_ERR_UNKNOWN: return "UNKNOWN";
65 }
66
67 return "Unknown error";
68 }
69};
70
71}
72
73#endif //ECL_TEST_MATCHERS_HPP
int count
Definition: cJSON.h:212
const char *const string
Definition: cJSON.h:170
Definition: matchers.hpp:9
virtual bool match(const int &count) const override
Definition: matchers.hpp:13
int expected
Definition: matchers.hpp:18
FstreamCount(int ex)
Definition: matchers.hpp:11
@ ECL_OK
Definition: e3/ecl/fortio.h:170
@ ECL_ERR_SEEK
Definition: e3/ecl/fortio.h:172
@ ECL_ERR_READ
Definition: e3/ecl/fortio.h:173
@ ECL_ERR_WRITE
Definition: e3/ecl/fortio.h:174
@ ECL_ERR_UNKNOWN
Definition: e3/ecl/fortio.h:171
@ ECL_EINVAL
Definition: e3/ecl/fortio.h:176
@ ECL_INVALID_RECORD
Definition: e3/ecl/fortio.h:175
Definition: catch.hpp:90
Definition: catch.hpp:2277
static std::string convert(const Err &err)
Definition: matchers.hpp:56
Definition: catch.hpp:829
Definition: matchers.hpp:36
static Err invalid_record()
Definition: matchers.hpp:47
bool operator!=(Err other) const
Definition: matchers.hpp:42
static Err read()
Definition: matchers.hpp:48
static Err ok()
Definition: matchers.hpp:46
bool operator==(Err other) const
Definition: matchers.hpp:39
Err(int ex)
Definition: matchers.hpp:37
int expected
Definition: matchers.hpp:50
Definition: matchers.hpp:21
virtual std::string describe() const override
Definition: matchers.hpp:23
Definition: matchers.hpp:28
virtual std::string describe() const override
Definition: matchers.hpp:31