From 2e41cc0623d79e5351f9a31f97a8aa1867aebe75 Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Wed, 3 Sep 2014 10:47:26 -0400 Subject: [PATCH] TextList code generation and tests --- compiler/src/main/cpp/capnpc-java.c++ | 4 ++++ .../test/scala/org/capnproto/TestUtil.scala | 18 ++++++++++++++++++ compiler/src/test/schema/test.capnp | 6 +++++- .../src/main/java/org/capnproto/TextList.java | 4 ++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/compiler/src/main/cpp/capnpc-java.c++ b/compiler/src/main/cpp/capnpc-java.c++ index bb6b019..e37b9d8 100644 --- a/compiler/src/main/cpp/capnpc-java.c++ +++ b/compiler/src/main/cpp/capnpc-java.c++ @@ -295,6 +295,7 @@ private: case schema::Type::STRUCT: return kj::strTree(" org.capnproto.StructList"); case schema::Type::TEXT: + return kj::strTree( "org.capnproto.TextList"); case schema::Type::DATA: case schema::Type::ENUM: case schema::Type::INTERFACE: @@ -1046,6 +1047,9 @@ private: break; case schema::Type::TEXT: + primitiveElement = false; + fieldSize = kj::str("org.capnproto.FieldSize.POINTER"); + case schema::Type::DATA: case schema::Type::LIST: case schema::Type::ANY_POINTER: diff --git a/compiler/src/test/scala/org/capnproto/TestUtil.scala b/compiler/src/test/scala/org/capnproto/TestUtil.scala index eca6983..f75ad4c 100644 --- a/compiler/src/test/scala/org/capnproto/TestUtil.scala +++ b/compiler/src/test/scala/org/capnproto/TestUtil.scala @@ -47,6 +47,11 @@ object TestUtil { builder.setEnumField(TestEnum.CORGE); builder.initVoidList(6); + val textList = builder.initTextList(3); + textList.set(0, new Text.Reader("plugh")); + textList.set(1, new Text.Reader("xyzzy")); + textList.set(2, new Text.Reader("thud")); + } @@ -87,6 +92,12 @@ object TestUtil { } assert(builder.getVoidList().size() == 6); + + val textList = builder.getTextList(); + assert(textList.size() == 3); + assert(textList.get(0).toString() == "plugh"); + assert(textList.get(1).toString() == "xyzzy"); + assert(textList.get(2).toString() == "thud"); } def checkTestMessage(reader : TestAllTypes.Reader) { @@ -126,6 +137,13 @@ object TestUtil { } assert(reader.getVoidList().size() == 6); + + val textList = reader.getTextList(); + assert(textList.size() == 3); + assert(textList.get(0).toString() == "plugh"); + assert(textList.get(1).toString() == "xyzzy"); + assert(textList.get(2).toString() == "thud"); + } diff --git a/compiler/src/test/schema/test.capnp b/compiler/src/test/schema/test.capnp index 7727455..56aaff6 100644 --- a/compiler/src/test/schema/test.capnp +++ b/compiler/src/test/schema/test.capnp @@ -46,7 +46,11 @@ struct TestAllTypes { uInt64List @26 : List(UInt64); float32List @27 : List(Float32); float64List @28 : List(Float64); -# ... + textList @29 : List(Text); +# dataList @30 : List(Data); +# structList @31 : List(TestAllTypes); +# enumList @32 : List(TestEnum); +# interfaceList @33 : List(Void); } struct TestOutOfOrder { diff --git a/runtime/src/main/java/org/capnproto/TextList.java b/runtime/src/main/java/org/capnproto/TextList.java index 2a55f2a..ab79aa5 100644 --- a/runtime/src/main/java/org/capnproto/TextList.java +++ b/runtime/src/main/java/org/capnproto/TextList.java @@ -62,6 +62,10 @@ public final class TextList { } + public final void set(int index, Text.Reader value) { + this.builder.getPointerElement(index).setText(value); + } + public final class Iterator implements java.util.Iterator { public Builder list; public int idx = 0;