From f15637b62ca1b1b7279a4639085314ffd57a2df4 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Wed, 1 Mar 2023 15:56:17 -0800 Subject: [PATCH] Make Metadata tests pass on Windows PiperOrigin-RevId: 513365428 --- mediapipe/tasks/cc/core/external_file_handler.cc | 2 +- mediapipe/tasks/cc/metadata/tests/BUILD | 1 + .../tasks/cc/metadata/tests/metadata_extractor_test.cc | 6 ++++-- mediapipe/tasks/cc/metadata/tests/metadata_parser_test.cc | 4 ++++ mediapipe/tasks/cc/metadata/tests/metadata_version_test.cc | 4 ++++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/mediapipe/tasks/cc/core/external_file_handler.cc b/mediapipe/tasks/cc/core/external_file_handler.cc index 6081ac1cd..907a19f8b 100644 --- a/mediapipe/tasks/cc/core/external_file_handler.cc +++ b/mediapipe/tasks/cc/core/external_file_handler.cc @@ -29,7 +29,7 @@ limitations under the License. #include #else #include -#endif +#endif // _WIN32 #include #include diff --git a/mediapipe/tasks/cc/metadata/tests/BUILD b/mediapipe/tasks/cc/metadata/tests/BUILD index 2b0e0bc2f..33cbf6b54 100644 --- a/mediapipe/tasks/cc/metadata/tests/BUILD +++ b/mediapipe/tasks/cc/metadata/tests/BUILD @@ -16,6 +16,7 @@ cc_test( "//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:status", "//mediapipe/tasks/cc:common", + "//mediapipe/tasks/cc/core:utils", "//mediapipe/tasks/cc/metadata:metadata_extractor", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", diff --git a/mediapipe/tasks/cc/metadata/tests/metadata_extractor_test.cc b/mediapipe/tasks/cc/metadata/tests/metadata_extractor_test.cc index 4dacc7b8c..41f664158 100644 --- a/mediapipe/tasks/cc/metadata/tests/metadata_extractor_test.cc +++ b/mediapipe/tasks/cc/metadata/tests/metadata_extractor_test.cc @@ -25,12 +25,14 @@ limitations under the License. #include "mediapipe/framework/port/status_macros.h" #include "mediapipe/framework/port/status_matchers.h" #include "mediapipe/tasks/cc/common.h" +#include "mediapipe/tasks/cc/core/utils.h" namespace mediapipe { namespace tasks { namespace metadata { namespace { +using core::LoadBinaryContent; using ::testing::Optional; constexpr char kTestDataDirectory[] = "mediapipe/tasks/testdata/metadata"; @@ -53,8 +55,8 @@ constexpr char kRandomTextFile[] = "external_file"; absl::StatusOr> CreateMetadataExtractor( std::string model_name, std::string* file_contents) { - MP_RETURN_IF_ERROR(file::GetContents( - file::JoinPath("./", kTestDataDirectory, model_name), file_contents)); + *file_contents = LoadBinaryContent( + file::JoinPath("./", kTestDataDirectory, model_name).c_str()); return ModelMetadataExtractor::CreateFromModelBuffer(file_contents->data(), file_contents->length()); } diff --git a/mediapipe/tasks/cc/metadata/tests/metadata_parser_test.cc b/mediapipe/tasks/cc/metadata/tests/metadata_parser_test.cc index 3605648e9..1d2e22cc7 100644 --- a/mediapipe/tasks/cc/metadata/tests/metadata_parser_test.cc +++ b/mediapipe/tasks/cc/metadata/tests/metadata_parser_test.cc @@ -26,7 +26,11 @@ using ::testing::MatchesRegex; TEST(MetadataParserTest, MatadataParserVersionIsWellFormed) { // Validates that the version is well-formed (x.y.z). +#ifdef _WIN32 + EXPECT_THAT(kMatadataParserVersion, MatchesRegex("\\d+\\.\\d+\\.\\d+")); +#else EXPECT_THAT(kMatadataParserVersion, MatchesRegex("[0-9]+\\.[0-9]+\\.[0-9]+")); +#endif // _WIN32 } } // namespace diff --git a/mediapipe/tasks/cc/metadata/tests/metadata_version_test.cc b/mediapipe/tasks/cc/metadata/tests/metadata_version_test.cc index bf6206f38..967853028 100644 --- a/mediapipe/tasks/cc/metadata/tests/metadata_version_test.cc +++ b/mediapipe/tasks/cc/metadata/tests/metadata_version_test.cc @@ -83,7 +83,11 @@ TEST(MetadataVersionTest, builder.GetSize(), &min_version), kTfLiteOk); // Validates that the version is well-formed (x.y.z). +#ifdef _WIN32 + EXPECT_THAT(min_version, MatchesRegex("\\d+\\.\\d+\\.\\d+")); +#else EXPECT_THAT(min_version, MatchesRegex("[0-9]+\\.[0-9]+\\.[0-9]+")); +#endif // _WIN32 } TEST(MetadataVersionTest,