50class BetweenCardinalityImpl :
public CardinalityInterface {
52 BetweenCardinalityImpl(
int min,
int max)
53 : min_(min >= 0 ? min : 0), max_(max >= min_ ? max : min_) {
56 ss <<
"The invocation lower bound must be >= 0, "
57 <<
"but is actually " << min <<
".";
60 ss <<
"The invocation upper bound must be >= 0, "
61 <<
"but is actually " << max <<
".";
63 }
else if (min > max) {
64 ss <<
"The invocation upper bound (" << max
65 <<
") must be >= the invocation lower bound (" << min <<
").";
72 int ConservativeLowerBound()
const override {
return min_; }
73 int ConservativeUpperBound()
const override {
return max_; }
75 bool IsSatisfiedByCallCount(
int call_count)
const override {
76 return min_ <= call_count && call_count <= max_;
79 bool IsSaturatedByCallCount(
int call_count)
const override {
80 return call_count >= max_;
83 void DescribeTo(::std::ostream* os)
const override;
89 BetweenCardinalityImpl(
const BetweenCardinalityImpl&) =
delete;
90 BetweenCardinalityImpl& operator=(
const BetweenCardinalityImpl&) =
delete;
94inline std::string FormatTimes(
int n) {
100 std::stringstream ss;
107void BetweenCardinalityImpl::DescribeTo(::std::ostream* os)
const {
110 *os <<
"never called";
111 }
else if (max_ == INT_MAX) {
112 *os <<
"called any number of times";
114 *os <<
"called at most " << FormatTimes(max_);
116 }
else if (min_ == max_) {
117 *os <<
"called " << FormatTimes(min_);
118 }
else if (max_ == INT_MAX) {
119 *os <<
"called at least " << FormatTimes(min_);
122 *os <<
"called between " << min_ <<
" and " << max_ <<
" times";
129void Cardinality::DescribeActualCallCountTo(
int actual_call_count,
130 ::std::ostream* os) {
131 if (actual_call_count > 0) {
132 *os <<
"called " << FormatTimes(actual_call_count);
134 *os <<
"never called";
149 return Cardinality(
new BetweenCardinalityImpl(min, max));
#define GTEST_API_
Definition gtest-port.h:842
void Expect(bool condition, const char *file, int line, const std::string &msg)
Definition gmock-internal-utils.h:255
Definition gmock-actions.h:151
GTEST_API_ Cardinality AtLeast(int n)
Definition gmock-cardinalities.cc:139
GTEST_API_ Cardinality Between(int min, int max)
Definition gmock-cardinalities.cc:148
GTEST_API_ Cardinality AtMost(int n)
Definition gmock-cardinalities.cc:142
GTEST_API_ Cardinality AnyNumber()
Definition gmock-cardinalities.cc:145
GTEST_API_ Cardinality Exactly(int n)
Definition gmock-cardinalities.cc:153