Refine search
public void testPartialEmptyBarWithString() throws Exception { Baz baz = new Baz(); Bar bar = new Bar(); bar.setSomeString("someString"); bar.setSomeBaz(baz); byte[] output = toByteArray(bar); Bar parsedBar = new Bar(); mergeFrom(output, 0, output.length, parsedBar, parsedBar.cachedSchema()); }
public void testBar() throws Exception { Bar bar = SerializableObjects.bar; protobufRoundTrip(bar, Bar.getSchema(), Bar.getPipeSchema()); protostuffRoundTrip(bar, Bar.getSchema(), Bar.getPipeSchema()); }
public void testPartialEmptyBar() throws Exception { Baz baz = new Baz(); Bar bar = new Bar(); bar.setSomeInt(1); bar.setSomeBaz(baz); byte[] output = toByteArray(bar); Bar parsedBar = new Bar(); mergeFrom(output, 0, output.length, parsedBar, parsedBar.cachedSchema()); }
public static void main(String[] args) { final Foo f = new Foo(); final Bar b = new Bar(); new Thread(new Runnable() { public void run() { f.doSomethingWithBar(b); } }).start(); new Thread(new Runnable() { public void run() { b.doSomethingWithFoo(f); } }).start(); }
public void testBarWithEmptyString() throws Exception { Bar bar = new Bar(); bar.setSomeString("someString"); byte[] output = toByteArray(bar); Bar parsedBar = new Bar(); mergeFrom(output, 0, output.length, parsedBar, parsedBar.cachedSchema()); }
public void testEmptyInnerBarDelimited() throws Exception { Bar barCompare = new Bar(); barCompare.setSomeBaz(new Baz()); ByteArrayOutputStream out = new ByteArrayOutputStream(); writeDelimitedTo(out, barCompare); byte[] data = out.toByteArray(); ByteArrayInputStream in = new ByteArrayInputStream(data); Bar bar = new Bar(); mergeDelimitedFrom(in, bar, bar.cachedSchema()); SerializableObjects.assertEquals(bar, barCompare); }
public void testEmptyInnerFooDelimited() throws Exception { Foo fooCompare = new Foo(); ArrayList<Bar> bars = new ArrayList<Bar>(); bars.add(new Bar()); fooCompare.setSomeBar(bars); ByteArrayOutputStream out = new ByteArrayOutputStream(); writeDelimitedTo(out, fooCompare); byte[] data = out.toByteArray(); ByteArrayInputStream in = new ByteArrayInputStream(data); Foo foo = new Foo(); mergeDelimitedFrom(in, foo, foo.cachedSchema()); SerializableObjects.assertEquals(foo, fooCompare); }
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 testBar() throws Exception { Schema<Bar> schema = Bar.getSchema(); Bar message = SerializableObjects.bar; 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()); assertTrue(merged); assertEquals(message, parsedMessage); }
public void testBar() throws Exception { Schema<Bar> schema = Bar.getSchema(); for (Bar message : new Bar[] { bar, negativeBar }) { byte[] data = XmlXIOUtil.toByteArray(message, schema, buf()); ByteArrayOutputStream out = new ByteArrayOutputStream(); XmlXIOUtil.writeTo(out, message, schema, buf()); assertTrue(Arrays.equals(data, out.toByteArray())); } }
public void testBar() throws Exception { for (Bar barCompare : new Bar[] { bar, negativeBar }) { byte[] data = toByteArray(barCompare, barCompare.cachedSchema()); ByteArrayOutputStream out = new ByteArrayOutputStream(); int total = writeTo(out, barCompare, barCompare.cachedSchema()); assertTrue(data.length == total); byte[] data2 = out.toByteArray(); assertTrue(data.length == data2.length); String text = STRING.deser(data); String text2 = STRING.deser(data2); assertEquals(text, text2); } }
public void testPartialEmptyFooInner() throws Exception { Baz baz = new Baz(); Bar bar = new Bar(); bar.setSomeBaz(baz); Foo foo = new Foo(); ArrayList<Bar> bars = new ArrayList<Bar>(); foo.setSomeBar(bars); byte[] output = toByteArray(foo); Foo parsedFoo = new Foo(); mergeFrom(output, 0, output.length, parsedFoo, parsedFoo.cachedSchema()); }
final CustomSchema<Bar> barSchema = new CustomSchema<Bar>(bar.cachedSchema()) baz.setId(1); baz.setName("baz"); final Bar bar = new Bar(); bar.setSomeBaz(baz); bar.setSomeInt(2); bar.setSomeString("bar"); bar.setSomeDouble(100.001d); bar.setSomeFloat(10.01f); Foo foo = new Foo(); mergeFrom(coded, 0, coded.length, foo, foo.cachedSchema()); assertTrue(bar.getSomeInt() == foo.getSomeInt().get(0)); assertEquals(bar.getSomeString(), foo.getSomeString().get(0)); assertTrue(bar.getSomeDouble() == foo.getSomeDouble().get(0)); assertTrue(bar.getSomeFloat() == foo.getSomeFloat().get(0));
public void testEmptyBarInner() throws Exception { Baz baz = new Baz(); Bar bar = new Bar(); bar.setSomeBaz(baz); byte[] output = toByteArray(bar); Bar parsedBar = new Bar(); mergeFrom(output, 0, output.length, parsedBar, parsedBar.cachedSchema()); }
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); }
public void testEmptyBar() throws Exception { Bar bar = new Bar(); byte[] output = toByteArray(bar); Bar parsedBar = new Bar(); mergeFrom(output, 0, output.length, parsedBar, parsedBar.cachedSchema()); }
static Foo newFoo() { // one-instance of Baz. Baz baz = new Baz(); baz.setId(100); Bar bar1 = new Bar(); bar1.setSomeInt(1); bar1.setSomeBaz(baz); Bar bar2 = new Bar(); bar2.setSomeInt(2); bar2.setSomeBaz(baz); ArrayList<Bar> bars = new ArrayList<Bar>(); bars.add(bar1); bars.add(bar2); Foo foo = new Foo(); foo.setSomeBar(bars); return foo; }
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); }
public void testBarNullFields() throws Exception { Bar b = new Bar(); JsonIOUtil.mergeFrom(JsonIOUtil.DEFAULT_JSON_FACTORY.createJsonParser( "{\"someInt\":null" + ",\"someString\":null" + ",\"someBaz\":null" + ",\"someEnum\":null" + ",\"someBytes\":null" + ",\"someBoolean\":null" + ",\"someFloat\":null" + ",\"someDouble\":null" + ",\"someLong\":null}"), b, b.cachedSchema(), false); assertEquals(0, b.getSomeInt()); assertNull(b.getSomeString()); assertNull(b.getSomeBaz()); assertNull(b.getSomeEnum()); assertNull(b.getSomeBytes()); assertFalse(b.getSomeBoolean()); assertEquals(0f, b.getSomeFloat()); assertEquals(0d, b.getSomeDouble()); assertEquals(0l, b.getSomeLong()); }