ADD: added new version of protobuf

This commit is contained in:
Henry Winkel
2022-12-20 10:09:28 +01:00
parent 4a79559129
commit 1e2b3dda7b
1513 changed files with 123720 additions and 83381 deletions

View File

@@ -61,7 +61,6 @@ import protobuf_unittest.UnittestProto.TestExtremeDefaultValues;
import protobuf_unittest.UnittestProto.TestJsonName;
import protobuf_unittest.UnittestProto.TestMultipleExtensionRanges;
import protobuf_unittest.UnittestProto.TestRequired;
import protobuf_unittest.UnittestProto.TestReservedEnumFields;
import protobuf_unittest.UnittestProto.TestReservedFields;
import protobuf_unittest.UnittestProto.TestService;
import java.util.Collections;
@@ -464,15 +463,15 @@ public class DescriptorsTest {
/** Tests that parsing an unknown enum throws an exception */
@Test
public void testParseUnknownEnum() {
FieldDescriptorProto.Builder field =
FieldDescriptorProto.newBuilder()
.setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
.setTypeName("UnknownEnum")
.setType(FieldDescriptorProto.Type.TYPE_ENUM)
.setName("bar")
.setNumber(1);
DescriptorProto.Builder messageType =
DescriptorProto.newBuilder().setName("Foo").addField(field);
FieldDescriptorProto.Builder field = FieldDescriptorProto.newBuilder()
.setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
.setTypeName("UnknownEnum")
.setType(FieldDescriptorProto.Type.TYPE_ENUM)
.setName("bar")
.setNumber(1);
DescriptorProto.Builder messageType = DescriptorProto.newBuilder()
.setName("Foo")
.addField(field);
FileDescriptorProto fooProto =
FileDescriptorProto.newBuilder()
.setName("foo.proto")
@@ -487,6 +486,7 @@ public class DescriptorsTest {
}
}
/**
* Tests the translate/crosslink for an example where a message field's name and type name are the
* same.
@@ -560,10 +560,8 @@ public class DescriptorsTest {
Descriptors.FileDescriptor.buildFrom(barProto, new FileDescriptor[] {fooFile});
// Items in the FileDescriptor array can be in any order.
FileDescriptor unused1 =
Descriptors.FileDescriptor.buildFrom(bazProto, new FileDescriptor[] {fooFile, barFile});
FileDescriptor unused2 =
Descriptors.FileDescriptor.buildFrom(bazProto, new FileDescriptor[] {barFile, fooFile});
Descriptors.FileDescriptor.buildFrom(bazProto, new FileDescriptor[] {fooFile, barFile});
Descriptors.FileDescriptor.buildFrom(bazProto, new FileDescriptor[] {barFile, fooFile});
}
@Test
@@ -625,8 +623,7 @@ public class DescriptorsTest {
.setName("bar")
.setNumber(1)))
.build();
FileDescriptor unused =
Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[0], true);
Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[0], true);
}
@Test
@@ -660,8 +657,7 @@ public class DescriptorsTest {
Descriptors.FileDescriptor.buildFrom(forwardProto, new FileDescriptor[] {barFile});
try {
FileDescriptor unused =
Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[] {forwardFile});
Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[] {forwardFile});
assertWithMessage("DescriptorValidationException expected").fail();
} catch (DescriptorValidationException e) {
assertThat(e).hasMessageThat().contains("Bar");
@@ -699,8 +695,7 @@ public class DescriptorsTest {
FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(barProto, new FileDescriptor[0]);
FileDescriptor forwardFile =
Descriptors.FileDescriptor.buildFrom(forwardProto, new FileDescriptor[] {barFile});
FileDescriptor unused =
Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[] {forwardFile});
Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[] {forwardFile});
}
/** Tests the translate/crosslink for an example with a more complex namespace referencing. */
@@ -797,20 +792,6 @@ public class DescriptorsTest {
assertThat(d.isReservedName("baz")).isTrue();
}
@Test
public void testReservedEnumFields() {
EnumDescriptor d = TestReservedEnumFields.getDescriptor();
assertThat(d.isReservedNumber(2)).isTrue();
assertThat(d.isReservedNumber(8)).isFalse();
assertThat(d.isReservedNumber(9)).isTrue();
assertThat(d.isReservedNumber(10)).isTrue();
assertThat(d.isReservedNumber(11)).isTrue();
assertThat(d.isReservedNumber(12)).isFalse();
assertThat(d.isReservedName("foo")).isFalse();
assertThat(d.isReservedName("bar")).isTrue();
assertThat(d.isReservedName("baz")).isTrue();
}
@Test
public void testToString() {
assertThat(
@@ -845,8 +826,7 @@ public class DescriptorsTest {
.build())
.build())
.build();
FileDescriptor unused =
Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, new FileDescriptor[0]);
Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, new FileDescriptor[0]);
}
@Test

