use of net.morimekta.test.providence.core.no_rw_binary.Containers in project providence by morimekta.
the class BinarySerializerTest method testNonPrecompiled_lenient.
@Test
public void testNonPrecompiled_lenient() throws IOException {
Serializer serializer = new BinarySerializer();
// Just a sanity check.
assertTrue(containers.size() == 10);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayInputStream bais;
int size;
// complex message, one at a time.
for (int i = 0; i < 10; ++i) {
baos.reset();
Containers expected = containers.get(i);
size = serializer.serialize(baos, expected);
assertEquals(baos.size(), size);
bais = new ByteArrayInputStream(baos.toByteArray());
Containers actual;
try {
actual = serializer.deserialize(bais, Containers.kDescriptor);
} catch (TokenizerException e) {
System.err.println(new String(baos.toByteArray(), UTF_8));
System.err.println(e.asString());
fail("oops");
return;
}
assertEquals(actual, expected);
}
// complex message in stream.
{
baos.reset();
size = 0;
for (int i = 0; i < 10; ++i) {
size += serializer.serialize(baos, containers.get(i));
}
assertEquals(baos.size(), size);
bais = new ByteArrayInputStream(baos.toByteArray());
for (int i = 0; i < 10; ++i) {
Containers expected = containers.get(i);
Containers actual = serializer.deserialize(bais, Containers.kDescriptor);
assertEquals(actual, expected);
}
assertEquals(0, bais.available());
}
}
Aggregations