summaryrefslogtreecommitdiffstats
path: root/testing/gmock/test
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-29 21:43:25 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-29 21:43:25 +0000
commit145a7ca423cf3a3249ca0329be37dc447f9ce855 (patch)
treecdf1ca18db5e088b671cbdeda33635726d32a1ad /testing/gmock/test
parent02ae88443795ca043b15083898e83ad2811b032b (diff)
downloadchromium_src-145a7ca423cf3a3249ca0329be37dc447f9ce855.zip
chromium_src-145a7ca423cf3a3249ca0329be37dc447f9ce855.tar.gz
chromium_src-145a7ca423cf3a3249ca0329be37dc447f9ce855.tar.bz2
Update gmock and gtest.
(Hoping to pick up a clang-related bug fix.) Review URL: http://codereview.chromium.org/521012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35352 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'testing/gmock/test')
-rw-r--r--testing/gmock/test/gmock-actions_test.cc76
-rw-r--r--testing/gmock/test/gmock-cardinalities_test.cc8
-rw-r--r--testing/gmock/test/gmock-generated-actions_test.cc44
-rw-r--r--testing/gmock/test/gmock-generated-function-mockers_test.cc30
-rw-r--r--testing/gmock/test/gmock-generated-matchers_test.cc23
-rw-r--r--testing/gmock/test/gmock-internal-utils_test.cc14
-rw-r--r--testing/gmock/test/gmock-matchers_test.cc87
-rw-r--r--testing/gmock/test/gmock-more-actions_test.cc20
-rw-r--r--testing/gmock/test/gmock-nice-strict_test.cc27
-rw-r--r--testing/gmock/test/gmock-port_test.cc127
-rw-r--r--testing/gmock/test/gmock-printers_test.cc33
-rw-r--r--testing/gmock/test/gmock-spec-builders_test.cc114
-rwxr-xr-x[-rw-r--r--]testing/gmock/test/gmock_leak_test.py54
-rw-r--r--testing/gmock/test/gmock_leak_test_.cc5
-rw-r--r--testing/gmock/test/gmock_link_test.h21
-rwxr-xr-x[-rw-r--r--]testing/gmock/test/gmock_output_test.py70
-rw-r--r--testing/gmock/test/gmock_output_test_.cc9
-rw-r--r--testing/gmock/test/gmock_output_test_golden.txt50
-rwxr-xr-x[-rw-r--r--]testing/gmock/test/gmock_test_utils.py49
19 files changed, 635 insertions, 226 deletions
diff --git a/testing/gmock/test/gmock-actions_test.cc b/testing/gmock/test/gmock-actions_test.cc
index d3d96c6..a2c6fe1 100644
--- a/testing/gmock/test/gmock-actions_test.cc
+++ b/testing/gmock/test/gmock-actions_test.cc
@@ -95,26 +95,26 @@ TEST(BuiltInDefaultValueTest, ExistsForPointerTypes) {
// Tests that BuiltInDefaultValue<T>::Get() returns 0 when T is a
// built-in numeric type.
TEST(BuiltInDefaultValueTest, IsZeroForNumericTypes) {
- EXPECT_EQ(0, BuiltInDefaultValue<unsigned char>::Get());
+ EXPECT_EQ(0U, BuiltInDefaultValue<unsigned char>::Get());
EXPECT_EQ(0, BuiltInDefaultValue<signed char>::Get());
EXPECT_EQ(0, BuiltInDefaultValue<char>::Get());
#if GMOCK_HAS_SIGNED_WCHAR_T_
- EXPECT_EQ(0, BuiltInDefaultValue<unsigned wchar_t>::Get());
+ EXPECT_EQ(0U, BuiltInDefaultValue<unsigned wchar_t>::Get());
EXPECT_EQ(0, BuiltInDefaultValue<signed wchar_t>::Get());
#endif
#if GMOCK_WCHAR_T_IS_NATIVE_
EXPECT_EQ(0, BuiltInDefaultValue<wchar_t>::Get());
#endif
- EXPECT_EQ(0, BuiltInDefaultValue<unsigned short>::Get()); // NOLINT
+ EXPECT_EQ(0U, BuiltInDefaultValue<unsigned short>::Get()); // NOLINT
EXPECT_EQ(0, BuiltInDefaultValue<signed short>::Get()); // NOLINT
EXPECT_EQ(0, BuiltInDefaultValue<short>::Get()); // NOLINT
- EXPECT_EQ(0, BuiltInDefaultValue<unsigned int>::Get());
+ EXPECT_EQ(0U, BuiltInDefaultValue<unsigned int>::Get());
EXPECT_EQ(0, BuiltInDefaultValue<signed int>::Get());
EXPECT_EQ(0, BuiltInDefaultValue<int>::Get());
- EXPECT_EQ(0, BuiltInDefaultValue<unsigned long>::Get()); // NOLINT
+ EXPECT_EQ(0U, BuiltInDefaultValue<unsigned long>::Get()); // NOLINT
EXPECT_EQ(0, BuiltInDefaultValue<signed long>::Get()); // NOLINT
EXPECT_EQ(0, BuiltInDefaultValue<long>::Get()); // NOLINT
- EXPECT_EQ(0, BuiltInDefaultValue<UInt64>::Get());
+ EXPECT_EQ(0U, BuiltInDefaultValue<UInt64>::Get());
EXPECT_EQ(0, BuiltInDefaultValue<Int64>::Get());
EXPECT_EQ(0, BuiltInDefaultValue<float>::Get());
EXPECT_EQ(0, BuiltInDefaultValue<double>::Get());
@@ -165,9 +165,7 @@ TEST(BuiltInDefaultValueTest, IsEmptyStringForString) {
EXPECT_EQ("", BuiltInDefaultValue< ::string>::Get());
#endif // GTEST_HAS_GLOBAL_STRING
-#if GTEST_HAS_STD_STRING
EXPECT_EQ("", BuiltInDefaultValue< ::std::string>::Get());
-#endif // GTEST_HAS_STD_STRING
}
// Tests that BuiltInDefaultValue<T>::Exists() returns true when T is a
@@ -177,9 +175,7 @@ TEST(BuiltInDefaultValueTest, ExistsForString) {
EXPECT_TRUE(BuiltInDefaultValue< ::string>::Exists());
#endif // GTEST_HAS_GLOBAL_STRING
-#if GTEST_HAS_STD_STRING
EXPECT_TRUE(BuiltInDefaultValue< ::std::string>::Exists());
-#endif // GTEST_HAS_STD_STRING
}
// Tests that BuiltInDefaultValue<const T>::Get() returns the same
@@ -515,6 +511,51 @@ TEST(ReturnTest, IsCovariant) {
EXPECT_EQ(&derived, ret.Perform(make_tuple()));
}
+// Tests that the type of the value passed into Return is converted into T
+// when the action is cast to Action<T(...)> rather than when the action is
+// performed. See comments on testing::internal::ReturnAction in
+// gmock-actions.h for more information.
+class FromType {
+ public:
+ FromType(bool* is_converted) : converted_(is_converted) {}
+ bool* converted() const { return converted_; }
+
+ private:
+ bool* const converted_;
+
+ GTEST_DISALLOW_ASSIGN_(FromType);
+};
+
+class ToType {
+ public:
+ ToType(const FromType& x) { *x.converted() = true; }
+};
+
+TEST(ReturnTest, ConvertsArgumentWhenConverted) {
+ bool converted = false;
+ FromType x(&converted);
+ Action<ToType()> action(Return(x));
+ EXPECT_TRUE(converted) << "Return must convert its argument in its own "
+ << "conversion operator.";
+ converted = false;
+ action.Perform(tuple<>());
+ EXPECT_FALSE(converted) << "Action must NOT convert its argument "
+ << "when performed." ;
+}
+
+class DestinationType {};
+
+class SourceType {
+ public:
+ // Note: a non-const typecast operator.
+ operator DestinationType() { return DestinationType(); }
+};
+
+TEST(ReturnTest, CanConvertArgumentUsingNonConstTypeCastOperator) {
+ SourceType s;
+ Action<DestinationType()> action(Return(s));
+}
+
// Tests that ReturnNull() returns NULL in a pointer-returning function.
TEST(ReturnNullTest, WorksInPointerReturningFunction) {
const Action<int*()> a1 = ReturnNull();
@@ -549,8 +590,13 @@ class MyClass {};
class MockClass {
public:
+ MockClass() {}
+
MOCK_METHOD1(IntFunc, int(bool flag)); // NOLINT
MOCK_METHOD0(Foo, MyClass());
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockClass);
};
// Tests that DoDefault() returns the built-in default value for the
@@ -576,7 +622,7 @@ TEST(DoDefaultDeathTest, DiesForUnknowType) {
// Tests that using DoDefault() inside a composite action leads to a
// run-time error.
-void VoidFunc(bool flag) {}
+void VoidFunc(bool /* flag */) {}
TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) {
MockClass mock;
@@ -762,7 +808,7 @@ bool Unary(int x) { return x < 0; }
const char* Plus1(const char* s) { return s + 1; }
-void VoidUnary(int n) { g_done = true; }
+void VoidUnary(int /* n */) { g_done = true; }
bool ByConstRef(const std::string& s) { return s == "Hi"; }
@@ -831,7 +877,7 @@ TEST(InvokeWithoutArgsTest, Function) {
EXPECT_EQ(1, a.Perform(make_tuple(2)));
// As an action that takes two arguments.
- Action<short(int, double)> a2 = InvokeWithoutArgs(Nullary); // NOLINT
+ Action<int(int, double)> a2 = InvokeWithoutArgs(Nullary); // NOLINT
EXPECT_EQ(1, a2.Perform(make_tuple(2, 3.5)));
// As an action that returns void.
@@ -848,7 +894,7 @@ TEST(InvokeWithoutArgsTest, Functor) {
EXPECT_EQ(2, a.Perform(make_tuple()));
// As an action that takes three arguments.
- Action<short(int, double, char)> a2 = // NOLINT
+ Action<int(int, double, char)> a2 = // NOLINT
InvokeWithoutArgs(NullaryFunctor());
EXPECT_EQ(2, a2.Perform(make_tuple(3, 3.5, 'a')));
@@ -889,7 +935,7 @@ TEST(IgnoreResultTest, MonomorphicAction) {
// Tests using IgnoreResult() on an action that returns a class type.
-MyClass ReturnMyClass(double x) {
+MyClass ReturnMyClass(double /* x */) {
g_done = true;
return MyClass();
}
diff --git a/testing/gmock/test/gmock-cardinalities_test.cc b/testing/gmock/test/gmock-cardinalities_test.cc
index f3f1e10..f6a9491 100644
--- a/testing/gmock/test/gmock-cardinalities_test.cc
+++ b/testing/gmock/test/gmock-cardinalities_test.cc
@@ -52,7 +52,11 @@ using testing::MakeCardinality;
class MockFoo {
public:
+ MockFoo() {}
MOCK_METHOD0(Bar, int()); // NOLINT
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
};
// Tests that Cardinality objects can be default constructed.
@@ -398,7 +402,9 @@ class EvenCardinality : public CardinalityInterface {
}
// Returns true iff call_count calls will saturate this cardinality.
- virtual bool IsSaturatedByCallCount(int call_count) const { return false; }
+ virtual bool IsSaturatedByCallCount(int /* call_count */) const {
+ return false;
+ }
// Describes self to an ostream.
virtual void DescribeTo(::std::ostream* ss) const {
diff --git a/testing/gmock/test/gmock-generated-actions_test.cc b/testing/gmock/test/gmock-generated-actions_test.cc
index 2e6fa0b..3c076d7 100644
--- a/testing/gmock/test/gmock-generated-actions_test.cc
+++ b/testing/gmock/test/gmock-generated-actions_test.cc
@@ -63,6 +63,10 @@ using testing::StaticAssertTypeEq;
using testing::Unused;
using testing::WithArgs;
+// For suppressing compiler warnings on conversion possibly losing precision.
+inline short Short(short n) { return n; } // NOLINT
+inline char Char(char ch) { return ch; }
+
// Sample functions and functors for testing various actions.
int Nullary() { return 1; }
@@ -242,7 +246,7 @@ TEST(InvokeArgumentTest, Function10) {
// Tests using InvokeArgument with a function that takes a pointer argument.
TEST(InvokeArgumentTest, ByPointerFunction) {
Action<const char*(const char*(*)(const char* input, short n))> a = // NOLINT
- InvokeArgument<0>(static_cast<const char*>("Hi"), 1);
+ InvokeArgument<0>(static_cast<const char*>("Hi"), Short(1));
EXPECT_STREQ("i", a.Perform(make_tuple(&Binary)));
}
@@ -250,7 +254,7 @@ TEST(InvokeArgumentTest, ByPointerFunction) {
// by passing it a C-string literal.
TEST(InvokeArgumentTest, FunctionWithCStringLiteral) {
Action<const char*(const char*(*)(const char* input, short n))> a = // NOLINT
- InvokeArgument<0>("Hi", 1);
+ InvokeArgument<0>("Hi", Short(1));
EXPECT_STREQ("i", a.Perform(make_tuple(&Binary)));
}
@@ -286,17 +290,17 @@ TEST(WithArgsTest, OneArg) {
// Tests using WithArgs with an action that takes 2 arguments.
TEST(WithArgsTest, TwoArgs) {
- Action<const char*(const char* s, double x, int n)> a =
+ Action<const char*(const char* s, double x, short n)> a =
WithArgs<0, 2>(Invoke(Binary));
const char s[] = "Hello";
- EXPECT_EQ(s + 2, a.Perform(make_tuple(CharPtr(s), 0.5, 2)));
+ EXPECT_EQ(s + 2, a.Perform(make_tuple(CharPtr(s), 0.5, Short(2))));
}
// Tests using WithArgs with an action that takes 3 arguments.
TEST(WithArgsTest, ThreeArgs) {
Action<int(int, double, char, short)> a = // NOLINT
WithArgs<0, 2, 3>(Invoke(Ternary));
- EXPECT_EQ(123, a.Perform(make_tuple(100, 6.5, 20, 3)));
+ EXPECT_EQ(123, a.Perform(make_tuple(100, 6.5, Char(20), Short(3))));
}
// Tests using WithArgs with an action that takes 4 arguments.
@@ -379,7 +383,7 @@ TEST(WithArgsTest, NonInvokeAction) {
TEST(WithArgsTest, Identity) {
Action<int(int x, char y, short z)> a = // NOLINT
WithArgs<0, 1, 2>(Invoke(Ternary));
- EXPECT_EQ(123, a.Perform(make_tuple(100, 20, 3)));
+ EXPECT_EQ(123, a.Perform(make_tuple(100, Char(20), Short(3))));
}
// Tests using WithArgs with repeated arguments.
@@ -394,14 +398,14 @@ TEST(WithArgsTest, ReversedArgumentOrder) {
Action<const char*(short n, const char* input)> a = // NOLINT
WithArgs<1, 0>(Invoke(Binary));
const char s[] = "Hello";
- EXPECT_EQ(s + 2, a.Perform(make_tuple(2, CharPtr(s))));
+ EXPECT_EQ(s + 2, a.Perform(make_tuple(Short(2), CharPtr(s))));
}
// Tests using WithArgs with compatible, but not identical, argument types.
TEST(WithArgsTest, ArgsOfCompatibleTypes) {
- Action<long(short x, int y, double z, char c)> a = // NOLINT
+ Action<long(short x, char y, double z, char c)> a = // NOLINT
WithArgs<0, 1, 3>(Invoke(Ternary));
- EXPECT_EQ(123, a.Perform(make_tuple(100, 20, 5.6, 3)));
+ EXPECT_EQ(123, a.Perform(make_tuple(Short(100), Char(20), 5.6, Char(3))));
}
// Tests using WithArgs with an action that returns void.
@@ -583,6 +587,16 @@ TEST(DoAllTest, TenActions) {
EXPECT_EQ('g', g);
}
+// The ACTION*() macros trigger warning C4100 (unreferenced formal
+// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
+// the macro definition, as the warnings are generated when the macro
+// is expanded and macro expansion cannot contain #pragma. Therefore
+// we suppress them here.
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable:4100)
+#endif
+
// Tests the ACTION*() macro family.
// Tests that ACTION() can define an action that doesn't reference the
@@ -633,7 +647,7 @@ ACTION(Sum2) {
TEST(ActionMacroTest, CanReferenceArgumentTuple) {
Action<int(int, char, int*)> a1 = Sum2();
int dummy = 0;
- EXPECT_EQ(11, a1.Perform(make_tuple(5, static_cast<char>(6), &dummy)));
+ EXPECT_EQ(11, a1.Perform(make_tuple(5, Char(6), &dummy)));
}
// Tests that the body of ACTION() can reference the mock function
@@ -731,7 +745,7 @@ ACTION_P(TypedPlus, n) {
TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) {
Action<int(char m, bool t)> a1 = TypedPlus(9);
- EXPECT_EQ(10, a1.Perform(make_tuple(static_cast<char>(1), true)));
+ EXPECT_EQ(10, a1.Perform(make_tuple(Char(1), true)));
}
// Tests that a parameterized action can be used in any mock function
@@ -851,7 +865,7 @@ TEST(ActionPnMacroTest, WorksFor10Parameters) {
ACTION_P2(PadArgument, prefix, suffix) {
// The following lines promote the two parameters to desired types.
std::string prefix_str(prefix);
- char suffix_char(suffix);
+ char suffix_char = static_cast<char>(suffix);
return prefix_str + arg0 + suffix_char;
}
@@ -1078,7 +1092,7 @@ class BoolResetter {
explicit BoolResetter(bool* value) : value_(value) {}
~BoolResetter() { *value_ = false; }
private:
- bool* const value_;
+ bool* value_;
};
TEST(ActionTemplateTest, WorksForIntegralTemplateParams) {
@@ -1190,5 +1204,9 @@ TEST(ActionTemplateTest, CanBeOverloadedOnNumberOfValueParameters) {
EXPECT_EQ(12345, a4.Perform(make_tuple()));
}
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
} // namespace gmock_generated_actions_test
} // namespace testing
diff --git a/testing/gmock/test/gmock-generated-function-mockers_test.cc b/testing/gmock/test/gmock-generated-function-mockers_test.cc
index 1ce8c45..5d839c4 100644
--- a/testing/gmock/test/gmock-generated-function-mockers_test.cc
+++ b/testing/gmock/test/gmock-generated-function-mockers_test.cc
@@ -114,6 +114,8 @@ class FooInterface {
class MockFoo : public FooInterface {
public:
+ MockFoo() {}
+
// Makes sure that a mock function parameter can be named.
MOCK_METHOD1(VoidReturning, void(int n)); // NOLINT
@@ -149,6 +151,9 @@ class MockFoo : public FooInterface {
const string& k));
MOCK_CONST_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTConst, char(int));
#endif // GTEST_OS_WINDOWS
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
};
class FunctionMockerTest : public testing::Test {
@@ -305,7 +310,12 @@ TEST_F(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) {
class MockB {
public:
+ MockB() {}
+
MOCK_METHOD0(DoB, void());
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockB);
};
// Tests that functions with no EXPECT_CALL() ruls can be called any
@@ -345,10 +355,15 @@ class StackInterface {
template <typename T>
class MockStack : public StackInterface<T> {
public:
+ MockStack() {}
+
MOCK_METHOD1_T(Push, void(const T& elem));
MOCK_METHOD0_T(Pop, void());
MOCK_CONST_METHOD0_T(GetSize, int()); // NOLINT
MOCK_CONST_METHOD0_T(GetTop, const T&());
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStack);
};
// Tests that template mock works.
@@ -393,10 +408,15 @@ class StackInterfaceWithCallType {
template <typename T>
class MockStackWithCallType : public StackInterfaceWithCallType<T> {
public:
+ MockStackWithCallType() {}
+
MOCK_METHOD1_T_WITH_CALLTYPE(STDMETHODCALLTYPE, Push, void(const T& elem));
MOCK_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, Pop, void());
MOCK_CONST_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, GetSize, int());
MOCK_CONST_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, GetTop, const T&());
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStackWithCallType);
};
// Tests that template mock with calltype works.
@@ -430,7 +450,12 @@ TEST(TemplateMockTestWithCallType, Works) {
class MockOverloadedOnArgNumber {
public:
+ MockOverloadedOnArgNumber() {}
+
MY_MOCK_METHODS1_;
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnArgNumber);
};
TEST(OverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
@@ -450,7 +475,12 @@ TEST(OverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
class MockOverloadedOnConstness {
public:
+ MockOverloadedOnConstness() {}
+
MY_MOCK_METHODS2_;
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnConstness);
};
TEST(OverloadedMockMethodTest, CanOverloadOnConstnessInMacroBody) {
diff --git a/testing/gmock/test/gmock-generated-matchers_test.cc b/testing/gmock/test/gmock-generated-matchers_test.cc
index 19024d0..4141305 100644
--- a/testing/gmock/test/gmock-generated-matchers_test.cc
+++ b/testing/gmock/test/gmock-generated-matchers_test.cc
@@ -223,8 +223,9 @@ class GreaterThanMatcher : public MatcherInterface<int> {
*os << "is " << -diff << " less than " << rhs_;
}
}
+
private:
- const int rhs_;
+ int rhs_;
};
Matcher<int> GreaterThan(int n) {
@@ -411,7 +412,7 @@ TEST(ElementsAreTest, WorksForNestedContainer) {
};
vector<list<char> > nested;
- for (int i = 0; i < GMOCK_ARRAY_SIZE_(strings); i++) {
+ for (size_t i = 0; i < GMOCK_ARRAY_SIZE_(strings); i++) {
nested.push_back(list<char>(strings[i], strings[i] + strlen(strings[i])));
}
@@ -446,7 +447,12 @@ TEST(ElementsAreTest, WorksWithNativeArrayPassedByReference) {
class NativeArrayPassedAsPointerAndSize {
public:
+ NativeArrayPassedAsPointerAndSize() {}
+
MOCK_METHOD2(Helper, void(int* array, int size));
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(NativeArrayPassedAsPointerAndSize);
};
TEST(ElementsAreTest, WorksWithNativeArrayPassedAsPointerAndSize) {
@@ -550,7 +556,10 @@ TEST(MatcherMacroTest, Works) {
// Tests that the description string supplied to MATCHER() must be
// valid.
-MATCHER(HasBadDescription, "Invalid%") { return true; }
+MATCHER(HasBadDescription, "Invalid%") {
+ // Uses arg to suppress "unused parameter" warning.
+ return arg==arg;
+}
TEST(MatcherMacroTest,
CreatingMatcherWithBadDescriptionGeneratesNonfatalFailure) {
@@ -560,7 +569,7 @@ TEST(MatcherMacroTest,
"use \"%%\" instead of \"%\" to print \"%\".");
}
-MATCHER(HasGoodDescription, "good") { return true; }
+MATCHER(HasGoodDescription, "good") { return arg==arg; }
TEST(MatcherMacroTest, AcceptsValidDescription) {
const Matcher<int> m = HasGoodDescription();
@@ -642,7 +651,7 @@ TEST(MatcherPMacroTest,
}
-MATCHER_P(HasGoodDescription1, n, "good %(n)s") { return true; }
+MATCHER_P(HasGoodDescription1, n, "good %(n)s") { return arg==arg; }
TEST(MatcherPMacroTest, AcceptsValidDescription) {
const Matcher<int> m = HasGoodDescription1(5);
@@ -709,7 +718,7 @@ TEST(MatcherPnMacroTest,
MATCHER_P2(HasComplexDescription, foo, bar,
"is as complex as %(foo)s %(bar)s (i.e. %(*)s or %%%(foo)s!)") {
- return true;
+ return arg==arg;
}
TEST(MatcherPnMacroTest, AcceptsValidDescription) {
@@ -861,7 +870,7 @@ TEST(MatcherPnMacroTest, WorksForDifferentParameterTypes) {
MATCHER_P2(EqConcat, prefix, suffix, "") {
// The following lines promote the two parameters to desired types.
std::string prefix_str(prefix);
- char suffix_char(suffix);
+ char suffix_char = static_cast<char>(suffix);
return arg == prefix_str + suffix_char;
}
diff --git a/testing/gmock/test/gmock-internal-utils_test.cc b/testing/gmock/test/gmock-internal-utils_test.cc
index ac3b2dd..7dd8311 100644
--- a/testing/gmock/test/gmock-internal-utils_test.cc
+++ b/testing/gmock/test/gmock-internal-utils_test.cc
@@ -819,7 +819,7 @@ TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
TEST(NativeArrayTest, ConstructorFromArrayWorks) {
const int a[3] = { 0, 1, 2 };
NativeArray<int> na(a, 3, kReference);
- EXPECT_EQ(3, na.size());
+ EXPECT_EQ(3U, na.size());
EXPECT_EQ(a, na.begin());
}
@@ -849,7 +849,7 @@ TEST(NativeArrayTest, TypeMembersAreCorrect) {
TEST(NativeArrayTest, MethodsWork) {
const int a[3] = { 0, 1, 2 };
NativeArray<int> na(a, 3, kCopy);
- ASSERT_EQ(3, na.size());
+ ASSERT_EQ(3U, na.size());
EXPECT_EQ(3, na.end() - na.begin());
NativeArray<int>::const_iterator it = na.begin();
@@ -875,7 +875,7 @@ TEST(NativeArrayTest, MethodsWork) {
TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
const char a[2][3] = { "hi", "lo" };
NativeArray<char[3]> na(a, 2, kReference);
- ASSERT_EQ(2, na.size());
+ ASSERT_EQ(2U, na.size());
EXPECT_EQ(a, na.begin());
}
@@ -910,11 +910,11 @@ TEST(StlContainerViewTest, WorksForStaticNativeArray) {
int a1[3] = { 0, 1, 2 };
NativeArray<int> a2 = StlContainerView<int[3]>::ConstReference(a1);
- EXPECT_EQ(3, a2.size());
+ EXPECT_EQ(3U, a2.size());
EXPECT_EQ(a1, a2.begin());
const NativeArray<int> a3 = StlContainerView<int[3]>::Copy(a1);
- ASSERT_EQ(3, a3.size());
+ ASSERT_EQ(3U, a3.size());
EXPECT_EQ(0, a3.begin()[0]);
EXPECT_EQ(1, a3.begin()[1]);
EXPECT_EQ(2, a3.begin()[2]);
@@ -937,12 +937,12 @@ TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
const int* const p1 = a1;
NativeArray<int> a2 = StlContainerView<tuple<const int*, int> >::
ConstReference(make_tuple(p1, 3));
- EXPECT_EQ(3, a2.size());
+ EXPECT_EQ(3U, a2.size());
EXPECT_EQ(a1, a2.begin());
const NativeArray<int> a3 = StlContainerView<tuple<int*, size_t> >::
Copy(make_tuple(static_cast<int*>(a1), 3));
- ASSERT_EQ(3, a3.size());
+ ASSERT_EQ(3U, a3.size());
EXPECT_EQ(0, a3.begin()[0]);
EXPECT_EQ(1, a3.begin()[1]);
EXPECT_EQ(2, a3.begin()[2]);
diff --git a/testing/gmock/test/gmock-matchers_test.cc b/testing/gmock/test/gmock-matchers_test.cc
index 20b9387..907749d 100644
--- a/testing/gmock/test/gmock-matchers_test.cc
+++ b/testing/gmock/test/gmock-matchers_test.cc
@@ -121,6 +121,8 @@ using testing::internal::ValidateMatcherDescription;
using testing::internal::kInvalidInterpolation;
using testing::internal::kPercentInterpolation;
using testing::internal::kTupleInterpolation;
+using testing::internal::linked_ptr;
+using testing::internal::scoped_ptr;
using testing::internal::string;
#ifdef GMOCK_HAS_REGEX
@@ -150,8 +152,9 @@ class GreaterThanMatcher : public MatcherInterface<int> {
*os << "is " << -diff << " less than " << rhs_;
}
}
+
private:
- const int rhs_;
+ int rhs_;
};
Matcher<int> GreaterThan(int n) {
@@ -333,7 +336,7 @@ class IntValue {
public:
// An int can be statically (although not implicitly) cast to a
// IntValue.
- explicit IntValue(int value) : value_(value) {}
+ explicit IntValue(int a_value) : value_(a_value) {}
int value() const { return value_; }
private:
@@ -558,7 +561,7 @@ class Unprintable {
public:
Unprintable() : c_('a') {}
- bool operator==(const Unprintable& rhs) { return true; }
+ bool operator==(const Unprintable& /* rhs */) { return true; }
private:
char c_;
};
@@ -604,7 +607,7 @@ TEST(TypedEqTest, CanDescribeSelf) {
// "undefined referece".
template <typename T>
struct Type {
- static bool IsTypeOf(const T& v) { return true; }
+ static bool IsTypeOf(const T& /* v */) { return true; }
template <typename T2>
static void IsTypeOf(T2 v);
@@ -715,6 +718,33 @@ TEST(IsNullTest, MatchesNullPointer) {
#endif
}
+TEST(IsNullTest, LinkedPtr) {
+ const Matcher<linked_ptr<int> > m = IsNull();
+ const linked_ptr<int> null_p;
+ const linked_ptr<int> non_null_p(new int);
+
+ EXPECT_TRUE(m.Matches(null_p));
+ EXPECT_FALSE(m.Matches(non_null_p));
+}
+
+TEST(IsNullTest, ReferenceToConstLinkedPtr) {
+ const Matcher<const linked_ptr<double>&> m = IsNull();
+ const linked_ptr<double> null_p;
+ const linked_ptr<double> non_null_p(new double);
+
+ EXPECT_TRUE(m.Matches(null_p));
+ EXPECT_FALSE(m.Matches(non_null_p));
+}
+
+TEST(IsNullTest, ReferenceToConstScopedPtr) {
+ const Matcher<const scoped_ptr<double>&> m = IsNull();
+ const scoped_ptr<double> null_p;
+ const scoped_ptr<double> non_null_p(new double);
+
+ EXPECT_TRUE(m.Matches(null_p));
+ EXPECT_FALSE(m.Matches(non_null_p));
+}
+
// Tests that IsNull() describes itself properly.
TEST(IsNullTest, CanDescribeSelf) {
Matcher<int*> m = IsNull();
@@ -736,6 +766,33 @@ TEST(NotNullTest, MatchesNonNullPointer) {
EXPECT_TRUE(m2.Matches("hi"));
}
+TEST(NotNullTest, LinkedPtr) {
+ const Matcher<linked_ptr<int> > m = NotNull();
+ const linked_ptr<int> null_p;
+ const linked_ptr<int> non_null_p(new int);
+
+ EXPECT_FALSE(m.Matches(null_p));
+ EXPECT_TRUE(m.Matches(non_null_p));
+}
+
+TEST(NotNullTest, ReferenceToConstLinkedPtr) {
+ const Matcher<const linked_ptr<double>&> m = NotNull();
+ const linked_ptr<double> null_p;
+ const linked_ptr<double> non_null_p(new double);
+
+ EXPECT_FALSE(m.Matches(null_p));
+ EXPECT_TRUE(m.Matches(non_null_p));
+}
+
+TEST(NotNullTest, ReferenceToConstScopedPtr) {
+ const Matcher<const scoped_ptr<double>&> m = NotNull();
+ const scoped_ptr<double> null_p;
+ const scoped_ptr<double> non_null_p(new double);
+
+ EXPECT_FALSE(m.Matches(null_p));
+ EXPECT_TRUE(m.Matches(non_null_p));
+}
+
// Tests that NotNull() describes itself properly.
TEST(NotNullTest, CanDescribeSelf) {
Matcher<int*> m = NotNull();
@@ -1805,8 +1862,9 @@ class IsGreaterThan {
explicit IsGreaterThan(int threshold) : threshold_(threshold) {}
bool operator()(int n) const { return n > threshold_; }
+
private:
- const int threshold_;
+ int threshold_;
};
// For testing Truly().
@@ -1903,7 +1961,12 @@ TEST(AllArgsTest, WorksForNonTuple) {
class AllArgsHelper {
public:
+ AllArgsHelper() {}
+
MOCK_METHOD2(Helper, int(char x, int y));
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(AllArgsHelper);
};
TEST(AllArgsTest, WorksInWithClause) {
@@ -2328,7 +2391,7 @@ TEST(PointeeTest, CanExplainMatchResult) {
// An uncopyable class.
class Uncopyable {
public:
- explicit Uncopyable(int value) : value_(value) {}
+ explicit Uncopyable(int a_value) : value_(a_value) {}
int value() const { return value_; }
private:
@@ -2349,11 +2412,17 @@ struct AStruct {
const double y; // A const field.
Uncopyable z; // An uncopyable field.
const char* p; // A pointer field.
+
+ private:
+ GTEST_DISALLOW_ASSIGN_(AStruct);
};
// A derived struct for testing Field().
struct DerivedStruct : public AStruct {
char ch;
+
+ private:
+ GTEST_DISALLOW_ASSIGN_(DerivedStruct);
};
// Tests that Field(&Foo::field, ...) works when field is non-const.
@@ -2887,7 +2956,7 @@ TEST(ResultOfTest, WorksForReferencingCallables) {
class DivisibleByImpl {
public:
- explicit DivisibleByImpl(int divider) : divider_(divider) {}
+ explicit DivisibleByImpl(int a_divider) : divider_(a_divider) {}
template <typename T>
bool Matches(const T& n) const {
@@ -2902,7 +2971,7 @@ class DivisibleByImpl {
*os << "is not divisible by " << divider_;
}
- void set_divider(int divider) { divider_ = divider; }
+ void set_divider(int a_divider) { divider_ = a_divider; }
int divider() const { return divider_; }
private:
@@ -2965,7 +3034,7 @@ TEST(ExplainmatcherResultTest, MonomorphicMatcher) {
class NotCopyable {
public:
- explicit NotCopyable(int value) : value_(value) {}
+ explicit NotCopyable(int a_value) : value_(a_value) {}
int value() const { return value_; }
diff --git a/testing/gmock/test/gmock-more-actions_test.cc b/testing/gmock/test/gmock-more-actions_test.cc
index f5dab5b..b3b17d3 100644
--- a/testing/gmock/test/gmock-more-actions_test.cc
+++ b/testing/gmock/test/gmock-more-actions_test.cc
@@ -65,6 +65,10 @@ using testing::Unused;
using testing::WithArg;
using testing::WithoutArgs;
+// For suppressing compiler warnings on conversion possibly losing precision.
+inline short Short(short n) { return n; } // NOLINT
+inline char Char(char ch) { return ch; }
+
// Sample functions and functors for testing Invoke() and etc.
int Nullary() { return 1; }
@@ -85,7 +89,7 @@ bool Unary(int x) { return x < 0; }
const char* Plus1(const char* s) { return s + 1; }
-void VoidUnary(int n) { g_done = true; }
+void VoidUnary(int /* n */) { g_done = true; }
bool ByConstRef(const string& s) { return s == "Hi"; }
@@ -239,13 +243,13 @@ TEST(InvokeTest, Unary) {
TEST(InvokeTest, Binary) {
Action<const char*(const char*, short)> a = Invoke(Binary); // NOLINT
const char* p = "Hello";
- EXPECT_EQ(p + 2, a.Perform(make_tuple(p, 2)));
+ EXPECT_EQ(p + 2, a.Perform(make_tuple(p, Short(2))));
}
// Tests using Invoke() with a ternary function.
TEST(InvokeTest, Ternary) {
Action<int(int, char, short)> a = Invoke(Ternary); // NOLINT
- EXPECT_EQ(6, a.Perform(make_tuple(1, '\2', 3)));
+ EXPECT_EQ(6, a.Perform(make_tuple(1, '\2', Short(3))));
}
// Tests using Invoke() with a 4-argument function.
@@ -340,14 +344,14 @@ TEST(InvokeTest, MethodWithUnusedParameters) {
// Tests using Invoke() with a functor.
TEST(InvokeTest, Functor) {
- Action<int(short, char)> a = Invoke(plus<short>()); // NOLINT
- EXPECT_EQ(3, a.Perform(make_tuple(1, 2)));
+ Action<long(long, int)> a = Invoke(plus<long>()); // NOLINT
+ EXPECT_EQ(3L, a.Perform(make_tuple(1, 2)));
}
// Tests using Invoke(f) as an action of a compatible type.
TEST(InvokeTest, FunctionWithCompatibleType) {
Action<long(int, short, char, bool)> a = Invoke(SumOf4); // NOLINT
- EXPECT_EQ(4321, a.Perform(make_tuple(4000, 300, 20, true)));
+ EXPECT_EQ(4321, a.Perform(make_tuple(4000, Short(300), Char(20), true)));
}
// Tests using Invoke() with an object pointer and a method pointer.
@@ -378,7 +382,7 @@ TEST(InvokeMethodTest, Binary) {
TEST(InvokeMethodTest, Ternary) {
Foo foo;
Action<int(int, bool, char)> a = Invoke(&foo, &Foo::Ternary); // NOLINT
- EXPECT_EQ(1124, a.Perform(make_tuple(1000, true, 1)));
+ EXPECT_EQ(1124, a.Perform(make_tuple(1000, true, Char(1))));
}
// Tests using Invoke() with a 4-argument method.
@@ -457,7 +461,7 @@ TEST(InvokeMethodTest, MethodWithCompatibleType) {
Foo foo;
Action<long(int, short, char, bool)> a = // NOLINT
Invoke(&foo, &Foo::SumOf4);
- EXPECT_EQ(4444, a.Perform(make_tuple(4000, 300, 20, true)));
+ EXPECT_EQ(4444, a.Perform(make_tuple(4000, Short(300), Char(20), true)));
}
// Tests using WithoutArgs with an action that takes no argument.
diff --git a/testing/gmock/test/gmock-nice-strict_test.cc b/testing/gmock/test/gmock-nice-strict_test.cc
index 0dc7106..1d36e03 100644
--- a/testing/gmock/test/gmock-nice-strict_test.cc
+++ b/testing/gmock/test/gmock-nice-strict_test.cc
@@ -40,7 +40,12 @@
// clash with ::testing::Mock.
class Mock {
public:
+ Mock() {}
+
MOCK_METHOD0(DoThis, void());
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(Mock);
};
namespace testing {
@@ -64,10 +69,14 @@ class Foo {
class MockFoo : public Foo {
public:
+ MockFoo() {}
void Delete() { delete this; }
MOCK_METHOD0(DoThis, void());
MOCK_METHOD1(DoThat, int(bool flag));
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
};
class MockBar {
@@ -89,6 +98,8 @@ class MockBar {
private:
string str_;
+
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar);
};
// TODO(wan@google.com): find a way to re-enable these tests.
@@ -173,21 +184,21 @@ TEST(NiceMockTest, NonDefaultConstructor10) {
nice_bar.That(5, true);
}
-#if !GTEST_OS_SYMBIAN
+#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that NiceMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). We had to workaround an
// MSVC 8.0 bug that caused the symbol Mock used in the definition of
// NiceMock to be looked up in the wrong context, and this test
// ensures that our fix works.
//
-// We have to skip this test on Symbian, as it causes the program to
-// crash there, for reasons unclear to us yet.
+// We have to skip this test on Symbian and Windows Mobile, as it
+// causes the program to crash there, for reasons unclear to us yet.
TEST(NiceMockTest, AcceptsClassNamedMock) {
NiceMock< ::Mock> nice;
EXPECT_CALL(nice, DoThis());
nice.DoThis();
}
-#endif // !GTEST_OS_SYMBIAN
+#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that a strict mock allows expected calls.
TEST(StrictMockTest, AllowsExpectedCall) {
@@ -247,21 +258,21 @@ TEST(StrictMockTest, NonDefaultConstructor10) {
"Uninteresting mock function call");
}
-#if !GTEST_OS_SYMBIAN
+#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that StrictMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). We had to workaround an
// MSVC 8.0 bug that caused the symbol Mock used in the definition of
// StrictMock to be looked up in the wrong context, and this test
// ensures that our fix works.
//
-// We have to skip this test on Symbian, as it causes the program to
-// crash there, for reasons unclear to us yet.
+// We have to skip this test on Symbian and Windows Mobile, as it
+// causes the program to crash there, for reasons unclear to us yet.
TEST(StrictMockTest, AcceptsClassNamedMock) {
StrictMock< ::Mock> strict;
EXPECT_CALL(strict, DoThis());
strict.DoThis();
}
-#endif // !GTEST_OS_SYMBIAN
+#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
} // namespace gmock_nice_strict_test
} // namespace testing
diff --git a/testing/gmock/test/gmock-port_test.cc b/testing/gmock/test/gmock-port_test.cc
index 9a64ec33e..054313b 100644
--- a/testing/gmock/test/gmock-port_test.cc
+++ b/testing/gmock/test/gmock-port_test.cc
@@ -36,4 +36,129 @@
#include <gmock/internal/gmock-port.h>
#include <gtest/gtest.h>
-// This file intentionally contains no test at this moment.
+// NOTE: if this file is left without tests for some reason, put a dummy
+// test here to make references to symbols in the gtest library and avoid
+// 'undefined symbol' linker errors in gmock_main:
+//
+// TEST(DummyTest, Dummy) {}
+
+namespace testing {
+namespace internal {
+// Needed to avoid name collisions in gmock_all_test.cc.
+namespace gmock_port_test {
+
+class Base {
+ public:
+ // Copy constructor and assignment operator do exactly what we need, so we
+ // use them.
+ Base() : member_(0) {}
+ explicit Base(int n) : member_(n) {}
+ virtual ~Base() {}
+ int member() { return member_; }
+
+ private:
+ int member_;
+};
+
+class Derived : public Base {
+ public:
+ explicit Derived(int n) : Base(n) {}
+};
+
+TEST(ImplicitCastTest, ConvertsPointers) {
+ Derived derived(0);
+ EXPECT_TRUE(&derived == ::testing::internal::implicit_cast<Base*>(&derived));
+}
+
+TEST(ImplicitCastTest, CanUseInheritance) {
+ Derived derived(1);
+ Base base = ::testing::internal::implicit_cast<Base>(derived);
+ EXPECT_EQ(derived.member(), base.member());
+}
+
+class Castable {
+ public:
+ Castable(bool* converted) : converted_(converted) {}
+ operator Base() {
+ *converted_ = true;
+ return Base();
+ }
+
+ private:
+ bool* converted_;
+};
+
+TEST(ImplicitCastTest, CanUseNonConstCastOperator) {
+ bool converted = false;
+ Castable castable(&converted);
+ Base base = ::testing::internal::implicit_cast<Base>(castable);
+ EXPECT_TRUE(converted);
+}
+
+class ConstCastable {
+ public:
+ ConstCastable(bool* converted) : converted_(converted) {}
+ operator Base() const {
+ *converted_ = true;
+ return Base();
+ }
+
+ private:
+ bool* converted_;
+};
+
+TEST(ImplicitCastTest, CanUseConstCastOperatorOnConstValues) {
+ bool converted = false;
+ const ConstCastable const_castable(&converted);
+ Base base = ::testing::internal::implicit_cast<Base>(const_castable);
+ EXPECT_TRUE(converted);
+}
+
+class ConstAndNonConstCastable {
+ public:
+ ConstAndNonConstCastable(bool* converted, bool* const_converted)
+ : converted_(converted), const_converted_(const_converted) {}
+ operator Base() {
+ *converted_ = true;
+ return Base();
+ }
+ operator Base() const {
+ *const_converted_ = true;
+ return Base();
+ }
+
+ private:
+ bool* converted_;
+ bool* const_converted_;
+};
+
+TEST(ImplicitCastTest, CanSelectBetweenConstAndNonConstCasrAppropriately) {
+ bool converted = false;
+ bool const_converted = false;
+ ConstAndNonConstCastable castable(&converted, &const_converted);
+ Base base = ::testing::internal::implicit_cast<Base>(castable);
+ EXPECT_TRUE(converted);
+ EXPECT_FALSE(const_converted);
+
+ converted = false;
+ const_converted = false;
+ const ConstAndNonConstCastable const_castable(&converted, &const_converted);
+ base = ::testing::internal::implicit_cast<Base>(const_castable);
+ EXPECT_FALSE(converted);
+ EXPECT_TRUE(const_converted);
+}
+
+class To {
+ public:
+ To(bool* converted) { *converted = true; } // NOLINT
+};
+
+TEST(ImplicitCastTest, CanUseImplicitConstructor) {
+ bool converted = false;
+ To to = ::testing::internal::implicit_cast<To>(&converted);
+ EXPECT_TRUE(converted);
+}
+
+} // namespace gmock_port_test
+} // namespace internal
+} // namespace testing
diff --git a/testing/gmock/test/gmock-printers_test.cc b/testing/gmock/test/gmock-printers_test.cc
index c72e3d3..0553e9c 100644
--- a/testing/gmock/test/gmock-printers_test.cc
+++ b/testing/gmock/test/gmock-printers_test.cc
@@ -77,7 +77,7 @@ class StreamableInGlobal {
virtual ~StreamableInGlobal() {}
};
-inline void operator<<(::std::ostream& os, const StreamableInGlobal& x) {
+inline void operator<<(::std::ostream& os, const StreamableInGlobal& /* x */) {
os << "StreamableInGlobal";
}
@@ -107,7 +107,7 @@ void PrintTo(const PrintableViaPrintTo& x, ::std::ostream* os) {
template <typename T>
class PrintableViaPrintToTemplate {
public:
- explicit PrintableViaPrintToTemplate(const T& value) : value_(value) {}
+ explicit PrintableViaPrintToTemplate(const T& a_value) : value_(a_value) {}
const T& value() const { return value_; }
private:
@@ -440,11 +440,17 @@ TEST(PrintPointerToPointerTest, IntPointerPointer) {
// Tests printing (non-member) function pointers.
-void MyFunction(int n) {}
+void MyFunction(int /* n */) {}
TEST(PrintPointerTest, NonMemberFunctionPointer) {
- EXPECT_EQ(PrintPointer(reinterpret_cast<const void*>(&MyFunction)),
- Print(&MyFunction));
+ // We cannot directly cast &MyFunction to const void* because the
+ // standard disallows casting between pointers to functions and
+ // pointers to objects, and some compilers (e.g. GCC 3.4) enforce
+ // this limitation.
+ EXPECT_EQ(
+ PrintPointer(reinterpret_cast<const void*>(
+ reinterpret_cast<internal::BiggestInt>(&MyFunction))),
+ Print(&MyFunction));
int (*p)(bool) = NULL; // NOLINT
EXPECT_EQ("NULL", Print(p));
}
@@ -458,7 +464,7 @@ struct Foo {
public:
virtual ~Foo() {}
int MyMethod(char x) { return x + 1; }
- virtual char MyVirtualMethod(int n) { return 'a'; }
+ virtual char MyVirtualMethod(int /* n */) { return 'a'; }
int value;
};
@@ -554,7 +560,6 @@ TEST(PrintStringTest, StringInGlobalNamespace) {
}
#endif // GTEST_HAS_GLOBAL_STRING
-#if GTEST_HAS_STD_STRING
// ::std::string.
TEST(PrintStringTest, StringInStdNamespace) {
const char s[] = "'\"\?\\\a\b\f\n\0\r\t\v\x7F\xFF a";
@@ -562,7 +567,6 @@ TEST(PrintStringTest, StringInStdNamespace) {
EXPECT_EQ("\"'\\\"\\?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"",
Print(str));
}
-#endif // GTEST_HAS_STD_STRING
// Tests printing ::wstring and ::std::wstring.
@@ -599,7 +603,7 @@ class AllowsGenericStreaming {};
template <typename Char, typename CharTraits>
std::basic_ostream<Char, CharTraits>& operator<<(
std::basic_ostream<Char, CharTraits>& os,
- const AllowsGenericStreaming& a) {
+ const AllowsGenericStreaming& /* a */) {
return os << "AllowsGenericStreaming";
}
@@ -616,7 +620,7 @@ class AllowsGenericStreamingTemplate {};
template <typename Char, typename CharTraits, typename T>
std::basic_ostream<Char, CharTraits>& operator<<(
std::basic_ostream<Char, CharTraits>& os,
- const AllowsGenericStreamingTemplate<T>& a) {
+ const AllowsGenericStreamingTemplate<T>& /* a */) {
return os << "AllowsGenericStreamingTemplate";
}
@@ -637,7 +641,7 @@ class AllowsGenericStreamingAndImplicitConversionTemplate {
template <typename Char, typename CharTraits, typename T>
std::basic_ostream<Char, CharTraits>& operator<<(
std::basic_ostream<Char, CharTraits>& os,
- const AllowsGenericStreamingAndImplicitConversionTemplate<T>& a) {
+ const AllowsGenericStreamingAndImplicitConversionTemplate<T>& /* a */) {
return os << "AllowsGenericStreamingAndImplicitConversionTemplate";
}
@@ -973,7 +977,12 @@ TEST(PrintReferenceTest, HandlesFunctionPointer) {
void (*fp)(int n) = &MyFunction;
const string fp_pointer_string =
PrintPointer(reinterpret_cast<const void*>(&fp));
- const string fp_string = PrintPointer(reinterpret_cast<const void*>(fp));
+ // We cannot directly cast &MyFunction to const void* because the
+ // standard disallows casting between pointers to functions and
+ // pointers to objects, and some compilers (e.g. GCC 3.4) enforce
+ // this limitation.
+ const string fp_string = PrintPointer(reinterpret_cast<const void*>(
+ reinterpret_cast<internal::BiggestInt>(fp)));
EXPECT_EQ("@" + fp_pointer_string + " " + fp_string,
PrintByRef(fp));
}
diff --git a/testing/gmock/test/gmock-spec-builders_test.cc b/testing/gmock/test/gmock-spec-builders_test.cc
index 707d896..c1e7738 100644
--- a/testing/gmock/test/gmock-spec-builders_test.cc
+++ b/testing/gmock/test/gmock-spec-builders_test.cc
@@ -97,16 +97,26 @@ class Result {};
class MockA {
public:
+ MockA() {}
+
MOCK_METHOD1(DoA, void(int n)); // NOLINT
MOCK_METHOD1(ReturnResult, Result(int n)); // NOLINT
MOCK_METHOD2(Binary, bool(int x, int y)); // NOLINT
MOCK_METHOD2(ReturnInt, int(int x, int y)); // NOLINT
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockA);
};
class MockB {
public:
+ MockB() {}
+
MOCK_CONST_METHOD0(DoB, int()); // NOLINT
MOCK_METHOD1(DoB, int(int n)); // NOLINT
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockB);
};
// Tests that EXPECT_CALL and ON_CALL compile in a presence of macro
@@ -123,7 +133,12 @@ class CC {
};
class MockCC : public CC {
public:
+ MockCC() {}
+
MOCK_METHOD0(Method, int());
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockCC);
};
// Tests that a method with expanded name compiles.
@@ -571,29 +586,34 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) {
b.DoB(2);
}
const string& output = GetCapturedTestStdout();
- EXPECT_PRED_FORMAT2(IsSubstring,
- "Too many actions specified.\n"
- "Expected to be never called, but has 1 WillOnce().",
- output); // #1
- EXPECT_PRED_FORMAT2(IsSubstring,
- "Too many actions specified.\n"
- "Expected to be called at most once, "
- "but has 2 WillOnce()s.",
- output); // #2
- EXPECT_PRED_FORMAT2(IsSubstring,
- "Too many actions specified.\n"
- "Expected to be called once, but has 2 WillOnce()s.",
- output); // #3
- EXPECT_PRED_FORMAT2(IsSubstring,
- "Too many actions specified.\n"
- "Expected to be never called, but has 0 WillOnce()s "
- "and a WillRepeatedly().",
- output); // #4
- EXPECT_PRED_FORMAT2(IsSubstring,
- "Too many actions specified.\n"
- "Expected to be called once, but has 1 WillOnce() "
- "and a WillRepeatedly().",
- output); // #5
+ EXPECT_PRED_FORMAT2(
+ IsSubstring,
+ "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
+ "Expected to be never called, but has 1 WillOnce().",
+ output); // #1
+ EXPECT_PRED_FORMAT2(
+ IsSubstring,
+ "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
+ "Expected to be called at most once, "
+ "but has 2 WillOnce()s.",
+ output); // #2
+ EXPECT_PRED_FORMAT2(
+ IsSubstring,
+ "Too many actions specified in EXPECT_CALL(b, DoB(1))...\n"
+ "Expected to be called once, but has 2 WillOnce()s.",
+ output); // #3
+ EXPECT_PRED_FORMAT2(
+ IsSubstring,
+ "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
+ "Expected to be never called, but has 0 WillOnce()s "
+ "and a WillRepeatedly().",
+ output); // #4
+ EXPECT_PRED_FORMAT2(
+ IsSubstring,
+ "Too many actions specified in EXPECT_CALL(b, DoB(2))...\n"
+ "Expected to be called once, but has 1 WillOnce() "
+ "and a WillRepeatedly().",
+ output); // #5
}
// Tests that Google Mock warns on having too few actions in an
@@ -608,11 +628,12 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
CaptureTestStdout();
b.DoB();
const string& output = GetCapturedTestStdout();
- EXPECT_PRED_FORMAT2(IsSubstring,
- "Too few actions specified.\n"
- "Expected to be called between 2 and 3 times, "
- "but has only 1 WillOnce().",
- output);
+ EXPECT_PRED_FORMAT2(
+ IsSubstring,
+ "Too few actions specified in EXPECT_CALL(b, DoB())...\n"
+ "Expected to be called between 2 and 3 times, "
+ "but has only 1 WillOnce().",
+ output);
b.DoB();
}
@@ -688,7 +709,7 @@ TEST(ExpectCallTest, CatchesTooFewCalls) {
.Times(AtLeast(2));
b.DoB(5);
- }, "Actual function call count doesn't match this expectation.\n"
+ }, "Actual function call count doesn't match EXPECT_CALL(b, DoB(5))...\n"
" Expected: to be called at least twice\n"
" Actual: called once - unsatisfied and active");
}
@@ -895,14 +916,14 @@ TEST(UnexpectedCallTest, GeneratesFailureForVoidFunction) {
"Google Mock tried the following 2 expectations, but none matched:");
EXPECT_NONFATAL_FAILURE(
a2.DoA(2),
- "tried expectation #0\n"
+ "tried expectation #0: EXPECT_CALL(a2, DoA(1))...\n"
" Expected arg #0: is equal to 1\n"
" Actual: 2\n"
" Expected: to be called once\n"
" Actual: called once - saturated and active");
EXPECT_NONFATAL_FAILURE(
a2.DoA(2),
- "tried expectation #1\n"
+ "tried expectation #1: EXPECT_CALL(a2, DoA(3))...\n"
" Expected arg #0: is equal to 3\n"
" Actual: 2\n"
" Expected: to be called once\n"
@@ -1611,8 +1632,19 @@ TEST(DeletingMockEarlyTest, Success2) {
// Tests that it's OK to delete a mock object itself in its action.
+// Suppresses warning on unreferenced formal parameter in MSVC with
+// -W4.
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable:4100)
+#endif
+
ACTION_P(Delete, ptr) { delete ptr; }
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) {
MockA* const a = new MockA;
EXPECT_CALL(*a, DoA(_)).WillOnce(Delete(a));
@@ -1685,7 +1717,9 @@ class EvenNumberCardinality : public CardinalityInterface {
}
// Returns true iff call_count calls will saturate this cardinality.
- virtual bool IsSaturatedByCallCount(int call_count) const { return false; }
+ virtual bool IsSaturatedByCallCount(int /* call_count */) const {
+ return false;
+ }
// Describes self to an ostream.
virtual void DescribeTo(::std::ostream* os) const {
@@ -1734,9 +1768,14 @@ struct Unprintable {
class MockC {
public:
+ MockC() {}
+
MOCK_METHOD6(VoidMethod, void(bool cond, int n, string s, void* p,
const Printable& x, Unprintable y));
MOCK_METHOD0(NonVoidMethod, int()); // NOLINT
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockC);
};
// TODO(wan@google.com): find a way to re-enable these tests.
@@ -1929,7 +1968,12 @@ void PrintTo(PrintMeNot /* dummy */, ::std::ostream* /* os */) {
class LogTestHelper {
public:
+ LogTestHelper() {}
+
MOCK_METHOD1(Foo, PrintMeNot(PrintMeNot));
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(LogTestHelper);
};
class GMockLogTest : public ::testing::Test {
@@ -2046,7 +2090,7 @@ TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndFail) {
MockB b;
EXPECT_CALL(b, DoB())
.WillOnce(Return(1));
- bool result;
+ bool result = true;
EXPECT_NONFATAL_FAILURE(result = Mock::VerifyAndClearExpectations(&b),
"Actual: never called");
ASSERT_FALSE(result);
@@ -2084,7 +2128,7 @@ TEST(VerifyAndClearExpectationsTest, AMethodHasManyExpectations) {
EXPECT_CALL(b, DoB(_))
.WillOnce(Return(2));
b.DoB(1);
- bool result;
+ bool result = true;
EXPECT_NONFATAL_FAILURE(result = Mock::VerifyAndClearExpectations(&b),
"Actual: never called");
ASSERT_FALSE(result);
@@ -2216,7 +2260,7 @@ TEST(VerifyAndClearTest, Failure) {
.WillOnce(Return(2));
b.DoB(1);
- bool result;
+ bool result = true;
EXPECT_NONFATAL_FAILURE(result = Mock::VerifyAndClear(&b),
"Actual: never called");
ASSERT_FALSE(result);
diff --git a/testing/gmock/test/gmock_leak_test.py b/testing/gmock/test/gmock_leak_test.py
index 1337e0b..38ff9d0 100644..100755
--- a/testing/gmock/test/gmock_leak_test.py
+++ b/testing/gmock/test/gmock_leak_test.py
@@ -33,51 +33,57 @@
__author__ = 'wan@google.com (Zhanyong Wan)'
-import gmock_test_utils
-import os
-import unittest
-IS_WINDOWS = os.name == 'nt'
+import gmock_test_utils
-if IS_WINDOWS:
- # TODO(wan@google.com): test the opt build too. We should do it
- # when Vlad Losev's work on Google Test's Python test driver is
- # done, such that we can reuse the work.
- PROGRAM = r'..\build.dbg\gmock_leak_test_.exe'
-else:
- PROGRAM = 'gmock_leak_test_'
-PROGRAM_PATH = os.path.join(gmock_test_utils.GetBuildDir(), PROGRAM)
-TEST_WITH_EXPECT_CALL = PROGRAM_PATH + ' --gtest_filter=*ExpectCall*'
-TEST_WITH_ON_CALL = PROGRAM_PATH + ' --gtest_filter=*OnCall*'
-TEST_MULTIPLE_LEAKS = PROGRAM_PATH + ' --gtest_filter=*MultipleLeaked*'
+PROGRAM_PATH = gmock_test_utils.GetTestExecutablePath('gmock_leak_test_')
+TEST_WITH_EXPECT_CALL = [PROGRAM_PATH, '--gtest_filter=*ExpectCall*']
+TEST_WITH_ON_CALL = [PROGRAM_PATH, '--gtest_filter=*OnCall*']
+TEST_MULTIPLE_LEAKS = [PROGRAM_PATH, '--gtest_filter=*MultipleLeaked*']
-class GMockLeakTest(unittest.TestCase):
+class GMockLeakTest(gmock_test_utils.TestCase):
def testCatchesLeakedMockByDefault(self):
- self.assertNotEqual(os.system(TEST_WITH_EXPECT_CALL), 0)
- self.assertNotEqual(os.system(TEST_WITH_ON_CALL), 0)
+ self.assertNotEqual(
+ 0,
+ gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL).exit_code)
+ self.assertNotEqual(
+ 0,
+ gmock_test_utils.Subprocess(TEST_WITH_ON_CALL).exit_code)
def testDoesNotCatchLeakedMockWhenDisabled(self):
self.assertEquals(
- 0, os.system(TEST_WITH_EXPECT_CALL + ' --gmock_catch_leaked_mocks=0'))
+ 0,
+ gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL +
+ ['--gmock_catch_leaked_mocks=0']).exit_code)
self.assertEquals(
- 0, os.system(TEST_WITH_ON_CALL + ' --gmock_catch_leaked_mocks=0'))
+ 0,
+ gmock_test_utils.Subprocess(TEST_WITH_ON_CALL +
+ ['--gmock_catch_leaked_mocks=0']).exit_code)
def testCatchesLeakedMockWhenEnabled(self):
self.assertNotEqual(
- os.system(TEST_WITH_EXPECT_CALL + ' --gmock_catch_leaked_mocks'), 0)
+ 0,
+ gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL +
+ ['--gmock_catch_leaked_mocks']).exit_code)
self.assertNotEqual(
- os.system(TEST_WITH_ON_CALL + ' --gmock_catch_leaked_mocks'), 0)
+ 0,
+ gmock_test_utils.Subprocess(TEST_WITH_ON_CALL +
+ ['--gmock_catch_leaked_mocks']).exit_code)
def testCatchesLeakedMockWhenEnabledWithExplictFlagValue(self):
self.assertNotEqual(
- os.system(TEST_WITH_EXPECT_CALL + ' --gmock_catch_leaked_mocks=1'), 0)
+ 0,
+ gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL +
+ ['--gmock_catch_leaked_mocks=1']).exit_code)
def testCatchesMultipleLeakedMocks(self):
self.assertNotEqual(
- os.system(TEST_MULTIPLE_LEAKS + ' --gmock_catch_leaked_mocks'), 0)
+ 0,
+ gmock_test_utils.Subprocess(TEST_MULTIPLE_LEAKS +
+ ['--gmock_catch_leaked_mocks']).exit_code)
if __name__ == '__main__':
diff --git a/testing/gmock/test/gmock_leak_test_.cc b/testing/gmock/test/gmock_leak_test_.cc
index 157bd7e..24dfc1f 100644
--- a/testing/gmock/test/gmock_leak_test_.cc
+++ b/testing/gmock/test/gmock_leak_test_.cc
@@ -48,7 +48,12 @@ class FooInterface {
class MockFoo : public FooInterface {
public:
+ MockFoo() {}
+
MOCK_METHOD0(DoThis, void());
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
};
TEST(LeakTest, LeakedMockWithExpectCallCausesFailureWhenLeakCheckingIsEnabled) {
diff --git a/testing/gmock/test/gmock_link_test.h b/testing/gmock/test/gmock_link_test.h
index 40554bf..d963590 100644
--- a/testing/gmock/test/gmock_link_test.h
+++ b/testing/gmock/test/gmock_link_test.h
@@ -206,6 +206,8 @@ class Interface {
class Mock: public Interface {
public:
+ Mock() {}
+
MOCK_METHOD1(VoidFromString, void(char* str));
MOCK_METHOD1(StringFromString, char*(char* str));
MOCK_METHOD1(IntFromString, int(char* str));
@@ -215,6 +217,9 @@ class Mock: public Interface {
MOCK_METHOD1(VoidFromFloat, void(float n));
MOCK_METHOD1(VoidFromDouble, void(double n));
MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v));
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(Mock);
};
class InvokeHelper {
@@ -229,7 +234,7 @@ class InvokeHelper {
class FieldHelper {
public:
- FieldHelper(int field) : field_(field) {}
+ FieldHelper(int a_field) : field_(a_field) {}
int field() const { return field_; }
int field_; // NOLINT -- need external access to field_ to test
// the Field matcher.
@@ -410,6 +415,16 @@ TEST(LinkTest, TestThrow) {
}
#endif // GTEST_HAS_EXCEPTIONS
+// The ACTION*() macros trigger warning C4100 (unreferenced formal
+// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
+// the macro definition, as the warnings are generated when the macro
+// is expanded and macro expansion cannot contain #pragma. Therefore
+// we suppress them here.
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable:4100)
+#endif
+
// Tests the linkage of actions created using ACTION macro.
namespace {
ACTION(Return1) { return 1; }
@@ -441,6 +456,10 @@ ACTION_P2(ReturnEqualsEitherOf, first, second) {
}
}
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
TEST(LinkTest, TestActionP2Macro) {
Mock mock;
char ch = 'x';
diff --git a/testing/gmock/test/gmock_output_test.py b/testing/gmock/test/gmock_output_test.py
index f43f707..614a58f 100644..100755
--- a/testing/gmock/test/gmock_output_test.py
+++ b/testing/gmock/test/gmock_output_test.py
@@ -40,29 +40,20 @@ SYNOPSIS
__author__ = 'wan@google.com (Zhanyong Wan)'
-import gmock_test_utils
import os
import re
-import string
import sys
-import unittest
+
+import gmock_test_utils
# The flag for generating the golden file
GENGOLDEN_FLAG = '--gengolden'
-IS_WINDOWS = os.name == 'nt'
-
-if IS_WINDOWS:
- PROGRAM = r'..\build.dbg\gmock_output_test_.exe'
-else:
- PROGRAM = 'gmock_output_test_'
-
-PROGRAM_PATH = os.path.join(gmock_test_utils.GetBuildDir(), PROGRAM)
-COMMAND = PROGRAM_PATH + ' --gtest_stack_trace_depth=0 --gtest_print_time=0'
+PROGRAM_PATH = gmock_test_utils.GetTestExecutablePath('gmock_output_test_')
+COMMAND = [PROGRAM_PATH, '--gtest_stack_trace_depth=0', '--gtest_print_time=0']
GOLDEN_NAME = 'gmock_output_test_golden.txt'
-GOLDEN_PATH = os.path.join(gmock_test_utils.GetSourceDir(),
- GOLDEN_NAME)
+GOLDEN_PATH = os.path.join(gmock_test_utils.GetSourceDir(), GOLDEN_NAME)
def ToUnixLineEnding(s):
@@ -144,51 +135,10 @@ def GetNormalizedOutputAndLeakyTests(output):
return (RemoveTestNamesOfLeakedMocks(output), GetLeakyTests(output))
-def IterShellCommandOutput(cmd, stdin_string=None):
- """Runs a command in a sub-process, and iterates the lines in its STDOUT.
-
- Args:
-
- cmd: The shell command.
- stdin_string: The string to be fed to the STDIN of the sub-process;
- If None, the sub-process will inherit the STDIN
- from the parent process.
- """
-
- # Spawns cmd in a sub-process, and gets its standard I/O file objects.
- stdin_file, stdout_file = os.popen2(cmd, 'b')
-
- # If the caller didn't specify a string for STDIN, gets it from the
- # parent process.
- if stdin_string is None:
- stdin_string = sys.stdin.read()
-
- # Feeds the STDIN string to the sub-process.
- stdin_file.write(stdin_string)
- stdin_file.close()
-
- while True:
- line = stdout_file.readline()
- if not line: # EOF
- stdout_file.close()
- break
-
- yield line
-
-
-def GetShellCommandOutput(cmd, stdin_string=None):
- """Runs a command in a sub-process, and returns its STDOUT in a string.
-
- Args:
-
- cmd: The shell command.
- stdin_string: The string to be fed to the STDIN of the sub-process;
- If None, the sub-process will inherit the STDIN
- from the parent process.
- """
+def GetShellCommandOutput(cmd):
+ """Runs a command in a sub-process, and returns its STDOUT in a string."""
- lines = list(IterShellCommandOutput(cmd, stdin_string))
- return string.join(lines, '')
+ return gmock_test_utils.Subprocess(cmd, capture_stderr=False).output
def GetNormalizedCommandOutputAndLeakyTests(cmd):
@@ -200,10 +150,10 @@ def GetNormalizedCommandOutputAndLeakyTests(cmd):
# Disables exception pop-ups on Windows.
os.environ['GTEST_CATCH_EXCEPTIONS'] = '1'
- return GetNormalizedOutputAndLeakyTests(GetShellCommandOutput(cmd, ''))
+ return GetNormalizedOutputAndLeakyTests(GetShellCommandOutput(cmd))
-class GMockOutputTest(unittest.TestCase):
+class GMockOutputTest(gmock_test_utils.TestCase):
def testOutput(self):
(output, leaky_tests) = GetNormalizedCommandOutputAndLeakyTests(COMMAND)
golden_file = open(GOLDEN_PATH, 'rb')
diff --git a/testing/gmock/test/gmock_output_test_.cc b/testing/gmock/test/gmock_output_test_.cc
index 8244f10..24c9b38 100644
--- a/testing/gmock/test/gmock_output_test_.cc
+++ b/testing/gmock/test/gmock_output_test_.cc
@@ -49,9 +49,14 @@ using testing::Sequence;
class MockFoo {
public:
+ MockFoo() {}
+
MOCK_METHOD3(Bar, char(const std::string& s, int i, double x));
MOCK_METHOD2(Bar2, bool(int x, int y));
MOCK_METHOD2(Bar3, void(int x, int y));
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
};
class GMockOutputTest : public testing::Test {
@@ -161,6 +166,10 @@ TEST_F(GMockOutputTest, UnsatisfiedPrerequisites) {
foo_.Bar2(1, 0);
}
+TEST_F(GMockOutputTest, UnsatisfiedWith) {
+ EXPECT_CALL(foo_, Bar2(_, _)).With(Ge());
+}
+
TEST_F(GMockOutputTest, UnsatisfiedExpectation) {
EXPECT_CALL(foo_, Bar(_, _, _));
EXPECT_CALL(foo_, Bar2(0, _))
diff --git a/testing/gmock/test/gmock_output_test_golden.txt b/testing/gmock/test/gmock_output_test_golden.txt
index aeec660..ed8deca 100644
--- a/testing/gmock/test/gmock_output_test_golden.txt
+++ b/testing/gmock/test/gmock_output_test_golden.txt
@@ -3,7 +3,7 @@
FILE:#: EXPECT_CALL(foo_, Bar2(0, _)) invoked
Stack trace:
-FILE:#: Expected mock function call.
+FILE:#: Mock function call matches EXPECT_CALL(foo_, Bar2(0, _))...
Function call: Bar2(0, 0)
Returns: false
Stack trace:
@@ -13,17 +13,17 @@ Stack trace:
FILE:#: EXPECT_CALL(foo_, Bar3(0, _)) invoked
Stack trace:
-FILE:#: Expected mock function call.
+FILE:#: Mock function call matches EXPECT_CALL(foo_, Bar3(0, _))...
Function call: Bar3(0, 0)
Stack trace:
[ OK ] GMockOutputTest.ExpectedCallToVoidFunction
[ RUN ] GMockOutputTest.ExplicitActionsRunOut
GMOCK WARNING:
-FILE:#: Too few actions specified.
+FILE:#: Too few actions specified in EXPECT_CALL(foo_, Bar2(_, _))...
Expected to be called twice, but has only 1 WillOnce().
GMOCK WARNING:
-FILE:#: Actions ran out.
+FILE:#: Actions ran out in EXPECT_CALL(foo_, Bar2(_, _))...
Called 2 times, but only 1 WillOnce() is specified - returning default value.
Stack trace:
[ OK ] GMockOutputTest.ExplicitActionsRunOut
@@ -35,7 +35,7 @@ Unexpected mock function call - returning default value.
Returns: false
Google Mock tried the following 1 expectation, but it didn't match:
-FILE:#:
+FILE:#: EXPECT_CALL(foo_, Bar2(0, _))...
Expected arg #0: is equal to 0
Actual: 1
Expected: to be called once
@@ -48,7 +48,7 @@ Unexpected mock function call - returning directly.
Function call: Bar3(1, 0)
Google Mock tried the following 1 expectation, but it didn't match:
-FILE:#:
+FILE:#: EXPECT_CALL(foo_, Bar3(0, _))...
Expected arg #0: is equal to 0
Actual: 1
Expected: to be called once
@@ -92,12 +92,12 @@ Unexpected mock function call - returning default value.
Returns: false
Google Mock tried the following 2 expectations, but none matched:
-FILE:#: tried expectation #0
+FILE:#: tried expectation #0: EXPECT_CALL(foo_, Bar2(_, _))...
Expected: the expectation is active
Actual: it is retired
Expected: to be called once
Actual: called once - saturated and retired
-FILE:#: tried expectation #1
+FILE:#: tried expectation #1: EXPECT_CALL(foo_, Bar2(0, 0))...
Expected arg #0: is equal to 0
Actual: 1
Expected arg #1: is equal to 0
@@ -113,12 +113,12 @@ Unexpected mock function call - returning default value.
Returns: false
Google Mock tried the following 2 expectations, but none matched:
-FILE:#: tried expectation #0
+FILE:#: tried expectation #0: EXPECT_CALL(foo_, Bar2(0, 0))...
Expected arg #0: is equal to 0
Actual: 1
Expected: to be called once
Actual: never called - unsatisfied and active
-FILE:#: tried expectation #1
+FILE:#: tried expectation #1: EXPECT_CALL(foo_, Bar2(1, _))...
Expected: all pre-requisites are satisfied
Actual: the following immediate pre-requisites are not satisfied:
FILE:#: pre-requisite #0
@@ -134,12 +134,12 @@ Unexpected mock function call - returning default value.
Returns: false
Google Mock tried the following 2 expectations, but none matched:
-FILE:#: tried expectation #0
+FILE:#: tried expectation #0: EXPECT_CALL(foo_, Bar2(0, 0))...
Expected arg #0: is equal to 0
Actual: 1
Expected: to be called once
Actual: never called - unsatisfied and active
-FILE:#: tried expectation #1
+FILE:#: tried expectation #1: EXPECT_CALL(foo_, Bar2(1, _))...
Expected: all pre-requisites are satisfied
Actual: the following immediate pre-requisites are not satisfied:
FILE:#: pre-requisite #0
@@ -148,13 +148,20 @@ FILE:#: pre-requisite #1
Expected: to be called once
Actual: never called - unsatisfied and active
[ FAILED ] GMockOutputTest.UnsatisfiedPrerequisites
+[ RUN ] GMockOutputTest.UnsatisfiedWith
+FILE:#: Failure
+Actual function call count doesn't match EXPECT_CALL(foo_, Bar2(_, _))...
+ Expected args: are a pair (x, y) where x >= y
+ Expected: to be called once
+ Actual: never called - unsatisfied and active
+[ FAILED ] GMockOutputTest.UnsatisfiedWith
[ RUN ] GMockOutputTest.UnsatisfiedExpectation
FILE:#: Failure
-Actual function call count doesn't match this expectation.
+Actual function call count doesn't match EXPECT_CALL(foo_, Bar2(0, _))...
Expected: to be called twice
Actual: called once - unsatisfied and active
FILE:#: Failure
-Actual function call count doesn't match this expectation.
+Actual function call count doesn't match EXPECT_CALL(foo_, Bar(_, _, _))...
Expected: to be called once
Actual: never called - unsatisfied and active
[ FAILED ] GMockOutputTest.UnsatisfiedExpectation
@@ -166,7 +173,7 @@ Unexpected mock function call - returning default value.
Returns: '\0'
Google Mock tried the following 1 expectation, but it didn't match:
-FILE:#:
+FILE:#: EXPECT_CALL(foo_, Bar(Ref(s), _, Ge(0)))...
Expected arg #0: references the variable @0x# "Hi"
Actual: "Ho" (is located @0x#)
Expected arg #2: is greater than or equal to 0
@@ -182,7 +189,7 @@ Unexpected mock function call - returning default value.
Returns: false
Google Mock tried the following 1 expectation, but it didn't match:
-FILE:#:
+FILE:#: EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))...
Expected args: are a pair (x, y) where x >= y
Actual: don't match
Expected: to be called once
@@ -196,7 +203,7 @@ Unexpected mock function call - returning default value.
Returns: false
Google Mock tried the following 1 expectation, but it didn't match:
-FILE:#:
+FILE:#: EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))...
Expected arg #0: is greater than or equal to 2
Actual: 1
Expected args: are a pair (x, y) where x >= y
@@ -213,7 +220,7 @@ FILE:#:
Returns: false
Google Mock tried the following 1 expectation, but it didn't match:
-FILE:#:
+FILE:#: EXPECT_CALL(foo_, Bar2(2, 2))...
Expected arg #0: is equal to 2
Actual: 1
Expected arg #1: is equal to 2
@@ -228,7 +235,7 @@ FILE:#:
Returns: true
Google Mock tried the following 1 expectation, but it didn't match:
-FILE:#:
+FILE:#: EXPECT_CALL(foo_, Bar2(2, 2))...
Expected arg #0: is equal to 2
Actual: 0
Expected arg #1: is equal to 2
@@ -271,10 +278,10 @@ Stack trace:
[ RUN ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction
GMOCK WARNING:
-FILE:#: Too few actions specified.
+FILE:#: Too few actions specified in EXPECT_CALL(foo_, Bar2(_, _))...
Expected to be called twice, but has only 1 WillOnce().
GMOCK WARNING:
-FILE:#: Actions ran out.
+FILE:#: Actions ran out in EXPECT_CALL(foo_, Bar2(_, _))...
Called 2 times, but only 1 WillOnce() is specified - taking default action specified at:
FILE:#:
Stack trace:
@@ -288,6 +295,7 @@ Stack trace:
[ FAILED ] GMockOutputTest.RetiredExpectation
[ FAILED ] GMockOutputTest.UnsatisfiedPrerequisite
[ FAILED ] GMockOutputTest.UnsatisfiedPrerequisites
+[ FAILED ] GMockOutputTest.UnsatisfiedWith
[ FAILED ] GMockOutputTest.UnsatisfiedExpectation
[ FAILED ] GMockOutputTest.MismatchArguments
[ FAILED ] GMockOutputTest.MismatchWith
diff --git a/testing/gmock/test/gmock_test_utils.py b/testing/gmock/test/gmock_test_utils.py
index 2fda138..fa896a4 100644..100755
--- a/testing/gmock/test/gmock_test_utils.py
+++ b/testing/gmock/test/gmock_test_utils.py
@@ -35,7 +35,20 @@ __author__ = 'wan@google.com (Zhanyong Wan)'
import os
import sys
-import unittest
+
+
+# Determines path to gtest_test_utils and imports it.
+SCRIPT_DIR = os.path.dirname(__file__) or '.'
+
+# isdir resolves symbolic links.
+gtest_tests_util_dir = os.path.join(SCRIPT_DIR, '../gtest/test')
+if os.path.isdir(gtest_tests_util_dir):
+ GTEST_TESTS_UTIL_DIR = gtest_tests_util_dir
+else:
+ GTEST_TESTS_UTIL_DIR = os.path.join(SCRIPT_DIR, '../../gtest/test')
+
+sys.path.append(GTEST_TESTS_UTIL_DIR)
+import gtest_test_utils # pylint: disable-msg=C6204
# Initially maps a flag to its default value. After
@@ -96,6 +109,22 @@ def GetBuildDir():
return os.path.abspath(GetFlag('gmock_build_dir'))
+def GetTestExecutablePath(executable_name):
+ """Returns the absolute path of the test binary given its name.
+
+ The function will print a message and abort the program if the resulting file
+ doesn't exist.
+
+ Args:
+ executable_name: name of the test binary that the test script runs.
+
+ Returns:
+ The absolute path of the test binary.
+ """
+
+ return gtest_test_utils.GetTestExecutablePath(executable_name, GetBuildDir())
+
+
def GetExitStatus(exit_code):
"""Returns the argument to exit(), or -1 if exit() wasn't called.
@@ -116,11 +145,23 @@ def GetExitStatus(exit_code):
return -1
+# Suppresses the "Invalid const name" lint complaint
+# pylint: disable-msg=C6409
+
+# Exposes Subprocess from gtest_test_utils.
+Subprocess = gtest_test_utils.Subprocess
+
+# Exposes TestCase from gtest_test_utils.
+TestCase = gtest_test_utils.TestCase
+
+# pylint: enable-msg=C6409
+
+
def Main():
"""Runs the unit test."""
# We must call _ParseAndStripGMockFlags() before calling
- # unittest.main(). Otherwise the latter will be confused by the
- # --gmock_* flags.
+ # gtest_test_utils.Main(). Otherwise unittest.main it calls will be
+ # confused by the --gmock_* flags.
_ParseAndStripGMockFlags(sys.argv)
- unittest.main()
+ gtest_test_utils.Main()