Moves the universal printer from gmock to gtest (by Vlad Losev).

This commit is contained in:
zhanyong.wan
2010-05-10 17:14:29 +00:00
parent 76c1c612e2
commit 02f7106557
22 changed files with 66 additions and 3092 deletions

View File

@@ -96,102 +96,6 @@ TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
ConvertIdentifierNameToWords("_Chapter11Section_1_"));
}
// Tests that CompileAssertTypesEqual compiles when the type arguments are
// equal.
TEST(CompileAssertTypesEqual, CompilesWhenTypesAreEqual) {
CompileAssertTypesEqual<void, void>();
CompileAssertTypesEqual<int*, int*>();
}
// Tests that RemoveReference does not affect non-reference types.
TEST(RemoveReferenceTest, DoesNotAffectNonReferenceType) {
CompileAssertTypesEqual<int, RemoveReference<int>::type>();
CompileAssertTypesEqual<const char, RemoveReference<const char>::type>();
}
// Tests that RemoveReference removes reference from reference types.
TEST(RemoveReferenceTest, RemovesReference) {
CompileAssertTypesEqual<int, RemoveReference<int&>::type>();
CompileAssertTypesEqual<const char, RemoveReference<const char&>::type>();
}
// Tests GMOCK_REMOVE_REFERENCE_.
template <typename T1, typename T2>
void TestGMockRemoveReference() {
CompileAssertTypesEqual<T1, GMOCK_REMOVE_REFERENCE_(T2)>();
}
TEST(RemoveReferenceTest, MacroVersion) {
TestGMockRemoveReference<int, int>();
TestGMockRemoveReference<const char, const char&>();
}
// Tests that RemoveConst does not affect non-const types.
TEST(RemoveConstTest, DoesNotAffectNonConstType) {
CompileAssertTypesEqual<int, RemoveConst<int>::type>();
CompileAssertTypesEqual<char&, RemoveConst<char&>::type>();
}
// Tests that RemoveConst removes const from const types.
TEST(RemoveConstTest, RemovesConst) {
CompileAssertTypesEqual<int, RemoveConst<const int>::type>();
CompileAssertTypesEqual<char[2], RemoveConst<const char[2]>::type>();
CompileAssertTypesEqual<char[2][3], RemoveConst<const char[2][3]>::type>();
}
// Tests GMOCK_REMOVE_CONST_.
template <typename T1, typename T2>
void TestGMockRemoveConst() {
CompileAssertTypesEqual<T1, GMOCK_REMOVE_CONST_(T2)>();
}
TEST(RemoveConstTest, MacroVersion) {
TestGMockRemoveConst<int, int>();
TestGMockRemoveConst<double&, double&>();
TestGMockRemoveConst<char, const char>();
}
// Tests that AddReference does not affect reference types.
TEST(AddReferenceTest, DoesNotAffectReferenceType) {
CompileAssertTypesEqual<int&, AddReference<int&>::type>();
CompileAssertTypesEqual<const char&, AddReference<const char&>::type>();
}
// Tests that AddReference adds reference to non-reference types.
TEST(AddReferenceTest, AddsReference) {
CompileAssertTypesEqual<int&, AddReference<int>::type>();
CompileAssertTypesEqual<const char&, AddReference<const char>::type>();
}
// Tests GMOCK_ADD_REFERENCE_.
template <typename T1, typename T2>
void TestGMockAddReference() {
CompileAssertTypesEqual<T1, GMOCK_ADD_REFERENCE_(T2)>();
}
TEST(AddReferenceTest, MacroVersion) {
TestGMockAddReference<int&, int>();
TestGMockAddReference<const char&, const char&>();
}
// Tests GMOCK_REFERENCE_TO_CONST_.
template <typename T1, typename T2>
void TestGMockReferenceToConst() {
CompileAssertTypesEqual<T1, GMOCK_REFERENCE_TO_CONST_(T2)>();
}
TEST(GMockReferenceToConstTest, Works) {
TestGMockReferenceToConst<const char&, char>();
TestGMockReferenceToConst<const int&, const int>();
TestGMockReferenceToConst<const double&, double>();
TestGMockReferenceToConst<const string&, const string&>();
}
TEST(PointeeOfTest, WorksForSmartPointers) {
CompileAssertTypesEqual<const char,
PointeeOf<internal::linked_ptr<const char> >::type>();
@@ -217,38 +121,11 @@ TEST(GetRawPointerTest, WorksForRawPointers) {
EXPECT_EQ(&n, GetRawPointer(&n));
}
// Tests KindOf<T>.
class Base {};
class Derived : public Base {};
// Tests that ImplicitlyConvertible<T1, T2>::value is a compile-time constant.
TEST(ImplicitlyConvertibleTest, ValueIsCompileTimeConstant) {
GMOCK_COMPILE_ASSERT_((ImplicitlyConvertible<int, int>::value), const_true);
GMOCK_COMPILE_ASSERT_((!ImplicitlyConvertible<void*, int*>::value),
const_false);
}
// Tests that ImplicitlyConvertible<T1, T2>::value is true when T1 can
// be implicitly converted to T2.
TEST(ImplicitlyConvertibleTest, ValueIsTrueWhenConvertible) {
EXPECT_TRUE((ImplicitlyConvertible<int, double>::value));
EXPECT_TRUE((ImplicitlyConvertible<double, int>::value));
EXPECT_TRUE((ImplicitlyConvertible<int*, void*>::value));
EXPECT_TRUE((ImplicitlyConvertible<int*, const int*>::value));
EXPECT_TRUE((ImplicitlyConvertible<Derived&, const Base&>::value));
EXPECT_TRUE((ImplicitlyConvertible<const Base, Base>::value));
}
// Tests that ImplicitlyConvertible<T1, T2>::value is false when T1
// cannot be implicitly converted to T2.
TEST(ImplicitlyConvertibleTest, ValueIsFalseWhenNotConvertible) {
EXPECT_FALSE((ImplicitlyConvertible<double, int*>::value));
EXPECT_FALSE((ImplicitlyConvertible<void*, int*>::value));
EXPECT_FALSE((ImplicitlyConvertible<const int*, int*>::value));
EXPECT_FALSE((ImplicitlyConvertible<Base&, Derived&>::value));
}
// Tests KindOf<T>.
TEST(KindOfTest, Bool) {
EXPECT_EQ(kBool, GMOCK_KIND_OF_(bool)); // NOLINT
}
@@ -382,46 +259,6 @@ TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
}
}
// Tests that IsAProtocolMessage<T>::value is a compile-time constant.
TEST(IsAProtocolMessageTest, ValueIsCompileTimeConstant) {
GMOCK_COMPILE_ASSERT_(IsAProtocolMessage<ProtocolMessage>::value, const_true);
GMOCK_COMPILE_ASSERT_(!IsAProtocolMessage<int>::value, const_false);
}
// Tests that IsAProtocolMessage<T>::value is true when T is
// ProtocolMessage or a sub-class of it.
TEST(IsAProtocolMessageTest, ValueIsTrueWhenTypeIsAProtocolMessage) {
EXPECT_TRUE(IsAProtocolMessage< ::proto2::Message>::value);
EXPECT_TRUE(IsAProtocolMessage<ProtocolMessage>::value);
#if GMOCK_HAS_PROTOBUF_
EXPECT_TRUE(IsAProtocolMessage<const TestMessage>::value);
#endif // GMOCK_HAS_PROTOBUF_
}
// Tests that IsAProtocolMessage<T>::value is false when T is neither
// ProtocolMessage nor a sub-class of it.
TEST(IsAProtocolMessageTest, ValueIsFalseWhenTypeIsNotAProtocolMessage) {
EXPECT_FALSE(IsAProtocolMessage<int>::value);
EXPECT_FALSE(IsAProtocolMessage<const Base>::value);
}
// Tests IsContainerTest.
class NonContainer {};
TEST(IsContainerTestTest, WorksForNonContainer) {
EXPECT_EQ(sizeof(IsNotContainer), sizeof(IsContainerTest<int>(0)));
EXPECT_EQ(sizeof(IsNotContainer), sizeof(IsContainerTest<char[5]>(0)));
EXPECT_EQ(sizeof(IsNotContainer), sizeof(IsContainerTest<NonContainer>(0)));
}
TEST(IsContainerTestTest, WorksForContainer) {
EXPECT_EQ(sizeof(IsContainer),
sizeof(IsContainerTest<std::vector<bool> >(0)));
EXPECT_EQ(sizeof(IsContainer),
sizeof(IsContainerTest<std::map<int, double> >(0)));
}
// Tests the TupleMatches() template function.
TEST(TupleMatchesTest, WorksForSize0) {
@@ -737,148 +574,6 @@ TEST(OnCallTest, LogsAnythingArgument) {
#endif // GTEST_HAS_STREAM_REDIRECTION_
// Tests ArrayEq().
TEST(ArrayEqTest, WorksForDegeneratedArrays) {
EXPECT_TRUE(ArrayEq(5, 5L));
EXPECT_FALSE(ArrayEq('a', 0));
}
TEST(ArrayEqTest, WorksForOneDimensionalArrays) {
const int a[] = { 0, 1 };
long b[] = { 0, 1 };
EXPECT_TRUE(ArrayEq(a, b));
EXPECT_TRUE(ArrayEq(a, 2, b));
b[0] = 2;
EXPECT_FALSE(ArrayEq(a, b));
EXPECT_FALSE(ArrayEq(a, 1, b));
}
TEST(ArrayEqTest, WorksForTwoDimensionalArrays) {
const char a[][3] = { "hi", "lo" };
const char b[][3] = { "hi", "lo" };
const char c[][3] = { "hi", "li" };
EXPECT_TRUE(ArrayEq(a, b));
EXPECT_TRUE(ArrayEq(a, 2, b));
EXPECT_FALSE(ArrayEq(a, c));
EXPECT_FALSE(ArrayEq(a, 2, c));
}
// Tests ArrayAwareFind().
TEST(ArrayAwareFindTest, WorksForOneDimensionalArray) {
const char a[] = "hello";
EXPECT_EQ(a + 4, ArrayAwareFind(a, a + 5, 'o'));
EXPECT_EQ(a + 5, ArrayAwareFind(a, a + 5, 'x'));
}
TEST(ArrayAwareFindTest, WorksForTwoDimensionalArray) {
int a[][2] = { { 0, 1 }, { 2, 3 }, { 4, 5 } };
const int b[2] = { 2, 3 };
EXPECT_EQ(a + 1, ArrayAwareFind(a, a + 3, b));
const int c[2] = { 6, 7 };
EXPECT_EQ(a + 3, ArrayAwareFind(a, a + 3, c));
}
// Tests CopyArray().
TEST(CopyArrayTest, WorksForDegeneratedArrays) {
int n = 0;
CopyArray('a', &n);
EXPECT_EQ('a', n);
}
TEST(CopyArrayTest, WorksForOneDimensionalArrays) {
const char a[3] = "hi";
int b[3];
CopyArray(a, &b);
EXPECT_TRUE(ArrayEq(a, b));
int c[3];
CopyArray(a, 3, c);
EXPECT_TRUE(ArrayEq(a, c));
}
TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
const int a[2][3] = { { 0, 1, 2 }, { 3, 4, 5 } };
int b[2][3];
CopyArray(a, &b);
EXPECT_TRUE(ArrayEq(a, b));
int c[2][3];
CopyArray(a, 2, c);
EXPECT_TRUE(ArrayEq(a, c));
}
// Tests NativeArray.
TEST(NativeArrayTest, ConstructorFromArrayWorks) {
const int a[3] = { 0, 1, 2 };
NativeArray<int> na(a, 3, kReference);
EXPECT_EQ(3U, na.size());
EXPECT_EQ(a, na.begin());
}
TEST(NativeArrayTest, CreatesAndDeletesCopyOfArrayWhenAskedTo) {
typedef int Array[2];
Array* a = new Array[1];
(*a)[0] = 0;
(*a)[1] = 1;
NativeArray<int> na(*a, 2, kCopy);
EXPECT_NE(*a, na.begin());
delete[] a;
EXPECT_EQ(0, na.begin()[0]);
EXPECT_EQ(1, na.begin()[1]);
// We rely on the heap checker to verify that na deletes the copy of
// array.
}
TEST(NativeArrayTest, TypeMembersAreCorrect) {
StaticAssertTypeEq<char, NativeArray<char>::value_type>();
StaticAssertTypeEq<int[2], NativeArray<int[2]>::value_type>();
StaticAssertTypeEq<const char*, NativeArray<char>::const_iterator>();
StaticAssertTypeEq<const bool(*)[2], NativeArray<bool[2]>::const_iterator>();
}
TEST(NativeArrayTest, MethodsWork) {
const int a[3] = { 0, 1, 2 };
NativeArray<int> na(a, 3, kCopy);
ASSERT_EQ(3U, na.size());
EXPECT_EQ(3, na.end() - na.begin());
NativeArray<int>::const_iterator it = na.begin();
EXPECT_EQ(0, *it);
++it;
EXPECT_EQ(1, *it);
it++;
EXPECT_EQ(2, *it);
++it;
EXPECT_EQ(na.end(), it);
EXPECT_THAT(na, Eq(na));
NativeArray<int> na2(a, 3, kReference);
EXPECT_THAT(na, Eq(na2));
const int b1[3] = { 0, 1, 1 };
const int b2[4] = { 0, 1, 2, 3 };
EXPECT_THAT(na, Not(Eq(NativeArray<int>(b1, 3, kReference))));
EXPECT_THAT(na, Not(Eq(NativeArray<int>(b2, 4, kCopy))));
}
TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
const char a[2][3] = { "hi", "lo" };
NativeArray<char[3]> na(a, 2, kReference);
ASSERT_EQ(2U, na.size());
EXPECT_EQ(a, na.begin());
}
// Tests StlContainerView.
TEST(StlContainerViewTest, WorksForStlContainer) {