View File

@@ -44,7 +44,6 @@ import protobuf_unittest.UnittestProto.TestAllTypes;
import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage;
import protobuf_unittest.UnittestProto.TestEmptyMessage;
import protobuf_unittest.UnittestProto.TestPackedTypes;
import java.util.ArrayList;
import org.junit.Test;
import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
@@ -231,19 +230,6 @@ public class DynamicMessageTest {
assertThat(rawBytes).isEqualTo(TestUtil.getPackedSet().toByteString());
}
@Test
public void testDynamicMessagePackedEmptySerialization() throws Exception {
Message message =
DynamicMessage.newBuilder(TestPackedTypes.getDescriptor())
.setField(
TestPackedTypes.getDescriptor()
.findFieldByNumber(TestPackedTypes.PACKED_INT64_FIELD_NUMBER),
new ArrayList<Long>())
.build();
assertThat(message.toByteString()).isEqualTo(ByteString.EMPTY);
}
@Test
public void testDynamicMessagePackedParsing() throws Exception {
TestPackedTypes.Builder builder = TestPackedTypes.newBuilder();

View File

@@ -1529,7 +1529,7 @@ public class GeneratedMessageTest {
assertThat(builder.getFooInt()).isEqualTo(123);
TestOneof2 message = builder.buildPartial();
assertThat(message.hasFooInt()).isTrue();
assertThat(message.getFooInt()).isEqualTo(123);
assertThat(123).isEqualTo(message.getFooInt());
assertThat(builder.clearFooInt().hasFooInt()).isFalse();
TestOneof2 message2 = builder.build();
@@ -1943,7 +1943,7 @@ public class GeneratedMessageTest {
@Test
public void
extendableBuilder_extensionFieldContainingBuilder_setRepeatedFieldOverwritesElement() {
extendableBuilder_extensionFieldContainingBuilder_setRepeatedFieldOverwritesElement() {
TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
builder.addRepeatedField(REPEATED_NESTED_MESSAGE_EXTENSION, NestedMessage.getDefaultInstance());
// Calling getRepeatedFieldBuilder and ignoring the returned Builder should have no

View File

@@ -30,13 +30,14 @@
package com.google.protobuf;
import junit.framework.TestCase;
import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.Bar;
import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.BarPrime;
import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.Foo;
import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.TestOneofEquals;
import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.TestRecursiveOneof;
import junit.framework.TestCase;
/**
* Test generate equal and hash methods for the lite runtime.
*
@@ -119,6 +120,6 @@ public class LiteEqualsAndHashTest extends TestCase {
public void testRecursiveHashcode() {
// This tests that we don't infinite loop.
int unused = TestRecursiveOneof.getDefaultInstance().hashCode();
TestRecursiveOneof.getDefaultInstance().hashCode();
}
}

View File

@@ -33,6 +33,7 @@ package com.google.protobuf;
import static com.google.common.truth.Truth.assertThat;
import protobuf_unittest.Engine;
import protobuf_unittest.TimingBelt;
import protobuf_unittest.Vehicle;
import protobuf_unittest.Wheel;
import java.util.ArrayList;
@@ -48,6 +49,27 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class NestedBuildersTest {
@Test
public void test3LayerPropagationWithIntermediateClear() {
Vehicle.Builder vehicleBuilder = Vehicle.newBuilder();
vehicleBuilder.getEngineBuilder().getTimingBeltBuilder();
// This step detaches the TimingBelt.Builder (though it leaves a SingleFieldBuilder in place)
vehicleBuilder.getEngineBuilder().clear();
// These steps build the middle and top level messages, it used to leave the vestigial
// TimingBelt.Builder in a state where further changes didn't propagate anymore
Object unused = vehicleBuilder.getEngineBuilder().build();
unused = vehicleBuilder.build();
TimingBelt expected = TimingBelt.newBuilder().setNumberOfTeeth(124).build();
vehicleBuilder.getEngineBuilder().setTimingBelt(expected);
// Testing that b/254158939 is fixed. It used to be that the setTimingBelt call above didn't
// propagate a change notification and the call below would return a stale version of the timing
// belt.
assertThat(vehicleBuilder.getEngine().getTimingBelt()).isEqualTo(expected);
}
@Test
public void testMessagesAndBuilders() {
Vehicle.Builder vehicleBuilder = Vehicle.newBuilder();

View File

@@ -82,7 +82,7 @@ public class SingleFieldBuilderV3Test {
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
assertThat(builder.getBuilder().getOptionalInt32()).isEqualTo(1);
assertThat(builder.getMessage().getOptionalInt32()).isEqualTo(1);
TestAllTypes unused = builder.build();
builder.build();
builder.getBuilder().setOptionalInt32(2);
assertThat(builder.getBuilder().getOptionalInt32()).isEqualTo(2);
assertThat(builder.getMessage().getOptionalInt32()).isEqualTo(2);

View File

@@ -34,7 +34,6 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static java.lang.Math.min;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -49,6 +48,52 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class SmallSortedMapTest {
// java.util.AbstractMap.SimpleEntry is private in JDK 1.5. We re-implement it
// here for JDK 1.5 users.
private static class SimpleEntry<K, V> implements Map.Entry<K, V> {
private final K key;
private V value;
SimpleEntry(K key, V value) {
this.key = key;
this.value = value;
}
@Override
public K getKey() {
return key;
}
@Override
public V getValue() {
return value;
}
@Override
public V setValue(V value) {
V oldValue = this.value;
this.value = value;
return oldValue;
}
private static boolean eq(Object o1, Object o2) {
return o1 == null ? o2 == null : o1.equals(o2);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Map.Entry)) {
return false;
}
Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
return eq(key, e.getKey()) && eq(value, e.getValue());
}
@Override
public int hashCode() {
return ((key == null) ? 0 : key.hashCode()) ^ ((value == null) ? 0 : value.hashCode());
}
}
@Test
public void testPutAndGetArrayEntriesOnly() {
@@ -197,8 +242,8 @@ public class SmallSortedMapTest {
}
Set<Map.Entry<Integer, Integer>> entrySet = map.entrySet();
for (int i = 0; i < 6; i++) {
assertThat(entrySet).contains(new AbstractMap.SimpleEntry<Integer, Integer>(i, i + 1));
assertThat(entrySet).doesNotContain(new AbstractMap.SimpleEntry<Integer, Integer>(i, i));
assertThat(entrySet).contains(new SimpleEntry<Integer, Integer>(i, i + 1));
assertThat(entrySet).doesNotContain(new SimpleEntry<Integer, Integer>(i, i));
}
}
@@ -207,7 +252,7 @@ public class SmallSortedMapTest {
SmallSortedMap<Integer, Integer> map = SmallSortedMap.newInstanceForTest(3);
Set<Map.Entry<Integer, Integer>> entrySet = map.entrySet();
for (int i = 0; i < 6; i++) {
Map.Entry<Integer, Integer> entry = new AbstractMap.SimpleEntry<>(i, i + 1);
Map.Entry<Integer, Integer> entry = new SimpleEntry<>(i, i + 1);
assertThat(entrySet.add(entry)).isTrue();
assertThat(entrySet.add(entry)).isFalse();
}
@@ -227,7 +272,7 @@ public class SmallSortedMapTest {
assertThat(map.put(i, i + 1)).isNull();
}
for (int i = 0; i < 6; i++) {
Map.Entry<Integer, Integer> entry = new AbstractMap.SimpleEntry<>(i, i + 1);
Map.Entry<Integer, Integer> entry = new SimpleEntry<>(i, i + 1);
assertThat(entrySet.remove(entry)).isTrue();
assertThat(entrySet.remove(entry)).isFalse();
}

View File

@@ -49,7 +49,7 @@ public class TestBadIdentifiers extends TestCase {
TestBadIdentifiersProto.Override.getDefaultInstance();
}
@SuppressWarnings({"IgnoredPureGetter", "CheckReturnValue"}) // TODO(b/221602772): Fix this
@SuppressWarnings("IgnoredPureGetter") // TODO(b/221602772): Fix this
public void testGetDescriptor() {
TestBadIdentifiersProto.getDescriptor();
TestBadIdentifiersProto.Descriptor.getDefaultInstance().getDescriptor();

View File

@@ -235,7 +235,6 @@ import protobuf_unittest.UnittestProto.TestRequired;
import protobuf_unittest.UnittestProto.TestUnpackedTypes;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Collections;
@@ -3843,11 +3842,7 @@ public final class TestUtil {
private static ByteString readBytesFromResource(String name) {
try {
InputStream in = TestUtil.class.getResourceAsStream(name);
if (in == null) { //
throw new RuntimeException("Tests data file " + name + " is missing.");
}
return ByteString.readFrom(in);
return ByteString.readFrom(TestUtil.class.getResourceAsStream(name));
} catch (IOException e) {
throw new RuntimeException(e);
}

View File

@@ -67,7 +67,9 @@ import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Test case for {@link TextFormat}. */
/**
* Test case for {@link TextFormat}.
*/
@RunWith(JUnit4.class)
public class TextFormatTest {
@@ -823,7 +825,6 @@ public class TextFormatTest {
}
}
@CanIgnoreReturnValue
private TestAllTypes assertParseSuccessWithOverwriteForbidden(String text)
throws TextFormat.ParseException {
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
@@ -1449,18 +1450,6 @@ public class TextFormatTest {
+ "unknown_field3: 3\n");
}
@Test
public void testParseUnknownExtensionWithAnyMessage() throws Exception {
assertParseSuccessWithUnknownExtensions(
"[unknown_extension]: { "
+ " any_value { "
+ " [type.googleapis.com/protobuf_unittest.OneString] { "
+ " data: 123 "
+ " } "
+ " } "
+ "}");
}
// See additional coverage in testOneofOverwriteForbidden and testMapOverwriteForbidden.
@Test
public void testParseNonRepeatedFields() throws Exception {
@@ -1773,7 +1762,6 @@ public class TextFormatTest {
}
}
@SuppressWarnings("LenientFormatStringValidation")
private void assertLocation(
TextFormatParseInfoTree tree,
final Descriptor descriptor,
@@ -1787,7 +1775,6 @@ public class TextFormatTest {
TextFormatParseLocation expected = TextFormatParseLocation.create(line, column);
assertThat(location).isEqualTo(expected);
} else if (line != -1 && column != -1) {
// Expected 0 args, but got 3.
assertWithMessage(
"Tree/descriptor/fieldname did not contain index %d, line %d column %d expected",
index, line, column)

View File

@@ -31,10 +31,7 @@
syntax = "proto2";
package map_for_proto2_lite_test;
option java_outer_classname = "MapForProto2TestProto";
option optimize_for = LITE_RUNTIME;
option java_package = "map_lite_test";
message TestMap {
message MessageValue {
@@ -128,3 +125,6 @@ message ReservedAsMapFieldWithEnumValue {
// null is not a 'reserved word' per se but as a literal needs similar care
map<string, SampleEnum> null = 10;
}
package map_for_proto2_lite_test;
option java_package = "map_lite_test";
option optimize_for = LITE_RUNTIME;

View File

@@ -45,6 +45,11 @@ message Vehicle {
message Engine {
optional int32 cylinder = 1;
optional int32 liters = 2;
optional TimingBelt timing_belt = 3;
}
message TimingBelt {
optional int32 number_of_teeth = 1;
}
message Wheel {

View File

@@ -36,6 +36,7 @@ package protobuf.experimental;
option java_package = "com.google.protobuf.testing";
option java_outer_classname = "Proto2Testing";
message Proto2SpecialFieldName {
optional double regular_name = 1;
optional int32 cached_size = 2;

View File

@@ -36,6 +36,7 @@ package protobuf.experimental.lite;
option java_package = "com.google.protobuf.testing";
option java_outer_classname = "Proto2TestingLite";
message Proto2MessageLite {
enum TestEnum {