42using std::stringstream;
63TEST(CardinalityTest, IsDefaultConstructable) {
68TEST(CardinalityTest, IsCopyable) {
70 Cardinality c = Exactly(1);
82TEST(CardinalityTest, IsOverSaturatedByCallCountWorks) {
83 const Cardinality c = AtMost(5);
91TEST(CardinalityTest, CanDescribeActualCallCount) {
93 Cardinality::DescribeActualCallCountTo(0, &ss0);
97 Cardinality::DescribeActualCallCountTo(1, &ss1);
101 Cardinality::DescribeActualCallCountTo(2, &ss2);
105 Cardinality::DescribeActualCallCountTo(3, &ss3);
110TEST(AnyNumber, Works) {
111 const Cardinality c = AnyNumber();
127TEST(AnyNumberTest, HasCorrectBounds) {
128 const Cardinality c = AnyNumber();
129 EXPECT_EQ(0, c.ConservativeLowerBound());
130 EXPECT_EQ(INT_MAX, c.ConservativeUpperBound());
135TEST(AtLeastTest, OnNegativeNumber) {
138 },
"The invocation lower bound must be >= 0");
141TEST(AtLeastTest, OnZero) {
142 const Cardinality c = AtLeast(0);
155TEST(AtLeastTest, OnPositiveNumber) {
156 const Cardinality c = AtLeast(2);
167 AtLeast(1).DescribeTo(&ss1);
177 AtLeast(3).DescribeTo(&ss3);
182TEST(AtLeastTest, HasCorrectBounds) {
183 const Cardinality c = AtLeast(2);
184 EXPECT_EQ(2, c.ConservativeLowerBound());
185 EXPECT_EQ(INT_MAX, c.ConservativeUpperBound());
190TEST(AtMostTest, OnNegativeNumber) {
193 },
"The invocation upper bound must be >= 0");
196TEST(AtMostTest, OnZero) {
197 const Cardinality c = AtMost(0);
210TEST(AtMostTest, OnPositiveNumber) {
211 const Cardinality c = AtMost(2);
222 AtMost(1).DescribeTo(&ss1);
232 AtMost(3).DescribeTo(&ss3);
237TEST(AtMostTest, HasCorrectBounds) {
238 const Cardinality c = AtMost(2);
239 EXPECT_EQ(0, c.ConservativeLowerBound());
240 EXPECT_EQ(2, c.ConservativeUpperBound());
245TEST(BetweenTest, OnNegativeStart) {
248 },
"The invocation lower bound must be >= 0, but is actually -1");
251TEST(BetweenTest, OnNegativeEnd) {
254 },
"The invocation upper bound must be >= 0, but is actually -2");
257TEST(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);
279TEST(BetweenTest, OnZeroStartAndNonZeroEnd) {
280 const Cardinality c = Between(0, 2);
297TEST(BetweenTest, OnSameStartAndEnd) {
298 const Cardinality c = Between(3, 3);
315TEST(BetweenTest, OnDifferentStartAndEnd) {
316 const Cardinality c = Between(3, 5);
336TEST(BetweenTest, HasCorrectBounds) {
337 const Cardinality c = Between(3, 5);
338 EXPECT_EQ(3, c.ConservativeLowerBound());
339 EXPECT_EQ(5, c.ConservativeUpperBound());
344TEST(ExactlyTest, OnNegativeNumber) {
347 },
"The invocation lower bound must be >= 0");
350TEST(ExactlyTest, OnZero) {
351 const Cardinality c = Exactly(0);
364TEST(ExactlyTest, OnPositiveNumber) {
365 const Cardinality c = Exactly(2);
373 Exactly(1).DescribeTo(&ss1);
383 Exactly(3).DescribeTo(&ss3);
388TEST(ExactlyTest, HasCorrectBounds) {
389 const Cardinality c = Exactly(3);
390 EXPECT_EQ(3, c.ConservativeLowerBound());
391 EXPECT_EQ(3, c.ConservativeUpperBound());
397class EvenCardinality :
public CardinalityInterface {
400 virtual bool IsSatisfiedByCallCount(
int call_count)
const {
401 return (call_count % 2 == 0);
405 virtual bool IsSaturatedByCallCount(
int )
const {
410 virtual void DescribeTo(::std::ostream* ss)
const {
411 *
ss <<
"called even number of times";
415TEST(MakeCardinalityTest, ConstructsCardinalityFromInterface) {
416 const Cardinality c = MakeCardinality(
new EvenCardinality);
425 EXPECT_EQ(
"called even number of times",
ss.str());
#define MOCK_METHOD0(m,...)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define EXPECT_EQ(val1, val2)
#define EXPECT_TRUE(condition)
#define TEST(test_case_name, test_name)
#define EXPECT_FALSE(condition)
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
static const Segment ss(Segment::ss)
GTEST_API_ Cardinality AtLeast(int n)
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 AtMost(int n)
GTEST_API_ Cardinality AnyNumber()
GTEST_API_ Cardinality Exactly(int n)
Cardinality MakeCardinality(const CardinalityInterface *c)