summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386>2011-03-09 01:18:08 +0000
committerzhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386>2011-03-09 01:18:08 +0000
commit35d98eb32933df50074c0dad62c86063898264d2 (patch)
treedaa8a90d0daedfaad62196bec42c63646f19f21d
parentdcc87ad72872210e2a32c54967d402ee9bf49c8b (diff)
downloadgooglemock-35d98eb32933df50074c0dad62c86063898264d2.tar.gz
Disables SetArgPointee("string literal") for GCC 4.0- and Symbian, and
adds support for SetArgPointee(L"wide string literal") -- by Vlad Losev. git-svn-id: http://googlemock.googlecode.com/svn/trunk@368 8415998a-534a-0410-bf83-d39667b30386
-rw-r--r--include/gmock/gmock-actions.h14
-rw-r--r--test/gmock-actions_test.cc51
2 files changed, 60 insertions, 5 deletions
diff --git a/include/gmock/gmock-actions.h b/include/gmock/gmock-actions.h
index cfd5850..d6a3e14 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<T>::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 <size_t N>
PolymorphicAction<
internal::SetArgumentPointeeAction<N, const char*, false> >
@@ -989,6 +993,16 @@ SetArgPointee(const char* p) {
return MakePolymorphicAction(internal::SetArgumentPointeeAction<
N, const char*, false>(p));
}
+
+template <size_t N>
+PolymorphicAction<
+ internal::SetArgumentPointeeAction<N, const wchar_t*, false> >
+SetArgPointee(const wchar_t* p) {
+ return MakePolymorphicAction(internal::SetArgumentPointeeAction<
+ N, const wchar_t*, false>(p));
+}
+#endif
+
// The following version is DEPRECATED.
template <size_t N, typename T>
PolymorphicAction<
diff --git a/test/gmock-actions_test.cc b/test/gmock-actions_test.cc
index b3f8d52..b7803fe 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<N>() 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<MyFunction> a = SetArgPointee<1>("hi");
+ typedef void MyFunction(std::string*, const char**);
+ Action<MyFunction> 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<MyFunction> 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<MyStringFunction> a2 = SetArgPointee<0>(L"world");
+ std::wstring str = L"";
+ a2.Perform(make_tuple(&str));
+ EXPECT_EQ(L"world", str);
+
+# endif
+}
+#endif
+
// Tests that SetArgPointee<N>() 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<MyFunction> 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<MyStringFunction> 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<N>(proto_buffer) sets the v1 protobuf