-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvocation.hpp
More file actions
174 lines (147 loc) · 3.85 KB
/
Copy pathinvocation.hpp
File metadata and controls
174 lines (147 loc) · 3.85 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//
// Copyright Mathieu Champlon 2008
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MOCK_INVOCATION_HPP_INCLUDED
#define MOCK_INVOCATION_HPP_INCLUDED
#include <boost/noncopyable.hpp>
#include <stdexcept>
#include <ostream>
#include <limits>
namespace mock
{
namespace detail
{
class invocation : private boost::noncopyable
{
public:
invocation() {}
virtual ~invocation() {}
virtual bool invoke() = 0;
virtual bool verify() const = 0;
virtual bool invoked() const = 0;
virtual bool exhausted() const = 0;
friend inline std::ostream& operator<<( std::ostream& s, const invocation& i )
{
return i.serialize( s );
}
private:
virtual std::ostream& serialize( std::ostream& s ) const = 0;
};
class between : public invocation
{
public:
between( std::size_t min, std::size_t max )
: min_ ( min )
, max_ ( max )
, count_( 0 )
{
if( min > max )
throw std::invalid_argument( "'min' > 'max'" );
}
virtual bool invoke()
{
if( count_ == max_ )
return false;
++count_;
return true;
}
virtual bool invoked() const
{
return count_ > 0;
}
virtual bool exhausted() const
{
return count_ >= max_;
}
virtual bool verify() const
{
return min_ <= count_ && count_ <= max_;
}
protected:
const std::size_t min_, max_;
std::size_t count_;
private:
virtual std::ostream& serialize( std::ostream& s ) const
{
return s << "between( " << count_ << "/[" << min_ << ',' << max_ << "] )";
}
};
class exactly : public between
{
public:
explicit exactly( std::size_t count )
: between( count, count )
{}
private:
virtual std::ostream& serialize( std::ostream& s ) const
{
return s << "exactly( " << count_ << '/' << max_ << " )";
}
};
class never : public exactly
{
public:
never()
: exactly( 0 )
{}
private:
virtual std::ostream& serialize( std::ostream& s ) const
{
return s << "never()";
}
};
class once : public exactly
{
public:
once()
: exactly( 1 )
{}
private:
virtual std::ostream& serialize( std::ostream& s ) const
{
return s << "once()";
}
};
class at_least : public between
{
public:
explicit at_least( std::size_t min )
: between( min, std::numeric_limits< std::size_t >::max() )
{}
private:
virtual std::ostream& serialize( std::ostream& s ) const
{
return s << "at_least( " << count_ << '/' << min_ << " )";
}
};
class at_most : public between
{
public:
explicit at_most( std::size_t max )
: between( 0, max )
{}
private:
virtual std::ostream& serialize( std::ostream& s ) const
{
return s << "at_most( " << count_ << '/' << max_ << " )";
}
};
class unlimited : public at_least
{
public:
unlimited()
: at_least( 0 )
{}
private:
virtual std::ostream& serialize( std::ostream& s ) const
{
return s << "unlimited()";
}
};
}
}
#endif // MOCK_INVOCATION_HPP_INCLUDED