From 625bc4d11df5e6fe58965bd9f188babf33aff224 Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Fri, 18 Mar 2022 22:26:32 +0100 Subject: [PATCH] Refactor code to avoid GTest GetCapturedStderr it's the same approach as in parser_TEST.cc --- src/SDF_TEST.cc | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/SDF_TEST.cc b/src/SDF_TEST.cc index b9e45db43..a04a5a6ef 100644 --- a/src/SDF_TEST.cc +++ b/src/SDF_TEST.cc @@ -542,7 +542,6 @@ TEST(SDF, Version) TEST(SDF, EmbeddedSpec) { std::string result; - std::string output; result = sdf::SDF::EmbeddedSpec("actor.sdf", false); EXPECT_NE(result.find(""), std::string::npos); @@ -562,21 +561,32 @@ TEST(SDF, EmbeddedSpec) TEST(SDF, EmbeddedSpecNonExistent) { std::string result; - std::string output; - testing::internal::CaptureStderr(); + // Capture sdferr output + std::stringstream stderr_buffer; + auto old = std::cerr.rdbuf(stderr_buffer.rdbuf()); + +#ifdef _WIN32 + sdf::Console::Instance()->SetQuiet(false); +#endif + result = sdf::SDF::EmbeddedSpec("unavailable.sdf", false); - output = testing::internal::GetCapturedStderr(); - EXPECT_NE(output.find("Unable to find SDF filename"), std::string::npos); - EXPECT_NE(output.find("with version"), std::string::npos); + EXPECT_NE(stderr_buffer.str().find("Unable to find SDF filename"), std::string::npos); + EXPECT_NE(stderr_buffer.str().find("with version"), std::string::npos); EXPECT_TRUE(result.empty()); - output = ""; - testing::internal::CaptureStderr(); + // clear the contents of the buffer + stderr_buffer.str(""); + result = sdf::SDF::EmbeddedSpec("unavailable.sdf", true); - output = testing::internal::GetCapturedStderr(); - EXPECT_TRUE(output.empty()); + EXPECT_TRUE(stderr_buffer.str().empty()); EXPECT_TRUE(result.empty()); + + // Revert cerr rdbuf to not interfere with other tests + std::cerr.rdbuf(old); +#ifdef _WIN32 + sdf::Console::Instance()->SetQuiet(true); +#endif } /////////////////////////////////////////////////