Search in sources :

Example 1 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testExtendableMessageOrBuilder.

public void testExtendableMessageOrBuilder() throws Exception {
    TypicalData.Builder builder = TypicalData.newBuilder().setMyInt(42);
    TypicalData data = builder.build();
    Object o = builder;
    ExtendableMessageOrBuilder emob = (ExtendableMessageOrBuilder) o;
    o = data;
    emob = (ExtendableMessageOrBuilder) o;
}
Also used : TypicalData(protos.TypicalData) ExtendableMessageOrBuilder(com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder)

Example 2 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testParseFromInvalidProtocolBufferException.

public void testParseFromInvalidProtocolBufferException() throws Exception {
    try {
        @SuppressWarnings("unused") TypicalData output = TypicalData.parseFrom(new byte[] { 0x08 });
        fail("Expected InvalidProtocolBufferException to be thrown.");
    } catch (InvalidProtocolBufferException e) {
    // Expected
    }
}
Also used : TypicalData(protos.TypicalData) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

Example 3 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testWriteDelimitedToOutputStream.

public void testWriteDelimitedToOutputStream() throws Exception {
    TypicalData data = TypicalData.newBuilder().setMyInt(7).setMyBool(true).setMyString("foo").build();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    data.writeDelimitedTo(out);
    byte[] bytes = out.toByteArray();
    byte[] expected = new byte[] { 0x09, 0x08, 0x07, 0x60, 0x01, 0x7A, 0x03, 0x66, 0x6F, 0x6F };
    checkBytes(expected, bytes);
}
Also used : TypicalData(protos.TypicalData) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 4 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testSetAndGetRepeatedFloat.

public void testSetAndGetRepeatedFloat() throws Exception {
    TypicalData data = TypicalData.newBuilder().addRepeatedFloat(0.5f).build();
    assertEquals(1, data.getRepeatedFloatCount());
    assertEquals(0.5f, data.getRepeatedFloat(0), 0.0001);
}
Also used : TypicalData(protos.TypicalData)

Example 5 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testMessageLiteToBuilderAndMergeFrom.

public void testMessageLiteToBuilderAndMergeFrom() throws Exception {
    TypicalData input = TypicalData.newBuilder().setMyInt(123).build();
    MessageLite msg = TypicalData.getDefaultInstance();
    // mergeFrom(byte[], ExtensionRegistryLite)
    MessageLite.Builder builder = msg.toBuilder();
    builder.mergeFrom(input.toByteString().toByteArray(), ExtensionRegistry.getEmptyRegistry());
    assertEquals(123, ((TypicalData) builder.build()).getMyInt());
    // mergeFrom(byte[])
    builder = msg.toBuilder();
    builder.mergeFrom(input.toByteString().toByteArray());
    assertEquals(123, ((TypicalData) builder.build()).getMyInt());
    // mergeFrom(ByteString, ExtensionRegistryLite)
    builder = msg.toBuilder();
    builder.mergeFrom(input.toByteString(), ExtensionRegistry.getEmptyRegistry());
    assertEquals(123, ((TypicalData) builder.build()).getMyInt());
    // mergeFrom(ByteString)
    builder = msg.toBuilder();
    builder.mergeFrom(input.toByteString());
    assertEquals(123, ((TypicalData) builder.build()).getMyInt());
}
Also used : TypicalData(protos.TypicalData) MessageLite(com.google.protobuf.MessageLite)

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