Add "string_type" to CppFeatures.

PiperOrigin-RevId: 603514708
pull/15653/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent 8b46b56467
commit 2a28082df3
  1. 2
      src/google/protobuf/cpp_edition_defaults.h
  2. 125
      src/google/protobuf/cpp_features.pb.cc
  3. 110
      src/google/protobuf/cpp_features.pb.h
  4. 15
      src/google/protobuf/cpp_features.proto
  5. 295
      src/google/protobuf/descriptor_unittest.cc
  6. 2
      src/google/protobuf/editions/generated_files_test.cc

@ -5,7 +5,7 @@
// the C++ runtime. This is used for feature resolution under Editions.
// NOLINTBEGIN
// clang-format off
#define PROTOBUF_INTERNAL_CPP_EDITION_DEFAULTS "\n\026\022\021\010\001\020\002\030\002 \003(\0010\002\302>\002\010\001\030\346\007\n\026\022\021\010\002\020\001\030\001 \002(\0010\001\302>\002\010\000\030\347\007\n\026\022\021\010\001\020\001\030\001 \002(\0010\001\302>\002\010\000\030\350\007 \346\007(\350\007"
#define PROTOBUF_INTERNAL_CPP_EDITION_DEFAULTS "\n\030\022\023\010\001\020\002\030\002 \003(\0010\002\302>\004\010\001\020\003\030\346\007\n\030\022\023\010\002\020\001\030\001 \002(\0010\001\302>\004\010\000\020\003\030\347\007\n\030\022\023\010\001\020\001\030\001 \002(\0010\001\302>\004\010\000\020\003\030\350\007 \346\007(\350\007"
// clang-format on
// NOLINTEND

@ -26,7 +26,8 @@ namespace pb {
inline constexpr CppFeatures::Impl_::Impl_(
::_pbi::ConstantInitialized) noexcept
: _cached_size_{0},
legacy_closed_enum_{false} {}
legacy_closed_enum_{false},
string_type_{static_cast< ::pb::CppFeatures_StringType >(0)} {}
template <typename>
PROTOBUF_CONSTEXPR CppFeatures::CppFeatures(::_pbi::ConstantInitialized)
@ -42,8 +43,7 @@ struct CppFeaturesDefaultTypeInternal {
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_EXPORT
PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 CppFeaturesDefaultTypeInternal _CppFeatures_default_instance_;
} // namespace pb
static constexpr const ::_pb::EnumDescriptor**
file_level_enum_descriptors_google_2fprotobuf_2fcpp_5ffeatures_2eproto = nullptr;
static const ::_pb::EnumDescriptor* file_level_enum_descriptors_google_2fprotobuf_2fcpp_5ffeatures_2eproto[1];
static constexpr const ::_pb::ServiceDescriptor**
file_level_service_descriptors_google_2fprotobuf_2fcpp_5ffeatures_2eproto = nullptr;
const ::uint32_t
@ -58,12 +58,14 @@ const ::uint32_t
~0u, // no _split_
~0u, // no sizeof(Split)
PROTOBUF_FIELD_OFFSET(::pb::CppFeatures, _impl_.legacy_closed_enum_),
PROTOBUF_FIELD_OFFSET(::pb::CppFeatures, _impl_.string_type_),
0,
1,
};
static const ::_pbi::MigrationSchema
schemas[] ABSL_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
{0, 9, -1, sizeof(::pb::CppFeatures)},
{0, 10, -1, sizeof(::pb::CppFeatures)},
};
static const ::_pb::Message* const file_default_instances[] = {
&::pb::_CppFeatures_default_instance_._instance,
@ -71,11 +73,15 @@ static const ::_pb::Message* const file_default_instances[] = {
const char descriptor_table_protodef_google_2fprotobuf_2fcpp_5ffeatures_2eproto[] ABSL_ATTRIBUTE_SECTION_VARIABLE(
protodesc_cold) = {
"\n\"google/protobuf/cpp_features.proto\022\002pb"
"\032 google/protobuf/descriptor.proto\"M\n\013Cp"
"pFeatures\022>\n\022legacy_closed_enum\030\001 \001(\010B\"\210"
"\001\001\230\001\004\230\001\001\242\001\t\022\004true\030\346\007\242\001\n\022\005false\030\347\007::\n\003cpp"
"\022\033.google.protobuf.FeatureSet\030\350\007 \001(\0132\017.p"
"b.CppFeatures"
"\032 google/protobuf/descriptor.proto\"\352\001\n\013C"
"ppFeatures\022>\n\022legacy_closed_enum\030\001 \001(\010B\""
"\210\001\001\230\001\004\230\001\001\242\001\t\022\004true\030\346\007\242\001\n\022\005false\030\347\007\022T\n\013st"
"ring_type\030\002 \001(\0162\032.pb.CppFeatures.StringT"
"ypeB#\210\001\001\230\001\004\230\001\001\242\001\013\022\006STRING\030\346\007\242\001\t\022\004VIEW\030\351\007"
"\"E\n\nStringType\022\027\n\023STRING_TYPE_UNKNOWN\020\000\022"
"\010\n\004VIEW\020\001\022\010\n\004CORD\020\002\022\n\n\006STRING\020\003::\n\003cpp\022\033"
".google.protobuf.FeatureSet\030\350\007 \001(\0132\017.pb."
"CppFeatures"
};
static const ::_pbi::DescriptorTable* const descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2eproto_deps[1] =
{
@ -85,7 +91,7 @@ static ::absl::once_flag descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2ep
PROTOBUF_CONSTINIT const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2eproto = {
false,
false,
213,
371,
descriptor_table_protodef_google_2fprotobuf_2fcpp_5ffeatures_2eproto,
"google/protobuf/cpp_features.proto",
&descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2eproto_once,
@ -99,6 +105,28 @@ PROTOBUF_CONSTINIT const ::_pbi::DescriptorTable descriptor_table_google_2fproto
file_level_service_descriptors_google_2fprotobuf_2fcpp_5ffeatures_2eproto,
};
namespace pb {
const ::google::protobuf::EnumDescriptor* CppFeatures_StringType_descriptor() {
::google::protobuf::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2eproto);
return file_level_enum_descriptors_google_2fprotobuf_2fcpp_5ffeatures_2eproto[0];
}
PROTOBUF_CONSTINIT const uint32_t CppFeatures_StringType_internal_data_[] = {
262144u, 0u, };
bool CppFeatures_StringType_IsValid(int value) {
return 0 <= value && value <= 3;
}
#if (__cplusplus < 201703) && \
(!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912))
constexpr CppFeatures_StringType CppFeatures::STRING_TYPE_UNKNOWN;
constexpr CppFeatures_StringType CppFeatures::VIEW;
constexpr CppFeatures_StringType CppFeatures::CORD;
constexpr CppFeatures_StringType CppFeatures::STRING;
constexpr CppFeatures_StringType CppFeatures::StringType_MIN;
constexpr CppFeatures_StringType CppFeatures::StringType_MAX;
constexpr int CppFeatures::StringType_ARRAYSIZE;
#endif // (__cplusplus < 201703) &&
// (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912))
// ===================================================================
class CppFeatures::_Internal {
@ -125,7 +153,12 @@ inline PROTOBUF_NDEBUG_INLINE CppFeatures::Impl_::Impl_(
inline void CppFeatures::SharedCtor(::_pb::Arena* arena) {
new (&_impl_) Impl_(internal_visibility(), arena);
_impl_.legacy_closed_enum_ = {};
::memset(reinterpret_cast<char *>(&_impl_) +
offsetof(Impl_, legacy_closed_enum_),
0,
offsetof(Impl_, string_type_) -
offsetof(Impl_, legacy_closed_enum_) +
sizeof(Impl_::string_type_));
}
CppFeatures::~CppFeatures() {
// @@protoc_insertion_point(destructor:pb.CppFeatures)
@ -154,23 +187,26 @@ CppFeatures::GetClassData() const {
return _data_.base();
}
PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1
const ::_pbi::TcParseTable<0, 1, 0, 0, 2> CppFeatures::_table_ = {
const ::_pbi::TcParseTable<1, 2, 1, 0, 2> CppFeatures::_table_ = {
{
PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_._has_bits_),
0, // no _extensions_
1, 0, // max_field_number, fast_idx_mask
2, 8, // max_field_number, fast_idx_mask
offsetof(decltype(_table_), field_lookup_table),
4294967294, // skipmap
4294967292, // skipmap
offsetof(decltype(_table_), field_entries),
1, // num_field_entries
0, // num_aux_entries
offsetof(decltype(_table_), field_names), // no aux_entries
2, // num_field_entries
1, // num_aux_entries
offsetof(decltype(_table_), aux_entries),
&_CppFeatures_default_instance_._instance,
::_pbi::TcParser::GenericFallback, // fallback
#ifdef PROTOBUF_PREFETCH_PARSE_TABLE
::_pbi::TcParser::GetTable<::pb::CppFeatures>(), // to_prefetch
#endif // PROTOBUF_PREFETCH_PARSE_TABLE
}, {{
// optional .pb.CppFeatures.StringType string_type = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
{::_pbi::TcParser::FastEr0S1,
{16, 1, 3, PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.string_type_)}},
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
{::_pbi::TcParser::SingularVarintNoZag1<bool, offsetof(CppFeatures, _impl_.legacy_closed_enum_), 0>(),
{8, 0, 0, PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.legacy_closed_enum_)}},
@ -180,9 +216,12 @@ const ::_pbi::TcParseTable<0, 1, 0, 0, 2> CppFeatures::_table_ = {
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
{PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.legacy_closed_enum_), _Internal::kHasBitsOffset + 0, 0,
(0 | ::_fl::kFcOptional | ::_fl::kBool)},
}},
// no aux_entries
{{
// optional .pb.CppFeatures.StringType string_type = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
{PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.string_type_), _Internal::kHasBitsOffset + 1, 0,
(0 | ::_fl::kFcOptional | ::_fl::kEnumRange)},
}}, {{
{0, 4},
}}, {{
}},
};
@ -193,7 +232,12 @@ PROTOBUF_NOINLINE void CppFeatures::Clear() {
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
_impl_.legacy_closed_enum_ = false;
cached_has_bits = _impl_._has_bits_[0];
if (cached_has_bits & 0x00000003u) {
::memset(&_impl_.legacy_closed_enum_, 0, static_cast<::size_t>(
reinterpret_cast<char*>(&_impl_.string_type_) -
reinterpret_cast<char*>(&_impl_.legacy_closed_enum_)) + sizeof(_impl_.string_type_));
}
_impl_._has_bits_.Clear();
_internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>();
}
@ -220,6 +264,13 @@ const char* CppFeatures::_InternalParse(
1, this->_internal_legacy_closed_enum(), target);
}
// optional .pb.CppFeatures.StringType string_type = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000002u) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray(
2, this->_internal_string_type(), target);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target =
::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray(
@ -237,12 +288,20 @@ const char* CppFeatures::_InternalParse(
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
cached_has_bits = _impl_._has_bits_[0];
if (cached_has_bits & 0x00000001u) {
total_size += 2;
}
if (cached_has_bits & 0x00000003u) {
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000001u) {
total_size += 2;
}
// optional .pb.CppFeatures.StringType string_type = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
if (cached_has_bits & 0x00000002u) {
total_size += 1 +
::_pbi::WireFormatLite::EnumSize(this->_internal_string_type());
}
}
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
}
@ -256,8 +315,13 @@ void CppFeatures::MergeImpl(::google::protobuf::MessageLite& to_msg, const ::goo
(void) cached_has_bits;
cached_has_bits = from._impl_._has_bits_[0];
if (cached_has_bits & 0x00000001u) {
_this->_impl_.legacy_closed_enum_ = from._impl_.legacy_closed_enum_;
if (cached_has_bits & 0x00000003u) {
if (cached_has_bits & 0x00000001u) {
_this->_impl_.legacy_closed_enum_ = from._impl_.legacy_closed_enum_;
}
if (cached_has_bits & 0x00000002u) {
_this->_impl_.string_type_ = from._impl_.string_type_;
}
}
_this->_impl_._has_bits_[0] |= cached_has_bits;
_this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_);
@ -278,7 +342,12 @@ void CppFeatures::InternalSwap(CppFeatures* PROTOBUF_RESTRICT other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
swap(_impl_.legacy_closed_enum_, other->_impl_.legacy_closed_enum_);
::google::protobuf::internal::memswap<
PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.string_type_)
+ sizeof(CppFeatures::_impl_.string_type_)
- PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_.legacy_closed_enum_)>(
reinterpret_cast<char*>(&_impl_.legacy_closed_enum_),
reinterpret_cast<char*>(&other->_impl_.legacy_closed_enum_));
}
::google::protobuf::Metadata CppFeatures::GetMetadata() const {

@ -27,6 +27,7 @@
#include "google/protobuf/message.h"
#include "google/protobuf/repeated_field.h" // IWYU pragma: export
#include "google/protobuf/extension_set.h" // IWYU pragma: export
#include "google/protobuf/generated_enum_reflection.h"
#include "google/protobuf/unknown_field_set.h"
#include "google/protobuf/descriptor.pb.h"
// @@protoc_insertion_point(includes)
@ -61,6 +62,37 @@ namespace protobuf {
} // namespace google
namespace pb {
enum CppFeatures_StringType : int {
CppFeatures_StringType_STRING_TYPE_UNKNOWN = 0,
CppFeatures_StringType_VIEW = 1,
CppFeatures_StringType_CORD = 2,
CppFeatures_StringType_STRING = 3,
};
PROTOBUF_EXPORT bool CppFeatures_StringType_IsValid(int value);
PROTOBUF_EXPORT extern const uint32_t CppFeatures_StringType_internal_data_[];
constexpr CppFeatures_StringType CppFeatures_StringType_StringType_MIN = static_cast<CppFeatures_StringType>(0);
constexpr CppFeatures_StringType CppFeatures_StringType_StringType_MAX = static_cast<CppFeatures_StringType>(3);
constexpr int CppFeatures_StringType_StringType_ARRAYSIZE = 3 + 1;
PROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor*
CppFeatures_StringType_descriptor();
template <typename T>
const std::string& CppFeatures_StringType_Name(T value) {
static_assert(std::is_same<T, CppFeatures_StringType>::value ||
std::is_integral<T>::value,
"Incorrect type passed to StringType_Name().");
return CppFeatures_StringType_Name(static_cast<CppFeatures_StringType>(value));
}
template <>
inline const std::string& CppFeatures_StringType_Name(CppFeatures_StringType value) {
return ::google::protobuf::internal::NameOfDenseEnum<CppFeatures_StringType_descriptor,
0, 3>(
static_cast<int>(value));
}
inline bool CppFeatures_StringType_Parse(absl::string_view name, CppFeatures_StringType* value) {
return ::google::protobuf::internal::ParseNamedEnum<CppFeatures_StringType>(
CppFeatures_StringType_descriptor(), name, value);
}
// ===================================================================
@ -188,10 +220,32 @@ class PROTOBUF_EXPORT CppFeatures final : public ::google::protobuf::Message
public:
::google::protobuf::Metadata GetMetadata() const;
// nested types ----------------------------------------------------
using StringType = CppFeatures_StringType;
static constexpr StringType STRING_TYPE_UNKNOWN = CppFeatures_StringType_STRING_TYPE_UNKNOWN;
static constexpr StringType VIEW = CppFeatures_StringType_VIEW;
static constexpr StringType CORD = CppFeatures_StringType_CORD;
static constexpr StringType STRING = CppFeatures_StringType_STRING;
static inline bool StringType_IsValid(int value) {
return CppFeatures_StringType_IsValid(value);
}
static constexpr StringType StringType_MIN = CppFeatures_StringType_StringType_MIN;
static constexpr StringType StringType_MAX = CppFeatures_StringType_StringType_MAX;
static constexpr int StringType_ARRAYSIZE = CppFeatures_StringType_StringType_ARRAYSIZE;
static inline const ::google::protobuf::EnumDescriptor* StringType_descriptor() {
return CppFeatures_StringType_descriptor();
}
template <typename T>
static inline const std::string& StringType_Name(T value) {
return CppFeatures_StringType_Name(value);
}
static inline bool StringType_Parse(absl::string_view name, StringType* value) {
return CppFeatures_StringType_Parse(name, value);
}
// accessors -------------------------------------------------------
enum : int {
kLegacyClosedEnumFieldNumber = 1,
kStringTypeFieldNumber = 2,
};
// optional bool legacy_closed_enum = 1 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
bool has_legacy_closed_enum() const;
@ -203,13 +257,24 @@ class PROTOBUF_EXPORT CppFeatures final : public ::google::protobuf::Message
bool _internal_legacy_closed_enum() const;
void _internal_set_legacy_closed_enum(bool value);
public:
// optional .pb.CppFeatures.StringType string_type = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
bool has_string_type() const;
void clear_string_type() ;
::pb::CppFeatures_StringType string_type() const;
void set_string_type(::pb::CppFeatures_StringType value);
private:
::pb::CppFeatures_StringType _internal_string_type() const;
void _internal_set_string_type(::pb::CppFeatures_StringType value);
public:
// @@protoc_insertion_point(class_scope:pb.CppFeatures)
private:
class _Internal;
friend class ::google::protobuf::internal::TcParser;
static const ::google::protobuf::internal::TcParseTable<
0, 1, 0,
1, 2, 1,
0, 2>
_table_;
friend class ::google::protobuf::MessageLite;
@ -228,6 +293,7 @@ class PROTOBUF_EXPORT CppFeatures final : public ::google::protobuf::Message
::google::protobuf::internal::HasBits<1> _has_bits_;
mutable ::google::protobuf::internal::CachedSize _cached_size_;
bool legacy_closed_enum_;
int string_type_;
PROTOBUF_TSAN_DECLARE_MEMBER
};
union { Impl_ _impl_; };
@ -283,6 +349,35 @@ inline void CppFeatures::_internal_set_legacy_closed_enum(bool value) {
_impl_.legacy_closed_enum_ = value;
}
// optional .pb.CppFeatures.StringType string_type = 2 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = {
inline bool CppFeatures::has_string_type() const {
bool value = (_impl_._has_bits_[0] & 0x00000002u) != 0;
return value;
}
inline void CppFeatures::clear_string_type() {
PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race);
_impl_.string_type_ = 0;
_impl_._has_bits_[0] &= ~0x00000002u;
}
inline ::pb::CppFeatures_StringType CppFeatures::string_type() const {
// @@protoc_insertion_point(field_get:pb.CppFeatures.string_type)
return _internal_string_type();
}
inline void CppFeatures::set_string_type(::pb::CppFeatures_StringType value) {
_internal_set_string_type(value);
_impl_._has_bits_[0] |= 0x00000002u;
// @@protoc_insertion_point(field_set:pb.CppFeatures.string_type)
}
inline ::pb::CppFeatures_StringType CppFeatures::_internal_string_type() const {
PROTOBUF_TSAN_READ(&_impl_._tsan_detect_race);
return static_cast<::pb::CppFeatures_StringType>(_impl_.string_type_);
}
inline void CppFeatures::_internal_set_string_type(::pb::CppFeatures_StringType value) {
PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race);
assert(::pb::CppFeatures_StringType_IsValid(value));
_impl_.string_type_ = value;
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__
@ -291,6 +386,19 @@ inline void CppFeatures::_internal_set_legacy_closed_enum(bool value) {
} // namespace pb
namespace google {
namespace protobuf {
template <>
struct is_proto_enum<::pb::CppFeatures_StringType> : std::true_type {};
template <>
inline const EnumDescriptor* GetEnumDescriptor<::pb::CppFeatures_StringType>() {
return ::pb::CppFeatures_StringType_descriptor();
}
} // namespace protobuf
} // namespace google
// @@protoc_insertion_point(global_scope)
#include "google/protobuf/port_undef.inc"

