Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabled editions support for upb generated code.
This required enabling the feature in the code generator and fixing a few edge cases around label and type. Also added tests to verify the special cases, and to verify that required fields work as expected. PiperOrigin-RevId: 580263087
- Loading branch information
Showing
14 changed files
with
277 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Protocol Buffers - Google's data interchange format | ||
// Copyright 2023 Google LLC. All rights reserved. | ||
// | ||
// 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 | ||
|
||
#include <gtest/gtest.h> | ||
#include "upb/base/descriptor_constants.h" | ||
#include "upb/mem/arena.hpp" | ||
#include "upb/reflection/def.hpp" | ||
#include "upb/test/editions_test.upb.h" | ||
#include "upb/test/editions_test.upbdefs.h" | ||
|
||
TEST(EditionsTest, PlainField) { | ||
upb::DefPool defpool; | ||
upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); | ||
upb::FieldDefPtr f(md.FindFieldByName("plain_field")); | ||
EXPECT_TRUE(f.has_presence()); | ||
} | ||
|
||
TEST(EditionsTest, ImplicitPresenceField) { | ||
upb::DefPool defpool; | ||
upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); | ||
upb::FieldDefPtr f(md.FindFieldByName("implicit_presence_field")); | ||
EXPECT_FALSE(f.has_presence()); | ||
} | ||
|
||
TEST(EditionsTest, DelimitedField) { | ||
upb::DefPool defpool; | ||
upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); | ||
upb::FieldDefPtr f(md.FindFieldByName("delimited_field")); | ||
EXPECT_EQ(kUpb_FieldType_Group, f.type()); | ||
} | ||
|
||
TEST(EditionsTest, RequiredField) { | ||
upb::DefPool defpool; | ||
upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); | ||
upb::FieldDefPtr f(md.FindFieldByName("required_field")); | ||
EXPECT_EQ(kUpb_Label_Required, f.label()); | ||
} | ||
|
||
TEST(EditionsTest, ClosedEnum) { | ||
upb::DefPool defpool; | ||
upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); | ||
upb::FieldDefPtr f(md.FindFieldByName("enum_field")); | ||
ASSERT_TRUE(f.enum_subdef().is_closed()); | ||
} | ||
|
||
TEST(EditionsTest, PackedField) { | ||
upb::DefPool defpool; | ||
upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); | ||
upb::FieldDefPtr f(md.FindFieldByName("unpacked_field")); | ||
ASSERT_FALSE(f.packed()); | ||
} | ||
|
||
TEST(EditionsTest, ConstructProto) { | ||
// Doesn't do anything except construct the proto. This just verifies that | ||
// the generated code compiles successfully. | ||
upb::Arena arena; | ||
upb_test_2023_EditionsMessage_new(arena.ptr()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Protocol Buffers - Google's data interchange format | ||
// Copyright 2023 Google LLC. All rights reserved. | ||
// | ||
// 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 | ||
|
||
edition = "2023"; | ||
|
||
package upb.test_2023; | ||
|
||
message EditionsMessage { | ||
int32 plain_field = 1; | ||
int32 implicit_presence_field = 2 [features.field_presence = IMPLICIT]; | ||
int32 required_field = 3 [features.field_presence = LEGACY_REQUIRED]; | ||
EditionsMessage delimited_field = 4 [features.message_encoding = DELIMITED]; | ||
EditionsEnum enum_field = 5; | ||
repeated int32 unpacked_field = 6 | ||
[features.repeated_field_encoding = EXPANDED]; | ||
} | ||
|
||
enum EditionsEnum { | ||
option features.enum_type = CLOSED; | ||
|
||
ONE = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Protocol Buffers - Google's data interchange format | ||
// Copyright 2023 Google LLC. All rights reserved. | ||
// | ||
// 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 | ||
|
||
edition = "2023"; | ||
|
||
package upb_util_2023_test; | ||
|
||
message EmptyMessage {} | ||
|
||
message HasRequiredField { | ||
int32 required_int32 = 1 [features.field_presence = LEGACY_REQUIRED]; | ||
} | ||
|
||
message TestRequiredFields { | ||
EmptyMessage required_message = 1 [features.field_presence = LEGACY_REQUIRED]; | ||
TestRequiredFields optional_message = 2; | ||
repeated HasRequiredField repeated_message = 3; | ||
map<int32, HasRequiredField> map_int32_message = 4; | ||
map<int64, HasRequiredField> map_int64_message = 5; | ||
map<uint32, HasRequiredField> map_uint32_message = 6; | ||
map<uint64, HasRequiredField> map_uint64_message = 7; | ||
map<bool, HasRequiredField> map_bool_message = 8; | ||
map<string, HasRequiredField> map_string_message = 9; | ||
} |
Oops, something went wrong.