Unverified Commit edadfecd authored by Akash Patel's avatar Akash Patel Committed by GitHub
Browse files

Update gtest to 1.11.0 (#1086)

Properly resolves #1083, #996.
parent 26e3b704
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
# include <algorithm> # include <algorithm>
# include <iostream> # include <iostream>
# include <list> # include <list>
# include <set>
# include <sstream> # include <sstream>
# include <string> # include <string>
# include <vector> # include <vector>
...@@ -489,16 +490,17 @@ TEST(CombineTest, CombineWithMaxNumberOfParameters) { ...@@ -489,16 +490,17 @@ TEST(CombineTest, CombineWithMaxNumberOfParameters) {
class NonDefaultConstructAssignString { class NonDefaultConstructAssignString {
public: public:
NonDefaultConstructAssignString(const std::string& s) : str_(s) {} NonDefaultConstructAssignString(const std::string& s) : str_(s) {}
NonDefaultConstructAssignString() = delete;
NonDefaultConstructAssignString(const NonDefaultConstructAssignString&) =
default;
NonDefaultConstructAssignString& operator=(
const NonDefaultConstructAssignString&) = delete;
~NonDefaultConstructAssignString() = default;
const std::string& str() const { return str_; } const std::string& str() const { return str_; }
private: private:
std::string str_; std::string str_;
// Not default constructible
NonDefaultConstructAssignString();
// Not assignable
void operator=(const NonDefaultConstructAssignString&);
}; };
TEST(CombineTest, NonDefaultConstructAssign) { TEST(CombineTest, NonDefaultConstructAssign) {
...@@ -802,7 +804,7 @@ TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) { ...@@ -802,7 +804,7 @@ TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) {
::testing::UnitTest::GetInstance()->current_test_info(); ::testing::UnitTest::GetInstance()->current_test_info();
EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_suite_name()); EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_suite_name());
EXPECT_STREQ("FooSomeTestName", test_info->name()); EXPECT_STREQ("FooSomeTestName/0", test_info->name());
} }
INSTANTIATE_TEST_SUITE_P(FortyTwo, MacroNamingTest, Values(42)); INSTANTIATE_TEST_SUITE_P(FortyTwo, MacroNamingTest, Values(42));
...@@ -819,6 +821,36 @@ TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized), ...@@ -819,6 +821,36 @@ TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized),
EXPECT_STREQ("FooSomeTestName", test_info->name()); EXPECT_STREQ("FooSomeTestName", test_info->name());
} }
TEST(MacroNameing, LookupNames) {
std::set<std::string> know_suite_names, know_test_names;
auto ins = testing::UnitTest::GetInstance();
int ts = 0;
while (const testing::TestSuite* suite = ins->GetTestSuite(ts++)) {
know_suite_names.insert(suite->name());
int ti = 0;
while (const testing::TestInfo* info = suite->GetTestInfo(ti++)) {
know_test_names.insert(std::string(suite->name()) + "." + info->name());
}
}
// Check that the expected form of the test suit name actually exists.
EXPECT_NE( //
know_suite_names.find("FortyTwo/MacroNamingTest"),
know_suite_names.end());
EXPECT_NE(
know_suite_names.find("MacroNamingTestNonParametrized"),
know_suite_names.end());
// Check that the expected form of the test name actually exists.
EXPECT_NE( //
know_test_names.find("FortyTwo/MacroNamingTest.FooSomeTestName/0"),
know_test_names.end());
EXPECT_NE(
know_test_names.find("MacroNamingTestNonParametrized.FooSomeTestName"),
know_test_names.end());
}
// Tests that user supplied custom parameter names are working correctly. // Tests that user supplied custom parameter names are working correctly.
// Runs the test with a builtin helper method which uses PrintToString, // Runs the test with a builtin helper method which uses PrintToString,
// as well as a custom function and custom functor to ensure all possible // as well as a custom function and custom functor to ensure all possible
...@@ -1037,6 +1069,38 @@ TEST_P(MyEnumTest, ChecksParamMoreThanZero) { EXPECT_GE(10, GetParam()); } ...@@ -1037,6 +1069,38 @@ TEST_P(MyEnumTest, ChecksParamMoreThanZero) { EXPECT_GE(10, GetParam()); }
INSTANTIATE_TEST_SUITE_P(MyEnumTests, MyEnumTest, INSTANTIATE_TEST_SUITE_P(MyEnumTests, MyEnumTest,
::testing::Values(ENUM1, ENUM2, 0)); ::testing::Values(ENUM1, ENUM2, 0));
namespace works_here {
// Never used not instantiated, this should work.
class NotUsedTest : public testing::TestWithParam<int> {};
///////
// Never used not instantiated, this should work.
template <typename T>
class NotUsedTypeTest : public testing::Test {};
TYPED_TEST_SUITE_P(NotUsedTypeTest);
// Used but not instantiated, this would fail. but...
class NotInstantiatedTest : public testing::TestWithParam<int> {};
// ... we mark is as allowed.
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NotInstantiatedTest);
TEST_P(NotInstantiatedTest, Used) { }
using OtherName = NotInstantiatedTest;
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(OtherName);
TEST_P(OtherName, Used) { }
// Used but not instantiated, this would fail. but...
template <typename T>
class NotInstantiatedTypeTest : public testing::Test {};
TYPED_TEST_SUITE_P(NotInstantiatedTypeTest);
// ... we mark is as allowed.
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NotInstantiatedTypeTest);
TYPED_TEST_P(NotInstantiatedTypeTest, Used) { }
REGISTER_TYPED_TEST_SUITE_P(NotInstantiatedTypeTest, Used);
} // namespace works_here
int main(int argc, char **argv) { int main(int argc, char **argv) {
// Used in TestGenerationTest test suite. // Used in TestGenerationTest test suite.
AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance()); AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance());
......
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
// This header file provides classes and functions used internally // This header file provides classes and functions used internally
// for testing Google Test itself. // for testing Google Test itself.
#ifndef GTEST_TEST_GTEST_PARAM_TEST_TEST_H_ #ifndef GOOGLETEST_TEST_GOOGLETEST_PARAM_TEST_TEST_H_
#define GTEST_TEST_GTEST_PARAM_TEST_TEST_H_ #define GOOGLETEST_TEST_GOOGLETEST_PARAM_TEST_TEST_H_
#include "gtest/gtest.h" #include "gtest/gtest.h"
...@@ -48,4 +48,4 @@ class InstantiationInMultipleTranslationUnitsTest ...@@ -48,4 +48,4 @@ class InstantiationInMultipleTranslationUnitsTest
: public ::testing::TestWithParam<int> { : public ::testing::TestWithParam<int> {
}; };
#endif // GTEST_TEST_GTEST_PARAM_TEST_TEST_H_ #endif // GOOGLETEST_TEST_GOOGLETEST_PARAM_TEST_TEST_H_
...@@ -90,10 +90,10 @@ TEST(IsXDigitTest, ReturnsFalseForWideNonAscii) { ...@@ -90,10 +90,10 @@ TEST(IsXDigitTest, ReturnsFalseForWideNonAscii) {
class Base { class Base {
public: public:
// Copy constructor and assignment operator do exactly what we need, so we
// use them.
Base() : member_(0) {} Base() : member_(0) {}
explicit Base(int n) : member_(n) {} explicit Base(int n) : member_(n) {}
Base(const Base&) = default;
Base& operator=(const Base&) = default;
virtual ~Base() {} virtual ~Base() {}
int member() { return member_; } int member() { return member_; }
...@@ -201,6 +201,13 @@ TEST(ImplicitCastTest, CanUseImplicitConstructor) { ...@@ -201,6 +201,13 @@ TEST(ImplicitCastTest, CanUseImplicitConstructor) {
EXPECT_TRUE(converted); EXPECT_TRUE(converted);
} }
// The following code intentionally tests a suboptimal syntax.
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-else"
#pragma GCC diagnostic ignored "-Wempty-body"
#pragma GCC diagnostic ignored "-Wpragmas"
#endif
TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) { TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) {
if (AlwaysFalse()) if (AlwaysFalse())
GTEST_CHECK_(false) << "This should never be executed; " GTEST_CHECK_(false) << "This should never be executed; "
...@@ -216,6 +223,9 @@ TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) { ...@@ -216,6 +223,9 @@ TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) {
else else
GTEST_CHECK_(true) << ""; GTEST_CHECK_(true) << "";
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
TEST(GtestCheckSyntaxTest, WorksWithSwitch) { TEST(GtestCheckSyntaxTest, WorksWithSwitch) {
switch (0) { switch (0) {
...@@ -363,8 +373,6 @@ TEST(RegexEngineSelectionTest, SelectsCorrectRegexEngine) { ...@@ -363,8 +373,6 @@ TEST(RegexEngineSelectionTest, SelectsCorrectRegexEngine) {
#if GTEST_USES_POSIX_RE #if GTEST_USES_POSIX_RE
# if GTEST_HAS_TYPED_TEST
template <typename Str> template <typename Str>
class RETest : public ::testing::Test {}; class RETest : public ::testing::Test {};
...@@ -420,8 +428,6 @@ TYPED_TEST(RETest, PartialMatchWorks) { ...@@ -420,8 +428,6 @@ TYPED_TEST(RETest, PartialMatchWorks) {
EXPECT_FALSE(RE::PartialMatch(TypeParam("zza"), re)); EXPECT_FALSE(RE::PartialMatch(TypeParam("zza"), re));
} }
# endif // GTEST_HAS_TYPED_TEST
#elif GTEST_USES_SIMPLE_RE #elif GTEST_USES_SIMPLE_RE
TEST(IsInSetTest, NulCharIsNotInAnySet) { TEST(IsInSetTest, NulCharIsNotInAnySet) {
...@@ -1180,8 +1186,6 @@ class DestructorTracker { ...@@ -1180,8 +1186,6 @@ class DestructorTracker {
return DestructorCall::List().size() - 1; return DestructorCall::List().size() - 1;
} }
const size_t index_; const size_t index_;
GTEST_DISALLOW_ASSIGN_(DestructorTracker);
}; };
typedef ThreadLocal<DestructorTracker>* ThreadParam; typedef ThreadLocal<DestructorTracker>* ThreadParam;
......
...@@ -32,14 +32,16 @@ ...@@ -32,14 +32,16 @@
// //
// This file tests the universal value printer. // This file tests the universal value printer.
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <algorithm> #include <algorithm>
#include <cctype>
#include <cstdint>
#include <cstring>
#include <deque> #include <deque>
#include <forward_list> #include <forward_list>
#include <limits>
#include <list> #include <list>
#include <map> #include <map>
#include <memory>
#include <set> #include <set>
#include <sstream> #include <sstream>
#include <string> #include <string>
...@@ -89,6 +91,18 @@ class BiggestIntConvertible { ...@@ -89,6 +91,18 @@ class BiggestIntConvertible {
operator ::testing::internal::BiggestInt() const { return 42; } operator ::testing::internal::BiggestInt() const { return 42; }
}; };
// A parent class with two child classes. The parent and one of the kids have
// stream operators.
class ParentClass {};
class ChildClassWithStreamOperator : public ParentClass {};
class ChildClassWithoutStreamOperator : public ParentClass {};
static void operator<<(std::ostream& os, const ParentClass&) {
os << "ParentClass";
}
static void operator<<(std::ostream& os, const ChildClassWithStreamOperator&) {
os << "ChildClassWithStreamOperator";
}
// A user-defined unprintable class template in the global namespace. // A user-defined unprintable class template in the global namespace.
template <typename T> template <typename T>
class UnprintableTemplateInGlobal { class UnprintableTemplateInGlobal {
...@@ -176,7 +190,18 @@ inline ::std::ostream& operator<<(::std::ostream& os, ...@@ -176,7 +190,18 @@ inline ::std::ostream& operator<<(::std::ostream& os,
return os << "StreamableTemplateInFoo: " << x.value(); return os << "StreamableTemplateInFoo: " << x.value();
} }
// A user-defined streamable but recursivly-defined container type in // A user-defined streamable type in a user namespace whose operator<< is
// templated on the type of the output stream.
struct TemplatedStreamableInFoo {};
template <typename OutputStream>
OutputStream& operator<<(OutputStream& os,
const TemplatedStreamableInFoo& /*ts*/) {
os << "TemplatedStreamableInFoo";
return os;
}
// A user-defined streamable but recursively-defined container type in
// a user namespace, it mimics therefore std::filesystem::path or // a user namespace, it mimics therefore std::filesystem::path or
// boost::filesystem::path. // boost::filesystem::path.
class PathLike { class PathLike {
...@@ -204,6 +229,33 @@ class PathLike { ...@@ -204,6 +229,33 @@ class PathLike {
} // namespace foo } // namespace foo
namespace testing { namespace testing {
namespace {
template <typename T>
class Wrapper {
public:
explicit Wrapper(T&& value) : value_(std::forward<T>(value)) {}
const T& value() const { return value_; }
private:
T value_;
};
} // namespace
namespace internal {
template <typename T>
class UniversalPrinter<Wrapper<T>> {
public:
static void Print(const Wrapper<T>& w, ::std::ostream* os) {
*os << "Wrapper(";
UniversalPrint(w.value(), os);
*os << ')';
}
};
} // namespace internal
namespace gtest_printers_test { namespace gtest_printers_test {
using ::std::deque; using ::std::deque;
...@@ -219,7 +271,6 @@ using ::testing::PrintToString; ...@@ -219,7 +271,6 @@ using ::testing::PrintToString;
using ::testing::internal::FormatForComparisonFailureMessage; using ::testing::internal::FormatForComparisonFailureMessage;
using ::testing::internal::ImplicitCast_; using ::testing::internal::ImplicitCast_;
using ::testing::internal::NativeArray; using ::testing::internal::NativeArray;
using ::testing::internal::RE;
using ::testing::internal::RelationToSourceReference; using ::testing::internal::RelationToSourceReference;
using ::testing::internal::Strings; using ::testing::internal::Strings;
using ::testing::internal::UniversalPrint; using ::testing::internal::UniversalPrint;
...@@ -310,6 +361,20 @@ TEST(PrintCharTest, UnsignedChar) { ...@@ -310,6 +361,20 @@ TEST(PrintCharTest, UnsignedChar) {
Print(static_cast<unsigned char>('b'))); Print(static_cast<unsigned char>('b')));
} }
TEST(PrintCharTest, Char16) {
EXPECT_EQ("U+0041", Print(u'A'));
}
TEST(PrintCharTest, Char32) {
EXPECT_EQ("U+0041", Print(U'A'));
}
#ifdef __cpp_char8_t
TEST(PrintCharTest, Char8) {
EXPECT_EQ("U+0041", Print(u8'A'));
}
#endif
// Tests printing other simple, built-in types. // Tests printing other simple, built-in types.
// bool. // bool.
...@@ -340,23 +405,39 @@ TEST(PrintBuiltInTypeTest, Wchar_t) { ...@@ -340,23 +405,39 @@ TEST(PrintBuiltInTypeTest, Wchar_t) {
EXPECT_EQ("L'\\xC74D' (51021)", Print(static_cast<wchar_t>(0xC74D))); EXPECT_EQ("L'\\xC74D' (51021)", Print(static_cast<wchar_t>(0xC74D)));
} }
// Test that Int64 provides more storage than wchar_t. // Test that int64_t provides more storage than wchar_t.
TEST(PrintTypeSizeTest, Wchar_t) { TEST(PrintTypeSizeTest, Wchar_t) {
EXPECT_LT(sizeof(wchar_t), sizeof(testing::internal::Int64)); EXPECT_LT(sizeof(wchar_t), sizeof(int64_t));
} }
// Various integer types. // Various integer types.
TEST(PrintBuiltInTypeTest, Integer) { TEST(PrintBuiltInTypeTest, Integer) {
EXPECT_EQ("'\\xFF' (255)", Print(static_cast<unsigned char>(255))); // uint8 EXPECT_EQ("'\\xFF' (255)", Print(static_cast<unsigned char>(255))); // uint8
EXPECT_EQ("'\\x80' (-128)", Print(static_cast<signed char>(-128))); // int8 EXPECT_EQ("'\\x80' (-128)", Print(static_cast<signed char>(-128))); // int8
EXPECT_EQ("65535", Print(USHRT_MAX)); // uint16 EXPECT_EQ("65535", Print(std::numeric_limits<uint16_t>::max())); // uint16
EXPECT_EQ("-32768", Print(SHRT_MIN)); // int16 EXPECT_EQ("-32768", Print(std::numeric_limits<int16_t>::min())); // int16
EXPECT_EQ("4294967295", Print(UINT_MAX)); // uint32 EXPECT_EQ("4294967295",
EXPECT_EQ("-2147483648", Print(INT_MIN)); // int32 Print(std::numeric_limits<uint32_t>::max())); // uint32
EXPECT_EQ("-2147483648",
Print(std::numeric_limits<int32_t>::min())); // int32
EXPECT_EQ("18446744073709551615", EXPECT_EQ("18446744073709551615",
Print(static_cast<testing::internal::UInt64>(-1))); // uint64 Print(std::numeric_limits<uint64_t>::max())); // uint64
EXPECT_EQ("-9223372036854775808", EXPECT_EQ("-9223372036854775808",
Print(static_cast<testing::internal::Int64>(1) << 63)); // int64 Print(std::numeric_limits<int64_t>::min())); // int64
#ifdef __cpp_char8_t
EXPECT_EQ("U+0000",
Print(std::numeric_limits<char8_t>::min())); // char8_t
EXPECT_EQ("U+00FF",
Print(std::numeric_limits<char8_t>::max())); // char8_t
#endif
EXPECT_EQ("U+0000",
Print(std::numeric_limits<char16_t>::min())); // char16_t
EXPECT_EQ("U+FFFF",
Print(std::numeric_limits<char16_t>::max())); // char16_t
EXPECT_EQ("U+0000",
Print(std::numeric_limits<char32_t>::min())); // char32_t
EXPECT_EQ("U+FFFFFFFF",
Print(std::numeric_limits<char32_t>::max())); // char32_t
} }
// Size types. // Size types.
...@@ -412,6 +493,92 @@ TEST(PrintCStringTest, EscapesProperly) { ...@@ -412,6 +493,92 @@ TEST(PrintCStringTest, EscapesProperly) {
Print(p)); Print(p));
} }
#ifdef __cpp_char8_t
// const char8_t*.
TEST(PrintU8StringTest, Const) {
const char8_t* p = u8"界";
EXPECT_EQ(PrintPointer(p) + " pointing to u8\"\\xE7\\x95\\x8C\"", Print(p));
}
// char8_t*.
TEST(PrintU8StringTest, NonConst) {
char8_t p[] = u8"世";
EXPECT_EQ(PrintPointer(p) + " pointing to u8\"\\xE4\\xB8\\x96\"",
Print(static_cast<char8_t*>(p)));
}
// NULL u8 string.
TEST(PrintU8StringTest, Null) {
const char8_t* p = nullptr;
EXPECT_EQ("NULL", Print(p));
}
// Tests that u8 strings are escaped properly.
TEST(PrintU8StringTest, EscapesProperly) {
const char8_t* p = u8"'\"?\\\a\b\f\n\r\t\v\x7F\xFF hello 世界";
EXPECT_EQ(PrintPointer(p) +
" pointing to u8\"'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\\x7F\\xFF "
"hello \\xE4\\xB8\\x96\\xE7\\x95\\x8C\"",
Print(p));
}
#endif
// const char16_t*.
TEST(PrintU16StringTest, Const) {
const char16_t* p = u"界";
EXPECT_EQ(PrintPointer(p) + " pointing to u\"\\x754C\"", Print(p));
}
// char16_t*.
TEST(PrintU16StringTest, NonConst) {
char16_t p[] = u"世";
EXPECT_EQ(PrintPointer(p) + " pointing to u\"\\x4E16\"",
Print(static_cast<char16_t*>(p)));
}
// NULL u16 string.
TEST(PrintU16StringTest, Null) {
const char16_t* p = nullptr;
EXPECT_EQ("NULL", Print(p));
}
// Tests that u16 strings are escaped properly.
TEST(PrintU16StringTest, EscapesProperly) {
const char16_t* p = u"'\"?\\\a\b\f\n\r\t\v\x7F\xFF hello 世界";
EXPECT_EQ(PrintPointer(p) +
" pointing to u\"'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\\x7F\\xFF "
"hello \\x4E16\\x754C\"",
Print(p));
}
// const char32_t*.
TEST(PrintU32StringTest, Const) {
const char32_t* p = U"🗺️";
EXPECT_EQ(PrintPointer(p) + " pointing to U\"\\x1F5FA\\xFE0F\"", Print(p));
}
// char32_t*.
TEST(PrintU32StringTest, NonConst) {
char32_t p[] = U"🌌";
EXPECT_EQ(PrintPointer(p) + " pointing to U\"\\x1F30C\"",
Print(static_cast<char32_t*>(p)));
}
// NULL u32 string.
TEST(PrintU32StringTest, Null) {
const char32_t* p = nullptr;
EXPECT_EQ("NULL", Print(p));
}
// Tests that u32 strings are escaped properly.
TEST(PrintU32StringTest, EscapesProperly) {
const char32_t* p = U"'\"?\\\a\b\f\n\r\t\v\x7F\xFF hello 🗺️";
EXPECT_EQ(PrintPointer(p) +
" pointing to U\"'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\\x7F\\xFF "
"hello \\x1F5FA\\xFE0F\"",
Print(p));
}
// MSVC compiler can be configured to define whar_t as a typedef // MSVC compiler can be configured to define whar_t as a typedef
// of unsigned short. Defining an overload for const wchar_t* in that case // of unsigned short. Defining an overload for const wchar_t* in that case
// would cause pointers to unsigned shorts be printed as wide strings, // would cause pointers to unsigned shorts be printed as wide strings,
...@@ -622,21 +789,66 @@ TEST(PrintArrayTest, CharArrayWithNoTerminatingNul) { ...@@ -622,21 +789,66 @@ TEST(PrintArrayTest, CharArrayWithNoTerminatingNul) {
EXPECT_EQ("\"H\\0i\" (no terminating NUL)", PrintArrayHelper(a)); EXPECT_EQ("\"H\\0i\" (no terminating NUL)", PrintArrayHelper(a));
} }
// const char array with terminating NUL. // char array with terminating NUL.
TEST(PrintArrayTest, ConstCharArrayWithTerminatingNul) { TEST(PrintArrayTest, CharArrayWithTerminatingNul) {
const char a[] = "\0Hi"; const char a[] = "\0Hi";
EXPECT_EQ("\"\\0Hi\"", PrintArrayHelper(a)); EXPECT_EQ("\"\\0Hi\"", PrintArrayHelper(a));
} }
// const wchar_t array without terminating NUL. #ifdef __cpp_char8_t
// char_t array without terminating NUL.
TEST(PrintArrayTest, Char8ArrayWithNoTerminatingNul) {
// Array a contains '\0' in the middle and doesn't end with '\0'.
const char8_t a[] = {u8'H', u8'\0', u8'i'};
EXPECT_EQ("u8\"H\\0i\" (no terminating NUL)", PrintArrayHelper(a));
}
// char8_t array with terminating NUL.
TEST(PrintArrayTest, Char8ArrayWithTerminatingNul) {
const char8_t a[] = u8"\0世界";
EXPECT_EQ(
"u8\"\\0\\xE4\\xB8\\x96\\xE7\\x95\\x8C\"",
PrintArrayHelper(a));
}
#endif
// const char16_t array without terminating NUL.
TEST(PrintArrayTest, Char16ArrayWithNoTerminatingNul) {
// Array a contains '\0' in the middle and doesn't end with '\0'.
const char16_t a[] = {u'こ', u'\0', u'ん', u'に', u'ち', u'は'};
EXPECT_EQ("u\"\\x3053\\0\\x3093\\x306B\\x3061\\x306F\" (no terminating NUL)",
PrintArrayHelper(a));
}
// char16_t array with terminating NUL.
TEST(PrintArrayTest, Char16ArrayWithTerminatingNul) {
const char16_t a[] = u"\0こんにちは";
EXPECT_EQ("u\"\\0\\x3053\\x3093\\x306B\\x3061\\x306F\"", PrintArrayHelper(a));
}
// char32_t array without terminating NUL.
TEST(PrintArrayTest, Char32ArrayWithNoTerminatingNul) {
// Array a contains '\0' in the middle and doesn't end with '\0'.
const char32_t a[] = {U'👋', U'\0', U'🌌'};
EXPECT_EQ("U\"\\x1F44B\\0\\x1F30C\" (no terminating NUL)",
PrintArrayHelper(a));
}
// char32_t array with terminating NUL.
TEST(PrintArrayTest, Char32ArrayWithTerminatingNul) {
const char32_t a[] = U"\0👋🌌";
EXPECT_EQ("U\"\\0\\x1F44B\\x1F30C\"", PrintArrayHelper(a));
}
// wchar_t array without terminating NUL.
TEST(PrintArrayTest, WCharArrayWithNoTerminatingNul) { TEST(PrintArrayTest, WCharArrayWithNoTerminatingNul) {
// Array a contains '\0' in the middle and doesn't end with '\0'. // Array a contains '\0' in the middle and doesn't end with '\0'.
const wchar_t a[] = { L'H', L'\0', L'i' }; const wchar_t a[] = {L'H', L'\0', L'i'};
EXPECT_EQ("L\"H\\0i\" (no terminating NUL)", PrintArrayHelper(a)); EXPECT_EQ("L\"H\\0i\" (no terminating NUL)", PrintArrayHelper(a));
} }
// wchar_t array with terminating NUL. // wchar_t array with terminating NUL.
TEST(PrintArrayTest, WConstCharArrayWithTerminatingNul) { TEST(PrintArrayTest, WCharArrayWithTerminatingNul) {
const wchar_t a[] = L"\0Hi"; const wchar_t a[] = L"\0Hi";
EXPECT_EQ("L\"\\0Hi\"", PrintArrayHelper(a)); EXPECT_EQ("L\"\\0Hi\"", PrintArrayHelper(a));
} }
...@@ -700,6 +912,26 @@ TEST(PrintWideStringTest, StringAmbiguousHex) { ...@@ -700,6 +912,26 @@ TEST(PrintWideStringTest, StringAmbiguousHex) {
} }
#endif // GTEST_HAS_STD_WSTRING #endif // GTEST_HAS_STD_WSTRING
#ifdef __cpp_char8_t
TEST(PrintStringTest, U8String) {
std::u8string str = u8"Hello, 世界";
EXPECT_EQ(str, str); // Verify EXPECT_EQ compiles with this type.
EXPECT_EQ("u8\"Hello, \\xE4\\xB8\\x96\\xE7\\x95\\x8C\"", Print(str));
}
#endif
TEST(PrintStringTest, U16String) {
std::u16string str = u"Hello, 世界";
EXPECT_EQ(str, str); // Verify EXPECT_EQ compiles with this type.
EXPECT_EQ("u\"Hello, \\x4E16\\x754C\"", Print(str));
}
TEST(PrintStringTest, U32String) {
std::u32string str = U"Hello, 🗺️";
EXPECT_EQ(str, str); // Verify EXPECT_EQ compiles with this type
EXPECT_EQ("U\"Hello, \\x1F5FA\\xFE0F\"", Print(str));
}
// Tests printing types that support generic streaming (i.e. streaming // Tests printing types that support generic streaming (i.e. streaming
// to std::basic_ostream<Char, CharTraits> for any valid Char and // to std::basic_ostream<Char, CharTraits> for any valid Char and
// CharTraits types). // CharTraits types).
...@@ -758,22 +990,22 @@ TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) { ...@@ -758,22 +990,22 @@ TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
EXPECT_EQ("AllowsGenericStreamingAndImplicitConversionTemplate", Print(a)); EXPECT_EQ("AllowsGenericStreamingAndImplicitConversionTemplate", Print(a));
} }
#if GTEST_HAS_ABSL #if GTEST_INTERNAL_HAS_STRING_VIEW
// Tests printing ::absl::string_view. // Tests printing internal::StringView.
TEST(PrintStringViewTest, SimpleStringView) { TEST(PrintStringViewTest, SimpleStringView) {
const ::absl::string_view sp = "Hello"; const internal::StringView sp = "Hello";
EXPECT_EQ("\"Hello\"", Print(sp)); EXPECT_EQ("\"Hello\"", Print(sp));
} }
TEST(PrintStringViewTest, UnprintableCharacters) { TEST(PrintStringViewTest, UnprintableCharacters) {
const char str[] = "NUL (\0) and \r\t"; const char str[] = "NUL (\0) and \r\t";
const ::absl::string_view sp(str, sizeof(str) - 1); const internal::StringView sp(str, sizeof(str) - 1);
EXPECT_EQ("\"NUL (\\0) and \\r\\t\"", Print(sp)); EXPECT_EQ("\"NUL (\\0) and \\r\\t\"", Print(sp));
} }
#endif // GTEST_HAS_ABSL #endif // GTEST_INTERNAL_HAS_STRING_VIEW
// Tests printing STL containers. // Tests printing STL containers.
...@@ -978,9 +1210,8 @@ TEST(PrintStdTupleTest, VariousSizes) { ...@@ -978,9 +1210,8 @@ TEST(PrintStdTupleTest, VariousSizes) {
EXPECT_EQ("(false, 2, 3, 4)", Print(t4)); EXPECT_EQ("(false, 2, 3, 4)", Print(t4));
const char* const str = "8"; const char* const str = "8";
::std::tuple<bool, char, short, testing::internal::Int32, // NOLINT ::std::tuple<bool, char, short, int32_t, int64_t, float, double, // NOLINT
testing::internal::Int64, float, double, const char*, void*, const char*, void*, std::string>
std::string>
t10(false, 'a', static_cast<short>(3), 4, 5, 1.5F, -2.5, str, // NOLINT t10(false, 'a', static_cast<short>(3), 4, 5, 1.5F, -2.5, str, // NOLINT
nullptr, "10"); nullptr, "10");
EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) + EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) +
...@@ -1064,6 +1295,20 @@ TEST(PrintStreamableTypeTest, TemplateTypeInUserNamespace) { ...@@ -1064,6 +1295,20 @@ TEST(PrintStreamableTypeTest, TemplateTypeInUserNamespace) {
Print(::foo::StreamableTemplateInFoo<int>())); Print(::foo::StreamableTemplateInFoo<int>()));
} }
TEST(PrintStreamableTypeTest, TypeInUserNamespaceWithTemplatedStreamOperator) {
EXPECT_EQ("TemplatedStreamableInFoo",
Print(::foo::TemplatedStreamableInFoo()));
}
TEST(PrintStreamableTypeTest, SubclassUsesSuperclassStreamOperator) {
ParentClass parent;
ChildClassWithStreamOperator child_stream;
ChildClassWithoutStreamOperator child_no_stream;
EXPECT_EQ("ParentClass", Print(parent));
EXPECT_EQ("ChildClassWithStreamOperator", Print(child_stream));
EXPECT_EQ("ParentClass", Print(child_no_stream));
}
// Tests printing a user-defined recursive container type that has a << // Tests printing a user-defined recursive container type that has a <<
// operator. // operator.
TEST(PrintStreamableTypeTest, PathLikeInUserNamespace) { TEST(PrintStreamableTypeTest, PathLikeInUserNamespace) {
...@@ -1472,6 +1717,13 @@ TEST(UniversalPrintTest, WorksForReference) { ...@@ -1472,6 +1717,13 @@ TEST(UniversalPrintTest, WorksForReference) {
EXPECT_EQ("123", ss.str()); EXPECT_EQ("123", ss.str());
} }
TEST(UniversalPrintTest, WorksForPairWithConst) {
std::pair<const Wrapper<std::string>, int> p(Wrapper<std::string>("abc"), 1);
::std::stringstream ss;
UniversalPrint(p, &ss);
EXPECT_EQ("(Wrapper(\"abc\"), 1)", ss.str());
}
TEST(UniversalPrintTest, WorksForCString) { TEST(UniversalPrintTest, WorksForCString) {
const char* s1 = "abc"; const char* s1 = "abc";
::std::stringstream ss1; ::std::stringstream ss1;
...@@ -1501,6 +1753,63 @@ TEST(UniversalPrintTest, WorksForCharArray) { ...@@ -1501,6 +1753,63 @@ TEST(UniversalPrintTest, WorksForCharArray) {
EXPECT_EQ("\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str()); EXPECT_EQ("\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str());
} }
TEST(UniversalPrintTest, IncompleteType) {
struct Incomplete;
char some_object = 0;
EXPECT_EQ("(incomplete type)",
PrintToString(reinterpret_cast<Incomplete&>(some_object)));
}
TEST(UniversalPrintTest, SmartPointers) {
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<int>()));
std::unique_ptr<int> p(new int(17));
EXPECT_EQ("(ptr = " + PrintPointer(p.get()) + ", value = 17)",
PrintToString(p));
std::unique_ptr<int[]> p2(new int[2]);
EXPECT_EQ("(" + PrintPointer(p2.get()) + ")", PrintToString(p2));
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<int>()));
std::shared_ptr<int> p3(new int(1979));
EXPECT_EQ("(ptr = " + PrintPointer(p3.get()) + ", value = 1979)",
PrintToString(p3));
#if __cpp_lib_shared_ptr_arrays >= 201611L
std::shared_ptr<int[]> p4(new int[2]);
EXPECT_EQ("(" + PrintPointer(p4.get()) + ")", PrintToString(p4));
#endif
// modifiers
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<int>()));
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<const int>()));
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<volatile int>()));
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<volatile const int>()));
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<int[]>()));
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<const int[]>()));
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<volatile int[]>()));
EXPECT_EQ("(nullptr)",
PrintToString(std::unique_ptr<volatile const int[]>()));
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<int>()));
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<const int>()));
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<volatile int>()));
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<volatile const int>()));
#if __cpp_lib_shared_ptr_arrays >= 201611L
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<int[]>()));
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<const int[]>()));
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<volatile int[]>()));
EXPECT_EQ("(nullptr)",
PrintToString(std::shared_ptr<volatile const int[]>()));
#endif
// void
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<void, void (*)(void*)>(
nullptr, nullptr)));
EXPECT_EQ("(" + PrintPointer(p.get()) + ")",
PrintToString(
std::unique_ptr<void, void (*)(void*)>(p.get(), [](void*) {})));
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<void>()));
EXPECT_EQ("(" + PrintPointer(p.get()) + ")",
PrintToString(std::shared_ptr<void>(p.get(), [](void*) {})));
}
TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) { TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) {
Strings result = UniversalTersePrintTupleFieldsToStrings(::std::make_tuple()); Strings result = UniversalTersePrintTupleFieldsToStrings(::std::make_tuple());
EXPECT_EQ(0u, result.size()); EXPECT_EQ(0u, result.size());
...@@ -1530,32 +1839,65 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) { ...@@ -1530,32 +1839,65 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
EXPECT_EQ("\"a\"", result[1]); EXPECT_EQ("\"a\"", result[1]);
} }
#if GTEST_HAS_ABSL #if GTEST_INTERNAL_HAS_ANY
class PrintAnyTest : public ::testing::Test {
protected:
template <typename T>
static std::string ExpectedTypeName() {
#if GTEST_HAS_RTTI
return internal::GetTypeName<T>();
#else
return "<unknown_type>";
#endif // GTEST_HAS_RTTI
}
};
TEST_F(PrintAnyTest, Empty) {
internal::Any any;
EXPECT_EQ("no value", PrintToString(any));
}
TEST_F(PrintAnyTest, NonEmpty) {
internal::Any any;
constexpr int val1 = 10;
const std::string val2 = "content";
any = val1;
EXPECT_EQ("value of type " + ExpectedTypeName<int>(), PrintToString(any));
any = val2;
EXPECT_EQ("value of type " + ExpectedTypeName<std::string>(),
PrintToString(any));
}
#endif // GTEST_INTERNAL_HAS_ANY
#if GTEST_INTERNAL_HAS_OPTIONAL
TEST(PrintOptionalTest, Basic) { TEST(PrintOptionalTest, Basic) {
absl::optional<int> value; internal::Optional<int> value;
EXPECT_EQ("(nullopt)", PrintToString(value)); EXPECT_EQ("(nullopt)", PrintToString(value));
value = {7}; value = {7};
EXPECT_EQ("(7)", PrintToString(value)); EXPECT_EQ("(7)", PrintToString(value));
EXPECT_EQ("(1.1)", PrintToString(absl::optional<double>{1.1})); EXPECT_EQ("(1.1)", PrintToString(internal::Optional<double>{1.1}));
EXPECT_EQ("(\"A\")", PrintToString(absl::optional<std::string>{"A"})); EXPECT_EQ("(\"A\")", PrintToString(internal::Optional<std::string>{"A"}));
} }
#endif // GTEST_INTERNAL_HAS_OPTIONAL
#if GTEST_INTERNAL_HAS_VARIANT
struct NonPrintable { struct NonPrintable {
unsigned char contents = 17; unsigned char contents = 17;
}; };
TEST(PrintOneofTest, Basic) { TEST(PrintOneofTest, Basic) {
using Type = absl::variant<int, StreamableInGlobal, NonPrintable>; using Type = internal::Variant<int, StreamableInGlobal, NonPrintable>;
EXPECT_EQ("('int' with value 7)", PrintToString(Type(7))); EXPECT_EQ("('int(index = 0)' with value 7)", PrintToString(Type(7)));
EXPECT_EQ("('StreamableInGlobal' with value StreamableInGlobal)", EXPECT_EQ("('StreamableInGlobal(index = 1)' with value StreamableInGlobal)",
PrintToString(Type(StreamableInGlobal{}))); PrintToString(Type(StreamableInGlobal{})));
EXPECT_EQ( EXPECT_EQ(
"('testing::gtest_printers_test::NonPrintable' with value 1-byte object " "('testing::gtest_printers_test::NonPrintable(index = 2)' with value "
"<11>)", "1-byte object <11>)",
PrintToString(Type(NonPrintable{}))); PrintToString(Type(NonPrintable{})));
} }
#endif // GTEST_HAS_ABSL #endif // GTEST_INTERNAL_HAS_VARIANT
namespace { namespace {
class string_ref; class string_ref;
......
#!/usr/bin/env bash #!/usr/bin/env python
# Copyright 2017 Google Inc.
# All Rights Reserved.
# #
# Copyright 2019, Google Inc.
# All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are # modification, are permitted provided that the following conditions are
...@@ -29,23 +29,26 @@ ...@@ -29,23 +29,26 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set -e """Verifies that SetUpTestSuite and TearDownTestSuite errors are noticed."""
# ccache on OS X needs installation first import gtest_test_utils
# reset ccache statistics
ccache --zero-stats
echo PATH=${PATH} COMMAND = gtest_test_utils.GetTestExecutablePath(
'googletest-setuptestsuite-test_')
echo "Compiler configuration:"
echo CXX=${CXX}
echo CC=${CC}
echo CXXFLAGS=${CXXFLAGS}
echo "C++ compiler version:" class GTestSetUpTestSuiteTest(gtest_test_utils.TestCase):
${CXX} --version || echo "${CXX} does not seem to support the --version flag"
${CXX} -v || echo "${CXX} does not seem to support the -v flag"
echo "C compiler version:" def testSetupErrorAndTearDownError(self):
${CC} --version || echo "${CXX} does not seem to support the --version flag" p = gtest_test_utils.Subprocess(COMMAND)
${CC} -v || echo "${CXX} does not seem to support the -v flag" self.assertNotEqual(p.exit_code, 0, msg=p.output)
self.assertIn(
'[ FAILED ] SetupFailTest: SetUpTestSuite or TearDownTestSuite\n'
'[ FAILED ] TearDownFailTest: SetUpTestSuite or TearDownTestSuite\n'
'\n'
' 2 FAILED TEST SUITES\n',
p.output)
if __name__ == '__main__':
gtest_test_utils.Main()
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "gtest/gtest.h"
class SetupFailTest : public ::testing::Test {
protected:
static void SetUpTestSuite() {
ASSERT_EQ("", "SET_UP_FAIL");
}
};
TEST_F(SetupFailTest, NoopPassingTest) {}
class TearDownFailTest : public ::testing::Test {
protected:
static void TearDownTestSuite() {
ASSERT_EQ("", "TEAR_DOWN_FAIL");
}
};
TEST_F(TearDownFailTest, NoopPassingTest) {}
...@@ -82,7 +82,7 @@ class TestNamePrinter : public EmptyTestEventListener { ...@@ -82,7 +82,7 @@ class TestNamePrinter : public EmptyTestEventListener {
} }
void OnTestStart(const TestInfo& test_info) override { void OnTestStart(const TestInfo& test_info) override {
printf("%s.%s\n", test_info.test_case_name(), test_info.name()); printf("%s.%s\n", test_info.test_suite_name(), test_info.name());
} }
}; };
......
...@@ -33,12 +33,8 @@ ...@@ -33,12 +33,8 @@
#include "test/gtest-typed-test_test.h" #include "test/gtest-typed-test_test.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#if GTEST_HAS_TYPED_TEST_P
// Tests that the same type-parameterized test case can be // Tests that the same type-parameterized test case can be
// instantiated in different translation units linked together. // instantiated in different translation units linked together.
// (ContainerTest is also instantiated in gtest-typed-test_test.cc.) // (ContainerTest is also instantiated in gtest-typed-test_test.cc.)
INSTANTIATE_TYPED_TEST_SUITE_P(Vector, ContainerTest, INSTANTIATE_TYPED_TEST_SUITE_P(Vector, ContainerTest,
testing::Types<std::vector<int> >); testing::Types<std::vector<int> >);
#endif // GTEST_HAS_TYPED_TEST_P
...@@ -88,9 +88,6 @@ class CommonTest : public Test { ...@@ -88,9 +88,6 @@ class CommonTest : public Test {
template <typename T> template <typename T>
T* CommonTest<T>::shared_ = nullptr; T* CommonTest<T>::shared_ = nullptr;
// This #ifdef block tests typed tests.
#if GTEST_HAS_TYPED_TEST
using testing::Types; using testing::Types;
// Tests that SetUpTestSuite()/TearDownTestSuite(), fixture ctor/dtor, // Tests that SetUpTestSuite()/TearDownTestSuite(), fixture ctor/dtor,
...@@ -193,22 +190,17 @@ TYPED_TEST(TypedTestWithNames, TestSuiteName) { ...@@ -193,22 +190,17 @@ TYPED_TEST(TypedTestWithNames, TestSuiteName) {
if (std::is_same<TypeParam, char>::value) { if (std::is_same<TypeParam, char>::value) {
EXPECT_STREQ(::testing::UnitTest::GetInstance() EXPECT_STREQ(::testing::UnitTest::GetInstance()
->current_test_info() ->current_test_info()
->test_case_name(), ->test_suite_name(),
"TypedTestWithNames/char0"); "TypedTestWithNames/char0");
} }
if (std::is_same<TypeParam, int>::value) { if (std::is_same<TypeParam, int>::value) {
EXPECT_STREQ(::testing::UnitTest::GetInstance() EXPECT_STREQ(::testing::UnitTest::GetInstance()
->current_test_info() ->current_test_info()
->test_case_name(), ->test_suite_name(),
"TypedTestWithNames/int1"); "TypedTestWithNames/int1");
} }
} }
#endif // GTEST_HAS_TYPED_TEST
// This #ifdef block tests type-parameterized tests.
#if GTEST_HAS_TYPED_TEST_P
using testing::Types; using testing::Types;
using testing::internal::TypedTestSuitePState; using testing::internal::TypedTestSuitePState;
...@@ -228,7 +220,7 @@ class TypedTestSuitePStateTest : public Test { ...@@ -228,7 +220,7 @@ class TypedTestSuitePStateTest : public Test {
TEST_F(TypedTestSuitePStateTest, SucceedsForMatchingList) { TEST_F(TypedTestSuitePStateTest, SucceedsForMatchingList) {
const char* tests = "A, B, C"; const char* tests = "A, B, C";
EXPECT_EQ(tests, EXPECT_EQ(tests,
state_.VerifyRegisteredTestNames("foo.cc", 1, tests)); state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, tests));
} }
// Makes sure that the order of the tests and spaces around the names // Makes sure that the order of the tests and spaces around the names
...@@ -236,33 +228,33 @@ TEST_F(TypedTestSuitePStateTest, SucceedsForMatchingList) { ...@@ -236,33 +228,33 @@ TEST_F(TypedTestSuitePStateTest, SucceedsForMatchingList) {
TEST_F(TypedTestSuitePStateTest, IgnoresOrderAndSpaces) { TEST_F(TypedTestSuitePStateTest, IgnoresOrderAndSpaces) {
const char* tests = "A,C, B"; const char* tests = "A,C, B";
EXPECT_EQ(tests, EXPECT_EQ(tests,
state_.VerifyRegisteredTestNames("foo.cc", 1, tests)); state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, tests));
} }
using TypedTestSuitePStateDeathTest = TypedTestSuitePStateTest; using TypedTestSuitePStateDeathTest = TypedTestSuitePStateTest;
TEST_F(TypedTestSuitePStateDeathTest, DetectsDuplicates) { TEST_F(TypedTestSuitePStateDeathTest, DetectsDuplicates) {
EXPECT_DEATH_IF_SUPPORTED( EXPECT_DEATH_IF_SUPPORTED(
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, A, C"), state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, B, A, C"),
"foo\\.cc.1.?: Test A is listed more than once\\."); "foo\\.cc.1.?: Test A is listed more than once\\.");
} }
TEST_F(TypedTestSuitePStateDeathTest, DetectsExtraTest) { TEST_F(TypedTestSuitePStateDeathTest, DetectsExtraTest) {
EXPECT_DEATH_IF_SUPPORTED( EXPECT_DEATH_IF_SUPPORTED(
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C, D"), state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, B, C, D"),
"foo\\.cc.1.?: No test named D can be found in this test suite\\."); "foo\\.cc.1.?: No test named D can be found in this test suite\\.");
} }
TEST_F(TypedTestSuitePStateDeathTest, DetectsMissedTest) { TEST_F(TypedTestSuitePStateDeathTest, DetectsMissedTest) {
EXPECT_DEATH_IF_SUPPORTED( EXPECT_DEATH_IF_SUPPORTED(
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, C"), state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, C"),
"foo\\.cc.1.?: You forgot to list test B\\."); "foo\\.cc.1.?: You forgot to list test B\\.");
} }
// Tests that defining a test for a parameterized test case generates // Tests that defining a test for a parameterized test case generates
// a run-time error if the test case has been registered. // a run-time error if the test case has been registered.
TEST_F(TypedTestSuitePStateDeathTest, DetectsTestAfterRegistration) { TEST_F(TypedTestSuitePStateDeathTest, DetectsTestAfterRegistration) {
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C"); state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, B, C");
EXPECT_DEATH_IF_SUPPORTED( EXPECT_DEATH_IF_SUPPORTED(
state_.AddTestName("foo.cc", 2, "FooTest", "D"), state_.AddTestName("foo.cc", 2, "FooTest", "D"),
"foo\\.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_SUITE_P" "foo\\.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_SUITE_P"
...@@ -315,13 +307,13 @@ TYPED_TEST_P(TypeParametrizedTestWithNames, TestSuiteName) { ...@@ -315,13 +307,13 @@ TYPED_TEST_P(TypeParametrizedTestWithNames, TestSuiteName) {
if (std::is_same<TypeParam, char>::value) { if (std::is_same<TypeParam, char>::value) {
EXPECT_STREQ(::testing::UnitTest::GetInstance() EXPECT_STREQ(::testing::UnitTest::GetInstance()
->current_test_info() ->current_test_info()
->test_case_name(), ->test_suite_name(),
"CustomName/TypeParametrizedTestWithNames/parChar0"); "CustomName/TypeParametrizedTestWithNames/parChar0");
} }
if (std::is_same<TypeParam, int>::value) { if (std::is_same<TypeParam, int>::value) {
EXPECT_STREQ(::testing::UnitTest::GetInstance() EXPECT_STREQ(::testing::UnitTest::GetInstance()
->current_test_info() ->current_test_info()
->test_case_name(), ->test_suite_name(),
"CustomName/TypeParametrizedTestWithNames/parInt1"); "CustomName/TypeParametrizedTestWithNames/parInt1");
} }
} }
...@@ -443,20 +435,3 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, TrimmedTest, TrimTypes); ...@@ -443,20 +435,3 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, TrimmedTest, TrimTypes);
} // namespace library2 } // namespace library2
#endif // GTEST_HAS_TYPED_TEST_P
#if !defined(GTEST_HAS_TYPED_TEST) && !defined(GTEST_HAS_TYPED_TEST_P)
// Google Test may not support type-parameterized tests with some
// compilers. If we use conditional compilation to compile out all
// code referring to the gtest_main library, MSVC linker will not link
// that library at all and consequently complain about missing entry
// point defined in that library (fatal error LNK1561: entry point
// must be defined). This dummy test keeps gtest_main linked in.
TEST(DummyTest, TypedTestsAreNotSupportedOnThisPlatform) {}
#if _MSC_VER
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4127
#endif // _MSC_VER
#endif // #if !defined(GTEST_HAS_TYPED_TEST) && !defined(GTEST_HAS_TYPED_TEST_P)
...@@ -27,14 +27,11 @@ ...@@ -27,14 +27,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef GOOGLETEST_TEST_GTEST_TYPED_TEST_TEST_H_
#ifndef GTEST_TEST_GTEST_TYPED_TEST_TEST_H_ #define GOOGLETEST_TEST_GTEST_TYPED_TEST_TEST_H_
#define GTEST_TEST_GTEST_TYPED_TEST_TEST_H_
#include "gtest/gtest.h" #include "gtest/gtest.h"
#if GTEST_HAS_TYPED_TEST_P
using testing::Test; using testing::Test;
// For testing that the same type-parameterized test case can be // For testing that the same type-parameterized test case can be
...@@ -60,6 +57,4 @@ TYPED_TEST_P(ContainerTest, InitialSizeIsZero) { ...@@ -60,6 +57,4 @@ TYPED_TEST_P(ContainerTest, InitialSizeIsZero) {
REGISTER_TYPED_TEST_SUITE_P(ContainerTest, REGISTER_TYPED_TEST_SUITE_P(ContainerTest,
CanBeDefaultConstructed, InitialSizeIsZero); CanBeDefaultConstructed, InitialSizeIsZero);
#endif // GTEST_HAS_TYPED_TEST_P #endif // GOOGLETEST_TEST_GTEST_TYPED_TEST_TEST_H_
#endif // GTEST_TEST_GTEST_TYPED_TEST_TEST_H_
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