assertEquals(0, newMsg.getRepeatedNestedMessage(0).getBb());
assertEquals(1, newMsg.getRepeatedNestedMessage(1).getBb());
}
public void testMicroRepeatedForeignMessage() throws Exception {
TestAllTypesMicro msg = new TestAllTypesMicro();
MicroOuterClass.ForeignMessageMicro foreignMsg0 =
new MicroOuterClass.ForeignMessageMicro().setC(0);
MicroOuterClass.ForeignMessageMicro foreignMsg1 =
new MicroOuterClass.ForeignMessageMicro().setC(1);
MicroOuterClass.ForeignMessageMicro foreignMsg2 =
new MicroOuterClass.ForeignMessageMicro().setC(2);
msg.addRepeatedForeignMessage(foreignMsg0);
assertEquals(1, msg.getRepeatedForeignMessageCount());
assertEquals(0, msg.getRepeatedForeignMessage(0).getC());
msg.addRepeatedForeignMessage(foreignMsg1);
assertEquals(2, msg.getRepeatedForeignMessageCount());
assertEquals(0, msg.getRepeatedForeignMessage(0).getC());
assertEquals(1, msg.getRepeatedForeignMessage(1).getC());
msg.setRepeatedForeignMessage(0, foreignMsg2);
assertEquals(2, msg.getRepeatedForeignMessageCount());
assertEquals(2, msg.getRepeatedForeignMessage(0).getC());
assertEquals(1, msg.getRepeatedForeignMessage(1).getC());
msg.clearRepeatedForeignMessage();
assertEquals(0, msg.getRepeatedForeignMessageCount());
msg.clearRepeatedForeignMessage()
.addRepeatedForeignMessage(foreignMsg1);
assertEquals(1, msg.getRepeatedForeignMessageCount());
assertEquals(1, msg.getRepeatedForeignMessage(0).getC());
msg.clear();
assertEquals(0, msg.getRepeatedForeignMessageCount());
// Test 1 entry
msg.clear()
.addRepeatedForeignMessage(foreignMsg0);
assertEquals(1, msg.getRepeatedForeignMessageCount());
byte [] result = msg.toByteArray();
int msgSerializedSize = msg.getSerializedSize();
//System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
assertTrue(msgSerializedSize == 5);
assertEquals(result.length, msgSerializedSize);
TestAllTypesMicro newMsg = TestAllTypesMicro.parseFrom(result);
assertEquals(1, newMsg.getRepeatedForeignMessageCount());
assertEquals(0, newMsg.getRepeatedForeignMessage(0).getC());
// Test 2 entries
msg.clear()
.addRepeatedForeignMessage(foreignMsg0)
.addRepeatedForeignMessage(foreignMsg1);
assertEquals(2, msg.getRepeatedForeignMessageCount());
result = msg.toByteArray();
msgSerializedSize = msg.getSerializedSize();
//System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
assertTrue(msgSerializedSize == 10);
assertEquals(result.length, msgSerializedSize);
newMsg = TestAllTypesMicro.parseFrom(result);
assertEquals(2, newMsg.getRepeatedForeignMessageCount());
assertEquals(0, newMsg.getRepeatedForeignMessage(0).getC());
assertEquals(1, newMsg.getRepeatedForeignMessage(1).getC());
}