|
|
|
@ -7,18 +7,22 @@ |
|
|
|
|
|
|
|
|
|
#include "upb/util/def_to_proto.h" |
|
|
|
|
|
|
|
|
|
#include <cstddef> |
|
|
|
|
#include <memory> |
|
|
|
|
#include <string> |
|
|
|
|
|
|
|
|
|
#include "google/protobuf/descriptor.pb.h" |
|
|
|
|
#include "google/protobuf/descriptor.upb.h" |
|
|
|
|
#include "google/protobuf/descriptor.upbdefs.h" |
|
|
|
|
#include <gmock/gmock.h> |
|
|
|
|
#include <gtest/gtest.h> |
|
|
|
|
#include "google/protobuf/dynamic_message.h" |
|
|
|
|
#include "google/protobuf/util/message_differencer.h" |
|
|
|
|
#include "upb/base/string_view.h" |
|
|
|
|
#include "upb/mem/arena.hpp" |
|
|
|
|
#include "upb/reflection/def.hpp" |
|
|
|
|
#include "upb/test/parse_text_proto.h" |
|
|
|
|
#include "upb/util/def_to_proto_editions_test.upbdefs.h" |
|
|
|
|
#include "upb/util/def_to_proto_test.h" |
|
|
|
|
#include "upb/util/def_to_proto_test.upbdefs.h" |
|
|
|
|
|
|
|
|
@ -115,6 +119,29 @@ TEST(DefToProto, Test) { |
|
|
|
|
CheckFile(file, file_desc); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Verifies that editions don't leak out legacy feature APIs (e.g. TYPE_GROUP
|
|
|
|
|
// and LABEL_REQUIRED):
|
|
|
|
|
// serialized descriptor -> upb def -> serialized descriptor
|
|
|
|
|
TEST(DefToProto, TestEditionsLegacyFeatures) { |
|
|
|
|
upb::Arena arena; |
|
|
|
|
upb::DefPool defpool; |
|
|
|
|
upb_StringView test_file_desc = |
|
|
|
|
upb_util_def_to_proto_editions_test_proto_upbdefinit |
|
|
|
|
.descriptor; |
|
|
|
|
const auto* file = google_protobuf_FileDescriptorProto_parse( |
|
|
|
|
test_file_desc.data, test_file_desc.size, arena.ptr()); |
|
|
|
|
|
|
|
|
|
size_t size; |
|
|
|
|
const auto* messages = google_protobuf_FileDescriptorProto_message_type(file, &size); |
|
|
|
|
ASSERT_EQ(size, 1); |
|
|
|
|
const auto* fields = google_protobuf_DescriptorProto_field(messages[0], &size); |
|
|
|
|
ASSERT_EQ(size, 2); |
|
|
|
|
EXPECT_EQ(google_protobuf_FieldDescriptorProto_label(fields[0]), |
|
|
|
|
google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL); |
|
|
|
|
EXPECT_EQ(google_protobuf_FieldDescriptorProto_type(fields[1]), |
|
|
|
|
google_protobuf_FieldDescriptorProto_TYPE_MESSAGE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Like the previous test, but uses a message layout built at runtime.
|
|
|
|
|
TEST(DefToProto, TestRuntimeReflection) { |
|
|
|
|
upb::Arena arena; |
|
|
|
|