TextList code generation and tests

This commit is contained in:
David Renshaw 2014-09-03 10:47:26 -04:00
parent fcda75e732
commit 2e41cc0623
4 changed files with 31 additions and 1 deletions

View file

@ -295,6 +295,7 @@ private:
case schema::Type::STRUCT: case schema::Type::STRUCT:
return kj::strTree(" org.capnproto.StructList"); return kj::strTree(" org.capnproto.StructList");
case schema::Type::TEXT: case schema::Type::TEXT:
return kj::strTree( "org.capnproto.TextList");
case schema::Type::DATA: case schema::Type::DATA:
case schema::Type::ENUM: case schema::Type::ENUM:
case schema::Type::INTERFACE: case schema::Type::INTERFACE:
@ -1046,6 +1047,9 @@ private:
break; break;
case schema::Type::TEXT: case schema::Type::TEXT:
primitiveElement = false;
fieldSize = kj::str("org.capnproto.FieldSize.POINTER");
case schema::Type::DATA: case schema::Type::DATA:
case schema::Type::LIST: case schema::Type::LIST:
case schema::Type::ANY_POINTER: case schema::Type::ANY_POINTER:

View file

@ -47,6 +47,11 @@ object TestUtil {
builder.setEnumField(TestEnum.CORGE); builder.setEnumField(TestEnum.CORGE);
builder.initVoidList(6); 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); 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) { def checkTestMessage(reader : TestAllTypes.Reader) {
@ -126,6 +137,13 @@ object TestUtil {
} }
assert(reader.getVoidList().size() == 6); 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");
} }

View file

@ -46,7 +46,11 @@ struct TestAllTypes {
uInt64List @26 : List(UInt64); uInt64List @26 : List(UInt64);
float32List @27 : List(Float32); float32List @27 : List(Float32);
float64List @28 : List(Float64); 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 { struct TestOutOfOrder {

View file

@ -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<Text.Builder> { public final class Iterator implements java.util.Iterator<Text.Builder> {
public Builder list; public Builder list;
public int idx = 0; public int idx = 0;