From 1eb54bdaa6ccc04c2b1a0ddceccca5d8525dd8c8 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Thu, 9 Feb 2023 18:47:23 -0800 Subject: [PATCH] Internal change PiperOrigin-RevId: 508533812 --- mediapipe/tasks/cc/core/BUILD | 15 ++++++++++ mediapipe/tasks/cc/core/base_options.cc | 4 +-- mediapipe/tasks/cc/core/base_options_test.cc | 30 ++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 mediapipe/tasks/cc/core/base_options_test.cc diff --git a/mediapipe/tasks/cc/core/BUILD b/mediapipe/tasks/cc/core/BUILD index e5bc18306..9deb38f40 100644 --- a/mediapipe/tasks/cc/core/BUILD +++ b/mediapipe/tasks/cc/core/BUILD @@ -35,6 +35,21 @@ cc_library( ], ) +cc_test( + name = "base_options_test", + srcs = ["base_options_test.cc"], + data = [ + "//mediapipe/tasks/testdata/core:test_models", + ], + deps = [ + ":base_options", + ":utils", + "//mediapipe/framework/port:gtest", + "//mediapipe/tasks/cc/core/proto:external_file_cc_proto", + "@com_google_googletest//:gtest_main", + ], +) + cc_library( name = "external_file_handler", srcs = ["external_file_handler.cc"], diff --git a/mediapipe/tasks/cc/core/base_options.cc b/mediapipe/tasks/cc/core/base_options.cc index 0e3bb7401..02a39081a 100644 --- a/mediapipe/tasks/cc/core/base_options.cc +++ b/mediapipe/tasks/cc/core/base_options.cc @@ -33,8 +33,8 @@ proto::BaseOptions ConvertBaseOptionsToProto(BaseOptions* base_options) { base_options->model_asset_path); } if (base_options->model_asset_buffer) { - base_options_proto.mutable_model_asset()->mutable_file_content()->swap( - *base_options->model_asset_buffer.release()); + base_options_proto.mutable_model_asset()->set_file_content( + std::move(*base_options->model_asset_buffer)); } if (base_options->model_asset_descriptor_meta.fd > 0) { auto* file_descriptor_meta_proto = base_options_proto.mutable_model_asset() diff --git a/mediapipe/tasks/cc/core/base_options_test.cc b/mediapipe/tasks/cc/core/base_options_test.cc new file mode 100644 index 000000000..23eb83d4a --- /dev/null +++ b/mediapipe/tasks/cc/core/base_options_test.cc @@ -0,0 +1,30 @@ +#include "mediapipe/tasks/cc/core/base_options.h" + +#include + +#include "mediapipe/framework/port/gmock.h" +#include "mediapipe/framework/port/gtest.h" +#include "mediapipe/tasks/cc/core/proto/external_file.pb.h" +#include "mediapipe/tasks/cc/core/utils.h" + +constexpr char kTestModelBundlePath[] = + "mediapipe/tasks/testdata/core/dummy_gesture_recognizer.task"; + +namespace mediapipe { +namespace tasks { +namespace core { +namespace { + +TEST(BaseOptionsTest, ConverBaseOptionsToProtoWithFile) { + BaseOptions base_options; + base_options.model_asset_buffer = + std::make_unique(LoadBinaryContent(kTestModelBundlePath)); + proto::BaseOptions proto = ConvertBaseOptionsToProto(&base_options); + EXPECT_TRUE(proto.has_model_asset()); + EXPECT_TRUE(proto.model_asset().has_file_content()); +} + +} // namespace +} // namespace core +} // namespace tasks +} // namespace mediapipe