aboutsummaryrefslogtreecommitdiffstats
path: root/googlemock/test/gmock-nice-strict_test.cc
diff options
context:
space:
mode:
authorClaus Stovgaard <claus.stovgaard@gmail.com>2017-08-31 12:22:53 +0200
committerClaus Stovgaard <claus.stovgaard@gmail.com>2017-08-31 12:22:53 +0200
commit34355c0e870efce3015fa19aff88c7d79839bbb1 (patch)
tree0fa858569364bb5818793d97d264aefd365399b5 /googlemock/test/gmock-nice-strict_test.cc
parenta6418a4dd19ea0e8aa5f7706b8bff12a2e453821 (diff)
parent16bfba08e2c63c33834a98d092cd6f1a3e547289 (diff)
downloadgoogletest-34355c0e870efce3015fa19aff88c7d79839bbb1.tar.gz
googletest-34355c0e870efce3015fa19aff88c7d79839bbb1.tar.bz2
googletest-34355c0e870efce3015fa19aff88c7d79839bbb1.zip
Merge remote-tracking branch 'github_google/master' into master-github_frosteyes
# Conflicts: # .gitignore
Diffstat (limited to 'googlemock/test/gmock-nice-strict_test.cc')
-rw-r--r--googlemock/test/gmock-nice-strict_test.cc50
1 files changed, 36 insertions, 14 deletions
diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc
index d0adcbbe..0eac6439 100644
--- a/googlemock/test/gmock-nice-strict_test.cc
+++ b/googlemock/test/gmock-nice-strict_test.cc
@@ -51,7 +51,6 @@ class Mock {
namespace testing {
namespace gmock_nice_strict_test {
-using testing::internal::string;
using testing::GMOCK_FLAG(verbose);
using testing::HasSubstr;
using testing::NaggyMock;
@@ -63,6 +62,12 @@ using testing::internal::CaptureStdout;
using testing::internal::GetCapturedStdout;
#endif
+// Class without default constructor.
+class NotDefaultConstructible {
+ public:
+ explicit NotDefaultConstructible(int) {}
+};
+
// Defines some mock classes needed by the tests.
class Foo {
@@ -80,6 +85,7 @@ class MockFoo : public Foo {
MOCK_METHOD0(DoThis, void());
MOCK_METHOD1(DoThat, int(bool flag));
+ MOCK_METHOD0(ReturnNonDefaultConstructible, NotDefaultConstructible());
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
@@ -87,23 +93,23 @@ class MockFoo : public Foo {
class MockBar {
public:
- explicit MockBar(const string& s) : str_(s) {}
+ explicit MockBar(const std::string& s) : str_(s) {}
- MockBar(char a1, char a2, string a3, string a4, int a5, int a6,
- const string& a7, const string& a8, bool a9, bool a10) {
- str_ = string() + a1 + a2 + a3 + a4 + static_cast<char>(a5) +
+ 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) {
+ str_ = std::string() + a1 + a2 + a3 + a4 + static_cast<char>(a5) +
static_cast<char>(a6) + a7 + a8 + (a9 ? 'T' : 'F') + (a10 ? 'T' : 'F');
}
virtual ~MockBar() {}
- const string& str() const { return str_; }
+ const std::string& str() const { return str_; }
MOCK_METHOD0(This, int());
- MOCK_METHOD2(That, string(int, bool));
+ MOCK_METHOD2(That, std::string(int, bool));
private:
- string str_;
+ std::string str_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar);
};
@@ -112,7 +118,7 @@ class MockBar {
// Tests that a raw mock generates warnings for uninteresting calls.
TEST(RawMockTest, WarningForUninterestingCall) {
- const string saved_flag = GMOCK_FLAG(verbose);
+ const std::string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = "warning";
MockFoo raw_foo;
@@ -129,7 +135,7 @@ TEST(RawMockTest, WarningForUninterestingCall) {
// Tests that a raw mock generates warnings for uninteresting calls
// that delete the mock object.
TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
- const string saved_flag = GMOCK_FLAG(verbose);
+ const std::string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = "warning";
MockFoo* const raw_foo = new MockFoo;
@@ -150,7 +156,7 @@ TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
TEST(RawMockTest, InfoForUninterestingCall) {
MockFoo raw_foo;
- const string saved_flag = GMOCK_FLAG(verbose);
+ const std::string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = "info";
CaptureStdout();
raw_foo.DoThis();
@@ -188,7 +194,7 @@ TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
TEST(NiceMockTest, InfoForUninterestingCall) {
NiceMock<MockFoo> nice_foo;
- const string saved_flag = GMOCK_FLAG(verbose);
+ const std::string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = "info";
CaptureStdout();
nice_foo.DoThis();
@@ -208,6 +214,22 @@ TEST(NiceMockTest, AllowsExpectedCall) {
nice_foo.DoThis();
}
+// Tests that an unexpected call on a nice mock which returns a not-default-constructible
+// type throws an exception and the exception contains the method's name.
+TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) {
+ NiceMock<MockFoo> nice_foo;
+#if GTEST_HAS_EXCEPTIONS
+ try {
+ nice_foo.ReturnNonDefaultConstructible();
+ FAIL();
+ } catch (const std::runtime_error& ex) {
+ EXPECT_THAT(ex.what(), HasSubstr("ReturnNonDefaultConstructible"));
+ }
+#else
+ EXPECT_DEATH_IF_SUPPORTED({ nice_foo.ReturnNonDefaultConstructible(); }, "");
+#endif
+}
+
// Tests that an unexpected call on a nice mock fails.
TEST(NiceMockTest, UnexpectedCallFails) {
NiceMock<MockFoo> nice_foo;
@@ -257,7 +279,7 @@ TEST(NiceMockTest, AcceptsClassNamedMock) {
// Tests that a naggy mock generates warnings for uninteresting calls.
TEST(NaggyMockTest, WarningForUninterestingCall) {
- const string saved_flag = GMOCK_FLAG(verbose);
+ const std::string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = "warning";
NaggyMock<MockFoo> naggy_foo;
@@ -274,7 +296,7 @@ TEST(NaggyMockTest, WarningForUninterestingCall) {
// Tests that a naggy mock generates a warning for an uninteresting call
// that deletes the mock object.
TEST(NaggyMockTest, WarningForUninterestingCallAfterDeath) {
- const string saved_flag = GMOCK_FLAG(verbose);
+ const std::string saved_flag = GMOCK_FLAG(verbose);
GMOCK_FLAG(verbose) = "warning";
NaggyMock<MockFoo>* const naggy_foo = new NaggyMock<MockFoo>;