41 using std::stringstream;
46 using testing::Cardinality;
47 using testing::CardinalityInterface;
50 using testing::MakeCardinality;
62 TEST(CardinalityTest, IsDefaultConstructable) {
67 TEST(CardinalityTest, IsCopyable) {
81 TEST(CardinalityTest, IsOverSaturatedByCallCountWorks) {
82 const Cardinality c =
AtMost(5);
90 TEST(CardinalityTest, CanDescribeActualCallCount) {
92 Cardinality::DescribeActualCallCountTo(0, &ss0);
96 Cardinality::DescribeActualCallCountTo(1, &ss1);
100 Cardinality::DescribeActualCallCountTo(2, &ss2);
104 Cardinality::DescribeActualCallCountTo(3, &ss3);
126 TEST(AnyNumberTest, HasCorrectBounds) {
128 EXPECT_EQ(0, c.ConservativeLowerBound());
129 EXPECT_EQ(INT_MAX, c.ConservativeUpperBound());
134 TEST(AtLeastTest, OnNegativeNumber) {
137 },
"The invocation lower bound must be >= 0");
140 TEST(AtLeastTest, OnZero) {
141 const Cardinality c =
AtLeast(0);
154 TEST(AtLeastTest, OnPositiveNumber) {
155 const Cardinality c =
AtLeast(2);
181 TEST(AtLeastTest, HasCorrectBounds) {
182 const Cardinality c =
AtLeast(2);
183 EXPECT_EQ(2, c.ConservativeLowerBound());
184 EXPECT_EQ(INT_MAX, c.ConservativeUpperBound());
189 TEST(AtMostTest, OnNegativeNumber) {
192 },
"The invocation upper bound must be >= 0");
195 TEST(AtMostTest, OnZero) {
196 const Cardinality c =
AtMost(0);
209 TEST(AtMostTest, OnPositiveNumber) {
210 const Cardinality c =
AtMost(2);
221 AtMost(1).DescribeTo(&ss1);
231 AtMost(3).DescribeTo(&ss3);
236 TEST(AtMostTest, HasCorrectBounds) {
237 const Cardinality c =
AtMost(2);
238 EXPECT_EQ(0, c.ConservativeLowerBound());
239 EXPECT_EQ(2, c.ConservativeUpperBound());
244 TEST(BetweenTest, OnNegativeStart) {
247 },
"The invocation lower bound must be >= 0, but is actually -1");
250 TEST(BetweenTest, OnNegativeEnd) {
253 },
"The invocation upper bound must be >= 0, but is actually -2");
256 TEST(BetweenTest, OnStartBiggerThanEnd) {
259 },
"The invocation upper bound (1) must be >= "
260 "the invocation lower bound (2)");
263 TEST(BetweenTest, OnZeroStartAndZeroEnd) {
264 const Cardinality c =
Between(0, 0);
278 TEST(BetweenTest, OnZeroStartAndNonZeroEnd) {
279 const Cardinality c =
Between(0, 2);
296 TEST(BetweenTest, OnSameStartAndEnd) {
297 const Cardinality c =
Between(3, 3);
314 TEST(BetweenTest, OnDifferentStartAndEnd) {
315 const Cardinality c =
Between(3, 5);
335 TEST(BetweenTest, HasCorrectBounds) {
336 const Cardinality c =
Between(3, 5);
337 EXPECT_EQ(3, c.ConservativeLowerBound());
338 EXPECT_EQ(5, c.ConservativeUpperBound());
343 TEST(ExactlyTest, OnNegativeNumber) {
346 },
"The invocation lower bound must be >= 0");
349 TEST(ExactlyTest, OnZero) {
350 const Cardinality c =
Exactly(0);
363 TEST(ExactlyTest, OnPositiveNumber) {
364 const Cardinality c =
Exactly(2);
387 TEST(ExactlyTest, HasCorrectBounds) {
388 const Cardinality c =
Exactly(3);
389 EXPECT_EQ(3, c.ConservativeLowerBound());
390 EXPECT_EQ(3, c.ConservativeUpperBound());
396 class EvenCardinality :
public CardinalityInterface {
400 bool IsSatisfiedByCallCount(
int call_count)
const override {
401 return (call_count % 2 == 0);
406 bool IsSaturatedByCallCount(
int )
const override {
411 void DescribeTo(::std::ostream* ss)
const override {
412 *ss <<
"called even number of times";
416 TEST(MakeCardinalityTest, ConstructsCardinalityFromInterface) {
417 const Cardinality c = MakeCardinality(
new EvenCardinality);
426 EXPECT_EQ(
"called even number of times", ss.str());
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
GTEST_API_ Cardinality AtLeast(int n)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
GTEST_API_ Cardinality AtMost(int n)
#define MOCK_METHOD0(m,...)
#define TEST(test_suite_name, test_name)
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
GTEST_API_ Cardinality Between(int min, int max)
GTEST_API_ Cardinality Exactly(int n)
GTEST_API_ Cardinality AnyNumber()
#define EXPECT_EQ(val1, val2)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
#define EXPECT_TRUE(condition)
#define EXPECT_FALSE(condition)