diff options
author | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2010-12-02 23:30:50 +0000 |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2010-12-02 23:30:50 +0000 |
commit | a684b5a5269e3f9c53ef842bf9b9658370418a0c (patch) | |
tree | 342974398cc8c2d734ea51676db283c40182737c | |
parent | 88032d8e0f6d4bc63b97aeeab84fdc44aeab1c89 (diff) | |
download | googletest-a684b5a5269e3f9c53ef842bf9b9658370418a0c.tar.gz googletest-a684b5a5269e3f9c53ef842bf9b9658370418a0c.tar.bz2 googletest-a684b5a5269e3f9c53ef842bf9b9658370418a0c.zip |
Enables SetArgPointee<>() to accept a string literal; removes a self-assignment warning; teaches gmock doctor to diagnose TTB with Clang; picks up gtest r525.
-rw-r--r-- | include/gmock/gmock-actions.h | 8 | ||||
-rwxr-xr-x | scripts/gmock_doctor.py | 18 | ||||
-rw-r--r-- | test/gmock-actions_test.cc | 37 | ||||
-rw-r--r-- | test/gmock_test.cc | 2 |
4 files changed, 63 insertions, 2 deletions
diff --git a/include/gmock/gmock-actions.h b/include/gmock/gmock-actions.h index 1d5509ce..215af4f9 100644 --- a/include/gmock/gmock-actions.h +++ b/include/gmock/gmock-actions.h @@ -1020,6 +1020,14 @@ SetArgPointee(const T& x) { return MakePolymorphicAction(internal::SetArgumentPointeeAction< N, T, internal::IsAProtocolMessage<T>::value>(x)); } +// This overload allows SetArgPointee() to accept a string literal. +template <size_t N> +PolymorphicAction< + internal::SetArgumentPointeeAction<N, const char*, false> > +SetArgPointee(const char* p) { + return MakePolymorphicAction(internal::SetArgumentPointeeAction< + N, const char*, false>(p)); +} // The following version is DEPRECATED. template <size_t N, typename T> PolymorphicAction< diff --git a/scripts/gmock_doctor.py b/scripts/gmock_doctor.py index 18c117fb..15e2433c 100755 --- a/scripts/gmock_doctor.py +++ b/scripts/gmock_doctor.py @@ -459,6 +459,20 @@ def _TypeInTemplatedBaseDiagnoser(msg): r'error: \'(?P<type>.+)\' was not declared in this scope\n' r'.*error: template argument 1 is invalid\n' r'.*error: \'.+\' was not declared in this scope') + clang_regex_type_of_retval_or_sole_param = ( + _CLANG_FILE_LINE_RE + + r'error: use of undeclared identifier \'(?P<type>.*)\'\n' + r'(.*\n)*?' + r'(?P=file):(?P=line):(?P=column): error: ' + r'non-friend class member \'Result\' cannot have a qualified name' + ) + clang_regex_type_of_a_param = ( + _CLANG_FILE_LINE_RE + + r'error: C\+\+ requires a type specifier for all declarations\n' + r'(.*\n)*?' + r'(?P=file):(?P=line):(?P=column): error: ' + r'C\+\+ requires a type specifier for all declarations' + ) diagnosis = """ In a mock class template, types or typedefs defined in the base class @@ -473,7 +487,9 @@ need to make it visible. One way to do it is: [(gcc_4_3_1_regex_type_in_retval, diagnosis % {'type': 'Foo'}), (gcc_4_4_0_regex_type_in_retval, diagnosis % {'type': 'Foo'}), (gcc_regex_type_of_sole_param, diagnosis), - (gcc_regex_type_of_a_param, diagnosis)], + (gcc_regex_type_of_a_param, diagnosis), + (clang_regex_type_of_retval_or_sole_param, diagnosis), + (clang_regex_type_of_a_param, diagnosis % {'type': 'Foo'})], msg) diff --git a/test/gmock-actions_test.cc b/test/gmock-actions_test.cc index 7200fa1a..e12402b9 100644 --- a/test/gmock-actions_test.cc +++ b/test/gmock-actions_test.cc @@ -715,6 +715,43 @@ TEST(SetArgPointeeTest, SetsTheNthPointee) { EXPECT_EQ('a', ch); } +// Tests that SetArgPointee<N>() accepts a string literal. +TEST(SetArgPointeeTest, AcceptsStringLiteral) { + typedef void MyFunction(bool, std::string*, const char**); + Action<MyFunction> a = SetArgPointee<1>("hi"); + std::string str; + const char* ptr = NULL; + a.Perform(make_tuple(true, &str, &ptr)); + EXPECT_EQ("hi", str); + EXPECT_TRUE(ptr == NULL); + + a = SetArgPointee<2>("world"); + str = ""; + a.Perform(make_tuple(true, &str, &ptr)); + EXPECT_EQ("", str); + EXPECT_STREQ("world", ptr); +} + +// Tests that SetArgPointee<N>() accepts a char pointer. +TEST(SetArgPointeeTest, AcceptsCharPointer) { + typedef void MyFunction(bool, std::string*, const char**); + const char* const hi = "hi"; + Action<MyFunction> a = SetArgPointee<1>(hi); + std::string str; + const char* ptr = NULL; + a.Perform(make_tuple(true, &str, &ptr)); + EXPECT_EQ("hi", str); + EXPECT_TRUE(ptr == NULL); + + char world_array[] = "world"; + char* const world = world_array; + a = SetArgPointee<2>(world); + str = ""; + a.Perform(make_tuple(true, &str, &ptr)); + EXPECT_EQ("", str); + EXPECT_EQ(world, ptr); +} + #if GTEST_HAS_PROTOBUF_ // Tests that SetArgPointee<N>(proto_buffer) sets the v1 protobuf diff --git a/test/gmock_test.cc b/test/gmock_test.cc index ba137dd3..0b891137 100644 --- a/test/gmock_test.cc +++ b/test/gmock_test.cc @@ -251,5 +251,5 @@ TEST(WideInitGoogleMockTest, CallsInitGoogleTest) { TEST(FlagTest, IsAccessibleInCode) { bool dummy = testing::GMOCK_FLAG(catch_leaked_mocks) && testing::GMOCK_FLAG(verbose) == ""; - dummy = dummy; // Avoids the "unused local variable" warning. + (void)dummy; // Avoids the "unused local variable" warning. } |