diff --git a/include/gmock/gmock-actions.h b/include/gmock/gmock-actions.h index cfd5850e..d6a3e148 100644 --- a/include/gmock/gmock-actions.h +++ b/include/gmock/gmock-actions.h @@ -981,7 +981,11 @@ SetArgPointee(const T& x) { return MakePolymorphicAction(internal::SetArgumentPointeeAction< N, T, internal::IsAProtocolMessage::value>(x)); } + +#if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN) // This overload allows SetArgPointee() to accept a string literal. +// GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish +// this overload from the templated version and emit a compile error. template PolymorphicAction< internal::SetArgumentPointeeAction > @@ -989,6 +993,16 @@ SetArgPointee(const char* p) { return MakePolymorphicAction(internal::SetArgumentPointeeAction< N, const char*, false>(p)); } + +template +PolymorphicAction< + internal::SetArgumentPointeeAction > +SetArgPointee(const wchar_t* p) { + return MakePolymorphicAction(internal::SetArgumentPointeeAction< + N, const wchar_t*, false>(p)); +} +#endif + // The following version is DEPRECATED. template PolymorphicAction< diff --git a/test/gmock-actions_test.cc b/test/gmock-actions_test.cc index b3f8d52b..b7803fe9 100644 --- a/test/gmock-actions_test.cc +++ b/test/gmock-actions_test.cc @@ -714,23 +714,44 @@ TEST(SetArgPointeeTest, SetsTheNthPointee) { EXPECT_EQ('a', ch); } +#if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN) // Tests that SetArgPointee() accepts a string literal. +// GCC prior to v4.0 and the Symbian compiler do not support this. TEST(SetArgPointeeTest, AcceptsStringLiteral) { - typedef void MyFunction(bool, std::string*, const char**); - Action a = SetArgPointee<1>("hi"); + typedef void MyFunction(std::string*, const char**); + Action a = SetArgPointee<0>("hi"); std::string str; const char* ptr = NULL; - a.Perform(make_tuple(true, &str, &ptr)); + a.Perform(make_tuple(&str, &ptr)); EXPECT_EQ("hi", str); EXPECT_TRUE(ptr == NULL); - a = SetArgPointee<2>("world"); + a = SetArgPointee<1>("world"); str = ""; - a.Perform(make_tuple(true, &str, &ptr)); + a.Perform(make_tuple(&str, &ptr)); EXPECT_EQ("", str); EXPECT_STREQ("world", ptr); } +TEST(SetArgPointeeTest, AcceptsWideStringLiteral) { + typedef void MyFunction(const wchar_t**); + Action a = SetArgPointee<0>(L"world"); + const wchar_t* ptr = NULL; + a.Perform(make_tuple(&ptr)); + EXPECT_STREQ(L"world", ptr); + +# if GTEST_HAS_STD_WSTRING + + typedef void MyStringFunction(std::wstring*); + Action a2 = SetArgPointee<0>(L"world"); + std::wstring str = L""; + a2.Perform(make_tuple(&str)); + EXPECT_EQ(L"world", str); + +# endif +} +#endif + // Tests that SetArgPointee() accepts a char pointer. TEST(SetArgPointeeTest, AcceptsCharPointer) { typedef void MyFunction(bool, std::string*, const char**); @@ -751,6 +772,26 @@ TEST(SetArgPointeeTest, AcceptsCharPointer) { EXPECT_EQ(world, ptr); } +TEST(SetArgPointeeTest, AcceptsWideCharPointer) { + typedef void MyFunction(bool, const wchar_t**); + const wchar_t* const hi = L"hi"; + Action a = SetArgPointee<1>(hi); + const wchar_t* ptr = NULL; + a.Perform(make_tuple(true, &ptr)); + EXPECT_EQ(hi, ptr); + +# if GTEST_HAS_STD_WSTRING + + typedef void MyStringFunction(bool, std::wstring*); + wchar_t world_array[] = L"world"; + wchar_t* const world = world_array; + Action a2 = SetArgPointee<1>(world); + std::wstring str; + a2.Perform(make_tuple(true, &str)); + EXPECT_EQ(world_array, str); +# endif +} + #if GTEST_HAS_PROTOBUF_ // Tests that SetArgPointee(proto_buffer) sets the v1 protobuf