Commit b007c54f authored by Abseil Team's avatar Abseil Team Committed by Copybara-Service
Browse files

Running clang-format over all of GoogleTest

A few tests are examining code locations and looking af the resulting line
numbers to verify that GoogleTest shows those to users correctly. Some of those
locations change when clang-format is run. For those locations, I've wrapped
portions in:
// clang-format off
...
// clang-format on

There may be other locations that are currently not tickled by running
clang-format.

PiperOrigin-RevId: 434844712
Change-Id: I3a9f0a6f39eff741c576b6de389bef9b1d11139d
parent 8a422b83
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest-spi.h" #include "gtest/gtest-spi.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
...@@ -102,7 +103,8 @@ class MockBar { ...@@ -102,7 +103,8 @@ class MockBar {
MockBar(char a1, char a2, std::string a3, std::string a4, int a5, int a6, MockBar(char a1, char a2, std::string a3, std::string a4, int a5, int a6,
const std::string& a7, const std::string& a8, bool a9, bool a10) { const std::string& a7, const std::string& a8, bool a9, bool a10) {
str_ = std::string() + a1 + a2 + a3 + a4 + static_cast<char>(a5) + str_ = std::string() + a1 + a2 + a3 + a4 + static_cast<char>(a5) +
static_cast<char>(a6) + a7 + a8 + (a9 ? 'T' : 'F') + (a10 ? 'T' : 'F'); static_cast<char>(a6) + a7 + a8 + (a9 ? 'T' : 'F') +
(a10 ? 'T' : 'F');
} }
virtual ~MockBar() {} virtual ~MockBar() {}
...@@ -118,7 +120,6 @@ class MockBar { ...@@ -118,7 +120,6 @@ class MockBar {
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar); GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar);
}; };
class MockBaz { class MockBaz {
public: public:
class MoveOnly { class MoveOnly {
...@@ -161,8 +162,7 @@ TEST(RawMockTest, WarningForUninterestingCallAfterDeath) { ...@@ -161,8 +162,7 @@ TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
MockFoo* const raw_foo = new MockFoo; MockFoo* const raw_foo = new MockFoo;
ON_CALL(*raw_foo, DoThis()) ON_CALL(*raw_foo, DoThis()).WillByDefault(Invoke(raw_foo, &MockFoo::Delete));
.WillByDefault(Invoke(raw_foo, &MockFoo::Delete));
CaptureStdout(); CaptureStdout();
raw_foo->DoThis(); raw_foo->DoThis();
...@@ -280,8 +280,8 @@ TEST(NiceMockTest, NonDefaultConstructor) { ...@@ -280,8 +280,8 @@ TEST(NiceMockTest, NonDefaultConstructor) {
// Tests that NiceMock works with a mock class that has a 10-ary // Tests that NiceMock works with a mock class that has a 10-ary
// non-default constructor. // non-default constructor.
TEST(NiceMockTest, NonDefaultConstructor10) { TEST(NiceMockTest, NonDefaultConstructor10) {
NiceMock<MockBar> nice_bar('a', 'b', "c", "d", 'e', 'f', NiceMock<MockBar> nice_bar('a', 'b', "c", "d", 'e', 'f', "g", "h", true,
"g", "h", true, false); false);
EXPECT_EQ("abcdefghTF", nice_bar.str()); EXPECT_EQ("abcdefghTF", nice_bar.str());
nice_bar.This(); nice_bar.This();
...@@ -390,8 +390,8 @@ TEST(NaggyMockTest, NonDefaultConstructor) { ...@@ -390,8 +390,8 @@ TEST(NaggyMockTest, NonDefaultConstructor) {
// Tests that NaggyMock works with a mock class that has a 10-ary // Tests that NaggyMock works with a mock class that has a 10-ary
// non-default constructor. // non-default constructor.
TEST(NaggyMockTest, NonDefaultConstructor10) { TEST(NaggyMockTest, NonDefaultConstructor10) {
NaggyMock<MockBar> naggy_bar('0', '1', "2", "3", '4', '5', NaggyMock<MockBar> naggy_bar('0', '1', "2", "3", '4', '5', "6", "7", true,
"6", "7", true, false); false);
EXPECT_EQ("01234567TF", naggy_bar.str()); EXPECT_EQ("01234567TF", naggy_bar.str());
naggy_bar.This(); naggy_bar.This();
...@@ -490,8 +490,8 @@ TEST(StrictMockTest, NonDefaultConstructor) { ...@@ -490,8 +490,8 @@ TEST(StrictMockTest, NonDefaultConstructor) {
// Tests that StrictMock works with a mock class that has a 10-ary // Tests that StrictMock works with a mock class that has a 10-ary
// non-default constructor. // non-default constructor.
TEST(StrictMockTest, NonDefaultConstructor10) { TEST(StrictMockTest, NonDefaultConstructor10) {
StrictMock<MockBar> strict_bar('a', 'b', "c", "d", 'e', 'f', StrictMock<MockBar> strict_bar('a', 'b', "c", "d", 'e', 'f', "g", "h", true,
"g", "h", true, false); false);
EXPECT_EQ("abcdefghTF", strict_bar.str()); EXPECT_EQ("abcdefghTF", strict_bar.str());
EXPECT_NONFATAL_FAILURE(strict_bar.That(5, true), EXPECT_NONFATAL_FAILURE(strict_bar.That(5, true),
......
...@@ -27,12 +27,12 @@ ...@@ -27,12 +27,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file tests the internal cross-platform support utilities. // This file tests the internal cross-platform support utilities.
#include "gmock/internal/gmock-port.h" #include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
// NOTE: if this file is left without tests for some reason, put a dummy // NOTE: if this file is left without tests for some reason, put a dummy
......
...@@ -30,11 +30,10 @@ ...@@ -30,11 +30,10 @@
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file tests the internal preprocessor macro library. // This file tests the internal preprocessor macro library.
#include "gmock/internal/gmock-pp.h"
#include <string> #include <string>
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gmock/internal/gmock-pp.h"
namespace testing { namespace testing {
namespace { namespace {
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file tests the spec builder syntax. // This file tests the spec builder syntax.
...@@ -41,8 +40,8 @@ ...@@ -41,8 +40,8 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gmock/internal/gmock-port.h" #include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h" #include "gtest/gtest-spi.h"
#include "gtest/gtest.h"
#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-port.h"
namespace testing { namespace testing {
...@@ -52,9 +51,7 @@ namespace internal { ...@@ -52,9 +51,7 @@ namespace internal {
class ExpectationTester { class ExpectationTester {
public: public:
// Sets the call count of the given expectation to the given number. // Sets the call count of the given expectation to the given number.
void SetCallCount(int n, ExpectationBase* exp) { void SetCallCount(int n, ExpectationBase* exp) { exp->call_count_ = n; }
exp->call_count_ = n;
}
}; };
} // namespace internal } // namespace internal
...@@ -125,8 +122,7 @@ TEST(MockMethodTest, CanInstantiateWithIncompleteArgType) { ...@@ -125,8 +122,7 @@ TEST(MockMethodTest, CanInstantiateWithIncompleteArgType) {
// use the mock, as long as Google Mock knows how to print the // use the mock, as long as Google Mock knows how to print the
// argument. // argument.
MockIncomplete incomplete; MockIncomplete incomplete;
EXPECT_CALL(incomplete, ByRefFunc(_)) EXPECT_CALL(incomplete, ByRefFunc(_)).Times(AnyNumber());
.Times(AnyNumber());
} }
// The definition of the printer for the argument type doesn't have to // The definition of the printer for the argument type doesn't have to
...@@ -162,7 +158,7 @@ class MockB { ...@@ -162,7 +158,7 @@ class MockB {
MockB() {} MockB() {}
MOCK_CONST_METHOD0(DoB, int()); // NOLINT MOCK_CONST_METHOD0(DoB, int()); // NOLINT
MOCK_METHOD1(DoB, int(int n)); // NOLINT MOCK_METHOD1(DoB, int(int n)); // NOLINT
private: private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockB); GTEST_DISALLOW_COPY_AND_ASSIGN_(MockB);
...@@ -253,41 +249,42 @@ TEST(OnCallSyntaxTest, EvaluatesSecondArgumentOnce) { ...@@ -253,41 +249,42 @@ TEST(OnCallSyntaxTest, EvaluatesSecondArgumentOnce) {
TEST(OnCallSyntaxTest, WithIsOptional) { TEST(OnCallSyntaxTest, WithIsOptional) {
MockA a; MockA a;
ON_CALL(a, DoA(5)) ON_CALL(a, DoA(5)).WillByDefault(Return());
.WillByDefault(Return()); ON_CALL(a, DoA(_)).With(_).WillByDefault(Return());
ON_CALL(a, DoA(_))
.With(_)
.WillByDefault(Return());
} }
TEST(OnCallSyntaxTest, WithCanAppearAtMostOnce) { TEST(OnCallSyntaxTest, WithCanAppearAtMostOnce) {
MockA a; MockA a;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
ON_CALL(a, ReturnResult(_)) { // NOLINT
.With(_) ON_CALL(a, ReturnResult(_))
.With(_) .With(_)
.WillByDefault(Return(Result())); .With(_)
}, ".With() cannot appear more than once in an ON_CALL()"); .WillByDefault(Return(Result()));
},
".With() cannot appear more than once in an ON_CALL()");
} }
TEST(OnCallSyntaxTest, WillByDefaultIsMandatory) { TEST(OnCallSyntaxTest, WillByDefaultIsMandatory) {
MockA a; MockA a;
EXPECT_DEATH_IF_SUPPORTED({ EXPECT_DEATH_IF_SUPPORTED(
ON_CALL(a, DoA(5)); {
a.DoA(5); ON_CALL(a, DoA(5));
}, ""); a.DoA(5);
},
"");
} }
TEST(OnCallSyntaxTest, WillByDefaultCanAppearAtMostOnce) { TEST(OnCallSyntaxTest, WillByDefaultCanAppearAtMostOnce) {
MockA a; MockA a;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
ON_CALL(a, DoA(5)) { // NOLINT
.WillByDefault(Return()) ON_CALL(a, DoA(5)).WillByDefault(Return()).WillByDefault(Return());
.WillByDefault(Return()); },
}, ".WillByDefault() must appear exactly once in an ON_CALL()"); ".WillByDefault() must appear exactly once in an ON_CALL()");
} }
// Tests that EXPECT_CALL evaluates its arguments exactly once as // Tests that EXPECT_CALL evaluates its arguments exactly once as
...@@ -315,21 +312,18 @@ TEST(ExpectCallSyntaxTest, EvaluatesSecondArgumentOnce) { ...@@ -315,21 +312,18 @@ TEST(ExpectCallSyntaxTest, EvaluatesSecondArgumentOnce) {
TEST(ExpectCallSyntaxTest, WithIsOptional) { TEST(ExpectCallSyntaxTest, WithIsOptional) {
MockA a; MockA a;
EXPECT_CALL(a, DoA(5)) EXPECT_CALL(a, DoA(5)).Times(0);
.Times(0); EXPECT_CALL(a, DoA(6)).With(_).Times(0);
EXPECT_CALL(a, DoA(6))
.With(_)
.Times(0);
} }
TEST(ExpectCallSyntaxTest, WithCanAppearAtMostOnce) { TEST(ExpectCallSyntaxTest, WithCanAppearAtMostOnce) {
MockA a; MockA a;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_CALL(a, DoA(6)) { // NOLINT
.With(_) EXPECT_CALL(a, DoA(6)).With(_).With(_);
.With(_); },
}, ".With() cannot appear more than once in an EXPECT_CALL()"); ".With() cannot appear more than once in an EXPECT_CALL()");
a.DoA(6); a.DoA(6);
} }
...@@ -337,19 +331,19 @@ TEST(ExpectCallSyntaxTest, WithCanAppearAtMostOnce) { ...@@ -337,19 +331,19 @@ TEST(ExpectCallSyntaxTest, WithCanAppearAtMostOnce) {
TEST(ExpectCallSyntaxTest, WithMustBeFirstClause) { TEST(ExpectCallSyntaxTest, WithMustBeFirstClause) {
MockA a; MockA a;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_CALL(a, DoA(1)) { // NOLINT
.Times(1) EXPECT_CALL(a, DoA(1)).Times(1).With(_);
.With(_); },
}, ".With() must be the first clause in an EXPECT_CALL()"); ".With() must be the first clause in an EXPECT_CALL()");
a.DoA(1); a.DoA(1);
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_CALL(a, DoA(2)) { // NOLINT
.WillOnce(Return()) EXPECT_CALL(a, DoA(2)).WillOnce(Return()).With(_);
.With(_); },
}, ".With() must be the first clause in an EXPECT_CALL()"); ".With() must be the first clause in an EXPECT_CALL()");
a.DoA(2); a.DoA(2);
} }
...@@ -357,12 +351,9 @@ TEST(ExpectCallSyntaxTest, WithMustBeFirstClause) { ...@@ -357,12 +351,9 @@ TEST(ExpectCallSyntaxTest, WithMustBeFirstClause) {
TEST(ExpectCallSyntaxTest, TimesCanBeInferred) { TEST(ExpectCallSyntaxTest, TimesCanBeInferred) {
MockA a; MockA a;
EXPECT_CALL(a, DoA(1)) EXPECT_CALL(a, DoA(1)).WillOnce(Return());
.WillOnce(Return());
EXPECT_CALL(a, DoA(2)) EXPECT_CALL(a, DoA(2)).WillOnce(Return()).WillRepeatedly(Return());
.WillOnce(Return())
.WillRepeatedly(Return());
a.DoA(1); a.DoA(1);
a.DoA(2); a.DoA(2);
...@@ -372,11 +363,11 @@ TEST(ExpectCallSyntaxTest, TimesCanBeInferred) { ...@@ -372,11 +363,11 @@ TEST(ExpectCallSyntaxTest, TimesCanBeInferred) {
TEST(ExpectCallSyntaxTest, TimesCanAppearAtMostOnce) { TEST(ExpectCallSyntaxTest, TimesCanAppearAtMostOnce) {
MockA a; MockA a;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_CALL(a, DoA(1)) { // NOLINT
.Times(1) EXPECT_CALL(a, DoA(1)).Times(1).Times(2);
.Times(2); },
}, ".Times() cannot appear more than once in an EXPECT_CALL()"); ".Times() cannot appear more than once in an EXPECT_CALL()");
a.DoA(1); a.DoA(1);
a.DoA(1); a.DoA(1);
...@@ -386,11 +377,11 @@ TEST(ExpectCallSyntaxTest, TimesMustBeBeforeInSequence) { ...@@ -386,11 +377,11 @@ TEST(ExpectCallSyntaxTest, TimesMustBeBeforeInSequence) {
MockA a; MockA a;
Sequence s; Sequence s;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_CALL(a, DoA(1)) { // NOLINT
.InSequence(s) EXPECT_CALL(a, DoA(1)).InSequence(s).Times(1);
.Times(1); },
}, ".Times() may only appear *before* "); ".Times() may only appear *before* ");
a.DoA(1); a.DoA(1);
} }
...@@ -400,8 +391,7 @@ TEST(ExpectCallSyntaxTest, InSequenceIsOptional) { ...@@ -400,8 +391,7 @@ TEST(ExpectCallSyntaxTest, InSequenceIsOptional) {
Sequence s; Sequence s;
EXPECT_CALL(a, DoA(1)); EXPECT_CALL(a, DoA(1));
EXPECT_CALL(a, DoA(2)) EXPECT_CALL(a, DoA(2)).InSequence(s);
.InSequence(s);
a.DoA(1); a.DoA(1);
a.DoA(2); a.DoA(2);
...@@ -411,9 +401,7 @@ TEST(ExpectCallSyntaxTest, InSequenceCanAppearMultipleTimes) { ...@@ -411,9 +401,7 @@ TEST(ExpectCallSyntaxTest, InSequenceCanAppearMultipleTimes) {
MockA a; MockA a;
Sequence s1, s2; Sequence s1, s2;
EXPECT_CALL(a, DoA(1)) EXPECT_CALL(a, DoA(1)).InSequence(s1, s2).InSequence(s1);
.InSequence(s1, s2)
.InSequence(s1);
a.DoA(1); a.DoA(1);
} }
...@@ -422,13 +410,12 @@ TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeAfter) { ...@@ -422,13 +410,12 @@ TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeAfter) {
MockA a; MockA a;
Sequence s; Sequence s;
Expectation e = EXPECT_CALL(a, DoA(1)) Expectation e = EXPECT_CALL(a, DoA(1)).Times(AnyNumber());
.Times(AnyNumber()); EXPECT_NONFATAL_FAILURE(
EXPECT_NONFATAL_FAILURE({ // NOLINT { // NOLINT
EXPECT_CALL(a, DoA(2)) EXPECT_CALL(a, DoA(2)).After(e).InSequence(s);
.After(e) },
.InSequence(s); ".InSequence() cannot appear after ");
}, ".InSequence() cannot appear after ");
a.DoA(2); a.DoA(2);
} }
...@@ -437,11 +424,11 @@ TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeWillOnce) { ...@@ -437,11 +424,11 @@ TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeWillOnce) {
MockA a; MockA a;
Sequence s; Sequence s;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_CALL(a, DoA(1)) { // NOLINT
.WillOnce(Return()) EXPECT_CALL(a, DoA(1)).WillOnce(Return()).InSequence(s);
.InSequence(s); },
}, ".InSequence() cannot appear after "); ".InSequence() cannot appear after ");
a.DoA(1); a.DoA(1);
} }
...@@ -450,11 +437,9 @@ TEST(ExpectCallSyntaxTest, AfterMustBeBeforeWillOnce) { ...@@ -450,11 +437,9 @@ TEST(ExpectCallSyntaxTest, AfterMustBeBeforeWillOnce) {
MockA a; MockA a;
Expectation e = EXPECT_CALL(a, DoA(1)); Expectation e = EXPECT_CALL(a, DoA(1));
EXPECT_NONFATAL_FAILURE({ EXPECT_NONFATAL_FAILURE(
EXPECT_CALL(a, DoA(2)) { EXPECT_CALL(a, DoA(2)).WillOnce(Return()).After(e); },
.WillOnce(Return()) ".After() cannot appear after ");
.After(e);
}, ".After() cannot appear after ");
a.DoA(1); a.DoA(1);
a.DoA(2); a.DoA(2);
...@@ -464,8 +449,7 @@ TEST(ExpectCallSyntaxTest, WillIsOptional) { ...@@ -464,8 +449,7 @@ TEST(ExpectCallSyntaxTest, WillIsOptional) {
MockA a; MockA a;
EXPECT_CALL(a, DoA(1)); EXPECT_CALL(a, DoA(1));
EXPECT_CALL(a, DoA(2)) EXPECT_CALL(a, DoA(2)).WillOnce(Return());
.WillOnce(Return());
a.DoA(1); a.DoA(1);
a.DoA(2); a.DoA(2);
...@@ -484,11 +468,11 @@ TEST(ExpectCallSyntaxTest, WillCanAppearMultipleTimes) { ...@@ -484,11 +468,11 @@ TEST(ExpectCallSyntaxTest, WillCanAppearMultipleTimes) {
TEST(ExpectCallSyntaxTest, WillMustBeBeforeWillRepeatedly) { TEST(ExpectCallSyntaxTest, WillMustBeBeforeWillRepeatedly) {
MockA a; MockA a;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_CALL(a, DoA(1)) { // NOLINT
.WillRepeatedly(Return()) EXPECT_CALL(a, DoA(1)).WillRepeatedly(Return()).WillOnce(Return());
.WillOnce(Return()); },
}, ".WillOnce() cannot appear after "); ".WillOnce() cannot appear after ");
a.DoA(1); a.DoA(1);
} }
...@@ -496,11 +480,8 @@ TEST(ExpectCallSyntaxTest, WillMustBeBeforeWillRepeatedly) { ...@@ -496,11 +480,8 @@ TEST(ExpectCallSyntaxTest, WillMustBeBeforeWillRepeatedly) {
TEST(ExpectCallSyntaxTest, WillRepeatedlyIsOptional) { TEST(ExpectCallSyntaxTest, WillRepeatedlyIsOptional) {
MockA a; MockA a;
EXPECT_CALL(a, DoA(1)) EXPECT_CALL(a, DoA(1)).WillOnce(Return());
.WillOnce(Return()); EXPECT_CALL(a, DoA(2)).WillOnce(Return()).WillRepeatedly(Return());
EXPECT_CALL(a, DoA(2))
.WillOnce(Return())
.WillRepeatedly(Return());
a.DoA(1); a.DoA(1);
a.DoA(2); a.DoA(2);
...@@ -510,30 +491,30 @@ TEST(ExpectCallSyntaxTest, WillRepeatedlyIsOptional) { ...@@ -510,30 +491,30 @@ TEST(ExpectCallSyntaxTest, WillRepeatedlyIsOptional) {
TEST(ExpectCallSyntaxTest, WillRepeatedlyCannotAppearMultipleTimes) { TEST(ExpectCallSyntaxTest, WillRepeatedlyCannotAppearMultipleTimes) {
MockA a; MockA a;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_CALL(a, DoA(1)) { // NOLINT
.WillRepeatedly(Return()) EXPECT_CALL(a, DoA(1)).WillRepeatedly(Return()).WillRepeatedly(
.WillRepeatedly(Return()); Return());
}, ".WillRepeatedly() cannot appear more than once in an " },
"EXPECT_CALL()"); ".WillRepeatedly() cannot appear more than once in an "
"EXPECT_CALL()");
} }
TEST(ExpectCallSyntaxTest, WillRepeatedlyMustBeBeforeRetiresOnSaturation) { TEST(ExpectCallSyntaxTest, WillRepeatedlyMustBeBeforeRetiresOnSaturation) {
MockA a; MockA a;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_CALL(a, DoA(1)) { // NOLINT
.RetiresOnSaturation() EXPECT_CALL(a, DoA(1)).RetiresOnSaturation().WillRepeatedly(Return());
.WillRepeatedly(Return()); },
}, ".WillRepeatedly() cannot appear after "); ".WillRepeatedly() cannot appear after ");
} }
TEST(ExpectCallSyntaxTest, RetiresOnSaturationIsOptional) { TEST(ExpectCallSyntaxTest, RetiresOnSaturationIsOptional) {
MockA a; MockA a;
EXPECT_CALL(a, DoA(1)); EXPECT_CALL(a, DoA(1));
EXPECT_CALL(a, DoA(1)) EXPECT_CALL(a, DoA(1)).RetiresOnSaturation();
.RetiresOnSaturation();
a.DoA(1); a.DoA(1);
a.DoA(1); a.DoA(1);
...@@ -542,11 +523,11 @@ TEST(ExpectCallSyntaxTest, RetiresOnSaturationIsOptional) { ...@@ -542,11 +523,11 @@ TEST(ExpectCallSyntaxTest, RetiresOnSaturationIsOptional) {
TEST(ExpectCallSyntaxTest, RetiresOnSaturationCannotAppearMultipleTimes) { TEST(ExpectCallSyntaxTest, RetiresOnSaturationCannotAppearMultipleTimes) {
MockA a; MockA a;
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
EXPECT_CALL(a, DoA(1)) { // NOLINT
.RetiresOnSaturation() EXPECT_CALL(a, DoA(1)).RetiresOnSaturation().RetiresOnSaturation();
.RetiresOnSaturation(); },
}, ".RetiresOnSaturation() cannot appear more than once"); ".RetiresOnSaturation() cannot appear more than once");
a.DoA(1); a.DoA(1);
} }
...@@ -557,16 +538,20 @@ TEST(ExpectCallSyntaxTest, DefaultCardinalityIsOnce) { ...@@ -557,16 +538,20 @@ TEST(ExpectCallSyntaxTest, DefaultCardinalityIsOnce) {
EXPECT_CALL(a, DoA(1)); EXPECT_CALL(a, DoA(1));
a.DoA(1); a.DoA(1);
} }
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
MockA a; { // NOLINT
EXPECT_CALL(a, DoA(1)); MockA a;
}, "to be called once"); EXPECT_CALL(a, DoA(1));
EXPECT_NONFATAL_FAILURE({ // NOLINT },
MockA a; "to be called once");
EXPECT_CALL(a, DoA(1)); EXPECT_NONFATAL_FAILURE(
a.DoA(1); { // NOLINT
a.DoA(1); MockA a;
}, "to be called once"); EXPECT_CALL(a, DoA(1));
a.DoA(1);
a.DoA(1);
},
"to be called once");
} }
#if GTEST_HAS_STREAM_REDIRECTION #if GTEST_HAS_STREAM_REDIRECTION
...@@ -579,13 +564,9 @@ TEST(ExpectCallSyntaxTest, DoesNotWarnOnAdequateActionCount) { ...@@ -579,13 +564,9 @@ TEST(ExpectCallSyntaxTest, DoesNotWarnOnAdequateActionCount) {
MockB b; MockB b;
// It's always fine to omit WillOnce() entirely. // It's always fine to omit WillOnce() entirely.
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).Times(0);
.Times(0); EXPECT_CALL(b, DoB(1)).Times(AtMost(1));
EXPECT_CALL(b, DoB(1)) EXPECT_CALL(b, DoB(2)).Times(1).WillRepeatedly(Return(1));
.Times(AtMost(1));
EXPECT_CALL(b, DoB(2))
.Times(1)
.WillRepeatedly(Return(1));
// It's fine for the number of WillOnce()s to equal the upper bound. // It's fine for the number of WillOnce()s to equal the upper bound.
EXPECT_CALL(b, DoB(3)) EXPECT_CALL(b, DoB(3))
...@@ -595,10 +576,8 @@ TEST(ExpectCallSyntaxTest, DoesNotWarnOnAdequateActionCount) { ...@@ -595,10 +576,8 @@ TEST(ExpectCallSyntaxTest, DoesNotWarnOnAdequateActionCount) {
// It's fine for the number of WillOnce()s to be smaller than the // It's fine for the number of WillOnce()s to be smaller than the
// upper bound when there is a WillRepeatedly(). // upper bound when there is a WillRepeatedly().
EXPECT_CALL(b, DoB(4)) EXPECT_CALL(b, DoB(4)).Times(AtMost(3)).WillOnce(Return(1)).WillRepeatedly(
.Times(AtMost(3)) Return(2));
.WillOnce(Return(1))
.WillRepeatedly(Return(2));
// Satisfies the above expectations. // Satisfies the above expectations.
b.DoB(2); b.DoB(2);
...@@ -615,13 +594,9 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) { ...@@ -615,13 +594,9 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) {
MockB b; MockB b;
// Warns when the number of WillOnce()s is larger than the upper bound. // Warns when the number of WillOnce()s is larger than the upper bound.
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).Times(0).WillOnce(Return(1)); // #1
.Times(0) EXPECT_CALL(b, DoB()).Times(AtMost(1)).WillOnce(Return(1)).WillOnce(
.WillOnce(Return(1)); // #1 Return(2)); // #2
EXPECT_CALL(b, DoB())
.Times(AtMost(1))
.WillOnce(Return(1))
.WillOnce(Return(2)); // #2
EXPECT_CALL(b, DoB(1)) EXPECT_CALL(b, DoB(1))
.Times(1) .Times(1)
.WillOnce(Return(1)) .WillOnce(Return(1))
...@@ -630,41 +605,34 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) { ...@@ -630,41 +605,34 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) {
// Warns when the number of WillOnce()s equals the upper bound and // Warns when the number of WillOnce()s equals the upper bound and
// there is a WillRepeatedly(). // there is a WillRepeatedly().
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).Times(0).WillRepeatedly(Return(1)); // #4
.Times(0) EXPECT_CALL(b, DoB(2)).Times(1).WillOnce(Return(1)).WillRepeatedly(
.WillRepeatedly(Return(1)); // #4 Return(2)); // #5
EXPECT_CALL(b, DoB(2))
.Times(1)
.WillOnce(Return(1))
.WillRepeatedly(Return(2)); // #5
// Satisfies the above expectations. // Satisfies the above expectations.
b.DoB(1); b.DoB(1);
b.DoB(2); b.DoB(2);
} }
const std::string output = GetCapturedStdout(); const std::string output = GetCapturedStdout();
EXPECT_PRED_FORMAT2( EXPECT_PRED_FORMAT2(IsSubstring,
IsSubstring, "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
"Too many actions specified in EXPECT_CALL(b, DoB())...\n" "Expected to be never called, but has 1 WillOnce().",
"Expected to be never called, but has 1 WillOnce().", output); // #1
output); // #1 EXPECT_PRED_FORMAT2(IsSubstring,
EXPECT_PRED_FORMAT2( "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
IsSubstring, "Expected to be called at most once, "
"Too many actions specified in EXPECT_CALL(b, DoB())...\n" "but has 2 WillOnce()s.",
"Expected to be called at most once, " output); // #2
"but has 2 WillOnce()s.",
output); // #2
EXPECT_PRED_FORMAT2( EXPECT_PRED_FORMAT2(
IsSubstring, IsSubstring,
"Too many actions specified in EXPECT_CALL(b, DoB(1))...\n" "Too many actions specified in EXPECT_CALL(b, DoB(1))...\n"
"Expected to be called once, but has 2 WillOnce()s.", "Expected to be called once, but has 2 WillOnce()s.",
output); // #3 output); // #3
EXPECT_PRED_FORMAT2( EXPECT_PRED_FORMAT2(IsSubstring,
IsSubstring, "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
"Too many actions specified in EXPECT_CALL(b, DoB())...\n" "Expected to be never called, but has 0 WillOnce()s "
"Expected to be never called, but has 0 WillOnce()s " "and a WillRepeatedly().",
"and a WillRepeatedly().", output); // #4
output); // #4
EXPECT_PRED_FORMAT2( EXPECT_PRED_FORMAT2(
IsSubstring, IsSubstring,
"Too many actions specified in EXPECT_CALL(b, DoB(2))...\n" "Too many actions specified in EXPECT_CALL(b, DoB(2))...\n"
...@@ -678,19 +646,16 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) { ...@@ -678,19 +646,16 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) {
TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) { TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
MockB b; MockB b;
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).Times(Between(2, 3)).WillOnce(Return(1));
.Times(Between(2, 3))
.WillOnce(Return(1));
CaptureStdout(); CaptureStdout();
b.DoB(); b.DoB();
const std::string output = GetCapturedStdout(); const std::string output = GetCapturedStdout();
EXPECT_PRED_FORMAT2( EXPECT_PRED_FORMAT2(IsSubstring,
IsSubstring, "Too few actions specified in EXPECT_CALL(b, DoB())...\n"
"Too few actions specified in EXPECT_CALL(b, DoB())...\n" "Expected to be called between 2 and 3 times, "
"Expected to be called between 2 and 3 times, " "but has only 1 WillOnce().",
"but has only 1 WillOnce().", output);
output);
b.DoB(); b.DoB();
} }
...@@ -718,10 +683,12 @@ TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) { ...@@ -718,10 +683,12 @@ TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) {
warning_output); warning_output);
GMOCK_FLAG_SET(default_mock_behavior, kFail); GMOCK_FLAG_SET(default_mock_behavior, kFail);
EXPECT_NONFATAL_FAILURE({ EXPECT_NONFATAL_FAILURE(
MockA a; {
a.DoA(0); MockA a;
}, "Uninteresting mock function call"); a.DoA(0);
},
"Uninteresting mock function call");
// Out of bounds values are converted to kWarn // Out of bounds values are converted to kWarn
GMOCK_FLAG_SET(default_mock_behavior, -1); GMOCK_FLAG_SET(default_mock_behavior, -1);
...@@ -765,8 +732,7 @@ TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCall) { ...@@ -765,8 +732,7 @@ TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCall) {
// matches the invocation. // matches the invocation.
TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCallMatches) { TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCallMatches) {
MockB b; MockB b;
ON_CALL(b, DoB(1)) ON_CALL(b, DoB(1)).WillByDefault(Return(1));
.WillByDefault(Return(1));
EXPECT_CALL(b, DoB(_)); EXPECT_CALL(b, DoB(_));
EXPECT_EQ(0, b.DoB(2)); EXPECT_EQ(0, b.DoB(2));
...@@ -775,12 +741,9 @@ TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCallMatches) { ...@@ -775,12 +741,9 @@ TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCallMatches) {
// Tests that the last matching ON_CALL() action is taken. // Tests that the last matching ON_CALL() action is taken.
TEST(OnCallTest, PicksLastMatchingOnCall) { TEST(OnCallTest, PicksLastMatchingOnCall) {
MockB b; MockB b;
ON_CALL(b, DoB(_)) ON_CALL(b, DoB(_)).WillByDefault(Return(3));
.WillByDefault(Return(3)); ON_CALL(b, DoB(2)).WillByDefault(Return(2));
ON_CALL(b, DoB(2)) ON_CALL(b, DoB(1)).WillByDefault(Return(1));
.WillByDefault(Return(2));
ON_CALL(b, DoB(1))
.WillByDefault(Return(1));
EXPECT_CALL(b, DoB(_)); EXPECT_CALL(b, DoB(_));
EXPECT_EQ(2, b.DoB(2)); EXPECT_EQ(2, b.DoB(2));
...@@ -804,25 +767,24 @@ TEST(ExpectCallTest, AllowsAnyCallWhenNoSpec) { ...@@ -804,25 +767,24 @@ TEST(ExpectCallTest, AllowsAnyCallWhenNoSpec) {
// Tests that the last matching EXPECT_CALL() fires. // Tests that the last matching EXPECT_CALL() fires.
TEST(ExpectCallTest, PicksLastMatchingExpectCall) { TEST(ExpectCallTest, PicksLastMatchingExpectCall) {
MockB b; MockB b;
EXPECT_CALL(b, DoB(_)) EXPECT_CALL(b, DoB(_)).WillRepeatedly(Return(2));
.WillRepeatedly(Return(2)); EXPECT_CALL(b, DoB(1)).WillRepeatedly(Return(1));
EXPECT_CALL(b, DoB(1))
.WillRepeatedly(Return(1));
EXPECT_EQ(1, b.DoB(1)); EXPECT_EQ(1, b.DoB(1));
} }
// Tests lower-bound violation. // Tests lower-bound violation.
TEST(ExpectCallTest, CatchesTooFewCalls) { TEST(ExpectCallTest, CatchesTooFewCalls) {
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
MockB b; { // NOLINT
EXPECT_CALL(b, DoB(5)) MockB b;
.Times(AtLeast(2)); EXPECT_CALL(b, DoB(5)).Times(AtLeast(2));
b.DoB(5); b.DoB(5);
}, "Actual function call count doesn't match EXPECT_CALL(b, DoB(5))...\n" },
" Expected: to be called at least twice\n" "Actual function call count doesn't match EXPECT_CALL(b, DoB(5))...\n"
" Actual: called once - unsatisfied and active"); " Expected: to be called at least twice\n"
" Actual: called once - unsatisfied and active");
} }
// Tests that the cardinality can be inferred when no Times(...) is // Tests that the cardinality can be inferred when no Times(...) is
...@@ -830,28 +792,24 @@ TEST(ExpectCallTest, CatchesTooFewCalls) { ...@@ -830,28 +792,24 @@ TEST(ExpectCallTest, CatchesTooFewCalls) {
TEST(ExpectCallTest, InfersCardinalityWhenThereIsNoWillRepeatedly) { TEST(ExpectCallTest, InfersCardinalityWhenThereIsNoWillRepeatedly) {
{ {
MockB b; MockB b;
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillOnce(Return(2));
.WillOnce(Return(1))
.WillOnce(Return(2));
EXPECT_EQ(1, b.DoB()); EXPECT_EQ(1, b.DoB());
EXPECT_EQ(2, b.DoB()); EXPECT_EQ(2, b.DoB());
} }
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
MockB b; { // NOLINT
EXPECT_CALL(b, DoB()) MockB b;
.WillOnce(Return(1)) EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillOnce(Return(2));
.WillOnce(Return(2));
EXPECT_EQ(1, b.DoB()); EXPECT_EQ(1, b.DoB());
}, "to be called twice"); },
"to be called twice");
{ // NOLINT { // NOLINT
MockB b; MockB b;
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillOnce(Return(2));
.WillOnce(Return(1))
.WillOnce(Return(2));
EXPECT_EQ(1, b.DoB()); EXPECT_EQ(1, b.DoB());
EXPECT_EQ(2, b.DoB()); EXPECT_EQ(2, b.DoB());
...@@ -862,40 +820,34 @@ TEST(ExpectCallTest, InfersCardinalityWhenThereIsNoWillRepeatedly) { ...@@ -862,40 +820,34 @@ TEST(ExpectCallTest, InfersCardinalityWhenThereIsNoWillRepeatedly) {
TEST(ExpectCallTest, InfersCardinality1WhenThereIsWillRepeatedly) { TEST(ExpectCallTest, InfersCardinality1WhenThereIsWillRepeatedly) {
{ {
MockB b; MockB b;
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillRepeatedly(Return(2));
.WillOnce(Return(1))
.WillRepeatedly(Return(2));
EXPECT_EQ(1, b.DoB()); EXPECT_EQ(1, b.DoB());
} }
{ // NOLINT { // NOLINT
MockB b; MockB b;
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillRepeatedly(Return(2));
.WillOnce(Return(1))
.WillRepeatedly(Return(2));
EXPECT_EQ(1, b.DoB()); EXPECT_EQ(1, b.DoB());
EXPECT_EQ(2, b.DoB()); EXPECT_EQ(2, b.DoB());
EXPECT_EQ(2, b.DoB()); EXPECT_EQ(2, b.DoB());
} }
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
MockB b; { // NOLINT
EXPECT_CALL(b, DoB()) MockB b;
.WillOnce(Return(1)) EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillRepeatedly(Return(2));
.WillRepeatedly(Return(2)); },
}, "to be called at least once"); "to be called at least once");
} }
// Tests that the n-th action is taken for the n-th matching // Tests that the n-th action is taken for the n-th matching
// invocation. // invocation.
TEST(ExpectCallTest, NthMatchTakesNthAction) { TEST(ExpectCallTest, NthMatchTakesNthAction) {
MockB b; MockB b;
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillOnce(Return(2)).WillOnce(
.WillOnce(Return(1)) Return(3));
.WillOnce(Return(2))
.WillOnce(Return(3));
EXPECT_EQ(1, b.DoB()); EXPECT_EQ(1, b.DoB());
EXPECT_EQ(2, b.DoB()); EXPECT_EQ(2, b.DoB());
...@@ -906,9 +858,7 @@ TEST(ExpectCallTest, NthMatchTakesNthAction) { ...@@ -906,9 +858,7 @@ TEST(ExpectCallTest, NthMatchTakesNthAction) {
// list is exhausted. // list is exhausted.
TEST(ExpectCallTest, TakesRepeatedActionWhenWillListIsExhausted) { TEST(ExpectCallTest, TakesRepeatedActionWhenWillListIsExhausted) {
MockB b; MockB b;
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillRepeatedly(Return(2));
.WillOnce(Return(1))
.WillRepeatedly(Return(2));
EXPECT_EQ(1, b.DoB()); EXPECT_EQ(1, b.DoB());
EXPECT_EQ(2, b.DoB()); EXPECT_EQ(2, b.DoB());
...@@ -921,8 +871,7 @@ TEST(ExpectCallTest, TakesRepeatedActionWhenWillListIsExhausted) { ...@@ -921,8 +871,7 @@ TEST(ExpectCallTest, TakesRepeatedActionWhenWillListIsExhausted) {
// exhausted and there is no WillRepeatedly(). // exhausted and there is no WillRepeatedly().
TEST(ExpectCallTest, TakesDefaultActionWhenWillListIsExhausted) { TEST(ExpectCallTest, TakesDefaultActionWhenWillListIsExhausted) {
MockB b; MockB b;
EXPECT_CALL(b, DoB(_)) EXPECT_CALL(b, DoB(_)).Times(1);
.Times(1);
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB())
.Times(AnyNumber()) .Times(AnyNumber())
.WillOnce(Return(1)) .WillOnce(Return(1))
...@@ -984,8 +933,7 @@ TEST(UninterestingCallTest, DoesDefaultAction) { ...@@ -984,8 +933,7 @@ TEST(UninterestingCallTest, DoesDefaultAction) {
// When there is an ON_CALL() statement, the action specified by it // When there is an ON_CALL() statement, the action specified by it
// should be taken. // should be taken.
MockA a; MockA a;
ON_CALL(a, Binary(_, _)) ON_CALL(a, Binary(_, _)).WillByDefault(Return(true));
.WillByDefault(Return(true));
EXPECT_TRUE(a.Binary(1, 2)); EXPECT_TRUE(a.Binary(1, 2));
// When there is no ON_CALL(), the default value for the return type // When there is no ON_CALL(), the default value for the return type
...@@ -999,8 +947,7 @@ TEST(UnexpectedCallTest, DoesDefaultAction) { ...@@ -999,8 +947,7 @@ TEST(UnexpectedCallTest, DoesDefaultAction) {
// When there is an ON_CALL() statement, the action specified by it // When there is an ON_CALL() statement, the action specified by it
// should be taken. // should be taken.
MockA a; MockA a;
ON_CALL(a, Binary(_, _)) ON_CALL(a, Binary(_, _)).WillByDefault(Return(true));
.WillByDefault(Return(true));
EXPECT_CALL(a, Binary(0, 0)); EXPECT_CALL(a, Binary(0, 0));
a.Binary(0, 0); a.Binary(0, 0);
bool result = false; bool result = false;
...@@ -1011,11 +958,9 @@ TEST(UnexpectedCallTest, DoesDefaultAction) { ...@@ -1011,11 +958,9 @@ TEST(UnexpectedCallTest, DoesDefaultAction) {
// When there is no ON_CALL(), the default value for the return type // When there is no ON_CALL(), the default value for the return type
// should be returned. // should be returned.
MockB b; MockB b;
EXPECT_CALL(b, DoB(0)) EXPECT_CALL(b, DoB(0)).Times(0);
.Times(0);
int n = -1; int n = -1;
EXPECT_NONFATAL_FAILURE(n = b.DoB(1), EXPECT_NONFATAL_FAILURE(n = b.DoB(1), "Unexpected mock function call");
"Unexpected mock function call");
EXPECT_EQ(0, n); EXPECT_EQ(0, n);
} }
...@@ -1092,14 +1037,12 @@ TEST(UnexpectedCallTest, GeneartesFailureForNonVoidFunction) { ...@@ -1092,14 +1037,12 @@ TEST(UnexpectedCallTest, GeneartesFailureForNonVoidFunction) {
// match the call. // match the call.
TEST(UnexpectedCallTest, RetiredExpectation) { TEST(UnexpectedCallTest, RetiredExpectation) {
MockB b; MockB b;
EXPECT_CALL(b, DoB(1)) EXPECT_CALL(b, DoB(1)).RetiresOnSaturation();
.RetiresOnSaturation();
b.DoB(1); b.DoB(1);
EXPECT_NONFATAL_FAILURE( EXPECT_NONFATAL_FAILURE(b.DoB(1),
b.DoB(1), " Expected: the expectation is active\n"
" Expected: the expectation is active\n" " Actual: it is retired");
" Actual: it is retired");
} }
// Tests that Google Mock explains that an expectation that doesn't // Tests that Google Mock explains that an expectation that doesn't
...@@ -1108,10 +1051,9 @@ TEST(UnexpectedCallTest, UnmatchedArguments) { ...@@ -1108,10 +1051,9 @@ TEST(UnexpectedCallTest, UnmatchedArguments) {
MockB b; MockB b;
EXPECT_CALL(b, DoB(1)); EXPECT_CALL(b, DoB(1));
EXPECT_NONFATAL_FAILURE( EXPECT_NONFATAL_FAILURE(b.DoB(2),
b.DoB(2), " Expected arg #0: is equal to 1\n"
" Expected arg #0: is equal to 1\n" " Actual: 2\n");
" Actual: 2\n");
b.DoB(1); b.DoB(1);
} }
...@@ -1120,15 +1062,10 @@ TEST(UnexpectedCallTest, UnmatchedArguments) { ...@@ -1120,15 +1062,10 @@ TEST(UnexpectedCallTest, UnmatchedArguments) {
TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) { TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) {
Sequence s1, s2; Sequence s1, s2;
MockB b; MockB b;
EXPECT_CALL(b, DoB(1)) EXPECT_CALL(b, DoB(1)).InSequence(s1);
.InSequence(s1); EXPECT_CALL(b, DoB(2)).Times(AnyNumber()).InSequence(s1);
EXPECT_CALL(b, DoB(2)) EXPECT_CALL(b, DoB(3)).InSequence(s2);
.Times(AnyNumber()) EXPECT_CALL(b, DoB(4)).InSequence(s1, s2);
.InSequence(s1);
EXPECT_CALL(b, DoB(3))
.InSequence(s2);
EXPECT_CALL(b, DoB(4))
.InSequence(s1, s2);
::testing::TestPartResultArray failures; ::testing::TestPartResultArray failures;
{ {
...@@ -1146,23 +1083,27 @@ TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) { ...@@ -1146,23 +1083,27 @@ TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) {
// Verifies that the failure message contains the two unsatisfied // Verifies that the failure message contains the two unsatisfied
// pre-requisites but not the satisfied one. // pre-requisites but not the satisfied one.
#if GTEST_USES_PCRE #if GTEST_USES_PCRE
EXPECT_THAT(r.message(), ContainsRegex( EXPECT_THAT(
// PCRE has trouble using (.|\n) to match any character, but r.message(),
// supports the (?s) prefix for using . to match any character. ContainsRegex(
"(?s)the following immediate pre-requisites are not satisfied:\n" // PCRE has trouble using (.|\n) to match any character, but
".*: pre-requisite #0\n" // supports the (?s) prefix for using . to match any character.
".*: pre-requisite #1")); "(?s)the following immediate pre-requisites are not satisfied:\n"
".*: pre-requisite #0\n"
".*: pre-requisite #1"));
#elif GTEST_USES_POSIX_RE #elif GTEST_USES_POSIX_RE
EXPECT_THAT(r.message(), ContainsRegex( EXPECT_THAT(r.message(),
// POSIX RE doesn't understand the (?s) prefix, but has no trouble ContainsRegex(
// with (.|\n). // POSIX RE doesn't understand the (?s) prefix, but has no
"the following immediate pre-requisites are not satisfied:\n" // trouble with (.|\n).
"(.|\n)*: pre-requisite #0\n" "the following immediate pre-requisites are not satisfied:\n"
"(.|\n)*: pre-requisite #1")); "(.|\n)*: pre-requisite #0\n"
"(.|\n)*: pre-requisite #1"));
#else #else
// We can only use Google Test's own simple regex. // We can only use Google Test's own simple regex.
EXPECT_THAT(r.message(), ContainsRegex( EXPECT_THAT(r.message(),
"the following immediate pre-requisites are not satisfied:")); ContainsRegex(
"the following immediate pre-requisites are not satisfied:"));
EXPECT_THAT(r.message(), ContainsRegex(": pre-requisite #0")); EXPECT_THAT(r.message(), ContainsRegex(": pre-requisite #0"));
EXPECT_THAT(r.message(), ContainsRegex(": pre-requisite #1")); EXPECT_THAT(r.message(), ContainsRegex(": pre-requisite #1"));
#endif // GTEST_USES_PCRE #endif // GTEST_USES_PCRE
...@@ -1191,8 +1132,7 @@ TEST(ExcessiveCallTest, DoesDefaultAction) { ...@@ -1191,8 +1132,7 @@ TEST(ExcessiveCallTest, DoesDefaultAction) {
// When there is an ON_CALL() statement, the action specified by it // When there is an ON_CALL() statement, the action specified by it
// should be taken. // should be taken.
MockA a; MockA a;
ON_CALL(a, Binary(_, _)) ON_CALL(a, Binary(_, _)).WillByDefault(Return(true));
.WillByDefault(Return(true));
EXPECT_CALL(a, Binary(0, 0)); EXPECT_CALL(a, Binary(0, 0));
a.Binary(0, 0); a.Binary(0, 0);
bool result = false; bool result = false;
...@@ -1203,8 +1143,7 @@ TEST(ExcessiveCallTest, DoesDefaultAction) { ...@@ -1203,8 +1143,7 @@ TEST(ExcessiveCallTest, DoesDefaultAction) {
// When there is no ON_CALL(), the default value for the return type // When there is no ON_CALL(), the default value for the return type
// should be returned. // should be returned.
MockB b; MockB b;
EXPECT_CALL(b, DoB(0)) EXPECT_CALL(b, DoB(0)).Times(0);
.Times(0);
int n = -1; int n = -1;
EXPECT_NONFATAL_FAILURE(n = b.DoB(0), EXPECT_NONFATAL_FAILURE(n = b.DoB(0),
"Mock function called more times than expected"); "Mock function called more times than expected");
...@@ -1215,8 +1154,7 @@ TEST(ExcessiveCallTest, DoesDefaultAction) { ...@@ -1215,8 +1154,7 @@ TEST(ExcessiveCallTest, DoesDefaultAction) {
// the failure message contains the argument values. // the failure message contains the argument values.
TEST(ExcessiveCallTest, GeneratesFailureForVoidFunction) { TEST(ExcessiveCallTest, GeneratesFailureForVoidFunction) {
MockA a; MockA a;
EXPECT_CALL(a, DoA(_)) EXPECT_CALL(a, DoA(_)).Times(0);
.Times(0);
EXPECT_NONFATAL_FAILURE( EXPECT_NONFATAL_FAILURE(
a.DoA(9), a.DoA(9),
"Mock function called more times than expected - returning directly.\n" "Mock function called more times than expected - returning directly.\n"
...@@ -1252,9 +1190,11 @@ TEST(InSequenceTest, AllExpectationInScopeAreInSequence) { ...@@ -1252,9 +1190,11 @@ TEST(InSequenceTest, AllExpectationInScopeAreInSequence) {
EXPECT_CALL(a, DoA(2)); EXPECT_CALL(a, DoA(2));
} }
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
a.DoA(2); { // NOLINT
}, "Unexpected mock function call"); a.DoA(2);
},
"Unexpected mock function call");
a.DoA(1); a.DoA(1);
a.DoA(2); a.DoA(2);
...@@ -1274,10 +1214,12 @@ TEST(InSequenceTest, NestedInSequence) { ...@@ -1274,10 +1214,12 @@ TEST(InSequenceTest, NestedInSequence) {
} }
} }
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
a.DoA(1); { // NOLINT
a.DoA(3); a.DoA(1);
}, "Unexpected mock function call"); a.DoA(3);
},
"Unexpected mock function call");
a.DoA(2); a.DoA(2);
a.DoA(3); a.DoA(3);
...@@ -1293,9 +1235,11 @@ TEST(InSequenceTest, ExpectationsOutOfScopeAreNotAffected) { ...@@ -1293,9 +1235,11 @@ TEST(InSequenceTest, ExpectationsOutOfScopeAreNotAffected) {
} }
EXPECT_CALL(a, DoA(3)); EXPECT_CALL(a, DoA(3));
EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_NONFATAL_FAILURE(
a.DoA(2); { // NOLINT
}, "Unexpected mock function call"); a.DoA(2);
},
"Unexpected mock function call");
a.DoA(3); a.DoA(3);
a.DoA(1); a.DoA(1);
...@@ -1309,8 +1253,7 @@ TEST(SequenceTest, AnyOrderIsOkByDefault) { ...@@ -1309,8 +1253,7 @@ TEST(SequenceTest, AnyOrderIsOkByDefault) {
MockB b; MockB b;
EXPECT_CALL(a, DoA(1)); EXPECT_CALL(a, DoA(1));
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).Times(AnyNumber());
.Times(AnyNumber());
a.DoA(1); a.DoA(1);
b.DoB(); b.DoB();
...@@ -1321,8 +1264,7 @@ TEST(SequenceTest, AnyOrderIsOkByDefault) { ...@@ -1321,8 +1264,7 @@ TEST(SequenceTest, AnyOrderIsOkByDefault) {
MockB b; MockB b;
EXPECT_CALL(a, DoA(1)); EXPECT_CALL(a, DoA(1));
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).Times(AnyNumber());
.Times(AnyNumber());
b.DoB(); b.DoB();
a.DoA(1); a.DoA(1);
...@@ -1333,16 +1275,12 @@ TEST(SequenceTest, AnyOrderIsOkByDefault) { ...@@ -1333,16 +1275,12 @@ TEST(SequenceTest, AnyOrderIsOkByDefault) {
// is specified. // is specified.
TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo1) { TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo1) {
MockA a; MockA a;
ON_CALL(a, ReturnResult(_)) ON_CALL(a, ReturnResult(_)).WillByDefault(Return(Result()));
.WillByDefault(Return(Result()));
Sequence s; Sequence s;
EXPECT_CALL(a, ReturnResult(1)) EXPECT_CALL(a, ReturnResult(1)).InSequence(s);
.InSequence(s); EXPECT_CALL(a, ReturnResult(2)).InSequence(s);
EXPECT_CALL(a, ReturnResult(2)) EXPECT_CALL(a, ReturnResult(3)).InSequence(s);
.InSequence(s);
EXPECT_CALL(a, ReturnResult(3))
.InSequence(s);
a.ReturnResult(1); a.ReturnResult(1);
...@@ -1357,14 +1295,11 @@ TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo1) { ...@@ -1357,14 +1295,11 @@ TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo1) {
// is specified. // is specified.
TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo2) { TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo2) {
MockA a; MockA a;
ON_CALL(a, ReturnResult(_)) ON_CALL(a, ReturnResult(_)).WillByDefault(Return(Result()));
.WillByDefault(Return(Result()));
Sequence s; Sequence s;
EXPECT_CALL(a, ReturnResult(1)) EXPECT_CALL(a, ReturnResult(1)).InSequence(s);
.InSequence(s); EXPECT_CALL(a, ReturnResult(2)).InSequence(s);
EXPECT_CALL(a, ReturnResult(2))
.InSequence(s);
// May only be called after a.ReturnResult(1). // May only be called after a.ReturnResult(1).
EXPECT_NONFATAL_FAILURE(a.ReturnResult(2), "Unexpected mock function call"); EXPECT_NONFATAL_FAILURE(a.ReturnResult(2), "Unexpected mock function call");
...@@ -1377,8 +1312,7 @@ TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo2) { ...@@ -1377,8 +1312,7 @@ TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo2) {
class PartialOrderTest : public testing::Test { class PartialOrderTest : public testing::Test {
protected: protected:
PartialOrderTest() { PartialOrderTest() {
ON_CALL(a_, ReturnResult(_)) ON_CALL(a_, ReturnResult(_)).WillByDefault(Return(Result()));
.WillByDefault(Return(Result()));
// Specifies this partial ordering: // Specifies this partial ordering:
// //
...@@ -1386,16 +1320,10 @@ class PartialOrderTest : public testing::Test { ...@@ -1386,16 +1320,10 @@ class PartialOrderTest : public testing::Test {
// a.ReturnResult(2) * n ==> a.ReturnResult(3) // a.ReturnResult(2) * n ==> a.ReturnResult(3)
// b.DoB() * 2 ==> // b.DoB() * 2 ==>
Sequence x, y; Sequence x, y;
EXPECT_CALL(a_, ReturnResult(1)) EXPECT_CALL(a_, ReturnResult(1)).InSequence(x);
.InSequence(x); EXPECT_CALL(b_, DoB()).Times(2).InSequence(y);
EXPECT_CALL(b_, DoB()) EXPECT_CALL(a_, ReturnResult(2)).Times(AnyNumber()).InSequence(x, y);
.Times(2) EXPECT_CALL(a_, ReturnResult(3)).InSequence(x);
.InSequence(y);
EXPECT_CALL(a_, ReturnResult(2))
.Times(AnyNumber())
.InSequence(x, y);
EXPECT_CALL(a_, ReturnResult(3))
.InSequence(x);
} }
MockA a_; MockA a_;
...@@ -1447,13 +1375,9 @@ TEST(SequenceTest, Retirement) { ...@@ -1447,13 +1375,9 @@ TEST(SequenceTest, Retirement) {
MockA a; MockA a;
Sequence s; Sequence s;
EXPECT_CALL(a, DoA(1)) EXPECT_CALL(a, DoA(1)).InSequence(s);
.InSequence(s); EXPECT_CALL(a, DoA(_)).InSequence(s).RetiresOnSaturation();
EXPECT_CALL(a, DoA(_)) EXPECT_CALL(a, DoA(1)).InSequence(s);
.InSequence(s)
.RetiresOnSaturation();
EXPECT_CALL(a, DoA(1))
.InSequence(s);
a.DoA(1); a.DoA(1);
a.DoA(2); a.DoA(2);
...@@ -1518,12 +1442,12 @@ TEST(ExpectationSetTest, ConstructorsWork) { ...@@ -1518,12 +1442,12 @@ TEST(ExpectationSetTest, ConstructorsWork) {
Expectation e1; Expectation e1;
const Expectation e2; const Expectation e2;
ExpectationSet es1; // Default ctor. ExpectationSet es1; // Default ctor.
ExpectationSet es2 = EXPECT_CALL(a, DoA(1)); // Ctor from EXPECT_CALL. ExpectationSet es2 = EXPECT_CALL(a, DoA(1)); // Ctor from EXPECT_CALL.
ExpectationSet es3 = e1; // Ctor from Expectation. ExpectationSet es3 = e1; // Ctor from Expectation.
ExpectationSet es4(e1); // Ctor from Expectation; alternative syntax. ExpectationSet es4(e1); // Ctor from Expectation; alternative syntax.
ExpectationSet es5 = e2; // Ctor from const Expectation. ExpectationSet es5 = e2; // Ctor from const Expectation.
ExpectationSet es6(e2); // Ctor from const Expectation; alternative syntax. ExpectationSet es6(e2); // Ctor from const Expectation; alternative syntax.
ExpectationSet es7 = es2; // Copy ctor. ExpectationSet es7 = es2; // Copy ctor.
EXPECT_EQ(0, es1.size()); EXPECT_EQ(0, es1.size());
...@@ -1595,7 +1519,7 @@ TEST(ExpectationSetTest, IsEnumerable) { ...@@ -1595,7 +1519,7 @@ TEST(ExpectationSetTest, IsEnumerable) {
EXPECT_TRUE(it != es.end()); EXPECT_TRUE(it != es.end());
EXPECT_THAT(*it, Eq(Expectation())); EXPECT_THAT(*it, Eq(Expectation()));
++it; ++it;
EXPECT_TRUE(it== es.end()); EXPECT_TRUE(it == es.end());
} }
// Tests the .After() clause. // Tests the .After() clause.
...@@ -1605,8 +1529,7 @@ TEST(AfterTest, SucceedsWhenPartialOrderIsSatisfied) { ...@@ -1605,8 +1529,7 @@ TEST(AfterTest, SucceedsWhenPartialOrderIsSatisfied) {
ExpectationSet es; ExpectationSet es;
es += EXPECT_CALL(a, DoA(1)); es += EXPECT_CALL(a, DoA(1));
es += EXPECT_CALL(a, DoA(2)); es += EXPECT_CALL(a, DoA(2));
EXPECT_CALL(a, DoA(3)) EXPECT_CALL(a, DoA(3)).After(es);
.After(es);
a.DoA(1); a.DoA(1);
a.DoA(2); a.DoA(2);
...@@ -1619,9 +1542,7 @@ TEST(AfterTest, SucceedsWhenTotalOrderIsSatisfied) { ...@@ -1619,9 +1542,7 @@ TEST(AfterTest, SucceedsWhenTotalOrderIsSatisfied) {
// The following also verifies that const Expectation objects work // The following also verifies that const Expectation objects work
// too. Do not remove the const modifiers. // too. Do not remove the const modifiers.
const Expectation e1 = EXPECT_CALL(a, DoA(1)); const Expectation e1 = EXPECT_CALL(a, DoA(1));
const Expectation e2 = EXPECT_CALL(b, DoB()) const Expectation e2 = EXPECT_CALL(b, DoB()).Times(2).After(e1);
.Times(2)
.After(e1);
EXPECT_CALL(a, DoA(2)).After(e2); EXPECT_CALL(a, DoA(2)).After(e2);
a.DoA(1); a.DoA(1);
...@@ -1638,10 +1559,8 @@ TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo1) { ...@@ -1638,10 +1559,8 @@ TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo1) {
// Define ordering: // Define ordering:
// a.DoA(1) ==> b.DoB() ==> a.DoA(2) // a.DoA(1) ==> b.DoB() ==> a.DoA(2)
Expectation e1 = EXPECT_CALL(a, DoA(1)); Expectation e1 = EXPECT_CALL(a, DoA(1));
Expectation e2 = EXPECT_CALL(b, DoB()) Expectation e2 = EXPECT_CALL(b, DoB()).After(e1);
.After(e1); EXPECT_CALL(a, DoA(2)).After(e2);
EXPECT_CALL(a, DoA(2))
.After(e2);
a.DoA(1); a.DoA(1);
...@@ -1660,11 +1579,8 @@ TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo2) { ...@@ -1660,11 +1579,8 @@ TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo2) {
// Define ordering: // Define ordering:
// a.DoA(1) ==> b.DoB() * 2 ==> a.DoA(2) // a.DoA(1) ==> b.DoB() * 2 ==> a.DoA(2)
Expectation e1 = EXPECT_CALL(a, DoA(1)); Expectation e1 = EXPECT_CALL(a, DoA(1));
Expectation e2 = EXPECT_CALL(b, DoB()) Expectation e2 = EXPECT_CALL(b, DoB()).Times(2).After(e1);
.Times(2) EXPECT_CALL(a, DoA(2)).After(e2);
.After(e1);
EXPECT_CALL(a, DoA(2))
.After(e2);
a.DoA(1); a.DoA(1);
b.DoB(); b.DoB();
...@@ -1679,16 +1595,14 @@ TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo2) { ...@@ -1679,16 +1595,14 @@ TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo2) {
// Calls must satisfy the partial order when specified so. // Calls must satisfy the partial order when specified so.
TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo) { TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo) {
MockA a; MockA a;
ON_CALL(a, ReturnResult(_)) ON_CALL(a, ReturnResult(_)).WillByDefault(Return(Result()));
.WillByDefault(Return(Result()));
// Define ordering: // Define ordering:
// a.DoA(1) ==> // a.DoA(1) ==>
// a.DoA(2) ==> a.ReturnResult(3) // a.DoA(2) ==> a.ReturnResult(3)
Expectation e = EXPECT_CALL(a, DoA(1)); Expectation e = EXPECT_CALL(a, DoA(1));
const ExpectationSet es = EXPECT_CALL(a, DoA(2)); const ExpectationSet es = EXPECT_CALL(a, DoA(2));
EXPECT_CALL(a, ReturnResult(3)) EXPECT_CALL(a, ReturnResult(3)).After(e, es);
.After(e, es);
// May only be called last. // May only be called last.
EXPECT_NONFATAL_FAILURE(a.ReturnResult(3), "Unexpected mock function call"); EXPECT_NONFATAL_FAILURE(a.ReturnResult(3), "Unexpected mock function call");
...@@ -1707,8 +1621,7 @@ TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo2) { ...@@ -1707,8 +1621,7 @@ TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo2) {
// a.DoA(2) ==> a.DoA(3) // a.DoA(2) ==> a.DoA(3)
Expectation e = EXPECT_CALL(a, DoA(1)); Expectation e = EXPECT_CALL(a, DoA(1));
const ExpectationSet es = EXPECT_CALL(a, DoA(2)); const ExpectationSet es = EXPECT_CALL(a, DoA(2));
EXPECT_CALL(a, DoA(3)) EXPECT_CALL(a, DoA(3)).After(e, es);
.After(e, es);
a.DoA(2); a.DoA(2);
...@@ -1725,9 +1638,7 @@ TEST(AfterTest, CanBeUsedWithInSequence) { ...@@ -1725,9 +1638,7 @@ TEST(AfterTest, CanBeUsedWithInSequence) {
Sequence s; Sequence s;
Expectation e = EXPECT_CALL(a, DoA(1)); Expectation e = EXPECT_CALL(a, DoA(1));
EXPECT_CALL(a, DoA(2)).InSequence(s); EXPECT_CALL(a, DoA(2)).InSequence(s);
EXPECT_CALL(a, DoA(3)) EXPECT_CALL(a, DoA(3)).InSequence(s).After(e);
.InSequence(s)
.After(e);
a.DoA(1); a.DoA(1);
...@@ -1744,10 +1655,7 @@ TEST(AfterTest, CanBeCalledManyTimes) { ...@@ -1744,10 +1655,7 @@ TEST(AfterTest, CanBeCalledManyTimes) {
Expectation e1 = EXPECT_CALL(a, DoA(1)); Expectation e1 = EXPECT_CALL(a, DoA(1));
Expectation e2 = EXPECT_CALL(a, DoA(2)); Expectation e2 = EXPECT_CALL(a, DoA(2));
Expectation e3 = EXPECT_CALL(a, DoA(3)); Expectation e3 = EXPECT_CALL(a, DoA(3));
EXPECT_CALL(a, DoA(4)) EXPECT_CALL(a, DoA(4)).After(e1).After(e2).After(e3);
.After(e1)
.After(e2)
.After(e3);
a.DoA(3); a.DoA(3);
a.DoA(1); a.DoA(1);
...@@ -1763,8 +1671,7 @@ TEST(AfterTest, AcceptsUpToFiveArguments) { ...@@ -1763,8 +1671,7 @@ TEST(AfterTest, AcceptsUpToFiveArguments) {
Expectation e3 = EXPECT_CALL(a, DoA(3)); Expectation e3 = EXPECT_CALL(a, DoA(3));
ExpectationSet es1 = EXPECT_CALL(a, DoA(4)); ExpectationSet es1 = EXPECT_CALL(a, DoA(4));
ExpectationSet es2 = EXPECT_CALL(a, DoA(5)); ExpectationSet es2 = EXPECT_CALL(a, DoA(5));
EXPECT_CALL(a, DoA(6)) EXPECT_CALL(a, DoA(6)).After(e1, e2, e3, es1, es2);
.After(e1, e2, e3, es1, es2);
a.DoA(5); a.DoA(5);
a.DoA(2); a.DoA(2);
...@@ -1777,8 +1684,7 @@ TEST(AfterTest, AcceptsUpToFiveArguments) { ...@@ -1777,8 +1684,7 @@ TEST(AfterTest, AcceptsUpToFiveArguments) {
// .After() allows input to contain duplicated Expectations. // .After() allows input to contain duplicated Expectations.
TEST(AfterTest, AcceptsDuplicatedInput) { TEST(AfterTest, AcceptsDuplicatedInput) {
MockA a; MockA a;
ON_CALL(a, ReturnResult(_)) ON_CALL(a, ReturnResult(_)).WillByDefault(Return(Result()));
.WillByDefault(Return(Result()));
// Define ordering: // Define ordering:
// DoA(1) ==> // DoA(1) ==>
...@@ -1788,8 +1694,7 @@ TEST(AfterTest, AcceptsDuplicatedInput) { ...@@ -1788,8 +1694,7 @@ TEST(AfterTest, AcceptsDuplicatedInput) {
ExpectationSet es; ExpectationSet es;
es += e1; es += e1;
es += e2; es += e2;
EXPECT_CALL(a, ReturnResult(3)) EXPECT_CALL(a, ReturnResult(3)).After(e1, e2, es, e1);
.After(e1, e2, es, e1);
a.DoA(1); a.DoA(1);
...@@ -1806,8 +1711,7 @@ TEST(AfterTest, ChangesToExpectationSetHaveNoEffectAfterwards) { ...@@ -1806,8 +1711,7 @@ TEST(AfterTest, ChangesToExpectationSetHaveNoEffectAfterwards) {
MockA a; MockA a;
ExpectationSet es1 = EXPECT_CALL(a, DoA(1)); ExpectationSet es1 = EXPECT_CALL(a, DoA(1));
Expectation e2 = EXPECT_CALL(a, DoA(2)); Expectation e2 = EXPECT_CALL(a, DoA(2));
EXPECT_CALL(a, DoA(3)) EXPECT_CALL(a, DoA(3)).After(es1);
.After(es1);
es1 += e2; es1 += e2;
a.DoA(1); a.DoA(1);
...@@ -1826,14 +1730,11 @@ TEST(DeletingMockEarlyTest, Success1) { ...@@ -1826,14 +1730,11 @@ TEST(DeletingMockEarlyTest, Success1) {
{ {
InSequence dummy; InSequence dummy;
EXPECT_CALL(*b1, DoB(_)) EXPECT_CALL(*b1, DoB(_)).WillOnce(Return(1));
.WillOnce(Return(1));
EXPECT_CALL(*a, Binary(_, _)) EXPECT_CALL(*a, Binary(_, _))
.Times(AnyNumber()) .Times(AnyNumber())
.WillRepeatedly(Return(true)); .WillRepeatedly(Return(true));
EXPECT_CALL(*b2, DoB(_)) EXPECT_CALL(*b2, DoB(_)).Times(AnyNumber()).WillRepeatedly(Return(2));
.Times(AnyNumber())
.WillRepeatedly(Return(2));
} }
EXPECT_EQ(1, b1->DoB(1)); EXPECT_EQ(1, b1->DoB(1));
...@@ -1854,13 +1755,9 @@ TEST(DeletingMockEarlyTest, Success2) { ...@@ -1854,13 +1755,9 @@ TEST(DeletingMockEarlyTest, Success2) {
{ {
InSequence dummy; InSequence dummy;
EXPECT_CALL(*b1, DoB(_)) EXPECT_CALL(*b1, DoB(_)).WillOnce(Return(1));
.WillOnce(Return(1)); EXPECT_CALL(*a, Binary(_, _)).Times(AnyNumber());
EXPECT_CALL(*a, Binary(_, _)) EXPECT_CALL(*b2, DoB(_)).Times(AnyNumber()).WillRepeatedly(Return(2));
.Times(AnyNumber());
EXPECT_CALL(*b2, DoB(_))
.Times(AnyNumber())
.WillRepeatedly(Return(2));
} }
delete a; // a is trivially satisfied. delete a; // a is trivially satisfied.
...@@ -1875,14 +1772,14 @@ TEST(DeletingMockEarlyTest, Success2) { ...@@ -1875,14 +1772,14 @@ TEST(DeletingMockEarlyTest, Success2) {
// Suppresses warning on unreferenced formal parameter in MSVC with // Suppresses warning on unreferenced formal parameter in MSVC with
// -W4. // -W4.
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(push) #pragma warning(push)
# pragma warning(disable:4100) #pragma warning(disable : 4100)
#endif #endif
ACTION_P(Delete, ptr) { delete ptr; } ACTION_P(Delete, ptr) { delete ptr; }
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(pop) #pragma warning(pop)
#endif #endif
TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) { TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) {
...@@ -1893,8 +1790,7 @@ TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) { ...@@ -1893,8 +1790,7 @@ TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) {
TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningValue) { TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningValue) {
MockA* const a = new MockA; MockA* const a = new MockA;
EXPECT_CALL(*a, ReturnResult(_)) EXPECT_CALL(*a, ReturnResult(_)).WillOnce(DoAll(Delete(a), Return(Result())));
.WillOnce(DoAll(Delete(a), Return(Result())));
a->ReturnResult(42); // This will cause a to be deleted. a->ReturnResult(42); // This will cause a to be deleted.
} }
...@@ -1906,19 +1802,13 @@ TEST(DeletingMockEarlyTest, Failure1) { ...@@ -1906,19 +1802,13 @@ TEST(DeletingMockEarlyTest, Failure1) {
{ {
InSequence dummy; InSequence dummy;
EXPECT_CALL(*b1, DoB(_)) EXPECT_CALL(*b1, DoB(_)).WillOnce(Return(1));
.WillOnce(Return(1)); EXPECT_CALL(*a, Binary(_, _)).Times(AnyNumber());
EXPECT_CALL(*a, Binary(_, _)) EXPECT_CALL(*b2, DoB(_)).Times(AnyNumber()).WillRepeatedly(Return(2));
.Times(AnyNumber());
EXPECT_CALL(*b2, DoB(_))
.Times(AnyNumber())
.WillRepeatedly(Return(2));
} }
delete a; // a is trivially satisfied. delete a; // a is trivially satisfied.
EXPECT_NONFATAL_FAILURE({ EXPECT_NONFATAL_FAILURE({ b2->DoB(2); }, "Unexpected mock function call");
b2->DoB(2);
}, "Unexpected mock function call");
EXPECT_EQ(1, b1->DoB(1)); EXPECT_EQ(1, b1->DoB(1));
delete b1; delete b1;
delete b2; delete b2;
...@@ -1933,18 +1823,13 @@ TEST(DeletingMockEarlyTest, Failure2) { ...@@ -1933,18 +1823,13 @@ TEST(DeletingMockEarlyTest, Failure2) {
{ {
InSequence dummy; InSequence dummy;
EXPECT_CALL(*b1, DoB(_)); EXPECT_CALL(*b1, DoB(_));
EXPECT_CALL(*a, Binary(_, _)) EXPECT_CALL(*a, Binary(_, _)).Times(AnyNumber());
.Times(AnyNumber()); EXPECT_CALL(*b2, DoB(_)).Times(AnyNumber());
EXPECT_CALL(*b2, DoB(_))
.Times(AnyNumber());
} }
EXPECT_NONFATAL_FAILURE(delete b1, EXPECT_NONFATAL_FAILURE(delete b1, "Actual: never called");
"Actual: never called"); EXPECT_NONFATAL_FAILURE(a->Binary(0, 1), "Unexpected mock function call");
EXPECT_NONFATAL_FAILURE(a->Binary(0, 1), EXPECT_NONFATAL_FAILURE(b2->DoB(1), "Unexpected mock function call");
"Unexpected mock function call");
EXPECT_NONFATAL_FAILURE(b2->DoB(1),
"Unexpected mock function call");
delete a; delete a;
delete b2; delete b2;
} }
...@@ -1969,23 +1854,16 @@ class EvenNumberCardinality : public CardinalityInterface { ...@@ -1969,23 +1854,16 @@ class EvenNumberCardinality : public CardinalityInterface {
} }
}; };
Cardinality EvenNumber() { Cardinality EvenNumber() { return Cardinality(new EvenNumberCardinality); }
return Cardinality(new EvenNumberCardinality);
}
TEST(ExpectationBaseTest, TEST(ExpectationBaseTest,
AllPrerequisitesAreSatisfiedWorksForNonMonotonicCardinality) { AllPrerequisitesAreSatisfiedWorksForNonMonotonicCardinality) {
MockA* a = new MockA; MockA* a = new MockA;
Sequence s; Sequence s;
EXPECT_CALL(*a, DoA(1)) EXPECT_CALL(*a, DoA(1)).Times(EvenNumber()).InSequence(s);
.Times(EvenNumber()) EXPECT_CALL(*a, DoA(2)).Times(AnyNumber()).InSequence(s);
.InSequence(s); EXPECT_CALL(*a, DoA(3)).Times(AnyNumber());
EXPECT_CALL(*a, DoA(2))
.Times(AnyNumber())
.InSequence(s);
EXPECT_CALL(*a, DoA(3))
.Times(AnyNumber());
a->DoA(3); a->DoA(3);
a->DoA(1); a->DoA(1);
...@@ -1996,8 +1874,7 @@ TEST(ExpectationBaseTest, ...@@ -1996,8 +1874,7 @@ TEST(ExpectationBaseTest,
// The following tests verify the message generated when a mock // The following tests verify the message generated when a mock
// function is called. // function is called.
struct Printable { struct Printable {};
};
inline void operator<<(::std::ostream& os, const Printable&) { inline void operator<<(::std::ostream& os, const Printable&) {
os << "Printable"; os << "Printable";
...@@ -2064,7 +1941,7 @@ TEST(FunctionCallMessageTest, ...@@ -2064,7 +1941,7 @@ TEST(FunctionCallMessageTest,
EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", output); EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", output);
EXPECT_PRED_FORMAT2(IsSubstring, "Stack trace:", output); EXPECT_PRED_FORMAT2(IsSubstring, "Stack trace:", output);
# ifndef NDEBUG #ifndef NDEBUG
// We check the stack trace content in dbg-mode only, as opt-mode // We check the stack trace content in dbg-mode only, as opt-mode
// may inline the call we are interested in seeing. // may inline the call we are interested in seeing.
...@@ -2080,7 +1957,7 @@ TEST(FunctionCallMessageTest, ...@@ -2080,7 +1957,7 @@ TEST(FunctionCallMessageTest,
const std::string output2 = GetCapturedStdout(); const std::string output2 = GetCapturedStdout();
EXPECT_PRED_FORMAT2(IsSubstring, "NonVoidMethod(", output2); EXPECT_PRED_FORMAT2(IsSubstring, "NonVoidMethod(", output2);
# endif // NDEBUG #endif // NDEBUG
} }
// Tests that an uninteresting mock function call on a naggy mock // Tests that an uninteresting mock function call on a naggy mock
...@@ -2096,7 +1973,8 @@ TEST(FunctionCallMessageTest, ...@@ -2096,7 +1973,8 @@ TEST(FunctionCallMessageTest,
IsSubstring, IsSubstring,
"Uninteresting mock function call - returning default value.\n" "Uninteresting mock function call - returning default value.\n"
" Function call: DoB()\n" " Function call: DoB()\n"
" Returns: 0\n", output1.c_str()); " Returns: 0\n",
output1.c_str());
// Makes sure the return value is printed. // Makes sure the return value is printed.
// A void mock function. // A void mock function.
...@@ -2104,12 +1982,12 @@ TEST(FunctionCallMessageTest, ...@@ -2104,12 +1982,12 @@ TEST(FunctionCallMessageTest,
CaptureStdout(); CaptureStdout();
c.VoidMethod(false, 5, "Hi", nullptr, Printable(), Unprintable()); c.VoidMethod(false, 5, "Hi", nullptr, Printable(), Unprintable());
const std::string output2 = GetCapturedStdout(); const std::string output2 = GetCapturedStdout();
EXPECT_THAT(output2.c_str(), EXPECT_THAT(
ContainsRegex( output2.c_str(),
"Uninteresting mock function call - returning directly\\.\n" ContainsRegex("Uninteresting mock function call - returning directly\\.\n"
" Function call: VoidMethod" " Function call: VoidMethod"
"\\(false, 5, \"Hi\", NULL, @.+ " "\\(false, 5, \"Hi\", NULL, @.+ "
"Printable, 4-byte object <00-00 00-00>\\)")); "Printable, 4-byte object <00-00 00-00>\\)"));
// A void function has no return value to print. // A void function has no return value to print.
} }
...@@ -2126,14 +2004,14 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture { ...@@ -2126,14 +2004,14 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
const std::string& function_name) { const std::string& function_name) {
if (should_print) { if (should_print) {
EXPECT_THAT(output.c_str(), HasSubstr(expected_substring)); EXPECT_THAT(output.c_str(), HasSubstr(expected_substring));
# ifndef NDEBUG #ifndef NDEBUG
// We check the stack trace content in dbg-mode only, as opt-mode // We check the stack trace content in dbg-mode only, as opt-mode
// may inline the call we are interested in seeing. // may inline the call we are interested in seeing.
EXPECT_THAT(output.c_str(), HasSubstr(function_name)); EXPECT_THAT(output.c_str(), HasSubstr(function_name));
# else #else
// Suppresses 'unused function parameter' warnings. // Suppresses 'unused function parameter' warnings.
static_cast<void>(function_name); static_cast<void>(function_name);
# endif // NDEBUG #endif // NDEBUG
} else { } else {
EXPECT_STREQ("", output.c_str()); EXPECT_STREQ("", output.c_str());
} }
...@@ -2143,31 +2021,26 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture { ...@@ -2143,31 +2021,26 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
void TestExpectedCall(bool should_print) { void TestExpectedCall(bool should_print) {
MockA a; MockA a;
EXPECT_CALL(a, DoA(5)); EXPECT_CALL(a, DoA(5));
EXPECT_CALL(a, Binary(_, 1)) EXPECT_CALL(a, Binary(_, 1)).WillOnce(Return(true));
.WillOnce(Return(true));
// A void-returning function. // A void-returning function.
CaptureStdout(); CaptureStdout();
a.DoA(5); a.DoA(5);
VerifyOutput( VerifyOutput(GetCapturedStdout(), should_print,
GetCapturedStdout(), "Mock function call matches EXPECT_CALL(a, DoA(5))...\n"
should_print, " Function call: DoA(5)\n"
"Mock function call matches EXPECT_CALL(a, DoA(5))...\n" "Stack trace:\n",
" Function call: DoA(5)\n" "DoA");
"Stack trace:\n",
"DoA");
// A non-void-returning function. // A non-void-returning function.
CaptureStdout(); CaptureStdout();
a.Binary(2, 1); a.Binary(2, 1);
VerifyOutput( VerifyOutput(GetCapturedStdout(), should_print,
GetCapturedStdout(), "Mock function call matches EXPECT_CALL(a, Binary(_, 1))...\n"
should_print, " Function call: Binary(2, 1)\n"
"Mock function call matches EXPECT_CALL(a, Binary(_, 1))...\n" " Returns: true\n"
" Function call: Binary(2, 1)\n" "Stack trace:\n",
" Returns: true\n" "Binary");
"Stack trace:\n",
"Binary");
} }
// Tests how the flag affects uninteresting calls on a naggy mock. // Tests how the flag affects uninteresting calls on a naggy mock.
...@@ -2185,27 +2058,23 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture { ...@@ -2185,27 +2058,23 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
// A void-returning function. // A void-returning function.
CaptureStdout(); CaptureStdout();
a.DoA(5); a.DoA(5);
VerifyOutput( VerifyOutput(GetCapturedStdout(), should_print,
GetCapturedStdout(), "\nGMOCK WARNING:\n"
should_print, "Uninteresting mock function call - returning directly.\n"
"\nGMOCK WARNING:\n" " Function call: DoA(5)\n" +
"Uninteresting mock function call - returning directly.\n" note,
" Function call: DoA(5)\n" + "DoA");
note,
"DoA");
// A non-void-returning function. // A non-void-returning function.
CaptureStdout(); CaptureStdout();
a.Binary(2, 1); a.Binary(2, 1);
VerifyOutput( VerifyOutput(GetCapturedStdout(), should_print,
GetCapturedStdout(), "\nGMOCK WARNING:\n"
should_print, "Uninteresting mock function call - returning default value.\n"
"\nGMOCK WARNING:\n" " Function call: Binary(2, 1)\n"
"Uninteresting mock function call - returning default value.\n" " Returns: false\n" +
" Function call: Binary(2, 1)\n" note,
" Returns: false\n" + "Binary");
note,
"Binary");
} }
}; };
...@@ -2270,22 +2139,19 @@ class GMockLogTest : public VerboseFlagPreservingFixture { ...@@ -2270,22 +2139,19 @@ class GMockLogTest : public VerboseFlagPreservingFixture {
TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsWarning) { TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsWarning) {
GMOCK_FLAG_SET(verbose, kWarningVerbosity); GMOCK_FLAG_SET(verbose, kWarningVerbosity);
EXPECT_CALL(helper_, Foo(_)) EXPECT_CALL(helper_, Foo(_)).WillOnce(Return(PrintMeNot()));
.WillOnce(Return(PrintMeNot()));
helper_.Foo(PrintMeNot()); // This is an expected call. helper_.Foo(PrintMeNot()); // This is an expected call.
} }
TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsError) { TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsError) {
GMOCK_FLAG_SET(verbose, kErrorVerbosity); GMOCK_FLAG_SET(verbose, kErrorVerbosity);
EXPECT_CALL(helper_, Foo(_)) EXPECT_CALL(helper_, Foo(_)).WillOnce(Return(PrintMeNot()));
.WillOnce(Return(PrintMeNot()));
helper_.Foo(PrintMeNot()); // This is an expected call. helper_.Foo(PrintMeNot()); // This is an expected call.
} }
TEST_F(GMockLogTest, DoesNotPrintWarningInternallyIfVerbosityIsError) { TEST_F(GMockLogTest, DoesNotPrintWarningInternallyIfVerbosityIsError) {
GMOCK_FLAG_SET(verbose, kErrorVerbosity); GMOCK_FLAG_SET(verbose, kErrorVerbosity);
ON_CALL(helper_, Foo(_)) ON_CALL(helper_, Foo(_)).WillByDefault(Return(PrintMeNot()));
.WillByDefault(Return(PrintMeNot()));
helper_.Foo(PrintMeNot()); // This should generate a warning. helper_.Foo(PrintMeNot()); // This should generate a warning.
} }
...@@ -2346,8 +2212,7 @@ TEST(VerifyAndClearExpectationsTest, NoMethodHasExpectations) { ...@@ -2346,8 +2212,7 @@ TEST(VerifyAndClearExpectationsTest, NoMethodHasExpectations) {
// verification succeeds. // verification succeeds.
TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndSucceed) { TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndSucceed) {
MockB b; MockB b;
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).WillOnce(Return(1));
.WillOnce(Return(1));
b.DoB(); b.DoB();
ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b)); ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b));
...@@ -2362,8 +2227,7 @@ TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndSucceed) { ...@@ -2362,8 +2227,7 @@ TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndSucceed) {
// verification fails. // verification fails.
TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndFail) { TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndFail) {
MockB b; MockB b;
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).WillOnce(Return(1));
.WillOnce(Return(1));
bool result = true; bool result = true;
EXPECT_NONFATAL_FAILURE(result = Mock::VerifyAndClearExpectations(&b), EXPECT_NONFATAL_FAILURE(result = Mock::VerifyAndClearExpectations(&b),
"Actual: never called"); "Actual: never called");
...@@ -2379,10 +2243,8 @@ TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndFail) { ...@@ -2379,10 +2243,8 @@ TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndFail) {
// when all of its methods have expectations. // when all of its methods have expectations.
TEST(VerifyAndClearExpectationsTest, AllMethodsHaveExpectations) { TEST(VerifyAndClearExpectationsTest, AllMethodsHaveExpectations) {
MockB b; MockB b;
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).WillOnce(Return(1));
.WillOnce(Return(1)); EXPECT_CALL(b, DoB(_)).WillOnce(Return(2));
EXPECT_CALL(b, DoB(_))
.WillOnce(Return(2));
b.DoB(); b.DoB();
b.DoB(1); b.DoB(1);
ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b)); ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b));
...@@ -2397,10 +2259,8 @@ TEST(VerifyAndClearExpectationsTest, AllMethodsHaveExpectations) { ...@@ -2397,10 +2259,8 @@ TEST(VerifyAndClearExpectationsTest, AllMethodsHaveExpectations) {
// when a method has more than one expectation. // when a method has more than one expectation.
TEST(VerifyAndClearExpectationsTest, AMethodHasManyExpectations) { TEST(VerifyAndClearExpectationsTest, AMethodHasManyExpectations) {
MockB b; MockB b;
EXPECT_CALL(b, DoB(0)) EXPECT_CALL(b, DoB(0)).WillOnce(Return(1));
.WillOnce(Return(1)); EXPECT_CALL(b, DoB(_)).WillOnce(Return(2));
EXPECT_CALL(b, DoB(_))
.WillOnce(Return(2));
b.DoB(1); b.DoB(1);
bool result = true; bool result = true;
EXPECT_NONFATAL_FAILURE(result = Mock::VerifyAndClearExpectations(&b), EXPECT_NONFATAL_FAILURE(result = Mock::VerifyAndClearExpectations(&b),
...@@ -2421,8 +2281,7 @@ TEST(VerifyAndClearExpectationsTest, CanCallManyTimes) { ...@@ -2421,8 +2281,7 @@ TEST(VerifyAndClearExpectationsTest, CanCallManyTimes) {
b.DoB(); b.DoB();
Mock::VerifyAndClearExpectations(&b); Mock::VerifyAndClearExpectations(&b);
EXPECT_CALL(b, DoB(_)) EXPECT_CALL(b, DoB(_)).WillOnce(Return(1));
.WillOnce(Return(1));
b.DoB(1); b.DoB(1);
Mock::VerifyAndClearExpectations(&b); Mock::VerifyAndClearExpectations(&b);
Mock::VerifyAndClearExpectations(&b); Mock::VerifyAndClearExpectations(&b);
...@@ -2446,8 +2305,7 @@ TEST(VerifyAndClearTest, NoMethodHasDefaultActions) { ...@@ -2446,8 +2305,7 @@ TEST(VerifyAndClearTest, NoMethodHasDefaultActions) {
// but not all of its methods have default actions. // but not all of its methods have default actions.
TEST(VerifyAndClearTest, SomeMethodsHaveDefaultActions) { TEST(VerifyAndClearTest, SomeMethodsHaveDefaultActions) {
MockB b; MockB b;
ON_CALL(b, DoB()) ON_CALL(b, DoB()).WillByDefault(Return(1));
.WillByDefault(Return(1));
Mock::VerifyAndClear(&b); Mock::VerifyAndClear(&b);
...@@ -2459,10 +2317,8 @@ TEST(VerifyAndClearTest, SomeMethodsHaveDefaultActions) { ...@@ -2459,10 +2317,8 @@ TEST(VerifyAndClearTest, SomeMethodsHaveDefaultActions) {
// its methods have default actions. // its methods have default actions.
TEST(VerifyAndClearTest, AllMethodsHaveDefaultActions) { TEST(VerifyAndClearTest, AllMethodsHaveDefaultActions) {
MockB b; MockB b;
ON_CALL(b, DoB()) ON_CALL(b, DoB()).WillByDefault(Return(1));
.WillByDefault(Return(1)); ON_CALL(b, DoB(_)).WillByDefault(Return(2));
ON_CALL(b, DoB(_))
.WillByDefault(Return(2));
Mock::VerifyAndClear(&b); Mock::VerifyAndClear(&b);
...@@ -2477,10 +2333,8 @@ TEST(VerifyAndClearTest, AllMethodsHaveDefaultActions) { ...@@ -2477,10 +2333,8 @@ TEST(VerifyAndClearTest, AllMethodsHaveDefaultActions) {
// method has more than one ON_CALL() set on it. // method has more than one ON_CALL() set on it.
TEST(VerifyAndClearTest, AMethodHasManyDefaultActions) { TEST(VerifyAndClearTest, AMethodHasManyDefaultActions) {
MockB b; MockB b;
ON_CALL(b, DoB(0)) ON_CALL(b, DoB(0)).WillByDefault(Return(1));
.WillByDefault(Return(1)); ON_CALL(b, DoB(_)).WillByDefault(Return(2));
ON_CALL(b, DoB(_))
.WillByDefault(Return(2));
Mock::VerifyAndClear(&b); Mock::VerifyAndClear(&b);
...@@ -2494,13 +2348,11 @@ TEST(VerifyAndClearTest, AMethodHasManyDefaultActions) { ...@@ -2494,13 +2348,11 @@ TEST(VerifyAndClearTest, AMethodHasManyDefaultActions) {
// times. // times.
TEST(VerifyAndClearTest, CanCallManyTimes) { TEST(VerifyAndClearTest, CanCallManyTimes) {
MockB b; MockB b;
ON_CALL(b, DoB()) ON_CALL(b, DoB()).WillByDefault(Return(1));
.WillByDefault(Return(1));
Mock::VerifyAndClear(&b); Mock::VerifyAndClear(&b);
Mock::VerifyAndClear(&b); Mock::VerifyAndClear(&b);
ON_CALL(b, DoB(_)) ON_CALL(b, DoB(_)).WillByDefault(Return(1));
.WillByDefault(Return(1));
Mock::VerifyAndClear(&b); Mock::VerifyAndClear(&b);
EXPECT_EQ(0, b.DoB()); EXPECT_EQ(0, b.DoB());
...@@ -2510,10 +2362,8 @@ TEST(VerifyAndClearTest, CanCallManyTimes) { ...@@ -2510,10 +2362,8 @@ TEST(VerifyAndClearTest, CanCallManyTimes) {
// Tests that VerifyAndClear() works when the verification succeeds. // Tests that VerifyAndClear() works when the verification succeeds.
TEST(VerifyAndClearTest, Success) { TEST(VerifyAndClearTest, Success) {
MockB b; MockB b;
ON_CALL(b, DoB()) ON_CALL(b, DoB()).WillByDefault(Return(1));
.WillByDefault(Return(1)); EXPECT_CALL(b, DoB(1)).WillOnce(Return(2));
EXPECT_CALL(b, DoB(1))
.WillOnce(Return(2));
b.DoB(); b.DoB();
b.DoB(1); b.DoB(1);
...@@ -2528,10 +2378,8 @@ TEST(VerifyAndClearTest, Success) { ...@@ -2528,10 +2378,8 @@ TEST(VerifyAndClearTest, Success) {
// Tests that VerifyAndClear() works when the verification fails. // Tests that VerifyAndClear() works when the verification fails.
TEST(VerifyAndClearTest, Failure) { TEST(VerifyAndClearTest, Failure) {
MockB b; MockB b;
ON_CALL(b, DoB(_)) ON_CALL(b, DoB(_)).WillByDefault(Return(1));
.WillByDefault(Return(1)); EXPECT_CALL(b, DoB()).WillOnce(Return(2));
EXPECT_CALL(b, DoB())
.WillOnce(Return(2));
b.DoB(1); b.DoB(1);
bool result = true; bool result = true;
...@@ -2549,12 +2397,9 @@ TEST(VerifyAndClearTest, Failure) { ...@@ -2549,12 +2397,9 @@ TEST(VerifyAndClearTest, Failure) {
// expectations are set on a const mock object. // expectations are set on a const mock object.
TEST(VerifyAndClearTest, Const) { TEST(VerifyAndClearTest, Const) {
MockB b; MockB b;
ON_CALL(Const(b), DoB()) ON_CALL(Const(b), DoB()).WillByDefault(Return(1));
.WillByDefault(Return(1));
EXPECT_CALL(Const(b), DoB()) EXPECT_CALL(Const(b), DoB()).WillOnce(DoDefault()).WillOnce(Return(2));
.WillOnce(DoDefault())
.WillOnce(Return(2));
b.DoB(); b.DoB();
b.DoB(); b.DoB();
...@@ -2570,18 +2415,14 @@ TEST(VerifyAndClearTest, Const) { ...@@ -2570,18 +2415,14 @@ TEST(VerifyAndClearTest, Const) {
// object after VerifyAndClear() has been called on it. // object after VerifyAndClear() has been called on it.
TEST(VerifyAndClearTest, CanSetDefaultActionsAndExpectationsAfterwards) { TEST(VerifyAndClearTest, CanSetDefaultActionsAndExpectationsAfterwards) {
MockB b; MockB b;
ON_CALL(b, DoB()) ON_CALL(b, DoB()).WillByDefault(Return(1));
.WillByDefault(Return(1)); EXPECT_CALL(b, DoB(_)).WillOnce(Return(2));
EXPECT_CALL(b, DoB(_))
.WillOnce(Return(2));
b.DoB(1); b.DoB(1);
Mock::VerifyAndClear(&b); Mock::VerifyAndClear(&b);
EXPECT_CALL(b, DoB()) EXPECT_CALL(b, DoB()).WillOnce(Return(3));
.WillOnce(Return(3)); ON_CALL(b, DoB(_)).WillByDefault(Return(4));
ON_CALL(b, DoB(_))
.WillByDefault(Return(4));
EXPECT_EQ(3, b.DoB()); EXPECT_EQ(3, b.DoB());
EXPECT_EQ(4, b.DoB(1)); EXPECT_EQ(4, b.DoB(1));
...@@ -2594,19 +2435,13 @@ TEST(VerifyAndClearTest, DoesNotAffectOtherMockObjects) { ...@@ -2594,19 +2435,13 @@ TEST(VerifyAndClearTest, DoesNotAffectOtherMockObjects) {
MockB b1; MockB b1;
MockB b2; MockB b2;
ON_CALL(a, Binary(_, _)) ON_CALL(a, Binary(_, _)).WillByDefault(Return(true));
.WillByDefault(Return(true)); EXPECT_CALL(a, Binary(_, _)).WillOnce(DoDefault()).WillOnce(Return(false));
EXPECT_CALL(a, Binary(_, _))
.WillOnce(DoDefault())
.WillOnce(Return(false));
ON_CALL(b1, DoB()) ON_CALL(b1, DoB()).WillByDefault(Return(1));
.WillByDefault(Return(1)); EXPECT_CALL(b1, DoB(_)).WillOnce(Return(2));
EXPECT_CALL(b1, DoB(_))
.WillOnce(Return(2));
ON_CALL(b2, DoB()) ON_CALL(b2, DoB()).WillByDefault(Return(3));
.WillByDefault(Return(3));
EXPECT_CALL(b2, DoB(_)); EXPECT_CALL(b2, DoB(_));
b2.DoB(0); b2.DoB(0);
...@@ -2647,8 +2482,7 @@ TEST(VerifyAndClearTest, ...@@ -2647,8 +2482,7 @@ TEST(VerifyAndClearTest,
ReferenceHoldingMock test_mock; ReferenceHoldingMock test_mock;
// ON_CALL stores a reference to a inside test_mock. // ON_CALL stores a reference to a inside test_mock.
ON_CALL(test_mock, AcceptReference(_)) ON_CALL(test_mock, AcceptReference(_)).WillByDefault(SetArgPointee<0>(a));
.WillByDefault(SetArgPointee<0>(a));
// Throw away the reference to the mock that we have in a. After this, the // Throw away the reference to the mock that we have in a. After this, the
// only reference to it is stored by test_mock. // only reference to it is stored by test_mock.
...@@ -2669,9 +2503,8 @@ TEST(VerifyAndClearTest, ...@@ -2669,9 +2503,8 @@ TEST(VerifyAndClearTest,
TEST(SynchronizationTest, CanCallMockMethodInAction) { TEST(SynchronizationTest, CanCallMockMethodInAction) {
MockA a; MockA a;
MockC c; MockC c;
ON_CALL(a, DoA(_)) ON_CALL(a, DoA(_)).WillByDefault(
.WillByDefault(IgnoreResult(InvokeWithoutArgs(&c, IgnoreResult(InvokeWithoutArgs(&c, &MockC::NonVoidMethod)));
&MockC::NonVoidMethod)));
EXPECT_CALL(a, DoA(1)); EXPECT_CALL(a, DoA(1));
EXPECT_CALL(a, DoA(1)) EXPECT_CALL(a, DoA(1))
.WillOnce(Invoke(&a, &MockA::DoA)) .WillOnce(Invoke(&a, &MockA::DoA))
...@@ -2760,9 +2593,9 @@ TEST(ParameterlessExpectationsTest, ...@@ -2760,9 +2593,9 @@ TEST(ParameterlessExpectationsTest,
// from it. This might be necessary on some platforms which require // from it. This might be necessary on some platforms which require
// specific setup and teardown. // specific setup and teardown.
#if GMOCK_RENAME_MAIN #if GMOCK_RENAME_MAIN
int gmock_main(int argc, char **argv) { int gmock_main(int argc, char** argv) {
#else #else
int main(int argc, char **argv) { int main(int argc, char** argv) {
#endif // GMOCK_RENAME_MAIN #endif // GMOCK_RENAME_MAIN
testing::InitGoogleMock(&argc, argv); testing::InitGoogleMock(&argc, argv);
// Ensures that the tests pass no matter what value of // Ensures that the tests pass no matter what value of
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Tests Google Mock's functionality that depends on exceptions. // Tests Google Mock's functionality that depends on exceptions.
#include "gmock/gmock.h" #include "gmock/gmock.h"
...@@ -75,6 +74,5 @@ TEST(DefaultValueTest, ThrowsRuntimeErrorWhenNoDefaultValue) { ...@@ -75,6 +74,5 @@ TEST(DefaultValueTest, ThrowsRuntimeErrorWhenNoDefaultValue) {
} }
} }
} // unnamed namespace } // unnamed namespace
#endif #endif
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This program is for verifying that a leaked mock object can be // This program is for verifying that a leaked mock object can be
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file is for verifying that various Google Mock constructs do not // This file is for verifying that various Google Mock constructs do not
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file is for verifying that various Google Mock constructs do not // This file is for verifying that various Google Mock constructs do not
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file tests that: // This file tests that:
...@@ -118,7 +117,7 @@ ...@@ -118,7 +117,7 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#if !GTEST_OS_WINDOWS_MOBILE #if !GTEST_OS_WINDOWS_MOBILE
# include <errno.h> #include <errno.h>
#endif #endif
#include <iostream> #include <iostream>
...@@ -200,14 +199,14 @@ class Interface { ...@@ -200,14 +199,14 @@ class Interface {
virtual char* StringFromString(char* str) = 0; virtual char* StringFromString(char* str) = 0;
virtual int IntFromString(char* str) = 0; virtual int IntFromString(char* str) = 0;
virtual int& IntRefFromString(char* str) = 0; virtual int& IntRefFromString(char* str) = 0;
virtual void VoidFromFunc(void(*func)(char* str)) = 0; virtual void VoidFromFunc(void (*func)(char* str)) = 0;
virtual void VoidFromIntRef(int& n) = 0; // NOLINT virtual void VoidFromIntRef(int& n) = 0; // NOLINT
virtual void VoidFromFloat(float n) = 0; virtual void VoidFromFloat(float n) = 0;
virtual void VoidFromDouble(double n) = 0; virtual void VoidFromDouble(double n) = 0;
virtual void VoidFromVector(const std::vector<int>& v) = 0; virtual void VoidFromVector(const std::vector<int>& v) = 0;
}; };
class Mock: public Interface { class Mock : public Interface {
public: public:
Mock() {} Mock() {}
...@@ -215,7 +214,7 @@ class Mock: public Interface { ...@@ -215,7 +214,7 @@ class Mock: public Interface {
MOCK_METHOD1(StringFromString, char*(char* str)); MOCK_METHOD1(StringFromString, char*(char* str));
MOCK_METHOD1(IntFromString, int(char* str)); MOCK_METHOD1(IntFromString, int(char* str));
MOCK_METHOD1(IntRefFromString, int&(char* str)); MOCK_METHOD1(IntRefFromString, int&(char* str));
MOCK_METHOD1(VoidFromFunc, void(void(*func)(char* str))); MOCK_METHOD1(VoidFromFunc, void(void (*func)(char* str)));
MOCK_METHOD1(VoidFromIntRef, void(int& n)); // NOLINT MOCK_METHOD1(VoidFromIntRef, void(int& n)); // NOLINT
MOCK_METHOD1(VoidFromFloat, void(float n)); MOCK_METHOD1(VoidFromFloat, void(float n));
MOCK_METHOD1(VoidFromDouble, void(double n)); MOCK_METHOD1(VoidFromDouble, void(double n));
...@@ -301,8 +300,8 @@ TEST(LinkTest, TestSetArrayArgument) { ...@@ -301,8 +300,8 @@ TEST(LinkTest, TestSetArrayArgument) {
char ch = 'x'; char ch = 'x';
char ch2 = 'y'; char ch2 = 'y';
EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArrayArgument<0>(&ch2, EXPECT_CALL(mock, VoidFromString(_))
&ch2 + 1)); .WillOnce(SetArrayArgument<0>(&ch2, &ch2 + 1));
mock.VoidFromString(&ch); mock.VoidFromString(&ch);
} }
...@@ -339,8 +338,8 @@ TEST(LinkTest, TestInvokeWithoutArgs) { ...@@ -339,8 +338,8 @@ TEST(LinkTest, TestInvokeWithoutArgs) {
EXPECT_CALL(mock, VoidFromString(_)) EXPECT_CALL(mock, VoidFromString(_))
.WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid)) .WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid))
.WillOnce(InvokeWithoutArgs(&test_invoke_helper, .WillOnce(
&InvokeHelper::VoidFromVoid)); InvokeWithoutArgs(&test_invoke_helper, &InvokeHelper::VoidFromVoid));
mock.VoidFromString(nullptr); mock.VoidFromString(nullptr);
mock.VoidFromString(nullptr); mock.VoidFromString(nullptr);
} }
...@@ -424,14 +423,14 @@ TEST(LinkTest, TestThrow) { ...@@ -424,14 +423,14 @@ TEST(LinkTest, TestThrow) {
// is expanded and macro expansion cannot contain #pragma. Therefore // is expanded and macro expansion cannot contain #pragma. Therefore
// we suppress them here. // we suppress them here.
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(push) #pragma warning(push)
# pragma warning(disable:4100) #pragma warning(disable : 4100)
#endif #endif
// Tests the linkage of actions created using ACTION macro. // Tests the linkage of actions created using ACTION macro.
namespace { namespace {
ACTION(Return1) { return 1; } ACTION(Return1) { return 1; }
} } // namespace
TEST(LinkTest, TestActionMacro) { TEST(LinkTest, TestActionMacro) {
Mock mock; Mock mock;
...@@ -443,7 +442,7 @@ TEST(LinkTest, TestActionMacro) { ...@@ -443,7 +442,7 @@ TEST(LinkTest, TestActionMacro) {
// Tests the linkage of actions created using ACTION_P macro. // Tests the linkage of actions created using ACTION_P macro.
namespace { namespace {
ACTION_P(ReturnArgument, ret_value) { return ret_value; } ACTION_P(ReturnArgument, ret_value) { return ret_value; }
} } // namespace
TEST(LinkTest, TestActionPMacro) { TEST(LinkTest, TestActionPMacro) {
Mock mock; Mock mock;
...@@ -457,10 +456,10 @@ namespace { ...@@ -457,10 +456,10 @@ namespace {
ACTION_P2(ReturnEqualsEitherOf, first, second) { ACTION_P2(ReturnEqualsEitherOf, first, second) {
return arg0 == first || arg0 == second; return arg0 == first || arg0 == second;
} }
} } // namespace
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(pop) #pragma warning(pop)
#endif #endif
TEST(LinkTest, TestActionP2Macro) { TEST(LinkTest, TestActionP2Macro) {
...@@ -492,8 +491,7 @@ TEST(LinkTest, TestMatchersEq) { ...@@ -492,8 +491,7 @@ TEST(LinkTest, TestMatchersEq) {
const char* p = "x"; const char* p = "x";
ON_CALL(mock, VoidFromString(Eq(p))).WillByDefault(Return()); ON_CALL(mock, VoidFromString(Eq(p))).WillByDefault(Return());
ON_CALL(mock, VoidFromString(const_cast<char*>("y"))) ON_CALL(mock, VoidFromString(const_cast<char*>("y"))).WillByDefault(Return());
.WillByDefault(Return());
} }
// Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers. // Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers.
...@@ -592,7 +590,7 @@ TEST(LinkTest, TestMatcherElementsAre) { ...@@ -592,7 +590,7 @@ TEST(LinkTest, TestMatcherElementsAre) {
// Tests the linkage of the ElementsAreArray matcher. // Tests the linkage of the ElementsAreArray matcher.
TEST(LinkTest, TestMatcherElementsAreArray) { TEST(LinkTest, TestMatcherElementsAreArray) {
Mock mock; Mock mock;
char arr[] = { 'a', 'b' }; char arr[] = {'a', 'b'};
ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return()); ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return());
} }
......
...@@ -27,21 +27,20 @@ ...@@ -27,21 +27,20 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Tests Google Mock's output in various scenarios. This ensures that // Tests Google Mock's output in various scenarios. This ensures that
// Google Mock's messages are readable and useful. // Google Mock's messages are readable and useful.
#include "gmock/gmock.h"
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
// Silence C4100 (unreferenced formal parameter) // Silence C4100 (unreferenced formal parameter)
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(push) #pragma warning(push)
# pragma warning(disable:4100) #pragma warning(disable : 4100)
#endif #endif
using testing::_; using testing::_;
...@@ -90,9 +89,7 @@ TEST_F(GMockOutputTest, ExpectedCallToVoidFunction) { ...@@ -90,9 +89,7 @@ TEST_F(GMockOutputTest, ExpectedCallToVoidFunction) {
} }
TEST_F(GMockOutputTest, ExplicitActionsRunOut) { TEST_F(GMockOutputTest, ExplicitActionsRunOut) {
EXPECT_CALL(foo_, Bar2(_, _)) EXPECT_CALL(foo_, Bar2(_, _)).Times(2).WillOnce(Return(false));
.Times(2)
.WillOnce(Return(false));
foo_.Bar2(2, 2); foo_.Bar2(2, 2);
foo_.Bar2(1, 1); // Explicit actions in EXPECT_CALL run out. foo_.Bar2(1, 1); // Explicit actions in EXPECT_CALL run out.
} }
...@@ -134,8 +131,7 @@ TEST_F(GMockOutputTest, UninterestingCallToVoidFunction) { ...@@ -134,8 +131,7 @@ TEST_F(GMockOutputTest, UninterestingCallToVoidFunction) {
} }
TEST_F(GMockOutputTest, RetiredExpectation) { TEST_F(GMockOutputTest, RetiredExpectation) {
EXPECT_CALL(foo_, Bar2(_, _)) EXPECT_CALL(foo_, Bar2(_, _)).RetiresOnSaturation();
.RetiresOnSaturation();
EXPECT_CALL(foo_, Bar2(0, 0)); EXPECT_CALL(foo_, Bar2(0, 0));
foo_.Bar2(1, 1); foo_.Bar2(1, 1);
...@@ -160,12 +156,9 @@ TEST_F(GMockOutputTest, UnsatisfiedPrerequisite) { ...@@ -160,12 +156,9 @@ TEST_F(GMockOutputTest, UnsatisfiedPrerequisite) {
TEST_F(GMockOutputTest, UnsatisfiedPrerequisites) { TEST_F(GMockOutputTest, UnsatisfiedPrerequisites) {
Sequence s1, s2; Sequence s1, s2;
EXPECT_CALL(foo_, Bar(_, 0, _)) EXPECT_CALL(foo_, Bar(_, 0, _)).InSequence(s1);
.InSequence(s1); EXPECT_CALL(foo_, Bar2(0, 0)).InSequence(s2);
EXPECT_CALL(foo_, Bar2(0, 0)) EXPECT_CALL(foo_, Bar2(1, _)).InSequence(s1, s2);
.InSequence(s2);
EXPECT_CALL(foo_, Bar2(1, _))
.InSequence(s1, s2);
foo_.Bar2(1, 0); // Has two immediate unsatisfied pre-requisites foo_.Bar2(1, 0); // Has two immediate unsatisfied pre-requisites
foo_.Bar("Hi", 0, 0); foo_.Bar("Hi", 0, 0);
...@@ -179,8 +172,7 @@ TEST_F(GMockOutputTest, UnsatisfiedWith) { ...@@ -179,8 +172,7 @@ TEST_F(GMockOutputTest, UnsatisfiedWith) {
TEST_F(GMockOutputTest, UnsatisfiedExpectation) { TEST_F(GMockOutputTest, UnsatisfiedExpectation) {
EXPECT_CALL(foo_, Bar(_, _, _)); EXPECT_CALL(foo_, Bar(_, _, _));
EXPECT_CALL(foo_, Bar2(0, _)) EXPECT_CALL(foo_, Bar2(0, _)).Times(2);
.Times(2);
foo_.Bar2(0, 1); foo_.Bar2(0, 1);
} }
...@@ -194,26 +186,22 @@ TEST_F(GMockOutputTest, MismatchArguments) { ...@@ -194,26 +186,22 @@ TEST_F(GMockOutputTest, MismatchArguments) {
} }
TEST_F(GMockOutputTest, MismatchWith) { TEST_F(GMockOutputTest, MismatchWith) {
EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1))) EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1))).With(Ge());
.With(Ge());
foo_.Bar2(2, 3); // Mismatch With() foo_.Bar2(2, 3); // Mismatch With()
foo_.Bar2(2, 1); foo_.Bar2(2, 1);
} }
TEST_F(GMockOutputTest, MismatchArgumentsAndWith) { TEST_F(GMockOutputTest, MismatchArgumentsAndWith) {
EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1))) EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1))).With(Ge());
.With(Ge());
foo_.Bar2(1, 3); // Mismatch arguments and mismatch With() foo_.Bar2(1, 3); // Mismatch arguments and mismatch With()
foo_.Bar2(2, 1); foo_.Bar2(2, 1);
} }
TEST_F(GMockOutputTest, UnexpectedCallWithDefaultAction) { TEST_F(GMockOutputTest, UnexpectedCallWithDefaultAction) {
ON_CALL(foo_, Bar2(_, _)) ON_CALL(foo_, Bar2(_, _)).WillByDefault(Return(true)); // Default action #1
.WillByDefault(Return(true)); // Default action #1 ON_CALL(foo_, Bar2(1, _)).WillByDefault(Return(false)); // Default action #2
ON_CALL(foo_, Bar2(1, _))
.WillByDefault(Return(false)); // Default action #2
EXPECT_CALL(foo_, Bar2(2, 2)); EXPECT_CALL(foo_, Bar2(2, 2));
foo_.Bar2(1, 0); // Unexpected call, takes default action #2. foo_.Bar2(1, 0); // Unexpected call, takes default action #2.
...@@ -222,10 +210,8 @@ TEST_F(GMockOutputTest, UnexpectedCallWithDefaultAction) { ...@@ -222,10 +210,8 @@ TEST_F(GMockOutputTest, UnexpectedCallWithDefaultAction) {
} }
TEST_F(GMockOutputTest, ExcessiveCallWithDefaultAction) { TEST_F(GMockOutputTest, ExcessiveCallWithDefaultAction) {
ON_CALL(foo_, Bar2(_, _)) ON_CALL(foo_, Bar2(_, _)).WillByDefault(Return(true)); // Default action #1
.WillByDefault(Return(true)); // Default action #1 ON_CALL(foo_, Bar2(1, _)).WillByDefault(Return(false)); // Default action #2
ON_CALL(foo_, Bar2(1, _))
.WillByDefault(Return(false)); // Default action #2
EXPECT_CALL(foo_, Bar2(2, 2)); EXPECT_CALL(foo_, Bar2(2, 2));
EXPECT_CALL(foo_, Bar2(1, 1)); EXPECT_CALL(foo_, Bar2(1, 1));
...@@ -237,22 +223,17 @@ TEST_F(GMockOutputTest, ExcessiveCallWithDefaultAction) { ...@@ -237,22 +223,17 @@ TEST_F(GMockOutputTest, ExcessiveCallWithDefaultAction) {
} }
TEST_F(GMockOutputTest, UninterestingCallWithDefaultAction) { TEST_F(GMockOutputTest, UninterestingCallWithDefaultAction) {
ON_CALL(foo_, Bar2(_, _)) ON_CALL(foo_, Bar2(_, _)).WillByDefault(Return(true)); // Default action #1
.WillByDefault(Return(true)); // Default action #1 ON_CALL(foo_, Bar2(1, _)).WillByDefault(Return(false)); // Default action #2
ON_CALL(foo_, Bar2(1, _))
.WillByDefault(Return(false)); // Default action #2
foo_.Bar2(2, 2); // Uninteresting call, takes default action #1. foo_.Bar2(2, 2); // Uninteresting call, takes default action #1.
foo_.Bar2(1, 1); // Uninteresting call, takes default action #2. foo_.Bar2(1, 1); // Uninteresting call, takes default action #2.
} }
TEST_F(GMockOutputTest, ExplicitActionsRunOutWithDefaultAction) { TEST_F(GMockOutputTest, ExplicitActionsRunOutWithDefaultAction) {
ON_CALL(foo_, Bar2(_, _)) ON_CALL(foo_, Bar2(_, _)).WillByDefault(Return(true)); // Default action #1
.WillByDefault(Return(true)); // Default action #1
EXPECT_CALL(foo_, Bar2(_, _)) EXPECT_CALL(foo_, Bar2(_, _)).Times(2).WillOnce(Return(false));
.Times(2)
.WillOnce(Return(false));
foo_.Bar2(2, 2); foo_.Bar2(2, 2);
foo_.Bar2(1, 1); // Explicit actions in EXPECT_CALL run out. foo_.Bar2(1, 1); // Explicit actions in EXPECT_CALL run out.
} }
...@@ -293,7 +274,7 @@ void TestCatchesLeakedMocksInAdHocTests() { ...@@ -293,7 +274,7 @@ void TestCatchesLeakedMocksInAdHocTests() {
// foo is deliberately leaked. // foo is deliberately leaked.
} }
int main(int argc, char **argv) { int main(int argc, char** argv) {
testing::InitGoogleMock(&argc, argv); testing::InitGoogleMock(&argc, argv);
// Ensures that the tests pass no matter what value of // Ensures that the tests pass no matter what value of
// --gmock_catch_leaked_mocks and --gmock_verbose the user specifies. // --gmock_catch_leaked_mocks and --gmock_verbose the user specifies.
...@@ -305,5 +286,5 @@ int main(int argc, char **argv) { ...@@ -305,5 +286,5 @@ int main(int argc, char **argv) {
} }
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(pop) #pragma warning(pop)
#endif #endif
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Tests that Google Mock constructs can be used in a large number of // Tests that Google Mock constructs can be used in a large number of
// threads concurrently. // threads concurrently.
...@@ -49,7 +48,7 @@ const int kRepeat = 50; ...@@ -49,7 +48,7 @@ const int kRepeat = 50;
class MockFoo { class MockFoo {
public: public:
MOCK_METHOD1(Bar, int(int n)); // NOLINT MOCK_METHOD1(Bar, int(int n)); // NOLINT
MOCK_METHOD2(Baz, char(const char* s1, const std::string& s2)); // NOLINT MOCK_METHOD2(Baz, char(const char* s1, const std::string& s2)); // NOLINT
}; };
...@@ -62,21 +61,16 @@ void JoinAndDelete(ThreadWithParam<T>* t) { ...@@ -62,21 +61,16 @@ void JoinAndDelete(ThreadWithParam<T>* t) {
struct Dummy {}; struct Dummy {};
// Tests that different mock objects can be used in their respective // Tests that different mock objects can be used in their respective
// threads. This should generate no Google Test failure. // threads. This should generate no Google Test failure.
void TestConcurrentMockObjects(Dummy /* dummy */) { void TestConcurrentMockObjects(Dummy /* dummy */) {
// Creates a mock and does some typical operations on it. // Creates a mock and does some typical operations on it.
MockFoo foo; MockFoo foo;
ON_CALL(foo, Bar(_)) ON_CALL(foo, Bar(_)).WillByDefault(Return(1));
.WillByDefault(Return(1)); ON_CALL(foo, Baz(_, _)).WillByDefault(Return('b'));
ON_CALL(foo, Baz(_, _)) ON_CALL(foo, Baz(_, "you")).WillByDefault(Return('a'));
.WillByDefault(Return('b'));
ON_CALL(foo, Baz(_, "you")) EXPECT_CALL(foo, Bar(0)).Times(AtMost(3));
.WillByDefault(Return('a'));
EXPECT_CALL(foo, Bar(0))
.Times(AtMost(3));
EXPECT_CALL(foo, Baz(_, _)); EXPECT_CALL(foo, Baz(_, _));
EXPECT_CALL(foo, Baz("hi", "you")) EXPECT_CALL(foo, Baz("hi", "you"))
.WillOnce(Return('z')) .WillOnce(Return('z'))
...@@ -119,22 +113,19 @@ void Helper1(Helper1Param param) { ...@@ -119,22 +113,19 @@ void Helper1(Helper1Param param) {
void TestConcurrentCallsOnSameObject(Dummy /* dummy */) { void TestConcurrentCallsOnSameObject(Dummy /* dummy */) {
MockFoo foo; MockFoo foo;
ON_CALL(foo, Bar(_)) ON_CALL(foo, Bar(_)).WillByDefault(Return(1));
.WillByDefault(Return(1)); EXPECT_CALL(foo, Baz(_, "b")).Times(kRepeat).WillRepeatedly(Return('a'));
EXPECT_CALL(foo, Baz(_, "b"))
.Times(kRepeat)
.WillRepeatedly(Return('a'));
EXPECT_CALL(foo, Baz(_, "c")); // Expected to be unsatisfied. EXPECT_CALL(foo, Baz(_, "c")); // Expected to be unsatisfied.
// This chunk of code should generate kRepeat failures about // This chunk of code should generate kRepeat failures about
// excessive calls, and 2*kRepeat failures about unexpected calls. // excessive calls, and 2*kRepeat failures about unexpected calls.
int count1 = 0; int count1 = 0;
const Helper1Param param = { &foo, &count1 }; const Helper1Param param = {&foo, &count1};
ThreadWithParam<Helper1Param>* const t = ThreadWithParam<Helper1Param>* const t =
new ThreadWithParam<Helper1Param>(Helper1, param, nullptr); new ThreadWithParam<Helper1Param>(Helper1, param, nullptr);
int count2 = 0; int count2 = 0;
const Helper1Param param2 = { &foo, &count2 }; const Helper1Param param2 = {&foo, &count2};
Helper1(param2); Helper1(param2);
JoinAndDelete(t); JoinAndDelete(t);
...@@ -162,22 +153,18 @@ void TestPartiallyOrderedExpectationsWithThreads(Dummy /* dummy */) { ...@@ -162,22 +153,18 @@ void TestPartiallyOrderedExpectationsWithThreads(Dummy /* dummy */) {
{ {
InSequence dummy; InSequence dummy;
EXPECT_CALL(foo, Bar(0)); EXPECT_CALL(foo, Bar(0));
EXPECT_CALL(foo, Bar(1)) EXPECT_CALL(foo, Bar(1)).InSequence(s1, s2);
.InSequence(s1, s2);
} }
EXPECT_CALL(foo, Bar(2)) EXPECT_CALL(foo, Bar(2))
.Times(2*kRepeat) .Times(2 * kRepeat)
.InSequence(s1) .InSequence(s1)
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_CALL(foo, Bar(3)) EXPECT_CALL(foo, Bar(3)).Times(2 * kRepeat).InSequence(s2);
.Times(2*kRepeat)
.InSequence(s2);
{ {
InSequence dummy; InSequence dummy;
EXPECT_CALL(foo, Bar(2)) EXPECT_CALL(foo, Bar(2)).InSequence(s1, s2);
.InSequence(s1, s2);
EXPECT_CALL(foo, Bar(4)); EXPECT_CALL(foo, Bar(4));
} }
...@@ -196,12 +183,12 @@ void TestPartiallyOrderedExpectationsWithThreads(Dummy /* dummy */) { ...@@ -196,12 +183,12 @@ void TestPartiallyOrderedExpectationsWithThreads(Dummy /* dummy */) {
// Tests using Google Mock constructs in many threads concurrently. // Tests using Google Mock constructs in many threads concurrently.
TEST(StressTest, CanUseGMockWithThreads) { TEST(StressTest, CanUseGMockWithThreads) {
void (*test_routines[])(Dummy dummy) = { void (*test_routines[])(Dummy dummy) = {
&TestConcurrentMockObjects, &TestConcurrentMockObjects,
&TestConcurrentCallsOnSameObject, &TestConcurrentCallsOnSameObject,
&TestPartiallyOrderedExpectationsWithThreads, &TestPartiallyOrderedExpectationsWithThreads,
}; };
const int kRoutines = sizeof(test_routines)/sizeof(test_routines[0]); const int kRoutines = sizeof(test_routines) / sizeof(test_routines[0]);
const int kCopiesOfEachRoutine = kMaxTestThreads / kRoutines; const int kCopiesOfEachRoutine = kMaxTestThreads / kRoutines;
const int kTestThreads = kCopiesOfEachRoutine * kRoutines; const int kTestThreads = kCopiesOfEachRoutine * kRoutines;
ThreadWithParam<Dummy>* threads[kTestThreads] = {}; ThreadWithParam<Dummy>* threads[kTestThreads] = {};
...@@ -220,7 +207,7 @@ TEST(StressTest, CanUseGMockWithThreads) { ...@@ -220,7 +207,7 @@ TEST(StressTest, CanUseGMockWithThreads) {
// Ensures that the correct number of failures have been reported. // Ensures that the correct number of failures have been reported.
const TestInfo* const info = UnitTest::GetInstance()->current_test_info(); const TestInfo* const info = UnitTest::GetInstance()->current_test_info();
const TestResult& result = *info->result(); const TestResult& result = *info->result();
const int kExpectedFailures = (3*kRepeat + 1)*kCopiesOfEachRoutine; const int kExpectedFailures = (3 * kRepeat + 1) * kCopiesOfEachRoutine;
GTEST_CHECK_(kExpectedFailures == result.total_part_count()) GTEST_CHECK_(kExpectedFailures == result.total_part_count())
<< "Expected " << kExpectedFailures << " failures, but got " << "Expected " << kExpectedFailures << " failures, but got "
<< result.total_part_count(); << result.total_part_count();
...@@ -229,7 +216,7 @@ TEST(StressTest, CanUseGMockWithThreads) { ...@@ -229,7 +216,7 @@ TEST(StressTest, CanUseGMockWithThreads) {
} // namespace } // namespace
} // namespace testing } // namespace testing
int main(int argc, char **argv) { int main(int argc, char** argv) {
testing::InitGoogleMock(&argc, argv); testing::InitGoogleMock(&argc, argv);
const int exit_code = RUN_ALL_TESTS(); // Expected to fail. const int exit_code = RUN_ALL_TESTS(); // Expected to fail.
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file tests code in gmock.cc. // This file tests code in gmock.cc.
...@@ -35,6 +34,7 @@ ...@@ -35,6 +34,7 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include <string> #include <string>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "gtest/internal/custom/gtest.h" #include "gtest/internal/custom/gtest.h"
......
...@@ -170,24 +170,24 @@ GTEST_API_ bool InDeathTestChild(); ...@@ -170,24 +170,24 @@ GTEST_API_ bool InDeathTestChild();
// Asserts that a given `statement` causes the program to exit, with an // Asserts that a given `statement` causes the program to exit, with an
// integer exit status that satisfies `predicate`, and emitting error output // integer exit status that satisfies `predicate`, and emitting error output
// that matches `matcher`. // that matches `matcher`.
# define ASSERT_EXIT(statement, predicate, matcher) \ #define ASSERT_EXIT(statement, predicate, matcher) \
GTEST_DEATH_TEST_(statement, predicate, matcher, GTEST_FATAL_FAILURE_) GTEST_DEATH_TEST_(statement, predicate, matcher, GTEST_FATAL_FAILURE_)
// Like `ASSERT_EXIT`, but continues on to successive tests in the // Like `ASSERT_EXIT`, but continues on to successive tests in the
// test suite, if any: // test suite, if any:
# define EXPECT_EXIT(statement, predicate, matcher) \ #define EXPECT_EXIT(statement, predicate, matcher) \
GTEST_DEATH_TEST_(statement, predicate, matcher, GTEST_NONFATAL_FAILURE_) GTEST_DEATH_TEST_(statement, predicate, matcher, GTEST_NONFATAL_FAILURE_)
// Asserts that a given `statement` causes the program to exit, either by // Asserts that a given `statement` causes the program to exit, either by
// explicitly exiting with a nonzero exit code or being killed by a // explicitly exiting with a nonzero exit code or being killed by a
// signal, and emitting error output that matches `matcher`. // signal, and emitting error output that matches `matcher`.
# define ASSERT_DEATH(statement, matcher) \ #define ASSERT_DEATH(statement, matcher) \
ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher) ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher)
// Like `ASSERT_DEATH`, but continues on to successive tests in the // Like `ASSERT_DEATH`, but continues on to successive tests in the
// test suite, if any: // test suite, if any:
# define EXPECT_DEATH(statement, matcher) \ #define EXPECT_DEATH(statement, matcher) \
EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher) EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher)
// Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*: // Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*:
...@@ -198,21 +198,23 @@ class GTEST_API_ ExitedWithCode { ...@@ -198,21 +198,23 @@ class GTEST_API_ ExitedWithCode {
ExitedWithCode(const ExitedWithCode&) = default; ExitedWithCode(const ExitedWithCode&) = default;
void operator=(const ExitedWithCode& other) = delete; void operator=(const ExitedWithCode& other) = delete;
bool operator()(int exit_status) const; bool operator()(int exit_status) const;
private: private:
const int exit_code_; const int exit_code_;
}; };
# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA #if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
// Tests that an exit code describes an exit due to termination by a // Tests that an exit code describes an exit due to termination by a
// given signal. // given signal.
class GTEST_API_ KilledBySignal { class GTEST_API_ KilledBySignal {
public: public:
explicit KilledBySignal(int signum); explicit KilledBySignal(int signum);
bool operator()(int exit_status) const; bool operator()(int exit_status) const;
private: private:
const int signum_; const int signum_;
}; };
# endif // !GTEST_OS_WINDOWS #endif // !GTEST_OS_WINDOWS
// EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode. // EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode.
// The death testing framework causes this to have interesting semantics, // The death testing framework causes this to have interesting semantics,
...@@ -257,23 +259,21 @@ class GTEST_API_ KilledBySignal { ...@@ -257,23 +259,21 @@ class GTEST_API_ KilledBySignal {
// EXPECT_EQ(12, DieInDebugOr12(&sideeffect)); // EXPECT_EQ(12, DieInDebugOr12(&sideeffect));
// }, "death"); // }, "death");
// //
# ifdef NDEBUG #ifdef NDEBUG
# define EXPECT_DEBUG_DEATH(statement, regex) \ #define EXPECT_DEBUG_DEATH(statement, regex) \
GTEST_EXECUTE_STATEMENT_(statement, regex) GTEST_EXECUTE_STATEMENT_(statement, regex)
# define ASSERT_DEBUG_DEATH(statement, regex) \ #define ASSERT_DEBUG_DEATH(statement, regex) \
GTEST_EXECUTE_STATEMENT_(statement, regex) GTEST_EXECUTE_STATEMENT_(statement, regex)
# else #else
# define EXPECT_DEBUG_DEATH(statement, regex) \ #define EXPECT_DEBUG_DEATH(statement, regex) EXPECT_DEATH(statement, regex)
EXPECT_DEATH(statement, regex)
# define ASSERT_DEBUG_DEATH(statement, regex) \ #define ASSERT_DEBUG_DEATH(statement, regex) ASSERT_DEATH(statement, regex)
ASSERT_DEATH(statement, regex)
# endif // NDEBUG for EXPECT_DEBUG_DEATH #endif // NDEBUG for EXPECT_DEBUG_DEATH
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST
// This macro is used for implementing macros such as // This macro is used for implementing macros such as
...@@ -311,18 +311,17 @@ class GTEST_API_ KilledBySignal { ...@@ -311,18 +311,17 @@ class GTEST_API_ KilledBySignal {
// statement unconditionally returns or throws. The Message constructor at // statement unconditionally returns or throws. The Message constructor at
// the end allows the syntax of streaming additional messages into the // the end allows the syntax of streaming additional messages into the
// macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH. // macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.
# define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, terminator) \ #define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, terminator) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::AlwaysTrue()) { \ if (::testing::internal::AlwaysTrue()) { \
GTEST_LOG_(WARNING) \ GTEST_LOG_(WARNING) << "Death tests are not supported on this platform.\n" \
<< "Death tests are not supported on this platform.\n" \ << "Statement '" #statement "' cannot be verified."; \
<< "Statement '" #statement "' cannot be verified."; \ } else if (::testing::internal::AlwaysFalse()) { \
} else if (::testing::internal::AlwaysFalse()) { \ ::testing::internal::RE::PartialMatch(".*", (regex)); \
::testing::internal::RE::PartialMatch(".*", (regex)); \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ terminator; \
terminator; \ } else \
} else \ ::testing::Message()
::testing::Message()
// EXPECT_DEATH_IF_SUPPORTED(statement, regex) and // EXPECT_DEATH_IF_SUPPORTED(statement, regex) and
// ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if // ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if
...@@ -330,15 +329,15 @@ class GTEST_API_ KilledBySignal { ...@@ -330,15 +329,15 @@ class GTEST_API_ KilledBySignal {
// useful when you are combining death test assertions with normal test // useful when you are combining death test assertions with normal test
// assertions in one test. // assertions in one test.
#if GTEST_HAS_DEATH_TEST #if GTEST_HAS_DEATH_TEST
# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ #define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
EXPECT_DEATH(statement, regex) EXPECT_DEATH(statement, regex)
# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ #define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
ASSERT_DEATH(statement, regex) ASSERT_DEATH(statement, regex)
#else #else
# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ #define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, ) GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, )
# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ #define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return) GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return)
#endif #endif
} // namespace testing } // namespace testing
......
...@@ -105,8 +105,7 @@ class MatchResultListener { ...@@ -105,8 +105,7 @@ class MatchResultListener {
GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener); GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener);
}; };
inline MatchResultListener::~MatchResultListener() { inline MatchResultListener::~MatchResultListener() {}
}
// An instance of a subclass of this knows how to describe itself as a // An instance of a subclass of this knows how to describe itself as a
// matcher. // matcher.
...@@ -180,27 +179,39 @@ namespace internal { ...@@ -180,27 +179,39 @@ namespace internal {
struct AnyEq { struct AnyEq {
template <typename A, typename B> template <typename A, typename B>
bool operator()(const A& a, const B& b) const { return a == b; } bool operator()(const A& a, const B& b) const {
return a == b;
}
}; };
struct AnyNe { struct AnyNe {
template <typename A, typename B> template <typename A, typename B>
bool operator()(const A& a, const B& b) const { return a != b; } bool operator()(const A& a, const B& b) const {
return a != b;
}
}; };
struct AnyLt { struct AnyLt {
template <typename A, typename B> template <typename A, typename B>
bool operator()(const A& a, const B& b) const { return a < b; } bool operator()(const A& a, const B& b) const {
return a < b;
}
}; };
struct AnyGt { struct AnyGt {
template <typename A, typename B> template <typename A, typename B>
bool operator()(const A& a, const B& b) const { return a > b; } bool operator()(const A& a, const B& b) const {
return a > b;
}
}; };
struct AnyLe { struct AnyLe {
template <typename A, typename B> template <typename A, typename B>
bool operator()(const A& a, const B& b) const { return a <= b; } bool operator()(const A& a, const B& b) const {
return a <= b;
}
}; };
struct AnyGe { struct AnyGe {
template <typename A, typename B> template <typename A, typename B>
bool operator()(const A& a, const B& b) const { return a >= b; } bool operator()(const A& a, const B& b) const {
return a >= b;
}
}; };
// A match result listener that ignores the explanation. // A match result listener that ignores the explanation.
...@@ -424,8 +435,8 @@ class MatcherBase : private MatcherDescriberInterface { ...@@ -424,8 +435,8 @@ class MatcherBase : private MatcherDescriberInterface {
static const M& Get(const MatcherBase& m) { static const M& Get(const MatcherBase& m) {
// When inlined along with Init, need to be explicit to avoid violating // When inlined along with Init, need to be explicit to avoid violating
// strict aliasing rules. // strict aliasing rules.
const M *ptr = static_cast<const M*>( const M* ptr =
static_cast<const void*>(&m.buffer_)); static_cast<const M*>(static_cast<const void*>(&m.buffer_));
return *ptr; return *ptr;
} }
static void Init(MatcherBase& m, M impl) { static void Init(MatcherBase& m, M impl) {
...@@ -745,7 +756,7 @@ template <typename Rhs> ...@@ -745,7 +756,7 @@ template <typename Rhs>
class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq> { class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq> {
public: public:
explicit EqMatcher(const Rhs& rhs) explicit EqMatcher(const Rhs& rhs)
: ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq>(rhs) { } : ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq>(rhs) {}
static const char* Desc() { return "is equal to"; } static const char* Desc() { return "is equal to"; }
static const char* NegatedDesc() { return "isn't equal to"; } static const char* NegatedDesc() { return "isn't equal to"; }
}; };
...@@ -753,7 +764,7 @@ template <typename Rhs> ...@@ -753,7 +764,7 @@ template <typename Rhs>
class NeMatcher : public ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe> { class NeMatcher : public ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe> {
public: public:
explicit NeMatcher(const Rhs& rhs) explicit NeMatcher(const Rhs& rhs)
: ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe>(rhs) { } : ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe>(rhs) {}
static const char* Desc() { return "isn't equal to"; } static const char* Desc() { return "isn't equal to"; }
static const char* NegatedDesc() { return "is equal to"; } static const char* NegatedDesc() { return "is equal to"; }
}; };
...@@ -761,7 +772,7 @@ template <typename Rhs> ...@@ -761,7 +772,7 @@ template <typename Rhs>
class LtMatcher : public ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt> { class LtMatcher : public ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt> {
public: public:
explicit LtMatcher(const Rhs& rhs) explicit LtMatcher(const Rhs& rhs)
: ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt>(rhs) { } : ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt>(rhs) {}
static const char* Desc() { return "is <"; } static const char* Desc() { return "is <"; }
static const char* NegatedDesc() { return "isn't <"; } static const char* NegatedDesc() { return "isn't <"; }
}; };
...@@ -769,7 +780,7 @@ template <typename Rhs> ...@@ -769,7 +780,7 @@ template <typename Rhs>
class GtMatcher : public ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt> { class GtMatcher : public ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt> {
public: public:
explicit GtMatcher(const Rhs& rhs) explicit GtMatcher(const Rhs& rhs)
: ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt>(rhs) { } : ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt>(rhs) {}
static const char* Desc() { return "is >"; } static const char* Desc() { return "is >"; }
static const char* NegatedDesc() { return "isn't >"; } static const char* NegatedDesc() { return "isn't >"; }
}; };
...@@ -777,7 +788,7 @@ template <typename Rhs> ...@@ -777,7 +788,7 @@ template <typename Rhs>
class LeMatcher : public ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe> { class LeMatcher : public ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe> {
public: public:
explicit LeMatcher(const Rhs& rhs) explicit LeMatcher(const Rhs& rhs)
: ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe>(rhs) { } : ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe>(rhs) {}
static const char* Desc() { return "is <="; } static const char* Desc() { return "is <="; }
static const char* NegatedDesc() { return "isn't <="; } static const char* NegatedDesc() { return "isn't <="; }
}; };
...@@ -785,7 +796,7 @@ template <typename Rhs> ...@@ -785,7 +796,7 @@ template <typename Rhs>
class GeMatcher : public ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe> { class GeMatcher : public ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe> {
public: public:
explicit GeMatcher(const Rhs& rhs) explicit GeMatcher(const Rhs& rhs)
: ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe>(rhs) { } : ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe>(rhs) {}
static const char* Desc() { return "is >="; } static const char* Desc() { return "is >="; }
static const char* NegatedDesc() { return "isn't >="; } static const char* NegatedDesc() { return "isn't >="; }
}; };
...@@ -876,12 +887,16 @@ PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex( ...@@ -876,12 +887,16 @@ PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
// Note: if the parameter of Eq() were declared as const T&, Eq("foo") // Note: if the parameter of Eq() were declared as const T&, Eq("foo")
// wouldn't compile. // wouldn't compile.
template <typename T> template <typename T>
inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); } inline internal::EqMatcher<T> Eq(T x) {
return internal::EqMatcher<T>(x);
}
// Constructs a Matcher<T> from a 'value' of type T. The constructed // Constructs a Matcher<T> from a 'value' of type T. The constructed
// matcher matches any value that's equal to 'value'. // matcher matches any value that's equal to 'value'.
template <typename T> template <typename T>
Matcher<T>::Matcher(T value) { *this = Eq(value); } Matcher<T>::Matcher(T value) {
*this = Eq(value);
}
// Creates a monomorphic matcher that matches anything with type Lhs // Creates a monomorphic matcher that matches anything with type Lhs
// and equal to rhs. A user may need to use this instead of Eq(...) // and equal to rhs. A user may need to use this instead of Eq(...)
...@@ -896,7 +911,9 @@ Matcher<T>::Matcher(T value) { *this = Eq(value); } ...@@ -896,7 +911,9 @@ Matcher<T>::Matcher(T value) { *this = Eq(value); }
// can always write Matcher<T>(Lt(5)) to be explicit about the type, // can always write Matcher<T>(Lt(5)) to be explicit about the type,
// for example. // for example.
template <typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
inline Matcher<Lhs> TypedEq(const Rhs& rhs) { return Eq(rhs); } inline Matcher<Lhs> TypedEq(const Rhs& rhs) {
return Eq(rhs);
}
// Creates a polymorphic matcher that matches anything >= x. // Creates a polymorphic matcher that matches anything >= x.
template <typename Rhs> template <typename Rhs>
......
...@@ -111,8 +111,8 @@ class GTEST_API_ Message { ...@@ -111,8 +111,8 @@ class GTEST_API_ Message {
// Streams a non-pointer value to this object. // Streams a non-pointer value to this object.
template <typename T> template <typename T>
inline Message& operator <<(const T& val) { inline Message& operator<<(const T& val) {
// Some libraries overload << for STL containers. These // Some libraries overload << for STL containers. These
// overloads are defined in the global namespace instead of ::std. // overloads are defined in the global namespace instead of ::std.
// //
// C++'s symbol lookup rule (i.e. Koenig lookup) says that these // C++'s symbol lookup rule (i.e. Koenig lookup) says that these
...@@ -126,7 +126,7 @@ class GTEST_API_ Message { ...@@ -126,7 +126,7 @@ class GTEST_API_ Message {
// from the global namespace. With this using declaration, // from the global namespace. With this using declaration,
// overloads of << defined in the global namespace and those // overloads of << defined in the global namespace and those
// visible via Koenig lookup are both exposed in this function. // visible via Koenig lookup are both exposed in this function.
using ::operator <<; using ::operator<<;
*ss_ << val; *ss_ << val;
return *this; return *this;
} }
...@@ -145,7 +145,7 @@ class GTEST_API_ Message { ...@@ -145,7 +145,7 @@ class GTEST_API_ Message {
// ensure consistent result across compilers, we always treat NULL // ensure consistent result across compilers, we always treat NULL
// as "(null)". // as "(null)".
template <typename T> template <typename T>
inline Message& operator <<(T* const& pointer) { // NOLINT inline Message& operator<<(T* const& pointer) { // NOLINT
if (pointer == nullptr) { if (pointer == nullptr) {
*ss_ << "(null)"; *ss_ << "(null)";
} else { } else {
...@@ -160,25 +160,23 @@ class GTEST_API_ Message { ...@@ -160,25 +160,23 @@ class GTEST_API_ Message {
// templatized version above. Without this definition, streaming // templatized version above. Without this definition, streaming
// endl or other basic IO manipulators to Message will confuse the // endl or other basic IO manipulators to Message will confuse the
// compiler. // compiler.
Message& operator <<(BasicNarrowIoManip val) { Message& operator<<(BasicNarrowIoManip val) {
*ss_ << val; *ss_ << val;
return *this; return *this;
} }
// Instead of 1/0, we want to see true/false for bool values. // Instead of 1/0, we want to see true/false for bool values.
Message& operator <<(bool b) { Message& operator<<(bool b) { return *this << (b ? "true" : "false"); }
return *this << (b ? "true" : "false");
}
// These two overloads allow streaming a wide C string to a Message // These two overloads allow streaming a wide C string to a Message
// using the UTF-8 encoding. // using the UTF-8 encoding.
Message& operator <<(const wchar_t* wide_c_str); Message& operator<<(const wchar_t* wide_c_str);
Message& operator <<(wchar_t* wide_c_str); Message& operator<<(wchar_t* wide_c_str);
#if GTEST_HAS_STD_WSTRING #if GTEST_HAS_STD_WSTRING
// Converts the given wide string to a narrow string using the UTF-8 // Converts the given wide string to a narrow string using the UTF-8
// encoding, and streams the result to this Message object. // encoding, and streams the result to this Message object.
Message& operator <<(const ::std::wstring& wstr); Message& operator<<(const ::std::wstring& wstr);
#endif // GTEST_HAS_STD_WSTRING #endif // GTEST_HAS_STD_WSTRING
// Gets the text streamed to this object so far as an std::string. // Gets the text streamed to this object so far as an std::string.
...@@ -197,7 +195,7 @@ class GTEST_API_ Message { ...@@ -197,7 +195,7 @@ class GTEST_API_ Message {
}; };
// Streams a Message to an ostream. // Streams a Message to an ostream.
inline std::ostream& operator <<(std::ostream& os, const Message& sb) { inline std::ostream& operator<<(std::ostream& os, const Message& sb) {
return os << sb.GetString(); return os << sb.GetString();
} }
......
...@@ -356,9 +356,7 @@ internal::ValueArray<T...> Values(T... v) { ...@@ -356,9 +356,7 @@ internal::ValueArray<T...> Values(T... v) {
// } // }
// INSTANTIATE_TEST_SUITE_P(BoolSequence, FlagDependentTest, Bool()); // INSTANTIATE_TEST_SUITE_P(BoolSequence, FlagDependentTest, Bool());
// //
inline internal::ParamGenerator<bool> Bool() { inline internal::ParamGenerator<bool> Bool() { return Values(false, true); }
return Values(false, true);
}
// Combine() allows the user to combine two or more sequences to produce // Combine() allows the user to combine two or more sequences to produce
// values of a Cartesian product of those sequences' elements. // values of a Cartesian product of those sequences' elements.
...@@ -456,43 +454,42 @@ internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) { ...@@ -456,43 +454,42 @@ internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) {
#define GTEST_GET_FIRST_(first, ...) first #define GTEST_GET_FIRST_(first, ...) first
#define GTEST_GET_SECOND_(first, second, ...) second #define GTEST_GET_SECOND_(first, second, ...) second
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, ...) \ #define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, ...) \
static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \ static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \
gtest_##prefix##test_suite_name##_EvalGenerator_() { \ gtest_##prefix##test_suite_name##_EvalGenerator_() { \
return GTEST_EXPAND_(GTEST_GET_FIRST_(__VA_ARGS__, DUMMY_PARAM_)); \ return GTEST_EXPAND_(GTEST_GET_FIRST_(__VA_ARGS__, DUMMY_PARAM_)); \
} \ } \
static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \ static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \
const ::testing::TestParamInfo<test_suite_name::ParamType>& info) { \ const ::testing::TestParamInfo<test_suite_name::ParamType>& info) { \
if (::testing::internal::AlwaysFalse()) { \ if (::testing::internal::AlwaysFalse()) { \
::testing::internal::TestNotEmpty(GTEST_EXPAND_(GTEST_GET_SECOND_( \ ::testing::internal::TestNotEmpty(GTEST_EXPAND_(GTEST_GET_SECOND_( \
__VA_ARGS__, \ __VA_ARGS__, \
::testing::internal::DefaultParamName<test_suite_name::ParamType>, \ ::testing::internal::DefaultParamName<test_suite_name::ParamType>, \
DUMMY_PARAM_))); \ DUMMY_PARAM_))); \
auto t = std::make_tuple(__VA_ARGS__); \ auto t = std::make_tuple(__VA_ARGS__); \
static_assert(std::tuple_size<decltype(t)>::value <= 2, \ static_assert(std::tuple_size<decltype(t)>::value <= 2, \
"Too Many Args!"); \ "Too Many Args!"); \
} \ } \
return ((GTEST_EXPAND_(GTEST_GET_SECOND_( \ return ((GTEST_EXPAND_(GTEST_GET_SECOND_( \
__VA_ARGS__, \ __VA_ARGS__, \
::testing::internal::DefaultParamName<test_suite_name::ParamType>, \ ::testing::internal::DefaultParamName<test_suite_name::ParamType>, \
DUMMY_PARAM_))))(info); \ DUMMY_PARAM_))))(info); \
} \ } \
static int gtest_##prefix##test_suite_name##_dummy_ \ static int gtest_##prefix##test_suite_name##_dummy_ \
GTEST_ATTRIBUTE_UNUSED_ = \ GTEST_ATTRIBUTE_UNUSED_ = \
::testing::UnitTest::GetInstance() \ ::testing::UnitTest::GetInstance() \
->parameterized_test_registry() \ ->parameterized_test_registry() \
.GetTestSuitePatternHolder<test_suite_name>( \ .GetTestSuitePatternHolder<test_suite_name>( \
GTEST_STRINGIFY_(test_suite_name), \ GTEST_STRINGIFY_(test_suite_name), \
::testing::internal::CodeLocation(__FILE__, __LINE__)) \ ::testing::internal::CodeLocation(__FILE__, __LINE__)) \
->AddTestSuiteInstantiation( \ ->AddTestSuiteInstantiation( \
GTEST_STRINGIFY_(prefix), \ GTEST_STRINGIFY_(prefix), \
&gtest_##prefix##test_suite_name##_EvalGenerator_, \ &gtest_##prefix##test_suite_name##_EvalGenerator_, \
&gtest_##prefix##test_suite_name##_EvalGenerateName_, \ &gtest_##prefix##test_suite_name##_EvalGenerateName_, \
__FILE__, __LINE__) __FILE__, __LINE__)
// Allow Marking a Parameterized test class as not needing to be instantiated. // Allow Marking a Parameterized test class as not needing to be instantiated.
#define GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(T) \ #define GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(T) \
namespace gtest_do_not_use_outside_namespace_scope {} \ namespace gtest_do_not_use_outside_namespace_scope {} \
static const ::testing::internal::MarkAsIgnored gtest_allow_ignore_##T( \ static const ::testing::internal::MarkAsIgnored gtest_allow_ignore_##T( \
GTEST_STRINGIFY_(T)) GTEST_STRINGIFY_(T))
......
...@@ -258,12 +258,10 @@ struct ConvertibleToStringViewPrinter { ...@@ -258,12 +258,10 @@ struct ConvertibleToStringViewPrinter {
#endif #endif
}; };
// Prints the given number of bytes in the given object to the given // Prints the given number of bytes in the given object to the given
// ostream. // ostream.
GTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes, GTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes,
size_t count, size_t count, ::std::ostream* os);
::std::ostream* os);
struct RawBytesPrinter { struct RawBytesPrinter {
// SFINAE on `sizeof` to make sure we have a complete type. // SFINAE on `sizeof` to make sure we have a complete type.
template <typename T, size_t = sizeof(T)> template <typename T, size_t = sizeof(T)>
...@@ -376,12 +374,12 @@ GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char32_t); ...@@ -376,12 +374,12 @@ GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char32_t);
// to point to a NUL-terminated string, and thus can print it as a string. // to point to a NUL-terminated string, and thus can print it as a string.
#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \ #define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
template <> \ template <> \
class FormatForComparison<CharType*, OtherStringType> { \ class FormatForComparison<CharType*, OtherStringType> { \
public: \ public: \
static ::std::string Format(CharType* value) { \ static ::std::string Format(CharType* value) { \
return ::testing::PrintToString(value); \ return ::testing::PrintToString(value); \
} \ } \
} }
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string); GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string);
...@@ -411,8 +409,8 @@ GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring); ...@@ -411,8 +409,8 @@ GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring);
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
template <typename T1, typename T2> template <typename T1, typename T2>
std::string FormatForComparisonFailureMessage( std::string FormatForComparisonFailureMessage(const T1& value,
const T1& value, const T2& /* other_operand */) { const T2& /* other_operand */) {
return FormatForComparison<T1, T2>::Format(value); return FormatForComparison<T1, T2>::Format(value);
} }
...@@ -552,7 +550,7 @@ void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) { ...@@ -552,7 +550,7 @@ void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) {
} }
// Overloads for ::std::string. // Overloads for ::std::string.
GTEST_API_ void PrintStringTo(const ::std::string&s, ::std::ostream* os); GTEST_API_ void PrintStringTo(const ::std::string& s, ::std::ostream* os);
inline void PrintTo(const ::std::string& s, ::std::ostream* os) { inline void PrintTo(const ::std::string& s, ::std::ostream* os) {
PrintStringTo(s, os); PrintStringTo(s, os);
} }
...@@ -579,7 +577,7 @@ inline void PrintTo(const ::std::u32string& s, ::std::ostream* os) { ...@@ -579,7 +577,7 @@ inline void PrintTo(const ::std::u32string& s, ::std::ostream* os) {
// Overloads for ::std::wstring. // Overloads for ::std::wstring.
#if GTEST_HAS_STD_WSTRING #if GTEST_HAS_STD_WSTRING
GTEST_API_ void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os); GTEST_API_ void PrintWideStringTo(const ::std::wstring& s, ::std::ostream* os);
inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) { inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
PrintWideStringTo(s, os); PrintWideStringTo(s, os);
} }
...@@ -823,8 +821,8 @@ void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) { ...@@ -823,8 +821,8 @@ void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) {
} }
} }
// This overload prints a (const) char array compactly. // This overload prints a (const) char array compactly.
GTEST_API_ void UniversalPrintArray( GTEST_API_ void UniversalPrintArray(const char* begin, size_t len,
const char* begin, size_t len, ::std::ostream* os); ::std::ostream* os);
#ifdef __cpp_char8_t #ifdef __cpp_char8_t
// This overload prints a (const) char8_t array compactly. // This overload prints a (const) char8_t array compactly.
...@@ -841,8 +839,8 @@ GTEST_API_ void UniversalPrintArray(const char32_t* begin, size_t len, ...@@ -841,8 +839,8 @@ GTEST_API_ void UniversalPrintArray(const char32_t* begin, size_t len,
::std::ostream* os); ::std::ostream* os);
// This overload prints a (const) wchar_t array compactly. // This overload prints a (const) wchar_t array compactly.
GTEST_API_ void UniversalPrintArray( GTEST_API_ void UniversalPrintArray(const wchar_t* begin, size_t len,
const wchar_t* begin, size_t len, ::std::ostream* os); ::std::ostream* os);
// Implements printing an array type T[N]. // Implements printing an array type T[N].
template <typename T, size_t N> template <typename T, size_t N>
...@@ -1001,10 +999,10 @@ void UniversalPrint(const T& value, ::std::ostream* os) { ...@@ -1001,10 +999,10 @@ void UniversalPrint(const T& value, ::std::ostream* os) {
UniversalPrinter<T1>::Print(value, os); UniversalPrinter<T1>::Print(value, os);
} }
typedef ::std::vector< ::std::string> Strings; typedef ::std::vector<::std::string> Strings;
// Tersely prints the first N fields of a tuple to a string vector, // Tersely prints the first N fields of a tuple to a string vector,
// one element for each field. // one element for each field.
template <typename Tuple> template <typename Tuple>
void TersePrintPrefixToStrings(const Tuple&, std::integral_constant<size_t, 0>, void TersePrintPrefixToStrings(const Tuple&, std::integral_constant<size_t, 0>,
Strings*) {} Strings*) {}
......
...@@ -101,6 +101,7 @@ class GTEST_API_ SingleFailureChecker { ...@@ -101,6 +101,7 @@ class GTEST_API_ SingleFailureChecker {
SingleFailureChecker(const TestPartResultArray* results, SingleFailureChecker(const TestPartResultArray* results,
TestPartResult::Type type, const std::string& substr); TestPartResult::Type type, const std::string& substr);
~SingleFailureChecker(); ~SingleFailureChecker();
private: private:
const TestPartResultArray* const results_; const TestPartResultArray* const results_;
const TestPartResult::Type type_; const TestPartResult::Type type_;
...@@ -138,38 +139,39 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 ...@@ -138,38 +139,39 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
// helper macro, due to some peculiarity in how the preprocessor // helper macro, due to some peculiarity in how the preprocessor
// works. The AcceptsMacroThatExpandsToUnprotectedComma test in // works. The AcceptsMacroThatExpandsToUnprotectedComma test in
// gtest_unittest.cc will fail to compile if we do that. // gtest_unittest.cc will fail to compile if we do that.
#define EXPECT_FATAL_FAILURE(statement, substr) \ #define EXPECT_FATAL_FAILURE(statement, substr) \
do { \ do { \
class GTestExpectFatalFailureHelper {\ class GTestExpectFatalFailureHelper { \
public:\ public: \
static void Execute() { statement; }\ static void Execute() { statement; } \
};\ }; \
::testing::TestPartResultArray gtest_failures;\ ::testing::TestPartResultArray gtest_failures; \
::testing::internal::SingleFailureChecker gtest_checker(\ ::testing::internal::SingleFailureChecker gtest_checker( \
&gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\ &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr)); \
{\ { \
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ ::testing::ScopedFakeTestPartResultReporter gtest_reporter( \
::testing::ScopedFakeTestPartResultReporter:: \ ::testing::ScopedFakeTestPartResultReporter:: \
INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\ INTERCEPT_ONLY_CURRENT_THREAD, \
GTestExpectFatalFailureHelper::Execute();\ &gtest_failures); \
}\ GTestExpectFatalFailureHelper::Execute(); \
} \
} while (::testing::internal::AlwaysFalse()) } while (::testing::internal::AlwaysFalse())
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ #define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
do { \ do { \
class GTestExpectFatalFailureHelper {\ class GTestExpectFatalFailureHelper { \
public:\ public: \
static void Execute() { statement; }\ static void Execute() { statement; } \
};\ }; \
::testing::TestPartResultArray gtest_failures;\ ::testing::TestPartResultArray gtest_failures; \
::testing::internal::SingleFailureChecker gtest_checker(\ ::testing::internal::SingleFailureChecker gtest_checker( \
&gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\ &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr)); \
{\ { \
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ ::testing::ScopedFakeTestPartResultReporter gtest_reporter( \
::testing::ScopedFakeTestPartResultReporter:: \ ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \
INTERCEPT_ALL_THREADS, &gtest_failures);\ &gtest_failures); \
GTestExpectFatalFailureHelper::Execute();\ GTestExpectFatalFailureHelper::Execute(); \
}\ } \
} while (::testing::internal::AlwaysFalse()) } while (::testing::internal::AlwaysFalse())
// A macro for testing Google Test assertions or code that's expected to // A macro for testing Google Test assertions or code that's expected to
...@@ -204,32 +206,37 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 ...@@ -204,32 +206,37 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
// instead of // instead of
// GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) // GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
// to avoid an MSVC warning on unreachable code. // to avoid an MSVC warning on unreachable code.
#define EXPECT_NONFATAL_FAILURE(statement, substr) \ #define EXPECT_NONFATAL_FAILURE(statement, substr) \
do {\ do { \
::testing::TestPartResultArray gtest_failures;\ ::testing::TestPartResultArray gtest_failures; \
::testing::internal::SingleFailureChecker gtest_checker(\ ::testing::internal::SingleFailureChecker gtest_checker( \
&gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \ &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \
(substr));\ (substr)); \
{\ { \
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ ::testing::ScopedFakeTestPartResultReporter gtest_reporter( \
::testing::ScopedFakeTestPartResultReporter:: \ ::testing::ScopedFakeTestPartResultReporter:: \
INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\ INTERCEPT_ONLY_CURRENT_THREAD, \
if (::testing::internal::AlwaysTrue()) { statement; }\ &gtest_failures); \
}\ if (::testing::internal::AlwaysTrue()) { \
statement; \
} \
} \
} while (::testing::internal::AlwaysFalse()) } while (::testing::internal::AlwaysFalse())
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ #define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
do {\ do { \
::testing::TestPartResultArray gtest_failures;\ ::testing::TestPartResultArray gtest_failures; \
::testing::internal::SingleFailureChecker gtest_checker(\ ::testing::internal::SingleFailureChecker gtest_checker( \
&gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \ &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \
(substr));\ (substr)); \
{\ { \
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ ::testing::ScopedFakeTestPartResultReporter gtest_reporter( \
::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \ ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \
&gtest_failures);\ &gtest_failures); \
if (::testing::internal::AlwaysTrue()) { statement; }\ if (::testing::internal::AlwaysTrue()) { \
}\ statement; \
} \
} \
} while (::testing::internal::AlwaysFalse()) } while (::testing::internal::AlwaysFalse())
#endif // GOOGLETEST_INCLUDE_GTEST_GTEST_SPI_H_ #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_SPI_H_
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <iosfwd> #include <iosfwd>
#include <vector> #include <vector>
#include "gtest/internal/gtest-internal.h" #include "gtest/internal/gtest-internal.h"
#include "gtest/internal/gtest-string.h" #include "gtest/internal/gtest-string.h"
...@@ -170,6 +171,7 @@ class GTEST_API_ HasNewFatalFailureHelper ...@@ -170,6 +171,7 @@ class GTEST_API_ HasNewFatalFailureHelper
~HasNewFatalFailureHelper() override; ~HasNewFatalFailureHelper() override;
void ReportTestPartResult(const TestPartResult& result) override; void ReportTestPartResult(const TestPartResult& result) override;
bool has_new_fatal_failure() const { return has_new_fatal_failure_; } bool has_new_fatal_failure() const { return has_new_fatal_failure_; }
private: private:
bool has_new_fatal_failure_; bool has_new_fatal_failure_;
TestPartResultReporterInterface* original_reporter_; TestPartResultReporterInterface* original_reporter_;
......
...@@ -192,7 +192,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); ...@@ -192,7 +192,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
typedef ::testing::internal::GenerateTypeList<Types>::type \ typedef ::testing::internal::GenerateTypeList<Types>::type \
GTEST_TYPE_PARAMS_(CaseName); \ GTEST_TYPE_PARAMS_(CaseName); \
typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \ typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
GTEST_NAME_GENERATOR_(CaseName) GTEST_NAME_GENERATOR_(CaseName)
#define TYPED_TEST(CaseName, TestName) \ #define TYPED_TEST(CaseName, TestName) \
static_assert(sizeof(GTEST_STRINGIFY_(TestName)) > 1, \ static_assert(sizeof(GTEST_STRINGIFY_(TestName)) > 1, \
...@@ -258,7 +258,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); ...@@ -258,7 +258,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
// #included in multiple translation units linked together. // #included in multiple translation units linked together.
#define TYPED_TEST_SUITE_P(SuiteName) \ #define TYPED_TEST_SUITE_P(SuiteName) \
static ::testing::internal::TypedTestSuitePState \ static ::testing::internal::TypedTestSuitePState \
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName) GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName)
// Legacy API is deprecated but still available // Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
...@@ -303,21 +303,21 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); ...@@ -303,21 +303,21 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
REGISTER_TYPED_TEST_SUITE_P REGISTER_TYPED_TEST_SUITE_P
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
#define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types, ...) \ #define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types, ...) \
static_assert(sizeof(GTEST_STRINGIFY_(Prefix)) > 1, \ static_assert(sizeof(GTEST_STRINGIFY_(Prefix)) > 1, \
"test-suit-prefix must not be empty"); \ "test-suit-prefix must not be empty"); \
static bool gtest_##Prefix##_##SuiteName GTEST_ATTRIBUTE_UNUSED_ = \ static bool gtest_##Prefix##_##SuiteName GTEST_ATTRIBUTE_UNUSED_ = \
::testing::internal::TypeParameterizedTestSuite< \ ::testing::internal::TypeParameterizedTestSuite< \
SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \ SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \
::testing::internal::GenerateTypeList<Types>::type>:: \ ::testing::internal::GenerateTypeList<Types>::type>:: \
Register(GTEST_STRINGIFY_(Prefix), \ Register(GTEST_STRINGIFY_(Prefix), \
::testing::internal::CodeLocation(__FILE__, __LINE__), \ ::testing::internal::CodeLocation(__FILE__, __LINE__), \
&GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName), \ &GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName), \
GTEST_STRINGIFY_(SuiteName), \ GTEST_STRINGIFY_(SuiteName), \
GTEST_REGISTERED_TEST_NAMES_(SuiteName), \ GTEST_REGISTERED_TEST_NAMES_(SuiteName), \
::testing::internal::GenerateNames< \ ::testing::internal::GenerateNames< \
::testing::internal::NameGeneratorSelector< \ ::testing::internal::NameGeneratorSelector< \
__VA_ARGS__>::type, \ __VA_ARGS__>::type, \
::testing::internal::GenerateTypeList<Types>::type>()) ::testing::internal::GenerateTypeList<Types>::type>())
// Legacy API is deprecated but still available // Legacy API is deprecated but still available
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment