Add a unittest locking down presence behavior for proto3 extensions

PiperOrigin-RevId: 613016814
pull/16070/head
Mike Kruskal 9 months ago committed by Copybara-Service
parent 16f96d15eb
commit 7de0ad1adb
  1. 1
      src/google/protobuf/BUILD.bazel
  2. 14
      src/google/protobuf/extension_set_unittest.cc
  3. 13
      src/google/protobuf/unittest_proto3_extensions.proto

@ -828,6 +828,7 @@ filegroup(
"unittest_proto3_arena.proto",
"unittest_proto3_arena_lite.proto",
"unittest_proto3_bad_macros.proto",
"unittest_proto3_extensions.proto",
"unittest_proto3_lite.proto",
"unittest_proto3_optional.proto",
"unittest_retention.proto",

@ -32,6 +32,7 @@
#include "google/protobuf/unittest.pb.h"
#include "google/protobuf/unittest.pb.h"
#include "google/protobuf/unittest_mset.pb.h"
#include "google/protobuf/unittest_proto3_extensions.pb.h"
#include "google/protobuf/wire_format.h"
#include "google/protobuf/wire_format_lite.h"
@ -1393,6 +1394,19 @@ TEST(ExtensionSetTest, Proto3PackedDynamicExtensions) {
EXPECT_EQ(reserialized_options, "\xca\xb5\x18\x01\x01");
}
TEST(ExtensionSetTest, Proto3ExtensionPresenceSingular) {
using protobuf_unittest::Proto3FileExtensions;
FileDescriptorProto file;
EXPECT_FALSE(file.options().HasExtension(Proto3FileExtensions::singular_int));
EXPECT_EQ(file.options().GetExtension(Proto3FileExtensions::singular_int), 0);
file.mutable_options()->SetExtension(Proto3FileExtensions::singular_int, 1);
EXPECT_TRUE(file.options().HasExtension(Proto3FileExtensions::singular_int));
EXPECT_EQ(file.options().GetExtension(Proto3FileExtensions::singular_int), 1);
}
TEST(ExtensionSetTest, BoolExtension) {
unittest::TestAllExtensions msg;
uint8_t wire_bytes[2] = {13 * 8, 42 /* out of bounds payload for bool */};

@ -0,0 +1,13 @@
syntax = "proto3";
package protobuf_unittest;
import "google/protobuf/descriptor.proto";
// For testing proto3 extension behaviors.
message Proto3FileExtensions {
extend google.protobuf.FileOptions {
int32 singular_int = 1001;
repeated int32 repeated_int = 1002;
}
}
Loading…
Cancel
Save