capnproto

FORK: Cap'n Proto serialization/RPC system - core tools and C++ library
git clone https://git.neptards.moe/neptards/capnproto.git
Log | Files | Refs | README | LICENSE

test.capnp (29249B)


      1 # Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
      2 # Licensed under the MIT License:
      3 #
      4 # Permission is hereby granted, free of charge, to any person obtaining a copy
      5 # of this software and associated documentation files (the "Software"), to deal
      6 # in the Software without restriction, including without limitation the rights
      7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      8 # copies of the Software, and to permit persons to whom the Software is
      9 # furnished to do so, subject to the following conditions:
     10 #
     11 # The above copyright notice and this permission notice shall be included in
     12 # all copies or substantial portions of the Software.
     13 #
     14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     20 # THE SOFTWARE.
     21 
     22 @0xd508eebdc2dc42b8;
     23 
     24 using Cxx = import "c++.capnp";
     25 
     26 # Use a namespace likely to cause trouble if the generated code doesn't use fully-qualified
     27 # names for stuff in the capnproto namespace.
     28 $Cxx.namespace("capnproto_test::capnp::test");
     29 
     30 enum TestEnum {
     31   foo @0;
     32   bar @1;
     33   baz @2;
     34   qux @3;
     35   quux @4;
     36   corge @5;
     37   grault @6;
     38   garply @7;
     39 }
     40 
     41 struct TestAllTypes {
     42   voidField      @0  : Void;
     43   boolField      @1  : Bool;
     44   int8Field      @2  : Int8;
     45   int16Field     @3  : Int16;
     46   int32Field     @4  : Int32;
     47   int64Field     @5  : Int64;
     48   uInt8Field     @6  : UInt8;
     49   uInt16Field    @7  : UInt16;
     50   uInt32Field    @8  : UInt32;
     51   uInt64Field    @9  : UInt64;
     52   float32Field   @10 : Float32;
     53   float64Field   @11 : Float64;
     54   textField      @12 : Text;
     55   dataField      @13 : Data;
     56   structField    @14 : TestAllTypes;
     57   enumField      @15 : TestEnum;
     58   interfaceField @16 : Void;  # TODO
     59 
     60   voidList      @17 : List(Void);
     61   boolList      @18 : List(Bool);
     62   int8List      @19 : List(Int8);
     63   int16List     @20 : List(Int16);
     64   int32List     @21 : List(Int32);
     65   int64List     @22 : List(Int64);
     66   uInt8List     @23 : List(UInt8);
     67   uInt16List    @24 : List(UInt16);
     68   uInt32List    @25 : List(UInt32);
     69   uInt64List    @26 : List(UInt64);
     70   float32List   @27 : List(Float32);
     71   float64List   @28 : List(Float64);
     72   textList      @29 : List(Text);
     73   dataList      @30 : List(Data);
     74   structList    @31 : List(TestAllTypes);
     75   enumList      @32 : List(TestEnum);
     76   interfaceList @33 : List(Void);  # TODO
     77 }
     78 
     79 struct TestDefaults {
     80   voidField      @0  : Void    = void;
     81   boolField      @1  : Bool    = true;
     82   int8Field      @2  : Int8    = -123;
     83   int16Field     @3  : Int16   = -12345;
     84   int32Field     @4  : Int32   = -12345678;
     85   int64Field     @5  : Int64   = -123456789012345;
     86   uInt8Field     @6  : UInt8   = 234;
     87   uInt16Field    @7  : UInt16  = 45678;
     88   uInt32Field    @8  : UInt32  = 3456789012;
     89   uInt64Field    @9  : UInt64  = 12345678901234567890;
     90   float32Field   @10 : Float32 = 1234.5;
     91   float64Field   @11 : Float64 = -123e45;
     92   textField      @12 : Text    = "foo";
     93   dataField      @13 : Data    = 0x"62 61 72"; # "bar"
     94   structField    @14 : TestAllTypes = (
     95       voidField      = void,
     96       boolField      = true,
     97       int8Field      = -12,
     98       int16Field     = 3456,
     99       int32Field     = -78901234,
    100       int64Field     = 56789012345678,
    101       uInt8Field     = 90,
    102       uInt16Field    = 1234,
    103       uInt32Field    = 56789012,
    104       uInt64Field    = 345678901234567890,
    105       float32Field   = -1.25e-10,
    106       float64Field   = 345,
    107       textField      = "baz",
    108       dataField      = "qux",
    109       structField    = (
    110           textField = "nested",
    111           structField = (textField = "really nested")),
    112       enumField      = baz,
    113       # interfaceField can't have a default
    114 
    115       voidList      = [void, void, void],
    116       boolList      = [false, true, false, true, true],
    117       int8List      = [12, -34, -0x80, 0x7f],
    118       int16List     = [1234, -5678, -0x8000, 0x7fff],
    119       int32List     = [12345678, -90123456, -0x80000000, 0x7fffffff],
    120       int64List     = [123456789012345, -678901234567890, -0x8000000000000000, 0x7fffffffffffffff],
    121       uInt8List     = [12, 34, 0, 0xff],
    122       uInt16List    = [1234, 5678, 0, 0xffff],
    123       uInt32List    = [12345678, 90123456, 0, 0xffffffff],
    124       uInt64List    = [123456789012345, 678901234567890, 0, 0xffffffffffffffff],
    125       float32List   = [0, 1234567, 1e37, -1e37, 1e-37, -1e-37],
    126       float64List   = [0, 123456789012345, 1e306, -1e306, 1e-306, -1e-306],
    127       textList      = ["quux", "corge", "grault"],
    128       dataList      = ["garply", "waldo", "fred"],
    129       structList    = [
    130           (textField = "x " "structlist"
    131                        " 1"),
    132           (textField = "x structlist 2"),
    133           (textField = "x structlist 3")],
    134       enumList      = [qux, bar, grault]
    135       # interfaceList can't have a default
    136       );
    137   enumField      @15 : TestEnum = corge;
    138   interfaceField @16 : Void;  # TODO
    139 
    140   voidList      @17 : List(Void)    = [void, void, void, void, void, void];
    141   boolList      @18 : List(Bool)    = [true, false, false, true];
    142   int8List      @19 : List(Int8)    = [111, -111];
    143   int16List     @20 : List(Int16)   = [11111, -11111];
    144   int32List     @21 : List(Int32)   = [111111111, -111111111];
    145   int64List     @22 : List(Int64)   = [1111111111111111111, -1111111111111111111];
    146   uInt8List     @23 : List(UInt8)   = [111, 222] ;
    147   uInt16List    @24 : List(UInt16)  = [33333, 44444];
    148   uInt32List    @25 : List(UInt32)  = [3333333333];
    149   uInt64List    @26 : List(UInt64)  = [11111111111111111111];
    150   float32List   @27 : List(Float32) = [5555.5, inf, -inf, nan];
    151   float64List   @28 : List(Float64) = [7777.75, inf, -inf, nan];
    152   textList      @29 : List(Text)    = ["plugh", "xyzzy", "thud"];
    153   dataList      @30 : List(Data)    = ["oops", "exhausted", "rfc3092"];
    154   structList    @31 : List(TestAllTypes) = [
    155       (textField = "structlist 1"),
    156       (textField = "structlist 2"),
    157       (textField = "structlist 3")];
    158   enumList      @32 : List(TestEnum) = [foo, garply];
    159   interfaceList @33 : List(Void);  # TODO
    160 }
    161 
    162 struct TestAnyPointer {
    163   anyPointerField @0 :AnyPointer;
    164 
    165   # Do not add any other fields here!  Some tests rely on anyPointerField being the last pointer
    166   # in the struct.
    167 }
    168 
    169 struct TestAnyOthers {
    170   anyStructField @0 :AnyStruct;
    171   anyListField @1 :AnyList;
    172   capabilityField @2 :Capability;
    173 }
    174 
    175 struct TestOutOfOrder {
    176   foo @3 :Text;
    177   bar @2 :Text;
    178   baz @8 :Text;
    179   qux @0 :Text;
    180   quux @6 :Text;
    181   corge @4 :Text;
    182   grault @1 :Text;
    183   garply @7 :Text;
    184   waldo @5 :Text;
    185 }
    186 
    187 struct TestUnion {
    188   union0 @0! :union {
    189     # Pack union 0 under ideal conditions: there is no unused padding space prior to it.
    190     u0f0s0  @4: Void;
    191     u0f0s1  @5: Bool;
    192     u0f0s8  @6: Int8;
    193     u0f0s16 @7: Int16;
    194     u0f0s32 @8: Int32;
    195     u0f0s64 @9: Int64;
    196     u0f0sp  @10: Text;
    197 
    198     # Pack more stuff into union0 -- should go in same space.
    199     u0f1s0  @11: Void;
    200     u0f1s1  @12: Bool;
    201     u0f1s8  @13: Int8;
    202     u0f1s16 @14: Int16;
    203     u0f1s32 @15: Int32;
    204     u0f1s64 @16: Int64;
    205     u0f1sp  @17: Text;
    206   }
    207 
    208   # Pack one bit in order to make pathological situation for union1.
    209   bit0 @18: Bool;
    210 
    211   union1 @1! :union {
    212     # Pack pathologically bad case.  Each field takes up new space.
    213     u1f0s0  @19: Void;
    214     u1f0s1  @20: Bool;
    215     u1f1s1  @21: Bool;
    216     u1f0s8  @22: Int8;
    217     u1f1s8  @23: Int8;
    218     u1f0s16 @24: Int16;
    219     u1f1s16 @25: Int16;
    220     u1f0s32 @26: Int32;
    221     u1f1s32 @27: Int32;
    222     u1f0s64 @28: Int64;
    223     u1f1s64 @29: Int64;
    224     u1f0sp  @30: Text;
    225     u1f1sp  @31: Text;
    226 
    227     # Pack more stuff into union1 -- each should go into the same space as corresponding u1f0s*.
    228     u1f2s0  @32: Void;
    229     u1f2s1  @33: Bool;
    230     u1f2s8  @34: Int8;
    231     u1f2s16 @35: Int16;
    232     u1f2s32 @36: Int32;
    233     u1f2s64 @37: Int64;
    234     u1f2sp  @38: Text;
    235   }
    236 
    237   # Fill in the rest of that bitfield from earlier.
    238   bit2 @39: Bool;
    239   bit3 @40: Bool;
    240   bit4 @41: Bool;
    241   bit5 @42: Bool;
    242   bit6 @43: Bool;
    243   bit7 @44: Bool;
    244 
    245   # Interleave two unions to be really annoying.
    246   # Also declare in reverse order to make sure union discriminant values are sorted by field number
    247   # and not by declaration order.
    248   union2 @2! :union {
    249     u2f0s64 @54: Int64;
    250     u2f0s32 @52: Int32;
    251     u2f0s16 @50: Int16;
    252     u2f0s8 @47: Int8;
    253     u2f0s1 @45: Bool;
    254   }
    255 
    256   union3 @3! :union {
    257     u3f0s64 @55: Int64;
    258     u3f0s32 @53: Int32;
    259     u3f0s16 @51: Int16;
    260     u3f0s8 @48: Int8;
    261     u3f0s1 @46: Bool;
    262   }
    263 
    264   byte0 @49: UInt8;
    265 }
    266 
    267 struct TestUnnamedUnion {
    268   before @0 :Text;
    269 
    270   union {
    271     foo @1 :UInt16;
    272     bar @3 :UInt32;
    273   }
    274 
    275   middle @2 :UInt16;
    276 
    277   after @4 :Text;
    278 }
    279 
    280 struct TestUnionInUnion {
    281   # There is no reason to ever do this.
    282   outer :union {
    283     inner :union {
    284       foo @0 :Int32;
    285       bar @1 :Int32;
    286     }
    287     baz @2 :Int32;
    288   }
    289 }
    290 
    291 struct TestGroups {
    292   groups :union {
    293     foo :group {
    294       corge @0 :Int32;
    295       grault @2 :Int64;
    296       garply @8 :Text;
    297     }
    298     bar :group {
    299       corge @3 :Int32;
    300       grault @4 :Text;
    301       garply @5 :Int64;
    302     }
    303     baz :group {
    304       corge @1 :Int32;
    305       grault @6 :Text;
    306       garply @7 :Text;
    307     }
    308   }
    309 }
    310 
    311 struct TestInterleavedGroups {
    312   group1 :group {
    313     foo @0 :UInt32;
    314     bar @2 :UInt64;
    315     union {
    316       qux @4 :UInt16;
    317       corge :group {
    318         grault @6 :UInt64;
    319         garply @8 :UInt16;
    320         plugh @14 :Text;
    321         xyzzy @16 :Text;
    322       }
    323 
    324       fred @12 :Text;
    325     }
    326 
    327     waldo @10 :Text;
    328   }
    329 
    330   group2 :group {
    331     foo @1 :UInt32;
    332     bar @3 :UInt64;
    333     union {
    334       qux @5 :UInt16;
    335       corge :group {
    336         grault @7 :UInt64;
    337         garply @9 :UInt16;
    338         plugh @15 :Text;
    339         xyzzy @17 :Text;
    340       }
    341 
    342       fred @13 :Text;
    343     }
    344 
    345     waldo @11 :Text;
    346   }
    347 }
    348 
    349 struct TestUnionDefaults {
    350   s16s8s64s8Set @0 :TestUnion =
    351       (union0 = (u0f0s16 = 321), union1 = (u1f0s8 = 123), union2 = (u2f0s64 = 12345678901234567),
    352        union3 = (u3f0s8 = 55));
    353   s0sps1s32Set @1 :TestUnion =
    354       (union0 = (u0f1s0 = void), union1 = (u1f0sp = "foo"), union2 = (u2f0s1 = true),
    355        union3 = (u3f0s32 = 12345678));
    356 
    357   unnamed1 @2 :TestUnnamedUnion = (foo = 123);
    358   unnamed2 @3 :TestUnnamedUnion = (bar = 321, before = "foo", after = "bar");
    359 }
    360 
    361 struct TestNestedTypes {
    362   enum NestedEnum {
    363     foo @0;
    364     bar @1;
    365   }
    366 
    367   struct NestedStruct {
    368     enum NestedEnum {
    369       baz @0;
    370       qux @1;
    371       quux @2;
    372     }
    373 
    374     outerNestedEnum @0 :TestNestedTypes.NestedEnum = bar;
    375     innerNestedEnum @1 :NestedEnum = quux;
    376   }
    377 
    378   nestedStruct @0 :NestedStruct;
    379 
    380   outerNestedEnum @1 :NestedEnum = bar;
    381   innerNestedEnum @2 :NestedStruct.NestedEnum = quux;
    382 }
    383 
    384 struct TestUsing {
    385   using OuterNestedEnum = TestNestedTypes.NestedEnum;
    386   using TestNestedTypes.NestedStruct.NestedEnum;
    387 
    388   outerNestedEnum @1 :OuterNestedEnum = bar;
    389   innerNestedEnum @0 :NestedEnum = quux;
    390 }
    391 
    392 struct TestLists {
    393   # Small structs, when encoded as list, will be encoded as primitive lists rather than struct
    394   # lists, to save space.
    395   struct Struct0  { f @0 :Void; }
    396   struct Struct1  { f @0 :Bool; }
    397   struct Struct8  { f @0 :UInt8; }
    398   struct Struct16 { f @0 :UInt16; }
    399   struct Struct32 { f @0 :UInt32; }
    400   struct Struct64 { f @0 :UInt64; }
    401   struct StructP  { f @0 :Text; }
    402 
    403   # Versions of the above which cannot be encoded as primitive lists.
    404   struct Struct0c  { f @0 :Void; pad @1 :Text; }
    405   struct Struct1c  { f @0 :Bool; pad @1 :Text; }
    406   struct Struct8c  { f @0 :UInt8; pad @1 :Text; }
    407   struct Struct16c { f @0 :UInt16; pad @1 :Text; }
    408   struct Struct32c { f @0 :UInt32; pad @1 :Text; }
    409   struct Struct64c { f @0 :UInt64; pad @1 :Text; }
    410   struct StructPc  { f @0 :Text; pad @1 :UInt64; }
    411 
    412   list0  @0 :List(Struct0);
    413   list1  @1 :List(Struct1);
    414   list8  @2 :List(Struct8);
    415   list16 @3 :List(Struct16);
    416   list32 @4 :List(Struct32);
    417   list64 @5 :List(Struct64);
    418   listP  @6 :List(StructP);
    419 
    420   int32ListList @7 :List(List(Int32));
    421   textListList @8 :List(List(Text));
    422   structListList @9 :List(List(TestAllTypes));
    423 }
    424 
    425 struct TestFieldZeroIsBit {
    426   bit @0 :Bool;
    427   secondBit @1 :Bool = true;
    428   thirdField @2 :UInt8 = 123;
    429 }
    430 
    431 struct TestListDefaults {
    432   lists @0 :TestLists = (
    433       list0  = [(f = void), (f = void)],
    434       list1  = [(f = true), (f = false), (f = true), (f = true)],
    435       list8  = [(f = 123), (f = 45)],
    436       list16 = [(f = 12345), (f = 6789)],
    437       list32 = [(f = 123456789), (f = 234567890)],
    438       list64 = [(f = 1234567890123456), (f = 2345678901234567)],
    439       listP  = [(f = "foo"), (f = "bar")],
    440       int32ListList = [[1, 2, 3], [4, 5], [12341234]],
    441       textListList = [["foo", "bar"], ["baz"], ["qux", "corge"]],
    442       structListList = [[(int32Field = 123), (int32Field = 456)], [(int32Field = 789)]]);
    443 }
    444 
    445 struct TestLateUnion {
    446   # Test what happens if the unions are not the first ordinals in the struct.  At one point this
    447   # was broken for the dynamic API.
    448 
    449   foo @0 :Int32;
    450   bar @1 :Text;
    451   baz @2 :Int16;
    452 
    453   theUnion @3! :union {
    454     qux @4 :Text;
    455     corge @5 :List(Int32);
    456     grault @6 :Float32;
    457   }
    458 
    459   anotherUnion @7! :union {
    460     qux @8 :Text;
    461     corge @9 :List(Int32);
    462     grault @10 :Float32;
    463   }
    464 }
    465 
    466 struct TestOldVersion {
    467   # A subset of TestNewVersion.
    468   old1 @0 :Int64;
    469   old2 @1 :Text;
    470   old3 @2 :TestOldVersion;
    471 }
    472 
    473 struct TestNewVersion {
    474   # A superset of TestOldVersion.
    475   old1 @0 :Int64;
    476   old2 @1 :Text;
    477   old3 @2 :TestNewVersion;
    478   new1 @3 :Int64 = 987;
    479   new2 @4 :Text = "baz";
    480 }
    481 
    482 struct TestOldUnionVersion {
    483   union {
    484     a @0 :Void;
    485     b @1 :UInt64;
    486   }
    487 }
    488 
    489 struct TestNewUnionVersion {
    490   union {
    491     a :union {
    492       a0 @0 :Void;
    493       a1 @2 :UInt64;
    494     }
    495     b @1 :UInt64;
    496   }
    497 }
    498 
    499 struct TestStructUnion {
    500   un @0! :union {
    501     struct @1 :SomeStruct;
    502     object @2 :TestAnyPointer;
    503   }
    504 
    505   struct SomeStruct {
    506     someText @0 :Text;
    507     moreText @1 :Text;
    508   }
    509 }
    510 
    511 struct TestPrintInlineStructs {
    512   someText @0 :Text;
    513 
    514   structList @1 :List(InlineStruct);
    515   struct InlineStruct {
    516     int32Field @0 :Int32;
    517     textField @1 :Text;
    518   }
    519 }
    520 
    521 struct TestWholeFloatDefault {
    522   # At one point, these failed to compile in C++ because it would produce literals like "123f",
    523   # which is not valid; it needs to be "123.0f".
    524   field @0 :Float32 = 123;
    525   bigField @1 :Float32 = 2e30;
    526   const constant :Float32 = 456;
    527   const bigConstant :Float32 = 4e30;
    528 }
    529 
    530 struct TestGenerics(Foo, Bar) {
    531   foo @0 :Foo;
    532   rev @1 :TestGenerics(Bar, Foo);
    533 
    534   union {
    535     uv @2:Void;
    536     ug :group {
    537       ugfoo @3:Int32;
    538     }
    539   }
    540 
    541   list @4 :List(Inner);
    542   # At one time this failed to compile with MSVC due to poor expression SFINAE support.
    543 
    544   struct Inner {
    545     foo @0 :Foo;
    546     bar @1 :Bar;
    547   }
    548 
    549   struct Inner2(Baz) {
    550     bar @0 :Bar;
    551     baz @1 :Baz;
    552     innerBound @2 :Inner;
    553     innerUnbound @3 :TestGenerics.Inner;
    554 
    555     struct DeepNest(Qux) {
    556       foo @0 :Foo;
    557       bar @1 :Bar;
    558       baz @2 :Baz;
    559       qux @3 :Qux;
    560 
    561       interface DeepNestInterface(Quux) {
    562         # At one time this failed to compile.
    563         call @0 () -> ();
    564       }
    565     }
    566   }
    567 
    568   interface Interface(Qux) {
    569     call @0 Inner2(Text) -> (qux :Qux, gen :TestGenerics(TestAllTypes, TestAnyPointer));
    570   }
    571 
    572   annotation ann(struct) :Foo;
    573 
    574   using AliasFoo = Foo;
    575   using AliasInner = Inner;
    576   using AliasInner2 = Inner2;
    577   using AliasInner2Text = Inner2(Text);
    578   using AliasRev = TestGenerics(Bar, Foo);
    579 
    580   struct UseAliases {
    581     foo @0 :AliasFoo;
    582     inner @1 :AliasInner;
    583     inner2 @2 :AliasInner2;
    584     inner2Bind @3 :AliasInner2(Text);
    585     inner2Text @4 :AliasInner2Text;
    586     revFoo @5 :AliasRev.AliasFoo;
    587   }
    588 }
    589 
    590 struct BoxedText { text @0 :Text; }
    591 using BrandedAlias = TestGenerics(BoxedText, Text);
    592 
    593 struct TestGenericsWrapper(Foo, Bar) {
    594   value @0 :TestGenerics(Foo, Bar);
    595 }
    596 
    597 struct TestGenericsWrapper2 {
    598   value @0 :TestGenericsWrapper(Text, TestAllTypes);
    599 }
    600 
    601 interface TestImplicitMethodParams {
    602   call @0 [T, U] (foo :T, bar :U) -> TestGenerics(T, U);
    603 }
    604 
    605 interface TestImplicitMethodParamsInGeneric(V) {
    606   call @0 [T, U] (foo :T, bar :U) -> TestGenerics(T, U);
    607 }
    608 
    609 struct TestGenericsUnion(Foo, Bar) {
    610   # At one point this failed to compile.
    611 
    612   union {
    613     foo @0 :Foo;
    614     bar @1 :Bar;
    615   }
    616 }
    617 
    618 struct TestUseGenerics $TestGenerics(Text, Data).ann("foo") {
    619   basic @0 :TestGenerics(TestAllTypes, TestAnyPointer);
    620   inner @1 :TestGenerics(TestAllTypes, TestAnyPointer).Inner;
    621   inner2 @2 :TestGenerics(TestAllTypes, TestAnyPointer).Inner2(Text);
    622   unspecified @3 :TestGenerics;
    623   unspecifiedInner @4 :TestGenerics.Inner2(Text);
    624   wrapper @8 :TestGenericsWrapper(TestAllTypes, TestAnyPointer);
    625   cap @18 :TestGenerics(TestInterface, Text);
    626   genericCap @19 :TestGenerics(TestAllTypes, List(UInt32)).Interface(Data);
    627 
    628   default @5 :TestGenerics(TestAllTypes, Text) =
    629       (foo = (int16Field = 123), rev = (foo = "text", rev = (foo = (int16Field = 321))));
    630   defaultInner @6 :TestGenerics(TestAllTypes, Text).Inner =
    631       (foo = (int16Field = 123), bar = "text");
    632   defaultUser @7 :TestUseGenerics = (basic = (foo = (int16Field = 123)));
    633   defaultWrapper @9 :TestGenericsWrapper(Text, TestAllTypes) =
    634       (value = (foo = "text", rev = (foo = (int16Field = 321))));
    635   defaultWrapper2 @10 :TestGenericsWrapper2 =
    636       (value = (value = (foo = "text", rev = (foo = (int16Field = 321)))));
    637 
    638   aliasFoo @11 :TestGenerics(TestAllTypes, TestAnyPointer).AliasFoo = (int16Field = 123);
    639   aliasInner @12 :TestGenerics(TestAllTypes, TestAnyPointer).AliasInner
    640       = (foo = (int16Field = 123));
    641   aliasInner2 @13 :TestGenerics(TestAllTypes, TestAnyPointer).AliasInner2
    642       = (innerBound = (foo = (int16Field = 123)));
    643   aliasInner2Bind @14 :TestGenerics(TestAllTypes, TestAnyPointer).AliasInner2(List(UInt32))
    644       = (baz = [12, 34], innerBound = (foo = (int16Field = 123)));
    645   aliasInner2Text @15 :TestGenerics(TestAllTypes, TestAnyPointer).AliasInner2Text
    646       = (baz = "text", innerBound = (foo = (int16Field = 123)));
    647   aliasRev @16 :TestGenerics(TestAnyPointer, Text).AliasRev.AliasFoo = "text";
    648 
    649   useAliases @17 :TestGenerics(TestAllTypes, List(UInt32)).UseAliases = (
    650       foo = (int16Field = 123),
    651       inner = (foo = (int16Field = 123)),
    652       inner2 = (innerBound = (foo = (int16Field = 123))),
    653       inner2Bind = (baz = "text", innerBound = (foo = (int16Field = 123))),
    654       inner2Text = (baz = "text", innerBound = (foo = (int16Field = 123))),
    655       revFoo = [12, 34, 56]);
    656 }
    657 
    658 struct TestEmptyStruct {}
    659 
    660 struct TestConstants {
    661   const voidConst      :Void    = void;
    662   const boolConst      :Bool    = true;
    663   const int8Const      :Int8    = -123;
    664   const int16Const     :Int16   = -12345;
    665   const int32Const     :Int32   = -12345678;
    666   const int64Const     :Int64   = -123456789012345;
    667   const uint8Const     :UInt8   = 234;
    668   const uint16Const    :UInt16  = 45678;
    669   const uint32Const    :UInt32  = 3456789012;
    670   const uint64Const    :UInt64  = 12345678901234567890;
    671   const float32Const   :Float32 = 1234.5;
    672   const float64Const   :Float64 = -123e45;
    673   const textConst      :Text    = "foo";
    674   const dataConst      :Data    = "bar";
    675   const structConst    :TestAllTypes = (
    676       voidField      = void,
    677       boolField      = true,
    678       int8Field      = -12,
    679       int16Field     = 3456,
    680       int32Field     = -78901234,
    681       int64Field     = 56789012345678,
    682       uInt8Field     = 90,
    683       uInt16Field    = 1234,
    684       uInt32Field    = 56789012,
    685       uInt64Field    = 345678901234567890,
    686       float32Field   = -1.25e-10,
    687       float64Field   = 345,
    688       textField      = "baz",
    689       dataField      = "qux",
    690       structField    = (
    691           textField = "nested",
    692           structField = (textField = "really nested")),
    693       enumField      = baz,
    694       # interfaceField can't have a default
    695 
    696       voidList      = [void, void, void],
    697       boolList      = [false, true, false, true, true],
    698       int8List      = [12, -34, -0x80, 0x7f],
    699       int16List     = [1234, -5678, -0x8000, 0x7fff],
    700       int32List     = [12345678, -90123456, -0x80000000, 0x7fffffff],
    701       int64List     = [123456789012345, -678901234567890, -0x8000000000000000, 0x7fffffffffffffff],
    702       uInt8List     = [12, 34, 0, 0xff],
    703       uInt16List    = [1234, 5678, 0, 0xffff],
    704       uInt32List    = [12345678, 90123456, 0, 0xffffffff],
    705       uInt64List    = [123456789012345, 678901234567890, 0, 0xffffffffffffffff],
    706       float32List   = [0, 1234567, 1e37, -1e37, 1e-37, -1e-37],
    707       float64List   = [0, 123456789012345, 1e306, -1e306, 1e-306, -1e-306],
    708       textList      = ["quux", "corge", "grault"],
    709       dataList      = ["garply", "waldo", "fred"],
    710       structList    = [
    711           (textField = "x " "structlist"
    712                        " 1"),
    713           (textField = "x structlist 2"),
    714           (textField = "x structlist 3")],
    715       enumList      = [qux, bar, grault]
    716       # interfaceList can't have a default
    717       );
    718   const enumConst      :TestEnum = corge;
    719 
    720   const voidListConst      :List(Void)    = [void, void, void, void, void, void];
    721   const boolListConst      :List(Bool)    = [true, false, false, true];
    722   const int8ListConst      :List(Int8)    = [111, -111];
    723   const int16ListConst     :List(Int16)   = [11111, -11111];
    724   const int32ListConst     :List(Int32)   = [111111111, -111111111];
    725   const int64ListConst     :List(Int64)   = [1111111111111111111, -1111111111111111111];
    726   const uint8ListConst     :List(UInt8)   = [111, 222] ;
    727   const uint16ListConst    :List(UInt16)  = [33333, 44444];
    728   const uint32ListConst    :List(UInt32)  = [3333333333];
    729   const uint64ListConst    :List(UInt64)  = [11111111111111111111];
    730   const float32ListConst   :List(Float32) = [5555.5, inf, -inf, nan];
    731   const float64ListConst   :List(Float64) = [7777.75, inf, -inf, nan];
    732   const textListConst      :List(Text)    = ["plugh", "xyzzy", "thud"];
    733   const dataListConst      :List(Data)    = ["oops", "exhausted", "rfc3092"];
    734   const structListConst    :List(TestAllTypes) = [
    735       (textField = "structlist 1"),
    736       (textField = "structlist 2"),
    737       (textField = "structlist 3")];
    738   const enumListConst      :List(TestEnum) = [foo, garply];
    739 }
    740 
    741 const globalInt :UInt32 = 12345;
    742 const globalText :Text = "foobar";
    743 const globalStruct :TestAllTypes = (int32Field = 54321);
    744 const globalPrintableStruct :TestPrintInlineStructs = (someText = "foo");
    745 const derivedConstant :TestAllTypes = (
    746     uInt32Field = .globalInt,
    747     textField = TestConstants.textConst,
    748     structField = TestConstants.structConst,
    749     int16List = TestConstants.int16ListConst,
    750     structList = TestConstants.structListConst);
    751 
    752 const genericConstant :TestGenerics(TestAllTypes, Text) =
    753     (foo = (int16Field = 123), rev = (foo = "text", rev = (foo = (int16Field = 321))));
    754 
    755 const embeddedData :Data = embed "testdata/packed";
    756 const embeddedText :Text = embed "testdata/short.txt";
    757 const embeddedStruct :TestAllTypes = embed "testdata/binary";
    758 
    759 const nonAsciiText :Text = "♫ é ✓";
    760 
    761 struct TestAnyPointerConstants {
    762   anyKindAsStruct @0 :AnyPointer;
    763   anyStructAsStruct @1 :AnyStruct;
    764   anyKindAsList @2 :AnyPointer;
    765   anyListAsList @3 :AnyList;
    766 }
    767 
    768 const anyPointerConstants :TestAnyPointerConstants = (
    769   anyKindAsStruct = TestConstants.structConst,
    770   anyStructAsStruct = TestConstants.structConst,
    771   anyKindAsList = TestConstants.int32ListConst,
    772   anyListAsList = TestConstants.int32ListConst,
    773 );
    774 
    775 struct TestListOfAny {
    776   capList @0 :List(Capability);
    777   #listList @1 :List(AnyList); # TODO(0.10): Make List(AnyList) work correctly in C++ generated code.
    778 }
    779 
    780 interface TestInterface {
    781   foo @0 (i :UInt32, j :Bool) -> (x :Text);
    782   bar @1 () -> ();
    783   baz @2 (s: TestAllTypes);
    784 }
    785 
    786 interface TestExtends extends(TestInterface) {
    787   qux @0 ();
    788   corge @1 TestAllTypes -> ();
    789   grault @2 () -> TestAllTypes;
    790 }
    791 
    792 interface TestExtends2 extends(TestExtends) {}
    793 
    794 interface TestPipeline {
    795   getCap @0 (n: UInt32, inCap :TestInterface) -> (s: Text, outBox :Box);
    796   testPointers @1 (cap :TestInterface, obj :AnyPointer, list :List(TestInterface)) -> ();
    797   getAnyCap @2 (n: UInt32, inCap :Capability) -> (s: Text, outBox :AnyBox);
    798 
    799   getCapPipelineOnly @3 () -> (outBox :Box);
    800   # Never returns, but uses setPipeline() to make the pipeline work.
    801 
    802   struct Box {
    803     cap @0 :TestInterface;
    804   }
    805   struct AnyBox {
    806     cap @0 :Capability;
    807   }
    808 }
    809 
    810 interface TestCallOrder {
    811   getCallSequence @0 (expected: UInt32) -> (n: UInt32);
    812   # First call returns 0, next returns 1, ...
    813   #
    814   # The input `expected` is ignored but useful for disambiguating debug logs.
    815 }
    816 
    817 interface TestTailCallee {
    818   struct TailResult {
    819     i @0 :UInt32;
    820     t @1 :Text;
    821     c @2 :TestCallOrder;
    822   }
    823 
    824   foo @0 (i :Int32, t :Text) -> TailResult;
    825 }
    826 
    827 interface TestTailCaller {
    828   foo @0 (i :Int32, callee :TestTailCallee) -> TestTailCallee.TailResult;
    829 }
    830 
    831 interface TestStreaming {
    832   doStreamI @0 (i :UInt32) -> stream;
    833   doStreamJ @1 (j :UInt32) -> stream;
    834   finishStream @2 () -> (totalI :UInt32, totalJ :UInt32);
    835   # Test streaming. finishStream() returns the totals of the values streamed to the other calls.
    836 }
    837 
    838 interface TestHandle {}
    839 
    840 interface TestMoreStuff extends(TestCallOrder) {
    841   # Catch-all type that contains lots of testing methods.
    842 
    843   callFoo @0 (cap :TestInterface) -> (s: Text);
    844   # Call `cap.foo()`, check the result, and return "bar".
    845 
    846   callFooWhenResolved @1 (cap :TestInterface) -> (s: Text);
    847   # Like callFoo but waits for `cap` to resolve first.
    848 
    849   neverReturn @2 (cap :TestInterface) -> (capCopy :TestInterface);
    850   # Doesn't return.  You should cancel it.
    851 
    852   hold @3 (cap :TestInterface) -> ();
    853   # Returns immediately but holds on to the capability.
    854 
    855   callHeld @4 () -> (s: Text);
    856   # Calls the capability previously held using `hold` (and keeps holding it).
    857 
    858   getHeld @5 () -> (cap :TestInterface);
    859   # Returns the capability previously held using `hold` (and keeps holding it).
    860 
    861   echo @6 (cap :TestCallOrder) -> (cap :TestCallOrder);
    862   # Just returns the input cap.
    863 
    864   expectCancel @7 (cap :TestInterface) -> ();
    865   # evalLater()-loops forever, holding `cap`.  Must be canceled.
    866 
    867   methodWithDefaults @8 (a :Text, b :UInt32 = 123, c :Text = "foo") -> (d :Text, e :Text = "bar");
    868 
    869   methodWithNullDefault @12 (a :Text, b :TestInterface = null);
    870 
    871   getHandle @9 () -> (handle :TestHandle);
    872   # Get a new handle. Tests have an out-of-band way to check the current number of live handles, so
    873   # this can be used to test garbage collection.
    874 
    875   getNull @10 () -> (nullCap :TestMoreStuff);
    876   # Always returns a null capability.
    877 
    878   getEnormousString @11 () -> (str :Text);
    879   # Attempts to return an 100MB string. Should always fail.
    880 
    881   writeToFd @13 (fdCap1 :TestInterface, fdCap2 :TestInterface)
    882              -> (fdCap3 :TestInterface, secondFdPresent :Bool);
    883   # Expects fdCap1 and fdCap2 wrap socket file descriptors. Writes "foo" to the first and "bar" to
    884   # the second. Also creates a socketpair, writes "baz" to one end, and returns the other end.
    885 
    886   throwException @14 ();
    887   throwRemoteException @15 ();
    888 }
    889 
    890 interface TestMembrane {
    891   makeThing @0 () -> (thing :Thing);
    892   callPassThrough @1 (thing :Thing, tailCall :Bool) -> Result;
    893   callIntercept @2 (thing :Thing, tailCall :Bool) -> Result;
    894   loopback @3 (thing :Thing) -> (thing :Thing);
    895 
    896   waitForever @4 ();
    897 
    898   interface Thing {
    899     passThrough @0 () -> Result;
    900     intercept @1 () -> Result;
    901   }
    902 
    903   struct Result {
    904     text @0 :Text;
    905   }
    906 }
    907 
    908 struct TestContainMembrane {
    909   cap @0 :TestMembrane.Thing;
    910   list @1 :List(TestMembrane.Thing);
    911 }
    912 
    913 struct TestTransferCap {
    914   list @0 :List(Element);
    915   struct Element {
    916     text @0 :Text;
    917     cap @1 :TestInterface;
    918   }
    919 }
    920 
    921 interface TestKeywordMethods {
    922   delete @0 ();
    923   class @1 ();
    924   void @2 ();
    925   return @3 ();
    926 }
    927 
    928 interface TestAuthenticatedBootstrap(VatId) {
    929   getCallerId @0 () -> (caller :VatId);
    930 }
    931 
    932 struct TestSturdyRef {
    933   hostId @0 :TestSturdyRefHostId;
    934   objectId @1 :AnyPointer;
    935 }
    936 
    937 struct TestSturdyRefHostId {
    938   host @0 :Text;
    939 }
    940 
    941 struct TestSturdyRefObjectId {
    942   tag @0 :Tag;
    943   enum Tag {
    944     testInterface @0;
    945     testExtends @1;
    946     testPipeline @2;
    947     testTailCallee @3;
    948     testTailCaller @4;
    949     testMoreStuff @5;
    950   }
    951 }
    952 
    953 struct TestProvisionId {}
    954 struct TestRecipientId {}
    955 struct TestThirdPartyCapId {}
    956 struct TestJoinResult {}
    957 
    958 struct TestNameAnnotation $Cxx.name("RenamedStruct") {
    959   union {
    960     badFieldName @0 :Bool $Cxx.name("goodFieldName");
    961     bar @1 :Int8;
    962   }
    963 
    964   enum BadlyNamedEnum $Cxx.name("RenamedEnum") {
    965     foo @0;
    966     bar @1;
    967     baz @2 $Cxx.name("qux");
    968   }
    969 
    970   anotherBadFieldName @2 :BadlyNamedEnum $Cxx.name("anotherGoodFieldName");
    971 
    972   struct NestedStruct $Cxx.name("RenamedNestedStruct") {
    973     badNestedFieldName @0 :Bool $Cxx.name("goodNestedFieldName");
    974     anotherBadNestedFieldName @1 :NestedStruct $Cxx.name("anotherGoodNestedFieldName");
    975 
    976     enum DeeplyNestedEnum $Cxx.name("RenamedDeeplyNestedEnum") {
    977       quux @0;
    978       corge @1;
    979       grault @2 $Cxx.name("garply");
    980     }
    981   }
    982 
    983   badlyNamedUnion :union $Cxx.name("renamedUnion") {
    984     badlyNamedGroup :group $Cxx.name("renamedGroup") {
    985       foo @3 :Void;
    986       bar @4 :Void;
    987     }
    988     baz @5 :NestedStruct $Cxx.name("qux");
    989   }
    990 }
    991 
    992 interface TestNameAnnotationInterface $Cxx.name("RenamedInterface") {
    993   badlyNamedMethod @0 (badlyNamedParam :UInt8 $Cxx.name("renamedParam")) $Cxx.name("renamedMethod");
    994 }