Home | History | Annotate | Download | only in Tests
      1 // Protocol Buffers - Google's data interchange format
      2 // Copyright 2011 Google Inc.  All rights reserved.
      3 //
      4 // Redistribution and use in source and binary forms, with or without
      5 // modification, are permitted provided that the following conditions are
      6 // met:
      7 //
      8 //     * Redistributions of source code must retain the above copyright
      9 // notice, this list of conditions and the following disclaimer.
     10 //     * Redistributions in binary form must reproduce the above
     11 // copyright notice, this list of conditions and the following disclaimer
     12 // in the documentation and/or other materials provided with the
     13 // distribution.
     14 //     * Neither the name of Google Inc. nor the names of its
     15 // contributors may be used to endorse or promote products derived from
     16 // this software without specific prior written permission.
     17 //
     18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 
     30 syntax = "proto2";
     31 
     32 import "google/protobuf/unittest.proto";
     33 
     34 package protobuf_unittest;
     35 
     36 // Using the messages in unittest.proto, setup for recursive cases for testing
     37 // extensions at various depths.
     38 extend TestAllExtensions {
     39   optional TestAllExtensions recursive_extension = 86;
     40 }
     41 
     42 // Recursive message to for testing autocreators at different depths.
     43 message TestRecursiveMessageWithRepeatedField {
     44   optional TestRecursiveMessageWithRepeatedField a = 1;
     45   repeated int32 i = 2;
     46   repeated string str = 3;
     47   map<int32, int32> i_to_i = 4;
     48   map<string, string> str_to_str = 5;
     49 }
     50 
     51 // Recursive message and extension to for testing autocreators at different
     52 // depths.
     53 message TestRecursiveExtension {
     54   optional TestRecursiveExtension recursive_sub_message = 1;
     55   repeated int32 repeated_value = 2;
     56   extensions 1000 to max;
     57 }
     58 
     59 extend TestRecursiveExtension {
     60   optional TestRecursiveExtension recursive_message_extension = 1000;
     61 }
     62 
     63 message self {
     64   message super {
     65     optional int32 description = 1;
     66   }
     67 
     68   enum autorelease {
     69     retain      = 1;
     70     release     = 2;
     71     retainCount = 3;
     72   }
     73 
     74   // Singular
     75   optional   bool id                =  1;
     76   optional   bool _cmd              =  2;
     77   optional   bool in                =  3;
     78   optional   bool out               =  4;
     79   optional   bool inout             =  5;
     80   optional   bool bycopy            =  6;
     81   optional   bool byref             =  7;
     82   optional   bool oneway            =  8;
     83   optional   bool dealloc           =  9;
     84   optional   bool zone              = 10;
     85   optional   bool isProxy           = 11;
     86   optional   bool copy              = 12;
     87   optional   bool readonly          = 13;
     88   optional   bool default           = 14;
     89   optional   bool assign            = 15;
     90   optional   bool getter            = 16;
     91   optional   bool setter            = 17;
     92   optional   bool weak              = 18;
     93   optional   bool public            = 19;
     94   optional   bool case              = 20;
     95 
     96   optional   autorelease SubEnum    = 25;
     97 
     98  optional group New = 50 {
     99    optional string copy = 51;
    100  }
    101   optional group MutableCopy = 60 {
    102     optional int32 extensionRegistry = 61;
    103   }
    104 
    105   extensions 90 to 94;
    106 
    107 }
    108 
    109 enum retain {
    110   count          = 4;
    111   initialized    = 5;
    112   serializedSize = 6;
    113 }
    114 
    115 message ObjCPropertyNaming {
    116   // Test that the properties properly get things all caps.
    117   optional string url           = 1;
    118   optional string thumbnail_url = 2;
    119   optional string url_foo       = 3;
    120   optional string some_url_blah = 4;
    121   optional string http          = 5;
    122   optional string https         = 6;
    123   // This one doesn't.
    124   repeated string urls          = 7;
    125 }
    126 
    127 // EnumValueShortName: The short names shouldn't get suffixes/prefixes.
    128 enum Foo {
    129   SERIALIZED_SIZE = 1;
    130   SIZE            = 2;
    131   OTHER           = 3;
    132 }
    133 
    134 // EnumValueShortName: The enum name gets a prefix.
    135 enum Category {
    136   RED  = 1;
    137   BLUE = 2;
    138 }
    139 
    140 // EnumValueShortName: Twist case, full name gets PB, but the short names
    141 // should still end up correct.
    142 enum Time {
    143   BASE            = 1;
    144   RECORD          = 2;
    145   SOMETHING_ELSE  = 3;
    146 }
    147 
    148 extend self {
    149   repeated    int32 debugDescription    =  90 [packed = true];
    150   repeated    int64 finalize            =  91 [packed = true];
    151   repeated   uint32 hash                =  92 [packed = true];
    152   repeated   uint64 classForCoder       =  93 [packed = true];
    153   repeated   sint32 byref               =  94 [packed = true];
    154 }
    155 
    156 // Test handing of fields that start with init* since Xcode 5's ARC support
    157 // doesn't like messages that look like initializers but aren't.
    158 message ObjCInitFoo {
    159   optional string init_val = 11;
    160   optional int32 init_size = 12;
    161   optional self init_self = 13;
    162 
    163   repeated string init_vals = 21;
    164   repeated int32 init_sizes = 22;
    165   repeated self init_selfs = 23;
    166 }
    167 
    168 // Test handling of fields that start with retained names.
    169 message ObjCRetainedFoo {
    170   optional string new_val_lower_complex = 11;
    171   optional string new_Val_upper_complex = 12;
    172   optional string newvalue_lower_no_underscore_complex = 13;
    173   optional string newValue_upper_no_underscore_complex = 14;
    174 
    175   optional int32 new_val_lower_primitive = 15;
    176   optional int32 new_Val_upper_primitive = 16;
    177   optional int32 newvalue_lower_no_underscore_primitive = 17;
    178   optional int32 newValue_upper_no_underscore_primitive = 18;
    179 
    180   optional self new_val_lower_message = 19;
    181   optional self new_Val_upper_message = 20;
    182   optional self newvalue_lower_no_underscore_message = 21;
    183   optional self newValue_upper_no_underscore_message = 22;
    184 
    185   optional Foo new_val_lower_enum = 23;
    186   optional Foo new_Val_upper_enum = 24;
    187   optional Foo newvalue_lower_no_underscore_enum = 25;
    188   optional Foo newValue_upper_no_underscore_enum = 26;
    189 
    190   repeated string new_val_lower_complex_repeated = 111;
    191   repeated string new_Val_upper_complex_repeated = 112;
    192   repeated string newvalue_lower_no_underscore_complex_repeated = 113;
    193   repeated string newValue_upper_no_underscore_complex_repeated = 114;
    194 
    195   repeated int32 new_val_lower_primitive_repeated = 115;
    196   repeated int32 new_Val_upper_primitive_repeated = 116;
    197   repeated int32 newvalue_lower_no_underscore_primitive_repeated = 117;
    198   repeated int32 newValue_upper_no_underscore_primitive_repeated = 118;
    199 
    200   repeated self new_val_lower_message_repeated = 119;
    201   repeated self new_Val_upper_message_repeated = 120;
    202   repeated self newvalue_lower_no_underscore_message_repeated = 121;
    203   repeated self newValue_upper_no_underscore_message_repeated = 122;
    204 
    205   repeated Foo new_val_lower_enum_repeated = 123;
    206   repeated Foo new_Val_upper_enum_repeated = 124;
    207   repeated Foo newvalue_lower_no_underscore_enum_repeated = 125;
    208   repeated Foo newValue_upper_no_underscore_enum_repeated = 126;
    209 
    210   optional string alloc_val_lower_complex = 211;
    211   optional string alloc_Val_upper_complex = 212;
    212   optional string allocvalue_lower_no_underscore_complex = 213;
    213   optional string allocValue_upper_no_underscore_complex = 214;
    214 
    215   optional int32 alloc_val_lower_primitive = 215;
    216   optional int32 alloc_Val_upper_primitive = 216;
    217   optional int32 allocvalue_lower_no_underscore_primitive = 217;
    218   optional int32 allocValue_upper_no_underscore_primitive = 218;
    219 
    220   optional self alloc_val_lower_message = 219;
    221   optional self alloc_Val_upper_message = 220;
    222   optional self allocvalue_lower_no_underscore_message = 221;
    223   optional self allocValue_upper_no_underscore_message = 222;
    224 
    225   optional Foo alloc_val_lower_enum = 223;
    226   optional Foo alloc_Val_upper_enum = 224;
    227   optional Foo allocvalue_lower_no_underscore_enum = 225;
    228   optional Foo allocValue_upper_no_underscore_enum = 226;
    229 
    230   repeated string alloc_val_lower_complex_repeated = 311;
    231   repeated string alloc_Val_upper_complex_repeated = 312;
    232   repeated string allocvalue_lower_no_underscore_complex_repeated = 313;
    233   repeated string allocValue_upper_no_underscore_complex_repeated = 314;
    234 
    235   repeated int32 alloc_val_lower_primitive_repeated = 315;
    236   repeated int32 alloc_Val_upper_primitive_repeated = 316;
    237   repeated int32 allocvalue_lower_no_underscore_primitive_repeated = 317;
    238   repeated int32 allocValue_upper_no_underscore_primitive_repeated = 318;
    239 
    240   repeated self alloc_val_lower_message_repeated = 319;
    241   repeated self alloc_Val_upper_message_repeated = 320;
    242   repeated self allocvalue_lower_no_underscore_message_repeated = 321;
    243   repeated self allocValue_upper_no_underscore_message_repeated = 322;
    244 
    245   repeated Foo alloc_val_lower_enum_repeated = 323;
    246   repeated Foo alloc_Val_upper_enum_repeated = 324;
    247   repeated Foo allocvalue_lower_no_underscore_enum_repeated = 325;
    248   repeated Foo allocValue_upper_no_underscore_enum_repeated = 326;
    249 
    250   optional string copy_val_lower_complex = 411;
    251   optional string copy_Val_upper_complex = 412;
    252   optional string copyvalue_lower_no_underscore_complex = 413;
    253   optional string copyValue_upper_no_underscore_complex = 414;
    254 
    255   optional int32 copy_val_lower_primitive = 415;
    256   optional int32 copy_Val_upper_primitive = 416;
    257   optional int32 copyvalue_lower_no_underscore_primitive = 417;
    258   optional int32 copyValue_upper_no_underscore_primitive = 418;
    259 
    260   optional self copy_val_lower_message = 419;
    261   optional self copy_Val_upper_message = 420;
    262   optional self copyvalue_lower_no_underscore_message = 421;
    263   optional self copyValue_upper_no_underscore_message = 422;
    264 
    265   optional Foo copy_val_lower_enum = 423;
    266   optional Foo copy_Val_upper_enum = 424;
    267   optional Foo copyvalue_lower_no_underscore_enum = 425;
    268   optional Foo copyValue_upper_no_underscore_enum = 426;
    269 
    270   repeated string copy_val_lower_complex_repeated = 511;
    271   repeated string copy_Val_upper_complex_repeated = 512;
    272   repeated string copyvalue_lower_no_underscore_complex_repeated = 513;
    273   repeated string copyValue_upper_no_underscore_complex_repeated = 514;
    274 
    275   repeated int32 copy_val_lower_primitive_repeated = 515;
    276   repeated int32 copy_Val_upper_primitive_repeated = 516;
    277   repeated int32 copyvalue_lower_no_underscore_primitive_repeated = 517;
    278   repeated int32 copyValue_upper_no_underscore_primitive_repeated = 518;
    279 
    280   repeated self copy_val_lower_message_repeated = 519;
    281   repeated self copy_Val_upper_message_repeated = 520;
    282   repeated self copyvalue_lower_no_underscore_message_repeated = 521;
    283   repeated self copyValue_upper_no_underscore_message_repeated = 522;
    284 
    285   repeated Foo copy_val_lower_enum_repeated = 523;
    286   repeated Foo copy_Val_upper_enum_repeated = 524;
    287   repeated Foo copyvalue_lower_no_underscore_enum_repeated = 525;
    288   repeated Foo copyValue_upper_no_underscore_enum_repeated = 526;
    289 
    290   optional string mutableCopy_val_lower_complex = 611;
    291   optional string mutableCopy_Val_upper_complex = 612;
    292   optional string mutableCopyvalue_lower_no_underscore_complex = 613;
    293   optional string mutableCopyValue_upper_no_underscore_complex = 614;
    294 
    295   optional int32 mutableCopy_val_lower_primitive = 615;
    296   optional int32 mutableCopy_Val_upper_primitive = 616;
    297   optional int32 mutableCopyvalue_lower_no_underscore_primitive = 617;
    298   optional int32 mutableCopyValue_upper_no_underscore_primitive = 618;
    299 
    300   optional self mutableCopy_val_lower_message = 619;
    301   optional self mutableCopy_Val_upper_message = 620;
    302   optional self mutableCopyvalue_lower_no_underscore_message = 621;
    303   optional self mutableCopyValue_upper_no_underscore_message = 622;
    304 
    305   optional Foo mutableCopy_val_lower_enum = 623;
    306   optional Foo mutableCopy_Val_upper_enum = 624;
    307   optional Foo mutableCopyvalue_lower_no_underscore_enum = 625;
    308   optional Foo mutableCopyValue_upper_no_underscore_enum = 626;
    309 
    310   repeated string mutableCopy_val_lower_complex_repeated = 711;
    311   repeated string mutableCopy_Val_upper_complex_repeated = 712;
    312   repeated string mutableCopyvalue_lower_no_underscore_complex_repeated = 713;
    313   repeated string mutableCopyValue_upper_no_underscore_complex_repeated = 714;
    314 
    315   repeated int32 mutableCopy_val_lower_primitive_repeated = 715;
    316   repeated int32 mutableCopy_Val_upper_primitive_repeated = 716;
    317   repeated int32 mutableCopyvalue_lower_no_underscore_primitive_repeated = 717;
    318   repeated int32 mutableCopyValue_upper_no_underscore_primitive_repeated = 718;
    319 
    320   repeated self mutableCopy_val_lower_message_repeated = 719;
    321   repeated self mutableCopy_Val_upper_message_repeated = 720;
    322   repeated self mutableCopyvalue_lower_no_underscore_message_repeated = 721;
    323   repeated self mutableCopyValue_upper_no_underscore_message_repeated = 722;
    324 
    325   repeated Foo mutableCopy_val_lower_enum_repeated = 723;
    326   repeated Foo mutableCopy_Val_upper_enum_repeated = 724;
    327   repeated Foo mutableCopyvalue_lower_no_underscore_enum_repeated = 725;
    328   repeated Foo mutableCopyValue_upper_no_underscore_enum_repeated = 726;
    329 }
    330 
    331 // Test handling of fields that are the retained names.
    332 message ObjCRetainedComplex {
    333   optional string new = 1;
    334   optional string alloc = 2;
    335   optional string copy = 3;
    336   optional string mutableCopy = 4;
    337 }
    338 
    339 message ObjCRetainedComplexRepeated {
    340   repeated string new = 1;
    341   repeated string alloc = 2;
    342   repeated string copy = 3;
    343   repeated string mutableCopy = 4;
    344 }
    345 
    346 message ObjCRetainedPrimitive {
    347   optional int32 new = 1;
    348   optional int32 alloc = 2;
    349   optional int32 copy = 3;
    350   optional int32 mutableCopy = 4;
    351 }
    352 
    353 message ObjCRetainedPrimitiveRepeated {
    354   repeated int32 new = 1;
    355   repeated int32 alloc = 2;
    356   repeated int32 copy = 3;
    357   repeated int32 mutableCopy = 4;
    358 }
    359 
    360 message ObjCRetainedMessage {
    361   optional self new = 1;
    362   optional self alloc = 2;
    363   optional self copy = 3;
    364   optional self mutableCopy = 4;
    365 }
    366 
    367 message ObjCRetainedMessageRepeated {
    368   repeated self new = 1;
    369   repeated self alloc = 2;
    370   repeated self copy = 3;
    371   repeated self mutableCopy = 4;
    372 }
    373 
    374 // Test Handling some MacTypes
    375 message Point {
    376   message Rect {
    377     optional int32 TimeValue = 1;
    378   }
    379 }
    380 
    381 // Test some weird defaults that we see in protos.
    382 message ObjcWeirdDefaults {
    383   // Set default values that match the protocol buffer defined defaults to
    384   // confirm hasDefault and the default values are set correctly.
    385   optional string foo = 1 [default = ""];
    386   optional bytes bar = 2 [default = ""];
    387 }
    388 
    389 // Used to confirm negative enum values work as expected.
    390 message EnumTestMsg {
    391   enum MyEnum {
    392     ZERO    = 0;
    393     ONE     = 1;
    394     TWO     = 2;
    395     NEG_ONE = -1;
    396     NEG_TWO = -2;
    397   }
    398   optional MyEnum foo = 1;
    399   optional MyEnum bar = 2 [default = ONE];
    400   optional MyEnum baz = 3 [default = NEG_ONE];
    401 
    402   repeated MyEnum mumble = 4;
    403 }
    404 
    405 // Test case for https://github.com/google/protobuf/issues/1453
    406 // Message with no explicit defaults, but a non zero default for an enum.
    407 message MessageWithOneBasedEnum {
    408   enum OneBasedEnum {
    409     ONE = 1;
    410     TWO = 2;
    411   }
    412   optional OneBasedEnum enum_field = 1;
    413 }
    414 
    415 // Message with all bools for testing things related to bool storage.
    416 message BoolOnlyMessage {
    417   optional bool bool_field_1 = 1;
    418   optional bool bool_field_2 = 2;
    419   optional bool bool_field_3 = 3;
    420   optional bool bool_field_4 = 4;
    421   optional bool bool_field_5 = 5;
    422   optional bool bool_field_6 = 6;
    423   optional bool bool_field_7 = 7;
    424   optional bool bool_field_8 = 8;
    425   optional bool bool_field_9 = 9;
    426   optional bool bool_field_10 = 10;
    427   optional bool bool_field_11 = 11;
    428   optional bool bool_field_12 = 12;
    429   optional bool bool_field_13 = 13;
    430   optional bool bool_field_14 = 14;
    431   optional bool bool_field_15 = 15;
    432   optional bool bool_field_16 = 16;
    433   optional bool bool_field_17 = 17;
    434   optional bool bool_field_18 = 18;
    435   optional bool bool_field_19 = 19;
    436   optional bool bool_field_20 = 20;
    437   optional bool bool_field_21 = 21;
    438   optional bool bool_field_22 = 22;
    439   optional bool bool_field_23 = 23;
    440   optional bool bool_field_24 = 24;
    441   optional bool bool_field_25 = 25;
    442   optional bool bool_field_26 = 26;
    443   optional bool bool_field_27 = 27;
    444   optional bool bool_field_28 = 28;
    445   optional bool bool_field_29 = 29;
    446   optional bool bool_field_30 = 30;
    447   optional bool bool_field_31 = 31;
    448   optional bool bool_field_32 = 32;
    449 }
    450