PageRenderTime 38ms CodeModel.GetById 9ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 1ms

/thirdparty/breakpad/third_party/protobuf/protobuf/src/google/protobuf/unittest_custom_options.proto

http://github.com/tomahawk-player/tomahawk
Protocol Buffers | 366 lines | 236 code | 66 blank | 64 comment | 0 complexity | 1e5cbaae39b4428e000337c4ae8d3793 MD5 | raw file
  1// Protocol Buffers - Google's data interchange format
  2// Copyright 2008 Google Inc.  All rights reserved.
  3// http://code.google.com/p/protobuf/
  4//
  5// Redistribution and use in source and binary forms, with or without
  6// modification, are permitted provided that the following conditions are
  7// met:
  8//
  9//     * Redistributions of source code must retain the above copyright
 10// notice, this list of conditions and the following disclaimer.
 11//     * Redistributions in binary form must reproduce the above
 12// copyright notice, this list of conditions and the following disclaimer
 13// in the documentation and/or other materials provided with the
 14// distribution.
 15//     * Neither the name of Google Inc. nor the names of its
 16// contributors may be used to endorse or promote products derived from
 17// this software without specific prior written permission.
 18//
 19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30
 31// Author: benjy@google.com (Benjy Weinberger)
 32//  Based on original Protocol Buffers design by
 33//  Sanjay Ghemawat, Jeff Dean, and others.
 34//
 35// A proto file used to test the "custom options" feature of proto2.
 36
 37
 38// Some generic_services option(s) added automatically.
 39// See:  http://go/proto2-generic-services-default
 40option cc_generic_services = true;     // auto-added
 41option java_generic_services = true;   // auto-added
 42option py_generic_services = true;
 43
 44// A custom file option (defined below).
 45option (file_opt1) = 9876543210;
 46
 47import "google/protobuf/descriptor.proto";
 48
 49// We don't put this in a package within proto2 because we need to make sure
 50// that the generated code doesn't depend on being in the proto2 namespace.
 51package protobuf_unittest;
 52
 53
 54// Some simple test custom options of various types.
 55
 56extend google.protobuf.FileOptions {
 57  optional uint64 file_opt1 = 7736974;
 58}
 59
 60extend google.protobuf.MessageOptions {
 61  optional int32 message_opt1 = 7739036;
 62}
 63
 64extend google.protobuf.FieldOptions {
 65  optional fixed64 field_opt1 = 7740936;
 66  // This is useful for testing that we correctly register default values for
 67  // extension options.
 68  optional int32 field_opt2 = 7753913 [default=42];
 69}
 70
 71extend google.protobuf.EnumOptions {
 72  optional sfixed32 enum_opt1 = 7753576;
 73}
 74
 75extend google.protobuf.EnumValueOptions {
 76  optional int32 enum_value_opt1 = 1560678;
 77}
 78
 79extend google.protobuf.ServiceOptions {
 80  optional sint64 service_opt1 = 7887650;
 81}
 82
 83enum MethodOpt1 {
 84  METHODOPT1_VAL1 = 1;
 85  METHODOPT1_VAL2 = 2;
 86}
 87
 88extend google.protobuf.MethodOptions {
 89  optional MethodOpt1 method_opt1 = 7890860;
 90}
 91
 92// A test message with custom options at all possible locations (and also some
 93// regular options, to make sure they interact nicely).
 94message TestMessageWithCustomOptions {
 95  option message_set_wire_format = false;
 96
 97  option (message_opt1) = -56;
 98
 99  optional string field1 = 1 [ctype=CORD,
100                              (field_opt1)=8765432109];
101
102  enum AnEnum {
103    option (enum_opt1) = -789;
104
105    ANENUM_VAL1 = 1;
106    ANENUM_VAL2 = 2 [(enum_value_opt1) = 123];
107  }
108}
109
110
111// A test RPC service with custom options at all possible locations (and also
112// some regular options, to make sure they interact nicely).
113message CustomOptionFooRequest {
114}
115
116message CustomOptionFooResponse {
117}
118
119service TestServiceWithCustomOptions {
120  option (service_opt1) = -9876543210;
121
122  rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
123    option (method_opt1) = METHODOPT1_VAL2;
124  }
125}
126
127
128
129// Options of every possible field type, so we can test them all exhaustively.
130
131message DummyMessageContainingEnum {
132  enum TestEnumType {
133    TEST_OPTION_ENUM_TYPE1 = 22;
134    TEST_OPTION_ENUM_TYPE2 = -23;
135  }
136}
137
138message DummyMessageInvalidAsOptionType {
139}
140
141extend google.protobuf.MessageOptions {
142  optional         bool     bool_opt = 7706090;
143  optional        int32    int32_opt = 7705709;
144  optional        int64    int64_opt = 7705542;
145  optional       uint32   uint32_opt = 7704880;
146  optional       uint64   uint64_opt = 7702367;
147  optional       sint32   sint32_opt = 7701568;
148  optional       sint64   sint64_opt = 7700863;
149  optional      fixed32  fixed32_opt = 7700307;
150  optional      fixed64  fixed64_opt = 7700194;
151  optional     sfixed32 sfixed32_opt = 7698645;
152  optional     sfixed64 sfixed64_opt = 7685475;
153  optional        float    float_opt = 7675390;
154  optional       double   double_opt = 7673293;
155  optional       string   string_opt = 7673285;
156  optional        bytes    bytes_opt = 7673238;
157  optional DummyMessageContainingEnum.TestEnumType enum_opt = 7673233;
158  optional DummyMessageInvalidAsOptionType message_type_opt = 7665967;
159}
160
161message CustomOptionMinIntegerValues {
162  option     (bool_opt) = false;
163  option    (int32_opt) = -0x80000000;
164  option    (int64_opt) = -0x8000000000000000;
165  option   (uint32_opt) = 0;
166  option   (uint64_opt) = 0;
167  option   (sint32_opt) = -0x80000000;
168  option   (sint64_opt) = -0x8000000000000000;
169  option  (fixed32_opt) = 0;
170  option  (fixed64_opt) = 0;
171  option (sfixed32_opt) = -0x80000000;
172  option (sfixed64_opt) = -0x8000000000000000;
173}
174
175message CustomOptionMaxIntegerValues {
176  option     (bool_opt) = true;
177  option    (int32_opt) = 0x7FFFFFFF;
178  option    (int64_opt) = 0x7FFFFFFFFFFFFFFF;
179  option   (uint32_opt) = 0xFFFFFFFF;
180  option   (uint64_opt) = 0xFFFFFFFFFFFFFFFF;
181  option   (sint32_opt) = 0x7FFFFFFF;
182  option   (sint64_opt) = 0x7FFFFFFFFFFFFFFF;
183  option  (fixed32_opt) = 0xFFFFFFFF;
184  option  (fixed64_opt) = 0xFFFFFFFFFFFFFFFF;
185  option (sfixed32_opt) = 0x7FFFFFFF;
186  option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF;
187}
188
189message CustomOptionOtherValues {
190  option  (int32_opt) = -100;  // To test sign-extension.
191  option  (float_opt) = 12.3456789;
192  option (double_opt) = 1.234567890123456789;
193  option (string_opt) = "Hello, \"World\"";
194  option  (bytes_opt) = "Hello\0World";
195  option   (enum_opt) = TEST_OPTION_ENUM_TYPE2;
196}
197
198message SettingRealsFromPositiveInts {
199  option  (float_opt) = 12;
200  option (double_opt) = 154;
201}
202
203message SettingRealsFromNegativeInts {
204  option  (float_opt) = -12;
205  option  (double_opt) = -154;
206}
207
208// Options of complex message types, themselves combined and extended in
209// various ways.
210
211message ComplexOptionType1 {
212  optional int32 foo = 1;
213  optional int32 foo2 = 2;
214  optional int32 foo3 = 3;
215
216  extensions 100 to max;
217}
218
219message ComplexOptionType2 {
220  optional ComplexOptionType1 bar = 1;
221  optional int32 baz = 2;
222
223  message ComplexOptionType4 {
224    optional int32 waldo = 1;
225
226    extend google.protobuf.MessageOptions {
227      optional ComplexOptionType4 complex_opt4 = 7633546;
228    }
229  }
230
231  optional ComplexOptionType4 fred = 3;
232
233  extensions 100 to max;
234}
235
236message ComplexOptionType3 {
237  optional int32 qux = 1;
238
239  optional group ComplexOptionType5 = 2 {
240    optional int32 plugh = 3;
241  }
242}
243
244extend ComplexOptionType1 {
245  optional int32 quux = 7663707;
246  optional ComplexOptionType3 corge = 7663442;
247}
248
249extend ComplexOptionType2 {
250  optional int32 grault = 7650927;
251  optional ComplexOptionType1 garply = 7649992;
252}
253
254extend google.protobuf.MessageOptions {
255  optional protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756;
256  optional ComplexOptionType2 complex_opt2 = 7636949;
257  optional ComplexOptionType3 complex_opt3 = 7636463;
258  optional group ComplexOpt6 = 7595468 {
259    optional int32 xyzzy = 7593951;
260  }
261}
262
263// Note that we try various different ways of naming the same extension.
264message VariousComplexOptions {
265  option (.protobuf_unittest.complex_opt1).foo = 42;
266  option (protobuf_unittest.complex_opt1).(.protobuf_unittest.quux) = 324;
267  option (.protobuf_unittest.complex_opt1).(protobuf_unittest.corge).qux = 876;
268  option (complex_opt2).baz = 987;
269  option (complex_opt2).(grault) = 654;
270  option (complex_opt2).bar.foo = 743;
271  option (complex_opt2).bar.(quux) = 1999;
272  option (complex_opt2).bar.(protobuf_unittest.corge).qux = 2008;
273  option (complex_opt2).(garply).foo = 741;
274  option (complex_opt2).(garply).(.protobuf_unittest.quux) = 1998;
275  option (complex_opt2).(protobuf_unittest.garply).(corge).qux = 2121;
276  option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971;
277  option (complex_opt2).fred.waldo = 321;
278  option (protobuf_unittest.complex_opt3).qux = 9;
279  option (complex_opt3).complexoptiontype5.plugh = 22;
280  option (complexopt6).xyzzy = 24;
281}
282
283// ------------------------------------------------------
284// Definitions for testing aggregate option parsing.
285// See descriptor_unittest.cc.
286
287message AggregateMessageSet {
288  option message_set_wire_format = true;
289  extensions 4 to max;
290}
291
292message AggregateMessageSetElement {
293  extend AggregateMessageSet {
294    optional AggregateMessageSetElement message_set_extension = 15447542;
295  }
296  optional string s = 1;
297}
298
299// A helper type used to test aggregate option parsing
300message Aggregate {
301  optional int32 i = 1;
302  optional string s = 2;
303
304  // A nested object
305  optional Aggregate sub = 3;
306
307  // To test the parsing of extensions inside aggregate values
308  optional google.protobuf.FileOptions file = 4;
309  extend google.protobuf.FileOptions {
310    optional Aggregate nested = 15476903;
311  }
312
313  // An embedded message set
314  optional AggregateMessageSet mset = 5;
315}
316
317// Allow Aggregate to be used as an option at all possible locations
318// in the .proto grammer.
319extend google.protobuf.FileOptions      { optional Aggregate fileopt    = 15478479; }
320extend google.protobuf.MessageOptions   { optional Aggregate msgopt     = 15480088; }
321extend google.protobuf.FieldOptions     { optional Aggregate fieldopt   = 15481374; }
322extend google.protobuf.EnumOptions      { optional Aggregate enumopt    = 15483218; }
323extend google.protobuf.EnumValueOptions { optional Aggregate enumvalopt = 15486921; }
324extend google.protobuf.ServiceOptions   { optional Aggregate serviceopt = 15497145; }
325extend google.protobuf.MethodOptions    { optional Aggregate methodopt  = 15512713; }
326
327// Try using AggregateOption at different points in the proto grammar
328option (fileopt) = {
329  s: 'FileAnnotation'
330  // Also test the handling of comments
331  /* of both types */ i: 100
332
333  sub { s: 'NestedFileAnnotation' }
334
335  // Include a google.protobuf.FileOptions and recursively extend it with
336  // another fileopt.
337  file {
338    [protobuf_unittest.fileopt] {
339      s:'FileExtensionAnnotation'
340    }
341  }
342
343  // A message set inside an option value
344  mset {
345    [protobuf_unittest.AggregateMessageSetElement.message_set_extension] {
346      s: 'EmbeddedMessageSetElement'
347    }
348  }
349};
350
351message AggregateMessage {
352  option (msgopt) = { i:101 s:'MessageAnnotation' };
353  optional int32 fieldname = 1 [(fieldopt) = { s:'FieldAnnotation' }];
354}
355
356service AggregateService {
357  option (serviceopt) = { s:'ServiceAnnotation' };
358  rpc Method (AggregateMessage) returns (AggregateMessage) {
359    option (methodopt) = { s:'MethodAnnotation' };
360  }
361}
362
363enum AggregateEnum {
364  option (enumopt) = { s:'EnumAnnotation' };
365  VALUE = 1 [(enumvalopt) = { s:'EnumValueAnnotation' }];
366}