Commit 32de5f53 authored by zhanyong.wan's avatar zhanyong.wan
Browse files

Fixes a slew of compiler warnings and turns on "warning as error" in the scons build.

parent 284b54d3
...@@ -223,8 +223,9 @@ class GreaterThanMatcher : public MatcherInterface<int> { ...@@ -223,8 +223,9 @@ class GreaterThanMatcher : public MatcherInterface<int> {
*os << "is " << -diff << " less than " << rhs_; *os << "is " << -diff << " less than " << rhs_;
} }
} }
private: private:
const int rhs_; int rhs_;
}; };
Matcher<int> GreaterThan(int n) { Matcher<int> GreaterThan(int n) {
...@@ -411,7 +412,7 @@ TEST(ElementsAreTest, WorksForNestedContainer) { ...@@ -411,7 +412,7 @@ TEST(ElementsAreTest, WorksForNestedContainer) {
}; };
vector<list<char> > nested; 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]))); nested.push_back(list<char>(strings[i], strings[i] + strlen(strings[i])));
} }
...@@ -446,7 +447,12 @@ TEST(ElementsAreTest, WorksWithNativeArrayPassedByReference) { ...@@ -446,7 +447,12 @@ TEST(ElementsAreTest, WorksWithNativeArrayPassedByReference) {
class NativeArrayPassedAsPointerAndSize { class NativeArrayPassedAsPointerAndSize {
public: public:
NativeArrayPassedAsPointerAndSize() {}
MOCK_METHOD2(Helper, void(int* array, int size)); MOCK_METHOD2(Helper, void(int* array, int size));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(NativeArrayPassedAsPointerAndSize);
}; };
TEST(ElementsAreTest, WorksWithNativeArrayPassedAsPointerAndSize) { TEST(ElementsAreTest, WorksWithNativeArrayPassedAsPointerAndSize) {
...@@ -550,7 +556,10 @@ TEST(MatcherMacroTest, Works) { ...@@ -550,7 +556,10 @@ TEST(MatcherMacroTest, Works) {
// Tests that the description string supplied to MATCHER() must be // Tests that the description string supplied to MATCHER() must be
// valid. // valid.
MATCHER(HasBadDescription, "Invalid%") { return true; } MATCHER(HasBadDescription, "Invalid%") {
// Uses arg to suppress "unused parameter" warning.
return arg==arg;
}
TEST(MatcherMacroTest, TEST(MatcherMacroTest,
CreatingMatcherWithBadDescriptionGeneratesNonfatalFailure) { CreatingMatcherWithBadDescriptionGeneratesNonfatalFailure) {
...@@ -560,7 +569,7 @@ TEST(MatcherMacroTest, ...@@ -560,7 +569,7 @@ TEST(MatcherMacroTest,
"use \"%%\" instead of \"%\" to print \"%\"."); "use \"%%\" instead of \"%\" to print \"%\".");
} }
MATCHER(HasGoodDescription, "good") { return true; } MATCHER(HasGoodDescription, "good") { return arg==arg; }
TEST(MatcherMacroTest, AcceptsValidDescription) { TEST(MatcherMacroTest, AcceptsValidDescription) {
const Matcher<int> m = HasGoodDescription(); const Matcher<int> m = HasGoodDescription();
...@@ -642,7 +651,7 @@ TEST(MatcherPMacroTest, ...@@ -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) { TEST(MatcherPMacroTest, AcceptsValidDescription) {
const Matcher<int> m = HasGoodDescription1(5); const Matcher<int> m = HasGoodDescription1(5);
...@@ -709,7 +718,7 @@ TEST(MatcherPnMacroTest, ...@@ -709,7 +718,7 @@ TEST(MatcherPnMacroTest,
MATCHER_P2(HasComplexDescription, foo, bar, MATCHER_P2(HasComplexDescription, foo, bar,
"is as complex as %(foo)s %(bar)s (i.e. %(*)s or %%%(foo)s!)") { "is as complex as %(foo)s %(bar)s (i.e. %(*)s or %%%(foo)s!)") {
return true; return arg==arg;
} }
TEST(MatcherPnMacroTest, AcceptsValidDescription) { TEST(MatcherPnMacroTest, AcceptsValidDescription) {
...@@ -861,7 +870,7 @@ TEST(MatcherPnMacroTest, WorksForDifferentParameterTypes) { ...@@ -861,7 +870,7 @@ TEST(MatcherPnMacroTest, WorksForDifferentParameterTypes) {
MATCHER_P2(EqConcat, prefix, suffix, "") { MATCHER_P2(EqConcat, prefix, suffix, "") {
// The following lines promote the two parameters to desired types. // The following lines promote the two parameters to desired types.
std::string prefix_str(prefix); std::string prefix_str(prefix);
char suffix_char(suffix); char suffix_char = static_cast<char>(suffix);
return arg == prefix_str + suffix_char; return arg == prefix_str + suffix_char;
} }
......
...@@ -819,7 +819,7 @@ TEST(CopyArrayTest, WorksForTwoDimensionalArrays) { ...@@ -819,7 +819,7 @@ TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
TEST(NativeArrayTest, ConstructorFromArrayWorks) { TEST(NativeArrayTest, ConstructorFromArrayWorks) {
const int a[3] = { 0, 1, 2 }; const int a[3] = { 0, 1, 2 };
NativeArray<int> na(a, 3, kReference); NativeArray<int> na(a, 3, kReference);
EXPECT_EQ(3, na.size()); EXPECT_EQ(3U, na.size());
EXPECT_EQ(a, na.begin()); EXPECT_EQ(a, na.begin());
} }
...@@ -849,7 +849,7 @@ TEST(NativeArrayTest, TypeMembersAreCorrect) { ...@@ -849,7 +849,7 @@ TEST(NativeArrayTest, TypeMembersAreCorrect) {
TEST(NativeArrayTest, MethodsWork) { TEST(NativeArrayTest, MethodsWork) {
const int a[3] = { 0, 1, 2 }; const int a[3] = { 0, 1, 2 };
NativeArray<int> na(a, 3, kCopy); NativeArray<int> na(a, 3, kCopy);
ASSERT_EQ(3, na.size()); ASSERT_EQ(3U, na.size());
EXPECT_EQ(3, na.end() - na.begin()); EXPECT_EQ(3, na.end() - na.begin());
NativeArray<int>::const_iterator it = na.begin(); NativeArray<int>::const_iterator it = na.begin();
...@@ -875,7 +875,7 @@ TEST(NativeArrayTest, MethodsWork) { ...@@ -875,7 +875,7 @@ TEST(NativeArrayTest, MethodsWork) {
TEST(NativeArrayTest, WorksForTwoDimensionalArray) { TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
const char a[2][3] = { "hi", "lo" }; const char a[2][3] = { "hi", "lo" };
NativeArray<char[3]> na(a, 2, kReference); NativeArray<char[3]> na(a, 2, kReference);
ASSERT_EQ(2, na.size()); ASSERT_EQ(2U, na.size());
EXPECT_EQ(a, na.begin()); EXPECT_EQ(a, na.begin());
} }
...@@ -910,11 +910,11 @@ TEST(StlContainerViewTest, WorksForStaticNativeArray) { ...@@ -910,11 +910,11 @@ TEST(StlContainerViewTest, WorksForStaticNativeArray) {
int a1[3] = { 0, 1, 2 }; int a1[3] = { 0, 1, 2 };
NativeArray<int> a2 = StlContainerView<int[3]>::ConstReference(a1); NativeArray<int> a2 = StlContainerView<int[3]>::ConstReference(a1);
EXPECT_EQ(3, a2.size()); EXPECT_EQ(3U, a2.size());
EXPECT_EQ(a1, a2.begin()); EXPECT_EQ(a1, a2.begin());
const NativeArray<int> a3 = StlContainerView<int[3]>::Copy(a1); 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(0, a3.begin()[0]);
EXPECT_EQ(1, a3.begin()[1]); EXPECT_EQ(1, a3.begin()[1]);
EXPECT_EQ(2, a3.begin()[2]); EXPECT_EQ(2, a3.begin()[2]);
...@@ -937,12 +937,12 @@ TEST(StlContainerViewTest, WorksForDynamicNativeArray) { ...@@ -937,12 +937,12 @@ TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
const int* const p1 = a1; const int* const p1 = a1;
NativeArray<int> a2 = StlContainerView<tuple<const int*, int> >:: NativeArray<int> a2 = StlContainerView<tuple<const int*, int> >::
ConstReference(make_tuple(p1, 3)); ConstReference(make_tuple(p1, 3));
EXPECT_EQ(3, a2.size()); EXPECT_EQ(3U, a2.size());
EXPECT_EQ(a1, a2.begin()); EXPECT_EQ(a1, a2.begin());
const NativeArray<int> a3 = StlContainerView<tuple<int*, size_t> >:: const NativeArray<int> a3 = StlContainerView<tuple<int*, size_t> >::
Copy(make_tuple(static_cast<int*>(a1), 3)); 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(0, a3.begin()[0]);
EXPECT_EQ(1, a3.begin()[1]); EXPECT_EQ(1, a3.begin()[1]);
EXPECT_EQ(2, a3.begin()[2]); EXPECT_EQ(2, a3.begin()[2]);
......
...@@ -152,8 +152,9 @@ class GreaterThanMatcher : public MatcherInterface<int> { ...@@ -152,8 +152,9 @@ class GreaterThanMatcher : public MatcherInterface<int> {
*os << "is " << -diff << " less than " << rhs_; *os << "is " << -diff << " less than " << rhs_;
} }
} }
private: private:
const int rhs_; int rhs_;
}; };
Matcher<int> GreaterThan(int n) { Matcher<int> GreaterThan(int n) {
...@@ -335,7 +336,7 @@ class IntValue { ...@@ -335,7 +336,7 @@ class IntValue {
public: public:
// An int can be statically (although not implicitly) cast to a // An int can be statically (although not implicitly) cast to a
// IntValue. // IntValue.
explicit IntValue(int value) : value_(value) {} explicit IntValue(int a_value) : value_(a_value) {}
int value() const { return value_; } int value() const { return value_; }
private: private:
...@@ -560,7 +561,7 @@ class Unprintable { ...@@ -560,7 +561,7 @@ class Unprintable {
public: public:
Unprintable() : c_('a') {} Unprintable() : c_('a') {}
bool operator==(const Unprintable& rhs) { return true; } bool operator==(const Unprintable& /* rhs */) { return true; }
private: private:
char c_; char c_;
}; };
...@@ -606,7 +607,7 @@ TEST(TypedEqTest, CanDescribeSelf) { ...@@ -606,7 +607,7 @@ TEST(TypedEqTest, CanDescribeSelf) {
// "undefined referece". // "undefined referece".
template <typename T> template <typename T>
struct Type { struct Type {
static bool IsTypeOf(const T& v) { return true; } static bool IsTypeOf(const T& /* v */) { return true; }
template <typename T2> template <typename T2>
static void IsTypeOf(T2 v); static void IsTypeOf(T2 v);
...@@ -1861,8 +1862,9 @@ class IsGreaterThan { ...@@ -1861,8 +1862,9 @@ class IsGreaterThan {
explicit IsGreaterThan(int threshold) : threshold_(threshold) {} explicit IsGreaterThan(int threshold) : threshold_(threshold) {}
bool operator()(int n) const { return n > threshold_; } bool operator()(int n) const { return n > threshold_; }
private: private:
const int threshold_; int threshold_;
}; };
// For testing Truly(). // For testing Truly().
...@@ -1959,7 +1961,12 @@ TEST(AllArgsTest, WorksForNonTuple) { ...@@ -1959,7 +1961,12 @@ TEST(AllArgsTest, WorksForNonTuple) {
class AllArgsHelper { class AllArgsHelper {
public: public:
AllArgsHelper() {}
MOCK_METHOD2(Helper, int(char x, int y)); MOCK_METHOD2(Helper, int(char x, int y));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(AllArgsHelper);
}; };
TEST(AllArgsTest, WorksInWithClause) { TEST(AllArgsTest, WorksInWithClause) {
...@@ -2384,7 +2391,7 @@ TEST(PointeeTest, CanExplainMatchResult) { ...@@ -2384,7 +2391,7 @@ TEST(PointeeTest, CanExplainMatchResult) {
// An uncopyable class. // An uncopyable class.
class Uncopyable { class Uncopyable {
public: public:
explicit Uncopyable(int value) : value_(value) {} explicit Uncopyable(int a_value) : value_(a_value) {}
int value() const { return value_; } int value() const { return value_; }
private: private:
...@@ -2405,11 +2412,17 @@ struct AStruct { ...@@ -2405,11 +2412,17 @@ struct AStruct {
const double y; // A const field. const double y; // A const field.
Uncopyable z; // An uncopyable field. Uncopyable z; // An uncopyable field.
const char* p; // A pointer field. const char* p; // A pointer field.
private:
GTEST_DISALLOW_ASSIGN_(AStruct);
}; };
// A derived struct for testing Field(). // A derived struct for testing Field().
struct DerivedStruct : public AStruct { struct DerivedStruct : public AStruct {
char ch; char ch;
private:
GTEST_DISALLOW_ASSIGN_(DerivedStruct);
}; };
// Tests that Field(&Foo::field, ...) works when field is non-const. // Tests that Field(&Foo::field, ...) works when field is non-const.
...@@ -2943,7 +2956,7 @@ TEST(ResultOfTest, WorksForReferencingCallables) { ...@@ -2943,7 +2956,7 @@ TEST(ResultOfTest, WorksForReferencingCallables) {
class DivisibleByImpl { class DivisibleByImpl {
public: public:
explicit DivisibleByImpl(int divider) : divider_(divider) {} explicit DivisibleByImpl(int a_divider) : divider_(a_divider) {}
template <typename T> template <typename T>
bool Matches(const T& n) const { bool Matches(const T& n) const {
...@@ -2958,7 +2971,7 @@ class DivisibleByImpl { ...@@ -2958,7 +2971,7 @@ class DivisibleByImpl {
*os << "is not divisible by " << divider_; *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_; } int divider() const { return divider_; }
private: private:
...@@ -3021,7 +3034,7 @@ TEST(ExplainmatcherResultTest, MonomorphicMatcher) { ...@@ -3021,7 +3034,7 @@ TEST(ExplainmatcherResultTest, MonomorphicMatcher) {
class NotCopyable { class NotCopyable {
public: public:
explicit NotCopyable(int value) : value_(value) {} explicit NotCopyable(int a_value) : value_(a_value) {}
int value() const { return value_; } int value() const { return value_; }
......
...@@ -65,6 +65,10 @@ using testing::Unused; ...@@ -65,6 +65,10 @@ using testing::Unused;
using testing::WithArg; using testing::WithArg;
using testing::WithoutArgs; 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. // Sample functions and functors for testing Invoke() and etc.
int Nullary() { return 1; } int Nullary() { return 1; }
...@@ -85,7 +89,7 @@ bool Unary(int x) { return x < 0; } ...@@ -85,7 +89,7 @@ bool Unary(int x) { return x < 0; }
const char* Plus1(const char* s) { return s + 1; } 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"; } bool ByConstRef(const string& s) { return s == "Hi"; }
...@@ -239,13 +243,13 @@ TEST(InvokeTest, Unary) { ...@@ -239,13 +243,13 @@ TEST(InvokeTest, Unary) {
TEST(InvokeTest, Binary) { TEST(InvokeTest, Binary) {
Action<const char*(const char*, short)> a = Invoke(Binary); // NOLINT Action<const char*(const char*, short)> a = Invoke(Binary); // NOLINT
const char* p = "Hello"; 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. // Tests using Invoke() with a ternary function.
TEST(InvokeTest, Ternary) { TEST(InvokeTest, Ternary) {
Action<int(int, char, short)> a = Invoke(Ternary); // NOLINT 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. // Tests using Invoke() with a 4-argument function.
...@@ -340,14 +344,14 @@ TEST(InvokeTest, MethodWithUnusedParameters) { ...@@ -340,14 +344,14 @@ TEST(InvokeTest, MethodWithUnusedParameters) {
// Tests using Invoke() with a functor. // Tests using Invoke() with a functor.
TEST(InvokeTest, Functor) { TEST(InvokeTest, Functor) {
Action<int(short, char)> a = Invoke(plus<short>()); // NOLINT Action<long(long, int)> a = Invoke(plus<long>()); // NOLINT
EXPECT_EQ(3, a.Perform(make_tuple(1, 2))); EXPECT_EQ(3L, a.Perform(make_tuple(1, 2)));
} }
// Tests using Invoke(f) as an action of a compatible type. // Tests using Invoke(f) as an action of a compatible type.
TEST(InvokeTest, FunctionWithCompatibleType) { TEST(InvokeTest, FunctionWithCompatibleType) {
Action<long(int, short, char, bool)> a = Invoke(SumOf4); // NOLINT 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. // Tests using Invoke() with an object pointer and a method pointer.
...@@ -378,7 +382,7 @@ TEST(InvokeMethodTest, Binary) { ...@@ -378,7 +382,7 @@ TEST(InvokeMethodTest, Binary) {
TEST(InvokeMethodTest, Ternary) { TEST(InvokeMethodTest, Ternary) {
Foo foo; Foo foo;
Action<int(int, bool, char)> a = Invoke(&foo, &Foo::Ternary); // NOLINT 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. // Tests using Invoke() with a 4-argument method.
...@@ -457,7 +461,7 @@ TEST(InvokeMethodTest, MethodWithCompatibleType) { ...@@ -457,7 +461,7 @@ TEST(InvokeMethodTest, MethodWithCompatibleType) {
Foo foo; Foo foo;
Action<long(int, short, char, bool)> a = // NOLINT Action<long(int, short, char, bool)> a = // NOLINT
Invoke(&foo, &Foo::SumOf4); 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. // Tests using WithoutArgs with an action that takes no argument.
......
...@@ -40,7 +40,12 @@ ...@@ -40,7 +40,12 @@
// clash with ::testing::Mock. // clash with ::testing::Mock.
class Mock { class Mock {
public: public:
Mock() {}
MOCK_METHOD0(DoThis, void()); MOCK_METHOD0(DoThis, void());
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(Mock);
}; };
namespace testing { namespace testing {
...@@ -64,10 +69,14 @@ class Foo { ...@@ -64,10 +69,14 @@ class Foo {
class MockFoo : public Foo { class MockFoo : public Foo {
public: public:
MockFoo() {}
void Delete() { delete this; } void Delete() { delete this; }
MOCK_METHOD0(DoThis, void()); MOCK_METHOD0(DoThis, void());
MOCK_METHOD1(DoThat, int(bool flag)); MOCK_METHOD1(DoThat, int(bool flag));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
}; };
class MockBar { class MockBar {
...@@ -89,6 +98,8 @@ class MockBar { ...@@ -89,6 +98,8 @@ class MockBar {
private: private:
string str_; string str_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar);
}; };
// TODO(wan@google.com): find a way to re-enable these tests. // TODO(wan@google.com): find a way to re-enable these tests.
......
...@@ -85,7 +85,7 @@ class Castable { ...@@ -85,7 +85,7 @@ class Castable {
} }
private: private:
bool* const converted_; bool* converted_;
}; };
TEST(ImplicitCastTest, CanUseNonConstCastOperator) { TEST(ImplicitCastTest, CanUseNonConstCastOperator) {
...@@ -104,7 +104,7 @@ class ConstCastable { ...@@ -104,7 +104,7 @@ class ConstCastable {
} }
private: private:
bool* const converted_; bool* converted_;
}; };
TEST(ImplicitCastTest, CanUseConstCastOperatorOnConstValues) { TEST(ImplicitCastTest, CanUseConstCastOperatorOnConstValues) {
...@@ -128,8 +128,8 @@ class ConstAndNonConstCastable { ...@@ -128,8 +128,8 @@ class ConstAndNonConstCastable {
} }
private: private:
bool* const converted_; bool* converted_;
bool* const const_converted_; bool* const_converted_;
}; };
TEST(ImplicitCastTest, CanSelectBetweenConstAndNonConstCasrAppropriately) { TEST(ImplicitCastTest, CanSelectBetweenConstAndNonConstCasrAppropriately) {
......
...@@ -77,7 +77,7 @@ class StreamableInGlobal { ...@@ -77,7 +77,7 @@ class StreamableInGlobal {
virtual ~StreamableInGlobal() {} virtual ~StreamableInGlobal() {}
}; };
inline void operator<<(::std::ostream& os, const StreamableInGlobal& x) { inline void operator<<(::std::ostream& os, const StreamableInGlobal& /* x */) {
os << "StreamableInGlobal"; os << "StreamableInGlobal";
} }
...@@ -107,7 +107,7 @@ void PrintTo(const PrintableViaPrintTo& x, ::std::ostream* os) { ...@@ -107,7 +107,7 @@ void PrintTo(const PrintableViaPrintTo& x, ::std::ostream* os) {
template <typename T> template <typename T>
class PrintableViaPrintToTemplate { class PrintableViaPrintToTemplate {
public: public:
explicit PrintableViaPrintToTemplate(const T& value) : value_(value) {} explicit PrintableViaPrintToTemplate(const T& a_value) : value_(a_value) {}
const T& value() const { return value_; } const T& value() const { return value_; }
private: private:
...@@ -440,7 +440,7 @@ TEST(PrintPointerToPointerTest, IntPointerPointer) { ...@@ -440,7 +440,7 @@ TEST(PrintPointerToPointerTest, IntPointerPointer) {
// Tests printing (non-member) function pointers. // Tests printing (non-member) function pointers.
void MyFunction(int n) {} void MyFunction(int /* n */) {}
TEST(PrintPointerTest, NonMemberFunctionPointer) { TEST(PrintPointerTest, NonMemberFunctionPointer) {
// We cannot directly cast &MyFunction to const void* because the // We cannot directly cast &MyFunction to const void* because the
...@@ -464,7 +464,7 @@ struct Foo { ...@@ -464,7 +464,7 @@ struct Foo {
public: public:
virtual ~Foo() {} virtual ~Foo() {}
int MyMethod(char x) { return x + 1; } int MyMethod(char x) { return x + 1; }
virtual char MyVirtualMethod(int n) { return 'a'; } virtual char MyVirtualMethod(int /* n */) { return 'a'; }
int value; int value;
}; };
...@@ -603,7 +603,7 @@ class AllowsGenericStreaming {}; ...@@ -603,7 +603,7 @@ class AllowsGenericStreaming {};
template <typename Char, typename CharTraits> template <typename Char, typename CharTraits>
std::basic_ostream<Char, CharTraits>& operator<<( std::basic_ostream<Char, CharTraits>& operator<<(
std::basic_ostream<Char, CharTraits>& os, std::basic_ostream<Char, CharTraits>& os,
const AllowsGenericStreaming& a) { const AllowsGenericStreaming& /* a */) {
return os << "AllowsGenericStreaming"; return os << "AllowsGenericStreaming";
} }
...@@ -620,7 +620,7 @@ class AllowsGenericStreamingTemplate {}; ...@@ -620,7 +620,7 @@ class AllowsGenericStreamingTemplate {};
template <typename Char, typename CharTraits, typename T> template <typename Char, typename CharTraits, typename T>
std::basic_ostream<Char, CharTraits>& operator<<( std::basic_ostream<Char, CharTraits>& operator<<(
std::basic_ostream<Char, CharTraits>& os, std::basic_ostream<Char, CharTraits>& os,
const AllowsGenericStreamingTemplate<T>& a) { const AllowsGenericStreamingTemplate<T>& /* a */) {
return os << "AllowsGenericStreamingTemplate"; return os << "AllowsGenericStreamingTemplate";
} }
...@@ -641,7 +641,7 @@ class AllowsGenericStreamingAndImplicitConversionTemplate { ...@@ -641,7 +641,7 @@ class AllowsGenericStreamingAndImplicitConversionTemplate {
template <typename Char, typename CharTraits, typename T> template <typename Char, typename CharTraits, typename T>
std::basic_ostream<Char, CharTraits>& operator<<( std::basic_ostream<Char, CharTraits>& operator<<(
std::basic_ostream<Char, CharTraits>& os, std::basic_ostream<Char, CharTraits>& os,
const AllowsGenericStreamingAndImplicitConversionTemplate<T>& a) { const AllowsGenericStreamingAndImplicitConversionTemplate<T>& /* a */) {
return os << "AllowsGenericStreamingAndImplicitConversionTemplate"; return os << "AllowsGenericStreamingAndImplicitConversionTemplate";
} }
......
...@@ -97,16 +97,26 @@ class Result {}; ...@@ -97,16 +97,26 @@ class Result {};
class MockA { class MockA {
public: public:
MockA() {}
MOCK_METHOD1(DoA, void(int n)); // NOLINT MOCK_METHOD1(DoA, void(int n)); // NOLINT
MOCK_METHOD1(ReturnResult, Result(int n)); // NOLINT MOCK_METHOD1(ReturnResult, Result(int n)); // NOLINT
MOCK_METHOD2(Binary, bool(int x, int y)); // NOLINT MOCK_METHOD2(Binary, bool(int x, int y)); // NOLINT
MOCK_METHOD2(ReturnInt, int(int x, int y)); // NOLINT MOCK_METHOD2(ReturnInt, int(int x, int y)); // NOLINT
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockA);
}; };
class MockB { class MockB {
public: public:
MockB() {}
MOCK_CONST_METHOD0(DoB, int()); // NOLINT MOCK_CONST_METHOD0(DoB, int()); // NOLINT
MOCK_METHOD1(DoB, int(int n)); // 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 // Tests that EXPECT_CALL and ON_CALL compile in a presence of macro
...@@ -123,7 +133,12 @@ class CC { ...@@ -123,7 +133,12 @@ class CC {
}; };
class MockCC : public CC { class MockCC : public CC {
public: public:
MockCC() {}
MOCK_METHOD0(Method, int()); MOCK_METHOD0(Method, int());
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockCC);
}; };
// Tests that a method with expanded name compiles. // Tests that a method with expanded name compiles.
...@@ -1617,8 +1632,19 @@ TEST(DeletingMockEarlyTest, Success2) { ...@@ -1617,8 +1632,19 @@ TEST(DeletingMockEarlyTest, Success2) {
// Tests that it's OK to delete a mock object itself in its action. // 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; } ACTION_P(Delete, ptr) { delete ptr; }
#ifdef _MSC_VER
#pragma warning(pop)
#endif
TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) { TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) {
MockA* const a = new MockA; MockA* const a = new MockA;
EXPECT_CALL(*a, DoA(_)).WillOnce(Delete(a)); EXPECT_CALL(*a, DoA(_)).WillOnce(Delete(a));
...@@ -1691,7 +1717,9 @@ class EvenNumberCardinality : public CardinalityInterface { ...@@ -1691,7 +1717,9 @@ class EvenNumberCardinality : public CardinalityInterface {
} }
// Returns true iff call_count calls will saturate this cardinality. // 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. // Describes self to an ostream.
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
...@@ -1740,9 +1768,14 @@ struct Unprintable { ...@@ -1740,9 +1768,14 @@ struct Unprintable {
class MockC { class MockC {
public: public:
MockC() {}
MOCK_METHOD6(VoidMethod, void(bool cond, int n, string s, void* p, MOCK_METHOD6(VoidMethod, void(bool cond, int n, string s, void* p,
const Printable& x, Unprintable y)); const Printable& x, Unprintable y));
MOCK_METHOD0(NonVoidMethod, int()); // NOLINT MOCK_METHOD0(NonVoidMethod, int()); // NOLINT
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockC);
}; };
// TODO(wan@google.com): find a way to re-enable these tests. // TODO(wan@google.com): find a way to re-enable these tests.
...@@ -1935,7 +1968,12 @@ void PrintTo(PrintMeNot /* dummy */, ::std::ostream* /* os */) { ...@@ -1935,7 +1968,12 @@ void PrintTo(PrintMeNot /* dummy */, ::std::ostream* /* os */) {
class LogTestHelper { class LogTestHelper {
public: public:
LogTestHelper() {}
MOCK_METHOD1(Foo, PrintMeNot(PrintMeNot)); MOCK_METHOD1(Foo, PrintMeNot(PrintMeNot));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(LogTestHelper);
}; };
class GMockLogTest : public ::testing::Test { class GMockLogTest : public ::testing::Test {
......
...@@ -48,7 +48,12 @@ class FooInterface { ...@@ -48,7 +48,12 @@ class FooInterface {
class MockFoo : public FooInterface { class MockFoo : public FooInterface {
public: public:
MockFoo() {}
MOCK_METHOD0(DoThis, void()); MOCK_METHOD0(DoThis, void());
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
}; };
TEST(LeakTest, LeakedMockWithExpectCallCausesFailureWhenLeakCheckingIsEnabled) { TEST(LeakTest, LeakedMockWithExpectCallCausesFailureWhenLeakCheckingIsEnabled) {
......
...@@ -206,6 +206,8 @@ class Interface { ...@@ -206,6 +206,8 @@ class Interface {
class Mock: public Interface { class Mock: public Interface {
public: public:
Mock() {}
MOCK_METHOD1(VoidFromString, void(char* str)); MOCK_METHOD1(VoidFromString, void(char* str));
MOCK_METHOD1(StringFromString, char*(char* str)); MOCK_METHOD1(StringFromString, char*(char* str));
MOCK_METHOD1(IntFromString, int(char* str)); MOCK_METHOD1(IntFromString, int(char* str));
...@@ -215,6 +217,9 @@ class Mock: public Interface { ...@@ -215,6 +217,9 @@ class Mock: public Interface {
MOCK_METHOD1(VoidFromFloat, void(float n)); MOCK_METHOD1(VoidFromFloat, void(float n));
MOCK_METHOD1(VoidFromDouble, void(double n)); MOCK_METHOD1(VoidFromDouble, void(double n));
MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v)); MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(Mock);
}; };
class InvokeHelper { class InvokeHelper {
...@@ -229,7 +234,7 @@ class InvokeHelper { ...@@ -229,7 +234,7 @@ class InvokeHelper {
class FieldHelper { class FieldHelper {
public: public:
FieldHelper(int field) : field_(field) {} FieldHelper(int a_field) : field_(a_field) {}
int field() const { return field_; } int field() const { return field_; }
int field_; // NOLINT -- need external access to field_ to test int field_; // NOLINT -- need external access to field_ to test
// the Field matcher. // the Field matcher.
...@@ -410,6 +415,16 @@ TEST(LinkTest, TestThrow) { ...@@ -410,6 +415,16 @@ TEST(LinkTest, TestThrow) {
} }
#endif // GTEST_HAS_EXCEPTIONS #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. // Tests the linkage of actions created using ACTION macro.
namespace { namespace {
ACTION(Return1) { return 1; } ACTION(Return1) { return 1; }
...@@ -441,6 +456,10 @@ ACTION_P2(ReturnEqualsEitherOf, first, second) { ...@@ -441,6 +456,10 @@ ACTION_P2(ReturnEqualsEitherOf, first, second) {
} }
} }
#ifdef _MSC_VER
#pragma warning(pop)
#endif
TEST(LinkTest, TestActionP2Macro) { TEST(LinkTest, TestActionP2Macro) {
Mock mock; Mock mock;
char ch = 'x'; char ch = 'x';
......
...@@ -49,9 +49,14 @@ using testing::Sequence; ...@@ -49,9 +49,14 @@ using testing::Sequence;
class MockFoo { class MockFoo {
public: public:
MockFoo() {}
MOCK_METHOD3(Bar, char(const std::string& s, int i, double x)); MOCK_METHOD3(Bar, char(const std::string& s, int i, double x));
MOCK_METHOD2(Bar2, bool(int x, int y)); MOCK_METHOD2(Bar2, bool(int x, int y));
MOCK_METHOD2(Bar3, void(int x, int y)); MOCK_METHOD2(Bar3, void(int x, int y));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
}; };
class GMockOutputTest : public testing::Test { class GMockOutputTest : public testing::Test {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment