diff --git a/compiler/src/test/scala/org/capnproto/EncodingTest.scala b/compiler/src/test/scala/org/capnproto/EncodingTest.scala index 8018726..f86302c 100644 --- a/compiler/src/test/scala/org/capnproto/EncodingTest.scala +++ b/compiler/src/test/scala/org/capnproto/EncodingTest.scala @@ -68,6 +68,28 @@ class EncodingSuite extends FunSuite { } } + test("UpgradeStructInBuilder") { + val builder = new MessageBuilder(); + val root = builder.initRoot(TestAnyPointer.factory); + + + val oldReader = { + val oldVersion = root.getAnyPointerField().initAsStruct(TestOldVersion.factory); + oldVersion.setOld1(123); + oldVersion.setOld2("foo"); + val sub = oldVersion.initOld3(); + sub.setOld1(456); + sub.setOld2("bar"); + oldVersion + } + + { + //val newVersion = root.getAnyPointerField().getAsStruct(TestNewVersion.factory); + } + + //... + } + test("Constants") { assert(Void.VOID == TestConstants.VOID_CONST); assert(true == TestConstants.BOOL_CONST); diff --git a/compiler/src/test/schema/test.capnp b/compiler/src/test/schema/test.capnp index 189eca0..0f228d8 100644 --- a/compiler/src/test/schema/test.capnp +++ b/compiler/src/test/schema/test.capnp @@ -192,6 +192,25 @@ struct TestGroups { } } + +struct TestOldVersion { + # A subset of TestNewVersion. + old1 @0 :Int64; + old2 @1 :Text; + old3 @2 :TestOldVersion; +} + +struct TestNewVersion { + # A superset of TestOldVersion. + old1 @0 :Int64; + old2 @1 :Text; + old3 @2 :TestNewVersion; + new1 @3 :Int64 = 987; + new2 @4 :Text = "baz"; +} + +struct TestEmptyStruct {} + struct TestConstants { const voidConst :Void = void; const boolConst :Bool = true;