mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
Add a bit more unit test coverage for Edition 2024 defaults.
(We also have some existing test coverage already in descriptor_unittest.cc but these other edition-specific tests seem to be missing edition 2024.) PiperOrigin-RevId: 902261564
This commit is contained in:
parent
3ff8d32550
commit
e3370c2e26
4 changed files with 111 additions and 0 deletions
|
|
@ -43,6 +43,16 @@ compile_edition_defaults(
|
|||
protoc = "//src/google/protobuf/compiler:protoc_minimal",
|
||||
)
|
||||
|
||||
compile_edition_defaults(
|
||||
name = "test_defaults_2024",
|
||||
testonly = True,
|
||||
srcs = ["//src/google/protobuf:unittest_features_proto"],
|
||||
maximum_edition = "2024",
|
||||
minimum_edition = "2024",
|
||||
# Test with HEAD protoc for any behavior change, other usages don't need this.
|
||||
protoc = "//src/google/protobuf/compiler:protoc_minimal",
|
||||
)
|
||||
|
||||
compile_edition_defaults(
|
||||
name = "test_defaults_future",
|
||||
testonly = True,
|
||||
|
|
@ -166,6 +176,7 @@ cc_test(
|
|||
data = [
|
||||
":protobuf_defaults",
|
||||
":test_defaults_2023",
|
||||
":test_defaults_2024",
|
||||
":test_defaults_far_future",
|
||||
":test_defaults_future",
|
||||
],
|
||||
|
|
@ -378,10 +389,23 @@ cc_proto_library(
|
|||
deps = [":test_editions_default_features_proto"],
|
||||
)
|
||||
|
||||
proto_library(
|
||||
name = "test_editions_2024_default_features_proto",
|
||||
testonly = True,
|
||||
srcs = ["input/test_editions_2024_default_features.proto"],
|
||||
)
|
||||
|
||||
cc_proto_library(
|
||||
name = "test_editions_2024_default_features_cc_proto",
|
||||
testonly = True,
|
||||
deps = [":test_editions_2024_default_features_proto"],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "generated_files_test",
|
||||
srcs = ["generated_files_test.cc"],
|
||||
deps = [
|
||||
":test_editions_2024_default_features_cc_proto",
|
||||
":test_editions_default_features_cc_proto",
|
||||
":test_messages_proto2_editions_cc_proto",
|
||||
":test_messages_proto3_editions_cc_proto",
|
||||
|
|
|
|||
|
|
@ -67,6 +67,33 @@ TEST(DefaultsTest, Check2023) {
|
|||
pb::VALUE3);
|
||||
}
|
||||
|
||||
TEST(DefaultsTest, Check2024) {
|
||||
auto defaults = ReadDefaults("test_defaults_2024");
|
||||
ASSERT_OK(defaults);
|
||||
ASSERT_EQ(defaults->defaults().size(), 5);
|
||||
ASSERT_EQ(defaults->minimum_edition(), EDITION_2024);
|
||||
ASSERT_EQ(defaults->maximum_edition(), EDITION_2024);
|
||||
|
||||
EXPECT_EQ(defaults->defaults()[0].edition(), EDITION_LEGACY);
|
||||
EXPECT_EQ(defaults->defaults()[1].edition(), EDITION_PROTO3);
|
||||
EXPECT_EQ(defaults->defaults()[2].edition(), EDITION_2023);
|
||||
EXPECT_EQ(defaults->defaults()[2].overridable_features().field_presence(),
|
||||
FeatureSet::EXPLICIT);
|
||||
EXPECT_EQ(defaults->defaults()[2]
|
||||
.overridable_features()
|
||||
.GetExtension(pb::test)
|
||||
.file_feature(),
|
||||
pb::VALUE3);
|
||||
EXPECT_EQ(defaults->defaults()[3].edition(), EDITION_2024);
|
||||
EXPECT_EQ(
|
||||
defaults->defaults()[3].overridable_features().enforce_naming_style(),
|
||||
FeatureSet::STYLE2024);
|
||||
EXPECT_EQ(defaults->defaults()[3]
|
||||
.overridable_features()
|
||||
.default_symbol_visibility(),
|
||||
FeatureSet::VisibilityFeature::EXPORT_TOP_LEVEL);
|
||||
}
|
||||
|
||||
TEST(DefaultsTest, CheckFuture) {
|
||||
auto defaults = ReadDefaults("test_defaults_future");
|
||||
ASSERT_OK(defaults);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include "google/protobuf/descriptor.h"
|
||||
#include "editions/golden/test_messages_proto2_editions.pb.h"
|
||||
#include "editions/golden/test_messages_proto3_editions.pb.h"
|
||||
#include "editions/input/test_editions_2024_default_features.pb.h"
|
||||
#include "editions/input/test_editions_default_features.pb.h"
|
||||
#include "google/protobuf/internal_feature_helper.h"
|
||||
#include "google/protobuf/test_textproto.h"
|
||||
|
|
@ -22,6 +23,7 @@ namespace google {
|
|||
namespace protobuf {
|
||||
namespace {
|
||||
|
||||
using ::protobuf_editions_test::Editions2024DefaultMessage;
|
||||
using ::protobuf_editions_test::EditionsDefaultMessage;
|
||||
using ::protobuf_test_messages::editions::proto2::TestAllRequiredTypesProto2;
|
||||
using ::protobuf_test_messages::editions::proto2::TestAllTypesProto2;
|
||||
|
|
@ -157,6 +159,40 @@ TEST(Generated, EditionDefaults2023InternalFeatures) {
|
|||
)pb"));
|
||||
}
|
||||
|
||||
TEST(Generated, EditionDefaults2024) {
|
||||
const Descriptor* desc = Editions2024DefaultMessage::descriptor();
|
||||
EXPECT_TRUE(desc->FindFieldByName("int32_field")->has_presence());
|
||||
EXPECT_TRUE(
|
||||
desc->FindFieldByName("string_field")->requires_utf8_validation());
|
||||
EXPECT_FALSE(desc->FindFieldByName("enum_field")
|
||||
->legacy_enum_field_treated_as_closed());
|
||||
EXPECT_FALSE(desc->FindFieldByName("enum_field")->enum_type()->is_closed());
|
||||
EXPECT_TRUE(desc->FindFieldByName("repeated_int32_field")->is_packed());
|
||||
EXPECT_EQ(desc->FindFieldByName("sub_message_field")->type(),
|
||||
FieldDescriptor::TYPE_MESSAGE);
|
||||
}
|
||||
|
||||
TEST(Generated, EditionDefaults2024InternalFeatures) {
|
||||
EXPECT_THAT(internal::InternalFeatureHelper::GetFeatures(
|
||||
*Editions2024DefaultMessage::descriptor()),
|
||||
google::protobuf::EqualsProto(R"pb(
|
||||
field_presence: EXPLICIT
|
||||
enum_type: OPEN
|
||||
repeated_field_encoding: PACKED
|
||||
utf8_validation: VERIFY
|
||||
message_encoding: LENGTH_PREFIXED
|
||||
json_format: ALLOW
|
||||
enforce_naming_style: STYLE2024
|
||||
default_symbol_visibility: EXPORT_TOP_LEVEL
|
||||
[pb.cpp] {
|
||||
legacy_closed_enum: false
|
||||
string_type: VIEW
|
||||
enum_name_uses_string_view: true
|
||||
repeated_type: LEGACY
|
||||
}
|
||||
)pb"));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
|
|
|||
24
editions/input/test_editions_2024_default_features.proto
Normal file
24
editions/input/test_editions_2024_default_features.proto
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
edition = "2024";
|
||||
|
||||
package protobuf_editions_test;
|
||||
|
||||
// This file tests the default Edition2024 features in the absence of any
|
||||
// dependencies.
|
||||
|
||||
enum Editions2024DefaultEnum {
|
||||
EDITIONS2024_DEFAULT_ENUM_UNKNOWN = 0;
|
||||
EDITIONS2024_DEFAULT_ENUM_VALUE1 = 1;
|
||||
}
|
||||
|
||||
message Editions2024DefaultMessage {
|
||||
int32 int32_field = 1;
|
||||
string string_field = 2;
|
||||
Editions2024DefaultEnum enum_field = 3;
|
||||
|
||||
repeated int32 repeated_int32_field = 4;
|
||||
|
||||
message SubMessage {
|
||||
int32 nested_int32_field = 1;
|
||||
}
|
||||
SubMessage sub_message_field = 6;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue