Search in sources :

Example 1 with StringMsg

use of protos.StringMsg in project j2objc by google.

the class StringsTest method testSerialization.

public void testSerialization() throws Exception {
    StringMsg msg = getFilledMessage();
    assertEquals(171, msg.getSerializedSize());
    byte[] bytes1 = msg.toByteArray();
    checkBytes(ALL_STRINGS_BYTES, bytes1);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    msg.writeTo(out);
    byte[] bytes2 = out.toByteArray();
    checkBytes(ALL_STRINGS_BYTES, bytes2);
}
Also used : StringMsg(protos.StringMsg) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with StringMsg

use of protos.StringMsg in project j2objc by google.

the class StringsTest method testMergeFromOtherMessage.

public void testMergeFromOtherMessage() throws Exception {
    StringMsg filledMsg = getFilledMessage();
    StringMsg.Builder builder = StringMsg.newBuilder();
    builder.mergeFrom(filledMsg);
    StringMsg msg = builder.build();
    checkFields(builder);
    checkFields(msg);
}
Also used : StringMsg(protos.StringMsg)

Example 3 with StringMsg

use of protos.StringMsg in project j2objc by google.

the class StringsTest method testParseFromByteArray.

public void testParseFromByteArray() throws Exception {
    ExtensionRegistry registry = ExtensionRegistry.newInstance();
    StringFields.registerAllExtensions(registry);
    StringMsg msg = StringMsg.parseFrom(ALL_STRINGS_BYTES, registry);
    checkFields(msg);
}
Also used : StringMsg(protos.StringMsg) ExtensionRegistry(com.google.protobuf.ExtensionRegistry)

Example 4 with StringMsg

use of protos.StringMsg in project j2objc by google.

the class StringsTest method testMergeFromInputStream.

public void testMergeFromInputStream() throws Exception {
    ExtensionRegistry registry = ExtensionRegistry.newInstance();
    StringFields.registerAllExtensions(registry);
    ByteArrayInputStream in = new ByteArrayInputStream(ALL_STRINGS_BYTES);
    StringMsg.Builder builder = StringMsg.newBuilder().mergeFrom(in, registry);
    StringMsg msg = builder.build();
    checkFields(builder);
    checkFields(msg);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StringMsg(protos.StringMsg) ExtensionRegistry(com.google.protobuf.ExtensionRegistry)

Example 5 with StringMsg

use of protos.StringMsg in project j2objc by google.

the class StringsTest method testDefaultValue.

public void testDefaultValue() throws Exception {
    StringMsg msg = StringMsg.newBuilder().build();
    assertEquals("", msg.getEmptyF());
    assertEquals("abc", msg.getDefaultStringF());
    assertEquals("", new String(msg.getBytesF().toByteArray()));
    assertEquals("def", new String(msg.getDefaultBytesF().toByteArray()));
    assertEquals("", msg.getExtension(StringFields.emptyFe));
    assertEquals("ghi", msg.getExtension(StringFields.defaultStringFe));
    assertEquals("", new String(msg.getExtension(StringFields.bytesFe).toByteArray()));
    assertEquals("jkl", new String(msg.getExtension(StringFields.defaultBytesFe).toByteArray()));
}
Also used : StringMsg(protos.StringMsg) ByteString(com.google.protobuf.ByteString)

Aggregations

StringMsg (protos.StringMsg)7 ByteString (com.google.protobuf.ByteString)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)2