Protocol Buffers - Google's data interchange format (grpc依赖)
https://developers.google.com/protocol-buffers/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.3 KiB
37 lines
1.3 KiB
1 year ago
|
// Protocol Buffers - Google's data interchange format
|
||
|
// Copyright 2023 Google LLC. All rights reserved.
|
||
2 years ago
|
//
|
||
1 year ago
|
// Use of this source code is governed by a BSD-style
|
||
|
// license that can be found in the LICENSE file or at
|
||
|
// https://developers.google.com/open-source/licenses/bsd
|
||
2 years ago
|
|
||
3 months ago
|
#include "google/protobuf/hpb/backend/upb/interop.h"
|
||
2 years ago
|
|
||
1 year ago
|
#include <gtest/gtest.h>
|
||
5 months ago
|
#include "google/protobuf/compiler/hpb/tests/test_model.upb.h"
|
||
|
#include "google/protobuf/compiler/hpb/tests/test_model.upb.proto.h"
|
||
1 year ago
|
#include "upb/mem/arena.h"
|
||
3 months ago
|
#include "upb/message/message.h"
|
||
2 years ago
|
|
||
5 months ago
|
namespace hpb::testing {
|
||
2 years ago
|
namespace {
|
||
5 months ago
|
using ::hpb_unittest::protos::TestModel;
|
||
2 years ago
|
|
||
3 months ago
|
TEST(CppGeneratedCode, InteropMoveMessage) {
|
||
2 years ago
|
// Generate message (simulating message created in another VM/language)
|
||
|
upb_Arena* source_arena = upb_Arena_New();
|
||
5 months ago
|
hpb_unittest_TestModel* message = hpb_unittest_TestModel_new(source_arena);
|
||
2 years ago
|
ASSERT_NE(message, nullptr);
|
||
5 months ago
|
hpb_unittest_TestModel_set_int_value_with_default(message, 123);
|
||
2 years ago
|
|
||
|
// Move ownership.
|
||
3 months ago
|
TestModel model = hpb::interop::upb::MoveMessage<TestModel>(
|
||
|
(upb_Message*)message, source_arena);
|
||
2 years ago
|
// Now that we have moved ownership, free original arena.
|
||
|
upb_Arena_Free(source_arena);
|
||
|
EXPECT_EQ(model.int_value_with_default(), 123);
|
||
|
}
|
||
|
|
||
|
} // namespace
|
||
5 months ago
|
} // namespace hpb::testing
|