From d4e084a1cc1b9d86f34b410bc43d1a5b6739427d Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 4 Nov 2021 16:44:06 -0400 Subject: [PATCH 1/7] Googletest export Style only change. Make use of advanced testing functions `FloatLE` and `DoubleLE` consistent. PiperOrigin-RevId: 407660542 --- docs/advanced.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/advanced.md b/docs/advanced.md index b18be2dc..71148572 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -157,8 +157,11 @@ that can be used in the predicate assertion macro example: ```c++ -EXPECT_PRED_FORMAT2(testing::FloatLE, val1, val2); -EXPECT_PRED_FORMAT2(testing::DoubleLE, val1, val2); +using ::testing::FloatLE; +using ::testing::DoubleLE; +... +EXPECT_PRED_FORMAT2(FloatLE, val1, val2); +EXPECT_PRED_FORMAT2(DoubleLE, val1, val2); ``` The above code verifies that `val1` is less than, or approximately equal to, From c3792825bfb11490a61caa088692be95944c1faf Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 8 Nov 2021 13:12:33 -0500 Subject: [PATCH 2/7] Googletest export Add printer for std::type_info. PiperOrigin-RevId: 408375407 --- googletest/include/gtest/gtest-printers.h | 6 ++++++ googletest/test/googletest-printers-test.cc | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index a28843d1..e07b537d 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -591,6 +591,12 @@ inline void PrintTo(internal::StringView sp, ::std::ostream* os) { inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; } +#if GTEST_HAS_RTTI +inline void PrintTo(const std::type_info& info, std::ostream* os) { + *os << internal::GetTypeName(info); +} +#endif // GTEST_HAS_RTTI + template void PrintTo(std::reference_wrapper ref, ::std::ostream* os) { UniversalPrinter::Print(ref.get(), os); diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index eb78eabc..0058917a 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -473,6 +473,16 @@ TEST(PrintBuiltInTypeTest, FloatingPoints) { EXPECT_EQ("-2.5", Print(-2.5)); // double } +#if GTEST_HAS_RTTI +TEST(PrintBuiltInTypeTest, TypeInfo) { + struct MyStruct {}; + auto res = Print(typeid(MyStruct{})); + // We can't guarantee that we can demangle the name, but either name should + // contain the substring "MyStruct". + EXPECT_NE(res.find("MyStruct"), res.npos) << res; +} +#endif // GTEST_HAS_RTTI + // Since ::std::stringstream::operator<<(const void *) formats the pointer // output differently with different compilers, we have to create the expected // output first and use it as our expectation. From aa486f165e982e82e2112d20a7561f64736d4b42 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 8 Nov 2021 13:49:32 -0500 Subject: [PATCH 3/7] Googletest export Add missing InitGoogleTest line in "Registering tests" example code Copying the original code gives the following error message """ IMPORTANT NOTICE - DO NOT IGNORE: This test program did NOT call testing::InitGoogleTest() before calling RUN_ALL_TESTS(). This is INVALID. Soon Google Test will start to enforce the valid usage. Please fix it ASAP, or IT WILL START TO FAIL. """ PiperOrigin-RevId: 408385714 --- docs/advanced.md | 1 + googletest/include/gtest/gtest.h | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/advanced.md b/docs/advanced.md index 71148572..f2f8854b 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -1597,6 +1597,7 @@ void RegisterMyTests(const std::vector& values) { } ... int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); std::vector values_to_test = LoadValuesFromConfig(); RegisterMyTests(values_to_test); ... diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index cdde1aa4..1bb9decc 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -2451,6 +2451,7 @@ GTEST_API_ std::string TempDir(); // } // ... // int main(int argc, char** argv) { +// ::testing::InitGoogleTest(&argc, argv); // std::vector values_to_test = LoadValuesFromConfig(); // RegisterMyTests(values_to_test); // ... From 79efd968bf7edb60667314750e101bbf99a0494e Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 9 Nov 2021 14:36:57 -0500 Subject: [PATCH 4/7] Googletest export Update example for SetUpTestSuite/TearDownTestSuite to use modern C++ standards. Currently it is using an outdated C++ construct (defining static member variables separately from the declaration). PiperOrigin-RevId: 408663014 --- docs/advanced.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/advanced.md b/docs/advanced.md index f2f8854b..aea4feec 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -926,11 +926,9 @@ class FooTest : public testing::Test { void TearDown() override { ... } // Some expensive resource shared by all tests. - static T* shared_resource_; + static T* shared_resource_ = nullptr; }; -T* FooTest::shared_resource_ = nullptr; - TEST_F(FooTest, Test1) { ... you can refer to shared_resource_ here ... } From e4ffd4d715c2cf4b431d04f11cf144e575bc0823 Mon Sep 17 00:00:00 2001 From: Mario Emmenlauer Date: Wed, 10 Nov 2021 13:20:14 +0100 Subject: [PATCH 5/7] googletest/src/gtest-port.cc: Added GetLastError() on Windows for CreateThread() --- googletest/src/gtest-port.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index f63625b5..5ee77403 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -629,7 +629,8 @@ class ThreadLocalRegistryImpl { &ThreadLocalRegistryImpl::WatcherThreadFunc, reinterpret_cast(new ThreadIdAndHandle(thread_id, thread)), CREATE_SUSPENDED, &watcher_thread_id); - GTEST_CHECK_(watcher_thread != nullptr); + GTEST_CHECK_(watcher_thread != nullptr) + << "CreateThread failed with error " << ::GetLastError() << "."; // Give the watcher thread the same priority as ours to avoid being // blocked by it. ::SetThreadPriority(watcher_thread, From 6c8a386513b70cb43df997b6406ae5c39f5c9b88 Mon Sep 17 00:00:00 2001 From: dmauro Date: Tue, 9 Nov 2021 16:35:30 -0500 Subject: [PATCH 6/7] Googletest export Explicitly used unsigned chars for testing for valid XML characters PiperOrigin-RevId: 408692969 --- googletest/src/gtest.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 3eb9505f..103c4457 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -3934,12 +3934,13 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener { private: // Is c a whitespace character that is normalized to a space character // when it appears in an XML attribute value? - static bool IsNormalizableWhitespace(char c) { - return c == 0x9 || c == 0xA || c == 0xD; + static bool IsNormalizableWhitespace(unsigned char c) { + return c == '\t' || c == '\n' || c == '\r'; } // May c appear in a well-formed XML document? - static bool IsValidXmlCharacter(char c) { + // https://www.w3.org/TR/REC-xml/#charsets + static bool IsValidXmlCharacter(unsigned char c) { return IsNormalizableWhitespace(c) || c >= 0x20; } From 9ca071b6e55568dff6960bebe1a5cfaa180fb3ce Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 10 Nov 2021 13:21:58 -0500 Subject: [PATCH 7/7] Googletest export Revert CL that updated example for SetUpTestSuite/TearDownTestSuite to initialize static member variables inline. It seems that non-const static data members for some reason still must be initialized out-of-line. PiperOrigin-RevId: 408913846 --- docs/advanced.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/advanced.md b/docs/advanced.md index aea4feec..f2f8854b 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -926,9 +926,11 @@ class FooTest : public testing::Test { void TearDown() override { ... } // Some expensive resource shared by all tests. - static T* shared_resource_ = nullptr; + static T* shared_resource_; }; +T* FooTest::shared_resource_ = nullptr; + TEST_F(FooTest, Test1) { ... you can refer to shared_resource_ here ... }