Search in sources :

Example 6 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testSetAndGetRepeatedInt32.

public void testSetAndGetRepeatedInt32() throws Exception {
    List<Integer> list = new ArrayList<Integer>();
    list.add(34);
    list.add(56);
    TypicalData data = TypicalData.newBuilder().addRepeatedInt32(12).addAllRepeatedInt32(list).setRepeatedInt32(2, 67).build();
    assertEquals(3, data.getRepeatedInt32Count());
    assertEquals(12, data.getRepeatedInt32(0));
    byte[] bytes = data.toByteArray();
    TypicalData other = TypicalData.parseFrom(bytes);
    assertEquals(12, other.getRepeatedInt32(0));
    // compareTo will fail in objc if the returned type is not JavaLangInteger.
    assertEquals(0, other.getRepeatedInt32List().get(1).compareTo(34));
    assertEquals(67, other.getRepeatedInt32(2));
}
Also used : TypicalData(protos.TypicalData) ArrayList(java.util.ArrayList)

Example 7 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testMergeFromLargeProto.

public void testMergeFromLargeProto() throws Exception {
    TypicalData.Builder builder1 = TypicalData.newBuilder();
    TypicalData.Builder builder2 = TypicalData.newBuilder();
    TypicalData.Builder builder3 = TypicalData.newBuilder();
    InputStream in = getTestData("largeproto");
    try {
        assertTrue(builder1.mergeDelimitedFrom(in));
        assertTrue(builder2.mergeDelimitedFrom(in));
        assertTrue(builder3.mergeDelimitedFrom(in));
    } finally {
        in.close();
    }
    TypicalData data1 = builder1.build();
    TypicalData data2 = builder2.build();
    TypicalData data3 = builder3.build();
    assertEquals(0, data1.getRepeatedInt32(0));
    assertEquals(999, data1.getRepeatedInt32(999));
    assertEquals(1000, data2.getRepeatedInt32(0));
    assertEquals(1999, data2.getRepeatedInt32(999));
    assertEquals(2000, data3.getRepeatedInt32(0));
    assertEquals(2999, data3.getRepeatedInt32(999));
}
Also used : TypicalData(protos.TypicalData) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream)

Example 8 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testSetAndGetRepeatedString.

public void testSetAndGetRepeatedString() throws Exception {
    TypicalData data = TypicalData.newBuilder().addRepeatedString("coin").build();
    assertEquals(1, data.getRepeatedStringCount());
    assertEquals("coin", data.getRepeatedString(0));
    List<String> list = data.getRepeatedStringList();
    assertEquals(1, list.size());
}
Also used : TypicalData(protos.TypicalData) ByteString(com.google.protobuf.ByteString)

Example 9 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testSetAndGetRepeatedUint64.

public void testSetAndGetRepeatedUint64() throws Exception {
    TypicalData data = TypicalData.newBuilder().addRepeatedUint64(123).build();
    assertEquals(1, data.getRepeatedUint64Count());
    assertEquals(123, data.getRepeatedUint64(0));
}
Also used : TypicalData(protos.TypicalData)

Example 10 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testSetAndGetByteString.

public void testSetAndGetByteString() throws Exception {
    ByteString bstr = ByteString.copyFrom("foo".getBytes());
    TypicalData data = TypicalData.newBuilder().setMyBytes(bstr).build();
    assertEquals("foo", new String(data.getMyBytes().toByteArray()));
}
Also used : TypicalData(protos.TypicalData) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString)

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