42using std::stringstream;
47using testing::Cardinality;
48using testing::CardinalityInterface;
51using testing::MakeCardinality;
59 MockFoo(
const MockFoo&) =
delete;
60 MockFoo& operator=(
const MockFoo&) =
delete;
64TEST(CardinalityTest, IsDefaultConstructable) { Cardinality c; }
67TEST(CardinalityTest, IsCopyable) {
69 Cardinality c = Exactly(1);
81TEST(CardinalityTest, IsOverSaturatedByCallCountWorks) {
82 const Cardinality c = AtMost(5);
90TEST(CardinalityTest, CanDescribeActualCallCount) {
92 Cardinality::DescribeActualCallCountTo(0, &ss0);
96 Cardinality::DescribeActualCallCountTo(1, &ss1);
100 Cardinality::DescribeActualCallCountTo(2, &ss2);
104 Cardinality::DescribeActualCallCountTo(3, &ss3);
109TEST(AnyNumber, Works) {
110 const Cardinality c = AnyNumber();
125TEST(AnyNumberTest, HasCorrectBounds) {
126 const Cardinality c = AnyNumber();
127 EXPECT_EQ(0, c.ConservativeLowerBound());
128 EXPECT_EQ(INT_MAX, c.ConservativeUpperBound());
133TEST(AtLeastTest, OnNegativeNumber) {
138 "The invocation lower bound must be >= 0");
141TEST(AtLeastTest, OnZero) {
142 const Cardinality c = AtLeast(0);
154TEST(AtLeastTest, OnPositiveNumber) {
155 const Cardinality c = AtLeast(2);
166 AtLeast(1).DescribeTo(&ss1);
174 AtLeast(3).DescribeTo(&ss3);
178TEST(AtLeastTest, HasCorrectBounds) {
179 const Cardinality c = AtLeast(2);
180 EXPECT_EQ(2, c.ConservativeLowerBound());
181 EXPECT_EQ(INT_MAX, c.ConservativeUpperBound());
186TEST(AtMostTest, OnNegativeNumber) {
191 "The invocation upper bound must be >= 0");
194TEST(AtMostTest, OnZero) {
195 const Cardinality c = AtMost(0);
207TEST(AtMostTest, OnPositiveNumber) {
208 const Cardinality c = AtMost(2);
219 AtMost(1).DescribeTo(&ss1);
227 AtMost(3).DescribeTo(&ss3);
231TEST(AtMostTest, HasCorrectBounds) {
232 const Cardinality c = AtMost(2);
233 EXPECT_EQ(0, c.ConservativeLowerBound());
234 EXPECT_EQ(2, c.ConservativeUpperBound());
239TEST(BetweenTest, OnNegativeStart) {
244 "The invocation lower bound must be >= 0, but is actually -1");
247TEST(BetweenTest, OnNegativeEnd) {
252 "The invocation upper bound must be >= 0, but is actually -2");
255TEST(BetweenTest, OnStartBiggerThanEnd) {
260 "The invocation upper bound (1) must be >= "
261 "the invocation lower bound (2)");
264TEST(BetweenTest, OnZeroStartAndZeroEnd) {
265 const Cardinality c = Between(0, 0);
278TEST(BetweenTest, OnZeroStartAndNonZeroEnd) {
279 const Cardinality c = Between(0, 2);
295TEST(BetweenTest, OnSameStartAndEnd) {
296 const Cardinality c = Between(3, 3);
312TEST(BetweenTest, OnDifferentStartAndEnd) {
313 const Cardinality c = Between(3, 5);
332TEST(BetweenTest, HasCorrectBounds) {
333 const Cardinality c = Between(3, 5);
334 EXPECT_EQ(3, c.ConservativeLowerBound());
335 EXPECT_EQ(5, c.ConservativeUpperBound());
340TEST(ExactlyTest, OnNegativeNumber) {
345 "The invocation lower bound must be >= 0");
348TEST(ExactlyTest, OnZero) {
349 const Cardinality c = Exactly(0);
361TEST(ExactlyTest, OnPositiveNumber) {
362 const Cardinality c = Exactly(2);
370 Exactly(1).DescribeTo(&ss1);
378 Exactly(3).DescribeTo(&ss3);
382TEST(ExactlyTest, HasCorrectBounds) {
383 const Cardinality c = Exactly(3);
384 EXPECT_EQ(3, c.ConservativeLowerBound());
385 EXPECT_EQ(3, c.ConservativeUpperBound());
391class EvenCardinality :
public CardinalityInterface {
395 bool IsSatisfiedByCallCount(
int call_count)
const override {
396 return (call_count % 2 == 0);
401 bool IsSaturatedByCallCount(
int )
const override {
406 void DescribeTo(::std::ostream* ss)
const override {
407 *ss <<
"called even number of times";
411TEST(MakeCardinalityTest, ConstructsCardinalityFromInterface) {
412 const Cardinality c = MakeCardinality(
new EvenCardinality);
421 EXPECT_EQ(
"called even number of times", ss.str());
#define MOCK_METHOD0(m,...)
Definition gmock-function-mocker.h:356
#define EXPECT_NONFATAL_FAILURE(statement, substr)
Definition gtest-spi.h:217
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1868
#define TEST(test_suite_name, test_name)
Definition gtest.h:2176
#define EXPECT_TRUE(condition)
Definition gtest.h:1807
#define EXPECT_FALSE(condition)
Definition gtest.h:1811
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
Definition gtest_pred_impl.h:143
GTEST_API_ Cardinality AtLeast(int n)
Definition gmock-cardinalities.cc:139
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
Definition gtest.cc:1835
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