Search in sources :

Example 11 with AllTypes

use of com.squareup.wire.protos.alltypes.AllTypes in project wire by square.

the class TestAllTypes method testReadStream.

@Test
public void testReadStream() throws IOException {
    byte[] data = adapter.encode(allTypes);
    InputStream stream = new ByteArrayInputStream(data);
    AllTypes parsed = adapter.decode(stream);
    assertThat(parsed).isEqualTo(allTypes);
    assertThat(allTypes.ext_opt_bool).isEqualTo(Boolean.TRUE);
    assertThat(allTypes.ext_rep_bool).isEqualTo(list(true));
    assertThat(allTypes.ext_pack_bool).isEqualTo(list(true));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AllTypes(com.squareup.wire.protos.alltypes.AllTypes) Test(org.junit.Test)

Example 12 with AllTypes

use of com.squareup.wire.protos.alltypes.AllTypes in project wire by square.

the class TestAllTypes method testHashCodes.

@Test
public void testHashCodes() {
    AllTypes.Builder builder = getBuilder();
    AllTypes message = builder.build();
    int messageHashCode = message.hashCode();
    assertThat(messageHashCode).isEqualTo(allTypes.hashCode());
}
Also used : AllTypes(com.squareup.wire.protos.alltypes.AllTypes) Test(org.junit.Test)

Example 13 with AllTypes

use of com.squareup.wire.protos.alltypes.AllTypes in project wire by square.

the class TestAllTypes method testReadNoExtension.

@Test
public void testReadNoExtension() throws IOException {
    byte[] data = adapter.encode(allTypes);
    AllTypes parsed = AllTypes.ADAPTER.decode(data);
    assertThat(allTypes).isEqualTo(parsed);
}
Also used : AllTypes(com.squareup.wire.protos.alltypes.AllTypes) Test(org.junit.Test)

Example 14 with AllTypes

use of com.squareup.wire.protos.alltypes.AllTypes in project wire by square.

the class GsonTest method omitsUnknownFields.

@Test
public void omitsUnknownFields() {
    AllTypes.Builder builder = createBuilder();
    builder.addUnknownField(9000, FieldEncoding.FIXED32, 9000);
    builder.addUnknownField(9001, FieldEncoding.FIXED64, 9001L);
    builder.addUnknownField(9002, FieldEncoding.LENGTH_DELIMITED, ByteString.of((byte) '9', (byte) '0', (byte) '0', (byte) '2'));
    builder.addUnknownField(9003, FieldEncoding.VARINT, 9003L);
    AllTypes allTypes = builder.build();
    String json = gson.toJson(allTypes);
    assertThat(json).isEqualTo(JSON);
}
Also used : AllTypes(com.squareup.wire.protos.alltypes.AllTypes) ByteString(okio.ByteString) Test(org.junit.Test)

Aggregations

AllTypes (com.squareup.wire.protos.alltypes.AllTypes)14 Test (org.junit.Test)14 Buffer (okio.Buffer)3 ByteString (okio.ByteString)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ForwardingSource (okio.ForwardingSource)1 Source (okio.Source)1