mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
upb: first attempt at implementing name mangling for minitable symbols
PiperOrigin-RevId: 571636273
This commit is contained in:
parent
99e659c1e0
commit
5b6543edb5
16 changed files with 195 additions and 92 deletions
|
|
@ -369,7 +369,7 @@ static PyObject* PyUpb_Descriptor_GetOneofs(PyObject* _self, void* closure) {
|
|||
static PyObject* PyUpb_Descriptor_GetOptions(PyObject* _self, PyObject* args) {
|
||||
PyUpb_DescriptorBase* self = (void*)_self;
|
||||
return PyUpb_DescriptorBase_GetOptions(
|
||||
self, upb_MessageDef_Options(self->def), &google_protobuf_MessageOptions_msg_init,
|
||||
self, upb_MessageDef_Options(self->def), &google__protobuf__MessageOptions_msg_init,
|
||||
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".MessageOptions");
|
||||
}
|
||||
|
||||
|
|
@ -377,7 +377,7 @@ static PyObject* PyUpb_Descriptor_CopyToProto(PyObject* _self,
|
|||
PyObject* py_proto) {
|
||||
return PyUpb_DescriptorBase_CopyToProto(
|
||||
_self, (PyUpb_ToProto_Func*)&upb_MessageDef_ToProto,
|
||||
&google_protobuf_DescriptorProto_msg_init,
|
||||
&google__protobuf__DescriptorProto_msg_init,
|
||||
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".DescriptorProto", py_proto);
|
||||
}
|
||||
|
||||
|
|
@ -793,7 +793,7 @@ static PyObject* PyUpb_EnumDescriptor_GetOptions(PyObject* _self,
|
|||
PyObject* args) {
|
||||
PyUpb_DescriptorBase* self = (void*)_self;
|
||||
return PyUpb_DescriptorBase_GetOptions(
|
||||
self, upb_EnumDef_Options(self->def), &google_protobuf_EnumOptions_msg_init,
|
||||
self, upb_EnumDef_Options(self->def), &google__protobuf__EnumOptions_msg_init,
|
||||
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".EnumOptions");
|
||||
}
|
||||
|
||||
|
|
@ -801,7 +801,7 @@ static PyObject* PyUpb_EnumDescriptor_CopyToProto(PyObject* _self,
|
|||
PyObject* py_proto) {
|
||||
return PyUpb_DescriptorBase_CopyToProto(
|
||||
_self, (PyUpb_ToProto_Func*)&upb_EnumDef_ToProto,
|
||||
&google_protobuf_EnumDescriptorProto_msg_init,
|
||||
&google__protobuf__EnumDescriptorProto_msg_init,
|
||||
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".EnumDescriptorProto", py_proto);
|
||||
}
|
||||
|
||||
|
|
@ -884,7 +884,7 @@ static PyObject* PyUpb_EnumValueDescriptor_GetOptions(PyObject* _self,
|
|||
PyUpb_DescriptorBase* self = (void*)_self;
|
||||
return PyUpb_DescriptorBase_GetOptions(
|
||||
self, upb_EnumValueDef_Options(self->def),
|
||||
&google_protobuf_EnumValueOptions_msg_init,
|
||||
&google__protobuf__EnumValueOptions_msg_init,
|
||||
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".EnumValueOptions");
|
||||
}
|
||||
|
||||
|
|
@ -1084,7 +1084,7 @@ static PyObject* PyUpb_FieldDescriptor_GetOptions(PyObject* _self,
|
|||
PyObject* args) {
|
||||
PyUpb_DescriptorBase* self = (void*)_self;
|
||||
return PyUpb_DescriptorBase_GetOptions(
|
||||
self, upb_FieldDef_Options(self->def), &google_protobuf_FieldOptions_msg_init,
|
||||
self, upb_FieldDef_Options(self->def), &google__protobuf__FieldOptions_msg_init,
|
||||
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".FieldOptions");
|
||||
}
|
||||
|
||||
|
|
@ -1222,7 +1222,7 @@ static PyObject* PyUpb_FileDescriptor_GetSerializedPb(PyObject* self,
|
|||
void* closure) {
|
||||
return PyUpb_DescriptorBase_GetSerializedProto(
|
||||
self, (PyUpb_ToProto_Func*)&upb_FileDef_ToProto,
|
||||
&google_protobuf_FileDescriptorProto_msg_init);
|
||||
&google__protobuf__FileDescriptorProto_msg_init);
|
||||
}
|
||||
|
||||
static PyObject* PyUpb_FileDescriptor_GetMessageTypesByName(PyObject* _self,
|
||||
|
|
@ -1325,7 +1325,7 @@ static PyObject* PyUpb_FileDescriptor_GetOptions(PyObject* _self,
|
|||
PyObject* args) {
|
||||
PyUpb_DescriptorBase* self = (void*)_self;
|
||||
return PyUpb_DescriptorBase_GetOptions(
|
||||
self, upb_FileDef_Options(self->def), &google_protobuf_FileOptions_msg_init,
|
||||
self, upb_FileDef_Options(self->def), &google__protobuf__FileOptions_msg_init,
|
||||
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".FileOptions");
|
||||
}
|
||||
|
||||
|
|
@ -1333,7 +1333,7 @@ static PyObject* PyUpb_FileDescriptor_CopyToProto(PyObject* _self,
|
|||
PyObject* py_proto) {
|
||||
return PyUpb_DescriptorBase_CopyToProto(
|
||||
_self, (PyUpb_ToProto_Func*)&upb_FileDef_ToProto,
|
||||
&google_protobuf_FileDescriptorProto_msg_init,
|
||||
&google__protobuf__FileDescriptorProto_msg_init,
|
||||
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".FileDescriptorProto", py_proto);
|
||||
}
|
||||
|
||||
|
|
@ -1445,7 +1445,7 @@ static PyObject* PyUpb_MethodDescriptor_GetOptions(PyObject* _self,
|
|||
PyObject* args) {
|
||||
PyUpb_DescriptorBase* self = (void*)_self;
|
||||
return PyUpb_DescriptorBase_GetOptions(
|
||||
self, upb_MethodDef_Options(self->def), &google_protobuf_MethodOptions_msg_init,
|
||||
self, upb_MethodDef_Options(self->def), &google__protobuf__MethodOptions_msg_init,
|
||||
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".MethodOptions");
|
||||
}
|
||||
|
||||
|
|
@ -1453,7 +1453,7 @@ static PyObject* PyUpb_MethodDescriptor_CopyToProto(PyObject* _self,
|
|||
PyObject* py_proto) {
|
||||
return PyUpb_DescriptorBase_CopyToProto(
|
||||
_self, (PyUpb_ToProto_Func*)&upb_MethodDef_ToProto,
|
||||
&google_protobuf_MethodDescriptorProto_msg_init,
|
||||
&google__protobuf__MethodDescriptorProto_msg_init,
|
||||
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".MethodDescriptorProto", py_proto);
|
||||
}
|
||||
|
||||
|
|
@ -1549,7 +1549,7 @@ static PyObject* PyUpb_OneofDescriptor_GetOptions(PyObject* _self,
|
|||
PyObject* args) {
|
||||
PyUpb_DescriptorBase* self = (void*)_self;
|
||||
return PyUpb_DescriptorBase_GetOptions(
|
||||
self, upb_OneofDef_Options(self->def), &google_protobuf_OneofOptions_msg_init,
|
||||
self, upb_OneofDef_Options(self->def), &google__protobuf__OneofOptions_msg_init,
|
||||
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".OneofOptions");
|
||||
}
|
||||
|
||||
|
|
@ -1649,7 +1649,7 @@ static PyObject* PyUpb_ServiceDescriptor_GetOptions(PyObject* _self,
|
|||
PyObject* args) {
|
||||
PyUpb_DescriptorBase* self = (void*)_self;
|
||||
return PyUpb_DescriptorBase_GetOptions(
|
||||
self, upb_ServiceDef_Options(self->def), &google_protobuf_ServiceOptions_msg_init,
|
||||
self, upb_ServiceDef_Options(self->def), &google__protobuf__ServiceOptions_msg_init,
|
||||
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".ServiceOptions");
|
||||
}
|
||||
|
||||
|
|
@ -1657,7 +1657,7 @@ static PyObject* PyUpb_ServiceDescriptor_CopyToProto(PyObject* _self,
|
|||
PyObject* py_proto) {
|
||||
return PyUpb_DescriptorBase_CopyToProto(
|
||||
_self, (PyUpb_ToProto_Func*)&upb_ServiceDef_ToProto,
|
||||
&google_protobuf_ServiceDescriptorProto_msg_init,
|
||||
&google__protobuf__ServiceDescriptorProto_msg_init,
|
||||
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".ServiceDescriptorProto", py_proto);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@
|
|||
# https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
load("//bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
|
||||
load(
|
||||
"//bazel:upb_minitable_proto_library.bzl",
|
||||
"upb_minitable_proto_library",
|
||||
)
|
||||
load(
|
||||
"//bazel:upb_proto_library.bzl",
|
||||
"upb_proto_library",
|
||||
|
|
@ -154,11 +158,11 @@ cc_library(
|
|||
":accessors_internal",
|
||||
":internal",
|
||||
":message",
|
||||
":tagged_ptr",
|
||||
":types",
|
||||
"//upb:base",
|
||||
"//upb:eps_copy_input_stream",
|
||||
"//upb:mem",
|
||||
"//upb:message_tagged_ptr",
|
||||
"//upb:mini_table",
|
||||
"//upb:mini_table_internal",
|
||||
"//upb:port",
|
||||
|
|
@ -225,6 +229,12 @@ proto_library(
|
|||
deps = ["//src/google/protobuf:test_messages_proto3_proto"],
|
||||
)
|
||||
|
||||
upb_minitable_proto_library(
|
||||
name = "message_test_upb_minitable_proto",
|
||||
testonly = 1,
|
||||
deps = [":message_test_proto"],
|
||||
)
|
||||
|
||||
upb_proto_library(
|
||||
name = "message_test_upb_proto",
|
||||
testonly = 1,
|
||||
|
|
@ -246,12 +256,15 @@ cc_test(
|
|||
"//:protobuf",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
"//upb:base",
|
||||
"//upb:mem",
|
||||
"//upb:mini_descriptor",
|
||||
"//upb:mini_descriptor_internal",
|
||||
"//upb:mini_table",
|
||||
"//upb:port",
|
||||
"//upb:wire",
|
||||
"//upb/test:test_messages_proto2_upb_minitable",
|
||||
"//upb/test:test_messages_proto2_upb_proto",
|
||||
"//upb/test:test_messages_proto3_upb_minitable",
|
||||
"//upb/test:test_messages_proto3_upb_proto",
|
||||
"//upb/test:test_upb_proto",
|
||||
"@com_google_absl//absl/container:flat_hash_set",
|
||||
|
|
@ -283,8 +296,8 @@ cc_test(
|
|||
"//upb:mem",
|
||||
"//upb:mini_table",
|
||||
"//upb:wire",
|
||||
"//upb/test:test_messages_proto2_upb_minitable",
|
||||
"//upb/test:test_messages_proto2_upb_proto",
|
||||
"//upb/test:test_messages_proto3_upb_proto",
|
||||
"//upb/test:test_upb_proto",
|
||||
"@com_google_absl//absl/container:flat_hash_set",
|
||||
],
|
||||
|
|
@ -307,18 +320,22 @@ cc_test(
|
|||
deps = [
|
||||
":accessors",
|
||||
":copy",
|
||||
":internal",
|
||||
":message",
|
||||
":promote",
|
||||
":tagged_ptr",
|
||||
"//:protobuf",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
"//upb:base",
|
||||
"//upb:mem",
|
||||
"//upb:mini_descriptor",
|
||||
"//upb:mini_descriptor_internal",
|
||||
"//upb:mini_table",
|
||||
"//upb:port",
|
||||
"//upb:wire",
|
||||
"//upb/test:test_messages_proto2_upb_proto",
|
||||
"//upb/test:test_messages_proto3_upb_proto",
|
||||
"//upb/test:test_proto_upb_minitable",
|
||||
"//upb/test:test_upb_proto",
|
||||
"@com_google_absl//absl/container:flat_hash_set",
|
||||
],
|
||||
|
|
@ -330,12 +347,16 @@ cc_test(
|
|||
name = "test",
|
||||
srcs = ["test.cc"],
|
||||
deps = [
|
||||
":message_test_upb_minitable_proto",
|
||||
":message_test_upb_proto",
|
||||
":message_test_upb_proto_reflection",
|
||||
":value",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
"//upb:base",
|
||||
"//upb:json",
|
||||
"//upb:mem",
|
||||
"//upb:message",
|
||||
"//upb:mini_table",
|
||||
"//upb:reflection",
|
||||
"//upb:wire",
|
||||
"//upb/test:fuzz_util",
|
||||
|
|
@ -350,6 +371,12 @@ proto_library(
|
|||
deps = ["//src/google/protobuf:test_messages_proto3_proto"],
|
||||
)
|
||||
|
||||
upb_minitable_proto_library(
|
||||
name = "utf8_test_upb_minitable_proto",
|
||||
testonly = 1,
|
||||
deps = [":utf8_test_proto"],
|
||||
)
|
||||
|
||||
upb_proto_library(
|
||||
name = "utf8_test_upb_proto",
|
||||
testonly = 1,
|
||||
|
|
@ -360,6 +387,7 @@ cc_test(
|
|||
name = "utf8_test",
|
||||
srcs = ["utf8_test.cc"],
|
||||
deps = [
|
||||
":utf8_test_upb_minitable_proto",
|
||||
":utf8_test_upb_proto",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
"//upb:base",
|
||||
|
|
|
|||
|
|
@ -13,18 +13,28 @@
|
|||
|
||||
#include "upb/message/accessors.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "google/protobuf/test_messages_proto2.upb.h"
|
||||
#include "google/protobuf/test_messages_proto2.upb_minitable.h"
|
||||
#include "google/protobuf/test_messages_proto3.upb.h"
|
||||
#include "google/protobuf/test_messages_proto3.upb_minitable.h"
|
||||
#include "upb/base/descriptor_constants.h"
|
||||
#include "upb/base/status.h"
|
||||
#include "upb/base/string_view.h"
|
||||
#include "upb/mem/arena.h"
|
||||
#include "upb/message/array.h"
|
||||
#include "upb/message/message.h"
|
||||
#include "upb/mini_descriptor/decode.h"
|
||||
#include "upb/mini_descriptor/internal/encode.hpp"
|
||||
#include "upb/mini_descriptor/internal/modifiers.h"
|
||||
#include "upb/test/test.upb.h"
|
||||
#include "upb/wire/decode.h"
|
||||
#include "upb/mini_table/field.h"
|
||||
#include "upb/mini_table/message.h"
|
||||
|
||||
// Must be last
|
||||
#include "upb/port/def.inc"
|
||||
|
|
@ -53,12 +63,14 @@ const uint64_t kTestUInt64 = 0xFEDCBAFF87654321;
|
|||
|
||||
const upb_MiniTableField* find_proto3_field(int field_number) {
|
||||
return upb_MiniTable_FindFieldByNumber(
|
||||
&protobuf_test_messages_proto3_TestAllTypesProto3_msg_init, field_number);
|
||||
&protobuf_0test_0messages__proto3__TestAllTypesProto3_msg_init,
|
||||
field_number);
|
||||
}
|
||||
|
||||
const upb_MiniTableField* find_proto2_field(int field_number) {
|
||||
return upb_MiniTable_FindFieldByNumber(
|
||||
&protobuf_test_messages_proto2_TestAllTypesProto2_msg_init, field_number);
|
||||
&protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
|
||||
field_number);
|
||||
}
|
||||
|
||||
TEST(GeneratedCode, HazzersProto2) {
|
||||
|
|
@ -265,7 +277,7 @@ TEST(GeneratedCode, SubMessage) {
|
|||
|
||||
const upb_MiniTableField* nested_message_a_field =
|
||||
upb_MiniTable_FindFieldByNumber(
|
||||
&protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_msg_init,
|
||||
&protobuf_0test_0messages__proto2__TestAllTypesProto2__NestedMessage_msg_init,
|
||||
kFieldOptionalNestedMessageA);
|
||||
EXPECT_EQ(5, upb_Message_GetInt32(sub_message, nested_message_a_field, 0));
|
||||
|
||||
|
|
@ -281,11 +293,11 @@ TEST(GeneratedCode, SubMessage) {
|
|||
upb_Message_SetInt32(new_nested_message, nested_message_a_field, 123,
|
||||
nullptr);
|
||||
upb_Message_SetMessage(
|
||||
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
|
||||
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
|
||||
optional_message_field, new_nested_message);
|
||||
|
||||
upb_Message* mutable_message = upb_Message_GetOrCreateMutableMessage(
|
||||
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
|
||||
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
|
||||
optional_message_field, arena);
|
||||
EXPECT_EQ(
|
||||
true,
|
||||
|
|
@ -358,10 +370,10 @@ TEST(GeneratedCode, GetMutableMessage) {
|
|||
const upb_MiniTableField* optional_message_field =
|
||||
find_proto2_field(kFieldOptionalNestedMessage);
|
||||
upb_Message* msg1 = upb_Message_GetOrCreateMutableMessage(
|
||||
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
|
||||
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
|
||||
optional_message_field, arena);
|
||||
upb_Message* msg2 = upb_Message_GetOrCreateMutableMessage(
|
||||
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
|
||||
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
|
||||
optional_message_field, arena);
|
||||
// Verify that newly constructed sub message is stored in msg.
|
||||
EXPECT_EQ(msg1, msg2);
|
||||
|
|
|
|||
|
|
@ -21,12 +21,14 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
#include "google/protobuf/test_messages_proto2.upb.h"
|
||||
#include "google/protobuf/test_messages_proto2.upb_minitable.h"
|
||||
#include "upb/base/string_view.h"
|
||||
#include "upb/mem/arena.h"
|
||||
#include "upb/message/accessors.h"
|
||||
#include "upb/message/internal/message.h"
|
||||
#include "upb/message/map.h"
|
||||
#include "upb/message/message.h"
|
||||
#include "upb/mini_table/field.h"
|
||||
#include "upb/mini_table/message.h"
|
||||
#include "upb/wire/encode.h"
|
||||
|
||||
|
|
@ -44,7 +46,8 @@ const int32_t kTestNestedInt32 = 123;
|
|||
|
||||
const upb_MiniTableField* find_proto2_field(int field_number) {
|
||||
return upb_MiniTable_FindFieldByNumber(
|
||||
&protobuf_test_messages_proto2_TestAllTypesProto2_msg_init, field_number);
|
||||
&protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
|
||||
field_number);
|
||||
}
|
||||
|
||||
TEST(GeneratedCode, DeepCloneMessageScalarAndString) {
|
||||
|
|
@ -66,7 +69,7 @@ TEST(GeneratedCode, DeepCloneMessageScalarAndString) {
|
|||
upb_Arena* arena = upb_Arena_New();
|
||||
protobuf_test_messages_proto2_TestAllTypesProto2* clone =
|
||||
(protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone(
|
||||
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
|
||||
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
|
||||
arena);
|
||||
// After cloning overwrite values and destroy source arena for MSAN.
|
||||
memset(string_in_arena, 0, sizeof(kTestStr1));
|
||||
|
|
@ -97,12 +100,12 @@ TEST(GeneratedCode, DeepCloneMessageSubMessage) {
|
|||
protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a(
|
||||
nested, kTestNestedInt32);
|
||||
upb_Message_SetMessage(
|
||||
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
|
||||
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
|
||||
nested_message_field, nested);
|
||||
upb_Arena* arena = upb_Arena_New();
|
||||
protobuf_test_messages_proto2_TestAllTypesProto2* clone =
|
||||
(protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone(
|
||||
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
|
||||
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
|
||||
arena);
|
||||
// After cloning overwrite values and destroy source arena for MSAN.
|
||||
protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a(nested,
|
||||
|
|
@ -132,7 +135,7 @@ TEST(GeneratedCode, DeepCloneMessageArrayField) {
|
|||
upb_Arena* arena = upb_Arena_New();
|
||||
protobuf_test_messages_proto2_TestAllTypesProto2* clone =
|
||||
(protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone(
|
||||
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
|
||||
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
|
||||
arena);
|
||||
protobuf_test_messages_proto2_TestAllTypesProto2_clear_repeated_sint32(msg);
|
||||
upb_Arena_Free(source_arena);
|
||||
|
|
@ -171,7 +174,7 @@ TEST(GeneratedCode, DeepCloneMessageMapField) {
|
|||
upb_Arena* arena = upb_Arena_New();
|
||||
protobuf_test_messages_proto2_TestAllTypesProto2* clone =
|
||||
(protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone(
|
||||
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
|
||||
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
|
||||
arena);
|
||||
protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a(nested,
|
||||
0);
|
||||
|
|
@ -248,7 +251,7 @@ TEST(GeneratedCode, DeepCloneMessageExtensions) {
|
|||
(protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrect*)
|
||||
upb_Message_DeepClone(
|
||||
msg,
|
||||
&protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrect_msg_init,
|
||||
&protobuf_0test_0messages__proto2__TestAllTypesProto2__MessageSetCorrect_msg_init,
|
||||
arena);
|
||||
|
||||
// Mutate original extension.
|
||||
|
|
@ -291,10 +294,10 @@ TEST(GeneratedCode, DeepCloneMessageWithUnknowns) {
|
|||
size_t len;
|
||||
char* data;
|
||||
upb_Arena* encode_arena = upb_Arena_New();
|
||||
upb_EncodeStatus status =
|
||||
upb_Encode(unknown_source,
|
||||
&protobuf_test_messages_proto2_UnknownToTestAllTypes_msg_init,
|
||||
kUpb_EncodeOption_CheckRequired, encode_arena, &data, &len);
|
||||
upb_EncodeStatus status = upb_Encode(
|
||||
unknown_source,
|
||||
&protobuf_0test_0messages__proto2__UnknownToTestAllTypes_msg_init,
|
||||
kUpb_EncodeOption_CheckRequired, encode_arena, &data, &len);
|
||||
ASSERT_EQ(status, kUpb_EncodeStatus_Ok);
|
||||
std::string unknown_data(data, len);
|
||||
// Add unknown data.
|
||||
|
|
@ -303,7 +306,7 @@ TEST(GeneratedCode, DeepCloneMessageWithUnknowns) {
|
|||
upb_Arena* clone_arena = upb_Arena_New();
|
||||
protobuf_test_messages_proto2_TestAllTypesProto2* clone =
|
||||
(protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone(
|
||||
msg, &protobuf_test_messages_proto2_TestAllTypesProto2_msg_init,
|
||||
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
|
||||
clone_arena);
|
||||
upb_Arena_Free(source_arena);
|
||||
upb_Arena_Free(unknown_arena);
|
||||
|
|
|
|||
|
|
@ -13,20 +13,37 @@
|
|||
|
||||
#include "upb/message/promote.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "google/protobuf/test_messages_proto2.upb.h"
|
||||
#include "google/protobuf/test_messages_proto3.upb.h"
|
||||
#include "upb/base/descriptor_constants.h"
|
||||
#include "upb/base/status.h"
|
||||
#include "upb/base/string_view.h"
|
||||
#include "upb/mem/arena.h"
|
||||
#include "upb/mem/arena.hpp"
|
||||
#include "upb/message/accessors.h"
|
||||
#include "upb/message/array.h"
|
||||
#include "upb/message/copy.h"
|
||||
#include "upb/message/internal/extension.h"
|
||||
#include "upb/message/internal/message.h"
|
||||
#include "upb/message/map.h"
|
||||
#include "upb/message/message.h"
|
||||
#include "upb/message/tagged_ptr.h"
|
||||
#include "upb/mini_descriptor/decode.h"
|
||||
#include "upb/mini_descriptor/internal/encode.hpp"
|
||||
#include "upb/mini_descriptor/internal/modifiers.h"
|
||||
#include "upb/mini_descriptor/link.h"
|
||||
#include "upb/mini_table/field.h"
|
||||
#include "upb/mini_table/message.h"
|
||||
#include "upb/mini_table/sub.h"
|
||||
#include "upb/test/test.upb.h"
|
||||
#include "upb/test/test.upb_minitable.h"
|
||||
#include "upb/wire/decode.h"
|
||||
#include "upb/wire/encode.h"
|
||||
|
||||
// Must be last
|
||||
#include "upb/port/def.inc"
|
||||
|
|
@ -349,7 +366,7 @@ TEST(GeneratedCode, PromoteUnknownMessage) {
|
|||
// Update mini table and promote unknown to a message.
|
||||
EXPECT_TRUE(
|
||||
upb_MiniTable_SetSubMessage(mini_table, (upb_MiniTableField*)submsg_field,
|
||||
&upb_test_ModelWithExtensions_msg_init));
|
||||
&upb_0test__ModelWithExtensions_msg_init));
|
||||
|
||||
const int decode_options =
|
||||
upb_DecodeOptions_MaxDepth(0); // UPB_DECODE_ALIAS disabled.
|
||||
|
|
@ -397,7 +414,7 @@ TEST(GeneratedCode, ReparseUnlinked) {
|
|||
upb_MiniTable_FindFieldByNumber(mini_table, 5);
|
||||
EXPECT_TRUE(
|
||||
upb_MiniTable_SetSubMessage(mini_table, (upb_MiniTableField*)submsg_field,
|
||||
&upb_test_ModelWithExtensions_msg_init));
|
||||
&upb_0test__ModelWithExtensions_msg_init));
|
||||
|
||||
const int decode_options =
|
||||
upb_DecodeOptions_MaxDepth(0); // UPB_DECODE_ALIAS disabled.
|
||||
|
|
@ -447,7 +464,7 @@ TEST(GeneratedCode, PromoteInParser) {
|
|||
upb_MiniTable_FindFieldByNumber(mini_table, 5);
|
||||
EXPECT_TRUE(
|
||||
upb_MiniTable_SetSubMessage(mini_table, (upb_MiniTableField*)submsg_field,
|
||||
&upb_test_ModelWithExtensions_msg_init));
|
||||
&upb_0test__ModelWithExtensions_msg_init));
|
||||
|
||||
// Parse again. This will promote the message. An explicit promote will not
|
||||
// be required.
|
||||
|
|
@ -526,11 +543,11 @@ TEST(GeneratedCode, PromoteUnknownRepeatedMessage) {
|
|||
// Update mini table and promote unknown to a message.
|
||||
EXPECT_TRUE(upb_MiniTable_SetSubMessage(
|
||||
mini_table, (upb_MiniTableField*)repeated_field,
|
||||
&upb_test_ModelWithExtensions_msg_init));
|
||||
&upb_0test__ModelWithExtensions_msg_init));
|
||||
const int decode_options =
|
||||
upb_DecodeOptions_MaxDepth(0); // UPB_DECODE_ALIAS disabled.
|
||||
upb_DecodeStatus promote_result =
|
||||
upb_Array_PromoteMessages(array, &upb_test_ModelWithExtensions_msg_init,
|
||||
upb_Array_PromoteMessages(array, &upb_0test__ModelWithExtensions_msg_init,
|
||||
decode_options, arena.ptr());
|
||||
EXPECT_EQ(promote_result, kUpb_DecodeStatus_Ok);
|
||||
const upb_Message* promoted_message = upb_Array_Get(array, 0).msg_val;
|
||||
|
|
@ -597,9 +614,9 @@ TEST(GeneratedCode, PromoteUnknownToMap) {
|
|||
upb_MiniTableField* entry_value = const_cast<upb_MiniTableField*>(
|
||||
upb_MiniTable_FindFieldByNumber(entry, 2));
|
||||
upb_MiniTable_SetSubMessage(entry, entry_value,
|
||||
&upb_test_ModelWithExtensions_msg_init);
|
||||
&upb_0test__ModelWithExtensions_msg_init);
|
||||
upb_DecodeStatus promote_result = upb_Map_PromoteMessages(
|
||||
map, &upb_test_ModelWithExtensions_msg_init, 0, arena.ptr());
|
||||
map, &upb_0test__ModelWithExtensions_msg_init, 0, arena.ptr());
|
||||
EXPECT_EQ(promote_result, kUpb_DecodeStatus_Ok);
|
||||
|
||||
upb_MessageValue key;
|
||||
|
|
@ -706,13 +723,13 @@ TEST(GeneratedCode, PromoteUnknownMessageOld) {
|
|||
// Update mini table and promote unknown to a message.
|
||||
EXPECT_TRUE(upb_MiniTable_SetSubMessage(
|
||||
mini_table, (upb_MiniTableField*)&mini_table->fields[1],
|
||||
&upb_test_ModelWithExtensions_msg_init));
|
||||
&upb_0test__ModelWithExtensions_msg_init));
|
||||
const int decode_options =
|
||||
upb_DecodeOptions_MaxDepth(0); // UPB_DECODE_ALIAS disabled.
|
||||
upb_UnknownToMessageRet promote_result =
|
||||
upb_MiniTable_PromoteUnknownToMessage(
|
||||
msg, mini_table, &mini_table->fields[1],
|
||||
&upb_test_ModelWithExtensions_msg_init, decode_options, arena);
|
||||
&upb_0test__ModelWithExtensions_msg_init, decode_options, arena);
|
||||
EXPECT_EQ(promote_result.status, kUpb_UnknownToMessage_Ok);
|
||||
const upb_Message* promoted_message =
|
||||
upb_Message_GetMessage(msg, &mini_table->fields[1], nullptr);
|
||||
|
|
@ -755,12 +772,12 @@ TEST(GeneratedCode, PromoteUnknownRepeatedMessageOld) {
|
|||
// Update mini table and promote unknown to a message.
|
||||
EXPECT_TRUE(upb_MiniTable_SetSubMessage(
|
||||
mini_table, (upb_MiniTableField*)&mini_table->fields[2],
|
||||
&upb_test_ModelWithExtensions_msg_init));
|
||||
&upb_0test__ModelWithExtensions_msg_init));
|
||||
const int decode_options =
|
||||
upb_DecodeOptions_MaxDepth(0); // UPB_DECODE_ALIAS disabled.
|
||||
upb_UnknownToMessage_Status promote_result =
|
||||
upb_MiniTable_PromoteUnknownToMessageArray(
|
||||
msg, &mini_table->fields[2], &upb_test_ModelWithExtensions_msg_init,
|
||||
msg, &mini_table->fields[2], &upb_0test__ModelWithExtensions_msg_init,
|
||||
decode_options, arena);
|
||||
EXPECT_EQ(promote_result, kUpb_UnknownToMessage_Ok);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,21 +5,34 @@
|
|||
// license that can be found in the LICENSE file or at
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "google/protobuf/test_messages_proto3.upb.h"
|
||||
#include "upb/base/status.hpp"
|
||||
#include "upb/base/string_view.h"
|
||||
#include "upb/json/decode.h"
|
||||
#include "upb/json/encode.h"
|
||||
#include "upb/mem/arena.h"
|
||||
#include "upb/mem/arena.hpp"
|
||||
#include "upb/message/message.h"
|
||||
#include "upb/message/test.upb.h"
|
||||
#include "upb/message/test.upb_minitable.h"
|
||||
#include "upb/message/test.upbdefs.h"
|
||||
#include "upb/message/value.h"
|
||||
#include "upb/mini_table/extension_registry.h"
|
||||
#include "upb/mini_table/message.h"
|
||||
#include "upb/reflection/def.h"
|
||||
#include "upb/reflection/def.hpp"
|
||||
#include "upb/reflection/message.h"
|
||||
#include "upb/test/fuzz_util.h"
|
||||
#include "upb/wire/decode.h"
|
||||
#include "upb/wire/encode.h"
|
||||
|
||||
// begin:google_only
|
||||
// #include "testing/fuzzing/fuzztest.h"
|
||||
|
|
@ -300,7 +313,7 @@ TEST(MessageTest, DecodeRequiredFieldsTopLevelMessage) {
|
|||
// Fails, because required fields are missing.
|
||||
EXPECT_EQ(
|
||||
kUpb_DecodeStatus_MissingRequired,
|
||||
upb_Decode(nullptr, 0, test_msg, &upb_test_TestRequiredFields_msg_init,
|
||||
upb_Decode(nullptr, 0, test_msg, &upb_0test__TestRequiredFields_msg_init,
|
||||
nullptr, kUpb_DecodeOption_CheckRequired, arena.ptr()));
|
||||
|
||||
upb_test_TestRequiredFields_set_required_int32(test_msg, 1);
|
||||
|
|
@ -314,7 +327,7 @@ TEST(MessageTest, DecodeRequiredFieldsTopLevelMessage) {
|
|||
// payload is not empty.
|
||||
EXPECT_EQ(kUpb_DecodeStatus_MissingRequired,
|
||||
upb_Decode(serialized, size, test_msg,
|
||||
&upb_test_TestRequiredFields_msg_init, nullptr,
|
||||
&upb_0test__TestRequiredFields_msg_init, nullptr,
|
||||
kUpb_DecodeOption_CheckRequired, arena.ptr()));
|
||||
|
||||
empty_msg = upb_test_EmptyMessage_new(arena.ptr());
|
||||
|
|
@ -325,7 +338,7 @@ TEST(MessageTest, DecodeRequiredFieldsTopLevelMessage) {
|
|||
// Succeeds, because required fields are present (though not in the input).
|
||||
EXPECT_EQ(
|
||||
kUpb_DecodeStatus_Ok,
|
||||
upb_Decode(nullptr, 0, test_msg, &upb_test_TestRequiredFields_msg_init,
|
||||
upb_Decode(nullptr, 0, test_msg, &upb_0test__TestRequiredFields_msg_init,
|
||||
nullptr, kUpb_DecodeOption_CheckRequired, arena.ptr()));
|
||||
|
||||
// Serialize a complete payload.
|
||||
|
|
@ -344,7 +357,7 @@ TEST(MessageTest, DecodeRequiredFieldsTopLevelMessage) {
|
|||
test_msg2, upb_test_TestRequiredFields_new(arena.ptr()));
|
||||
EXPECT_EQ(kUpb_DecodeStatus_Ok,
|
||||
upb_Decode(serialized, size, test_msg2,
|
||||
&upb_test_TestRequiredFields_msg_init, nullptr,
|
||||
&upb_0test__TestRequiredFields_msg_init, nullptr,
|
||||
kUpb_DecodeOption_CheckRequired, arena.ptr()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include "upb/mem/arena.h"
|
||||
#include "upb/mem/arena.hpp"
|
||||
#include "upb/message/utf8_test.upb.h"
|
||||
#include "upb/message/utf8_test.upb_minitable.h"
|
||||
#include "upb/wire/decode.h"
|
||||
|
||||
namespace {
|
||||
|
|
@ -69,7 +70,7 @@ TEST(Utf8Test, Proto3FieldValidates) {
|
|||
upb_test_TestUtf8Proto3String_new(arena.ptr());
|
||||
|
||||
upb_DecodeStatus status =
|
||||
upb_Decode(data, size, msg, &upb_test_TestUtf8Proto3String_msg_init,
|
||||
upb_Decode(data, size, msg, &upb_0test__TestUtf8Proto3String_msg_init,
|
||||
nullptr, 0, arena.ptr());
|
||||
|
||||
// Parse fails, because proto3 string fields validate UTF-8.
|
||||
|
|
@ -85,8 +86,8 @@ TEST(Utf8Test, RepeatedProto3FieldValidates) {
|
|||
upb_test_TestUtf8RepeatedProto3String_new(arena.ptr());
|
||||
|
||||
upb_DecodeStatus status = upb_Decode(
|
||||
data, size, msg, &upb_test_TestUtf8RepeatedProto3String_msg_init, nullptr,
|
||||
0, arena.ptr());
|
||||
data, size, msg, &upb_0test__TestUtf8RepeatedProto3String_msg_init,
|
||||
nullptr, 0, arena.ptr());
|
||||
|
||||
// Parse fails, because proto3 string fields validate UTF-8.
|
||||
ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status);
|
||||
|
|
@ -101,9 +102,9 @@ TEST(Utf8Test, RepeatedProto3FieldValidates) {
|
|||
// upb_test_TestUtf8Proto3StringMixed* msg =
|
||||
// upb_test_TestUtf8Proto3StringMixed_new(arena.ptr());
|
||||
//
|
||||
// upb_DecodeStatus status =
|
||||
// upb_Decode(data, size, msg, &upb_test_TestUtf8Proto3StringMixed_msg_init,
|
||||
// nullptr, 0, arena.ptr());
|
||||
// upb_DecodeStatus status = upb_Decode(
|
||||
// data, size, msg, &upb_0test__TestUtf8Proto3StringMixed_msg_init, nullptr,
|
||||
// 0, arena.ptr());
|
||||
//
|
||||
// // Parse fails, because proto3 string fields validate UTF-8.
|
||||
// ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status);
|
||||
|
|
|
|||
|
|
@ -83,8 +83,8 @@ cc_test(
|
|||
deps = [
|
||||
"@com_google_googletest//:gtest_main",
|
||||
"//upb:mini_table_compat",
|
||||
"//upb/test:test_messages_proto2_upb_proto",
|
||||
"//upb/test:test_messages_proto3_upb_proto",
|
||||
"//upb/test:test_messages_proto2_upb_minitable",
|
||||
"//upb/test:test_messages_proto3_upb_minitable",
|
||||
"//upb/test:test_upb_proto",
|
||||
],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -14,21 +14,21 @@
|
|||
#include "upb/mini_table/compat.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "google/protobuf/test_messages_proto2.upb.h"
|
||||
#include "google/protobuf/test_messages_proto3.upb.h"
|
||||
#include "google/protobuf/test_messages_proto2.upb_minitable.h"
|
||||
#include "google/protobuf/test_messages_proto3.upb_minitable.h"
|
||||
|
||||
namespace {
|
||||
|
||||
TEST(GeneratedCode, EqualsTestProto2) {
|
||||
EXPECT_TRUE(upb_MiniTable_Equals(
|
||||
&protobuf_test_messages_proto2_ProtoWithKeywords_msg_init,
|
||||
&protobuf_test_messages_proto2_ProtoWithKeywords_msg_init));
|
||||
&protobuf_0test_0messages__proto2__ProtoWithKeywords_msg_init,
|
||||
&protobuf_0test_0messages__proto2__ProtoWithKeywords_msg_init));
|
||||
}
|
||||
|
||||
TEST(GeneratedCode, EqualsTestProto3) {
|
||||
EXPECT_TRUE(upb_MiniTable_Equals(
|
||||
&protobuf_test_messages_proto3_TestAllTypesProto3_msg_init,
|
||||
&protobuf_test_messages_proto3_TestAllTypesProto3_msg_init));
|
||||
&protobuf_0test_0messages__proto3__TestAllTypesProto3_msg_init,
|
||||
&protobuf_0test_0messages__proto3__TestAllTypesProto3_msg_init));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@ load(
|
|||
"//bazel:build_defs.bzl",
|
||||
"UPB_DEFAULT_CPPOPTS",
|
||||
)
|
||||
load(
|
||||
"//bazel:upb_minitable_proto_library.bzl",
|
||||
"upb_minitable_proto_library",
|
||||
)
|
||||
load(
|
||||
"//bazel:upb_proto_library.bzl",
|
||||
"upb_proto_library",
|
||||
|
|
@ -66,6 +70,13 @@ proto_library(
|
|||
srcs = ["test.proto"],
|
||||
)
|
||||
|
||||
upb_minitable_proto_library(
|
||||
name = "test_proto_upb_minitable",
|
||||
testonly = 1,
|
||||
visibility = ["//upb:__subpackages__"],
|
||||
deps = [":test_proto"],
|
||||
)
|
||||
|
||||
upb_proto_library(
|
||||
name = "test_upb_proto",
|
||||
testonly = 1,
|
||||
|
|
@ -89,6 +100,20 @@ upb_proto_reflection_library(
|
|||
deps = ["test_cpp_proto"],
|
||||
)
|
||||
|
||||
upb_minitable_proto_library(
|
||||
name = "test_messages_proto2_upb_minitable",
|
||||
testonly = 1,
|
||||
visibility = ["//upb:__subpackages__"],
|
||||
deps = ["//src/google/protobuf:test_messages_proto2_proto"],
|
||||
)
|
||||
|
||||
upb_minitable_proto_library(
|
||||
name = "test_messages_proto3_upb_minitable",
|
||||
testonly = 1,
|
||||
visibility = ["//upb:__subpackages__"],
|
||||
deps = ["//src/google/protobuf:test_messages_proto3_proto"],
|
||||
)
|
||||
|
||||
upb_proto_library(
|
||||
name = "test_messages_proto2_upb_proto",
|
||||
testonly = 1,
|
||||
|
|
@ -182,12 +207,10 @@ cc_test(
|
|||
],
|
||||
deps = [
|
||||
":empty_upb_proto_reflection",
|
||||
":test_messages_proto2_upb_proto",
|
||||
":test_messages_proto3_upb_proto",
|
||||
":test_messages_proto2_upb_minitable",
|
||||
":test_upb_proto",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
"//upb:mini_table",
|
||||
"//upb:mini_table_internal",
|
||||
"//upb:port",
|
||||
],
|
||||
)
|
||||
|
|
@ -223,6 +246,12 @@ proto_library(
|
|||
deps = [":empty_srcs_3_proto"],
|
||||
)
|
||||
|
||||
upb_minitable_proto_library(
|
||||
name = "test_import_empty_srcs_upb_minitable_proto",
|
||||
testonly = 1,
|
||||
deps = [":test_import_empty_srcs_proto"],
|
||||
)
|
||||
|
||||
upb_proto_library(
|
||||
name = "test_import_empty_srcs_upb_proto",
|
||||
testonly = 1,
|
||||
|
|
@ -233,7 +262,7 @@ cc_test(
|
|||
name = "test_import_empty_srcs",
|
||||
srcs = ["test_import_empty_srcs.cc"],
|
||||
deps = [
|
||||
":test_import_empty_srcs_upb_proto",
|
||||
":test_import_empty_srcs_upb_minitable_proto",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "upb/test/test_import_empty_srcs.upb.h"
|
||||
#include "upb/test/test_import_empty_srcs.upb_minitable.h"
|
||||
|
||||
TEST(Test, Reexport) {
|
||||
// This test really just ensures that compilation succeeds.
|
||||
ASSERT_GT(sizeof(upb_test_ContainsImported_msg_init), 0);
|
||||
ASSERT_GT(sizeof(upb_0test__ContainsImported_msg_init), 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,9 @@
|
|||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "google/protobuf/test_messages_proto2.upb.h"
|
||||
#include "google/protobuf/test_messages_proto3.upb.h"
|
||||
#include "google/protobuf/test_messages_proto2.upb_minitable.h"
|
||||
#include "upb/mini_table/field.h"
|
||||
#include "upb/mini_table/message.h"
|
||||
#include "upb/test/test.upb.h"
|
||||
|
||||
// Must be last.
|
||||
#include "upb/port/def.inc"
|
||||
|
|
@ -20,7 +18,7 @@ TEST(MiniTableOneofTest, OneOfIteratorProto2) {
|
|||
constexpr int oneof_test_field_number = 116;
|
||||
|
||||
const upb_MiniTable* google_protobuf_table =
|
||||
&protobuf_test_messages_proto2_TestAllTypesProto2_msg_init;
|
||||
&protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init;
|
||||
const upb_MiniTableField* field =
|
||||
upb_MiniTable_FindFieldByNumber(google_protobuf_table, oneof_test_field_number);
|
||||
ASSERT_TRUE(field != nullptr);
|
||||
|
|
@ -34,7 +32,7 @@ TEST(MiniTableOneofTest, OneOfIteratorProto2) {
|
|||
TEST(MiniTableOneofTest, InitialFieldNotOneOf) {
|
||||
constexpr int test_field_number = 1; // optional int that is not a oneof
|
||||
const upb_MiniTable* google_protobuf_table =
|
||||
&protobuf_test_messages_proto2_TestAllTypesProto2_msg_init;
|
||||
&protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init;
|
||||
const upb_MiniTableField* field =
|
||||
upb_MiniTable_FindFieldByNumber(google_protobuf_table, test_field_number);
|
||||
ASSERT_TRUE(field != nullptr);
|
||||
|
|
|
|||
|
|
@ -48,6 +48,11 @@
|
|||
// Must be last
|
||||
#include "upb/port/def.inc"
|
||||
|
||||
// Generate a mangled C name for a proto object.
|
||||
static std::string MangleName(absl::string_view name) {
|
||||
return absl::StrReplaceAll(name, {{"_", "_0"}, {".", "__"}});
|
||||
}
|
||||
|
||||
namespace upb {
|
||||
namespace generator {
|
||||
|
||||
|
|
@ -78,6 +83,14 @@ void EmitFileWarning(absl::string_view name, Output& output) {
|
|||
name);
|
||||
}
|
||||
|
||||
std::string MessageInit(absl::string_view full_name) {
|
||||
return MangleName(full_name) + "_msg_init";
|
||||
}
|
||||
|
||||
std::string MessageInitName(upb::MessageDefPtr descriptor) {
|
||||
return MessageInit(descriptor.full_name());
|
||||
}
|
||||
|
||||
std::string MessageName(upb::MessageDefPtr descriptor) {
|
||||
return ToCIdent(descriptor.full_name());
|
||||
}
|
||||
|
|
@ -94,10 +107,6 @@ std::string MiniTableHeaderFilename(upb::FileDefPtr file) {
|
|||
return StripExtension(file.name()) + ".upb_minitable.h";
|
||||
}
|
||||
|
||||
std::string MessageInit(absl::string_view full_name) {
|
||||
return ToCIdent(full_name) + "_msg_init";
|
||||
}
|
||||
|
||||
std::string EnumInit(upb::EnumDefPtr descriptor) {
|
||||
return ToCIdent(descriptor.full_name()) + "_enum_init";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,12 +81,13 @@ std::string StripExtension(absl::string_view fname);
|
|||
std::string ToCIdent(absl::string_view str);
|
||||
std::string ToPreproc(absl::string_view str);
|
||||
void EmitFileWarning(absl::string_view name, Output& output);
|
||||
std::string MessageInit(absl::string_view full_name);
|
||||
std::string MessageInitName(upb::MessageDefPtr descriptor);
|
||||
std::string MessageName(upb::MessageDefPtr descriptor);
|
||||
std::string FileLayoutName(upb::FileDefPtr file);
|
||||
std::string MiniTableHeaderFilename(upb::FileDefPtr file);
|
||||
std::string CApiHeaderFilename(upb::FileDefPtr file);
|
||||
|
||||
std::string MessageInit(absl::string_view full_name);
|
||||
std::string EnumInit(upb::EnumDefPtr descriptor);
|
||||
|
||||
std::string FieldInitializer(upb::FieldDefPtr field,
|
||||
|
|
|
|||
|
|
@ -73,10 +73,6 @@ std::string SourceFilename(upb::FileDefPtr file) {
|
|||
return StripExtension(file.name()) + ".upb.c";
|
||||
}
|
||||
|
||||
std::string MessageInitName(upb::MessageDefPtr descriptor) {
|
||||
return absl::StrCat(MessageName(descriptor), "_msg_init");
|
||||
}
|
||||
|
||||
std::string MessageMiniTableRef(upb::MessageDefPtr descriptor,
|
||||
const Options& options) {
|
||||
if (options.bootstrap) {
|
||||
|
|
|
|||
|
|
@ -84,10 +84,6 @@ std::string SourceFilename(upb::FileDefPtr file) {
|
|||
return StripExtension(file.name()) + ".upb_minitable.c";
|
||||
}
|
||||
|
||||
std::string MessageInitName(upb::MessageDefPtr descriptor) {
|
||||
return absl::StrCat(MessageName(descriptor), "_msg_init");
|
||||
}
|
||||
|
||||
std::string ExtensionIdentBase(upb::FieldDefPtr ext) {
|
||||
assert(ext.is_extension());
|
||||
std::string ext_scope;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue