Search in sources :

Example 6 with TypicalDataMessage

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());
}
Also used : TypicalDataMessage(protos.TypicalDataMessage) TypicalData(protos.TypicalData)

Example 7 with TypicalDataMessage

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);
}
Also used : TypicalDataMessage(protos.TypicalDataMessage) TypicalData(protos.TypicalData) Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) EnumDescriptor(com.google.protobuf.Descriptors.EnumDescriptor) EnumValueDescriptor(com.google.protobuf.Descriptors.EnumValueDescriptor) EnumValueDescriptor(com.google.protobuf.Descriptors.EnumValueDescriptor)

Example 8 with 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);
}
Also used : TypicalDataMessage(protos.TypicalDataMessage) TypicalData(protos.TypicalData) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ExtensionRegistry(com.google.protobuf.ExtensionRegistry)

Aggregations

TypicalDataMessage (protos.TypicalDataMessage)8 TypicalData (protos.TypicalData)5 EnumValueDescriptor (com.google.protobuf.Descriptors.EnumValueDescriptor)4 Descriptor (com.google.protobuf.Descriptors.Descriptor)3 EnumDescriptor (com.google.protobuf.Descriptors.EnumDescriptor)3 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)3 ByteString (com.google.protobuf.ByteString)2 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)2 ArrayList (java.util.ArrayList)2 AbstractMessage (com.google.protobuf.AbstractMessage)1 Message (com.google.protobuf.Message)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 List (java.util.List)1 MsgWithDefaultsOrBuilder (protos.MsgWithDefaultsOrBuilder)1 TypicalDataOrBuilder (protos.TypicalDataOrBuilder)1