Search in sources :

Example 11 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testIOExceptionFromOutputStream.

public void testIOExceptionFromOutputStream() throws Exception {
    // The issue being tested requires a proto that is larger than the CodedOutputStream buffer
    // size.
    TypicalData data;
    try (InputStream in = getTestData("largeproto")) {
        data = TypicalData.parseDelimitedFrom(in);
    }
    OutputStream out = new OutputStream() {

        @Override
        public void write(int b) throws IOException {
            throw new IOException("test exception");
        }
    };
    try {
        data.writeTo(out);
        fail("Expected IOException to be thrown.");
    } catch (IOException e) {
    // Expected
    }
}
Also used : TypicalData(protos.TypicalData) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 12 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testMutatingBuilderDoesntMutateMessage.

public void testMutatingBuilderDoesntMutateMessage() throws Exception {
    TypicalData.Builder builder = TypicalData.newBuilder();
    TypicalData data = builder.build();
    builder.setMyInt(23);
    assertEquals(0, data.getMyInt());
    builder = data.toBuilder();
    builder.setMyInt(45);
    assertEquals(0, data.getMyInt());
}
Also used : TypicalData(protos.TypicalData)

Example 13 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testWriteToOutputStream.

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

Example 14 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testNewBuilderWithPrototype.

public void testNewBuilderWithPrototype() throws Exception {
    TypicalData data = TypicalData.newBuilder().setMyInt(123).build();
    TypicalData.Builder builder = TypicalData.newBuilder(data);
    assertEquals(123, builder.getMyInt());
}
Also used : TypicalData(protos.TypicalData)

Example 15 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testSetAndGetRepeatedInt64.

public void testSetAndGetRepeatedInt64() throws Exception {
    TypicalData data = TypicalData.newBuilder().addRepeatedInt64(123).build();
    assertEquals(1, data.getRepeatedInt64Count());
    assertEquals(123, data.getRepeatedInt64(0));
}
Also used : TypicalData(protos.TypicalData)

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