Search in sources :

Example 31 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testSetAndGetInt.

public void testSetAndGetInt() throws Exception {
    TypicalData data = TypicalData.newBuilder().setMyInt(42).build();
    assertEquals(42, data.getMyInt());
}
Also used : TypicalData(protos.TypicalData)

Example 32 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class PerformanceBenchmarks method testGetPrimitiveFields.

private static void testGetPrimitiveFields() {
    TypicalData.Builder builder = TypicalData.newBuilder();
    setAllPrimitiveFields(builder);
    TypicalData data = builder.build();
    for (int i = 0; i < 100000; i++) {
        data.getMyInt();
        data.getMyBool();
        data.getMyFloat();
        data.getMyDouble();
        data.getMyUint();
        data.getMyLong();
        data.getMyUlong();
    }
}
Also used : TypicalData(protos.TypicalData)

Example 33 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class PerformanceBenchmarks method testWriteTo.

private static void testWriteTo() throws Exception {
    TypicalData.Builder builder = TypicalData.newBuilder();
    setAllPrimitiveFields(builder);
    setAllRepeatedFields(builder, 5);
    setMessageField(builder);
    TypicalData data = builder.build();
    for (int i = 0; i < 10000; i++) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        data.writeTo(out);
    }
}
Also used : TypicalData(protos.TypicalData) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 34 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testProtocolMessageEnum.

public void testProtocolMessageEnum() throws Exception {
    TypicalData data = TypicalData.newBuilder().setMyEnumType(TypicalData.EnumType.VALUE1).build();
    ProtocolMessageEnum type = data.getMyEnumType();
    assertEquals(1, type.getNumber());
    // Test casting to ProtocolMessageEnum.
    Object value = TypicalData.EnumType.VALUE2;
    type = (ProtocolMessageEnum) value;
}
Also used : TypicalData(protos.TypicalData) ProtocolMessageEnum(com.google.protobuf.ProtocolMessageEnum)

Example 35 with TypicalData

use of protos.TypicalData 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)

Aggregations

TypicalData (protos.TypicalData)39 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 TypicalDataMessage (protos.TypicalDataMessage)5 ByteString (com.google.protobuf.ByteString)3 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3 ArrayList (java.util.ArrayList)3 MessageLite (com.google.protobuf.MessageLite)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Descriptor (com.google.protobuf.Descriptors.Descriptor)1 EnumDescriptor (com.google.protobuf.Descriptors.EnumDescriptor)1 EnumValueDescriptor (com.google.protobuf.Descriptors.EnumValueDescriptor)1 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)1 ExtensionRegistryLite (com.google.protobuf.ExtensionRegistryLite)1 GeneratedMessage (com.google.protobuf.GeneratedMessage)1 ExtendableMessageOrBuilder (com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder)1 Message (com.google.protobuf.Message)1 ProtocolMessageEnum (com.google.protobuf.ProtocolMessageEnum)1