• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc.  All rights reserved.
3// https://developers.google.com/protocol-buffers/
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: kenton@google.com (Kenton Varda)
32//  Based on original Protocol Buffers design by
33//  Sanjay Ghemawat, Jeff Dean, and others.
34//
35// This file tests that various identifiers work as field and type names even
36// though the same identifiers are used internally by the C++ code generator.
37
38// LINT: LEGACY_NAMES
39
40syntax = "proto2";
41
42// Some generic_services option(s) added automatically.
43// See:  http://go/proto2-generic-services-default
44option cc_generic_services = true; // auto-added
45
46// We don't put this in a package within proto2 because we need to make sure
47// that the generated code doesn't depend on being in the proto2 namespace.
48package protobuf_unittest;
49
50// Test that fields can have names like "input" and "i" which are also used
51// internally by the code generator for local variables.
52message TestConflictingSymbolNames {
53  message BuildDescriptors {}
54  message TypeTraits {}
55
56  optional int32 input = 1;
57  optional int32 output = 2;
58  optional string length = 3;
59  repeated int32 i = 4;
60  repeated string new_element = 5 [ctype = STRING_PIECE];
61  optional int32 total_size = 6;
62  optional int32 tag = 7;
63
64  enum TestEnum { FOO = 0; }
65  message Data1 {
66    repeated int32 data = 1;
67  }
68  message Data2 {
69    repeated TestEnum data = 1;
70  }
71  message Data3 {
72    repeated string data = 1;
73  }
74  message Data4 {
75    repeated Data4 data = 1;
76  }
77  message Data5 {
78    repeated string data = 1 [ctype = STRING_PIECE];
79  }
80  message Data6 {
81    repeated string data = 1 [ctype = CORD];
82  }
83
84  optional int32 source = 8;
85  optional int32 value = 9;
86  optional int32 file = 10;
87  optional int32 from = 11;
88  optional int32 handle_uninterpreted = 12;
89  repeated int32 index = 13;
90  optional int32 controller = 14;
91  optional int32 already_here = 15;
92
93  optional uint32 uint32 = 16;
94  optional uint64 uint64 = 17;
95  optional string string = 18;
96  optional int32 memset = 19;
97  optional int32 int32 = 20;
98  optional int64 int64 = 21;
99
100  optional uint32 cached_size = 22;
101  optional uint32 extensions = 23;
102  optional uint32 bit = 24;
103  optional uint32 bits = 25;
104  optional uint32 offsets = 26;
105  optional uint32 reflection = 27;
106
107  message Cord {}
108  optional string some_cord = 28 [ctype = CORD];
109
110  message StringPiece {}
111  optional string some_string_piece = 29 [ctype = STRING_PIECE];
112
113  // Some keywords.
114  optional uint32 int = 30;
115  optional uint32 friend = 31;
116  optional uint32 class = 37;
117  optional uint32 typedecl = 39;
118  optional uint32 auto = 40;
119
120  // The generator used to #define a macro called "DO" inside the .cc file.
121  message DO {}
122  optional DO do = 32;
123
124  // Some template parameter names for extensions.
125  optional int32 field_type = 33;
126  optional bool is_packed = 34;
127
128  // test conflicting release_$name$. "length" and "do" field in this message
129  // must remain string or message fields to make the test valid.
130  optional string release_length = 35;
131  // A more extreme case, the field name "do" here is a keyword, which will be
132  // escaped to "do_" already. Test there is no conflict even with escaped field
133  // names.
134  optional DO release_do = 36;
135
136  // For clashing local variables in Serialize and ByteSize calculation.
137  optional string target = 38;
138
139  extensions 1000 to max;  // NO_PROTO3
140}
141
142message TestConflictingSymbolNamesExtension {                      // NO_PROTO3
143  extend TestConflictingSymbolNames {                              // NO_PROTO3
144    repeated int32 repeated_int32_ext = 20423638 [packed = true];  // NO_PROTO3
145  }                                                                // NO_PROTO3
146}  // NO_PROTO3
147
148message TestConflictingEnumNames {  // NO_PROTO3
149  enum while {                      // NO_PROTO3
150    default = 0;                    // NO_PROTO3
151    and = 1;                        // NO_PROTO3
152    class = 2;                      // NO_PROTO3
153    int = 3;                        // NO_PROTO3
154    typedef = 4;                    // NO_PROTO3
155    XOR = 5;                        // NO_PROTO3
156  }                                 // NO_PROTO3
157
158  optional while conflicting_enum = 1;  // NO_PROTO3
159}  // NO_PROTO3
160
161enum bool {             // NO_PROTO3
162  default = 0;          // NO_PROTO3
163  NOT_EQ = 1;           // NO_PROTO3
164  volatile = 2;         // NO_PROTO3
165  return = 3;           // NO_PROTO3
166}  // NO_PROTO3
167
168message DummyMessage {}
169
170message NULL {
171  optional int32 int = 1;
172}
173
174extend TestConflictingSymbolNames {  // NO_PROTO3
175  optional int32 void = 314253;      // NO_PROTO3
176}                                    // NO_PROTO3
177
178// Message names that could conflict.
179message Shutdown {}
180message TableStruct {}
181
182service TestConflictingMethodNames {
183  rpc Closure(DummyMessage) returns (DummyMessage);
184}
185