Search in sources :

Example 1 with GroupFe

use of protos.GroupFe in project j2objc by google.

the class MessagesTest method testMergeExistingMessageFields.

public void testMergeExistingMessageFields() throws Exception {
    ExtensionRegistry registry = ExtensionRegistry.newInstance();
    MessageFields.registerAllExtensions(registry);
    MessageData toMerge = MessageData.newBuilder().setMsgF(SubMsg.newBuilder().setUintF(123).build()).setGroupF(GroupF.newBuilder().setUintF(234).build()).addMsgR(SubMsg.newBuilder().setUintF(345).build()).addGroupR(GroupR.newBuilder().setUintF(456).build()).setExtension(MessageFields.msgFe, SubMsg.newBuilder().setUintF(567).build()).setExtension(MessageFields.groupFe, GroupFe.newBuilder().setUintF(678).build()).addExtension(MessageFields.msgRe, SubMsg.newBuilder().setUintF(789).build()).addExtension(MessageFields.groupRe, GroupRe.newBuilder().setUintF(890).build()).build();
    byte[] toMergeBytes = toMerge.toByteArray();
    // Save the singular fields so we can verify that they aren't modified by merging.
    SubMsg field1 = SubMsg.newBuilder().setIntF(321).build();
    GroupF field2 = GroupF.newBuilder().setIntF(432).build();
    SubMsg field3 = SubMsg.newBuilder().setIntF(765).build();
    GroupFe field4 = GroupFe.newBuilder().setIntF(876).build();
    MessageData.Builder builder = MessageData.newBuilder().setMsgF(field1).setGroupF(field2).addMsgR(SubMsg.newBuilder().setIntF(543).build()).addGroupR(GroupR.newBuilder().setIntF(654).build()).setExtension(MessageFields.msgFe, field3).setExtension(MessageFields.groupFe, field4).addExtension(MessageFields.msgRe, SubMsg.newBuilder().setIntF(987).build()).addExtension(MessageFields.groupRe, GroupRe.newBuilder().setIntF(98).build());
    MessageData.Builder builder1 = builder.build().toBuilder();
    builder1.mergeFrom(toMerge);
    checkMergedFields(builder1);
    MessageData.Builder builder2 = builder.build().toBuilder();
    builder2.mergeFrom(toMergeBytes, registry);
    // TODO(kstanger): This is a bug in the native ObjC runtime. It fails to
    // merge message type extension fields when reading from data. Instead it
    // just overwrites the existing message field.
    //checkMergedFields(builder2);
    assertFalse(field1.hasUintF());
    assertFalse(field2.hasUintF());
    assertFalse(field3.hasUintF());
    assertFalse(field4.hasUintF());
}
Also used : SubMsg(protos.MessageData.SubMsg) GroupF(protos.MessageData.GroupF) MessageData(protos.MessageData) GroupFe(protos.GroupFe) ExtensionRegistry(com.google.protobuf.ExtensionRegistry)

Aggregations

ExtensionRegistry (com.google.protobuf.ExtensionRegistry)1 GroupFe (protos.GroupFe)1 MessageData (protos.MessageData)1 GroupF (protos.MessageData.GroupF)1 SubMsg (protos.MessageData.SubMsg)1