Make Metadata tests pass on Windows

PiperOrigin-RevId: 513365428
This commit is contained in:
Sebastian Schmidt 2023-03-01 15:56:17 -08:00 committed by Copybara-Service
parent 82ee00f25d
commit f15637b62c
5 changed files with 14 additions and 3 deletions

View File

@ -29,7 +29,7 @@ limitations under the License.
#include <windows.h> #include <windows.h>
#else #else
#include <unistd.h> #include <unistd.h>
#endif #endif // _WIN32
#include <memory> #include <memory>
#include <string> #include <string>

View File

@ -16,6 +16,7 @@ cc_test(
"//mediapipe/framework/port:gtest_main", "//mediapipe/framework/port:gtest_main",
"//mediapipe/framework/port:status", "//mediapipe/framework/port:status",
"//mediapipe/tasks/cc:common", "//mediapipe/tasks/cc:common",
"//mediapipe/tasks/cc/core:utils",
"//mediapipe/tasks/cc/metadata:metadata_extractor", "//mediapipe/tasks/cc/metadata:metadata_extractor",
"@com_google_absl//absl/status", "@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor", "@com_google_absl//absl/status:statusor",

View File

@ -25,12 +25,14 @@ limitations under the License.
#include "mediapipe/framework/port/status_macros.h" #include "mediapipe/framework/port/status_macros.h"
#include "mediapipe/framework/port/status_matchers.h" #include "mediapipe/framework/port/status_matchers.h"
#include "mediapipe/tasks/cc/common.h" #include "mediapipe/tasks/cc/common.h"
#include "mediapipe/tasks/cc/core/utils.h"
namespace mediapipe { namespace mediapipe {
namespace tasks { namespace tasks {
namespace metadata { namespace metadata {
namespace { namespace {
using core::LoadBinaryContent;
using ::testing::Optional; using ::testing::Optional;
constexpr char kTestDataDirectory[] = "mediapipe/tasks/testdata/metadata"; constexpr char kTestDataDirectory[] = "mediapipe/tasks/testdata/metadata";
@ -53,8 +55,8 @@ constexpr char kRandomTextFile[] = "external_file";
absl::StatusOr<std::unique_ptr<ModelMetadataExtractor>> CreateMetadataExtractor( absl::StatusOr<std::unique_ptr<ModelMetadataExtractor>> CreateMetadataExtractor(
std::string model_name, std::string* file_contents) { std::string model_name, std::string* file_contents) {
MP_RETURN_IF_ERROR(file::GetContents( *file_contents = LoadBinaryContent(
file::JoinPath("./", kTestDataDirectory, model_name), file_contents)); file::JoinPath("./", kTestDataDirectory, model_name).c_str());
return ModelMetadataExtractor::CreateFromModelBuffer(file_contents->data(), return ModelMetadataExtractor::CreateFromModelBuffer(file_contents->data(),
file_contents->length()); file_contents->length());
} }

View File

@ -26,7 +26,11 @@ using ::testing::MatchesRegex;
TEST(MetadataParserTest, MatadataParserVersionIsWellFormed) { TEST(MetadataParserTest, MatadataParserVersionIsWellFormed) {
// Validates that the version is well-formed (x.y.z). // 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]+")); EXPECT_THAT(kMatadataParserVersion, MatchesRegex("[0-9]+\\.[0-9]+\\.[0-9]+"));
#endif // _WIN32
} }
} // namespace } // namespace

View File

@ -83,7 +83,11 @@ TEST(MetadataVersionTest,
builder.GetSize(), &min_version), builder.GetSize(), &min_version),
kTfLiteOk); kTfLiteOk);
// Validates that the version is well-formed (x.y.z). // 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]+")); EXPECT_THAT(min_version, MatchesRegex("[0-9]+\\.[0-9]+\\.[0-9]+"));
#endif // _WIN32
} }
TEST(MetadataVersionTest, TEST(MetadataVersionTest,