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
123
124
125
126
127
128
|
// (C) 2015 Simon Warta (Kullo GmbH)
// Botan is released under the Simplified BSD License (see license.txt)
#ifndef BOTAN_CATCHY_TESTS_H__
#define BOTAN_CATCHY_TESTS_H__
#include "catch.hpp"
#include <botan/build.h>
// BEGIN CATCH STD::VECTOR IMPLEMENTATION
// This is basically https://github.com/philsquared/Catch/pull/466
#include <vector>
#include <type_traits>
namespace Catch {
namespace Matchers {
namespace Impl {
namespace Generic {
template<typename ExpressionT>
struct Not : public MatcherImpl<Not<ExpressionT>, ExpressionT>
{
Not( Matcher<ExpressionT> const& matcher ) : m_matcher(matcher.clone()) {}
Not( Not const& other ) : m_matcher( other.m_matcher ) {}
virtual bool match( ExpressionT const& expr ) const
{
return !m_matcher->match( expr );
}
virtual std::string toString() const {
return "not " + m_matcher->toString();
}
Ptr<Matcher<ExpressionT>> m_matcher;
};
} // namespace Generic
namespace StdVector {
template<typename T, typename Alloc>
struct Equals : MatcherImpl<Equals<T, Alloc>, std::vector<T, Alloc> >
{
Equals( std::vector<T, Alloc> const& vec ) : m_vector( vec ){}
Equals( Equals const& other ) : m_vector( other.m_vector ){}
virtual ~Equals() {}
virtual bool match( std::vector<T, Alloc> const& expr ) const {
return m_vector == expr;
}
virtual std::string toString() const {
return "equals: std::vector of length " + Catch::toString(m_vector.size());
}
std::vector<T, Alloc> m_vector;
};
} // namespace StdVector
namespace Boolean {
struct Equals : MatcherImpl<Equals, bool>
{
Equals( const bool expected ) : m_expected( expected ){}
Equals( Equals const& other ) : m_expected( other.m_expected ){}
virtual ~Equals() override {}
virtual bool match( bool const& expr ) const override {
return m_expected == expr;
}
virtual std::string toString() const override {
return "== " + Catch::toString(m_expected);
}
bool m_expected;
};
} // Boolean
namespace Integer {
template<typename T>
struct Equals : MatcherImpl<Equals<T>, T>
{
Equals( const T expected ) : m_expected( expected ){}
Equals( Equals const& other ) : m_expected( other.m_expected ){}
virtual ~Equals() override {}
virtual bool match( T const& expr ) const override {
return m_expected == expr;
}
virtual std::string toString() const override {
return "== " + Catch::toString(m_expected);
}
T m_expected;
};
} // namespace Integer
} // namespace Impl
// The following functions create the actual matcher objects.
// This allows the types to be inferred
template<typename ExpressionT>
inline Impl::Generic::Not<ExpressionT> Not( Impl::Matcher<ExpressionT> const& m ) {
return Impl::Generic::Not<ExpressionT>( m );
}
template <typename T, typename Alloc>
inline Impl::StdVector::Equals<T, Alloc> Equals( std::vector<T, Alloc> const& vec ) {
return Impl::StdVector::Equals<T, Alloc>( vec );
}
template <typename T,
typename = typename std::enable_if<std::numeric_limits<T>::is_integer, T>::type>
inline Impl::Integer::Equals<T> Equals( T expected ) {
return Impl::Integer::Equals<T>( expected );
}
inline Impl::Boolean::Equals Equals( bool expected ) {
return Impl::Boolean::Equals( expected );
}
} // namespace Matchers
} // namespace Catch
// END CATCH STD::VECTOR IMPLEMENTATION
#endif // BOTAN_CATCHY_TESTS_H__
|