add a few more structs to test.capnp

This commit is contained in:
David Renshaw 2014-06-21 09:50:48 -04:00
parent a4155d7746
commit 7df18d5646
2 changed files with 112 additions and 1 deletions

View file

@ -24,6 +24,15 @@ class EncodingSuite extends FunSuite {
TestUtil.checkTestMessage(allTypes.asReader());
}
test("Groups") {
val builder = new MessageBuilder();
val root = builder.initRoot(TestGroups.factory);
//val foo = root.getGroups().initFoo();
}
// to debug, do this:
//Serialize.writeMessage((new java.io.FileOutputStream("/Users/dwrensha/Desktop/test.dat")).getChannel(),
// message);

View file

@ -59,4 +59,106 @@ struct TestOutOfOrder {
grault @1 :Text;
garply @7 :Text;
waldo @5 :Text;
}
}
struct TestUnion {
union0 @0! :union {
# Pack union 0 under ideal conditions: there is no unused padding space prior to it.
u0f0s0 @4: Void;
u0f0s1 @5: Bool;
u0f0s8 @6: Int8;
u0f0s16 @7: Int16;
u0f0s32 @8: Int32;
u0f0s64 @9: Int64;
u0f0sp @10: Text;
# Pack more stuff into union0 -- should go in same space.
u0f1s0 @11: Void;
u0f1s1 @12: Bool;
u0f1s8 @13: Int8;
u0f1s16 @14: Int16;
u0f1s32 @15: Int32;
u0f1s64 @16: Int64;
u0f1sp @17: Text;
}
# Pack one bit in order to make pathological situation for union1.
bit0 @18: Bool;
union1 @1! :union {
# Pack pathologically bad case. Each field takes up new space.
u1f0s0 @19: Void;
u1f0s1 @20: Bool;
u1f1s1 @21: Bool;
u1f0s8 @22: Int8;
u1f1s8 @23: Int8;
u1f0s16 @24: Int16;
u1f1s16 @25: Int16;
u1f0s32 @26: Int32;
u1f1s32 @27: Int32;
u1f0s64 @28: Int64;
u1f1s64 @29: Int64;
u1f0sp @30: Text;
u1f1sp @31: Text;
# Pack more stuff into union1 -- each should go into the same space as corresponding u1f0s*.
u1f2s0 @32: Void;
u1f2s1 @33: Bool;
u1f2s8 @34: Int8;
u1f2s16 @35: Int16;
u1f2s32 @36: Int32;
u1f2s64 @37: Int64;
u1f2sp @38: Text;
}
# Fill in the rest of that bitfield from earlier.
bit2 @39: Bool;
bit3 @40: Bool;
bit4 @41: Bool;
bit5 @42: Bool;
bit6 @43: Bool;
bit7 @44: Bool;
# Interleave two unions to be really annoying.
# Also declare in reverse order to make sure union discriminant values are sorted by field number
# and not by declaration order.
union2 @2! :union {
u2f0s64 @54: Int64;
u2f0s32 @52: Int32;
u2f0s16 @50: Int16;
u2f0s8 @47: Int8;
u2f0s1 @45: Bool;
}
union3 @3! :union {
u3f0s64 @55: Int64;
u3f0s32 @53: Int32;
u3f0s16 @51: Int16;
u3f0s8 @48: Int8;
u3f0s1 @46: Bool;
}
byte0 @49: UInt8;
}
struct TestGroups {
groups :union {
foo :group {
corge @0 :Int32;
grault @2 :Int64;
garply @8 :Text;
}
bar :group {
corge @3 :Int32;
grault @4 :Text;
garply @5 :Int64;
}
baz :group {
corge @1 :Int32;
grault @6 :Text;
garply @7 :Text;
}
}
}