Merge tag 'refs/tags/sync-piper' into sync-stage

# Conflicts:
#	csharp/src/Google.Protobuf.Test/testprotos.pb
This commit is contained in:
Mike Kruskal 2022-04-04 13:50:21 -07:00
commit 701650b7d0
99 changed files with 1341 additions and 666 deletions

View File

@ -153,6 +153,7 @@ set(tests_files
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/annotation_test_util.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/command_line_interface_unittest.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/message_size_unittest.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/metadata_test.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/move_unittest.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/plugin_unittest.cc

View File

@ -2226,11 +2226,11 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForNonRepeatedTypes() {
"optional_aliased_enum: ALIAS_BAZ");
RunValidJsonTest(
"EnumFieldWithAliasUseAlias", REQUIRED,
R"({"optionalAliasedEnum": "QUX"})",
R"({"optionalAliasedEnum": "MOO"})",
"optional_aliased_enum: ALIAS_BAZ");
RunValidJsonTest(
"EnumFieldWithAliasLowerCase", REQUIRED,
R"({"optionalAliasedEnum": "qux"})",
R"({"optionalAliasedEnum": "moo"})",
"optional_aliased_enum: ALIAS_BAZ");
RunValidJsonTest(
"EnumFieldWithAliasDifferentCase", REQUIRED,

View File

@ -226,7 +226,7 @@ namespace ProtobufTestMessages.Proto3 {
"dG8zLkZvcmVpZ25FbnVtOgI4ASI5CgpOZXN0ZWRFbnVtEgcKA0ZPTxAAEgcK",
"A0JBUhABEgcKA0JBWhACEhAKA05FRxD///////////8BIlkKC0FsaWFzZWRF",
"bnVtEg0KCUFMSUFTX0ZPTxAAEg0KCUFMSUFTX0JBUhABEg0KCUFMSUFTX0JB",
"WhACEgcKA1FVWBACEgcKA3F1eBACEgcKA2JBehACGgIQAUINCgtvbmVvZl9m",
"WhACEgcKA01PTxACEgcKA21vbxACEgcKA2JBehACGgIQAUINCgtvbmVvZl9m",
"aWVsZEoGCPUDEP8DIhsKDkZvcmVpZ25NZXNzYWdlEgkKAWMYASABKAUiFgoU",
"TnVsbEh5cG90aGVzaXNQcm90bzMiLwoORW51bU9ubHlQcm90bzMiHQoEQm9v",
"bBIKCgZrRmFsc2UQABIJCgVrVHJ1ZRABKkAKC0ZvcmVpZ25FbnVtEg8KC0ZP",
@ -5432,8 +5432,8 @@ namespace ProtobufTestMessages.Proto3 {
[pbr::OriginalName("ALIAS_FOO")] AliasFoo = 0,
[pbr::OriginalName("ALIAS_BAR")] AliasBar = 1,
[pbr::OriginalName("ALIAS_BAZ")] AliasBaz = 2,
[pbr::OriginalName("QUX", PreferredAlias = false)] Qux = 2,
[pbr::OriginalName("qux", PreferredAlias = false)] Qux_ = 2,
[pbr::OriginalName("MOO", PreferredAlias = false)] Moo = 2,
[pbr::OriginalName("moo", PreferredAlias = false)] Moo_ = 2,
[pbr::OriginalName("bAz", PreferredAlias = false)] BAz = 2,
}

View File

@ -9611,8 +9611,8 @@ namespace Google.Protobuf.Reflection {
/// The name of the uninterpreted option. Each string represents a segment in
/// a dot-separated name. is_extension is true iff a segment represents an
/// extension (denoted with parentheses in options specs in .proto files).
/// E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
/// "foo.(bar.baz).qux".
/// E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents
/// "foo.(bar.baz).moo".
/// </summary>
public sealed partial class NamePart : pb::IMessage<NamePart>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
@ -10241,13 +10241,13 @@ namespace Google.Protobuf.Reflection {
/// // Comment attached to baz.
/// // Another line attached to baz.
///
/// // Comment attached to qux.
/// // Comment attached to moo.
/// //
/// // Another line attached to qux.
/// optional double qux = 4;
/// // Another line attached to moo.
/// optional double moo = 4;
///
/// // Detached comment for corge. This is not leading or trailing comments
/// // to qux or corge because there are blank lines separating it from
/// // to moo or corge because there are blank lines separating it from
/// // both.
///
/// // Detached comment for corge paragraph 2.

View File

@ -1295,13 +1295,13 @@ public final class Descriptors {
* }
* message Bar {
* extend Foo {
* optional int32 qux = 4321;
* optional int32 moo = 4321;
* }
* }
* </pre>
*
* Both {@code baz}'s and {@code qux}'s containing type is {@code Foo}. However, {@code baz}'s
* extension scope is {@code null} while {@code qux}'s extension scope is {@code Bar}.
* Both {@code baz}'s and {@code moo}'s containing type is {@code Foo}. However, {@code baz}'s
* extension scope is {@code null} while {@code moo}'s extension scope is {@code Bar}.
*/
public Descriptor getExtensionScope() {
if (!isExtension()) {

View File

@ -472,7 +472,7 @@ public final class TextFormat {
private final FieldDescriptor.JavaType fieldType;
public MapEntryAdapter(Object entry, FieldDescriptor fieldDescriptor) {
MapEntryAdapter(Object entry, FieldDescriptor fieldDescriptor) {
if (entry instanceof MapEntry) {
this.mapEntry = (MapEntry) entry;
} else {
@ -485,14 +485,14 @@ public final class TextFormat {
return fieldDescriptor.getMessageType().getFields().get(0).getJavaType();
}
public Object getKey() {
Object getKey() {
if (mapEntry != null) {
return mapEntry.getKey();
}
return null;
}
public Object getEntry() {
Object getEntry() {
if (mapEntry != null) {
return mapEntry;
}
@ -1557,13 +1557,13 @@ public final class TextFormat {
/**
* Determines if repeated values for non-repeated fields and oneofs are permitted. For example,
* given required/optional field "foo" and a oneof containing "baz" and "qux":
* given required/optional field "foo" and a oneof containing "baz" and "moo":
*
* <ul>
* <li>"foo: 1 foo: 2"
* <li>"baz: 1 qux: 2"
* <li>"baz: 1 moo: 2"
* <li>merging "foo: 2" into a proto in which foo is already set, or
* <li>merging "qux: 2" into a proto in which baz is already set.
* <li>merging "moo: 2" into a proto in which baz is already set.
* </ul>
*/
public enum SingularOverwritePolicy {

View File

@ -1498,7 +1498,7 @@ public class GeneratedMessageTest {
assertThat(message.hasFooStringPiece()).isTrue();
TestUtil.assertAtMostOneFieldSetOneof(message);
message = builder.setFooBytes(TestUtil.toBytes("qux")).buildPartial();
message = builder.setFooBytes(TestUtil.toBytes("moo")).buildPartial();
assertThat(message.hasFooBytes()).isTrue();
TestUtil.assertAtMostOneFieldSetOneof(message);
@ -1508,7 +1508,7 @@ public class GeneratedMessageTest {
message =
builder
.setFooMessage(TestOneof2.NestedMessage.newBuilder().setQuxInt(234).build())
.setFooMessage(TestOneof2.NestedMessage.newBuilder().setMooInt(234).build())
.buildPartial();
assertThat(message.hasFooMessage()).isTrue();
TestUtil.assertAtMostOneFieldSetOneof(message);
@ -1625,31 +1625,31 @@ public class GeneratedMessageTest {
{
// set
TestOneof2.Builder builder = TestOneof2.newBuilder();
assertThat(builder.getFooMessage().getQuxInt()).isEqualTo(0);
builder.setFooMessage(TestOneof2.NestedMessage.newBuilder().setQuxInt(234).build());
assertThat(builder.getFooMessage().getMooInt()).isEqualTo(0);
builder.setFooMessage(TestOneof2.NestedMessage.newBuilder().setMooInt(234).build());
assertThat(builder.hasFooMessage()).isTrue();
assertThat(builder.getFooMessage().getQuxInt()).isEqualTo(234);
assertThat(builder.getFooMessage().getMooInt()).isEqualTo(234);
TestOneof2 message = builder.buildPartial();
assertThat(message.hasFooMessage()).isTrue();
assertThat(message.getFooMessage().getQuxInt()).isEqualTo(234);
assertThat(message.getFooMessage().getMooInt()).isEqualTo(234);
// clear
assertThat(builder.clearFooMessage().hasFooString()).isFalse();
message = builder.build();
assertThat(message.hasFooMessage()).isFalse();
assertThat(message.getFooMessage().getQuxInt()).isEqualTo(0);
assertThat(message.getFooMessage().getMooInt()).isEqualTo(0);
// nested builder
builder = TestOneof2.newBuilder();
assertThat(builder.getFooMessageOrBuilder())
.isSameInstanceAs(TestOneof2.NestedMessage.getDefaultInstance());
assertThat(builder.hasFooMessage()).isFalse();
builder.getFooMessageBuilder().setQuxInt(123);
builder.getFooMessageBuilder().setMooInt(123);
assertThat(builder.hasFooMessage()).isTrue();
assertThat(builder.getFooMessage().getQuxInt()).isEqualTo(123);
assertThat(builder.getFooMessage().getMooInt()).isEqualTo(123);
message = builder.build();
assertThat(message.hasFooMessage()).isTrue();
assertThat(message.getFooMessage().getQuxInt()).isEqualTo(123);
assertThat(message.getFooMessage().getMooInt()).isEqualTo(123);
}
// LazyMessage is tested in LazyMessageLiteTest.java
@ -1689,10 +1689,10 @@ public class GeneratedMessageTest {
public void testOneofMergeMessage_mergeIntoNewBuilder() {
TestOneof2.Builder builder = TestOneof2.newBuilder();
TestOneof2 message =
builder.setFooMessage(TestOneof2.NestedMessage.newBuilder().setQuxInt(234).build()).build();
builder.setFooMessage(TestOneof2.NestedMessage.newBuilder().setMooInt(234).build()).build();
TestOneof2 message2 = TestOneof2.newBuilder().mergeFrom(message).build();
assertThat(message2.hasFooMessage()).isTrue();
assertThat(message2.getFooMessage().getQuxInt()).isEqualTo(234);
assertThat(message2.getFooMessage().getMooInt()).isEqualTo(234);
}
@Test
@ -1755,12 +1755,12 @@ public class GeneratedMessageTest {
TestOneof2.Builder builder = TestOneof2.newBuilder();
TestOneof2 message =
builder
.setFooMessage(TestOneof2.NestedMessage.newBuilder().setQuxInt(234).build())
.setFooMessage(TestOneof2.NestedMessage.newBuilder().setMooInt(234).build())
.build();
ByteString serialized = message.toByteString();
TestOneof2 message2 = TestOneof2.parseFrom(serialized);
assertThat(message2.hasFooMessage()).isTrue();
assertThat(message2.getFooMessage().getQuxInt()).isEqualTo(234);
assertThat(message2.getFooMessage().getMooInt()).isEqualTo(234);
}
}

View File

@ -2537,7 +2537,7 @@ public final class TestUtil {
// ===================================================================
// oneof
public static void setOneof(TestOneof2.Builder message) {
message.setFooLazyMessage(TestOneof2.NestedMessage.newBuilder().setQuxInt(100).build());
message.setFooLazyMessage(TestOneof2.NestedMessage.newBuilder().setMooInt(100).build());
message.setBarString("101");
message.setBazInt(102);
message.setBazString("103");
@ -2545,13 +2545,13 @@ public final class TestUtil {
public static void assertOneofSet(TestOneof2 message) {
Assert.assertTrue(message.hasFooLazyMessage());
Assert.assertTrue(message.getFooLazyMessage().hasQuxInt());
Assert.assertTrue(message.getFooLazyMessage().hasMooInt());
Assert.assertTrue(message.hasBarString());
Assert.assertTrue(message.hasBazInt());
Assert.assertTrue(message.hasBazString());
Assert.assertEquals(100, message.getFooLazyMessage().getQuxInt());
Assert.assertEquals(100, message.getFooLazyMessage().getMooInt());
Assert.assertEquals("101", message.getBarString());
Assert.assertEquals(102, message.getBazInt());
Assert.assertEquals("103", message.getBazString());

View File

@ -142,7 +142,7 @@ final class FieldMaskTree {
* <li>If all children of a node have been removed, the node itself will be removed as well.
* That is, if "foo" only has one child "bar" and "foo.bar" only has one child "baz",
* removing "foo.bar.barz" would remove both "foo" and "foo.bar". If "foo" has both "bar"
* and "qux" as children, removing "foo.bar" would leave the path "foo.qux" intact.
* and "moo" as children, removing "foo.bar" would leave the path "foo.moo" intact.
* <li>If the field path to remove is a non-exist sub-path, nothing will be changed.
* </ul>
*/

View File

@ -1718,7 +1718,8 @@ public class JsonFormat {
FieldDescriptor field, JsonElement json, Message.Builder builder)
throws InvalidProtocolBufferException {
if (!(json instanceof JsonArray)) {
throw new InvalidProtocolBufferException("Expect an array but found: " + json);
throw new InvalidProtocolBufferException(
"Expected an array for " + field.getName() + " but found " + json);
}
JsonArray array = (JsonArray) json;
for (int i = 0; i < array.size(); ++i) {

View File

@ -820,6 +820,23 @@ public class JsonFormatTest {
assertThat(map.getInt32ToEnumMapMap()).isEmpty();
}
@Test
// https://github.com/protocolbuffers/protobuf/issues/7456
public void testArrayTypeMismatch() throws IOException {
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
try {
mergeFromJson(
"{\n"
+ " \"repeated_int32\": 5\n"
+ "}",
builder);
assertWithMessage("should have thrown exception for incorrect type").fail();
} catch (InvalidProtocolBufferException expected) {
assertThat(expected).hasMessageThat()
.isEqualTo("Expected an array for repeated_int32 but found 5");
}
}
@Test
public void testParserAcceptNonQuotedObjectKey() throws Exception {
TestMap.Builder builder = TestMap.newBuilder();

View File

@ -57,8 +57,8 @@ describe('binaryReaderTest', function() {
it('testInstanceCaches', /** @suppress {visibility} */ function() {
var writer = new jspb.BinaryWriter();
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
writer.writeMessage(1, dummyMessage, goog.nullFunction);
writer.writeMessage(2, dummyMessage, goog.nullFunction);
writer.writeMessage(1, dummyMessage, () => {});
writer.writeMessage(2, dummyMessage, () => {});
var buffer = writer.getResultBuffer();
@ -139,7 +139,7 @@ describe('binaryReaderTest', function() {
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
reader.nextField();
assertThrows(function() {
reader.readMessage(dummyMessage, goog.nullFunction);
reader.readMessage(dummyMessage, () => {});
});
// Reading past the end of the stream should trigger an assertion.
@ -651,7 +651,7 @@ describe('binaryReaderTest', function() {
});
// Add one empty message.
writer.writeMessage(6, dummyMessage, goog.nullFunction);
writer.writeMessage(6, dummyMessage, () => {});
writer.writeInt32(7, 700);

View File

@ -65,7 +65,7 @@ describe('binaryWriterTest', function() {
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
assertFails(function() {
writer.writeMessage(-1, dummyMessage, goog.nullFunction);
writer.writeMessage(-1, dummyMessage, () => {});
});
// Writing invalid field indices should assert.

View File

@ -56,8 +56,8 @@ describe('binaryReaderTest', function() {
it('testInstanceCaches', /** @suppress {visibility} */ function() {
var writer = new jspb.BinaryWriter();
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
writer.writeMessage(1, dummyMessage, goog.nullFunction);
writer.writeMessage(2, dummyMessage, goog.nullFunction);
writer.writeMessage(1, dummyMessage, () => {});
writer.writeMessage(2, dummyMessage, () => {});
var buffer = writer.getResultBuffer();
@ -138,7 +138,7 @@ describe('binaryReaderTest', function() {
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
reader.nextField();
assertThrows(function() {
reader.readMessage(dummyMessage, goog.nullFunction);
reader.readMessage(dummyMessage, () => {});
});
// Reading past the end of the stream should trigger an assertion.
@ -596,7 +596,7 @@ describe('binaryReaderTest', function() {
});
// Add one empty message.
writer.writeMessage(6, dummyMessage, goog.nullFunction);
writer.writeMessage(6, dummyMessage, () => {});
writer.writeInt32(7, 700);

View File

@ -62,7 +62,7 @@ describe('binaryWriterTest', function() {
var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
assertFails(function() {
writer.writeMessage(-1, dummyMessage, goog.nullFunction);
writer.writeMessage(-1, dummyMessage, () => {});
});
// Writing invalid field indices should assert.

View File

@ -56,8 +56,8 @@ describe('binaryReaderTest', function() {
it('testInstanceCaches', /** @suppress {visibility} */ function() {
var writer = new jspb.BinaryWriter();
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
writer.writeMessage(1, dummyMessage, goog.nullFunction);
writer.writeMessage(2, dummyMessage, goog.nullFunction);
writer.writeMessage(1, dummyMessage, () => {});
writer.writeMessage(2, dummyMessage, () => {});
var buffer = writer.getResultBuffer();
@ -138,7 +138,7 @@ describe('binaryReaderTest', function() {
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
reader.nextField();
assertThrows(function() {
reader.readMessage(dummyMessage, goog.nullFunction);
reader.readMessage(dummyMessage, () => {});
});
// Reading past the end of the stream should trigger an assertion.
@ -620,7 +620,7 @@ describe('binaryReaderTest', function() {
});
// Add one empty message.
writer.writeMessage(6, dummyMessage, goog.nullFunction);
writer.writeMessage(6, dummyMessage, () => {});
writer.writeInt32(7, 700);

View File

@ -62,7 +62,7 @@ describe('binaryWriterTest', function() {
var dummyMessage = /** @type {!jspb.BinaryMessage} */ ({});
assertFails(function() {
writer.writeMessage(-1, dummyMessage, goog.nullFunction);
writer.writeMessage(-1, dummyMessage, () => {});
});
// Writing invalid field indices should assert.

View File

@ -72,12 +72,12 @@ class Location extends \Google\Protobuf\Internal\Message
* optional string baz = 3;
* // Comment attached to baz.
* // Another line attached to baz.
* // Comment attached to qux.
* // Comment attached to moo.
* //
* // Another line attached to qux.
* optional double qux = 4;
* // Another line attached to moo.
* optional double moo = 4;
* // Detached comment for corge. This is not leading or trailing comments
* // to qux or corge because there are blank lines separating it from
* // to moo or corge because there are blank lines separating it from
* // both.
* // Detached comment for corge paragraph 2.
* optional string corge = 5;
@ -156,12 +156,12 @@ class Location extends \Google\Protobuf\Internal\Message
* optional string baz = 3;
* // Comment attached to baz.
* // Another line attached to baz.
* // Comment attached to qux.
* // Comment attached to moo.
* //
* // Another line attached to qux.
* optional double qux = 4;
* // Another line attached to moo.
* optional double moo = 4;
* // Detached comment for corge. This is not leading or trailing comments
* // to qux or corge because there are blank lines separating it from
* // to moo or corge because there are blank lines separating it from
* // both.
* // Detached comment for corge paragraph 2.
* optional string corge = 5;
@ -302,12 +302,12 @@ class Location extends \Google\Protobuf\Internal\Message
* optional string baz = 3;
* // Comment attached to baz.
* // Another line attached to baz.
* // Comment attached to qux.
* // Comment attached to moo.
* //
* // Another line attached to qux.
* optional double qux = 4;
* // Another line attached to moo.
* optional double moo = 4;
* // Detached comment for corge. This is not leading or trailing comments
* // to qux or corge because there are blank lines separating it from
* // to moo or corge because there are blank lines separating it from
* // both.
* // Detached comment for corge paragraph 2.
* optional string corge = 5;
@ -358,12 +358,12 @@ class Location extends \Google\Protobuf\Internal\Message
* optional string baz = 3;
* // Comment attached to baz.
* // Another line attached to baz.
* // Comment attached to qux.
* // Comment attached to moo.
* //
* // Another line attached to qux.
* optional double qux = 4;
* // Another line attached to moo.
* optional double moo = 4;
* // Detached comment for corge. This is not leading or trailing comments
* // to qux or corge because there are blank lines separating it from
* // to moo or corge because there are blank lines separating it from
* // both.
* // Detached comment for corge paragraph 2.
* optional string corge = 5;

View File

@ -14,8 +14,8 @@ use Google\Protobuf\Internal\GPBUtil;
* The name of the uninterpreted option. Each string represents a segment in
* a dot-separated name. is_extension is true iff a segment represents an
* extension (denoted with parentheses in options specs in .proto files).
* E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
* "foo.(bar.baz).qux".
* E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents
* "foo.(bar.baz).moo".
*
* Generated from protobuf message <code>google.protobuf.UninterpretedOption.NamePart</code>
*/

View File

@ -328,10 +328,10 @@ class DescriptorTest(unittest.TestCase):
unittest_custom_options_pb2.complex_opt1].foo)
self.assertEqual(324, options.Extensions[
unittest_custom_options_pb2.complex_opt1].Extensions[
unittest_custom_options_pb2.quux])
unittest_custom_options_pb2.mooo])
self.assertEqual(876, options.Extensions[
unittest_custom_options_pb2.complex_opt1].Extensions[
unittest_custom_options_pb2.corge].qux)
unittest_custom_options_pb2.corge].moo)
self.assertEqual(987, options.Extensions[
unittest_custom_options_pb2.complex_opt2].baz)
self.assertEqual(654, options.Extensions[
@ -341,28 +341,28 @@ class DescriptorTest(unittest.TestCase):
unittest_custom_options_pb2.complex_opt2].bar.foo)
self.assertEqual(1999, options.Extensions[
unittest_custom_options_pb2.complex_opt2].bar.Extensions[
unittest_custom_options_pb2.quux])
unittest_custom_options_pb2.mooo])
self.assertEqual(2008, options.Extensions[
unittest_custom_options_pb2.complex_opt2].bar.Extensions[
unittest_custom_options_pb2.corge].qux)
unittest_custom_options_pb2.corge].moo)
self.assertEqual(741, options.Extensions[
unittest_custom_options_pb2.complex_opt2].Extensions[
unittest_custom_options_pb2.garply].foo)
self.assertEqual(1998, options.Extensions[
unittest_custom_options_pb2.complex_opt2].Extensions[
unittest_custom_options_pb2.garply].Extensions[
unittest_custom_options_pb2.quux])
unittest_custom_options_pb2.mooo])
self.assertEqual(2121, options.Extensions[
unittest_custom_options_pb2.complex_opt2].Extensions[
unittest_custom_options_pb2.garply].Extensions[
unittest_custom_options_pb2.corge].qux)
unittest_custom_options_pb2.corge].moo)
self.assertEqual(1971, options.Extensions[
unittest_custom_options_pb2.ComplexOptionType2
.ComplexOptionType4.complex_opt4].waldo)
self.assertEqual(321, options.Extensions[
unittest_custom_options_pb2.complex_opt2].fred.waldo)
self.assertEqual(9, options.Extensions[
unittest_custom_options_pb2.complex_opt3].qux)
unittest_custom_options_pb2.complex_opt3].moo)
self.assertEqual(22, options.Extensions[
unittest_custom_options_pb2.complex_opt3].complexoptiontype5.plugh)
self.assertEqual(24, options.Extensions[

View File

@ -174,48 +174,42 @@ class MessageFactoryTest(unittest.TestCase):
factory = message_factory.MessageFactory(pool=pool)
# Add Container message.
f = descriptor_pb2.FileDescriptorProto()
f.name = 'google/protobuf/internal/container.proto'
f.package = 'google.protobuf.python.internal'
msg = f.message_type.add()
msg.name = 'Container'
rng = msg.extension_range.add()
rng.start = 1
rng.end = 10
f = descriptor_pb2.FileDescriptorProto(
name='google/protobuf/internal/container.proto',
package='google.protobuf.python.internal')
f.message_type.add(name='Container').extension_range.add(start=1, end=10)
pool.Add(f)
msgs = factory.GetMessages([f.name])
self.assertIn('google.protobuf.python.internal.Container', msgs)
# Extend container.
f = descriptor_pb2.FileDescriptorProto()
f.name = 'google/protobuf/internal/extension.proto'
f.package = 'google.protobuf.python.internal'
f.dependency.append('google/protobuf/internal/container.proto')
msg = f.message_type.add()
msg.name = 'Extension'
ext = msg.extension.add()
ext.name = 'extension_field'
ext.number = 2
ext.label = descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL
ext.type_name = 'Extension'
ext.extendee = 'Container'
f = descriptor_pb2.FileDescriptorProto(
name='google/protobuf/internal/extension.proto',
package='google.protobuf.python.internal',
dependency=['google/protobuf/internal/container.proto'])
msg = f.message_type.add(name='Extension')
msg.extension.add(
name='extension_field',
number=2,
label=descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL,
type_name='Extension',
extendee='Container')
pool.Add(f)
msgs = factory.GetMessages([f.name])
self.assertIn('google.protobuf.python.internal.Extension', msgs)
# Add Duplicate extending the same field number.
f = descriptor_pb2.FileDescriptorProto()
f.name = 'google/protobuf/internal/duplicate.proto'
f.package = 'google.protobuf.python.internal'
f.dependency.append('google/protobuf/internal/container.proto')
msg = f.message_type.add()
msg.name = 'Duplicate'
ext = msg.extension.add()
ext.name = 'extension_field'
ext.number = 2
ext.label = descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL
ext.type_name = 'Duplicate'
ext.extendee = 'Container'
f = descriptor_pb2.FileDescriptorProto(
name='google/protobuf/internal/duplicate.proto',
package='google.protobuf.python.internal',
dependency=['google/protobuf/internal/container.proto'])
msg = f.message_type.add(name='Duplicate')
msg.extension.add(
name='extension_field',
number=2,
label=descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL,
type_name='Duplicate',
extendee='Container')
pool.Add(f)
with self.assertRaises(Exception) as cm:
@ -230,6 +224,76 @@ class MessageFactoryTest(unittest.TestCase):
' with field number 2.',
'Double registration of Extensions'])
def testExtensionValueInDifferentFile(self):
# Add Container message.
f1 = descriptor_pb2.FileDescriptorProto(
name='google/protobuf/internal/container.proto',
package='google.protobuf.python.internal')
f1.message_type.add(name='Container').extension_range.add(start=1, end=10)
# Add ValueType message.
f2 = descriptor_pb2.FileDescriptorProto(
name='google/protobuf/internal/value_type.proto',
package='google.protobuf.python.internal')
f2.message_type.add(name='ValueType').field.add(
name='setting',
number=1,
label=descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL,
type=descriptor_pb2.FieldDescriptorProto.TYPE_INT32,
default_value='123')
# Extend container with field of ValueType.
f3 = descriptor_pb2.FileDescriptorProto(
name='google/protobuf/internal/extension.proto',
package='google.protobuf.python.internal',
dependency=[f1.name, f2.name])
f3.extension.add(
name='top_level_extension_field',
number=2,
label=descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL,
type_name='ValueType',
extendee='Container')
f3.message_type.add(name='Extension').extension.add(
name='nested_extension_field',
number=3,
label=descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL,
type_name='ValueType',
extendee='Container')
class SimpleDescriptorDB:
def __init__(self, files):
self._files = files
def FindFileByName(self, name):
return self._files[name]
db = SimpleDescriptorDB({f1.name: f1, f2.name: f2, f3.name: f3})
pool = descriptor_pool.DescriptorPool(db)
factory = message_factory.MessageFactory(pool=pool)
msgs = factory.GetMessages([f1.name, f3.name]) # Deliberately not f2.
msg = msgs['google.protobuf.python.internal.Container']
desc = msgs['google.protobuf.python.internal.Extension'].DESCRIPTOR
ext1 = desc.file.extensions_by_name['top_level_extension_field']
ext2 = desc.extensions_by_name['nested_extension_field']
m = msg()
m.Extensions[ext1].setting = 234
m.Extensions[ext2].setting = 345
serialized = m.SerializeToString()
pool = descriptor_pool.DescriptorPool(db)
factory = message_factory.MessageFactory(pool=pool)
msgs = factory.GetMessages([f1.name, f3.name]) # Deliberately not f2.
msg = msgs['google.protobuf.python.internal.Container']
desc = msgs['google.protobuf.python.internal.Extension'].DESCRIPTOR
ext1 = desc.file.extensions_by_name['top_level_extension_field']
ext2 = desc.extensions_by_name['nested_extension_field']
m = msg.FromString(serialized)
self.assertEqual(2, len(m.ListFields()))
self.assertEqual(234, m.Extensions[ext1].setting)
self.assertEqual(345, m.Extensions[ext2].setting)
if __name__ == '__main__':
unittest.main()

View File

@ -1479,7 +1479,7 @@ class _Listener(object):
In order to support semantics like:
foo.bar.baz.qux = 23
foo.bar.baz.moo = 23
assert foo.HasField('bar')
...child objects must have back references to their parents.

View File

@ -1933,17 +1933,17 @@ class Proto2ReflectionTest(unittest.TestCase):
def testDisconnectingInOneof(self):
m = unittest_pb2.TestOneof2() # This message has two messages in a oneof.
m.foo_message.qux_int = 5
m.foo_message.moo_int = 5
sub_message = m.foo_message
# Accessing another message's field does not clear the first one
self.assertEqual(m.foo_lazy_message.qux_int, 0)
self.assertEqual(m.foo_message.qux_int, 5)
self.assertEqual(m.foo_lazy_message.moo_int, 0)
self.assertEqual(m.foo_message.moo_int, 5)
# But mutating another message in the oneof detaches the first one.
m.foo_lazy_message.qux_int = 6
self.assertEqual(m.foo_message.qux_int, 0)
m.foo_lazy_message.moo_int = 6
self.assertEqual(m.foo_message.moo_int, 0)
# The reference we got above was detached and is still valid.
self.assertEqual(sub_message.qux_int, 5)
sub_message.qux_int = 7
self.assertEqual(sub_message.moo_int, 5)
sub_message.moo_int = 7
def assertInitialized(self, proto):
self.assertTrue(proto.IsInitialized())

View File

@ -657,9 +657,9 @@ class FieldMaskTest(unittest.TestCase):
# Test Merge oneof field.
new_msg = unittest_pb2.TestOneof2()
dst = unittest_pb2.TestOneof2()
dst.foo_message.qux_int = 1
dst.foo_message.moo_int = 1
mask = field_mask_pb2.FieldMask()
mask.FromJsonString('fooMessage,fooLazyMessage.quxInt')
mask.FromJsonString('fooMessage,fooLazyMessage.mooInt')
mask.MergeMessage(new_msg, dst)
self.assertTrue(dst.HasField('foo_message'))
self.assertFalse(dst.HasField('foo_lazy_message'))

View File

@ -118,6 +118,8 @@ class MessageFactory(object):
self.GetPrototype(extension.containing_type)
extended_class = self._classes[extension.containing_type]
extended_class.RegisterExtension(extension)
if extension.message_type:
self.GetPrototype(extension.message_type)
return result_class
def GetMessages(self, files):
@ -154,6 +156,8 @@ class MessageFactory(object):
self.GetPrototype(extension.containing_type)
extended_class = self._classes[extension.containing_type]
extended_class.RegisterExtension(extension)
if extension.message_type:
self.GetPrototype(extension.message_type)
return result

View File

@ -331,7 +331,7 @@ static PyObject* RichCompare(ExtensionDict* self, PyObject* other, int opid) {
}
bool equals = false;
if (PyObject_TypeCheck(other, &ExtensionDict_Type)) {
equals = self->parent == reinterpret_cast<ExtensionDict*>(other)->parent;;
equals = self->parent == reinterpret_cast<ExtensionDict*>(other)->parent;
}
if (equals ^ (opid == Py_EQ)) {
Py_RETURN_FALSE;

View File

@ -264,7 +264,7 @@ static bool PythonToMapValueRef(MapContainer* self, PyObject* obj,
case FieldDescriptor::CPPTYPE_BOOL: {
GOOGLE_CHECK_GET_BOOL(obj, value, false);
value_ref->SetBoolValue(value);
return true;;
return true;
}
case FieldDescriptor::CPPTYPE_STRING: {
std::string str;

View File

@ -133,6 +133,8 @@ static void Dealloc(PyObject* pself) {
PyUnknownFieldSet* self = reinterpret_cast<PyUnknownFieldSet*>(pself);
if (self->parent == nullptr) {
delete self->fields;
} else {
Py_CLEAR(self->parent);
}
auto* py_type = Py_TYPE(pself);
self->~PyUnknownFieldSet();

View File

@ -744,6 +744,7 @@ protobuf_test_SOURCES = \
google/protobuf/compiler/annotation_test_util.h \
google/protobuf/compiler/command_line_interface_unittest.cc \
google/protobuf/compiler/cpp/bootstrap_unittest.cc \
google/protobuf/compiler/cpp/message_size_unittest.cc \
google/protobuf/compiler/cpp/metadata_test.cc \
google/protobuf/compiler/cpp/move_unittest.cc \
google/protobuf/compiler/cpp/plugin_unittest.cc \

View File

@ -296,7 +296,7 @@ size_t Any::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Any::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Any::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Any::GetClassData() const { return &_class_data_; }

View File

@ -533,7 +533,7 @@ size_t Api::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Api::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Api::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Api::GetClassData() const { return &_class_data_; }
@ -957,7 +957,7 @@ size_t Method::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Method::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Method::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Method::GetClassData() const { return &_class_data_; }
@ -1237,7 +1237,7 @@ size_t Mixin::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Mixin::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Mixin::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Mixin::GetClassData() const { return &_class_data_; }

View File

@ -41,7 +41,6 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/unittest_arena.pb.h>
#include <gmock/gmock.h>
@ -55,6 +54,7 @@
#include <google/protobuf/message.h>
#include <google/protobuf/message_lite.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/unknown_field_set.h>
#include <google/protobuf/wire_format_lite.h>

View File

@ -189,9 +189,9 @@ typedef GeneratorContext OutputDirectory;
// Several code generators treat the parameter argument as holding a
// list of options separated by commas. This helper function parses
// a set of comma-delimited name/value pairs: e.g.,
// "foo=bar,baz,qux=corge"
// "foo=bar,baz,moo=corge"
// parses to the pairs:
// ("foo", "bar"), ("baz", ""), ("qux", "corge")
// ("foo", "bar"), ("baz", ""), ("moo", "corge")
PROTOC_EXPORT void ParseGeneratorParameter(
const std::string&, std::vector<std::pair<std::string, std::string> >*);

View File

@ -50,24 +50,27 @@
#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/file.h>
#include <google/protobuf/any.pb.h>
#include <google/protobuf/compiler/mock_code_generator.h>
#include <google/protobuf/compiler/subprocess.h>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/command_line_interface.h>
#include <google/protobuf/test_util2.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/unittest_custom_options.pb.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/command_line_interface.h>
#include <google/protobuf/compiler/mock_code_generator.h>
#include <google/protobuf/compiler/subprocess.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/io_win32.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
// Must be included last.
#include <google/protobuf/port_def.inc>
namespace google {
namespace protobuf {
namespace compiler {
@ -2777,6 +2780,8 @@ INSTANTIATE_TEST_SUITE_P(FileDescriptorSetSource, EncodeDecodeTest,
#endif // !GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN
#include <google/protobuf/port_undef.inc>
} // namespace compiler
} // namespace protobuf
} // namespace google

View File

@ -46,7 +46,6 @@
#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/file.h>
#include <google/protobuf/compiler/cpp/helpers.h>
#include <google/protobuf/compiler/cpp/generator.h>
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/test_util2.h>
@ -56,6 +55,7 @@
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/compiler/cpp/helpers.h>
#include <google/protobuf/stubs/map_util.h>
#include <google/protobuf/stubs/stl_util.h>

View File

@ -1529,7 +1529,8 @@ FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor* file,
inline bool IsMessageOwnedArenaEligible(const Descriptor* desc,
const Options& options) {
return GetOptimizeFor(desc->file(), options) != FileOptions::LITE_RUNTIME &&
AllocExpected(desc) && !options.bootstrap;
!options.bootstrap && !options.opensource_runtime &&
AllocExpected(desc);
}
bool EnableMessageOwnedArena(const Descriptor* desc, const Options& options) {
@ -1543,6 +1544,14 @@ bool EnableMessageOwnedArenaTrial(const Descriptor* desc,
return false;
}
bool HasMessageFieldOrExtension(const Descriptor* desc) {
if (desc->extension_range_count() > 0) return true;
for (const auto* f : FieldRange(desc)) {
if (f->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) return true;
}
return false;
}
} // namespace cpp
} // namespace compiler
} // namespace protobuf

View File

@ -128,11 +128,11 @@ std::string QualifiedClassName(const EnumDescriptor* d);
// Returns the non-nested type name for the given type. If "qualified" is
// true, prefix the type with the full namespace. For example, if you had:
// package foo.bar;
// message Baz { message Qux {} }
// Then the qualified ClassName for Qux would be:
// ::foo::bar::Baz_Qux
// message Baz { message Moo {} }
// Then the qualified ClassName for Moo would be:
// ::foo::bar::Baz_Moo
// While the non-qualified version would be:
// Baz_Qux
// Baz_Moo
inline std::string ClassName(const Descriptor* descriptor, bool qualified) {
return qualified ? QualifiedClassName(descriptor, Options())
: ClassName(descriptor);
@ -735,6 +735,18 @@ inline std::string SimpleBaseClass(const Descriptor* desc,
return "";
}
// Returns true if this message has a _tracker_ field.
inline bool HasTracker(const Descriptor* desc, const Options& options) {
return options.field_listener_options.inject_field_listener_events &&
desc->file()->options().optimize_for() !=
google::protobuf::FileOptions::LITE_RUNTIME;
}
// Returns true if this message needs an Impl_ struct for it's data.
inline bool HasImplData(const Descriptor* desc, const Options& options) {
return !HasSimpleBaseClass(desc, options);
}
// Formatter is a functor class which acts as a closure around printer and
// the variable map. It's much like printer->Print except it supports both named
// variables that are substituted using a key value map and direct arguments. In
@ -1024,6 +1036,8 @@ bool ShouldVerifySimple(const Descriptor* descriptor);
bool IsUtf8String(const FieldDescriptor* field);
bool HasMessageFieldOrExtension(const Descriptor* desc);
} // namespace cpp
} // namespace compiler
} // namespace protobuf

View File

@ -547,9 +547,7 @@ void GenerateExtensionAnnotations(
for (const auto& annotation : accessor_annotations_to_hooks) {
(*variables)[annotation.first] = "";
}
if (!options.field_listener_options.inject_field_listener_events ||
descriptor->file()->options().optimize_for() ==
google::protobuf::FileOptions::LITE_RUNTIME) {
if (!HasTracker(descriptor, options)) {
return;
}
StringPiece tracker = (*variables)["tracker"];
@ -630,9 +628,7 @@ MessageGenerator::MessageGenerator(
variables_["annotate_bytesize"] = "";
variables_["annotate_mergefrom"] = "";
if (options.field_listener_options.inject_field_listener_events &&
descriptor->file()->options().optimize_for() !=
google::protobuf::FileOptions::LITE_RUNTIME) {
if (HasTracker(descriptor_, options_)) {
const std::string injector_template =
StrCat(" ", variables_["tracker"], ".");
@ -1865,9 +1861,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"\n");
}
if (options_.field_listener_options.inject_field_listener_events &&
descriptor_->file()->options().optimize_for() !=
google::protobuf::FileOptions::LITE_RUNTIME) {
if (HasTracker(descriptor_, options_)) {
format("static ::$proto_ns$::AccessListener<$1$> _tracker_;\n",
ClassName(descriptor_));
}
@ -1950,9 +1944,12 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
}
format.Outdent();
format(
"};\n"
"union { Impl_ _impl_; };\n");
format("};\n");
// Only create the _impl_ field if it contains data.
if (HasImplData(descriptor_, options_)) {
format("union { Impl_ _impl_; };\n");
}
// The TableStruct struct needs access to the private parts, in order to
// construct the offsets of all members.
@ -2185,9 +2182,7 @@ void MessageGenerator::GenerateClassMethods(io::Printer* printer) {
"\n");
}
if (options_.field_listener_options.inject_field_listener_events &&
descriptor_->file()->options().optimize_for() !=
google::protobuf::FileOptions::LITE_RUNTIME) {
if (HasTracker(descriptor_, options_)) {
format(
"::$proto_ns$::AccessListener<$classtype$> "
"$1$::$tracker$(&FullMessageName);\n",
@ -2496,7 +2491,7 @@ void MessageGenerator::GenerateArenaDestructorCode(io::Printer* printer) {
void MessageGenerator::GenerateConstexprConstructor(io::Printer* printer) {
Formatter format(printer, variables_);
if (IsMapEntryMessage(descriptor_)) {
if (IsMapEntryMessage(descriptor_) || !HasImplData(descriptor_, options_)) {
format(
"PROTOBUF_CONSTEXPR $classname$::$classname$(\n"
" ::_pbi::ConstantInitialized) {}\n");
@ -2648,65 +2643,69 @@ void MessageGenerator::GenerateStructors(io::Printer* printer) {
" : $superclass$() {\n");
format.Indent();
const char* field_sep = " ";
const auto put_sep = [&] {
format("\n$1$ ", field_sep);
field_sep = ",";
};
if (HasImplData(descriptor_, options_)) {
const char* field_sep = " ";
const auto put_sep = [&] {
format("\n$1$ ", field_sep);
field_sep = ",";
};
format("new (&_impl_) Impl_{");
format.Indent();
format("new (&_impl_) Impl_{");
format.Indent();
if (descriptor_->extension_range_count() > 0) {
put_sep();
format("/*decltype($extensions$)*/{}");
}
if (!inlined_string_indices_.empty()) {
// Do not copy inlined_string_donated_, because this is not an arena
// constructor.
put_sep();
format("decltype($inlined_string_donated_array$){}");
}
bool need_to_emit_cached_size =
!HasSimpleBaseClass(descriptor_, options_);
if (!has_bit_indices_.empty()) {
put_sep();
format("decltype($has_bits$){from.$has_bits$}");
if (need_to_emit_cached_size) {
put_sep();
format("/*decltype($cached_size$)*/{}");
need_to_emit_cached_size = false;
}
}
// Initialize member variables with arena constructor.
for (auto field : optimized_order_) {
put_sep();
field_generators_.get(field).GenerateCopyAggregateInitializer(printer);
}
for (auto oneof : OneOfRange(descriptor_)) {
put_sep();
format("decltype(_impl_.$1$_){}", oneof->name());
}
if (descriptor_->extension_range_count() > 0) {
put_sep();
format("/*decltype($extensions$)*/{}");
}
if (!inlined_string_indices_.empty()) {
// Do not copy inlined_string_donated_, because this is not an arena
// constructor.
put_sep();
format("decltype($inlined_string_donated_array$){}");
}
bool need_to_emit_cached_size = !HasSimpleBaseClass(descriptor_, options_);
if (!has_bit_indices_.empty()) {
put_sep();
format("decltype($has_bits$){from.$has_bits$}");
if (need_to_emit_cached_size) {
put_sep();
format("/*decltype($cached_size$)*/{}");
need_to_emit_cached_size = false;
}
}
// Initialize member variables with arena constructor.
for (auto field : optimized_order_) {
put_sep();
field_generators_.get(field).GenerateCopyAggregateInitializer(printer);
if (descriptor_->real_oneof_decl_count() != 0) {
put_sep();
format("/*decltype($oneof_case$)*/{}");
}
if (num_weak_fields_ > 0) {
put_sep();
format("decltype($weak_field_map$){from.$weak_field_map$}");
}
if (IsAnyMessage(descriptor_, options_)) {
put_sep();
format(
"/*decltype($any_metadata$)*/{&_impl_.type_url_, &_impl_.value_}");
}
format.Outdent();
format("};\n\n");
}
for (auto oneof : OneOfRange(descriptor_)) {
put_sep();
format("decltype(_impl_.$1$_){}", oneof->name());
}
if (need_to_emit_cached_size) {
put_sep();
format("/*decltype($cached_size$)*/{}");
}
if (descriptor_->real_oneof_decl_count() != 0) {
put_sep();
format("/*decltype($oneof_case$)*/{}");
}
if (num_weak_fields_ > 0) {
put_sep();
format("decltype($weak_field_map$){from.$weak_field_map$}");
}
if (IsAnyMessage(descriptor_, options_)) {
put_sep();
format("/*decltype($any_metadata$)*/{&_impl_.type_url_, &_impl_.value_}");
}
format.Outdent();
format("};\n\n");
format(
"_internal_metadata_.MergeFrom<$unknown_fields_type$>(from._internal_"
@ -3145,7 +3144,7 @@ void MessageGenerator::GenerateMergeFrom(io::Printer* printer) {
format(
"const ::$proto_ns$::Message::ClassData "
"$classname$::_class_data_ = {\n"
" ::$proto_ns$::Message::CopyWithSizeCheck,\n"
" ::$proto_ns$::Message::CopyWithSourceCheck,\n"
" $classname$::MergeImpl\n"
"};\n"
"const ::$proto_ns$::Message::ClassData*"
@ -3359,12 +3358,12 @@ void MessageGenerator::GenerateCopyFrom(io::Printer* printer) {
// takes in the Message base class as a parameter); instead we just
// let the base Message::CopyFrom take care of it. The base MergeFrom
// knows how to quickly confirm the types exactly match, and if so, will
// use GetClassData() to get the address of Message::CopyWithSizeCheck,
// use GetClassData() to get the address of Message::CopyWithSourceCheck,
// which calls Clear() and then MergeFrom(), as well as making sure that
// clearing the destination message doesn't alter the size of the source,
// when in debug builds.
// Most callers avoid this by passing a "from" message that is the same
// type as the message being merged into, rather than a generic Message.
// clearing the destination message doesn't alter the source, when in debug
// builds. Most callers avoid this by passing a "from" message that is the
// same type as the message being merged into, rather than a generic
// Message.
}
// Generate the class-specific CopyFrom.
@ -3376,20 +3375,33 @@ void MessageGenerator::GenerateCopyFrom(io::Printer* printer) {
format("if (&from == this) return;\n");
if (!options_.opensource_runtime) {
if (!options_.opensource_runtime && HasMessageFieldOrExtension(descriptor_)) {
// This check is disabled in the opensource release because we're
// concerned that many users do not define NDEBUG in their release builds.
// It is also disabled if a message has neither message fields nor
// extensions, as it's impossible to copy from its descendant.
//
// Note that FailIfCopyFromDescendant is implemented by reflection and not
// available for lite runtime. In that case, check if the size of the source
// has changed after Clear.
format("#ifndef NDEBUG\n");
if (HasDescriptorMethods(descriptor_->file(), options_)) {
format("FailIfCopyFromDescendant(this, from);\n");
} else {
format("size_t from_size = from.ByteSizeLong();\n");
}
format(
"#ifndef NDEBUG\n"
"size_t from_size = from.ByteSizeLong();\n"
"#endif\n"
"Clear();\n"
"#ifndef NDEBUG\n"
"$CHK$_EQ(from_size, from.ByteSizeLong())\n"
" << \"Source of CopyFrom changed when clearing target. Either \"\n"
" \"source is a nested message in target (not allowed), or \"\n"
" \"another thread is modifying the source.\";\n"
"#endif\n");
"Clear();\n");
if (!HasDescriptorMethods(descriptor_->file(), options_)) {
format(
"#ifndef NDEBUG\n"
"$CHK$_EQ(from_size, from.ByteSizeLong())\n"
" << \"Source of CopyFrom changed when clearing target. Either \"\n"
" \"source is a nested message in target (not allowed), or \"\n"
" \"another thread is modifying the source.\";\n"
"#endif\n");
}
} else {
format("Clear();\n");
}

View File

@ -0,0 +1,272 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/descriptor.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace google {
namespace protobuf {
namespace compiler {
namespace cpp {
// Can't use an anonymous namespace here due to brokenness of Tru64 compiler.
namespace cpp_unittest {
#if !defined(GOOGLE_CHECK_MESSAGE_SIZE)
#define GOOGLE_CHECK_MESSAGE_SIZE(t, expected)
#endif
// Mock structures to lock down the size of messages in a platform-independent
// way. The commented sizes only apply when build with clang x86_64.
struct MockMessageBase {
virtual ~MockMessageBase() = default; // 8 bytes vtable
void* internal_metadata; // 8 bytes
};
GOOGLE_CHECK_MESSAGE_SIZE(MockMessageBase, 16);
struct MockZeroFieldsBase : public MockMessageBase {
int cached_size; // 4 bytes
// + 4 bytes padding
};
GOOGLE_CHECK_MESSAGE_SIZE(MockZeroFieldsBase, 24);
struct MockExtensionSet {
void* arena; // 8 bytes
int16_t capacity; // 4 bytes
int16_t size; // 4 bytes
void* data; // 8 bytes
};
GOOGLE_CHECK_MESSAGE_SIZE(MockExtensionSet, 24);
struct MockRepeatedPtrField {
void* arena; // 8 bytes
int current_size; // 4 bytes
int total_size; // 4 bytes
void* data; // 8 bytes
};
GOOGLE_CHECK_MESSAGE_SIZE(MockRepeatedPtrField, 24);
struct MockRepeatedField {
int current_size; // 4 bytes
int total_size; // 4 bytes
void* data; // 8 bytes
};
GOOGLE_CHECK_MESSAGE_SIZE(MockRepeatedField, 16);
TEST(GeneratedMessageTest, MockSizes) {
// Consistency checks -- if these fail, the tests below will definitely fail.
GOOGLE_CHECK_EQ(sizeof(MessageLite), sizeof(MockMessageBase));
GOOGLE_CHECK_EQ(sizeof(Message), sizeof(MockMessageBase));
GOOGLE_CHECK_EQ(sizeof(internal::ZeroFieldsBase), sizeof(MockZeroFieldsBase));
GOOGLE_CHECK_EQ(sizeof(internal::ExtensionSet), sizeof(MockExtensionSet));
GOOGLE_CHECK_EQ(sizeof(RepeatedPtrField<std::string>), sizeof(MockRepeatedPtrField));
GOOGLE_CHECK_EQ(sizeof(RepeatedField<int>), sizeof(MockRepeatedField));
}
TEST(GeneratedMessageTest, EmptyMessageSize) {
EXPECT_EQ(sizeof(protobuf_unittest::TestEmptyMessage),
sizeof(MockZeroFieldsBase));
}
TEST(GeneratedMessageTest, ReservedSize) {
EXPECT_EQ(sizeof(protobuf_unittest::TestReservedFields),
sizeof(MockZeroFieldsBase));
}
TEST(GeneratedMessageTest, EmptyMessageWithExtensionsSize) {
struct MockGenerated : public MockMessageBase { // 16 bytes
MockExtensionSet extensions; // 24 bytes
int cached_size; // 4 bytes
// + 4 bytes of padding
};
GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 48);
EXPECT_EQ(sizeof(protobuf_unittest::TestEmptyMessageWithExtensions),
sizeof(MockGenerated));
}
TEST(GeneratedMessageTest, RecursiveMessageSize) {
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
void* a; // 8 bytes
int32_t i; // 4 bytes
// + 4 bytes padding
};
GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 40);
EXPECT_EQ(sizeof(protobuf_unittest::TestRecursiveMessage),
sizeof(MockGenerated));
}
TEST(GeneratedMessageTest, OneStringSize) {
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
void* data; // 8 bytes
};
GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 32);
EXPECT_EQ(sizeof(protobuf_unittest::OneString), sizeof(MockGenerated));
}
TEST(GeneratedMessageTest, MoreStringSize) {
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
MockRepeatedPtrField data; // 24 bytes
};
GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 48);
EXPECT_EQ(sizeof(protobuf_unittest::MoreString), sizeof(MockGenerated));
}
TEST(GeneratedMessageTest, Int32MessageSize) {
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
int32_t data; // 4 bytes
// + 4 bytes padding
};
GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 32);
EXPECT_EQ(sizeof(protobuf_unittest::Int32Message), sizeof(MockGenerated));
}
TEST(GeneratedMessageTest, Int64MessageSize) {
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
int64_t data; // 8 bytes
};
GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 32);
EXPECT_EQ(sizeof(protobuf_unittest::Int64Message), sizeof(MockGenerated));
}
TEST(GeneratedMessageTest, BoolMessageSize) {
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
bool data; // 1 byte
// + 3 bytes padding
};
GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 32);
EXPECT_EQ(sizeof(protobuf_unittest::BoolMessage), sizeof(MockGenerated));
}
TEST(GeneratedMessageTest, OneofSize) {
struct MockGenerated : public MockMessageBase { // 16 bytes
void* foo; // 8 bytes
int cached_size; // 4 bytes
uint32_t oneof_case[1]; // 4 bytes
};
GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 32);
EXPECT_EQ(sizeof(protobuf_unittest::TestOneof), sizeof(MockGenerated));
}
TEST(GeneratedMessageTest, Oneof2Size) {
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
void* baz_string; // 8 bytes
int32_t baz_int; // 4 bytes
// + 4 bytes padding
void* foo; // 8 bytes
void* bar; // 8 bytes
uint32_t oneof_case[2]; // 8 bytes
};
GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 64);
EXPECT_EQ(sizeof(protobuf_unittest::TestOneof2), sizeof(MockGenerated));
}
TEST(GeneratedMessageTest, FieldOrderingsSize) {
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
MockExtensionSet extensions; // 24 bytes
void* my_string; // 8 bytes
void* optional_nested_message; // 8 bytes
int64_t my_int; // 8 bytes
float my_float; // 4 bytes
// + 4 bytes of padding
};
GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 80);
EXPECT_EQ(sizeof(protobuf_unittest::TestFieldOrderings), sizeof(MockGenerated));
}
TEST(GeneratedMessageTest, TestMessageSize) {
// We expect the message to contain (not in this order):
struct MockGenerated : public MockMessageBase { // 16 bytes
int has_bits[1]; // 4 bytes
int cached_size; // 4 bytes
void* m4; // 8 bytes
int64_t m2; // 8 bytes
bool m1; // 1 bytes
bool m3; // 1 bytes
// + 2 bytes padding
int m5; // 4 bytes
int64_t m6; // 8 bytes
};
GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 56);
EXPECT_EQ(sizeof(protobuf_unittest::TestMessageSize), sizeof(MockGenerated));
}
TEST(GeneratedMessageTest, PackedTypesSize) {
struct MockGenerated : public MockMessageBase { // 16 bytes
MockRepeatedField packed_int32; // 16 bytes
int packed_int32_cached_byte_size; // 4 bytes + 4 bytes padding
MockRepeatedField packed_int64; // 16 bytes
int packed_int64_cached_byte_size; // 4 bytes + 4 bytes padding
MockRepeatedField packed_uint32; // 16 bytes
int packed_uint32_cached_byte_size; // 4 bytes + 4 bytes padding
MockRepeatedField packed_uint64; // 16 bytes
int packed_uint64_cached_byte_size; // 4 bytes + 4 bytes padding
MockRepeatedField packed_sint32; // 16 bytes
int packed_sint32_cached_byte_size; // 4 bytes + 4 bytes padding
MockRepeatedField packed_sint64; // 16 bytes
int packed_sint64_cached_byte_size; // 4 bytes + 4 bytes padding
MockRepeatedField packed_fixed32; // 16 bytes
MockRepeatedField packed_fixed64; // 16 bytes
MockRepeatedField packed_sfixed32; // 16 bytes
MockRepeatedField packed_sfixed64; // 16 bytes
MockRepeatedField packed_float; // 16 bytes
MockRepeatedField packed_double; // 16 bytes
MockRepeatedField packed_bool; // 16 bytes
MockRepeatedField packed_enum; // 16 bytes
int packed_enum_cached_byte_size; // 4 bytes
int cached_size; // 4 bytes
};
GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 16 * 15 + 8 * 6 + 8);
EXPECT_EQ(sizeof(protobuf_unittest::TestPackedTypes), sizeof(MockGenerated));
}
} // namespace cpp_unittest
} // namespace cpp
} // namespace compiler
} // namespace protobuf
} // namespace google

View File

@ -32,13 +32,13 @@
#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/file.h>
#include <google/protobuf/compiler/cpp/helpers.h>
#include <google/protobuf/compiler/cpp/generator.h>
#include <google/protobuf/compiler/annotation_test_util.h>
#include <google/protobuf/compiler/command_line_interface.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/compiler/annotation_test_util.h>
#include <google/protobuf/compiler/cpp/helpers.h>
namespace google {
namespace protobuf {

View File

@ -51,9 +51,9 @@ namespace cpp {
//
// For example, if you had:
// package foo.bar;
// message Baz { message Qux {} }
// message Baz { message Moo {} }
// Then the non-qualified version would be:
// Baz_Qux
// Baz_Moo
std::string ClassName(const Descriptor* descriptor);
std::string ClassName(const EnumDescriptor* enum_descriptor);
@ -61,9 +61,9 @@ std::string ClassName(const EnumDescriptor* enum_descriptor);
//
// For example, if you had:
// package foo.bar;
// message Baz { message Qux {} }
// Then the qualified ClassName for Qux would be:
// ::foo::bar::Baz_Qux
// message Baz { message Moo {} }
// Then the qualified ClassName for Moo would be:
// ::foo::bar::Baz_Moo
std::string QualifiedClassName(const Descriptor* d);
std::string QualifiedClassName(const EnumDescriptor* d);
std::string QualifiedExtensionName(const FieldDescriptor* d);

View File

@ -79,7 +79,7 @@ struct Options {
bool opensource_runtime = false;
bool annotate_accessor = false;
bool unused_field_stripping = false;
bool unverified_lazy_message_sets = true;
bool unverified_lazy_message_sets = false;
bool eagerly_verified_lazy = true;
bool profile_driven_inline_string = true;
bool message_owned_arena_trial = false;

View File

@ -198,7 +198,7 @@ TEST(CppPluginTest, PluginTest) {
" ctype = CORD\n"
" ];\n"
"\n"
" oneof Qux {\n"
" oneof Moo {\n"
" int64 oneOfInt = 20;\n"
" string oneOfString = 21;\n"
" Baz oneOfMessage = 22;\n"

View File

@ -49,7 +49,6 @@
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/unittest_embed_optimize_for.pb.h>
#include <google/protobuf/unittest_optimize_for.pb.h>
#include <google/protobuf/test_util.h>
#define MESSAGE_TEST_NAME MessageTest

View File

@ -58,16 +58,16 @@
#endif
#include <google/protobuf/compiler/cpp/helpers.h>
#include <google/protobuf/compiler/cpp/test_bad_identifiers.pb.h>
#include <google/protobuf/compiler/scc.h>
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/test_util2.h>
#include <google/protobuf/unittest_no_generic_services.pb.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/compiler/scc.h>
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/test_util2.h>
#include <google/protobuf/stubs/callback.h>
#include <google/protobuf/stubs/common.h>
@ -393,6 +393,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, StringCharStarLength) {
}
#if !defined(PROTOBUF_TEST_NO_DESCRIPTORS) || defined(NDEBUG)
TEST(GENERATED_MESSAGE_TEST_NAME, CopyFrom) {
UNITTEST::TestAllTypes message1, message2;
@ -405,6 +406,20 @@ TEST(GENERATED_MESSAGE_TEST_NAME, CopyFrom) {
TestUtil::ExpectAllFieldsSet(message2);
}
TEST(GENERATED_MESSAGE_TEST_NAME, CopyAssignmentOperator) {
UNITTEST::TestAllTypes message1;
TestUtil::SetAllFields(&message1);
UNITTEST::TestAllTypes message2;
message2 = message1;
TestUtil::ExpectAllFieldsSet(message2);
// Make sure that self-assignment does something sane.
message2.operator=(message2);
TestUtil::ExpectAllFieldsSet(message2);
}
#endif // !PROTOBUF_TEST_NO_DESCRIPTORS || NDEBUG
TEST(GENERATED_MESSAGE_TEST_NAME, SwapWithEmpty) {
UNITTEST::TestAllTypes message1, message2;
@ -579,20 +594,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, CopyConstructorWithArenas) {
TestUtil::ExpectAllFieldsSet(*message2_heap);
}
TEST(GENERATED_MESSAGE_TEST_NAME, CopyAssignmentOperator) {
UNITTEST::TestAllTypes message1;
TestUtil::SetAllFields(&message1);
UNITTEST::TestAllTypes message2;
message2 = message1;
TestUtil::ExpectAllFieldsSet(message2);
// Make sure that self-assignment does something sane.
message2.operator=(message2);
TestUtil::ExpectAllFieldsSet(message2);
}
#if !defined(PROTOBUF_TEST_NO_DESCRIPTORS) || PROTOBUF_RTTI
#ifndef PROTOBUF_TEST_NO_DESCRIPTORS
TEST(GENERATED_MESSAGE_TEST_NAME, UpcastCopyFrom) {
// Test the CopyFrom method that takes in the generic const Message&
// parameter.
@ -605,9 +607,6 @@ TEST(GENERATED_MESSAGE_TEST_NAME, UpcastCopyFrom) {
TestUtil::ExpectAllFieldsSet(message2);
}
#endif
#ifndef PROTOBUF_TEST_NO_DESCRIPTORS
TEST(GENERATED_MESSAGE_TEST_NAME, DynamicMessageCopyFrom) {
// Test copying from a DynamicMessage, which must fall back to using
@ -824,7 +823,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, CamelCaseFieldNames) {
message.mutable_messagefield()->set_c(6);
message.add_repeatedprimitivefield(8);
message.add_repeatedstringfield("qux");
message.add_repeatedstringfield("moo");
message.add_repeatedenumfield(UNITTEST::FOREIGN_BAR);
message.add_repeatedmessagefield()->set_c(15);
@ -834,7 +833,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, CamelCaseFieldNames) {
EXPECT_EQ(6, message.messagefield().c());
EXPECT_EQ(8, message.repeatedprimitivefield(0));
EXPECT_EQ("qux", message.repeatedstringfield(0));
EXPECT_EQ("moo", message.repeatedstringfield(0));
EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.repeatedenumfield(0));
EXPECT_EQ(15, message.repeatedmessagefield(0).c());
}
@ -949,7 +948,6 @@ TEST(GENERATED_MESSAGE_TEST_NAME, TestOneofSpaceUsed) {
#endif // !PROTOBUF_TEST_NO_DESCRIPTORS
TEST(GENERATED_MESSAGE_TEST_NAME, FieldConstantValues) {
UNITTEST::TestRequired message;
EXPECT_EQ(UNITTEST::TestAllTypes_NestedMessage::kBbFieldNumber, 1);
@ -1474,7 +1472,7 @@ TEST_F(OneofTest, SettingOneFieldClearsOthers) {
TestUtil::ExpectAtMostOneFieldSetInOneof(message);
message.set_foo_bytes("qux");
message.set_foo_bytes("moo");
EXPECT_TRUE(message.has_foo_bytes());
TestUtil::ExpectAtMostOneFieldSetInOneof(message);
@ -1482,7 +1480,7 @@ TEST_F(OneofTest, SettingOneFieldClearsOthers) {
EXPECT_TRUE(message.has_foo_enum());
TestUtil::ExpectAtMostOneFieldSetInOneof(message);
message.mutable_foo_message()->set_qux_int(234);
message.mutable_foo_message()->set_moo_int(234);
EXPECT_TRUE(message.has_foo_message());
TestUtil::ExpectAtMostOneFieldSetInOneof(message);
@ -1505,11 +1503,11 @@ TEST_F(OneofTest, EnumCases) {
ExpectEnumCasesWork(message);
message.set_foo_string("foo");
ExpectEnumCasesWork(message);
message.set_foo_bytes("qux");
message.set_foo_bytes("moo");
ExpectEnumCasesWork(message);
message.set_foo_enum(UNITTEST::TestOneof2::FOO);
ExpectEnumCasesWork(message);
message.mutable_foo_message()->set_qux_int(234);
message.mutable_foo_message()->set_moo_int(234);
ExpectEnumCasesWork(message);
message.mutable_foogroup()->set_a(345);
ExpectEnumCasesWork(message);
@ -1559,15 +1557,15 @@ TEST_F(OneofTest, SetString) {
EXPECT_FALSE(message.has_foo_string());
message.set_foo_string("qux", 3);
message.set_foo_string("moo", 3);
EXPECT_TRUE(message.has_foo_string());
EXPECT_EQ(message.foo_string(), "qux");
EXPECT_EQ(message.foo_string(), "moo");
message.clear_foo_string();
EXPECT_FALSE(message.has_foo_string());
message.mutable_foo_string()->assign("quux");
message.mutable_foo_string()->assign("mooo");
EXPECT_TRUE(message.has_foo_string());
EXPECT_EQ(message.foo_string(), "quux");
EXPECT_EQ(message.foo_string(), "mooo");
message.clear_foo_string();
EXPECT_FALSE(message.has_foo_string());
@ -1643,11 +1641,11 @@ TEST_F(OneofTest, SetMessage) {
// Unset field returns default instance
EXPECT_EQ(&message.foo_message(),
&UNITTEST::TestOneof2_NestedMessage::default_instance());
EXPECT_EQ(message.foo_message().qux_int(), 0);
EXPECT_EQ(message.foo_message().moo_int(), 0);
message.mutable_foo_message()->set_qux_int(234);
message.mutable_foo_message()->set_moo_int(234);
EXPECT_TRUE(message.has_foo_message());
EXPECT_EQ(message.foo_message().qux_int(), 234);
EXPECT_EQ(message.foo_message().moo_int(), 234);
message.clear_foo_message();
EXPECT_FALSE(message.has_foo_message());
}
@ -1660,13 +1658,13 @@ TEST_F(OneofTest, ReleaseMessage) {
EXPECT_EQ(nullptr, message.release_foo_message());
EXPECT_FALSE(message.has_foo_message());
message.mutable_foo_message()->set_qux_int(1);
message.mutable_foo_message()->set_moo_int(1);
EXPECT_TRUE(message.has_foo_message());
std::unique_ptr<UNITTEST::TestOneof2_NestedMessage> mes(
message.release_foo_message());
EXPECT_FALSE(message.has_foo_message());
ASSERT_TRUE(mes != nullptr);
EXPECT_EQ(1, mes->qux_int());
EXPECT_EQ(1, mes->moo_int());
EXPECT_EQ(nullptr, message.release_foo_message());
EXPECT_FALSE(message.has_foo_message());
@ -1678,7 +1676,7 @@ TEST_F(OneofTest, SetAllocatedMessage) {
EXPECT_FALSE(message.has_foo_message());
message.mutable_foo_message()->set_qux_int(1);
message.mutable_foo_message()->set_moo_int(1);
EXPECT_TRUE(message.has_foo_message());
message.set_allocated_foo_message(nullptr);
@ -1686,14 +1684,14 @@ TEST_F(OneofTest, SetAllocatedMessage) {
EXPECT_EQ(&message.foo_message(),
&UNITTEST::TestOneof2_NestedMessage::default_instance());
message.mutable_foo_message()->set_qux_int(1);
message.mutable_foo_message()->set_moo_int(1);
UNITTEST::TestOneof2_NestedMessage* mes = message.release_foo_message();
ASSERT_TRUE(mes != nullptr);
EXPECT_FALSE(message.has_foo_message());
message.set_allocated_foo_message(mes);
EXPECT_TRUE(message.has_foo_message());
EXPECT_EQ(1, message.foo_message().qux_int());
EXPECT_EQ(1, message.foo_message().moo_int());
}
@ -1723,7 +1721,7 @@ TEST_F(OneofTest, Defaults) {
EXPECT_EQ(message.foo_enum(), 1);
EXPECT_FALSE(message.has_foo_message());
EXPECT_EQ(message.foo_message().qux_int(), 0);
EXPECT_EQ(message.foo_message().moo_int(), 0);
EXPECT_FALSE(message.has_foogroup());
EXPECT_EQ(message.foogroup().a(), 0);
@ -1767,14 +1765,14 @@ TEST_F(OneofTest, SwapBothHasFields) {
message1.set_foo_string("FOO");
EXPECT_TRUE(message1.has_foo_string());
message2.mutable_foo_message()->set_qux_int(1);
message2.mutable_foo_message()->set_moo_int(1);
EXPECT_TRUE(message2.has_foo_message());
message1.Swap(&message2);
EXPECT_FALSE(message1.has_foo_string());
EXPECT_FALSE(message2.has_foo_message());
EXPECT_TRUE(message1.has_foo_message());
EXPECT_EQ(message1.foo_message().qux_int(), 1);
EXPECT_EQ(message1.foo_message().moo_int(), 1);
EXPECT_TRUE(message2.has_foo_string());
EXPECT_EQ(message2.foo_string(), "FOO");
}
@ -1805,16 +1803,16 @@ TEST_F(OneofTest, CopyFrom) {
TEST_F(OneofTest, CopyAssignmentOperator) {
UNITTEST::TestOneof2 message1;
message1.mutable_foo_message()->set_qux_int(123);
message1.mutable_foo_message()->set_moo_int(123);
EXPECT_TRUE(message1.has_foo_message());
UNITTEST::TestOneof2 message2;
message2 = message1;
EXPECT_EQ(message2.foo_message().qux_int(), 123);
EXPECT_EQ(message2.foo_message().moo_int(), 123);
// Make sure that self-assignment does something sane.
message2 = *&message2; // Avoid -Wself-assign.
EXPECT_EQ(message2.foo_message().qux_int(), 123);
EXPECT_EQ(message2.foo_message().moo_int(), 123);
}
TEST_F(OneofTest, UpcastCopyFrom) {
@ -1869,14 +1867,14 @@ EXPECT_EQ(message2.foo_int(), 123);
{
UNITTEST::TestOneof2 message1, message2;
std::string data;
message1.set_foo_bytes("qux");
message1.set_foo_bytes("moo");
int size = message1.ByteSizeLong();
data.resize(size);
uint8_t* start = reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&data));
uint8_t* end = message1.SerializeWithCachedSizesToArray(start);
EXPECT_EQ(size, end - start);
EXPECT_TRUE(message2.ParseFromString(data));
EXPECT_EQ(message2.foo_bytes(), "qux");
EXPECT_EQ(message2.foo_bytes(), "moo");
}
// Enum
@ -1897,14 +1895,14 @@ EXPECT_EQ(message2.foo_int(), 123);
{
UNITTEST::TestOneof2 message1, message2;
std::string data;
message1.mutable_foo_message()->set_qux_int(234);
message1.mutable_foo_message()->set_moo_int(234);
int size = message1.ByteSizeLong();
data.resize(size);
uint8_t* start = reinterpret_cast<uint8_t*>(::google::protobuf::string_as_array(&data));
uint8_t* end = message1.SerializeWithCachedSizesToArray(start);
EXPECT_EQ(size, end - start);
EXPECT_TRUE(message2.ParseFromString(data));
EXPECT_EQ(message2.foo_message().qux_int(), 234);
EXPECT_EQ(message2.foo_message().moo_int(), 234);
}
// Group
@ -1976,7 +1974,7 @@ data.resize(size);
{
UNITTEST::TestOneof2 message1, message2;
std::string data;
message1.set_foo_bytes("qux");
message1.set_foo_bytes("moo");
int size = message1.ByteSizeLong();
data.resize(size);
@ -1990,7 +1988,7 @@ data.resize(size);
}
EXPECT_TRUE(message2.ParseFromString(data));
EXPECT_EQ(message2.foo_bytes(), "qux");
EXPECT_EQ(message2.foo_bytes(), "moo");
}
// Enum
@ -2018,7 +2016,7 @@ data.resize(size);
{
UNITTEST::TestOneof2 message1, message2;
std::string data;
message1.mutable_foo_message()->set_qux_int(234);
message1.mutable_foo_message()->set_moo_int(234);
int size = message1.ByteSizeLong();
data.resize(size);
@ -2032,7 +2030,7 @@ data.resize(size);
}
EXPECT_TRUE(message2.ParseFromString(data));
EXPECT_EQ(message2.foo_message().qux_int(), 234);
EXPECT_EQ(message2.foo_message().moo_int(), 234);
}
// Group
@ -2074,11 +2072,11 @@ TEST_F(OneofTest, MergeFrom) {
EXPECT_EQ(message2.foo_string(), "foo");
message1.set_foo_bytes("qux");
message1.set_foo_bytes("moo");
message2.MergeFrom(message1);
TestUtil::ExpectAtMostOneFieldSetInOneof(message2);
EXPECT_TRUE(message2.has_foo_bytes());
EXPECT_EQ(message2.foo_bytes(), "qux");
EXPECT_EQ(message2.foo_bytes(), "moo");
message1.set_foo_enum(UNITTEST::TestOneof2::FOO);
message2.MergeFrom(message1);
@ -2086,11 +2084,11 @@ TEST_F(OneofTest, MergeFrom) {
EXPECT_TRUE(message2.has_foo_enum());
EXPECT_EQ(message2.foo_enum(), UNITTEST::TestOneof2::FOO);
message1.mutable_foo_message()->set_qux_int(234);
message1.mutable_foo_message()->set_moo_int(234);
message2.MergeFrom(message1);
TestUtil::ExpectAtMostOneFieldSetInOneof(message2);
EXPECT_TRUE(message2.has_foo_message());
EXPECT_EQ(message2.foo_message().qux_int(), 234);
EXPECT_EQ(message2.foo_message().moo_int(), 234);
message1.mutable_foogroup()->set_a(345);
message2.MergeFrom(message1);

View File

@ -47,13 +47,13 @@
#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/file.h>
#include <google/protobuf/compiler/plugin.pb.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/text_format.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/text_format.h>
#ifdef major
#undef major

View File

@ -64,32 +64,33 @@ namespace {
typedef std::unordered_map<std::string, FieldDescriptorProto::Type> TypeNameMap;
TypeNameMap MakeTypeNameTable() {
TypeNameMap result;
const TypeNameMap& GetTypeNameTable() {
static auto* table = new auto([]() {
TypeNameMap result;
result["double"] = FieldDescriptorProto::TYPE_DOUBLE;
result["float"] = FieldDescriptorProto::TYPE_FLOAT;
result["uint64"] = FieldDescriptorProto::TYPE_UINT64;
result["fixed64"] = FieldDescriptorProto::TYPE_FIXED64;
result["fixed32"] = FieldDescriptorProto::TYPE_FIXED32;
result["bool"] = FieldDescriptorProto::TYPE_BOOL;
result["string"] = FieldDescriptorProto::TYPE_STRING;
result["group"] = FieldDescriptorProto::TYPE_GROUP;
result["double"] = FieldDescriptorProto::TYPE_DOUBLE;
result["float"] = FieldDescriptorProto::TYPE_FLOAT;
result["uint64"] = FieldDescriptorProto::TYPE_UINT64;
result["fixed64"] = FieldDescriptorProto::TYPE_FIXED64;
result["fixed32"] = FieldDescriptorProto::TYPE_FIXED32;
result["bool"] = FieldDescriptorProto::TYPE_BOOL;
result["string"] = FieldDescriptorProto::TYPE_STRING;
result["group"] = FieldDescriptorProto::TYPE_GROUP;
result["bytes"] = FieldDescriptorProto::TYPE_BYTES;
result["uint32"] = FieldDescriptorProto::TYPE_UINT32;
result["sfixed32"] = FieldDescriptorProto::TYPE_SFIXED32;
result["sfixed64"] = FieldDescriptorProto::TYPE_SFIXED64;
result["int32"] = FieldDescriptorProto::TYPE_INT32;
result["int64"] = FieldDescriptorProto::TYPE_INT64;
result["sint32"] = FieldDescriptorProto::TYPE_SINT32;
result["sint64"] = FieldDescriptorProto::TYPE_SINT64;
result["bytes"] = FieldDescriptorProto::TYPE_BYTES;
result["uint32"] = FieldDescriptorProto::TYPE_UINT32;
result["sfixed32"] = FieldDescriptorProto::TYPE_SFIXED32;
result["sfixed64"] = FieldDescriptorProto::TYPE_SFIXED64;
result["int32"] = FieldDescriptorProto::TYPE_INT32;
result["int64"] = FieldDescriptorProto::TYPE_INT64;
result["sint32"] = FieldDescriptorProto::TYPE_SINT32;
result["sint64"] = FieldDescriptorProto::TYPE_SINT64;
return result;
return result;
}());
return *table;
}
const TypeNameMap kTypeNames = MakeTypeNameTable();
// Camel-case the field name and append "Entry" for generated map entry name.
// e.g. map<KeyType, ValueType> foo_map => FooMapEntry
std::string MapEntryName(const std::string& field_name) {
@ -2270,8 +2271,9 @@ bool Parser::ParseLabel(FieldDescriptorProto::Label* label,
bool Parser::ParseType(FieldDescriptorProto::Type* type,
std::string* type_name) {
TypeNameMap::const_iterator iter = kTypeNames.find(input_->current().text);
if (iter != kTypeNames.end()) {
const auto& type_names_table = GetTypeNameTable();
auto iter = type_names_table.find(input_->current().text);
if (iter != type_names_table.end()) {
*type = iter->second;
input_->Next();
} else {
@ -2283,8 +2285,9 @@ bool Parser::ParseType(FieldDescriptorProto::Type* type,
bool Parser::ParseUserDefinedType(std::string* type_name) {
type_name->clear();
TypeNameMap::const_iterator iter = kTypeNames.find(input_->current().text);
if (iter != kTypeNames.end()) {
const auto& type_names_table = GetTypeNameTable();
auto iter = type_names_table.find(input_->current().text);
if (iter != type_names_table.end()) {
// Note: The only place enum types are allowed is for field types, but
// if we are parsing a field type then we would not get here because
// primitives are allowed there as well. So this error message doesn't

View File

@ -484,7 +484,7 @@ class PROTOBUF_EXPORT Parser {
// Parses a single part of a multipart option name. A multipart name consists
// of names separated by dots. Each name is either an identifier or a series
// of identifiers separated by dots and enclosed in parentheses. E.g.,
// "foo.(bar.baz).qux".
// "foo.(bar.baz).moo".
bool ParseOptionNamePart(UninterpretedOption* uninterpreted_option,
const LocationRecorder& part_location,
const FileDescriptorProto* containing_file);

View File

@ -484,7 +484,7 @@ size_t Version::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Version::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Version::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Version::GetClassData() const { return &_class_data_; }
@ -844,7 +844,7 @@ size_t CodeGeneratorRequest::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData CodeGeneratorRequest::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
CodeGeneratorRequest::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*CodeGeneratorRequest::GetClassData() const { return &_class_data_; }
@ -1228,7 +1228,7 @@ size_t CodeGeneratorResponse_File::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData CodeGeneratorResponse_File::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
CodeGeneratorResponse_File::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*CodeGeneratorResponse_File::GetClassData() const { return &_class_data_; }
@ -1533,7 +1533,7 @@ size_t CodeGeneratorResponse::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData CodeGeneratorResponse::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
CodeGeneratorResponse::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*CodeGeneratorResponse::GetClassData() const { return &_class_data_; }

View File

@ -555,7 +555,7 @@ void PyiGenerator::PrintMessage(
void PyiGenerator::PrintMessages(
const std::map<std::string, std::string>& import_map) const {
// Order the descriptors by name to have same output with proto_to_pyi.py
// Deterministically order the descriptors.
std::vector<const Descriptor*> messages;
messages.reserve(file_->message_type_count());
for (int i = 0; i < file_->message_type_count(); ++i) {
@ -593,9 +593,6 @@ bool PyiGenerator::Generate(const FileDescriptor* file,
MutexLock lock(&mutex_);
// Calculate file name.
file_ = file;
// proto_to_pyi.py may set the output file name directly. To replace
// proto_to_pyi.py in google3, protoc also accept --pyi_out to set
// the output file name.
std::string filename =
parameter.empty() ? GetFileName(file, ".pyi") : parameter;

View File

@ -34,7 +34,9 @@
// command_line_interface_unittest.
#include <stdlib.h>
#include <string>
#include <google/protobuf/compiler/mock_code_generator.h>
#include <google/protobuf/compiler/plugin.h>

View File

@ -1101,8 +1101,9 @@ typedef HASH_MAP<std::string, const SourceCodeInfo_Location*>
std::set<std::string>* NewAllowedProto3Extendee() {
auto allowed_proto3_extendees = new std::set<std::string>;
const char* kOptionNames[] = {
"FileOptions", "MessageOptions", "FieldOptions", "EnumOptions",
"EnumValueOptions", "ServiceOptions", "MethodOptions", "OneofOptions"};
"FileOptions", "MessageOptions", "FieldOptions",
"EnumOptions", "EnumValueOptions", "ServiceOptions",
"MethodOptions", "OneofOptions", "ExtensionRangeOptions"};
for (const char* option_name : kOptionNames) {
// descriptor.proto has a different package name in opensource. We allow
// both so the opensource protocol compiler can also compile internal
@ -3772,9 +3773,9 @@ class DescriptorBuilder {
// Like FindSymbol(), but looks up the name relative to some other symbol
// name. This first searches siblings of relative_to, then siblings of its
// parents, etc. For example, LookupSymbol("foo.bar", "baz.qux.corge") makes
// parents, etc. For example, LookupSymbol("foo.bar", "baz.moo.corge") makes
// the following calls, returning the first non-null result:
// FindSymbol("baz.qux.foo.bar"), FindSymbol("baz.foo.bar"),
// FindSymbol("baz.moo.foo.bar"), FindSymbol("baz.foo.bar"),
// FindSymbol("foo.bar"). If AllowUnknownDependencies() has been called
// on the DescriptorPool, this will generate a placeholder type if
// the name is not found (unless the name itself is malformed). The

View File

@ -1463,7 +1463,7 @@ size_t FileDescriptorSet::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData FileDescriptorSet::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
FileDescriptorSet::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FileDescriptorSet::GetClassData() const { return &_class_data_; }
@ -2101,7 +2101,7 @@ size_t FileDescriptorProto::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData FileDescriptorProto::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
FileDescriptorProto::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FileDescriptorProto::GetClassData() const { return &_class_data_; }
@ -2428,7 +2428,7 @@ size_t DescriptorProto_ExtensionRange::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData DescriptorProto_ExtensionRange::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
DescriptorProto_ExtensionRange::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*DescriptorProto_ExtensionRange::GetClassData() const { return &_class_data_; }
@ -2674,7 +2674,7 @@ size_t DescriptorProto_ReservedRange::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData DescriptorProto_ReservedRange::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
DescriptorProto_ReservedRange::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*DescriptorProto_ReservedRange::GetClassData() const { return &_class_data_; }
@ -3211,7 +3211,7 @@ size_t DescriptorProto::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData DescriptorProto::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
DescriptorProto::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*DescriptorProto::GetClassData() const { return &_class_data_; }
@ -3461,7 +3461,7 @@ size_t ExtensionRangeOptions::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ExtensionRangeOptions::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
ExtensionRangeOptions::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ExtensionRangeOptions::GetClassData() const { return &_class_data_; }
@ -4080,7 +4080,7 @@ size_t FieldDescriptorProto::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData FieldDescriptorProto::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
FieldDescriptorProto::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FieldDescriptorProto::GetClassData() const { return &_class_data_; }
@ -4411,7 +4411,7 @@ size_t OneofDescriptorProto::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData OneofDescriptorProto::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
OneofDescriptorProto::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*OneofDescriptorProto::GetClassData() const { return &_class_data_; }
@ -4654,7 +4654,7 @@ size_t EnumDescriptorProto_EnumReservedRange::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData EnumDescriptorProto_EnumReservedRange::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
EnumDescriptorProto_EnumReservedRange::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumDescriptorProto_EnumReservedRange::GetClassData() const { return &_class_data_; }
@ -5031,7 +5031,7 @@ size_t EnumDescriptorProto::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData EnumDescriptorProto::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
EnumDescriptorProto::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumDescriptorProto::GetClassData() const { return &_class_data_; }
@ -5343,7 +5343,7 @@ size_t EnumValueDescriptorProto::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData EnumValueDescriptorProto::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
EnumValueDescriptorProto::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumValueDescriptorProto::GetClassData() const { return &_class_data_; }
@ -5661,7 +5661,7 @@ size_t ServiceDescriptorProto::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ServiceDescriptorProto::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
ServiceDescriptorProto::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ServiceDescriptorProto::GetClassData() const { return &_class_data_; }
@ -6098,7 +6098,7 @@ size_t MethodDescriptorProto::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData MethodDescriptorProto::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
MethodDescriptorProto::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*MethodDescriptorProto::GetClassData() const { return &_class_data_; }
@ -7136,7 +7136,7 @@ size_t FileOptions::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData FileOptions::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
FileOptions::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FileOptions::GetClassData() const { return &_class_data_; }
@ -7584,7 +7584,7 @@ size_t MessageOptions::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData MessageOptions::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
MessageOptions::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*MessageOptions::GetClassData() const { return &_class_data_; }
@ -8025,7 +8025,7 @@ size_t FieldOptions::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData FieldOptions::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
FieldOptions::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FieldOptions::GetClassData() const { return &_class_data_; }
@ -8269,7 +8269,7 @@ size_t OneofOptions::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData OneofOptions::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
OneofOptions::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*OneofOptions::GetClassData() const { return &_class_data_; }
@ -8547,7 +8547,7 @@ size_t EnumOptions::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData EnumOptions::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
EnumOptions::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumOptions::GetClassData() const { return &_class_data_; }
@ -8811,7 +8811,7 @@ size_t EnumValueOptions::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData EnumValueOptions::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
EnumValueOptions::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumValueOptions::GetClassData() const { return &_class_data_; }
@ -9063,7 +9063,7 @@ size_t ServiceOptions::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ServiceOptions::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
ServiceOptions::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ServiceOptions::GetClassData() const { return &_class_data_; }
@ -9355,7 +9355,7 @@ size_t MethodOptions::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData MethodOptions::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
MethodOptions::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*MethodOptions::GetClassData() const { return &_class_data_; }
@ -9642,7 +9642,7 @@ size_t UninterpretedOption_NamePart::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData UninterpretedOption_NamePart::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
UninterpretedOption_NamePart::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*UninterpretedOption_NamePart::GetClassData() const { return &_class_data_; }
@ -10086,7 +10086,7 @@ size_t UninterpretedOption::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData UninterpretedOption::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
UninterpretedOption::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*UninterpretedOption::GetClassData() const { return &_class_data_; }
@ -10519,7 +10519,7 @@ size_t SourceCodeInfo_Location::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData SourceCodeInfo_Location::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
SourceCodeInfo_Location::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*SourceCodeInfo_Location::GetClassData() const { return &_class_data_; }
@ -10731,7 +10731,7 @@ size_t SourceCodeInfo::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData SourceCodeInfo::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
SourceCodeInfo::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*SourceCodeInfo::GetClassData() const { return &_class_data_; }
@ -11046,7 +11046,7 @@ size_t GeneratedCodeInfo_Annotation::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData GeneratedCodeInfo_Annotation::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
GeneratedCodeInfo_Annotation::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GeneratedCodeInfo_Annotation::GetClassData() const { return &_class_data_; }
@ -11260,7 +11260,7 @@ size_t GeneratedCodeInfo::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData GeneratedCodeInfo::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
GeneratedCodeInfo::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GeneratedCodeInfo::GetClassData() const { return &_class_data_; }

View File

@ -740,8 +740,8 @@ message UninterpretedOption {
// The name of the uninterpreted option. Each string represents a segment in
// a dot-separated name. is_extension is true iff a segment represents an
// extension (denoted with parentheses in options specs in .proto files).
// E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
// "foo.(bar.baz).qux".
// E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents
// "foo.(bar.baz).moo".
message NamePart {
required string name_part = 1;
required bool is_extension = 2;
@ -868,13 +868,13 @@ message SourceCodeInfo {
// // Comment attached to baz.
// // Another line attached to baz.
//
// // Comment attached to qux.
// // Comment attached to moo.
// //
// // Another line attached to qux.
// optional double qux = 4;
// // Another line attached to moo.
// optional double moo = 4;
//
// // Detached comment for corge. This is not leading or trailing comments
// // to qux or corge because there are blank lines separating it from
// // to moo or corge because there are blank lines separating it from
// // both.
//
// // Detached comment for corge paragraph 2.

View File

@ -628,7 +628,7 @@ class DescriptorTest : public testing::Test {
// required string foo = 1;
// optional TestEnum bar = 6;
// repeated TestForeign baz = 500000000;
// optional group qux = 15 {}
// optional group moo = 15 {}
// }
//
// // in "bar.proto"
@ -636,7 +636,7 @@ class DescriptorTest : public testing::Test {
// message TestMessage2 {
// required string foo = 1;
// required string bar = 2;
// required string quux = 6;
// required string mooo = 6;
// }
//
// // in "map.proto"
@ -654,7 +654,7 @@ class DescriptorTest : public testing::Test {
// optional int32 field_name6 = 6 [json_name = "@type"];
// }
//
// We cheat and use TestForeign as the type for qux rather than create
// We cheat and use TestForeign as the type for moo rather than create
// an actual nested type.
//
// Since all primitive types (including string) use the same building
@ -678,7 +678,7 @@ class DescriptorTest : public testing::Test {
AddField(message, "baz", 500000000, FieldDescriptorProto::LABEL_REPEATED,
FieldDescriptorProto::TYPE_MESSAGE)
->set_type_name("TestForeign");
AddField(message, "qux", 15, FieldDescriptorProto::LABEL_OPTIONAL,
AddField(message, "moo", 15, FieldDescriptorProto::LABEL_OPTIONAL,
FieldDescriptorProto::TYPE_GROUP)
->set_type_name("TestForeign");
@ -691,7 +691,7 @@ class DescriptorTest : public testing::Test {
FieldDescriptorProto::TYPE_STRING);
AddField(message2, "bar", 2, FieldDescriptorProto::LABEL_REQUIRED,
FieldDescriptorProto::TYPE_STRING);
AddField(message2, "quux", 6, FieldDescriptorProto::LABEL_REQUIRED,
AddField(message2, "mooo", 6, FieldDescriptorProto::LABEL_REQUIRED,
FieldDescriptorProto::TYPE_STRING);
FileDescriptorProto map_file;
@ -754,7 +754,7 @@ class DescriptorTest : public testing::Test {
foo_ = message_->field(0);
bar_ = message_->field(1);
baz_ = message_->field(2);
qux_ = message_->field(3);
moo_ = message_->field(3);
ASSERT_EQ(1, bar_file_->message_type_count());
message2_ = bar_file_->message_type(0);
@ -762,7 +762,7 @@ class DescriptorTest : public testing::Test {
ASSERT_EQ(3, message2_->field_count());
foo2_ = message2_->field(0);
bar2_ = message2_->field(1);
quux2_ = message2_->field(2);
mooo2_ = message2_->field(2);
ASSERT_EQ(1, map_file_->message_type_count());
message3_ = map_file_->message_type(0);
@ -801,11 +801,11 @@ class DescriptorTest : public testing::Test {
const FieldDescriptor* foo_;
const FieldDescriptor* bar_;
const FieldDescriptor* baz_;
const FieldDescriptor* qux_;
const FieldDescriptor* moo_;
const FieldDescriptor* foo2_;
const FieldDescriptor* bar2_;
const FieldDescriptor* quux2_;
const FieldDescriptor* mooo2_;
const FieldDescriptor* map_;
};
@ -886,7 +886,7 @@ TEST_F(DescriptorTest, FieldsByIndex) {
EXPECT_EQ(foo_, message_->field(0));
EXPECT_EQ(bar_, message_->field(1));
EXPECT_EQ(baz_, message_->field(2));
EXPECT_EQ(qux_, message_->field(3));
EXPECT_EQ(moo_, message_->field(3));
}
TEST_F(DescriptorTest, FindFieldByName) {
@ -898,28 +898,28 @@ TEST_F(DescriptorTest, FindFieldByName) {
EXPECT_EQ(foo_, message_->FindFieldByName("foo"));
EXPECT_EQ(bar_, message_->FindFieldByName("bar"));
EXPECT_EQ(baz_, message_->FindFieldByName("baz"));
EXPECT_EQ(qux_, message_->FindFieldByName("qux"));
EXPECT_EQ(moo_, message_->FindFieldByName("moo"));
EXPECT_TRUE(message_->FindFieldByName("no_such_field") == nullptr);
EXPECT_TRUE(message_->FindFieldByName("quux") == nullptr);
EXPECT_TRUE(message_->FindFieldByName("mooo") == nullptr);
EXPECT_EQ(foo2_, message2_->FindFieldByName("foo"));
EXPECT_EQ(bar2_, message2_->FindFieldByName("bar"));
EXPECT_EQ(quux2_, message2_->FindFieldByName("quux"));
EXPECT_EQ(mooo2_, message2_->FindFieldByName("mooo"));
EXPECT_TRUE(message2_->FindFieldByName("baz") == nullptr);
EXPECT_TRUE(message2_->FindFieldByName("qux") == nullptr);
EXPECT_TRUE(message2_->FindFieldByName("moo") == nullptr);
}
TEST_F(DescriptorTest, FindFieldByNumber) {
EXPECT_EQ(foo_, message_->FindFieldByNumber(1));
EXPECT_EQ(bar_, message_->FindFieldByNumber(6));
EXPECT_EQ(baz_, message_->FindFieldByNumber(500000000));
EXPECT_EQ(qux_, message_->FindFieldByNumber(15));
EXPECT_EQ(moo_, message_->FindFieldByNumber(15));
EXPECT_TRUE(message_->FindFieldByNumber(837592) == nullptr);
EXPECT_TRUE(message_->FindFieldByNumber(2) == nullptr);
EXPECT_EQ(foo2_, message2_->FindFieldByNumber(1));
EXPECT_EQ(bar2_, message2_->FindFieldByNumber(2));
EXPECT_EQ(quux2_, message2_->FindFieldByNumber(6));
EXPECT_EQ(mooo2_, message2_->FindFieldByNumber(6));
EXPECT_TRUE(message2_->FindFieldByNumber(15) == nullptr);
EXPECT_TRUE(message2_->FindFieldByNumber(500000000) == nullptr);
}
@ -928,32 +928,32 @@ TEST_F(DescriptorTest, FieldName) {
EXPECT_EQ("foo", foo_->name());
EXPECT_EQ("bar", bar_->name());
EXPECT_EQ("baz", baz_->name());
EXPECT_EQ("qux", qux_->name());
EXPECT_EQ("moo", moo_->name());
}
TEST_F(DescriptorTest, FieldFullName) {
EXPECT_EQ("TestMessage.foo", foo_->full_name());
EXPECT_EQ("TestMessage.bar", bar_->full_name());
EXPECT_EQ("TestMessage.baz", baz_->full_name());
EXPECT_EQ("TestMessage.qux", qux_->full_name());
EXPECT_EQ("TestMessage.moo", moo_->full_name());
EXPECT_EQ("corge.grault.TestMessage2.foo", foo2_->full_name());
EXPECT_EQ("corge.grault.TestMessage2.bar", bar2_->full_name());
EXPECT_EQ("corge.grault.TestMessage2.quux", quux2_->full_name());
EXPECT_EQ("corge.grault.TestMessage2.mooo", mooo2_->full_name());
}
TEST_F(DescriptorTest, PrintableNameIsFullNameForNonExtensionFields) {
EXPECT_EQ("TestMessage.foo", foo_->PrintableNameForExtension());
EXPECT_EQ("TestMessage.bar", bar_->PrintableNameForExtension());
EXPECT_EQ("TestMessage.baz", baz_->PrintableNameForExtension());
EXPECT_EQ("TestMessage.qux", qux_->PrintableNameForExtension());
EXPECT_EQ("TestMessage.moo", moo_->PrintableNameForExtension());
EXPECT_EQ("corge.grault.TestMessage2.foo",
foo2_->PrintableNameForExtension());
EXPECT_EQ("corge.grault.TestMessage2.bar",
bar2_->PrintableNameForExtension());
EXPECT_EQ("corge.grault.TestMessage2.quux",
quux2_->PrintableNameForExtension());
EXPECT_EQ("corge.grault.TestMessage2.mooo",
mooo2_->PrintableNameForExtension());
}
TEST_F(DescriptorTest, PrintableNameIsFullNameForNonMessageSetExtension) {
@ -1016,39 +1016,39 @@ TEST_F(DescriptorTest, FieldFile) {
EXPECT_EQ(foo_file_, foo_->file());
EXPECT_EQ(foo_file_, bar_->file());
EXPECT_EQ(foo_file_, baz_->file());
EXPECT_EQ(foo_file_, qux_->file());
EXPECT_EQ(foo_file_, moo_->file());
EXPECT_EQ(bar_file_, foo2_->file());
EXPECT_EQ(bar_file_, bar2_->file());
EXPECT_EQ(bar_file_, quux2_->file());
EXPECT_EQ(bar_file_, mooo2_->file());
}
TEST_F(DescriptorTest, FieldIndex) {
EXPECT_EQ(0, foo_->index());
EXPECT_EQ(1, bar_->index());
EXPECT_EQ(2, baz_->index());
EXPECT_EQ(3, qux_->index());
EXPECT_EQ(3, moo_->index());
}
TEST_F(DescriptorTest, FieldNumber) {
EXPECT_EQ(1, foo_->number());
EXPECT_EQ(6, bar_->number());
EXPECT_EQ(500000000, baz_->number());
EXPECT_EQ(15, qux_->number());
EXPECT_EQ(15, moo_->number());
}
TEST_F(DescriptorTest, FieldType) {
EXPECT_EQ(FieldDescriptor::TYPE_STRING, foo_->type());
EXPECT_EQ(FieldDescriptor::TYPE_ENUM, bar_->type());
EXPECT_EQ(FieldDescriptor::TYPE_MESSAGE, baz_->type());
EXPECT_EQ(FieldDescriptor::TYPE_GROUP, qux_->type());
EXPECT_EQ(FieldDescriptor::TYPE_GROUP, moo_->type());
}
TEST_F(DescriptorTest, FieldLabel) {
EXPECT_EQ(FieldDescriptor::LABEL_REQUIRED, foo_->label());
EXPECT_EQ(FieldDescriptor::LABEL_OPTIONAL, bar_->label());
EXPECT_EQ(FieldDescriptor::LABEL_REPEATED, baz_->label());
EXPECT_EQ(FieldDescriptor::LABEL_OPTIONAL, qux_->label());
EXPECT_EQ(FieldDescriptor::LABEL_OPTIONAL, moo_->label());
EXPECT_TRUE(foo_->is_required());
EXPECT_FALSE(foo_->is_optional());
@ -1089,18 +1089,18 @@ TEST_F(DescriptorTest, FieldHasDefault) {
EXPECT_FALSE(foo_->has_default_value());
EXPECT_FALSE(bar_->has_default_value());
EXPECT_FALSE(baz_->has_default_value());
EXPECT_FALSE(qux_->has_default_value());
EXPECT_FALSE(moo_->has_default_value());
}
TEST_F(DescriptorTest, FieldContainingType) {
EXPECT_EQ(message_, foo_->containing_type());
EXPECT_EQ(message_, bar_->containing_type());
EXPECT_EQ(message_, baz_->containing_type());
EXPECT_EQ(message_, qux_->containing_type());
EXPECT_EQ(message_, moo_->containing_type());
EXPECT_EQ(message2_, foo2_->containing_type());
EXPECT_EQ(message2_, bar2_->containing_type());
EXPECT_EQ(message2_, quux2_->containing_type());
EXPECT_EQ(message2_, mooo2_->containing_type());
}
TEST_F(DescriptorTest, FieldMessageType) {
@ -1108,13 +1108,13 @@ TEST_F(DescriptorTest, FieldMessageType) {
EXPECT_TRUE(bar_->message_type() == nullptr);
EXPECT_EQ(foreign_, baz_->message_type());
EXPECT_EQ(foreign_, qux_->message_type());
EXPECT_EQ(foreign_, moo_->message_type());
}
TEST_F(DescriptorTest, FieldEnumType) {
EXPECT_TRUE(foo_->enum_type() == nullptr);
EXPECT_TRUE(baz_->enum_type() == nullptr);
EXPECT_TRUE(qux_->enum_type() == nullptr);
EXPECT_TRUE(moo_->enum_type() == nullptr);
EXPECT_EQ(enum_, bar_->enum_type());
}
@ -1708,7 +1708,7 @@ class NestedDescriptorTest : public testing::Test {
// message Foo {}
// message Bar {}
// enum Baz { A = 1; }
// enum Qux { B = 1; }
// enum Moo { B = 1; }
// }
//
// // in "bar.proto"
@ -1716,8 +1716,8 @@ class NestedDescriptorTest : public testing::Test {
// message TestMessage2 {
// message Foo {}
// message Baz {}
// enum Qux { A = 1; }
// enum Quux { C = 1; }
// enum Moo { A = 1; }
// enum Mooo { C = 1; }
// }
//
// TestMessage2 is primarily here to test FindNestedTypeByName and friends.
@ -1735,8 +1735,8 @@ class NestedDescriptorTest : public testing::Test {
AddNestedMessage(message, "Bar");
EnumDescriptorProto* baz = AddNestedEnum(message, "Baz");
AddEnumValue(baz, "A", 1);
EnumDescriptorProto* qux = AddNestedEnum(message, "Qux");
AddEnumValue(qux, "B", 1);
EnumDescriptorProto* moo = AddNestedEnum(message, "Moo");
AddEnumValue(moo, "B", 1);
FileDescriptorProto bar_file;
bar_file.set_name("bar.proto");
@ -1745,10 +1745,10 @@ class NestedDescriptorTest : public testing::Test {
DescriptorProto* message2 = AddMessage(&bar_file, "TestMessage2");
AddNestedMessage(message2, "Foo");
AddNestedMessage(message2, "Baz");
EnumDescriptorProto* qux2 = AddNestedEnum(message2, "Qux");
AddEnumValue(qux2, "A", 1);
EnumDescriptorProto* quux2 = AddNestedEnum(message2, "Quux");
AddEnumValue(quux2, "C", 1);
EnumDescriptorProto* moo2 = AddNestedEnum(message2, "Moo");
AddEnumValue(moo2, "A", 1);
EnumDescriptorProto* mooo2 = AddNestedEnum(message2, "Mooo");
AddEnumValue(mooo2, "C", 1);
// Build the descriptors and get the pointers.
foo_file_ = pool_.BuildFile(foo_file);
@ -1766,12 +1766,12 @@ class NestedDescriptorTest : public testing::Test {
ASSERT_EQ(2, message_->enum_type_count());
baz_ = message_->enum_type(0);
qux_ = message_->enum_type(1);
moo_ = message_->enum_type(1);
ASSERT_EQ(1, baz_->value_count());
a_ = baz_->value(0);
ASSERT_EQ(1, qux_->value_count());
b_ = qux_->value(0);
ASSERT_EQ(1, moo_->value_count());
b_ = moo_->value(0);
ASSERT_EQ(1, bar_file_->message_type_count());
message2_ = bar_file_->message_type(0);
@ -1781,13 +1781,13 @@ class NestedDescriptorTest : public testing::Test {
baz2_ = message2_->nested_type(1);
ASSERT_EQ(2, message2_->enum_type_count());
qux2_ = message2_->enum_type(0);
quux2_ = message2_->enum_type(1);
moo2_ = message2_->enum_type(0);
mooo2_ = message2_->enum_type(1);
ASSERT_EQ(1, qux2_->value_count());
a2_ = qux2_->value(0);
ASSERT_EQ(1, quux2_->value_count());
c2_ = quux2_->value(0);
ASSERT_EQ(1, moo2_->value_count());
a2_ = moo2_->value(0);
ASSERT_EQ(1, mooo2_->value_count());
c2_ = mooo2_->value(0);
}
DescriptorPool pool_;
@ -1801,14 +1801,14 @@ class NestedDescriptorTest : public testing::Test {
const Descriptor* foo_;
const Descriptor* bar_;
const EnumDescriptor* baz_;
const EnumDescriptor* qux_;
const EnumDescriptor* moo_;
const EnumValueDescriptor* a_;
const EnumValueDescriptor* b_;
const Descriptor* foo2_;
const Descriptor* baz2_;
const EnumDescriptor* qux2_;
const EnumDescriptor* quux2_;
const EnumDescriptor* moo2_;
const EnumDescriptor* mooo2_;
const EnumValueDescriptor* a2_;
const EnumValueDescriptor* c2_;
};
@ -1840,9 +1840,9 @@ TEST_F(NestedDescriptorTest, NestedMessagesByIndex) {
TEST_F(NestedDescriptorTest, FindFieldByNameDoesntFindNestedTypes) {
EXPECT_TRUE(message_->FindFieldByName("Foo") == nullptr);
EXPECT_TRUE(message_->FindFieldByName("Qux") == nullptr);
EXPECT_TRUE(message_->FindFieldByName("Moo") == nullptr);
EXPECT_TRUE(message_->FindExtensionByName("Foo") == nullptr);
EXPECT_TRUE(message_->FindExtensionByName("Qux") == nullptr);
EXPECT_TRUE(message_->FindExtensionByName("Moo") == nullptr);
}
TEST_F(NestedDescriptorTest, FindNestedTypeByName) {
@ -1855,26 +1855,26 @@ TEST_F(NestedDescriptorTest, FindNestedTypeByName) {
EXPECT_TRUE(message_->FindNestedTypeByName("Baz") == nullptr);
EXPECT_TRUE(message2_->FindNestedTypeByName("Bar") == nullptr);
EXPECT_TRUE(message_->FindNestedTypeByName("Qux") == nullptr);
EXPECT_TRUE(message_->FindNestedTypeByName("Moo") == nullptr);
}
TEST_F(NestedDescriptorTest, EnumName) {
EXPECT_EQ("Baz", baz_->name());
EXPECT_EQ("Qux", qux_->name());
EXPECT_EQ("Qux", qux2_->name());
EXPECT_EQ("Quux", quux2_->name());
EXPECT_EQ("Moo", moo_->name());
EXPECT_EQ("Moo", moo2_->name());
EXPECT_EQ("Mooo", mooo2_->name());
EXPECT_EQ("TestMessage.Baz", baz_->full_name());
EXPECT_EQ("TestMessage.Qux", qux_->full_name());
EXPECT_EQ("corge.grault.TestMessage2.Qux", qux2_->full_name());
EXPECT_EQ("corge.grault.TestMessage2.Quux", quux2_->full_name());
EXPECT_EQ("TestMessage.Moo", moo_->full_name());
EXPECT_EQ("corge.grault.TestMessage2.Moo", moo2_->full_name());
EXPECT_EQ("corge.grault.TestMessage2.Mooo", mooo2_->full_name());
}
TEST_F(NestedDescriptorTest, EnumContainingType) {
EXPECT_EQ(message_, baz_->containing_type());
EXPECT_EQ(message_, qux_->containing_type());
EXPECT_EQ(message2_, qux2_->containing_type());
EXPECT_EQ(message2_, quux2_->containing_type());
EXPECT_EQ(message_, moo_->containing_type());
EXPECT_EQ(message2_, moo2_->containing_type());
EXPECT_EQ(message2_, mooo2_->containing_type());
}
TEST_F(NestedDescriptorTest, NestedEnumsByIndex) {
@ -1885,12 +1885,12 @@ TEST_F(NestedDescriptorTest, NestedEnumsByIndex) {
TEST_F(NestedDescriptorTest, FindEnumTypeByName) {
EXPECT_EQ(baz_, message_->FindEnumTypeByName("Baz"));
EXPECT_EQ(qux_, message_->FindEnumTypeByName("Qux"));
EXPECT_EQ(qux2_, message2_->FindEnumTypeByName("Qux"));
EXPECT_EQ(quux2_, message2_->FindEnumTypeByName("Quux"));
EXPECT_EQ(moo_, message_->FindEnumTypeByName("Moo"));
EXPECT_EQ(moo2_, message2_->FindEnumTypeByName("Moo"));
EXPECT_EQ(mooo2_, message2_->FindEnumTypeByName("Mooo"));
EXPECT_TRUE(message_->FindEnumTypeByName("NoSuchType") == nullptr);
EXPECT_TRUE(message_->FindEnumTypeByName("Quux") == nullptr);
EXPECT_TRUE(message_->FindEnumTypeByName("Mooo") == nullptr);
EXPECT_TRUE(message2_->FindEnumTypeByName("Baz") == nullptr);
EXPECT_TRUE(message_->FindEnumTypeByName("Foo") == nullptr);
@ -1918,7 +1918,7 @@ class ExtensionDescriptorTest : public testing::Test {
// Build descriptors for the following definitions:
//
// enum Baz {}
// message Qux {}
// message Moo {}
//
// message Foo {
// extensions 10 to 19;
@ -1933,8 +1933,8 @@ class ExtensionDescriptorTest : public testing::Test {
// message Bar {
// optional int32 non_ext_int32 = 1;
// extend Foo {
// optional Qux foo_message = 30;
// repeated Qux foo_group = 39; // (but internally set to TYPE_GROUP)
// optional Moo foo_message = 30;
// repeated Moo foo_group = 39; // (but internally set to TYPE_GROUP)
// }
// }
@ -1942,7 +1942,7 @@ class ExtensionDescriptorTest : public testing::Test {
foo_file.set_name("foo.proto");
AddEmptyEnum(&foo_file, "Baz");
AddMessage(&foo_file, "Qux");
AddMessage(&foo_file, "Moo");
DescriptorProto* foo = AddMessage(&foo_file, "Foo");
AddExtensionRange(foo, 10, 20);
@ -1962,11 +1962,11 @@ class ExtensionDescriptorTest : public testing::Test {
AddNestedExtension(bar, "Foo", "foo_message", 30,
FieldDescriptorProto::LABEL_OPTIONAL,
FieldDescriptorProto::TYPE_MESSAGE)
->set_type_name("Qux");
->set_type_name("Moo");
AddNestedExtension(bar, "Foo", "foo_group", 39,
FieldDescriptorProto::LABEL_REPEATED,
FieldDescriptorProto::TYPE_GROUP)
->set_type_name("Qux");
->set_type_name("Moo");
// Build the descriptors and get the pointers.
foo_file_ = pool_.BuildFile(foo_file);
@ -1976,7 +1976,7 @@ class ExtensionDescriptorTest : public testing::Test {
baz_ = foo_file_->enum_type(0);
ASSERT_EQ(3, foo_file_->message_type_count());
qux_ = foo_file_->message_type(0);
moo_ = foo_file_->message_type(0);
foo_ = foo_file_->message_type(1);
bar_ = foo_file_->message_type(2);
}
@ -1988,7 +1988,7 @@ class ExtensionDescriptorTest : public testing::Test {
const Descriptor* foo_;
const Descriptor* bar_;
const EnumDescriptor* baz_;
const Descriptor* qux_;
const Descriptor* moo_;
};
TEST_F(ExtensionDescriptorTest, ExtensionRanges) {
@ -2028,8 +2028,8 @@ TEST_F(ExtensionDescriptorTest, Extensions) {
EXPECT_EQ(FieldDescriptor::TYPE_GROUP, bar_->extension(1)->type());
EXPECT_EQ(baz_, foo_file_->extension(1)->enum_type());
EXPECT_EQ(qux_, bar_->extension(0)->message_type());
EXPECT_EQ(qux_, bar_->extension(1)->message_type());
EXPECT_EQ(moo_, bar_->extension(0)->message_type());
EXPECT_EQ(moo_, bar_->extension(1)->message_type());
EXPECT_EQ(FieldDescriptor::LABEL_OPTIONAL, foo_file_->extension(0)->label());
EXPECT_EQ(FieldDescriptor::LABEL_REPEATED, foo_file_->extension(1)->label());
@ -2863,8 +2863,8 @@ class AllowUnknownDependenciesTest
" name: 'Foo'"
" field { name:'bar' number:1 label:LABEL_OPTIONAL type_name:'Bar' }"
" field { name:'baz' number:2 label:LABEL_OPTIONAL type_name:'Baz' }"
" field { name:'qux' number:3 label:LABEL_OPTIONAL"
" type_name: '.corge.Qux'"
" field { name:'moo' number:3 label:LABEL_OPTIONAL"
" type_name: '.corge.Moo'"
" type: TYPE_ENUM"
" options {"
" uninterpreted_option {"
@ -2902,7 +2902,7 @@ class AllowUnknownDependenciesTest
ASSERT_EQ(3, foo_type_->field_count());
bar_field_ = foo_type_->field(0);
baz_field_ = foo_type_->field(1);
qux_field_ = foo_type_->field(2);
moo_field_ = foo_type_->field(2);
}
const FileDescriptor* BuildFile(const FileDescriptorProto& proto) {
@ -2925,7 +2925,7 @@ class AllowUnknownDependenciesTest
const Descriptor* foo_type_;
const FieldDescriptor* bar_field_;
const FieldDescriptor* baz_field_;
const FieldDescriptor* qux_field_;
const FieldDescriptor* moo_field_;
SimpleDescriptorDatabase db_; // used if in FALLBACK_DATABASE mode.
std::unique_ptr<DescriptorPool> pool_;
@ -2964,18 +2964,18 @@ TEST_P(AllowUnknownDependenciesTest, PlaceholderTypes) {
EXPECT_EQ(0, baz_type->extension_range_count());
EXPECT_TRUE(baz_type->is_placeholder());
ASSERT_EQ(FieldDescriptor::TYPE_ENUM, qux_field_->type());
const EnumDescriptor* qux_type = qux_field_->enum_type();
EXPECT_EQ("Qux", qux_type->name());
EXPECT_EQ("corge.Qux", qux_type->full_name());
EXPECT_TRUE(qux_type->is_placeholder());
ASSERT_EQ(FieldDescriptor::TYPE_ENUM, moo_field_->type());
const EnumDescriptor* moo_type = moo_field_->enum_type();
EXPECT_EQ("Moo", moo_type->name());
EXPECT_EQ("corge.Moo", moo_type->full_name());
EXPECT_TRUE(moo_type->is_placeholder());
// Placeholder enum values should not be findable.
EXPECT_EQ(qux_type->FindValueByNumber(0), nullptr);
EXPECT_EQ(moo_type->FindValueByNumber(0), nullptr);
// Placeholder types should not be findable.
EXPECT_EQ(bar_type_, pool_->FindMessageTypeByName(bar_type_->full_name()));
EXPECT_TRUE(pool_->FindMessageTypeByName(baz_type->full_name()) == nullptr);
EXPECT_TRUE(pool_->FindEnumTypeByName(qux_type->full_name()) == nullptr);
EXPECT_TRUE(pool_->FindEnumTypeByName(moo_type->full_name()) == nullptr);
}
TEST_P(AllowUnknownDependenciesTest, CopyTo) {
@ -2994,18 +2994,18 @@ TEST_P(AllowUnknownDependenciesTest, CopyTo) {
EXPECT_EQ("Baz", proto.type_name());
EXPECT_FALSE(proto.has_type());
// Qux is a fully-qualified placeholder.
// Moo is a fully-qualified placeholder.
proto.Clear();
qux_field_->CopyTo(&proto);
EXPECT_EQ(".corge.Qux", proto.type_name());
moo_field_->CopyTo(&proto);
EXPECT_EQ(".corge.Moo", proto.type_name());
EXPECT_EQ(FieldDescriptorProto::TYPE_ENUM, proto.type());
}
TEST_P(AllowUnknownDependenciesTest, CustomOptions) {
// Qux should still have the uninterpreted option attached.
ASSERT_EQ(1, qux_field_->options().uninterpreted_option_size());
// Moo should still have the uninterpreted option attached.
ASSERT_EQ(1, moo_field_->options().uninterpreted_option_size());
const UninterpretedOption& option =
qux_field_->options().uninterpreted_option(0);
moo_field_->options().uninterpreted_option(0);
ASSERT_EQ(1, option.name_size());
EXPECT_EQ("grault", option.name(0).name_part());
}
@ -3103,12 +3103,12 @@ TEST_P(AllowUnknownDependenciesTest,
"name: \"invalid_file_as_undeclared_dep.proto\" "
"package: \"undeclared\" "
"message_type: { "
" name: \"Quux\" "
" name: \"Mooo\" "
" field { "
" name:'qux' number:1 label:LABEL_OPTIONAL type: TYPE_INT32 "
" name:'moo' number:1 label:LABEL_OPTIONAL type: TYPE_INT32 "
" }"
" field { "
" name:'quux' number:1 label:LABEL_OPTIONAL type: TYPE_INT64 "
" name:'mooo' number:1 label:LABEL_OPTIONAL type: TYPE_INT64 "
" }"
"}",
&undeclared_dep_proto));
@ -3132,8 +3132,8 @@ TEST_P(AllowUnknownDependenciesTest,
"message_type: { "
" name: \"Corge\" "
" field { "
" name:'quux' number:1 label: LABEL_OPTIONAL "
" type_name:'undeclared.Quux' type: TYPE_MESSAGE "
" name:'mooo' number:1 label: LABEL_OPTIONAL "
" type_name:'undeclared.Mooo' type: TYPE_MESSAGE "
" }"
"}",
&test_proto));
@ -3149,13 +3149,13 @@ TEST_P(AllowUnknownDependenciesTest,
ASSERT_EQ(1, corge_desc->field_count());
EXPECT_FALSE(corge_desc->is_placeholder());
const FieldDescriptor* quux_field = corge_desc->field(0);
ASSERT_EQ(FieldDescriptor::TYPE_MESSAGE, quux_field->type());
ASSERT_EQ("Quux", quux_field->message_type()->name());
ASSERT_EQ("undeclared.Quux", quux_field->message_type()->full_name());
EXPECT_TRUE(quux_field->message_type()->is_placeholder());
const FieldDescriptor* mooo_field = corge_desc->field(0);
ASSERT_EQ(FieldDescriptor::TYPE_MESSAGE, mooo_field->type());
ASSERT_EQ("Mooo", mooo_field->message_type()->name());
ASSERT_EQ("undeclared.Mooo", mooo_field->message_type()->full_name());
EXPECT_TRUE(mooo_field->message_type()->is_placeholder());
// The place holder type should not be findable.
ASSERT_TRUE(pool_->FindMessageTypeByName("undeclared.Quux") == nullptr);
ASSERT_TRUE(pool_->FindMessageTypeByName("undeclared.Mooo") == nullptr);
}
INSTANTIATE_TEST_SUITE_P(DatabaseSource, AllowUnknownDependenciesTest,
@ -3271,11 +3271,11 @@ TEST(CustomOptions, ComplexExtensionOptions) {
&protobuf_unittest::VariousComplexOptions::descriptor()->options();
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt1).foo(), 42);
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt1)
.GetExtension(protobuf_unittest::quux),
.GetExtension(protobuf_unittest::mooo),
324);
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt1)
.GetExtension(protobuf_unittest::corge)
.qux(),
.moo(),
876);
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2).baz(), 987);
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2)
@ -3285,12 +3285,12 @@ TEST(CustomOptions, ComplexExtensionOptions) {
743);
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2)
.bar()
.GetExtension(protobuf_unittest::quux),
.GetExtension(protobuf_unittest::mooo),
1999);
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2)
.bar()
.GetExtension(protobuf_unittest::corge)
.qux(),
.moo(),
2008);
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2)
.GetExtension(protobuf_unittest::garply)
@ -3298,12 +3298,12 @@ TEST(CustomOptions, ComplexExtensionOptions) {
741);
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2)
.GetExtension(protobuf_unittest::garply)
.GetExtension(protobuf_unittest::quux),
.GetExtension(protobuf_unittest::mooo),
1998);
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2)
.GetExtension(protobuf_unittest::garply)
.GetExtension(protobuf_unittest::corge)
.qux(),
.moo(),
2121);
EXPECT_EQ(options
->GetExtension(protobuf_unittest::ComplexOptionType2::
@ -3312,7 +3312,7 @@ TEST(CustomOptions, ComplexExtensionOptions) {
1971);
EXPECT_EQ(options->GetExtension(protobuf_unittest::complex_opt2).fred().waldo(),
321);
EXPECT_EQ(9, options->GetExtension(protobuf_unittest::complex_opt3).qux());
EXPECT_EQ(9, options->GetExtension(protobuf_unittest::complex_opt3).moo());
EXPECT_EQ(22, options->GetExtension(protobuf_unittest::complex_opt3)
.complexoptiontype5()
.plugh());
@ -4114,7 +4114,7 @@ TEST_F(ValidationErrorTest, FieldInExtensionRange) {
"}"
" field { name: \"baz\" number: 19 label:LABEL_OPTIONAL type:TYPE_INT32 "
"}"
" field { name: \"qux\" number: 20 label:LABEL_OPTIONAL type:TYPE_INT32 "
" field { name: \"moo\" number: 20 label:LABEL_OPTIONAL type:TYPE_INT32 "
"}"
" extension_range { start: 10 end: 20 }"
"}",
@ -4446,13 +4446,13 @@ TEST_F(ValidationErrorTest, InvalidDefaults) {
" default_value: \"abc\" }"
// Messages can't have defaults.
" field { name: \"qux\" number: 4 label: LABEL_OPTIONAL type: "
" field { name: \"moo\" number: 4 label: LABEL_OPTIONAL type: "
"TYPE_MESSAGE"
" default_value: \"abc\" type_name: \"Foo\" }"
// Same thing, but we don't know that this field has message type until
// we look up the type name.
" field { name: \"quux\" number: 5 label: LABEL_OPTIONAL"
" field { name: \"mooo\" number: 5 label: LABEL_OPTIONAL"
" default_value: \"abc\" type_name: \"Foo\" }"
// Repeateds can't have defaults.
@ -4466,12 +4466,12 @@ TEST_F(ValidationErrorTest, InvalidDefaults) {
"foo.proto: Foo.bar: DEFAULT_VALUE: Couldn't parse default value \"\".\n"
"foo.proto: Foo.baz: DEFAULT_VALUE: Boolean default must be true or "
"false.\n"
"foo.proto: Foo.qux: DEFAULT_VALUE: Messages can't have default values.\n"
"foo.proto: Foo.moo: DEFAULT_VALUE: Messages can't have default values.\n"
"foo.proto: Foo.corge: DEFAULT_VALUE: Repeated fields can't have default "
"values.\n"
// This ends up being reported later because the error is detected at
// cross-linking time.
"foo.proto: Foo.quux: DEFAULT_VALUE: Messages can't have default "
"foo.proto: Foo.mooo: DEFAULT_VALUE: Messages can't have default "
"values.\n");
}
@ -4511,7 +4511,7 @@ TEST_F(ValidationErrorTest, ReservedFieldNumber) {
"type:TYPE_INT32 }"
" field {name:\"baz\" number: 19999 label:LABEL_OPTIONAL "
"type:TYPE_INT32 }"
" field {name:\"qux\" number: 20000 label:LABEL_OPTIONAL "
" field {name:\"moo\" number: 20000 label:LABEL_OPTIONAL "
"type:TYPE_INT32 }"
"}",
@ -5108,7 +5108,7 @@ TEST_F(ValidationErrorTest, PackageOriginallyDeclaredInTransitiveDependent) {
// baz.proto:
// package foo;
// import "bar.proto"
// message Baz { optional bar.Bar qux = 1; }
// message Baz { optional bar.Bar moo = 1; }
//
// When validating baz.proto, we will look up "bar.Bar". As part of this
// lookup, we first lookup "bar" then try to find "Bar" within it. "bar"
@ -5132,7 +5132,7 @@ TEST_F(ValidationErrorTest, PackageOriginallyDeclaredInTransitiveDependent) {
"dependency: \"bar.proto\" "
"message_type { "
" name: \"Baz\" "
" field { name:\"qux\" number:1 label:LABEL_OPTIONAL "
" field { name:\"moo\" number:1 label:LABEL_OPTIONAL "
" type_name:\"bar.Bar\" }"
"}");
}
@ -5472,12 +5472,12 @@ TEST_F(ValidationErrorTest, ResolveUndefinedOption) {
// message Bar { optional int32 foo = 1; }
// extend FileOptions { optional Bar bar = 7672757; }
//
// qux.proto:
// package qux.baz
// moo.proto:
// package moo.baz
// option (baz.bar).foo = 1;
//
// Although "baz.bar" is already defined, the lookup code will try
// "qux.baz.bar", since it's the match from the innermost scope, which will
// "moo.baz.bar", since it's the match from the innermost scope, which will
// cause a symbol not defined error.
BuildDescriptorMessagesInTestPool();
@ -5493,16 +5493,16 @@ TEST_F(ValidationErrorTest, ResolveUndefinedOption) {
" extendee: \"google.protobuf.FileOptions\" }");
BuildFileWithErrors(
"name: \"qux.proto\" "
"package: \"qux.baz\" "
"name: \"moo.proto\" "
"package: \"moo.baz\" "
"options { uninterpreted_option { name { name_part: \"baz.bar\" "
" is_extension: true } "
" name { name_part: \"foo\" "
" is_extension: false } "
" positive_int_value: 1 } }",
"qux.proto: qux.proto: OPTION_NAME: Option \"(baz.bar)\" is resolved to "
"\"(qux.baz.bar)\","
"moo.proto: moo.proto: OPTION_NAME: Option \"(baz.bar)\" is resolved to "
"\"(moo.baz.bar)\","
" which is not defined. The innermost scope is searched first in name "
"resolution. Consider using a leading '.'(i.e., \"(.baz.bar)\") to start "
"from the outermost scope.\n");
@ -5510,15 +5510,15 @@ TEST_F(ValidationErrorTest, ResolveUndefinedOption) {
TEST_F(ValidationErrorTest, UnknownOption) {
BuildFileWithErrors(
"name: \"qux.proto\" "
"package: \"qux.baz\" "
"name: \"moo.proto\" "
"package: \"moo.baz\" "
"options { uninterpreted_option { name { name_part: \"baaz.bar\" "
" is_extension: true } "
" name { name_part: \"foo\" "
" is_extension: false } "
" positive_int_value: 1 } }",
"qux.proto: qux.proto: OPTION_NAME: Option \"(baaz.bar)\" unknown. "
"moo.proto: moo.proto: OPTION_NAME: Option \"(baaz.bar)\" unknown. "
"Ensure "
"that your proto definition file imports the proto which defines the "
"option.\n");
@ -5732,7 +5732,7 @@ TEST_F(ValidationErrorTest, EnumOptionValueIsNotIdentifier) {
" extendee: \"google.protobuf.FileOptions\" }"
"options { uninterpreted_option { name { name_part: \"foo\" "
" is_extension: true } "
" string_value: \"QUUX\" } }",
" string_value: \"MOOO\" } }",
"foo.proto: foo.proto: OPTION_VALUE: Value must be identifier for "
"enum-valued option \"foo\".\n");
@ -5751,10 +5751,10 @@ TEST_F(ValidationErrorTest, EnumOptionValueIsNotEnumValueName) {
" extendee: \"google.protobuf.FileOptions\" }"
"options { uninterpreted_option { name { name_part: \"foo\" "
" is_extension: true } "
" identifier_value: \"QUUX\" } }",
" identifier_value: \"MOOO\" } }",
"foo.proto: foo.proto: OPTION_VALUE: Enum type \"FooEnum\" has no value "
"named \"QUUX\" for option \"foo\".\n");
"named \"MOOO\" for option \"foo\".\n");
}
TEST_F(ValidationErrorTest, EnumOptionValueIsSiblingEnumValueName) {
@ -5765,17 +5765,17 @@ TEST_F(ValidationErrorTest, EnumOptionValueIsSiblingEnumValueName) {
"dependency: \"google/protobuf/descriptor.proto\" "
"enum_type { name: \"FooEnum1\" value { name: \"BAR\" number: 1 } "
" value { name: \"BAZ\" number: 2 } }"
"enum_type { name: \"FooEnum2\" value { name: \"QUX\" number: 1 } "
" value { name: \"QUUX\" number: 2 } }"
"enum_type { name: \"FooEnum2\" value { name: \"MOO\" number: 1 } "
" value { name: \"MOOO\" number: 2 } }"
"extension { name: \"foo\" number: 7672757 label: LABEL_OPTIONAL "
" type: TYPE_ENUM type_name: \"FooEnum1\" "
" extendee: \"google.protobuf.FileOptions\" }"
"options { uninterpreted_option { name { name_part: \"foo\" "
" is_extension: true } "
" identifier_value: \"QUUX\" } }",
" identifier_value: \"MOOO\" } }",
"foo.proto: foo.proto: OPTION_VALUE: Enum type \"FooEnum1\" has no value "
"named \"QUUX\" for option \"foo\". This appears to be a value from a "
"named \"MOOO\" for option \"foo\". This appears to be a value from a "
"sibling type.\n");
}
@ -5789,7 +5789,7 @@ TEST_F(ValidationErrorTest, StringOptionValueIsNotString) {
" type: TYPE_STRING extendee: \"google.protobuf.FileOptions\" }"
"options { uninterpreted_option { name { name_part: \"foo\" "
" is_extension: true } "
" identifier_value: \"QUUX\" } }",
" identifier_value: \"MOOO\" } }",
"foo.proto: foo.proto: OPTION_VALUE: Value must be quoted string "
"for "
@ -6731,16 +6731,64 @@ TEST_F(ValidationErrorTest, ValidateProto3Extension) {
ASSERT_TRUE(pool.BuildFile(file_proto) != nullptr);
// Add "foo.proto":
// import "google/protobuf/descriptor.proto";
// extend google.protobuf.FileOptions {
// optional string test_file_opt = 1001;
// }
// extend google.protobuf.MessageOptions {
// optional string test_msg_opt = 1002;
// }
// extend google.protobuf.FieldOptions {
// optional int32 option1 = 1000;
// optional string test_field_opt = 1003;
// }
// extend google.protobuf.EnumOptions {
// repeated int32 test_enum_opt = 1004;
// }
// extend google.protobuf.EnumValueOptions {
// optional int32 test_enumval_opt = 1005;
// }
// extend google.protobuf.ServiceOptions {
// repeated int32 test_svc_opt = 1006;
// }
// extend google.protobuf.MethodOptions {
// optional string test_method_opt = 1007;
// }
// extend google.protobuf.OneofOptions {
// optional string test_oneof_opt = 1008;
// }
// extend google.protobuf.ExtensionRangeOptions {
// optional string test_ext_opt = 1009;
// }
file_proto.Clear();
file_proto.set_name("foo.proto");
file_proto.set_syntax("proto3");
file_proto.add_dependency("google/protobuf/descriptor.proto");
AddExtension(&file_proto, "google.protobuf.FieldOptions", "option1", 1000,
AddExtension(&file_proto, "google.protobuf.FileOptions", "test_file_opt", 1001,
FieldDescriptorProto::LABEL_OPTIONAL,
FieldDescriptorProto::TYPE_STRING);
AddExtension(&file_proto, "google.protobuf.MessageOptions", "test_msg_opt", 1001,
FieldDescriptorProto::LABEL_OPTIONAL,
FieldDescriptorProto::TYPE_STRING);
AddExtension(&file_proto, "google.protobuf.FieldOptions", "test_field_opt", 1003,
FieldDescriptorProto::LABEL_OPTIONAL,
FieldDescriptorProto::TYPE_STRING);
AddExtension(&file_proto, "google.protobuf.EnumOptions", "test_enum_opt", 1004,
FieldDescriptorProto::LABEL_REPEATED,
FieldDescriptorProto::TYPE_INT32);
AddExtension(&file_proto, "google.protobuf.EnumValueOptions", "test_enumval_opt", 1005,
FieldDescriptorProto::LABEL_OPTIONAL,
FieldDescriptorProto::TYPE_INT32);
AddExtension(&file_proto, "google.protobuf.ServiceOptions", "test_svc_opt", 1006,
FieldDescriptorProto::LABEL_REPEATED,
FieldDescriptorProto::TYPE_INT32);
AddExtension(&file_proto, "google.protobuf.MethodOptions", "test_method_opt", 1007,
FieldDescriptorProto::LABEL_OPTIONAL,
FieldDescriptorProto::TYPE_STRING);
AddExtension(&file_proto, "google.protobuf.OneofOptions", "test_oneof_opt", 1008,
FieldDescriptorProto::LABEL_OPTIONAL,
FieldDescriptorProto::TYPE_STRING);
AddExtension(&file_proto, "google.protobuf.ExtensionRangeOptions", "test_ext_opt",
1009, FieldDescriptorProto::LABEL_OPTIONAL,
FieldDescriptorProto::TYPE_STRING);
ASSERT_TRUE(pool.BuildFile(file_proto) != nullptr);
// Copy and change the package of the descriptor.proto

View File

@ -44,19 +44,19 @@ namespace protobuf {
TEST(DropUnknownFieldsTest, GeneratedMessage) {
FooWithExtraFields foo_with_extra_fields;
foo_with_extra_fields.set_int32_value(1);
foo_with_extra_fields.set_enum_value(FooWithExtraFields::QUX);
foo_with_extra_fields.set_enum_value(FooWithExtraFields::MOO);
foo_with_extra_fields.set_extra_int32_value(2);
Foo foo;
ASSERT_TRUE(foo.ParseFromString(foo_with_extra_fields.SerializeAsString()));
EXPECT_EQ(1, foo.int32_value());
EXPECT_EQ(static_cast<int>(FooWithExtraFields::QUX),
EXPECT_EQ(static_cast<int>(FooWithExtraFields::MOO),
static_cast<int>(foo.enum_value()));
EXPECT_FALSE(foo.GetReflection()->GetUnknownFields(foo).empty());
ASSERT_TRUE(foo_with_extra_fields.ParseFromString(foo.SerializeAsString()));
EXPECT_EQ(1, foo_with_extra_fields.int32_value());
EXPECT_EQ(FooWithExtraFields::QUX, foo_with_extra_fields.enum_value());
EXPECT_EQ(FooWithExtraFields::MOO, foo_with_extra_fields.enum_value());
// The "extra_int32_value" field should not be lost.
EXPECT_EQ(2, foo_with_extra_fields.extra_int32_value());
}
@ -64,7 +64,7 @@ TEST(DropUnknownFieldsTest, GeneratedMessage) {
TEST(DropUnknownFieldsTest, DynamicMessage) {
FooWithExtraFields foo_with_extra_fields;
foo_with_extra_fields.set_int32_value(1);
foo_with_extra_fields.set_enum_value(FooWithExtraFields::QUX);
foo_with_extra_fields.set_enum_value(FooWithExtraFields::MOO);
foo_with_extra_fields.set_extra_int32_value(2);
DynamicMessageFactory factory;
@ -74,7 +74,7 @@ TEST(DropUnknownFieldsTest, DynamicMessage) {
ASSERT_TRUE(foo_with_extra_fields.ParseFromString(foo->SerializeAsString()));
EXPECT_EQ(1, foo_with_extra_fields.int32_value());
EXPECT_EQ(FooWithExtraFields::QUX, foo_with_extra_fields.enum_value());
EXPECT_EQ(FooWithExtraFields::MOO, foo_with_extra_fields.enum_value());
// The "extra_int32_value" field should not be lost.
EXPECT_EQ(2, foo_with_extra_fields.extra_int32_value());
}

View File

@ -242,7 +242,7 @@ size_t Duration::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Duration::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Duration::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Duration::GetClassData() const { return &_class_data_; }

View File

@ -40,19 +40,19 @@
// reflection_ops_unittest, cover the rest of the functionality used by
// DynamicMessage.
#include <google/protobuf/dynamic_message.h>
#include <memory>
#include <google/protobuf/test_util.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/unittest_no_field_presence.pb.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/test_util.h>
namespace google {
namespace protobuf {

View File

@ -22,7 +22,7 @@ namespace _pbi = _pb::internal;
PROTOBUF_NAMESPACE_OPEN
PROTOBUF_CONSTEXPR Empty::Empty(
::_pbi::ConstantInitialized): _impl_{} {}
::_pbi::ConstantInitialized) {}
struct EmptyDefaultTypeInternal {
PROTOBUF_CONSTEXPR EmptyDefaultTypeInternal()
: _instance(::_pbi::ConstantInitialized{}) {}
@ -90,8 +90,6 @@ Empty::Empty(::PROTOBUF_NAMESPACE_ID::Arena* arena,
}
Empty::Empty(const Empty& from)
: ::PROTOBUF_NAMESPACE_ID::internal::ZeroFieldsBase() {
new (&_impl_) Impl_{};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.Empty)
}

View File

@ -171,7 +171,6 @@ class PROTOBUF_EXPORT Empty final :
typedef void DestructorSkippable_;
struct Impl_ {
};
union { Impl_ _impl_; };
friend struct ::TableStruct_google_2fprotobuf_2fempty_2eproto;
};
// ===================================================================

View File

@ -36,8 +36,6 @@
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/test_util2.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/unittest_mset.pb.h>
#include <google/protobuf/io/coded_stream.h>
@ -50,6 +48,8 @@
#include <google/protobuf/wire_format.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/test_util2.h>
#include <google/protobuf/stubs/stl_util.h>
// Must be included last.
@ -63,7 +63,7 @@ namespace {
using TestUtil::EqualsToSerialized;
// This test closely mirrors net/proto2/compiler/cpp/internal/unittest.cc
// This test closely mirrors third_party/protobuf/compiler/cpp/unittest.cc
// except that it uses extensions rather than regular fields.
TEST(ExtensionSetTest, Defaults) {

View File

@ -229,7 +229,7 @@ size_t FieldMask::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData FieldMask::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
FieldMask::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FieldMask::GetClassData() const { return &_class_data_; }

View File

@ -3107,6 +3107,56 @@ void UnknownFieldSetSerializer(const uint8_t* base, uint32_t offset,
}
}
bool IsDescendant(Message* root, const Message& message) {
const Reflection* reflection = root->GetReflection();
std::vector<const FieldDescriptor*> fields;
reflection->ListFieldsOmitStripped(*root, &fields);
for (const auto* field : fields) {
// Skip non-message fields.
if (field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) continue;
// Optional messages.
if (!field->is_repeated()) {
Message* sub_message = reflection->MutableMessage(root, field);
if (sub_message == &message || IsDescendant(sub_message, message)) {
return true;
}
continue;
}
// Repeated messages.
if (!IsMapFieldInApi(field)) {
int count = reflection->FieldSize(*root, field);
for (int i = 0; i < count; i++) {
Message* sub_message =
reflection->MutableRepeatedMessage(root, field, i);
if (sub_message == &message || IsDescendant(sub_message, message)) {
return true;
}
}
continue;
}
// Map field: if accessed as repeated fields, messages are *copied* and
// matching pointer won't work. Must directly access map.
constexpr int kValIdx = 1;
const FieldDescriptor* val_field = field->message_type()->field(kValIdx);
// Skip map fields whose value type is not message.
if (val_field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) continue;
MapIterator end = reflection->MapEnd(root, field);
for (auto iter = reflection->MapBegin(root, field); iter != end; ++iter) {
Message* sub_message = iter.MutableValueRef()->MutableMessageValue();
if (sub_message == &message || IsDescendant(sub_message, message)) {
return true;
}
}
}
return false;
}
} // namespace internal
} // namespace protobuf
} // namespace google

View File

@ -48,9 +48,7 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/map_test_util.h>
#include <google/protobuf/map_unittest.pb.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/unittest_mset.pb.h>
#include <google/protobuf/unittest_mset_wire_format.pb.h>
@ -58,6 +56,8 @@
#include <google/protobuf/descriptor.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/map_test_util.h>
#include <google/protobuf/test_util.h>
// Must be included last.
#include <google/protobuf/port_def.inc>
@ -545,7 +545,7 @@ TEST(GeneratedMessageReflectionTest,
auto* message1 = Arena::CreateMessage<unittest::TestOneof2>(&arena);
auto* message2 = Arena::CreateMessage<unittest::TestOneof2>(&arena);
TestUtil::SetOneof1(message1);
message1->mutable_foo_message()->set_qux_int(1000);
message1->mutable_foo_message()->set_moo_int(1000);
auto* kept_foo_ptr = message1->mutable_foo_message();
std::vector<const FieldDescriptor*> fields;
@ -557,7 +557,7 @@ TEST(GeneratedMessageReflectionTest,
message1, message2, fields);
EXPECT_TRUE(message2->has_foo_message());
EXPECT_EQ(message2->foo_message().qux_int(), 1000);
EXPECT_EQ(message2->foo_message().moo_int(), 1000);
EXPECT_EQ(kept_foo_ptr, message2->mutable_foo_message());
}
@ -1300,6 +1300,67 @@ TEST(GeneratedMessageReflectionTest, UsageErrors) {
#endif // PROTOBUF_HAS_DEATH_TEST
using internal::IsDescendant;
TEST(GeneratedMessageReflection, IsDescendantMessage) {
unittest::TestAllTypes msg1, msg2;
TestUtil::SetAllFields(&msg1);
msg2 = msg1;
EXPECT_TRUE(IsDescendant(&msg1, msg1.optional_nested_message()));
EXPECT_TRUE(IsDescendant(&msg1, msg1.repeated_foreign_message(0)));
EXPECT_FALSE(IsDescendant(&msg1, msg2.optional_nested_message()));
EXPECT_FALSE(IsDescendant(&msg1, msg2.repeated_foreign_message(0)));
}
TEST(GeneratedMessageReflection, IsDescendantMap) {
unittest::TestMap msg1, msg2;
(*msg1.mutable_map_int32_foreign_message())[0].set_c(100);
TestUtil::SetAllFields(&(*msg1.mutable_map_int32_all_types())[0]);
msg2 = msg1;
EXPECT_TRUE(IsDescendant(&msg1, msg1.map_int32_foreign_message().at(0)));
EXPECT_TRUE(IsDescendant(&msg1, msg1.map_int32_all_types().at(0)));
EXPECT_FALSE(IsDescendant(&msg1, msg2.map_int32_foreign_message().at(0)));
EXPECT_FALSE(IsDescendant(&msg1, msg2.map_int32_all_types().at(0)));
}
TEST(GeneratedMessageReflection, IsDescendantExtension) {
unittest::TestAllExtensions msg1, msg2;
TestUtil::SetAllExtensions(&msg1);
msg2 = msg1;
EXPECT_TRUE(IsDescendant(
&msg1, msg1.GetExtension(unittest::optional_nested_message_extension)));
EXPECT_TRUE(IsDescendant(
&msg1,
msg1.GetExtension(unittest::repeated_foreign_message_extension, 0)));
EXPECT_FALSE(IsDescendant(
&msg1, msg2.GetExtension(unittest::optional_nested_message_extension)));
EXPECT_FALSE(IsDescendant(
&msg1,
msg2.GetExtension(unittest::repeated_foreign_message_extension, 0)));
}
TEST(GeneratedMessageReflection, IsDescendantOneof) {
unittest::TestOneof msg1, msg2;
TestUtil::SetAllFields(msg1.mutable_foo_message());
msg2 = msg1;
EXPECT_TRUE(
IsDescendant(&msg1, msg1.foo_message().optional_nested_message()));
EXPECT_TRUE(
IsDescendant(&msg1, msg1.foo_message().repeated_foreign_message(0)));
EXPECT_FALSE(
IsDescendant(&msg1, msg2.foo_message().optional_nested_message()));
EXPECT_FALSE(
IsDescendant(&msg1, msg2.foo_message().repeated_foreign_message(0)));
}
} // namespace
} // namespace protobuf
} // namespace google

View File

@ -844,7 +844,9 @@ TEST_F(TokenizerTest, ParseInteger) {
// Test near the limits of signed parsing (values in kint64max +/- 1600)
for (int64_t offset = -1600; offset <= 1600; ++offset) {
uint64_t i = 0x7FFFFFFFFFFFFFFF + offset;
// We make sure to perform an unsigned addition so that we avoid signed
// overflow, which would be undefined behavior.
uint64_t i = 0x7FFFFFFFFFFFFFFFu + static_cast<uint64_t>(offset);
char decimal[32];
snprintf(decimal, 32, "%llu", static_cast<unsigned long long>(i));
if (offset > 0) {

View File

@ -30,6 +30,7 @@
// Author: kenton@google.com (Kenton Varda)
#include <climits>
#include <iostream>
#include <string>
@ -45,6 +46,7 @@
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/map_lite_test_util.h>
#include <google/protobuf/parse_context.h>
#include <google/protobuf/test_util_lite.h>
#include <google/protobuf/wire_format_lite.h>
@ -88,6 +90,61 @@ void SetSomeTypesInEmptyMessageUnknownFields(
empty_message->ParseFromString(data);
}
TEST(ParseVarintTest, Varint32) {
auto test_value = [](uint32_t value, int varint_length) {
uint8_t buffer[10];
uint8_t* p = io::CodedOutputStream::WriteVarint32ToArray(value, buffer);
ASSERT_EQ(p - buffer, varint_length) << "Value = " << value;
const char* cbuffer = reinterpret_cast<const char*>(buffer);
uint32_t parsed = ~value;
const char* r = internal::VarintParse(cbuffer, &parsed);
ASSERT_EQ(r - cbuffer, varint_length) << "Value = " << value;
ASSERT_EQ(parsed, value);
};
uint32_t base = 73; // 1001011b
for (int varint_length = 1; varint_length <= 5; ++varint_length) {
uint32_t values[] = {
base - 73, base - 72, base, base + 126 - 73, base + 126 - 72,
};
for (uint32_t value : values) {
test_value(value, varint_length);
}
base = (base << 7) + 73;
}
test_value(std::numeric_limits<uint32_t>::max(), 5);
}
TEST(ParseVarintTest, Varint64) {
auto test_value = [](uint64_t value, int varint_length) {
uint8_t buffer[10];
uint8_t* p = io::CodedOutputStream::WriteVarint64ToArray(value, buffer);
ASSERT_EQ(p - buffer, varint_length) << "Value = " << value;
const char* cbuffer = reinterpret_cast<const char*>(buffer);
uint64_t parsed = ~value;
const char* r = internal::VarintParse(cbuffer, &parsed);
ASSERT_EQ(r - cbuffer, varint_length) << "Value = " << value;
ASSERT_EQ(parsed, value);
};
uint64_t base = 73; // 1001011b
for (int varint_length = 1; varint_length <= 10; ++varint_length) {
uint64_t values[] = {
base - 73, base - 72, base, base + 126 - 73, base + 126 - 72,
};
for (uint64_t value : values) {
test_value(value, varint_length);
}
base = (base << 7) + 73;
}
test_value(std::numeric_limits<uint64_t>::max(), 10);
}
TEST(Lite, AllLite1) {
std::string data;

View File

@ -49,7 +49,6 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/testing/file.h>
#include <google/protobuf/test_util2.h>
#include <google/protobuf/descriptor.pb.h>
#include <gmock/gmock.h>
#include <google/protobuf/testing/googletest.h>
@ -57,21 +56,22 @@
#include <google/protobuf/stubs/casts.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/arena_test_util.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor_database.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/map.h>
#include <google/protobuf/map_field_inl.h>
#include <google/protobuf/message.h>
#include <google/protobuf/reflection.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/test_util2.h>
#include <google/protobuf/text_format.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/util/message_differencer.h>
#include <google/protobuf/util/time_util.h>
#include <google/protobuf/wire_format.h>
// Must be included last.

View File

@ -118,20 +118,23 @@ void Message::CopyFrom(const Message& from) {
copy_to_from(this, from);
}
void Message::CopyWithSizeCheck(Message* to, const Message& from) {
void Message::CopyWithSourceCheck(Message* to, const Message& from) {
#ifndef NDEBUG
size_t from_size = from.ByteSizeLong();
FailIfCopyFromDescendant(to, from);
#endif
to->Clear();
#ifndef NDEBUG
GOOGLE_CHECK_EQ(from_size, from.ByteSizeLong())
<< "Source of CopyFrom changed when clearing target. Either "
"source is a nested message in target (not allowed), or "
"another thread is modifying the source.";
#endif
to->GetClassData()->merge_to_from(to, from);
}
void Message::FailIfCopyFromDescendant(Message* to, const Message& from) {
auto* arena = to->GetArenaForAllocation();
bool same_message_owned_arena = to->GetOwningArena() == nullptr &&
arena != nullptr &&
arena == from.GetOwningArena();
GOOGLE_CHECK(!same_message_owned_arena && !internal::IsDescendant(to, from))
<< "Source of CopyFrom cannot be a descendant of the target.";
}
std::string Message::GetTypeName() const {
return GetDescriptor()->full_name();
}

View File

@ -219,6 +219,9 @@ const To& GetConstRefAtOffset(const Message& message, uint32_t offset) {
}
bool CreateUnknownEnumValues(const FieldDescriptor* field);
// Returns true if "message" is a descendant of "root".
PROTOBUF_EXPORT bool IsDescendant(Message* root, const Message& message);
} // namespace internal
// Abstract interface for protocol messages.
@ -252,7 +255,7 @@ class PROTOBUF_EXPORT Message : public MessageLite {
// Make this message into a copy of the given message. The given message
// must have the same descriptor, but need not necessarily be the same class.
// By default this is just implemented as "Clear(); MergeFrom(from);".
virtual void CopyFrom(const Message& from);
void CopyFrom(const Message& from);
// Merge the fields from the given message into this message. Singular
// fields will be overwritten, if specified in from, except for embedded
@ -302,8 +305,11 @@ class PROTOBUF_EXPORT Message : public MessageLite {
// Debugging & Testing----------------------------------------------
// Generates a human readable form of this message, useful for debugging
// and other purposes.
// Generates a human-readable form of this message for debugging purposes.
// Note that the format and content of a debug string is not guaranteed, may
// change without notice, and should not be depended on. Code that does
// anything except display a string to assist in debugging should use
// TextFormat instead.
std::string DebugString() const;
// Like DebugString(), but with less whitespace.
std::string ShortDebugString() const;
@ -375,11 +381,14 @@ class PROTOBUF_EXPORT Message : public MessageLite {
// TODO(jorg): change to pure virtual
virtual const ClassData* GetClassData() const { return nullptr; }
// CopyWithSizeCheck calls Clear() and then MergeFrom(), and in debug
// CopyWithSourceCheck calls Clear() and then MergeFrom(), and in debug
// builds, checks that calling Clear() on the destination message doesn't
// alter the size of the source. It assumes the messages are known to be
// of the same type, and thus uses GetClassData().
static void CopyWithSizeCheck(Message* to, const Message& from);
// alter the source. It assumes the messages are known to be of the same
// type, and thus uses GetClassData().
static void CopyWithSourceCheck(Message* to, const Message& from);
// Fail if "from" is a descendant of "to" as such copy is not allowed.
static void FailIfCopyFromDescendant(Message* to, const Message& from);
inline explicit Message(Arena* arena, bool is_message_owned = false)
: MessageLite(arena, is_message_owned) {}
@ -1021,6 +1030,7 @@ class PROTOBUF_EXPORT Reflection final {
bool IsEagerlyVerifiedLazyField(const FieldDescriptor* field) const;
friend class FastReflectionMessageMutator;
friend bool internal::IsDescendant(Message* root, const Message& message);
const Descriptor* const descriptor_;
const internal::ReflectionSchema schema_;

View File

@ -51,20 +51,20 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/test_util2.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/generated_message_reflection.h>
#include <gmock/gmock.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/io/io_win32.h>
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/test_util2.h>
namespace google {

View File

@ -63,10 +63,14 @@ namespace internal {
class InternalMetadata {
public:
constexpr InternalMetadata() : ptr_(0) {}
explicit InternalMetadata(Arena* arena, bool is_message_owned = false)
: ptr_(is_message_owned
? reinterpret_cast<intptr_t>(arena) | kMessageOwnedArenaTagMask
: reinterpret_cast<intptr_t>(arena)) {
explicit InternalMetadata(Arena* arena, bool is_message_owned = false) {
SetArena(arena, is_message_owned);
}
void SetArena(Arena* arena, bool is_message_owned) {
ptr_ = is_message_owned
? reinterpret_cast<intptr_t>(arena) | kMessageOwnedArenaTagMask
: reinterpret_cast<intptr_t>(arena);
GOOGLE_DCHECK(!is_message_owned || arena != nullptr);
}

View File

@ -501,6 +501,10 @@
#error PROTOBUF_FORCE_COPY_IN_MOVE was previously defined
#endif
#ifdef PROTOBUF_FORCE_RESET_IN_CLEAR
#error PROTOBUF_FORCE_RESET_IN_CLEAR was previously defined
#endif
// Force copy the default string to a string field so that non-optimized builds
// have harder-to-rely-on address stability.
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING

View File

@ -67,6 +67,7 @@
#undef PROTOBUF_FORCE_COPY_IN_RELEASE
#undef PROTOBUF_FORCE_COPY_IN_SWAP
#undef PROTOBUF_FORCE_COPY_IN_MOVE
#undef PROTOBUF_FORCE_RESET_IN_CLEAR
#undef PROTOBUF_FORCE_COPY_DEFAULT_STRING
#undef PROTOBUF_NAMESPACE_OPEN
#undef PROTOBUF_NAMESPACE_CLOSE

View File

@ -32,7 +32,6 @@
#include <string>
#include <vector>
#include <google/protobuf/test_util.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/unittest_proto3_arena.pb.h>
#include <google/protobuf/unittest_proto3_optional.pb.h>
@ -41,6 +40,7 @@
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/test_util.h>
// Must be included last.
#include <google/protobuf/port_def.inc>

View File

@ -33,14 +33,14 @@
// Sanjay Ghemawat, Jeff Dean, and others.
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/stubs/strutil.h>

View File

@ -30,9 +30,9 @@
#include <google/protobuf/reflection_tester.h>
#include <gtest/gtest.h>
#include <google/protobuf/map_field.h>
#include <google/protobuf/message.h>
#include <gtest/gtest.h>
// Must include last.
#include <google/protobuf/port_def.inc>

View File

@ -34,11 +34,11 @@
// This test proto2 methods on a proto2 layout.
#include <google/protobuf/stubs/casts.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/reflection.h>
#include <gtest/gtest.h>
#include <google/protobuf/test_util.h>
namespace google {
namespace protobuf {

View File

@ -1311,12 +1311,12 @@ TEST(RepeatedPtrField, AddAllocated) {
}
field.RemoveLast();
index = field.size();
std::string* qux = new std::string("qux");
field.AddAllocated(qux);
std::string* moo = new std::string("moo");
field.AddAllocated(moo);
EXPECT_EQ(index + 1, field.size());
// We should have discarded the cleared object.
EXPECT_EQ(0, field.ClearedCount());
EXPECT_EQ(qux, &field.Get(index));
EXPECT_EQ(moo, &field.Get(index));
}
TEST(RepeatedPtrField, AddAllocatedDifferentArena) {
@ -1906,8 +1906,8 @@ TEST_F(RepeatedPtrFieldIteratorTest, STLAlgorithms_lower_bound) {
TEST_F(RepeatedPtrFieldIteratorTest, Mutation) {
RepeatedPtrField<std::string>::iterator iter = proto_array_.begin();
*iter = "qux";
EXPECT_EQ("qux", proto_array_.Get(0));
*iter = "moo";
EXPECT_EQ("moo", proto_array_.Get(0));
}
// -------------------------------------------------------------------
@ -2107,8 +2107,8 @@ TEST_F(RepeatedPtrFieldPtrsIteratorTest, PtrSTLAlgorithms_lower_bound) {
TEST_F(RepeatedPtrFieldPtrsIteratorTest, PtrMutation) {
RepeatedPtrField<std::string>::pointer_iterator iter =
proto_array_.pointer_begin();
**iter = "qux";
EXPECT_EQ("qux", proto_array_.Get(0));
**iter = "moo";
EXPECT_EQ("moo", proto_array_.Get(0));
EXPECT_EQ("bar", proto_array_.Get(1));
EXPECT_EQ("baz", proto_array_.Get(2));

View File

@ -235,7 +235,7 @@ size_t SourceContext::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData SourceContext::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
SourceContext::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*SourceContext::GetClassData() const { return &_class_data_; }

View File

@ -365,7 +365,7 @@ size_t Struct::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Struct::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Struct::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Struct::GetClassData() const { return &_class_data_; }
@ -775,7 +775,7 @@ size_t Value::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Value::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Value::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Value::GetClassData() const { return &_class_data_; }
@ -992,7 +992,7 @@ size_t ListValue::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData ListValue::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
ListValue::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ListValue::GetClassData() const { return &_class_data_; }

View File

@ -80,8 +80,8 @@ message TestAllTypesProto3 {
ALIAS_FOO = 0;
ALIAS_BAR = 1;
ALIAS_BAZ = 2;
QUX = 2;
qux = 2;
MOO = 2;
moo = 2;
bAz = 2;
}
@ -278,8 +278,7 @@ enum ForeignEnum {
FOREIGN_BAZ = 2;
}
message NullHypothesisProto3 {
}
message NullHypothesisProto3 {}
message EnumOnlyProto3 {
enum Bool {

View File

@ -348,7 +348,7 @@ inline void TestUtil::ReflectionTester::SetOneofViaReflection(
Message* sub_message = reflection->MutableMessage(
message, descriptor->FindFieldByName("foo_lazy_message"));
sub_message->GetReflection()->SetInt64(
sub_message, sub_message->GetDescriptor()->FindFieldByName("qux_int"),
sub_message, sub_message->GetDescriptor()->FindFieldByName("moo_int"),
100);
reflection->SetString(message, descriptor->FindFieldByName("bar_cord"),
@ -376,7 +376,7 @@ inline void TestUtil::ReflectionTester::ExpectOneofSetViaReflection(
message, descriptor->FindFieldByName("foo_lazy_message"));
EXPECT_EQ(100, sub_message->GetReflection()->GetInt64(
*sub_message,
sub_message->GetDescriptor()->FindFieldByName("qux_int")));
sub_message->GetDescriptor()->FindFieldByName("moo_int")));
EXPECT_EQ("101", reflection->GetString(
message, descriptor->FindFieldByName("bar_cord")));

View File

@ -39,9 +39,9 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <gtest/gtest.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/message.h>
#include <gtest/gtest.h>
namespace google {
namespace protobuf {
@ -2315,7 +2315,7 @@ inline void TestUtil::ExpectRepeatedExtensionsSwapped(
}
inline void TestUtil::SetOneof1(UNITTEST::TestOneof2* message) {
message->mutable_foo_lazy_message()->set_qux_int(100);
message->mutable_foo_lazy_message()->set_moo_int(100);
message->set_bar_string("101");
message->set_baz_int(102);
message->set_baz_string("103");
@ -2332,7 +2332,7 @@ inline void TestUtil::ExpectOneofSet1(const UNITTEST::TestOneof2& message) {
ExpectAtMostOneFieldSetInOneof(message);
EXPECT_TRUE(message.has_foo_lazy_message());
EXPECT_TRUE(message.foo_lazy_message().has_qux_int());
EXPECT_TRUE(message.foo_lazy_message().has_moo_int());
EXPECT_TRUE(message.has_bar_string());
EXPECT_TRUE(message.has_baz_int());
@ -2340,7 +2340,7 @@ inline void TestUtil::ExpectOneofSet1(const UNITTEST::TestOneof2& message) {
ASSERT_EQ(0, message.foo_lazy_message().corge_int_size());
EXPECT_EQ(100, message.foo_lazy_message().qux_int());
EXPECT_EQ(100, message.foo_lazy_message().moo_int());
EXPECT_EQ("101", message.bar_string());
EXPECT_EQ(102, message.baz_int());
EXPECT_EQ("103", message.baz_string());

View File

@ -33,10 +33,10 @@
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/util/message_differencer.h>
#include <google/protobuf/testing/googletest.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/util/message_differencer.h>
namespace google {
namespace protobuf {

View File

@ -245,8 +245,8 @@ class TextFormat::Parser::ParserImpl {
public:
// Determines if repeated values for non-repeated fields and
// oneofs are permitted, e.g., the string "foo: 1 foo: 2" for a
// required/optional field named "foo", or "baz: 1 qux: 2"
// where "baz" and "qux" are members of the same oneof.
// required/optional field named "foo", or "baz: 1 bar: 2"
// where "baz" and "bar" are members of the same oneof.
enum SingularOverwritePolicy {
ALLOW_SINGULAR_OVERWRITES = 0, // the last value is retained
FORBID_SINGULAR_OVERWRITES = 1, // an error is issued

View File

@ -456,16 +456,15 @@ class PROTOBUF_EXPORT TextFormat {
};
// Parses a text-format protocol message from the given input stream to
// the given message object. This function parses the human-readable format
// written by Print(). Returns true on success. The message is cleared first,
// even if the function fails -- See Merge() to avoid this behavior.
// the given message object. This function parses the human-readable
// serialization format written by Print(). Returns true on success. The
// message is cleared first, even if the function fails -- See Merge() to
// avoid this behavior.
//
// Example input: "user {\n id: 123 extra { gender: MALE language: 'en' }\n}"
//
// One use for this function is parsing handwritten strings in test code.
// Another use is to parse the output from google::protobuf::Message::DebugString()
// (or ShortDebugString()), because these functions output using
// google::protobuf::TextFormat::Print().
// One common use for this function is parsing handwritten strings in test
// code.
//
// If you would like to read a protocol buffer serialized in the
// (non-human-readable) binary wire format, see

View File

@ -47,8 +47,6 @@
#include <google/protobuf/testing/file.h>
#include <google/protobuf/any.pb.h>
#include <google/protobuf/map_unittest.pb.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/test_util2.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/unittest_mset.pb.h>
#include <google/protobuf/unittest_mset_wire_format.pb.h>
@ -61,6 +59,8 @@
#include <gtest/gtest.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/test_util2.h>
// Must be included last.

View File

@ -242,7 +242,7 @@ size_t Timestamp::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Timestamp::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Timestamp::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Timestamp::GetClassData() const { return &_class_data_; }

View File

@ -667,7 +667,7 @@ size_t Type::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Type::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Type::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Type::GetClassData() const { return &_class_data_; }
@ -1169,7 +1169,7 @@ size_t Field::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Field::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Field::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Field::GetClassData() const { return &_class_data_; }
@ -1552,7 +1552,7 @@ size_t Enum::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Enum::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Enum::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Enum::GetClassData() const { return &_class_data_; }
@ -1829,7 +1829,7 @@ size_t EnumValue::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData EnumValue::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
EnumValue::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumValue::GetClassData() const { return &_class_data_; }
@ -2084,7 +2084,7 @@ size_t Option::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Option::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Option::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Option::GetClassData() const { return &_class_data_; }

View File

@ -842,7 +842,7 @@ message TestOneof2 {
optional string baz_string = 19 [default = "BAZ"];
message NestedMessage {
optional int64 qux_int = 1;
optional int64 moo_int = 1;
repeated int32 corge_int = 2;
}
@ -1034,6 +1034,17 @@ message TestCommentInjectionMessage {
optional string a = 1 [default="*/ <- Neither should this."];
}
// Used to check that the c++ code generator re-orders messages to reduce
// padding.
message TestMessageSize {
optional bool m1 = 1;
optional int64 m2 = 2;
optional bool m3 = 3;
optional string m4 = 4;
optional int32 m5 = 5;
optional int64 m6 = 6;
}
// Test that RPC services work.
message FooRequest {}

View File

@ -245,7 +245,7 @@ message ComplexOptionType2 {
}
message ComplexOptionType3 {
optional int32 qux = 1;
optional int32 moo = 1;
optional group ComplexOptionType5 = 2 {
optional int32 plugh = 3;
@ -253,7 +253,7 @@ message ComplexOptionType3 {
}
extend ComplexOptionType1 {
optional int32 quux = 7663707;
optional int32 mooo = 7663707;
optional ComplexOptionType3 corge = 7663442;
}
@ -274,18 +274,18 @@ extend google.protobuf.MessageOptions {
// Note that we try various different ways of naming the same extension.
message VariousComplexOptions {
option (.protobuf_unittest.complex_opt1).foo = 42;
option (protobuf_unittest.complex_opt1).(.protobuf_unittest.quux) = 324;
option (.protobuf_unittest.complex_opt1).(protobuf_unittest.corge).qux = 876;
option (protobuf_unittest.complex_opt1).(.protobuf_unittest.mooo) = 324;
option (.protobuf_unittest.complex_opt1).(protobuf_unittest.corge).moo = 876;
option (protobuf_unittest.complex_opt1).foo4 = 99;
option (protobuf_unittest.complex_opt1).foo4 = 88;
option (complex_opt2).baz = 987;
option (complex_opt2).(grault) = 654;
option (complex_opt2).bar.foo = 743;
option (complex_opt2).bar.(quux) = 1999;
option (complex_opt2).bar.(protobuf_unittest.corge).qux = 2008;
option (complex_opt2).bar.(mooo) = 1999;
option (complex_opt2).bar.(protobuf_unittest.corge).moo = 2008;
option (complex_opt2).(garply).foo = 741;
option (complex_opt2).(garply).(.protobuf_unittest.quux) = 1998;
option (complex_opt2).(protobuf_unittest.garply).(corge).qux = 2121;
option (complex_opt2).(garply).(.protobuf_unittest.mooo) = 1998;
option (complex_opt2).(protobuf_unittest.garply).(corge).moo = 2121;
option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971;
option (complex_opt2).fred.waldo = 321;
option (complex_opt2).barney = {
@ -294,7 +294,7 @@ message VariousComplexOptions {
option (complex_opt2).barney = {
waldo: 212
};
option (protobuf_unittest.complex_opt3).qux = 9;
option (protobuf_unittest.complex_opt3).moo = 9;
option (complex_opt3).complexoptiontype5.plugh = 22;
option (complexopt6).xyzzy = 24;
}
@ -439,7 +439,9 @@ message NestedOptionType {
// Custom message option that has a required enum field.
// WARNING: this is strongly discouraged!
message OldOptionType {
enum TestEnum { OLD_VALUE = 0; }
enum TestEnum {
OLD_VALUE = 0;
}
required TestEnum value = 1;
}

View File

@ -31,8 +31,8 @@
syntax = "proto3";
package unittest_drop_unknown_fields;
option objc_class_prefix = "DropUnknowns";
option objc_class_prefix = "DropUnknowns";
option csharp_namespace = "Google.Protobuf.TestProtos";
message Foo {
@ -50,7 +50,7 @@ message FooWithExtraFields {
FOO = 0;
BAR = 1;
BAZ = 2;
QUX = 3;
MOO = 3;
}
int32 int32_value = 1;
NestedEnum enum_value = 2;

View File

@ -111,7 +111,7 @@ void UnknownFieldSet::MergeToInternalMetadata(
size_t UnknownFieldSet::SpaceUsedExcludingSelfLong() const {
if (fields_.empty()) return 0;
size_t total_size = sizeof(fields_) + sizeof(UnknownField) * fields_.size();
size_t total_size = sizeof(UnknownField) * fields_.capacity();
for (const UnknownField& field : fields_) {
switch (field.type()) {

View File

@ -37,12 +37,13 @@
#include <google/protobuf/unknown_field_set.h>
#include <string>
#include <unordered_set>
#include <vector>
#include <google/protobuf/stubs/callback.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/unittest_lite.pb.h>
#include <google/protobuf/io/coded_stream.h>
@ -54,6 +55,7 @@
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/time.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/stubs/stl_util.h>
namespace google {
@ -533,38 +535,61 @@ TEST_F(UnknownFieldSetTest, UnknownEnumValue) {
TEST_F(UnknownFieldSetTest, SpaceUsedExcludingSelf) {
UnknownFieldSet empty;
empty.AddVarint(1, 0);
EXPECT_EQ(sizeof(std::vector<UnknownField>) + sizeof(UnknownField),
empty.SpaceUsedExcludingSelf());
EXPECT_EQ(sizeof(UnknownField), empty.SpaceUsedExcludingSelf());
}
TEST_F(UnknownFieldSetTest, SpaceUsed) {
// Keep shadow vectors to avoid making assumptions about its capacity growth.
// We imitate the push back calls here to determine the expected capacity.
std::vector<UnknownField> shadow_vector, shadow_vector_group;
unittest::TestEmptyMessage empty_message;
// Make sure an unknown field set has zero space used until a field is
// actually added.
size_t base_size = empty_message.SpaceUsedLong();
const size_t base = empty_message.SpaceUsedLong();
std::string* str = nullptr;
UnknownFieldSet* group = nullptr;
const auto total = [&] {
size_t result = base;
result += shadow_vector.capacity() * sizeof(UnknownField);
result += shadow_vector_group.capacity() * sizeof(UnknownField);
if (str != nullptr) {
result += sizeof(std::string);
static const size_t sso_capacity = std::string().capacity();
if (str->capacity() > sso_capacity) result += str->capacity();
}
if (group != nullptr) {
result += sizeof(UnknownFieldSet);
}
return result;
};
UnknownFieldSet* unknown_fields = empty_message.mutable_unknown_fields();
EXPECT_EQ(base_size, empty_message.SpaceUsedLong());
EXPECT_EQ(total(), empty_message.SpaceUsedLong());
// Make sure each thing we add to the set increases the SpaceUsedLong().
unknown_fields->AddVarint(1, 0);
EXPECT_LT(base_size, empty_message.SpaceUsedLong());
base_size = empty_message.SpaceUsedLong();
shadow_vector.emplace_back();
EXPECT_EQ(total(), empty_message.SpaceUsedLong()) << "Var";
std::string* str = unknown_fields->AddLengthDelimited(1);
EXPECT_LT(base_size, empty_message.SpaceUsedLong());
base_size = empty_message.SpaceUsedLong();
str = unknown_fields->AddLengthDelimited(1);
shadow_vector.emplace_back();
EXPECT_EQ(total(), empty_message.SpaceUsedLong()) << "Str";
str->assign(sizeof(std::string) + 1, 'x');
EXPECT_LT(base_size, empty_message.SpaceUsedLong());
base_size = empty_message.SpaceUsedLong();
EXPECT_EQ(total(), empty_message.SpaceUsedLong()) << "Str2";
UnknownFieldSet* group = unknown_fields->AddGroup(1);
EXPECT_LT(base_size, empty_message.SpaceUsedLong());
base_size = empty_message.SpaceUsedLong();
group = unknown_fields->AddGroup(1);
shadow_vector.emplace_back();
EXPECT_EQ(total(), empty_message.SpaceUsedLong()) << "Group";
group->AddVarint(1, 0);
EXPECT_LT(base_size, empty_message.SpaceUsedLong());
shadow_vector_group.emplace_back();
EXPECT_EQ(total(), empty_message.SpaceUsedLong()) << "Group2";
unknown_fields->AddVarint(1, 0);
shadow_vector.emplace_back();
EXPECT_EQ(total(), empty_message.SpaceUsedLong()) << "Var2";
}

View File

@ -28,8 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef GOOGLE_PROTOBUF_UTIL_CONVERTER_EXPECTING_OBJECTWRITER_H__
#define GOOGLE_PROTOBUF_UTIL_CONVERTER_EXPECTING_OBJECTWRITER_H__
#ifndef GOOGLE_PROTOBUF_UTIL_INTERNAL_EXPECTING_OBJECTWRITER_H__
#define GOOGLE_PROTOBUF_UTIL_INTERNAL_EXPECTING_OBJECTWRITER_H__
// An implementation of ObjectWriter that automatically sets the
// gmock expectations for the response to a method. Every method
@ -53,9 +53,9 @@
#include <cstdint>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/util/internal/object_writer.h>
#include <gmock/gmock.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/util/internal/object_writer.h>
namespace google {
namespace protobuf {
@ -247,4 +247,4 @@ class ExpectingObjectWriter : public ObjectWriter {
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_EXPECTING_OBJECTWRITER_H__
#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_EXPECTING_OBJECTWRITER_H__

View File

@ -28,13 +28,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef GOOGLE_PROTOBUF_UTIL_CONVERTER_MOCK_ERROR_LISTENER_H__
#define GOOGLE_PROTOBUF_UTIL_CONVERTER_MOCK_ERROR_LISTENER_H__
#ifndef GOOGLE_PROTOBUF_UTIL_INTERNAL_MOCK_ERROR_LISTENER_H__
#define GOOGLE_PROTOBUF_UTIL_INTERNAL_MOCK_ERROR_LISTENER_H__
#include <google/protobuf/util/internal/error_listener.h>
#include <google/protobuf/util/internal/location_tracker.h>
#include <gmock/gmock.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/util/internal/error_listener.h>
#include <google/protobuf/util/internal/location_tracker.h>
namespace google {
namespace protobuf {
@ -65,4 +65,4 @@ class MockErrorListener : public ErrorListener {
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_MOCK_ERROR_LISTENER_H__
#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_MOCK_ERROR_LISTENER_H__

View File

@ -223,16 +223,16 @@ class PROTOBUF_EXPORT MessageDifferencer {
// itself and the second will be the actual field in the embedded message
// that was added/deleted/modified.
// Fields will be reported in PostTraversalOrder.
// For example, given following proto, if both baz and quux are changed.
// For example, given following proto, if both baz and mooo are changed.
// foo {
// bar {
// baz: 1
// quux: 2
// mooo: 2
// }
// }
// ReportModified will be invoked with following order:
// 1. foo.bar.baz or foo.bar.quux
// 2. foo.bar.quux or foo.bar.baz
// 1. foo.bar.baz or foo.bar.mooo
// 2. foo.bar.mooo or foo.bar.baz
// 2. foo.bar
// 3. foo
class PROTOBUF_EXPORT Reporter {

View File

@ -34,7 +34,6 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/test_util2.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
@ -48,6 +47,7 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/test_util2.h>
#include <google/protobuf/stubs/stl_util.h>
// clang-format off

View File

@ -405,7 +405,7 @@ size_t DoubleValue::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData DoubleValue::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
DoubleValue::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*DoubleValue::GetClassData() const { return &_class_data_; }
@ -598,7 +598,7 @@ size_t FloatValue::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData FloatValue::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
FloatValue::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FloatValue::GetClassData() const { return &_class_data_; }
@ -783,7 +783,7 @@ size_t Int64Value::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Int64Value::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Int64Value::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Int64Value::GetClassData() const { return &_class_data_; }
@ -964,7 +964,7 @@ size_t UInt64Value::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData UInt64Value::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
UInt64Value::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*UInt64Value::GetClassData() const { return &_class_data_; }
@ -1145,7 +1145,7 @@ size_t Int32Value::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData Int32Value::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
Int32Value::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Int32Value::GetClassData() const { return &_class_data_; }
@ -1326,7 +1326,7 @@ size_t UInt32Value::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData UInt32Value::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
UInt32Value::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*UInt32Value::GetClassData() const { return &_class_data_; }
@ -1507,7 +1507,7 @@ size_t BoolValue::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData BoolValue::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
BoolValue::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*BoolValue::GetClassData() const { return &_class_data_; }
@ -1708,7 +1708,7 @@ size_t StringValue::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData StringValue::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
StringValue::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*StringValue::GetClassData() const { return &_class_data_; }
@ -1909,7 +1909,7 @@ size_t BytesValue::ByteSizeLong() const {
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData BytesValue::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck,
BytesValue::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*BytesValue::GetClassData() const { return &_class_data_; }