Search in sources :

Example 1 with EnumMsg

use of protos.EnumMsg in project j2objc by google.

the class EnumsTest method testMergeFromInputStream.

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

Example 2 with EnumMsg

use of protos.EnumMsg in project j2objc by google.

the class EnumsTest method testParseFromByteArray.

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

Example 3 with EnumMsg

use of protos.EnumMsg in project j2objc by google.

the class EnumsTest method testMergeFromOtherMessage.

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

Example 4 with EnumMsg

use of protos.EnumMsg in project j2objc by google.

the class EnumsTest method testBadEnumValue.

// TODO(kstanger): This fails with native ObjC because it doesn't sign-extend
// when writing the negative enum value.
/*public void testSerialization() throws Exception {
    EnumMsg msg = getFilledMessage();

    assertEquals(71, msg.getSerializedSize());
    byte[] bytes1 = msg.toByteArray();
    checkBytes(ALL_ENUMS_BYTES, bytes1);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    msg.writeTo(out);
    byte[] bytes2 = out.toByteArray();
    checkBytes(ALL_ENUMS_BYTES, bytes2);
  }*/
// Tests that unknown enum values are skipped and don't cause a
// InvalidProtocolBufferException.
public void testBadEnumValue() throws Exception {
    ExtensionRegistry registry = ExtensionRegistry.newInstance();
    EnumFields.registerAllExtensions(registry);
    byte[] bytes = asBytes(new int[] { 0x08, 0x09, 0xA8, 0x01, 0x09, 0xCA, 0x02, 0x01, 0x09, 0xC8, 0x3E, 0x09, 0xE8, 0x3F, 0x09, 0x8A, 0x41, 0x01, 0x09 });
    EnumMsg msg = EnumMsg.parseFrom(bytes, registry);
    assertFalse(msg.hasEnumF());
    assertEquals(0, msg.getEnumRCount());
    assertEquals(0, msg.getEnumPCount());
// TODO(kstanger): Native ObjC behavior differs from Java behavior here.
//assertFalse(msg.hasExtension(EnumFields.enumFe));
//assertEquals(0, msg.getExtensionCount(EnumFields.enumRe));
//assertEquals(0, msg.getExtensionCount(EnumFields.enumPe));
}
Also used : EnumMsg(protos.EnumMsg) ExtensionRegistry(com.google.protobuf.ExtensionRegistry)

Aggregations

EnumMsg (protos.EnumMsg)4 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1