aboutsummaryrefslogtreecommitdiffstats
path: root/googlemock/test/gmock-nice-strict_test.cc
diff options
context:
space:
mode:
authorVictor Costan <costan@gmail.com>2018-04-09 21:57:54 -0700
committerVictor Costan <costan@gmail.com>2018-04-12 00:48:30 -0700
commit1324e2d706d739217cceae361259a5cc01d1ff41 (patch)
tree70bb7c7b555713db2fe60166863bf147c8387d76 /googlemock/test/gmock-nice-strict_test.cc
parentfdb57f85710ccb17076acb1870a881964f5e04af (diff)
downloadgoogletest-1324e2d706d739217cceae361259a5cc01d1ff41.tar.gz
googletest-1324e2d706d739217cceae361259a5cc01d1ff41.tar.bz2
googletest-1324e2d706d739217cceae361259a5cc01d1ff41.zip
Remove multiple inheritance from "unintesting call" mock classes.
Internal CL 156157936, which was published in commit fe402c27790ff1cc9a7e17c5d0aea4ebe7fd8a71, introduced undefined behavior by casting a base class (internal::{Naggy,Nice,Strict}Base<MockClass>, using the curiously recurring template pattern) pointer to a derived class ({Naggy,Nice,Strict}Mock<MockClass>), in the base class' constructor. At that point, the object isn't guaranteed to have taken on the shape of the derived class, and casting is undefined behavior. The undefined behavior was caught by Chrome's CFI build bot [1], and prevents rolling googletest past that commit / CL. This commit simplifies the {Naggy,Nice,Strict}Mock class hierarchy in a way that removes the undefined behavior. [1] https://www.chromium.org/developers/testing/control-flow-integrity
Diffstat (limited to 'googlemock/test/gmock-nice-strict_test.cc')
-rw-r--r--googlemock/test/gmock-nice-strict_test.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc
index 0eac6439..7812f626 100644
--- a/googlemock/test/gmock-nice-strict_test.cc
+++ b/googlemock/test/gmock-nice-strict_test.cc
@@ -259,6 +259,13 @@ TEST(NiceMockTest, NonDefaultConstructor10) {
nice_bar.That(5, true);
}
+TEST(NiceMockTest, AllowLeak) {
+ NiceMock<MockFoo>* leaked = new NiceMock<MockFoo>;
+ Mock::AllowLeak(leaked);
+ EXPECT_CALL(*leaked, DoThis());
+ leaked->DoThis();
+}
+
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that NiceMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). We had to work around an
@@ -352,6 +359,13 @@ TEST(NaggyMockTest, NonDefaultConstructor10) {
naggy_bar.That(5, true);
}
+TEST(NaggyMockTest, AllowLeak) {
+ NaggyMock<MockFoo>* leaked = new NaggyMock<MockFoo>;
+ Mock::AllowLeak(leaked);
+ EXPECT_CALL(*leaked, DoThis());
+ leaked->DoThis();
+}
+
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that NaggyMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). We had to work around an
@@ -426,6 +440,13 @@ TEST(StrictMockTest, NonDefaultConstructor10) {
"Uninteresting mock function call");
}
+TEST(StrictMockTest, AllowLeak) {
+ StrictMock<MockFoo>* leaked = new StrictMock<MockFoo>;
+ Mock::AllowLeak(leaked);
+ EXPECT_CALL(*leaked, DoThis());
+ leaked->DoThis();
+}
+
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that StrictMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). We had to work around an