assertEquals("hello", newMsg.getRepeatedString(0));
assertEquals("world", newMsg.getRepeatedString(1));
}
public void testMicroRepeatedBytes() throws Exception {
TestAllTypesMicro msg = new TestAllTypesMicro();
assertEquals(0, msg.getRepeatedBytesCount());
msg.addRepeatedBytes(ByteStringMicro.copyFromUtf8("hello"));
assertEquals(1, msg.getRepeatedBytesCount());
assertEquals("hello", msg.getRepeatedBytes(0).toStringUtf8());
msg.addRepeatedBytes(ByteStringMicro.copyFromUtf8("bye"));
assertEquals(2, msg.getRepeatedBytesCount());
assertEquals("hello", msg.getRepeatedBytes(0).toStringUtf8());
assertEquals("bye", msg.getRepeatedBytes(1).toStringUtf8());
msg.setRepeatedBytes(0, ByteStringMicro.copyFromUtf8("boo"));
assertEquals(2, msg.getRepeatedBytesCount());
assertEquals("boo", msg.getRepeatedBytes(0).toStringUtf8());
assertEquals("bye", msg.getRepeatedBytes(1).toStringUtf8());
msg.clearRepeatedBytes();
assertEquals(0, msg.getRepeatedBytesCount());
msg.clearRepeatedBytes()
.addRepeatedBytes(ByteStringMicro.copyFromUtf8("hello"));
assertEquals(1, msg.getRepeatedBytesCount());
assertEquals("hello", msg.getRepeatedBytes(0).toStringUtf8());
msg.clear();
assertEquals(0, msg.getRepeatedBytesCount());
// Test 1 entry and an empty byte array can be serialized
msg.clear()
.addRepeatedBytes(ByteStringMicro.copyFromUtf8(""));
assertEquals(1, msg.getRepeatedBytesCount());
assertEquals("", msg.getRepeatedBytes(0).toStringUtf8());
byte [] result = msg.toByteArray();
int msgSerializedSize = msg.getSerializedSize();
//System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
assertTrue(msgSerializedSize == 3);
assertEquals(result.length, msgSerializedSize);
TestAllTypesMicro newMsg = TestAllTypesMicro.parseFrom(result);
assertEquals(1, newMsg.getRepeatedBytesCount());
assertEquals("", newMsg.getRepeatedBytes(0).toStringUtf8());
// Test 2 entries
msg.clear()
.addRepeatedBytes(ByteStringMicro.copyFromUtf8("hello"))
.addRepeatedBytes(ByteStringMicro.copyFromUtf8("world"));
assertEquals(2, msg.getRepeatedBytesCount());
result = msg.toByteArray();
msgSerializedSize = msg.getSerializedSize();
//System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
assertTrue(msgSerializedSize == 16);
assertEquals(result.length, msgSerializedSize);
newMsg = TestAllTypesMicro.parseFrom(result);
assertEquals(2, newMsg.getRepeatedBytesCount());
assertEquals("hello", newMsg.getRepeatedBytes(0).toStringUtf8());
assertEquals("world", newMsg.getRepeatedBytes(1).toStringUtf8());
}