public void testBarTooLarge2() throws Exception { Schema<Bar> schema = Bar.getSchema(); Bar message = new Bar(); message.setSomeBytes(ByteString.wrap( new byte[StringSerializer.THREE_BYTE_LOWER_LIMIT - 1])); ByteArrayOutputStream out = new ByteArrayOutputStream(); int size = optWriteDelimitedTo(out, message, schema, buf()); int delimSize = ProtobufOutput.computeRawVarint32Size(size); byte[] data = out.toByteArray(); int expectedSize = size + delimSize; assertEquals(expectedSize, data.length); verifyOptData(data, message, schema, buf()); ByteArrayInputStream in = new ByteArrayInputStream(data); Bar parsedMessage = schema.newMessage(); boolean merged = optMergeDelimitedFrom(in, parsedMessage, schema, buf(256)); assertFalse(merged); }
public void testBarTooLarge3() throws Exception { Schema<Bar> schema = Bar.getSchema(); Bar message = new Bar(); message.setSomeBytes(ByteString.wrap( new byte[StringSerializer.FOUR_BYTE_LOWER_LIMIT - 1])); ByteArrayOutputStream out = new ByteArrayOutputStream(); int size = optWriteDelimitedTo(out, message, schema, buf()); int delimSize = ProtobufOutput.computeRawVarint32Size(size); byte[] data = out.toByteArray(); int expectedSize = size + delimSize; assertEquals(expectedSize, data.length); verifyOptData(data, message, schema, buf()); ByteArrayInputStream in = new ByteArrayInputStream(data); Bar parsedMessage = schema.newMessage(); boolean merged = optMergeDelimitedFrom(in, parsedMessage, schema, buf(256)); assertFalse(merged); } }
public void testFoo() throws Exception { Bar bar = new Bar(); bar.setSomeInt(1); bar.setSomeBytes(ByteString.copyFromUtf8(ESCAPE_TARGET)); bar.setSomeString(ESCAPE_TARGET); ArrayList<Bar> bars = new ArrayList<Bar>(); bars.add(bar); bars.add(bar); ArrayList<String> strings = new ArrayList<String>(); strings.add(ESCAPE_TARGET); strings.add(""); strings.add(ESCAPE_TARGET); Foo foo = new Foo(); foo.setSomeBar(bars); foo.setSomeString(strings); byte[] protostuff = ProtostuffIOUtil.toByteArray(foo, foo.cachedSchema(), buf()); byte[] json = JsonIOUtil.toByteArray(ProtostuffIOUtil.newPipe(protostuff), Foo.getPipeSchema(), false); byte[] json2 = JsonXIOUtil.toByteArray(ProtostuffIOUtil.newPipe(protostuff), Foo.getPipeSchema(), false, buf()); assertTrue(json.length == json2.length); String strJson = STRING.deser(json); String strJson2 = STRING.deser(json2); assertEquals(strJson, strJson2); System.err.println(strJson); System.err.println(strJson2); }
@Test public void testBarWithEmptyStringAndByteString() throws Exception { Bar barCompare = new Bar(); barCompare.setSomeBytes(ByteString.copyFromUtf8(new String(""))); barCompare.setSomeString(new String("")); Bar dbar = new Bar(); byte[] data = XmlIOUtil.toByteArray(barCompare, barCompare.cachedSchema()); XmlIOUtil.mergeFrom(data, dbar, dbar.cachedSchema()); SerializableObjects.assertEquals(barCompare, dbar); // test equal serialization on both xml outputs byte[] actuals = XmlXIOUtil.toByteArray(barCompare, barCompare.cachedSchema(), LinkedBuffer.allocate(256)); assertArrayEquals(data, actuals); }
public void testBar() throws Exception { Bar bar = new Bar(); bar.setSomeInt(1); bar.setSomeBytes(ByteString.copyFromUtf8(ESCAPE_TARGET)); bar.setSomeString(ESCAPE_TARGET); byte[] protostuff = ProtostuffIOUtil.toByteArray(bar, bar.cachedSchema(), buf()); byte[] json = JsonIOUtil.toByteArray(ProtostuffIOUtil.newPipe(protostuff), Bar.getPipeSchema(), false); byte[] json2 = JsonXIOUtil.toByteArray(ProtostuffIOUtil.newPipe(protostuff), Bar.getPipeSchema(), false, buf()); assertTrue(json.length == json2.length); String strJson = STRING.deser(json); String strJson2 = STRING.deser(json2); assertEquals(strJson, strJson2); System.err.println(strJson); System.err.println(strJson2); }