Internal change

PiperOrigin-RevId: 508533812
This commit is contained in:
MediaPipe Team 2023-02-09 18:47:23 -08:00 committed by Copybara-Service
parent 1f848c4d69
commit 1eb54bdaa6
3 changed files with 47 additions and 2 deletions

View File

@ -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"],

View File

@ -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()

View File

@ -0,0 +1,30 @@
#include "mediapipe/tasks/cc/core/base_options.h"
#include <string>
#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<std::string>(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