use of protos.TypicalDataMessage in project j2objc by google.
the class CompatibilityTest method testToBuilder.
public void testToBuilder() throws Exception {
TypicalData data = TypicalData.newBuilder().setMyInt(42).setMyMessage(TypicalDataMessage.newBuilder().setMyMessageInt(43)).build();
TypicalData.Builder builder = data.toBuilder();
TypicalDataMessage message = builder.getMyMessage();
assertNotNull(message);
assertEquals(43, message.getMyMessageInt());
}
use of protos.TypicalDataMessage in project j2objc by google.
the class CompatibilityTest method testGetUnsetField.
public void testGetUnsetField() throws Exception {
TypicalData data = TypicalData.newBuilder().build();
Descriptor descriptor = TypicalData.getDescriptor();
assertEquals(0, data.getField(descriptor.findFieldByNumber(1)));
Object result = data.getField(descriptor.findFieldByNumber(3));
assertTrue(result instanceof EnumValueDescriptor);
assertEquals(TypicalData.EnumType.VALUE1.getValueDescriptor().getNumber(), ((EnumValueDescriptor) result).getNumber());
assertTrue(data.getField(descriptor.findFieldByNumber(11)) instanceof TypicalDataMessage);
}
use of protos.TypicalDataMessage 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.copyFromUtf8("abc")).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);
}
Aggregations