Abrogate protos::Parse with hpb::Parse

PiperOrigin-RevId: 667643856
pull/17897/head
Hong Shin 3 months ago committed by Copybara-Service
parent 9d3391f183
commit d4fc727be4
  1. 3
      hpb/internal/message_lock_test.cc
  2. 18
      hpb_generator/tests/test_generated.cc
  3. 1
      protos/protos.h

@ -58,8 +58,7 @@ void TestConcurrentExtensionAccess(::hpb::ExtensionRegistry registry) {
::hpb::internal::upb_extension_locker_global.store(&lock_func, ::hpb::internal::upb_extension_locker_global.store(&lock_func,
std::memory_order_release); std::memory_order_release);
const std::string payload = GenerateTestData(); const std::string payload = GenerateTestData();
TestModel parsed_model = TestModel parsed_model = ::hpb::Parse<TestModel>(payload, registry).value();
::protos::Parse<TestModel>(payload, registry).value();
const auto test_main = [&] { EXPECT_EQ("str", parsed_model.str1()); }; const auto test_main = [&] { EXPECT_EQ("str", parsed_model.str1()); };
const auto test_theme = [&] { const auto test_theme = [&] {
ASSERT_TRUE(::hpb::HasExtension(&parsed_model, theme)); ASSERT_TRUE(::hpb::HasExtension(&parsed_model, theme));

@ -888,7 +888,7 @@ TEST(CppGeneratedCode, SerializeUsingArena) {
::upb::Arena arena; ::upb::Arena arena;
absl::StatusOr<absl::string_view> bytes = ::hpb::Serialize(&model, arena); absl::StatusOr<absl::string_view> bytes = ::hpb::Serialize(&model, arena);
EXPECT_EQ(true, bytes.ok()); EXPECT_EQ(true, bytes.ok());
TestModel parsed_model = ::protos::Parse<TestModel>(bytes.value()).value(); TestModel parsed_model = ::hpb::Parse<TestModel>(bytes.value()).value();
EXPECT_EQ("Hello World", parsed_model.str1()); EXPECT_EQ("Hello World", parsed_model.str1());
} }
@ -900,7 +900,7 @@ TEST(CppGeneratedCode, SerializeProxyUsingArena) {
absl::StatusOr<absl::string_view> bytes = absl::StatusOr<absl::string_view> bytes =
::hpb::Serialize(&model_proxy, arena); ::hpb::Serialize(&model_proxy, arena);
EXPECT_EQ(true, bytes.ok()); EXPECT_EQ(true, bytes.ok());
TestModel parsed_model = ::protos::Parse<TestModel>(bytes.value()).value(); TestModel parsed_model = ::hpb::Parse<TestModel>(bytes.value()).value();
EXPECT_EQ("Hello World", parsed_model.str1()); EXPECT_EQ("Hello World", parsed_model.str1());
} }
@ -911,7 +911,7 @@ TEST(CppGeneratedCode, SerializeNestedMessageUsingArena) {
::hpb::Ptr<const TestModel> child = model.recursive_child(); ::hpb::Ptr<const TestModel> child = model.recursive_child();
absl::StatusOr<absl::string_view> bytes = ::hpb::Serialize(child, arena); absl::StatusOr<absl::string_view> bytes = ::hpb::Serialize(child, arena);
EXPECT_EQ(true, bytes.ok()); EXPECT_EQ(true, bytes.ok());
TestModel parsed_model = ::protos::Parse<TestModel>(bytes.value()).value(); TestModel parsed_model = ::hpb::Parse<TestModel>(bytes.value()).value();
EXPECT_EQ("Hello World", parsed_model.str1()); EXPECT_EQ("Hello World", parsed_model.str1());
} }
@ -924,7 +924,7 @@ TEST(CppGeneratedCode, Parse) {
::upb::Arena arena; ::upb::Arena arena;
auto bytes = ::hpb::Serialize(&model, arena); auto bytes = ::hpb::Serialize(&model, arena);
EXPECT_EQ(true, bytes.ok()); EXPECT_EQ(true, bytes.ok());
TestModel parsed_model = ::protos::Parse<TestModel>(bytes.value()).value(); TestModel parsed_model = ::hpb::Parse<TestModel>(bytes.value()).value();
EXPECT_EQ("Test123", parsed_model.str1()); EXPECT_EQ("Test123", parsed_model.str1());
EXPECT_EQ(true, ::protos::GetExtension(&parsed_model, theme).ok()); EXPECT_EQ(true, ::protos::GetExtension(&parsed_model, theme).ok());
} }
@ -939,7 +939,7 @@ TEST(CppGeneratedCode, ParseIntoPtrToModel) {
auto bytes = ::hpb::Serialize(&model, arena); auto bytes = ::hpb::Serialize(&model, arena);
EXPECT_EQ(true, bytes.ok()); EXPECT_EQ(true, bytes.ok());
::hpb::Ptr<TestModel> parsed_model = ::hpb::CreateMessage<TestModel>(arena); ::hpb::Ptr<TestModel> parsed_model = ::hpb::CreateMessage<TestModel>(arena);
EXPECT_TRUE(::protos::Parse(parsed_model, bytes.value())); EXPECT_TRUE(::hpb::Parse(parsed_model, bytes.value()));
EXPECT_EQ("Test123", parsed_model->str1()); EXPECT_EQ("Test123", parsed_model->str1());
// Should return an extension even if we don't pass ExtensionRegistry // Should return an extension even if we don't pass ExtensionRegistry
// by promoting unknown. // by promoting unknown.
@ -961,7 +961,7 @@ TEST(CppGeneratedCode, ParseWithExtensionRegistry) {
::hpb::ExtensionRegistry extensions( ::hpb::ExtensionRegistry extensions(
{&theme, &other_ext, &ThemeExtension::theme_extension}, arena); {&theme, &other_ext, &ThemeExtension::theme_extension}, arena);
TestModel parsed_model = TestModel parsed_model =
::protos::Parse<TestModel>(bytes.value(), extensions).value(); ::hpb::Parse<TestModel>(bytes.value(), extensions).value();
EXPECT_EQ("Test123", parsed_model.str1()); EXPECT_EQ("Test123", parsed_model.str1());
EXPECT_EQ(true, ::protos::GetExtension(&parsed_model, theme).ok()); EXPECT_EQ(true, ::protos::GetExtension(&parsed_model, theme).ok());
EXPECT_EQ(true, ::protos::GetExtension(&parsed_model, EXPECT_EQ(true, ::protos::GetExtension(&parsed_model,
@ -985,14 +985,14 @@ TEST(CppGeneratedCode, SharedPointer) {
std::shared_ptr<TestModel> model = std::make_shared<TestModel>(); std::shared_ptr<TestModel> model = std::make_shared<TestModel>();
::upb::Arena arena; ::upb::Arena arena;
auto bytes = ::hpb::Serialize(model.get(), arena); auto bytes = ::hpb::Serialize(model.get(), arena);
EXPECT_TRUE(::protos::Parse(model.get(), bytes.value())); EXPECT_TRUE(::hpb::Parse(model.get(), bytes.value()));
} }
TEST(CppGeneratedCode, UniquePointer) { TEST(CppGeneratedCode, UniquePointer) {
auto model = std::make_unique<TestModel>(); auto model = std::make_unique<TestModel>();
::upb::Arena arena; ::upb::Arena arena;
auto bytes = ::hpb::Serialize(model.get(), arena); auto bytes = ::hpb::Serialize(model.get(), arena);
EXPECT_TRUE(::protos::Parse(model.get(), bytes.value())); EXPECT_TRUE(::hpb::Parse(model.get(), bytes.value()));
} }
TEST(CppGeneratedCode, Assignment) { TEST(CppGeneratedCode, Assignment) {
@ -1224,7 +1224,7 @@ TEST(CppGeneratedCode, HasExtensionAndRegistry) {
// Test with ExtensionRegistry // Test with ExtensionRegistry
::hpb::ExtensionRegistry extensions({&theme}, arena); ::hpb::ExtensionRegistry extensions({&theme}, arena);
TestModel parsed_model = ::protos::Parse<TestModel>(data, extensions).value(); TestModel parsed_model = ::hpb::Parse<TestModel>(data, extensions).value();
EXPECT_TRUE(::hpb::HasExtension(&parsed_model, theme)); EXPECT_TRUE(::hpb::HasExtension(&parsed_model, theme));
} }

@ -21,7 +21,6 @@ typename T::CProxy CreateMessage(const upb_Message* msg, upb_Arena* arena) {
return hpb::interop::upb::MakeCHandle<T>(msg, arena); return hpb::interop::upb::MakeCHandle<T>(msg, arena);
} }
} // namespace internal } // namespace internal
using hpb::Parse;
using hpb::Serialize; using hpb::Serialize;
using hpb::GetExtension; using hpb::GetExtension;

Loading…
Cancel
Save