From 95b12332c345cee508a8e2b68e007280392506e0 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 25 Sep 2009 18:55:50 +0000 Subject: Makes gmock work on Symbian (both 3rd & 5th editions), original patch contributed by Mika Raento. --- test/gmock-actions_test.cc | 19 +++++++++++--- test/gmock-internal-utils_test.cc | 3 ++- test/gmock-matchers_test.cc | 55 +++++++++++++++++++++++++++------------ test/gmock-printers_test.cc | 8 +++--- 4 files changed, 60 insertions(+), 25 deletions(-) (limited to 'test') diff --git a/test/gmock-actions_test.cc b/test/gmock-actions_test.cc index 5d05bc50..d3d96c6d 100644 --- a/test/gmock-actions_test.cc +++ b/test/gmock-actions_test.cc @@ -98,11 +98,13 @@ TEST(BuiltInDefaultValueTest, IsZeroForNumericTypes) { EXPECT_EQ(0, BuiltInDefaultValue::Get()); EXPECT_EQ(0, BuiltInDefaultValue::Get()); EXPECT_EQ(0, BuiltInDefaultValue::Get()); -#if !GTEST_OS_WINDOWS +#if GMOCK_HAS_SIGNED_WCHAR_T_ EXPECT_EQ(0, BuiltInDefaultValue::Get()); EXPECT_EQ(0, BuiltInDefaultValue::Get()); -#endif // !GTEST_OS_WINDOWS +#endif +#if GMOCK_WCHAR_T_IS_NATIVE_ EXPECT_EQ(0, BuiltInDefaultValue::Get()); +#endif EXPECT_EQ(0, BuiltInDefaultValue::Get()); // NOLINT EXPECT_EQ(0, BuiltInDefaultValue::Get()); // NOLINT EXPECT_EQ(0, BuiltInDefaultValue::Get()); // NOLINT @@ -124,11 +126,13 @@ TEST(BuiltInDefaultValueTest, ExistsForNumericTypes) { EXPECT_TRUE(BuiltInDefaultValue::Exists()); EXPECT_TRUE(BuiltInDefaultValue::Exists()); EXPECT_TRUE(BuiltInDefaultValue::Exists()); -#if !GTEST_OS_WINDOWS +#if GMOCK_HAS_SIGNED_WCHAR_T_ EXPECT_TRUE(BuiltInDefaultValue::Exists()); EXPECT_TRUE(BuiltInDefaultValue::Exists()); -#endif // !GTEST_OS_WINDOWS +#endif +#if GMOCK_WCHAR_T_IS_NATIVE_ EXPECT_TRUE(BuiltInDefaultValue::Exists()); +#endif EXPECT_TRUE(BuiltInDefaultValue::Exists()); // NOLINT EXPECT_TRUE(BuiltInDefaultValue::Exists()); // NOLINT EXPECT_TRUE(BuiltInDefaultValue::Exists()); // NOLINT @@ -395,12 +399,19 @@ class IsNotZero : public ActionInterface { // NOLINT } }; +#if !GTEST_OS_SYMBIAN +// Compiling this test on Nokia's Symbian compiler fails with: +// 'Result' is not a member of class 'testing::internal::Function' +// (point of instantiation: '@unnamed@gmock_actions_test_cc@:: +// ActionTest_CanBeConvertedToOtherActionType_Test::TestBody()') +// with no obvious fix. TEST(ActionTest, CanBeConvertedToOtherActionType) { const Action a1(new IsNotZero); // NOLINT const Action a2 = Action(a1); // NOLINT EXPECT_EQ(1, a2.Perform(make_tuple('a'))); EXPECT_EQ(0, a2.Perform(make_tuple('\0'))); } +#endif // !GTEST_OS_SYMBIAN // The following two classes are for testing MakePolymorphicAction(). diff --git a/test/gmock-internal-utils_test.cc b/test/gmock-internal-utils_test.cc index d3a16ad3..ac3b2dd2 100644 --- a/test/gmock-internal-utils_test.cc +++ b/test/gmock-internal-utils_test.cc @@ -211,7 +211,8 @@ TEST(GetRawPointerTest, WorksForSmartPointers) { TEST(GetRawPointerTest, WorksForRawPointers) { int* p = NULL; - EXPECT_EQ(NULL, GetRawPointer(p)); + // Don't use EXPECT_EQ as no NULL-testing magic on Symbian. + EXPECT_TRUE(NULL == GetRawPointer(p)); int n = 1; EXPECT_EQ(&n, GetRawPointer(&n)); } diff --git a/test/gmock-matchers_test.cc b/test/gmock-matchers_test.cc index fe88c643..20b9387f 100644 --- a/test/gmock-matchers_test.cc +++ b/test/gmock-matchers_test.cc @@ -699,10 +699,20 @@ TEST(IsNullTest, MatchesNullPointer) { EXPECT_TRUE(m2.Matches(p2)); EXPECT_FALSE(m2.Matches("hi")); +#if !GTEST_OS_SYMBIAN + // Nokia's Symbian compiler generates: + // gmock-matchers.h: ambiguous access to overloaded function + // gmock-matchers.h: 'testing::Matcher::Matcher(void *)' + // gmock-matchers.h: 'testing::Matcher::Matcher(const testing:: + // MatcherInterface *)' + // gmock-matchers.h: (point of instantiation: 'testing:: + // gmock_matchers_test::IsNullTest_MatchesNullPointer_Test::TestBody()') + // gmock-matchers.h: (instantiating: 'testing::PolymorphicMatc Matcher m3 = IsNull(); void* p3 = NULL; EXPECT_TRUE(m3.Matches(p3)); EXPECT_FALSE(m3.Matches(reinterpret_cast(0xbeef))); +#endif } // Tests that IsNull() describes itself properly. @@ -933,24 +943,24 @@ TEST(KeyTest, SafelyCastsInnerMatcher) { } TEST(KeyTest, InsideContainsUsingMap) { - std::map container; - container.insert(std::make_pair(1, "foo")); - container.insert(std::make_pair(2, "bar")); - container.insert(std::make_pair(4, "baz")); + std::map container; + container.insert(std::make_pair(1, 'a')); + container.insert(std::make_pair(2, 'b')); + container.insert(std::make_pair(4, 'c')); EXPECT_THAT(container, Contains(Key(1))); EXPECT_THAT(container, Not(Contains(Key(3)))); } TEST(KeyTest, InsideContainsUsingMultimap) { - std::multimap container; - container.insert(std::make_pair(1, "foo")); - container.insert(std::make_pair(2, "bar")); - container.insert(std::make_pair(4, "baz")); + std::multimap container; + container.insert(std::make_pair(1, 'a')); + container.insert(std::make_pair(2, 'b')); + container.insert(std::make_pair(4, 'c')); EXPECT_THAT(container, Not(Contains(Key(25)))); - container.insert(std::make_pair(25, "more foo")); + container.insert(std::make_pair(25, 'd')); EXPECT_THAT(container, Contains(Key(25))); - container.insert(std::make_pair(25, "more bar")); + container.insert(std::make_pair(25, 'e')); EXPECT_THAT(container, Contains(Key(25))); EXPECT_THAT(container, Contains(Key(1))); @@ -1031,13 +1041,13 @@ TEST(PairTest, SafelyCastsInnerMatchers) { } TEST(PairTest, InsideContainsUsingMap) { - std::map container; - container.insert(std::make_pair(1, "foo")); - container.insert(std::make_pair(2, "bar")); - container.insert(std::make_pair(4, "baz")); - EXPECT_THAT(container, Contains(Pair(1, "foo"))); + std::map container; + container.insert(std::make_pair(1, 'a')); + container.insert(std::make_pair(2, 'b')); + container.insert(std::make_pair(4, 'c')); + EXPECT_THAT(container, Contains(Pair(1, 'a'))); EXPECT_THAT(container, Contains(Pair(1, _))); - EXPECT_THAT(container, Contains(Pair(_, "foo"))); + EXPECT_THAT(container, Contains(Pair(_, 'a'))); EXPECT_THAT(container, Not(Contains(Pair(3, _)))); } @@ -1961,8 +1971,20 @@ TEST(MatcherAssertionTest, WorksForByRefArguments) { "Actual: 0 (is located @"); } +#if !GTEST_OS_SYMBIAN // Tests that ASSERT_THAT() and EXPECT_THAT() work when the matcher is // monomorphic. + +// ASSERT_THAT("hello", starts_with_he) fails to compile with Nokia's +// Symbian compiler: it tries to compile +// template class MatcherCastImpl { ... +// virtual bool Matches(T x) const { +// return source_matcher_.Matches(static_cast(x)); +// with U == string and T == const char* +// With ASSERT_THAT("hello"...) changed to ASSERT_THAT(string("hello") ... ) +// the compiler silently crashes with no output. +// If MatcherCastImpl is changed to use U(x) instead of static_cast(x) +// the code compiles but the converted string is bogus. TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) { Matcher starts_with_he = StartsWith("he"); ASSERT_THAT("hello", starts_with_he); @@ -1976,6 +1998,7 @@ TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) { "Expected: is greater than 5\n" " Actual: 5"); } +#endif // !GTEST_OS_SYMBIAN // Tests floating-point matchers. template diff --git a/test/gmock-printers_test.cc b/test/gmock-printers_test.cc index 0eb8e094..4b900c57 100644 --- a/test/gmock-printers_test.cc +++ b/test/gmock-printers_test.cc @@ -840,16 +840,16 @@ TEST(PrintTupleTest, VariousSizes) { const char* const str = "8"; tuple - t10(false, 'a', 3, 4, 5, 6.5F, 7.5, str, NULL, "10"); - EXPECT_EQ("(false, 'a' (97), 3, 4, 5, 6.5, 7.5, " + PrintPointer(str) + + t10(false, 'a', 3, 4, 5, 1.5F, -2.5, str, NULL, "10"); + EXPECT_EQ("(false, 'a' (97), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) + " pointing to \"8\", NULL, \"10\")", Print(t10)); } // Nested tuples. TEST(PrintTupleTest, NestedTuple) { - tuple, char> nested(make_tuple(5, 9.5), 'a'); - EXPECT_EQ("((5, 9.5), 'a' (97))", Print(nested)); + tuple, char> nested(make_tuple(5, true), 'a'); + EXPECT_EQ("((5, true), 'a' (97))", Print(nested)); } // Tests printing user-defined unprintable types. -- cgit v1.2.3