@ -27,4 +27,19 @@ message CppFeatures {
edition_defaults = { edition: EDITION_PROTO2, value: "true" },
edition_defaults = { edition: EDITION_PROTO3, value: "false" }
];
enum StringType {
STRING_TYPE_UNKNOWN = 0;
VIEW = 1;
CORD = 2;
STRING = 3;
}
optional StringType string_type = 2 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_FIELD,
targets = TARGET_TYPE_FILE,
edition_defaults = { edition: EDITION_PROTO2, value: "STRING" },
edition_defaults = { edition: EDITION_2024, value: "VIEW" }
];
}

@ -7415,30 +7415,33 @@ TEST_F(FeaturesTest, Proto2Features) {
const FieldDescriptor* group = message->field(1);
EXPECT_THAT(file->options(), EqualsProto(""));
EXPECT_EQ(GetFeatures(file).GetExtension(pb::test).int_file_feature(), -2);
EXPECT_THAT(GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
[pb.cpp] { legacy_closed_enum: true })pb"));
EXPECT_THAT(GetCoreFeatures(field), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
[pb.cpp] { legacy_closed_enum: true })pb"));
EXPECT_THAT(GetCoreFeatures(group), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: DELIMITED
json_format: LEGACY_BEST_EFFORT
[pb.cpp] { legacy_closed_enum: true })pb"));
EXPECT_THAT(
GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
[pb.cpp] { legacy_closed_enum: true string_type: STRING })pb"));
EXPECT_THAT(
GetCoreFeatures(field), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
[pb.cpp] { legacy_closed_enum: true string_type: STRING })pb"));
EXPECT_THAT(
GetCoreFeatures(group), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: DELIMITED
json_format: LEGACY_BEST_EFFORT
[pb.cpp] { legacy_closed_enum: true string_type: STRING })pb"));
EXPECT_TRUE(field->has_presence());
EXPECT_FALSE(field->requires_utf8_validation());
EXPECT_EQ(
@ -7492,22 +7495,24 @@ TEST_F(FeaturesTest, Proto3Features) {
const FieldDescriptor* field = message->field(0);
EXPECT_THAT(file->options(), EqualsProto(""));
EXPECT_EQ(GetFeatures(file).GetExtension(pb::test).int_file_feature(), -3);
EXPECT_THAT(GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false })pb"));
EXPECT_THAT(GetCoreFeatures(field), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false })pb"));
EXPECT_THAT(
GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_THAT(
GetCoreFeatures(field), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
EXPECT_FALSE(field->has_presence());
EXPECT_FALSE(field->requires_utf8_validation());
EXPECT_EQ(
@ -7646,7 +7651,7 @@ TEST_F(FeaturesTest, Edition2023Defaults) {
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false }
[pb.cpp] { legacy_closed_enum: false string_type: STRING }
)pb"));
// Since pb::test is registered in the pool, it should end up with defaults in
@ -7674,7 +7679,7 @@ TEST_F(FeaturesBaseTest, DefaultEdition2023Defaults) {
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false }
[pb.cpp] { legacy_closed_enum: false string_type: STRING }
)pb"));
EXPECT_FALSE(GetFeatures(file).HasExtension(pb::test));
}
@ -7691,14 +7696,15 @@ TEST_F(FeaturesTest, ClearsOptions) {
}
)pb");
EXPECT_THAT(file->options(), EqualsProto("java_package: 'bar'"));
EXPECT_THAT(GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false })pb"));
EXPECT_THAT(
GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
}
TEST_F(FeaturesTest, RestoresOptionsRoundTrip) {
@ -8055,14 +8061,15 @@ TEST_F(FeaturesTest, NoOptions) {
name: "foo.proto" syntax: "editions" edition: EDITION_2023
)pb");
EXPECT_EQ(&file->options(), &FileOptions::default_instance());
EXPECT_THAT(GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false })pb"));
EXPECT_THAT(
GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
}
TEST_F(FeaturesTest, InvalidEdition) {
@ -8084,14 +8091,15 @@ TEST_F(FeaturesTest, FileFeatures) {
options { features { field_presence: IMPLICIT } }
)pb");
EXPECT_THAT(file->options(), EqualsProto(""));
EXPECT_THAT(GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false })pb"));
EXPECT_THAT(
GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
}
TEST_F(FeaturesTest, FileFeaturesExtension) {
@ -8159,14 +8167,15 @@ TEST_F(FeaturesTest, MessageFeaturesDefault) {
)pb");
const Descriptor* message = file->message_type(0);
EXPECT_THAT(message->options(), EqualsProto(""));
EXPECT_THAT(GetCoreFeatures(message), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false })pb"));
EXPECT_THAT(
GetCoreFeatures(message), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
}
TEST_F(FeaturesTest, MessageFeaturesInherit) {
@ -8264,14 +8273,15 @@ TEST_F(FeaturesTest, FieldFeaturesDefault) {
)pb");
const FieldDescriptor* field = file->message_type(0)->field(0);
EXPECT_THAT(field->options(), EqualsProto(""));
EXPECT_THAT(GetCoreFeatures(field), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false })pb"));
EXPECT_THAT(
GetCoreFeatures(field), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
}
TEST_F(FeaturesTest, FieldFeaturesInherit) {
@ -8652,14 +8662,15 @@ TEST_F(FeaturesTest, EnumFeaturesDefault) {
)pb");
const EnumDescriptor* enm = file->enum_type(0);
EXPECT_THAT(enm->options(), EqualsProto(""));
EXPECT_THAT(GetCoreFeatures(enm), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false })pb"));
EXPECT_THAT(
GetCoreFeatures(enm), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
}
TEST_F(FeaturesTest, EnumFeaturesInherit) {
@ -8759,14 +8770,15 @@ TEST_F(FeaturesTest, EnumValueFeaturesDefault) {
)pb");
const EnumValueDescriptor* value = file->enum_type(0)->value(0);
EXPECT_THAT(value->options(), EqualsProto(""));
EXPECT_THAT(GetCoreFeatures(value), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false })pb"));
EXPECT_THAT(
GetCoreFeatures(value), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
}
TEST_F(FeaturesTest, EnumValueFeaturesInherit) {
@ -8851,14 +8863,15 @@ TEST_F(FeaturesTest, OneofFeaturesDefault) {
)pb");
const OneofDescriptor* oneof = file->message_type(0)->oneof_decl(0);
EXPECT_THAT(oneof->options(), EqualsProto(""));
EXPECT_THAT(GetCoreFeatures(oneof), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false })pb"));
EXPECT_THAT(
GetCoreFeatures(oneof), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
}
TEST_F(FeaturesTest, OneofFeaturesInherit) {
@ -8950,14 +8963,15 @@ TEST_F(FeaturesTest, ExtensionRangeFeaturesDefault) {
const Descriptor::ExtensionRange* range =
file->message_type(0)->extension_range(0);
EXPECT_THAT(range->options(), EqualsProto(""));
EXPECT_THAT(GetCoreFeatures(range), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false })pb"));
EXPECT_THAT(
GetCoreFeatures(range), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
}
TEST_F(FeaturesTest, ExtensionRangeFeaturesInherit) {
@ -9034,14 +9048,15 @@ TEST_F(FeaturesTest, ServiceFeaturesDefault) {
)pb");
const ServiceDescriptor* service = file->service(0);
EXPECT_THAT(service->options(), EqualsProto(""));
EXPECT_THAT(GetCoreFeatures(service), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false })pb"));
EXPECT_THAT(
GetCoreFeatures(service), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
}
TEST_F(FeaturesTest, ServiceFeaturesInherit) {
@ -9100,14 +9115,15 @@ TEST_F(FeaturesTest, MethodFeaturesDefault) {
)pb");
const MethodDescriptor* method = file->service(0)->method(0);
EXPECT_THAT(method->options(), EqualsProto(""));
EXPECT_THAT(GetCoreFeatures(method), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false })pb"));
EXPECT_THAT(
GetCoreFeatures(method), EqualsProto(R"pb(
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
}
TEST_F(FeaturesTest, MethodFeaturesInherit) {
@ -9313,7 +9329,7 @@ TEST_F(FeaturesTest, EnumFeatureHelpers) {
type_name: "FooOpen"
options {
features {
[pb.cpp] { legacy_closed_enum: true }
[pb.cpp] { legacy_closed_enum: true string_type: STRING }
}
}
}
@ -9931,14 +9947,15 @@ TEST_F(FeaturesTest, UninterpretedOptions) {
}
)pb");
EXPECT_THAT(file->options(), EqualsProto(""));
EXPECT_THAT(GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false })pb"));
EXPECT_THAT(
GetCoreFeatures(file), EqualsProto(R"pb(
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false string_type: STRING })pb"));
}
TEST_F(FeaturesTest, UninterpretedOptionsMerge) {

@ -146,7 +146,7 @@ TEST(Generated, EditionDefaults2023InternalFeatures) {
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.cpp] { legacy_closed_enum: false }
[pb.cpp] { legacy_closed_enum: false string_type: STRING }
)pb"));
}

Loading…
Cancel
Save