From 0433771cf6abd2e489679c292ef6b7092eb2253e Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Thu, 17 Mar 2022 14:22:51 +0100 Subject: [PATCH] Add unittest for EmbeddedSpec for non-existing mappings this uses internal functions from GoogleTests to capture the stderr message but according to the documentation it should be fine to use them: // All macros ending with _ and symbols defined in an // internal namespace are subject to change without notice. Code // outside Google Test MUST NOT USE THEM DIRECTLY. Macros that don't // end with _ are part of Google Test's public API and can be used by // code outside Google Test. see https://github.com/google/googletest/blob/main/googletest/include/gtest/internal/gtest-port.h Signed-off-by: Bi0T1N --- src/SDF_TEST.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/SDF_TEST.cc b/src/SDF_TEST.cc index 89dc3d431..ea1890511 100644 --- a/src/SDF_TEST.cc +++ b/src/SDF_TEST.cc @@ -559,6 +559,26 @@ TEST(SDF, EmbeddedSpec) EXPECT_NE(result.find("name=\"version\" type=\"string\""), std::string::npos); } +TEST(SDF, EmbeddedSpecNonExistent) +{ + std::string result; + std::string output; + + testing::internal::CaptureStderr(); + 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_TRUE(result.empty()); + + output = ""; + testing::internal::CaptureStderr(); + result = sdf::SDF::EmbeddedSpec("unavailable.sdf", true); + output = testing::internal::GetCapturedStderr(); + EXPECT_TRUE(output.empty()); + EXPECT_TRUE(result.empty()); +} + ///////////////////////////////////////////////// TEST(SDF, FilePath) {