36 #include "gmock/gmock.h" 37 #include "gtest/gtest.h" 38 #include "gtest/gtest-spi.h" 42 using std::stringstream;
63 TEST(CardinalityTest, IsDefaultConstructable) {
82 TEST(CardinalityTest, IsOverSaturatedByCallCountWorks) {
83 const Cardinality c =
AtMost(5);
91 TEST(CardinalityTest, CanDescribeActualCallCount) {
93 Cardinality::DescribeActualCallCountTo(0, &ss0);
97 Cardinality::DescribeActualCallCountTo(1, &ss1);
101 Cardinality::DescribeActualCallCountTo(2, &ss2);
105 Cardinality::DescribeActualCallCountTo(3, &ss3);
127 TEST(AnyNumberTest, HasCorrectBounds) {
129 EXPECT_EQ(0, c.ConservativeLowerBound());
130 EXPECT_EQ(INT_MAX, c.ConservativeUpperBound());
135 TEST(AtLeastTest, OnNegativeNumber) {
138 },
"The invocation lower bound must be >= 0");
141 TEST(AtLeastTest, OnZero) {
142 const Cardinality c =
AtLeast(0);
155 TEST(AtLeastTest, OnPositiveNumber) {
156 const Cardinality c =
AtLeast(2);
182 TEST(AtLeastTest, HasCorrectBounds) {
183 const Cardinality c =
AtLeast(2);
184 EXPECT_EQ(2, c.ConservativeLowerBound());
185 EXPECT_EQ(INT_MAX, c.ConservativeUpperBound());
190 TEST(AtMostTest, OnNegativeNumber) {
193 },
"The invocation upper bound must be >= 0");
196 TEST(AtMostTest, OnZero) {
197 const Cardinality c =
AtMost(0);
210 TEST(AtMostTest, OnPositiveNumber) {
211 const Cardinality c =
AtMost(2);
237 TEST(AtMostTest, HasCorrectBounds) {
238 const Cardinality c =
AtMost(2);
239 EXPECT_EQ(0, c.ConservativeLowerBound());
240 EXPECT_EQ(2, c.ConservativeUpperBound());
245 TEST(BetweenTest, OnNegativeStart) {
248 },
"The invocation lower bound must be >= 0, but is actually -1");
251 TEST(BetweenTest, OnNegativeEnd) {
254 },
"The invocation upper bound must be >= 0, but is actually -2");
257 TEST(BetweenTest, OnStartBiggerThanEnd) {
260 },
"The invocation upper bound (1) must be >= " 261 "the invocation lower bound (2)");
264 TEST(BetweenTest, OnZeroStartAndZeroEnd) {
265 const Cardinality c =
Between(0, 0);
279 TEST(BetweenTest, OnZeroStartAndNonZeroEnd) {
280 const Cardinality c =
Between(0, 2);
297 TEST(BetweenTest, OnSameStartAndEnd) {
298 const Cardinality c =
Between(3, 3);
315 TEST(BetweenTest, OnDifferentStartAndEnd) {
316 const Cardinality c =
Between(3, 5);
336 TEST(BetweenTest, HasCorrectBounds) {
337 const Cardinality c =
Between(3, 5);
338 EXPECT_EQ(3, c.ConservativeLowerBound());
339 EXPECT_EQ(5, c.ConservativeUpperBound());
344 TEST(ExactlyTest, OnNegativeNumber) {
347 },
"The invocation lower bound must be >= 0");
350 TEST(ExactlyTest, OnZero) {
351 const Cardinality c =
Exactly(0);
364 TEST(ExactlyTest, OnPositiveNumber) {
365 const Cardinality c =
Exactly(2);
388 TEST(ExactlyTest, HasCorrectBounds) {
389 const Cardinality c =
Exactly(3);
390 EXPECT_EQ(3, c.ConservativeLowerBound());
391 EXPECT_EQ(3, c.ConservativeUpperBound());
397 class 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";
415 TEST(MakeCardinalityTest, ConstructsCardinalityFromInterface) {
425 EXPECT_EQ(
"called even number of times", ss.str());
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
#define TEST(test_case_name, test_name)
GTEST_API_ Cardinality AtLeast(int n)
GTEST_API_ Cardinality AtMost(int n)
#define EXPECT_EQ(val1, val2)
void DescribeTo(::std::ostream *os) const
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
Cardinality MakeCardinality(const CardinalityInterface *c)
GTEST_API_ Cardinality Between(int min, int max)
GTEST_API_ Cardinality Exactly(int n)
#define EXPECT_TRUE(condition)
GTEST_API_ Cardinality AnyNumber()
StrictConjunction< std::is_copy_constructible< T >, std::is_copy_assignable< T >> IsCopyable
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define EXPECT_FALSE(condition)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
#define MOCK_METHOD0(m,...)