aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorjgm <jgm@google.com>2012-04-10 16:02:11 +0000
committerjgm <jgm@google.com>2012-04-10 16:02:11 +0000
commit79a367eb217fcd47e2beaf8c0f87fe6d5926f739 (patch)
tree148e73f4c3b6354f900cae94be5e9495e04d7efa /test
parent9bcb5f9146db42bc38b6bb744fb0cf518a0205be (diff)
downloadgoogletest-79a367eb217fcd47e2beaf8c0f87fe6d5926f739.tar.gz
googletest-79a367eb217fcd47e2beaf8c0f87fe6d5926f739.tar.bz2
googletest-79a367eb217fcd47e2beaf8c0f87fe6d5926f739.zip
Reduced template instantiation depth for the AllOf and AnyOf matchers. Also some formatting changes.
Diffstat (limited to 'test')
-rw-r--r--test/gmock-actions_test.cc13
-rw-r--r--test/gmock-generated-function-mockers_test.cc10
-rw-r--r--test/gmock-generated-matchers_test.cc14
-rw-r--r--test/gmock-matchers_test.cc92
-rw-r--r--test/gmock-more-actions_test.cc1
-rw-r--r--test/gmock_link_test.h16
6 files changed, 104 insertions, 42 deletions
diff --git a/test/gmock-actions_test.cc b/test/gmock-actions_test.cc
index b7803fe9..fd87c74c 100644
--- a/test/gmock-actions_test.cc
+++ b/test/gmock-actions_test.cc
@@ -518,7 +518,7 @@ TEST(ReturnTest, IsCovariant) {
// gmock-actions.h for more information.
class FromType {
public:
- FromType(bool* is_converted) : converted_(is_converted) {}
+ explicit FromType(bool* is_converted) : converted_(is_converted) {}
bool* converted() const { return converted_; }
private:
@@ -529,7 +529,8 @@ class FromType {
class ToType {
public:
- ToType(const FromType& x) { *x.converted() = true; }
+ // Must allow implicit conversion due to use in ImplicitCast_<T>.
+ ToType(const FromType& x) { *x.converted() = true; } // NOLINT
};
TEST(ReturnTest, ConvertsArgumentWhenConverted) {
@@ -541,7 +542,7 @@ TEST(ReturnTest, ConvertsArgumentWhenConverted) {
converted = false;
action.Perform(tuple<>());
EXPECT_FALSE(converted) << "Action must NOT convert its argument "
- << "when performed." ;
+ << "when performed.";
}
class DestinationType {};
@@ -1226,7 +1227,8 @@ TEST(ByRefTest, IsCopyable) {
const std::string s1 = "Hi";
const std::string s2 = "Hello";
- ::testing::internal::ReferenceWrapper<const std::string> ref_wrapper = ByRef(s1);
+ ::testing::internal::ReferenceWrapper<const std::string> ref_wrapper =
+ ByRef(s1);
const std::string& r1 = ref_wrapper;
EXPECT_EQ(&s1, &r1);
@@ -1235,7 +1237,8 @@ TEST(ByRefTest, IsCopyable) {
const std::string& r2 = ref_wrapper;
EXPECT_EQ(&s2, &r2);
- ::testing::internal::ReferenceWrapper<const std::string> ref_wrapper1 = ByRef(s1);
+ ::testing::internal::ReferenceWrapper<const std::string> ref_wrapper1 =
+ ByRef(s1);
// Copies ref_wrapper1 to ref_wrapper.
ref_wrapper = ref_wrapper1;
const std::string& r3 = ref_wrapper;
diff --git a/test/gmock-generated-function-mockers_test.cc b/test/gmock-generated-function-mockers_test.cc
index 0d90ded7..2087f991 100644
--- a/test/gmock-generated-function-mockers_test.cc
+++ b/test/gmock-generated-function-mockers_test.cc
@@ -35,11 +35,6 @@
#include "gmock/gmock-generated-function-mockers.h"
-#include <map>
-#include <string>
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-
#if GTEST_OS_WINDOWS
// MSDN says the header file to be included for STDMETHOD is BaseTyps.h but
// we are getting compiler errors if we use basetyps.h, hence including
@@ -47,6 +42,11 @@
# include <objbase.h>
#endif // GTEST_OS_WINDOWS
+#include <map>
+#include <string>
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
// There is a bug in MSVC (fixed in VS 2008) that prevents creating a
// mock for a function with const arguments, so we don't test such
// cases for MSVC versions older than 2008.
diff --git a/test/gmock-generated-matchers_test.cc b/test/gmock-generated-matchers_test.cc
index 819f1a83..b35c4505 100644
--- a/test/gmock-generated-matchers_test.cc
+++ b/test/gmock-generated-matchers_test.cc
@@ -1091,6 +1091,20 @@ TEST(ContainsTest, WorksForTwoDimensionalNativeArray) {
EXPECT_THAT(a, Contains(Not(Contains(5))));
}
+TEST(AllOfTest, HugeMatcher) {
+ // Verify that using AllOf with many arguments doesn't cause
+ // the compiler to exceed template instantiation depth limit.
+ EXPECT_THAT(0, testing::AllOf(_, _, _, _, _, _, _, _, _,
+ testing::AllOf(_, _, _, _, _, _, _, _, _, _)));
+}
+
+TEST(AnyOfTest, HugeMatcher) {
+ // Verify that using AnyOf with many arguments doesn't cause
+ // the compiler to exceed template instantiation depth limit.
+ EXPECT_THAT(0, testing::AnyOf(_, _, _, _, _, _, _, _, _,
+ testing::AnyOf(_, _, _, _, _, _, _, _, _, _)));
+}
+
namespace adl_test {
// Verifies that the implementation of ::testing::AllOf and ::testing::AnyOf
diff --git a/test/gmock-matchers_test.cc b/test/gmock-matchers_test.cc
index c4ed96ba..35d59fa8 100644
--- a/test/gmock-matchers_test.cc
+++ b/test/gmock-matchers_test.cc
@@ -545,6 +545,37 @@ TEST(MatcherCastTest, FromSameType) {
EXPECT_FALSE(m2.Matches(1));
}
+// Implicitly convertible form any type.
+struct ConvertibleFromAny {
+ ConvertibleFromAny(int a_value) : value(a_value) {}
+ template <typename T>
+ ConvertibleFromAny(const T& a_value) : value(-1) {
+ ADD_FAILURE() << "Conversion constructor called";
+ }
+ int value;
+};
+
+bool operator==(const ConvertibleFromAny& a, const ConvertibleFromAny& b) {
+ return a.value == b.value;
+}
+
+ostream& operator<<(ostream& os, const ConvertibleFromAny& a) {
+ return os << a.value;
+}
+
+TEST(MatcherCastTest, ConversionConstructorIsUsed) {
+ Matcher<ConvertibleFromAny> m = MatcherCast<ConvertibleFromAny>(1);
+ EXPECT_TRUE(m.Matches(ConvertibleFromAny(1)));
+ EXPECT_FALSE(m.Matches(ConvertibleFromAny(2)));
+}
+
+TEST(MatcherCastTest, FromConvertibleFromAny) {
+ Matcher<ConvertibleFromAny> m =
+ MatcherCast<ConvertibleFromAny>(Eq(ConvertibleFromAny(1)));
+ EXPECT_TRUE(m.Matches(ConvertibleFromAny(1)));
+ EXPECT_FALSE(m.Matches(ConvertibleFromAny(2)));
+}
+
class Base {};
class Derived : public Base {};
@@ -620,6 +651,19 @@ TEST(SafeMatcherCastTest, FromSameType) {
EXPECT_FALSE(m2.Matches(1));
}
+TEST(SafeMatcherCastTest, ConversionConstructorIsUsed) {
+ Matcher<ConvertibleFromAny> m = SafeMatcherCast<ConvertibleFromAny>(1);
+ EXPECT_TRUE(m.Matches(ConvertibleFromAny(1)));
+ EXPECT_FALSE(m.Matches(ConvertibleFromAny(2)));
+}
+
+TEST(SafeMatcherCastTest, FromConvertibleFromAny) {
+ Matcher<ConvertibleFromAny> m =
+ SafeMatcherCast<ConvertibleFromAny>(Eq(ConvertibleFromAny(1)));
+ EXPECT_TRUE(m.Matches(ConvertibleFromAny(1)));
+ EXPECT_FALSE(m.Matches(ConvertibleFromAny(2)));
+}
+
// Tests that A<T>() matches any value of type T.
TEST(ATest, MatchesAnyValue) {
// Tests a matcher for a value type.
@@ -1940,19 +1984,19 @@ TEST(AllOfTest, CanDescribeSelf) {
m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3));
- EXPECT_EQ("(is > 0) and "
- "((isn't equal to 1) and "
+ EXPECT_EQ("((is > 0) and "
+ "(isn't equal to 1)) and "
"((isn't equal to 2) and "
- "(isn't equal to 3)))",
+ "(isn't equal to 3))",
Describe(m));
m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7));
- EXPECT_EQ("(is >= 0) and "
- "((is < 10) and "
+ EXPECT_EQ("((is >= 0) and "
+ "(is < 10)) and "
"((isn't equal to 3) and "
"((isn't equal to 5) and "
- "(isn't equal to 7))))",
+ "(isn't equal to 7)))",
Describe(m));
}
@@ -1972,19 +2016,19 @@ TEST(AllOfTest, CanDescribeNegation) {
m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3));
- EXPECT_EQ("(isn't > 0) or "
- "((is equal to 1) or "
+ EXPECT_EQ("((isn't > 0) or "
+ "(is equal to 1)) or "
"((is equal to 2) or "
- "(is equal to 3)))",
+ "(is equal to 3))",
DescribeNegation(m));
m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7));
- EXPECT_EQ("(isn't >= 0) or "
- "((isn't < 10) or "
+ EXPECT_EQ("((isn't >= 0) or "
+ "(isn't < 10)) or "
"((is equal to 3) or "
"((is equal to 5) or "
- "(is equal to 7))))",
+ "(is equal to 7)))",
DescribeNegation(m));
}
@@ -2112,18 +2156,18 @@ TEST(AnyOfTest, CanDescribeSelf) {
Describe(m));
m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3));
- EXPECT_EQ("(is < 0) or "
- "((is equal to 1) or "
+ EXPECT_EQ("((is < 0) or "
+ "(is equal to 1)) or "
"((is equal to 2) or "
- "(is equal to 3)))",
+ "(is equal to 3))",
Describe(m));
m = AnyOf(Le(0), Gt(10), 3, 5, 7);
- EXPECT_EQ("(is <= 0) or "
- "((is > 10) or "
+ EXPECT_EQ("((is <= 0) or "
+ "(is > 10)) or "
"((is equal to 3) or "
"((is equal to 5) or "
- "(is equal to 7))))",
+ "(is equal to 7)))",
Describe(m));
}
@@ -2140,18 +2184,18 @@ TEST(AnyOfTest, CanDescribeNegation) {
DescribeNegation(m));
m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3));
- EXPECT_EQ("(isn't < 0) and "
- "((isn't equal to 1) and "
+ EXPECT_EQ("((isn't < 0) and "
+ "(isn't equal to 1)) and "
"((isn't equal to 2) and "
- "(isn't equal to 3)))",
+ "(isn't equal to 3))",
DescribeNegation(m));
m = AnyOf(Le(0), Gt(10), 3, 5, 7);
- EXPECT_EQ("(isn't <= 0) and "
- "((isn't > 10) and "
+ EXPECT_EQ("((isn't <= 0) and "
+ "(isn't > 10)) and "
"((isn't equal to 3) and "
"((isn't equal to 5) and "
- "(isn't equal to 7))))",
+ "(isn't equal to 7)))",
DescribeNegation(m));
}
diff --git a/test/gmock-more-actions_test.cc b/test/gmock-more-actions_test.cc
index 43ff55d8..9fa9e2ec 100644
--- a/test/gmock-more-actions_test.cc
+++ b/test/gmock-more-actions_test.cc
@@ -225,6 +225,7 @@ class Foo {
const char* s10) {
return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
}
+
private:
int value_;
};
diff --git a/test/gmock_link_test.h b/test/gmock_link_test.h
index ab5af4b4..1f55f5bd 100644
--- a/test/gmock_link_test.h
+++ b/test/gmock_link_test.h
@@ -195,8 +195,8 @@ class Interface {
virtual char* StringFromString(char* str) = 0;
virtual int IntFromString(char* str) = 0;
virtual int& IntRefFromString(char* str) = 0;
- virtual void VoidFromFunc(void(*)(char*)) = 0;
- virtual void VoidFromIntRef(int& n) = 0;
+ virtual void VoidFromFunc(void(*func)(char* str)) = 0;
+ virtual void VoidFromIntRef(int& n) = 0; // NOLINT
virtual void VoidFromFloat(float n) = 0;
virtual void VoidFromDouble(double n) = 0;
virtual void VoidFromVector(const std::vector<int>& v) = 0;
@@ -211,7 +211,7 @@ class Mock: public Interface {
MOCK_METHOD1(IntFromString, int(char* str));
MOCK_METHOD1(IntRefFromString, int&(char* str));
MOCK_METHOD1(VoidFromFunc, void(void(*func)(char* str)));
- MOCK_METHOD1(VoidFromIntRef, void(int& n));
+ MOCK_METHOD1(VoidFromIntRef, void(int& n)); // NOLINT
MOCK_METHOD1(VoidFromFloat, void(float n));
MOCK_METHOD1(VoidFromDouble, void(double n));
MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v));
@@ -224,15 +224,15 @@ class InvokeHelper {
public:
static void StaticVoidFromVoid() {}
void VoidFromVoid() {}
- static void StaticVoidFromString(char*) {}
- void VoidFromString(char*) {}
- static int StaticIntFromString(char*) { return 1; }
- static bool StaticBoolFromString(const char*) { return true; }
+ static void StaticVoidFromString(char* /* str */) {}
+ void VoidFromString(char* /* str */) {}
+ static int StaticIntFromString(char* /* str */) { return 1; }
+ static bool StaticBoolFromString(const char* /* str */) { return true; }
};
class FieldHelper {
public:
- FieldHelper(int a_field) : field_(a_field) {}
+ explicit 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.