"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googlemock/test/gmock-nice-strict_test.cc" between
googletest-release-1.11.0.tar.gz and googletest-release-1.12.0.tar.gz

About: GoogleTest is Google's (unit) testing and mocking framework for C++ tests.

gmock-nice-strict_test.cc  (googletest-release-1.11.0):gmock-nice-strict_test.cc  (googletest-release-1.12.0)
skipping to change at line 34 skipping to change at line 34
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (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.
#include "gmock/gmock-nice-strict.h" #include "gmock/gmock-nice-strict.h"
#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"
// This must not be defined inside the ::testing namespace, or it will // This must not be defined inside the ::testing namespace, or it will
// clash with ::testing::Mock. // clash with ::testing::Mock.
class Mock { class Mock {
public: public:
Mock() {} Mock() {}
MOCK_METHOD0(DoThis, void()); MOCK_METHOD0(DoThis, void());
private: private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(Mock); Mock(const Mock&) = delete;
Mock& operator=(const Mock&) = delete;
}; };
namespace testing { namespace testing {
namespace gmock_nice_strict_test { namespace gmock_nice_strict_test {
using testing::GMOCK_FLAG(verbose);
using testing::HasSubstr; using testing::HasSubstr;
using testing::NaggyMock; using testing::NaggyMock;
using testing::NiceMock; using testing::NiceMock;
using testing::StrictMock; using testing::StrictMock;
#if GTEST_HAS_STREAM_REDIRECTION #if GTEST_HAS_STREAM_REDIRECTION
using testing::internal::CaptureStdout; using testing::internal::CaptureStdout;
using testing::internal::GetCapturedStdout; using testing::internal::GetCapturedStdout;
#endif #endif
skipping to change at line 96 skipping to change at line 97
class MockFoo : public Foo { class MockFoo : public Foo {
public: public:
MockFoo() {} MockFoo() {}
void Delete() { delete this; } void Delete() { delete this; }
MOCK_METHOD0(DoThis, void()); MOCK_METHOD0(DoThis, void());
MOCK_METHOD1(DoThat, int(bool flag)); MOCK_METHOD1(DoThat, int(bool flag));
MOCK_METHOD0(ReturnNonDefaultConstructible, NotDefaultConstructible()); MOCK_METHOD0(ReturnNonDefaultConstructible, NotDefaultConstructible());
private: private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo); MockFoo(const MockFoo&) = delete;
MockFoo& operator=(const MockFoo&) = delete;
}; };
class MockBar { class MockBar {
public: public:
explicit MockBar(const std::string& s) : str_(s) {} explicit MockBar(const std::string& s) : str_(s) {}
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() {}
const std::string& str() const { return str_; } const std::string& str() const { return str_; }
MOCK_METHOD0(This, int()); MOCK_METHOD0(This, int());
MOCK_METHOD2(That, std::string(int, bool)); MOCK_METHOD2(That, std::string(int, bool));
private: private:
std::string str_; std::string str_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar); MockBar(const MockBar&) = delete;
MockBar& operator=(const MockBar&) = delete;
}; };
class MockBaz { class MockBaz {
public: public:
class MoveOnly { class MoveOnly {
public: public:
MoveOnly() = default; MoveOnly() = default;
MoveOnly(const MoveOnly&) = delete; MoveOnly(const MoveOnly&) = delete;
MoveOnly& operator=(const MoveOnly&) = delete; MoveOnly& operator=(const MoveOnly&) = delete;
skipping to change at line 142 skipping to change at line 146
MoveOnly& operator=(MoveOnly&&) = default; MoveOnly& operator=(MoveOnly&&) = default;
}; };
MockBaz(MoveOnly) {} MockBaz(MoveOnly) {}
}; };
#if GTEST_HAS_STREAM_REDIRECTION #if GTEST_HAS_STREAM_REDIRECTION
// Tests that a raw mock generates warnings for uninteresting calls. // Tests that a raw mock generates warnings for uninteresting calls.
TEST(RawMockTest, WarningForUninterestingCall) { TEST(RawMockTest, WarningForUninterestingCall) {
const std::string saved_flag = GMOCK_FLAG(verbose); const std::string saved_flag = GMOCK_FLAG_GET(verbose);
GMOCK_FLAG(verbose) = "warning"; GMOCK_FLAG_SET(verbose, "warning");
MockFoo raw_foo; MockFoo raw_foo;
CaptureStdout(); CaptureStdout();
raw_foo.DoThis(); raw_foo.DoThis();
raw_foo.DoThat(true); raw_foo.DoThat(true);
EXPECT_THAT(GetCapturedStdout(), EXPECT_THAT(GetCapturedStdout(),
HasSubstr("Uninteresting mock function call")); HasSubstr("Uninteresting mock function call"));
GMOCK_FLAG(verbose) = saved_flag; GMOCK_FLAG_SET(verbose, saved_flag);
} }
// Tests that a raw mock generates warnings for uninteresting calls // Tests that a raw mock generates warnings for uninteresting calls
// that delete the mock object. // that delete the mock object.
TEST(RawMockTest, WarningForUninterestingCallAfterDeath) { TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
const std::string saved_flag = GMOCK_FLAG(verbose); const std::string saved_flag = GMOCK_FLAG_GET(verbose);
GMOCK_FLAG(verbose) = "warning"; GMOCK_FLAG_SET(verbose, "warning");
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();
EXPECT_THAT(GetCapturedStdout(), EXPECT_THAT(GetCapturedStdout(),
HasSubstr("Uninteresting mock function call")); HasSubstr("Uninteresting mock function call"));
GMOCK_FLAG(verbose) = saved_flag; GMOCK_FLAG_SET(verbose, saved_flag);
} }
// Tests that a raw mock generates informational logs for // Tests that a raw mock generates informational logs for
// uninteresting calls. // uninteresting calls.
TEST(RawMockTest, InfoForUninterestingCall) { TEST(RawMockTest, InfoForUninterestingCall) {
MockFoo raw_foo; MockFoo raw_foo;
const std::string saved_flag = GMOCK_FLAG(verbose); const std::string saved_flag = GMOCK_FLAG_GET(verbose);
GMOCK_FLAG(verbose) = "info"; GMOCK_FLAG_SET(verbose, "info");
CaptureStdout(); CaptureStdout();
raw_foo.DoThis(); raw_foo.DoThis();
EXPECT_THAT(GetCapturedStdout(), EXPECT_THAT(GetCapturedStdout(),
HasSubstr("Uninteresting mock function call")); HasSubstr("Uninteresting mock function call"));
GMOCK_FLAG(verbose) = saved_flag; GMOCK_FLAG_SET(verbose, saved_flag);
} }
TEST(RawMockTest, IsNaggy_IsNice_IsStrict) { TEST(RawMockTest, IsNaggy_IsNice_IsStrict) {
MockFoo raw_foo; MockFoo raw_foo;
EXPECT_TRUE(Mock::IsNaggy(&raw_foo)); EXPECT_TRUE(Mock::IsNaggy(&raw_foo));
EXPECT_FALSE(Mock::IsNice(&raw_foo)); EXPECT_FALSE(Mock::IsNice(&raw_foo));
EXPECT_FALSE(Mock::IsStrict(&raw_foo)); EXPECT_FALSE(Mock::IsStrict(&raw_foo));
} }
// Tests that a nice mock generates no warning for uninteresting calls. // Tests that a nice mock generates no warning for uninteresting calls.
skipping to change at line 225 skipping to change at line 228
CaptureStdout(); CaptureStdout();
nice_foo->DoThis(); nice_foo->DoThis();
EXPECT_EQ("", GetCapturedStdout()); EXPECT_EQ("", GetCapturedStdout());
} }
// Tests that a nice mock generates informational logs for // Tests that a nice mock generates informational logs for
// uninteresting calls. // uninteresting calls.
TEST(NiceMockTest, InfoForUninterestingCall) { TEST(NiceMockTest, InfoForUninterestingCall) {
NiceMock<MockFoo> nice_foo; NiceMock<MockFoo> nice_foo;
const std::string saved_flag = GMOCK_FLAG(verbose); const std::string saved_flag = GMOCK_FLAG_GET(verbose);
GMOCK_FLAG(verbose) = "info"; GMOCK_FLAG_SET(verbose, "info");
CaptureStdout(); CaptureStdout();
nice_foo.DoThis(); nice_foo.DoThis();
EXPECT_THAT(GetCapturedStdout(), EXPECT_THAT(GetCapturedStdout(),
HasSubstr("Uninteresting mock function call")); HasSubstr("Uninteresting mock function call"));
GMOCK_FLAG(verbose) = saved_flag; GMOCK_FLAG_SET(verbose, saved_flag);
} }
#endif // GTEST_HAS_STREAM_REDIRECTION #endif // GTEST_HAS_STREAM_REDIRECTION
// Tests that a nice mock allows expected calls. // Tests that a nice mock allows expected calls.
TEST(NiceMockTest, AllowsExpectedCall) { TEST(NiceMockTest, AllowsExpectedCall) {
NiceMock<MockFoo> nice_foo; NiceMock<MockFoo> nice_foo;
EXPECT_CALL(nice_foo, DoThis()); EXPECT_CALL(nice_foo, DoThis());
nice_foo.DoThis(); nice_foo.DoThis();
skipping to change at line 283 skipping to change at line 286
NiceMock<MockBar> nice_bar("hi"); NiceMock<MockBar> nice_bar("hi");
EXPECT_EQ("hi", nice_bar.str()); EXPECT_EQ("hi", nice_bar.str());
nice_bar.This(); nice_bar.This();
nice_bar.That(5, true); nice_bar.That(5, true);
} }
// 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();
nice_bar.That(5, true); nice_bar.That(5, true);
} }
TEST(NiceMockTest, AllowLeak) { TEST(NiceMockTest, AllowLeak) {
NiceMock<MockFoo>* leaked = new NiceMock<MockFoo>; NiceMock<MockFoo>* leaked = new NiceMock<MockFoo>;
Mock::AllowLeak(leaked); Mock::AllowLeak(leaked);
EXPECT_CALL(*leaked, DoThis()); EXPECT_CALL(*leaked, DoThis());
skipping to change at line 328 skipping to change at line 331
NiceMock<MockFoo> nice_foo; NiceMock<MockFoo> nice_foo;
EXPECT_FALSE(Mock::IsNaggy(&nice_foo)); EXPECT_FALSE(Mock::IsNaggy(&nice_foo));
EXPECT_TRUE(Mock::IsNice(&nice_foo)); EXPECT_TRUE(Mock::IsNice(&nice_foo));
EXPECT_FALSE(Mock::IsStrict(&nice_foo)); EXPECT_FALSE(Mock::IsStrict(&nice_foo));
} }
#if GTEST_HAS_STREAM_REDIRECTION #if GTEST_HAS_STREAM_REDIRECTION
// Tests that a naggy mock generates warnings for uninteresting calls. // Tests that a naggy mock generates warnings for uninteresting calls.
TEST(NaggyMockTest, WarningForUninterestingCall) { TEST(NaggyMockTest, WarningForUninterestingCall) {
const std::string saved_flag = GMOCK_FLAG(verbose); const std::string saved_flag = GMOCK_FLAG_GET(verbose);
GMOCK_FLAG(verbose) = "warning"; GMOCK_FLAG_SET(verbose, "warning");
NaggyMock<MockFoo> naggy_foo; NaggyMock<MockFoo> naggy_foo;
CaptureStdout(); CaptureStdout();
naggy_foo.DoThis(); naggy_foo.DoThis();
naggy_foo.DoThat(true); naggy_foo.DoThat(true);
EXPECT_THAT(GetCapturedStdout(), EXPECT_THAT(GetCapturedStdout(),
HasSubstr("Uninteresting mock function call")); HasSubstr("Uninteresting mock function call"));
GMOCK_FLAG(verbose) = saved_flag; GMOCK_FLAG_SET(verbose, saved_flag);
} }
// Tests that a naggy mock generates a warning for an uninteresting call // Tests that a naggy mock generates a warning for an uninteresting call
// that deletes the mock object. // that deletes the mock object.
TEST(NaggyMockTest, WarningForUninterestingCallAfterDeath) { TEST(NaggyMockTest, WarningForUninterestingCallAfterDeath) {
const std::string saved_flag = GMOCK_FLAG(verbose); const std::string saved_flag = GMOCK_FLAG_GET(verbose);
GMOCK_FLAG(verbose) = "warning"; GMOCK_FLAG_SET(verbose, "warning");
NaggyMock<MockFoo>* const naggy_foo = new NaggyMock<MockFoo>; NaggyMock<MockFoo>* const naggy_foo = new NaggyMock<MockFoo>;
ON_CALL(*naggy_foo, DoThis()) ON_CALL(*naggy_foo, DoThis())
.WillByDefault(Invoke(naggy_foo, &MockFoo::Delete)); .WillByDefault(Invoke(naggy_foo, &MockFoo::Delete));
CaptureStdout(); CaptureStdout();
naggy_foo->DoThis(); naggy_foo->DoThis();
EXPECT_THAT(GetCapturedStdout(), EXPECT_THAT(GetCapturedStdout(),
HasSubstr("Uninteresting mock function call")); HasSubstr("Uninteresting mock function call"));
GMOCK_FLAG(verbose) = saved_flag; GMOCK_FLAG_SET(verbose, saved_flag);
} }
#endif // GTEST_HAS_STREAM_REDIRECTION #endif // GTEST_HAS_STREAM_REDIRECTION
// Tests that a naggy mock allows expected calls. // Tests that a naggy mock allows expected calls.
TEST(NaggyMockTest, AllowsExpectedCall) { TEST(NaggyMockTest, AllowsExpectedCall) {
NaggyMock<MockFoo> naggy_foo; NaggyMock<MockFoo> naggy_foo;
EXPECT_CALL(naggy_foo, DoThis()); EXPECT_CALL(naggy_foo, DoThis());
naggy_foo.DoThis(); naggy_foo.DoThis();
skipping to change at line 393 skipping to change at line 396
NaggyMock<MockBar> naggy_bar("hi"); NaggyMock<MockBar> naggy_bar("hi");
EXPECT_EQ("hi", naggy_bar.str()); EXPECT_EQ("hi", naggy_bar.str());
naggy_bar.This(); naggy_bar.This();
naggy_bar.That(5, true); naggy_bar.That(5, true);
} }
// 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();
naggy_bar.That(5, true); naggy_bar.That(5, true);
} }
TEST(NaggyMockTest, AllowLeak) { TEST(NaggyMockTest, AllowLeak) {
NaggyMock<MockFoo>* leaked = new NaggyMock<MockFoo>; NaggyMock<MockFoo>* leaked = new NaggyMock<MockFoo>;
Mock::AllowLeak(leaked); Mock::AllowLeak(leaked);
EXPECT_CALL(*leaked, DoThis()); EXPECT_CALL(*leaked, DoThis());
skipping to change at line 421 skipping to change at line 424
// Tests that NaggyMock<Mock> compiles where Mock is a user-defined // Tests that NaggyMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). // class (as opposed to ::testing::Mock).
TEST(NaggyMockTest, AcceptsClassNamedMock) { TEST(NaggyMockTest, AcceptsClassNamedMock) {
NaggyMock< ::Mock> naggy; NaggyMock< ::Mock> naggy;
EXPECT_CALL(naggy, DoThis()); EXPECT_CALL(naggy, DoThis());
naggy.DoThis(); naggy.DoThis();
} }
TEST(NaggyMockTest, IsNaggyInDestructor) { TEST(NaggyMockTest, IsNaggyInDestructor) {
const std::string saved_flag = GMOCK_FLAG(verbose); const std::string saved_flag = GMOCK_FLAG_GET(verbose);
GMOCK_FLAG(verbose) = "warning"; GMOCK_FLAG_SET(verbose, "warning");
CaptureStdout(); CaptureStdout();
{ {
NaggyMock<CallsMockMethodInDestructor> naggy_on_destroy; NaggyMock<CallsMockMethodInDestructor> naggy_on_destroy;
// Don't add an expectation for the call before the mock goes out of scope. // Don't add an expectation for the call before the mock goes out of scope.
} }
EXPECT_THAT(GetCapturedStdout(), EXPECT_THAT(GetCapturedStdout(),
HasSubstr("Uninteresting mock function call")); HasSubstr("Uninteresting mock function call"));
GMOCK_FLAG(verbose) = saved_flag; GMOCK_FLAG_SET(verbose, saved_flag);
} }
TEST(NaggyMockTest, IsNaggy_IsNice_IsStrict) { TEST(NaggyMockTest, IsNaggy_IsNice_IsStrict) {
NaggyMock<MockFoo> naggy_foo; NaggyMock<MockFoo> naggy_foo;
EXPECT_TRUE(Mock::IsNaggy(&naggy_foo)); EXPECT_TRUE(Mock::IsNaggy(&naggy_foo));
EXPECT_FALSE(Mock::IsNice(&naggy_foo)); EXPECT_FALSE(Mock::IsNice(&naggy_foo));
EXPECT_FALSE(Mock::IsStrict(&naggy_foo)); EXPECT_FALSE(Mock::IsStrict(&naggy_foo));
} }
// Tests that a strict mock allows expected calls. // Tests that a strict mock allows expected calls.
skipping to change at line 493 skipping to change at line 496
StrictMock<MockBar> strict_bar("hi"); StrictMock<MockBar> strict_bar("hi");
EXPECT_EQ("hi", strict_bar.str()); EXPECT_EQ("hi", strict_bar.str());
EXPECT_NONFATAL_FAILURE(strict_bar.That(5, true), EXPECT_NONFATAL_FAILURE(strict_bar.That(5, true),
"Uninteresting mock function call"); "Uninteresting mock function call");
} }
// 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),
"Uninteresting mock function call"); "Uninteresting mock function call");
} }
TEST(StrictMockTest, AllowLeak) { TEST(StrictMockTest, AllowLeak) {
StrictMock<MockFoo>* leaked = new StrictMock<MockFoo>; StrictMock<MockFoo>* leaked = new StrictMock<MockFoo>;
Mock::AllowLeak(leaked); Mock::AllowLeak(leaked);
EXPECT_CALL(*leaked, DoThis()); EXPECT_CALL(*leaked, DoThis());
 End of changes. 24 change blocks. 
34 lines changed or deleted 37 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)