use of com.google.protobuf.ExtensionRegistry in project j2objc by google.
the class CompatibilityTest method testSetAndGetExtensions.
public void testSetAndGetExtensions() throws Exception {
TypicalDataMessage extensionMessage = TypicalDataMessage.newBuilder().setMyMessageInt(321).build();
List<Integer> repeatedInts = new ArrayList<Integer>();
repeatedInts.add(1);
repeatedInts.add(2);
List<TypicalDataMessage> repeatedData = new ArrayList<TypicalDataMessage>();
repeatedData.add(TypicalDataMessage.newBuilder().setMyMessageInt(432).build());
repeatedData.add(TypicalDataMessage.newBuilder().setMyMessageInt(543).build());
TypicalData.Builder dataBuilder = TypicalData.newBuilder().setExtension(Typical.myPrimitiveExtension, 123).setExtension(Typical.myExtension, extensionMessage).setExtension(Typical.myRepeatedPrimitiveExtension, repeatedInts).addExtension(Typical.myRepeatedPrimitiveExtension, 3).setExtension(Typical.myRepeatedExtension, repeatedData).setExtension(Typical.myEnumExtension, TypicalData.EnumType.VALUE1).setExtension(Typical.myBytesExtension, ByteString.copyFrom("abc".getBytes())).setExtension(Typical.myBoolExtension, Boolean.TRUE).setExtension(MsgWithNestedExtensions.intExt, 456);
checkGetExtensions(dataBuilder);
checkGetExtensions(dataBuilder.build());
ByteArrayOutputStream out = new ByteArrayOutputStream();
dataBuilder.build().writeTo(out);
byte[] msgBytes = asBytes(new int[] { 0xC2, 0x3E, 0x03, 0x08, 0xC1, 0x02, 0xC8, 0x3E, 0x7B, 0xD0, 0x3E, 0x01, 0xD0, 0x3E, 0x02, 0xD0, 0x3E, 0x03, 0xDA, 0x3E, 0x03, 0x08, 0xB0, 0x03, 0xDA, 0x3E, 0x03, 0x08, 0x9F, 0x04, 0xE0, 0x3E, 0x01, 0xEA, 0x3E, 0x03, 0x61, 0x62, 0x63, 0xF0, 0x3E, 0x01, 0x80, 0x7D, 0xC8, 0x03 });
checkBytes(msgBytes, out.toByteArray());
ExtensionRegistry registry = ExtensionRegistry.newInstance();
Typical.registerAllExtensions(registry);
ByteArrayInputStream in = new ByteArrayInputStream(msgBytes);
TypicalData data = TypicalData.newBuilder().mergeFrom(in, registry).build();
checkGetExtensions(data);
}
use of com.google.protobuf.ExtensionRegistry in project j2objc by google.
the class PrimitivesTest method testParseFromByteArray.
public void testParseFromByteArray() throws Exception {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
Primitives.registerAllExtensions(registry);
PrimitiveFields msg = PrimitiveFields.parseFrom(ALL_PRIMITIVES_BYTES, registry);
checkFields(msg);
}
use of com.google.protobuf.ExtensionRegistry in project j2objc by google.
the class StringsTest method testMergeFromInputStream.
public void testMergeFromInputStream() throws Exception {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
StringFields.registerAllExtensions(registry);
ByteArrayInputStream in = new ByteArrayInputStream(ALL_STRINGS_BYTES);
StringMsg.Builder builder = StringMsg.newBuilder().mergeFrom(in, registry);
StringMsg msg = builder.build();
checkFields(builder);
checkFields(msg);
}
use of com.google.protobuf.ExtensionRegistry in project j2objc by google.
the class CompatibilityTest method testExtensionRegistryGetUnmodifiable.
public void testExtensionRegistryGetUnmodifiable() throws Exception {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
ExtensionRegistry registry2 = registry.getUnmodifiable();
registry.add(Typical.myPrimitiveExtension);
// Extension added to registry should be visible in registry2.
Descriptor descriptor = TypicalData.getDescriptor();
ExtensionRegistry.ExtensionInfo extensionInfo = registry2.findExtensionByNumber(descriptor, 1001);
assertNotNull(extensionInfo);
ExtensionRegistryLite registryLite = ExtensionRegistryLite.newInstance();
ExtensionRegistryLite registryLite2 = registryLite.getUnmodifiable();
assertNotNull(registryLite2);
}
use of com.google.protobuf.ExtensionRegistry in project j2objc by google.
the class EnumsTest method testBadEnumValue.
// TODO(kstanger): This fails with native ObjC because it doesn't sign-extend
// when writing the negative enum value.
/*public void testSerialization() throws Exception {
EnumMsg msg = getFilledMessage();
assertEquals(71, msg.getSerializedSize());
byte[] bytes1 = msg.toByteArray();
checkBytes(ALL_ENUMS_BYTES, bytes1);
ByteArrayOutputStream out = new ByteArrayOutputStream();
msg.writeTo(out);
byte[] bytes2 = out.toByteArray();
checkBytes(ALL_ENUMS_BYTES, bytes2);
}*/
// Tests that unknown enum values are skipped and don't cause a
// InvalidProtocolBufferException.
public void testBadEnumValue() throws Exception {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
EnumFields.registerAllExtensions(registry);
byte[] bytes = asBytes(new int[] { 0x08, 0x09, 0xA8, 0x01, 0x09, 0xCA, 0x02, 0x01, 0x09, 0xC8, 0x3E, 0x09, 0xE8, 0x3F, 0x09, 0x8A, 0x41, 0x01, 0x09 });
EnumMsg msg = EnumMsg.parseFrom(bytes, registry);
assertFalse(msg.hasEnumF());
assertEquals(0, msg.getEnumRCount());
assertEquals(0, msg.getEnumPCount());
// TODO(kstanger): Native ObjC behavior differs from Java behavior here.
//assertFalse(msg.hasExtension(EnumFields.enumFe));
//assertEquals(0, msg.getExtensionCount(EnumFields.enumRe));
//assertEquals(0, msg.getExtensionCount(EnumFields.enumPe));
}
Aggregations