My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes  
Changes to /trunk/src/google/protobuf/test_util.cc
r251 vs. r425 Compare: vs.  Format:
Revision r425
Go to: 
Project members, sign in to write a code review
/trunk/src/google/protobuf/test_util.cc   r251 /trunk/src/google/protobuf/test_util.cc   r425
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // http://code.google.com/p/protobuf/ 3 // http://code.google.com/p/protobuf/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above 11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer 12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the 13 // in the documentation and/or other materials provided with the
14 // distribution. 14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its 15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from 16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission. 17 // this software without specific prior written permission.
18 // 18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 30
31 // Author: kenton@google.com (Kenton Varda) 31 // Author: kenton@google.com (Kenton Varda)
32 // Based on original Protocol Buffers design by 32 // Based on original Protocol Buffers design by
33 // Sanjay Ghemawat, Jeff Dean, and others. 33 // Sanjay Ghemawat, Jeff Dean, and others.
34 34
35 #ifdef _WIN32 35 #ifdef _WIN32
36 // Verify that #including windows.h does not break anything (e.g. because 36 // Verify that #including windows.h does not break anything (e.g. because
37 // windows.h #defines GetMessage() as a macro). 37 // windows.h #defines GetMessage() as a macro).
38 #include <windows.h> 38 #include <windows.h>
39 #endif 39 #endif
40 40
41 #include <google/protobuf/test_util.h> 41 #include <google/protobuf/test_util.h>
42 #include <google/protobuf/descriptor.h> 42 #include <google/protobuf/descriptor.h>
43 #include <google/protobuf/message.h> 43 #include <google/protobuf/message.h>
44 44
45 #include <google/protobuf/stubs/common.h> 45 #include <google/protobuf/stubs/common.h>
46 #include <google/protobuf/testing/googletest.h> 46 #include <google/protobuf/testing/googletest.h>
47 #include <gtest/gtest.h> 47 #include <gtest/gtest.h>
48 48
49 namespace google { 49 namespace google {
50 namespace protobuf { 50 namespace protobuf {
51 51
52 void TestUtil::SetAllFields(unittest::TestAllTypes* message) { 52 void TestUtil::SetAllFields(unittest::TestAllTypes* message) {
53 SetOptionalFields(message);
54 AddRepeatedFields1(message);
55 AddRepeatedFields2(message);
56 SetDefaultFields(message);
57 }
58
59 void TestUtil::SetOptionalFields(unittest::TestAllTypes* message) {
53 message->set_optional_int32 (101); 60 message->set_optional_int32 (101);
54 message->set_optional_int64 (102); 61 message->set_optional_int64 (102);
55 message->set_optional_uint32 (103); 62 message->set_optional_uint32 (103);
56 message->set_optional_uint64 (104); 63 message->set_optional_uint64 (104);
57 message->set_optional_sint32 (105); 64 message->set_optional_sint32 (105);
58 message->set_optional_sint64 (106); 65 message->set_optional_sint64 (106);
59 message->set_optional_fixed32 (107); 66 message->set_optional_fixed32 (107);
60 message->set_optional_fixed64 (108); 67 message->set_optional_fixed64 (108);
61 message->set_optional_sfixed32(109); 68 message->set_optional_sfixed32(109);
62 message->set_optional_sfixed64(110); 69 message->set_optional_sfixed64(110);
63 message->set_optional_float (111); 70 message->set_optional_float (111);
64 message->set_optional_double (112); 71 message->set_optional_double (112);
65 message->set_optional_bool (true); 72 message->set_optional_bool (true);
66 message->set_optional_string ("115"); 73 message->set_optional_string ("115");
67 message->set_optional_bytes ("116"); 74 message->set_optional_bytes ("116");
68 75
69 message->mutable_optionalgroup ()->set_a(117); 76 message->mutable_optionalgroup ()->set_a(117);
70 message->mutable_optional_nested_message ()->set_bb(118); 77 message->mutable_optional_nested_message ()->set_bb(118);
71 message->mutable_optional_foreign_message()->set_c(119); 78 message->mutable_optional_foreign_message ()->set_c(119);
72 message->mutable_optional_import_message ()->set_d(120); 79 message->mutable_optional_import_message ()->set_d(120);
80 message->mutable_optional_public_import_message()->set_e(126);
81 message->mutable_optional_lazy_message ()->set_bb(127);
73 82
74 message->set_optional_nested_enum (unittest::TestAllTypes::BAZ); 83 message->set_optional_nested_enum (unittest::TestAllTypes::BAZ);
75 message->set_optional_foreign_enum(unittest::FOREIGN_BAZ ); 84 message->set_optional_foreign_enum(unittest::FOREIGN_BAZ );
76 message->set_optional_import_enum (unittest_import::IMPORT_BAZ); 85 message->set_optional_import_enum (unittest_import::IMPORT_BAZ);
77 86
78 // StringPiece and Cord fields are only accessible via reflection in the 87 // StringPiece and Cord fields are only accessible via reflection in the
79 // open source release; see comments in compiler/cpp/string_field.cc. 88 // open source release; see comments in compiler/cpp/string_field.cc.
80 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS 89 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
81 message->GetReflection()->SetString( 90 message->GetReflection()->SetString(
82 message, 91 message,
83 message->GetDescriptor()->FindFieldByName("optional_string_piece"), 92 message->GetDescriptor()->FindFieldByName("optional_string_piece"),
84 "124"); 93 "124");
85 message->GetReflection()->SetString( 94 message->GetReflection()->SetString(
86 message, 95 message,
87 message->GetDescriptor()->FindFieldByName("optional_cord"), 96 message->GetDescriptor()->FindFieldByName("optional_cord"),
88 "125"); 97 "125");
89 #endif // !PROTOBUF_TEST_NO_DESCRIPTORS 98 #endif // !PROTOBUF_TEST_NO_DESCRIPTORS
99 }
90 100
91 // ----------------------------------------------------------------- 101 // -------------------------------------------------------------------
92 102
103 void TestUtil::AddRepeatedFields1(unittest::TestAllTypes* message) {
93 message->add_repeated_int32 (201); 104 message->add_repeated_int32 (201);
94 message->add_repeated_int64 (202); 105 message->add_repeated_int64 (202);
95 message->add_repeated_uint32 (203); 106 message->add_repeated_uint32 (203);
96 message->add_repeated_uint64 (204); 107 message->add_repeated_uint64 (204);
97 message->add_repeated_sint32 (205); 108 message->add_repeated_sint32 (205);
98 message->add_repeated_sint64 (206); 109 message->add_repeated_sint64 (206);
99 message->add_repeated_fixed32 (207); 110 message->add_repeated_fixed32 (207);
100 message->add_repeated_fixed64 (208); 111 message->add_repeated_fixed64 (208);
101 message->add_repeated_sfixed32(209); 112 message->add_repeated_sfixed32(209);
102 message->add_repeated_sfixed64(210); 113 message->add_repeated_sfixed64(210);
103 message->add_repeated_float (211); 114 message->add_repeated_float (211);
104 message->add_repeated_double (212); 115 message->add_repeated_double (212);
105 message->add_repeated_bool (true); 116 message->add_repeated_bool (true);
106 message->add_repeated_string ("215"); 117 message->add_repeated_string ("215");
107 message->add_repeated_bytes ("216"); 118 message->add_repeated_bytes ("216");
108 119
109 message->add_repeatedgroup ()->set_a(217); 120 message->add_repeatedgroup ()->set_a(217);
110 message->add_repeated_nested_message ()->set_bb(218); 121 message->add_repeated_nested_message ()->set_bb(218);
111 message->add_repeated_foreign_message()->set_c(219); 122 message->add_repeated_foreign_message()->set_c(219);
112 message->add_repeated_import_message ()->set_d(220); 123 message->add_repeated_import_message ()->set_d(220);
124 message->add_repeated_lazy_message ()->set_bb(227);
113 125
114 message->add_repeated_nested_enum (unittest::TestAllTypes::BAR); 126 message->add_repeated_nested_enum (unittest::TestAllTypes::BAR);
115 message->add_repeated_foreign_enum(unittest::FOREIGN_BAR ); 127 message->add_repeated_foreign_enum(unittest::FOREIGN_BAR );
116 message->add_repeated_import_enum (unittest_import::IMPORT_BAR); 128 message->add_repeated_import_enum (unittest_import::IMPORT_BAR);
117 129
118 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS 130 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
119 message->GetReflection()->AddString( 131 message->GetReflection()->AddString(
120 message, 132 message,
121 message->GetDescriptor()->FindFieldByName("repeated_string_piece"), 133 message->GetDescriptor()->FindFieldByName("repeated_string_piece"),
122 "224"); 134 "224");
123 message->GetReflection()->AddString( 135 message->GetReflection()->AddString(
124 message, 136 message,
125 message->GetDescriptor()->FindFieldByName("repeated_cord"), 137 message->GetDescriptor()->FindFieldByName("repeated_cord"),
126 "225"); 138 "225");
127 #endif // !PROTOBUF_TEST_NO_DESCRIPTORS 139 #endif // !PROTOBUF_TEST_NO_DESCRIPTORS
140 }
128 141
142 void TestUtil::AddRepeatedFields2(unittest::TestAllTypes* message) {
129 // Add a second one of each field. 143 // Add a second one of each field.
130 message->add_repeated_int32 (301); 144 message->add_repeated_int32 (301);
131 message->add_repeated_int64 (302); 145 message->add_repeated_int64 (302);
132 message->add_repeated_uint32 (303); 146 message->add_repeated_uint32 (303);
133 message->add_repeated_uint64 (304); 147 message->add_repeated_uint64 (304);
134 message->add_repeated_sint32 (305); 148 message->add_repeated_sint32 (305);
135 message->add_repeated_sint64 (306); 149 message->add_repeated_sint64 (306);
136 message->add_repeated_fixed32 (307); 150 message->add_repeated_fixed32 (307);
137 message->add_repeated_fixed64 (308); 151 message->add_repeated_fixed64 (308);
138 message->add_repeated_sfixed32(309); 152 message->add_repeated_sfixed32(309);
139 message->add_repeated_sfixed64(310); 153 message->add_repeated_sfixed64(310);
140 message->add_repeated_float (311); 154 message->add_repeated_float (311);
141 message->add_repeated_double (312); 155 message->add_repeated_double (312);
142 message->add_repeated_bool (false); 156 message->add_repeated_bool (false);
143 message->add_repeated_string ("315"); 157 message->add_repeated_string ("315");
144 message->add_repeated_bytes ("316"); 158 message->add_repeated_bytes ("316");
145 159
146 message->add_repeatedgroup ()->set_a(317); 160 message->add_repeatedgroup ()->set_a(317);
147 message->add_repeated_nested_message ()->set_bb(318); 161 message->add_repeated_nested_message ()->set_bb(318);
148 message->add_repeated_foreign_message()->set_c(319); 162 message->add_repeated_foreign_message()->set_c(319);
149 message->add_repeated_import_message ()->set_d(320); 163 message->add_repeated_import_message ()->set_d(320);
164 message->add_repeated_lazy_message ()->set_bb(327);
150 165
151 message->add_repeated_nested_enum (unittest::TestAllTypes::BAZ); 166 message->add_repeated_nested_enum (unittest::TestAllTypes::BAZ);
152 message->add_repeated_foreign_enum(unittest::FOREIGN_BAZ ); 167 message->add_repeated_foreign_enum(unittest::FOREIGN_BAZ );
153 message->add_repeated_import_enum (unittest_import::IMPORT_BAZ); 168 message->add_repeated_import_enum (unittest_import::IMPORT_BAZ);
154 169
155 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS 170 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
156 message->GetReflection()->AddString( 171 message->GetReflection()->AddString(
157 message, 172 message,
158 message->GetDescriptor()->FindFieldByName("repeated_string_piece"), 173 message->GetDescriptor()->FindFieldByName("repeated_string_piece"),
159 "324"); 174 "324");
160 message->GetReflection()->AddString( 175 message->GetReflection()->AddString(
161 message, 176 message,
162 message->GetDescriptor()->FindFieldByName("repeated_cord"), 177 message->GetDescriptor()->FindFieldByName("repeated_cord"),
163 "325"); 178 "325");
164 #endif // !PROTOBUF_TEST_NO_DESCRIPTORS 179 #endif // !PROTOBUF_TEST_NO_DESCRIPTORS
180 }
165 181
166 // ----------------------------------------------------------------- 182 // -------------------------------------------------------------------
167 183
184 void TestUtil::SetDefaultFields(unittest::TestAllTypes* message) {
168 message->set_default_int32 (401); 185 message->set_default_int32 (401);
169 message->set_default_int64 (402); 186 message->set_default_int64 (402);
170 message->set_default_uint32 (403); 187 message->set_default_uint32 (403);
171 message->set_default_uint64 (404); 188 message->set_default_uint64 (404);
172 message->set_default_sint32 (405); 189 message->set_default_sint32 (405);
173 message->set_default_sint64 (406); 190 message->set_default_sint64 (406);
174 message->set_default_fixed32 (407); 191 message->set_default_fixed32 (407);
175 message->set_default_fixed64 (408); 192 message->set_default_fixed64 (408);
176 message->set_default_sfixed32(409); 193 message->set_default_sfixed32(409);
177 message->set_default_sfixed64(410); 194 message->set_default_sfixed64(410);
178 message->set_default_float (411); 195 message->set_default_float (411);
179 message->set_default_double (412); 196 message->set_default_double (412);
180 message->set_default_bool (false); 197 message->set_default_bool (false);
181 message->set_default_string ("415"); 198 message->set_default_string ("415");
182 message->set_default_bytes ("416"); 199 message->set_default_bytes ("416");
183 200
184 message->set_default_nested_enum (unittest::TestAllTypes::FOO); 201 message->set_default_nested_enum (unittest::TestAllTypes::FOO);
185 message->set_default_foreign_enum(unittest::FOREIGN_FOO ); 202 message->set_default_foreign_enum(unittest::FOREIGN_FOO );
186 message->set_default_import_enum (unittest_import::IMPORT_FOO); 203 message->set_default_import_enum (unittest_import::IMPORT_FOO);
187 204
188 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS 205 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
189 message->GetReflection()->SetString( 206 message->GetReflection()->SetString(
190 message, 207 message,
191 message->GetDescriptor()->FindFieldByName("default_string_piece"), 208 message->GetDescriptor()->FindFieldByName("default_string_piece"),
192 "424"); 209 "424");
193 message->GetReflection()->SetString( 210 message->GetReflection()->SetString(
194 message, 211 message,
195 message->GetDescriptor()->FindFieldByName("default_cord"), 212 message->GetDescriptor()->FindFieldByName("default_cord"),
196 "425"); 213 "425");
197 #endif // !PROTOBUF_TEST_NO_DESCRIPTORS 214 #endif // !PROTOBUF_TEST_NO_DESCRIPTORS
198 } 215 }
199 216
200 // ------------------------------------------------------------------- 217 // -------------------------------------------------------------------
201 218
202 void TestUtil::ModifyRepeatedFields(unittest::TestAllTypes* message) { 219 void TestUtil::ModifyRepeatedFields(unittest::TestAllTypes* message) {
203 message->set_repeated_int32 (1, 501); 220 message->set_repeated_int32 (1, 501);
204 message->set_repeated_int64 (1, 502); 221 message->set_repeated_int64 (1, 502);
205 message->set_repeated_uint32 (1, 503); 222 message->set_repeated_uint32 (1, 503);
206 message->set_repeated_uint64 (1, 504); 223 message->set_repeated_uint64 (1, 504);
207 message->set_repeated_sint32 (1, 505); 224 message->set_repeated_sint32 (1, 505);
208 message->set_repeated_sint64 (1, 506); 225 message->set_repeated_sint64 (1, 506);
209 message->set_repeated_fixed32 (1, 507); 226 message->set_repeated_fixed32 (1, 507);
210 message->set_repeated_fixed64 (1, 508); 227 message->set_repeated_fixed64 (1, 508);
211 message->set_repeated_sfixed32(1, 509); 228 message->set_repeated_sfixed32(1, 509);
212 message->set_repeated_sfixed64(1, 510); 229 message->set_repeated_sfixed64(1, 510);
213 message->set_repeated_float (1, 511); 230 message->set_repeated_float (1, 511);
214 message->set_repeated_double (1, 512); 231 message->set_repeated_double (1, 512);
215 message->set_repeated_bool (1, true); 232 message->set_repeated_bool (1, true);
216 message->set_repeated_string (1, "515"); 233 message->set_repeated_string (1, "515");
217 message->set_repeated_bytes (1, "516"); 234 message->set_repeated_bytes (1, "516");
218 235
219 message->mutable_repeatedgroup (1)->set_a(517); 236 message->mutable_repeatedgroup (1)->set_a(517);
220 message->mutable_repeated_nested_message (1)->set_bb(518); 237 message->mutable_repeated_nested_message (1)->set_bb(518);
221 message->mutable_repeated_foreign_message(1)->set_c(519); 238 message->mutable_repeated_foreign_message(1)->set_c(519);
222 message->mutable_repeated_import_message (1)->set_d(520); 239 message->mutable_repeated_import_message (1)->set_d(520);
240 message->mutable_repeated_lazy_message (1)->set_bb(527);
223 241
224 message->set_repeated_nested_enum (1, unittest::TestAllTypes::FOO); 242 message->set_repeated_nested_enum (1, unittest::TestAllTypes::FOO);
225 message->set_repeated_foreign_enum(1, unittest::FOREIGN_FOO ); 243 message->set_repeated_foreign_enum(1, unittest::FOREIGN_FOO );
226 message->set_repeated_import_enum (1, unittest_import::IMPORT_FOO); 244 message->set_repeated_import_enum (1, unittest_import::IMPORT_FOO);
227 245
228 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS 246 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
229 message->GetReflection()->SetRepeatedString( 247 message->GetReflection()->SetRepeatedString(
230 message, 248 message,
231 message->GetDescriptor()->FindFieldByName("repeated_string_piece"), 249 message->GetDescriptor()->FindFieldByName("repeated_string_piece"),
232 1, "524"); 250 1, "524");
233 message->GetReflection()->SetRepeatedString( 251 message->GetReflection()->SetRepeatedString(
234 message, 252 message,
235 message->GetDescriptor()->FindFieldByName("repeated_cord"), 253 message->GetDescriptor()->FindFieldByName("repeated_cord"),
236 1, "525"); 254 1, "525");
237 #endif // !PROTOBUF_TEST_NO_DESCRIPTORS 255 #endif // !PROTOBUF_TEST_NO_DESCRIPTORS
238 } 256 }
239 257
240 // ------------------------------------------------------------------- 258 // -------------------------------------------------------------------
241 259
242 void TestUtil::ExpectAllFieldsSet(const unittest::TestAllTypes& message) { 260 void TestUtil::ExpectAllFieldsSet(const unittest::TestAllTypes& message) {
243 EXPECT_TRUE(message.has_optional_int32 ()); 261 EXPECT_TRUE(message.has_optional_int32 ());
244 EXPECT_TRUE(message.has_optional_int64 ()); 262 EXPECT_TRUE(message.has_optional_int64 ());
245 EXPECT_TRUE(message.has_optional_uint32 ()); 263 EXPECT_TRUE(message.has_optional_uint32 ());
246 EXPECT_TRUE(message.has_optional_uint64 ()); 264 EXPECT_TRUE(message.has_optional_uint64 ());
247 EXPECT_TRUE(message.has_optional_sint32 ()); 265 EXPECT_TRUE(message.has_optional_sint32 ());
248 EXPECT_TRUE(message.has_optional_sint64 ()); 266 EXPECT_TRUE(message.has_optional_sint64 ());
249 EXPECT_TRUE(message.has_optional_fixed32 ()); 267 EXPECT_TRUE(message.has_optional_fixed32 ());
250 EXPECT_TRUE(message.has_optional_fixed64 ()); 268 EXPECT_TRUE(message.has_optional_fixed64 ());
251 EXPECT_TRUE(message.has_optional_sfixed32()); 269 EXPECT_TRUE(message.has_optional_sfixed32());
252 EXPECT_TRUE(message.has_optional_sfixed64()); 270 EXPECT_TRUE(message.has_optional_sfixed64());
253 EXPECT_TRUE(message.has_optional_float ()); 271 EXPECT_TRUE(message.has_optional_float ());
254 EXPECT_TRUE(message.has_optional_double ()); 272 EXPECT_TRUE(message.has_optional_double ());
255 EXPECT_TRUE(message.has_optional_bool ()); 273 EXPECT_TRUE(message.has_optional_bool ());
256 EXPECT_TRUE(message.has_optional_string ()); 274 EXPECT_TRUE(message.has_optional_string ());
257 EXPECT_TRUE(message.has_optional_bytes ()); 275 EXPECT_TRUE(message.has_optional_bytes ());
258 276
259 EXPECT_TRUE(message.has_optionalgroup ()); 277 EXPECT_TRUE(message.has_optionalgroup ());
260 EXPECT_TRUE(message.has_optional_nested_message ()); 278 EXPECT_TRUE(message.has_optional_nested_message ());
261 EXPECT_TRUE(message.has_optional_foreign_message()); 279 EXPECT_TRUE(message.has_optional_foreign_message ());
262 EXPECT_TRUE(message.has_optional_import_message ()); 280 EXPECT_TRUE(message.has_optional_import_message ());
281 EXPECT_TRUE(message.has_optional_public_import_message());
282 EXPECT_TRUE(message.has_optional_lazy_message ());
263 283
264 EXPECT_TRUE(message.optionalgroup ().has_a()); 284 EXPECT_TRUE(message.optionalgroup ().has_a());
265 EXPECT_TRUE(message.optional_nested_message ().has_bb()); 285 EXPECT_TRUE(message.optional_nested_message ().has_bb());
266 EXPECT_TRUE(message.optional_foreign_message().has_c()); 286 EXPECT_TRUE(message.optional_foreign_message ().has_c());
267 EXPECT_TRUE(message.optional_import_message ().has_d()); 287 EXPECT_TRUE(message.optional_import_message ().has_d());
288 EXPECT_TRUE(message.optional_public_import_message().has_e());
289 EXPECT_TRUE(message.optional_lazy_message ().has_bb());
268 290
269 EXPECT_TRUE(message.has_optional_nested_enum ()); 291 EXPECT_TRUE(message.has_optional_nested_enum ());
270 EXPECT_TRUE(message.has_optional_foreign_enum()); 292 EXPECT_TRUE(message.has_optional_foreign_enum());
271 EXPECT_TRUE(message.has_optional_import_enum ()); 293 EXPECT_TRUE(message.has_optional_import_enum ());
272 294
273 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS 295 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
274 EXPECT_TRUE(message.has_optional_string_piece()); 296 EXPECT_TRUE(message.has_optional_string_piece());
275 EXPECT_TRUE(message.has_optional_cord()); 297 EXPECT_TRUE(message.has_optional_cord());
276 #endif 298 #endif
277 299
278 EXPECT_EQ(101 , message.optional_int32 ()); 300 EXPECT_EQ(101 , message.optional_int32 ());
279 EXPECT_EQ(102 , message.optional_int64 ()); 301 EXPECT_EQ(102 , message.optional_int64 ());
280 EXPECT_EQ(103 , message.optional_uint32 ()); 302 EXPECT_EQ(103 , message.optional_uint32 ());
281 EXPECT_EQ(104 , message.optional_uint64 ()); 303 EXPECT_EQ(104 , message.optional_uint64 ());
282 EXPECT_EQ(105 , message.optional_sint32 ()); 304 EXPECT_EQ(105 , message.optional_sint32 ());
283 EXPECT_EQ(106 , message.optional_sint64 ()); 305 EXPECT_EQ(106 , message.optional_sint64 ());
284 EXPECT_EQ(107 , message.optional_fixed32 ()); 306 EXPECT_EQ(107 , message.optional_fixed32 ());
285 EXPECT_EQ(108 , message.optional_fixed64 ()); 307 EXPECT_EQ(108 , message.optional_fixed64 ());
286 EXPECT_EQ(109 , message.optional_sfixed32()); 308 EXPECT_EQ(109 , message.optional_sfixed32());
287 EXPECT_EQ(110 , message.optional_sfixed64()); 309 EXPECT_EQ(110 , message.optional_sfixed64());
288 EXPECT_EQ(111 , message.optional_float ()); 310 EXPECT_EQ(111 , message.optional_float ());
289 EXPECT_EQ(112 , message.optional_double ()); 311 EXPECT_EQ(112 , message.optional_double ());
290 EXPECT_EQ(true , message.optional_bool ()); 312 EXPECT_EQ(true , message.optional_bool ());
291 EXPECT_EQ("115", message.optional_string ()); 313 EXPECT_EQ("115", message.optional_string ());
292 EXPECT_EQ("116", message.optional_bytes ()); 314 EXPECT_EQ("116", message.optional_bytes ());
293 315
294 EXPECT_EQ(117, message.optionalgroup ().a()); 316 EXPECT_EQ(117, message.optionalgroup ().a());
295 EXPECT_EQ(118, message.optional_nested_message ().bb()); 317 EXPECT_EQ(118, message.optional_nested_message ().bb());
296 EXPECT_EQ(119, message.optional_foreign_message().c()); 318 EXPECT_EQ(119, message.optional_foreign_message ().c());
297 EXPECT_EQ(120, message.optional_import_message ().d()); 319 EXPECT_EQ(120, message.optional_import_message ().d());
320 EXPECT_EQ(126, message.optional_public_import_message ().e());
321 EXPECT_EQ(127, message.optional_lazy_message ().bb());
298 322
299 EXPECT_EQ(unittest::TestAllTypes::BAZ, message.optional_nested_enum ()); 323 EXPECT_EQ(unittest::TestAllTypes::BAZ, message.optional_nested_enum ());
300 EXPECT_EQ(unittest::FOREIGN_BAZ , message.optional_foreign_enum()); 324 EXPECT_EQ(unittest::FOREIGN_BAZ , message.optional_foreign_enum());
301 EXPECT_EQ(unittest_import::IMPORT_BAZ, message.optional_import_enum ()); 325 EXPECT_EQ(unittest_import::IMPORT_BAZ, message.optional_import_enum ());
302 326
303 327
304 // ----------------------------------------------------------------- 328 // -----------------------------------------------------------------
305 329
306 ASSERT_EQ(2, message.repeated_int32_size ()); 330 ASSERT_EQ(2, message.repeated_int32_size ());
307 ASSERT_EQ(2, message.repeated_int64_size ()); 331 ASSERT_EQ(2, message.repeated_int64_size ());
308 ASSERT_EQ(2, message.repeated_uint32_size ()); 332 ASSERT_EQ(2, message.repeated_uint32_size ());
309 ASSERT_EQ(2, message.repeated_uint64_size ()); 333 ASSERT_EQ(2, message.repeated_uint64_size ());
310 ASSERT_EQ(2, message.repeated_sint32_size ()); 334 ASSERT_EQ(2, message.repeated_sint32_size ());
311 ASSERT_EQ(2, message.repeated_sint64_size ()); 335 ASSERT_EQ(2, message.repeated_sint64_size ());
312 ASSERT_EQ(2, message.repeated_fixed32_size ()); 336 ASSERT_EQ(2, message.repeated_fixed32_size ());
313 ASSERT_EQ(2, message.repeated_fixed64_size ()); 337 ASSERT_EQ(2, message.repeated_fixed64_size ());
314 ASSERT_EQ(2, message.repeated_sfixed32_size()); 338 ASSERT_EQ(2, message.repeated_sfixed32_size());
315 ASSERT_EQ(2, message.repeated_sfixed64_size()); 339 ASSERT_EQ(2, message.repeated_sfixed64_size());
316 ASSERT_EQ(2, message.repeated_float_size ()); 340 ASSERT_EQ(2, message.repeated_float_size ());
317 ASSERT_EQ(2, message.repeated_double_size ()); 341 ASSERT_EQ(2, message.repeated_double_size ());
318 ASSERT_EQ(2, message.repeated_bool_size ()); 342 ASSERT_EQ(2, message.repeated_bool_size ());
319 ASSERT_EQ(2, message.repeated_string_size ()); 343 ASSERT_EQ(2, message.repeated_string_size ());
320 ASSERT_EQ(2, message.repeated_bytes_size ()); 344 ASSERT_EQ(2, message.repeated_bytes_size ());
321 345
322 ASSERT_EQ(2, message.repeatedgroup_size ()); 346 ASSERT_EQ(2, message.repeatedgroup_size ());
323 ASSERT_EQ(2, message.repeated_nested_message_size ()); 347 ASSERT_EQ(2, message.repeated_nested_message_size ());
324 ASSERT_EQ(2, message.repeated_foreign_message_size()); 348 ASSERT_EQ(2, message.repeated_foreign_message_size());
325 ASSERT_EQ(2, message.repeated_import_message_size ()); 349 ASSERT_EQ(2, message.repeated_import_message_size ());
350 ASSERT_EQ(2, message.repeated_lazy_message_size ());
326 ASSERT_EQ(2, message.repeated_nested_enum_size ()); 351 ASSERT_EQ(2, message.repeated_nested_enum_size ());
327 ASSERT_EQ(2, message.repeated_foreign_enum_size ()); 352 ASSERT_EQ(2, message.repeated_foreign_enum_size ());
328 ASSERT_EQ(2, message.repeated_import_enum_size ()); 353 ASSERT_EQ(2, message.repeated_import_enum_size ());
329 354
330 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS 355 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
331 ASSERT_EQ(2, message.repeated_string_piece_size()); 356 ASSERT_EQ(2, message.repeated_string_piece_size());
332 ASSERT_EQ(2, message.repeated_cord_size()); 357 ASSERT_EQ(2, message.repeated_cord_size());
333 #endif 358 #endif
334 359
335 EXPECT_EQ(201 , message.repeated_int32 (0)); 360 EXPECT_EQ(201 , message.repeated_int32 (0));
336 EXPECT_EQ(202 , message.repeated_int64 (0)); 361 EXPECT_EQ(202 , message.repeated_int64 (0));
337 EXPECT_EQ(203 , message.repeated_uint32 (0)); 362 EXPECT_EQ(203 , message.repeated_uint32 (0));
338 EXPECT_EQ(204 , message.repeated_uint64 (0)); 363 EXPECT_EQ(204 , message.repeated_uint64 (0));
339 EXPECT_EQ(205 , message.repeated_sint32 (0)); 364 EXPECT_EQ(205 , message.repeated_sint32 (0));
340 EXPECT_EQ(206 , message.repeated_sint64 (0)); 365 EXPECT_EQ(206 , message.repeated_sint64 (0));
341 EXPECT_EQ(207 , message.repeated_fixed32 (0)); 366 EXPECT_EQ(207 , message.repeated_fixed32 (0));
342 EXPECT_EQ(208 , message.repeated_fixed64 (0)); 367 EXPECT_EQ(208 , message.repeated_fixed64 (0));
343 EXPECT_EQ(209 , message.repeated_sfixed32(0)); 368 EXPECT_EQ(209 , message.repeated_sfixed32(0));
344 EXPECT_EQ(210 , message.repeated_sfixed64(0)); 369 EXPECT_EQ(210 , message.repeated_sfixed64(0));
345 EXPECT_EQ(211 , message.repeated_float (0)); 370 EXPECT_EQ(211 , message.repeated_float (0));
346 EXPECT_EQ(212 , message.repeated_double (0)); 371 EXPECT_EQ(212 , message.repeated_double (0));
347 EXPECT_EQ(true , message.repeated_bool (0)); 372 EXPECT_EQ(true , message.repeated_bool (0));
348 EXPECT_EQ("215", message.repeated_string (0)); 373 EXPECT_EQ("215", message.repeated_string (0));
349 EXPECT_EQ("216", message.repeated_bytes (0)); 374 EXPECT_EQ("216", message.repeated_bytes (0));
350 375
351 EXPECT_EQ(217, message.repeatedgroup (0).a()); 376 EXPECT_EQ(217, message.repeatedgroup (0).a());
352 EXPECT_EQ(218, message.repeated_nested_message (0).bb()); 377 EXPECT_EQ(218, message.repeated_nested_message (0).bb());
353 EXPECT_EQ(219, message.repeated_foreign_message(0).c()); 378 EXPECT_EQ(219, message.repeated_foreign_message(0).c());
354 EXPECT_EQ(220, message.repeated_import_message (0).d()); 379 EXPECT_EQ(220, message.repeated_import_message (0).d());
380 EXPECT_EQ(227, message.repeated_lazy_message (0).bb());
355 381
356 382
357 EXPECT_EQ(unittest::TestAllTypes::BAR, message.repeated_nested_enum (0)); 383 EXPECT_EQ(unittest::TestAllTypes::BAR, message.repeated_nested_enum (0));
358 EXPECT_EQ(unittest::FOREIGN_BAR , message.repeated_foreign_enum(0)); 384 EXPECT_EQ(unittest::FOREIGN_BAR , message.repeated_foreign_enum(0));
359 EXPECT_EQ(unittest_import::IMPORT_BAR, message.repeated_import_enum (0)); 385 EXPECT_EQ(unittest_import::IMPORT_BAR, message.repeated_import_enum (0));
360 386
361 EXPECT_EQ(301 , message.repeated_int32 (1)); 387 EXPECT_EQ(301 , message.repeated_int32 (1));
362 EXPECT_EQ(302 , message.repeated_int64 (1)); 388 EXPECT_EQ(302 , message.repeated_int64 (1));
363 EXPECT_EQ(303 , message.repeated_uint32 (1)); 389 EXPECT_EQ(303 , message.repeated_uint32 (1));
364 EXPECT_EQ(304 , message.repeated_uint64 (1)); 390 EXPECT_EQ(304 , message.repeated_uint64 (1));
365 EXPECT_EQ(305 , message.repeated_sint32 (1)); 391 EXPECT_EQ(305 , message.repeated_sint32 (1));
366 EXPECT_EQ(306 , message.repeated_sint64 (1)); 392 EXPECT_EQ(306 , message.repeated_sint64 (1));
367 EXPECT_EQ(307 , message.repeated_fixed32 (1)); 393 EXPECT_EQ(307 , message.repeated_fixed32 (1));
368 EXPECT_EQ(308 , message.repeated_fixed64 (1)); 394 EXPECT_EQ(308 , message.repeated_fixed64 (1));
369 EXPECT_EQ(309 , message.repeated_sfixed32(1)); 395 EXPECT_EQ(309 , message.repeated_sfixed32(1));
370 EXPECT_EQ(310 , message.repeated_sfixed64(1)); 396 EXPECT_EQ(310 , message.repeated_sfixed64(1));
371 EXPECT_EQ(311 , message.repeated_float (1)); 397 EXPECT_EQ(311 , message.repeated_float (1));
372 EXPECT_EQ(312 , message.repeated_double (1)); 398 EXPECT_EQ(312 , message.repeated_double (1));
373 EXPECT_EQ(false, message.repeated_bool (1)); 399 EXPECT_EQ(false, message.repeated_bool (1));
374 EXPECT_EQ("315", message.repeated_string (1)); 400 EXPECT_EQ("315", message.repeated_string (1));
375 EXPECT_EQ("316", message.repeated_bytes (1)); 401 EXPECT_EQ("316", message.repeated_bytes (1));
376 402
377 EXPECT_EQ(317, message.repeatedgroup (1).a()); 403 EXPECT_EQ(317, message.repeatedgroup (1).a());
378 EXPECT_EQ(318, message.repeated_nested_message (1).bb()); 404 EXPECT_EQ(318, message.repeated_nested_message (1).bb());
379 EXPECT_EQ(319, message.repeated_foreign_message(1).c()); 405 EXPECT_EQ(319, message.repeated_foreign_message(1).c());
380 EXPECT_EQ(320, message.repeated_import_message (1).d()); 406 EXPECT_EQ(320, message.repeated_import_message (1).d());
407 EXPECT_EQ(327, message.repeated_lazy_message (1).bb());
381 408
382 EXPECT_EQ(unittest::TestAllTypes::BAZ, message.repeated_nested_enum (1)); 409 EXPECT_EQ(unittest::TestAllTypes::BAZ, message.repeated_nested_enum (1));
383 EXPECT_EQ(unittest::FOREIGN_BAZ , message.repeated_foreign_enum(1)); 410 EXPECT_EQ(unittest::FOREIGN_BAZ , message.repeated_foreign_enum(1));
384 EXPECT_EQ(unittest_import::IMPORT_BAZ, message.repeated_import_enum (1)); 411 EXPECT_EQ(unittest_import::IMPORT_BAZ, message.repeated_import_enum (1));
385 412
386 413
387 // ----------------------------------------------------------------- 414 // -----------------------------------------------------------------
388 415
389 EXPECT_TRUE(message.has_default_int32 ()); 416 EXPECT_TRUE(message.has_default_int32 ());
390 EXPECT_TRUE(message.has_default_int64 ()); 417 EXPECT_TRUE(message.has_default_int64 ());
391 EXPECT_TRUE(message.has_default_uint32 ()); 418 EXPECT_TRUE(message.has_default_uint32 ());
392 EXPECT_TRUE(message.has_default_uint64 ()); 419 EXPECT_TRUE(message.has_default_uint64 ());
393 EXPECT_TRUE(message.has_default_sint32 ()); 420 EXPECT_TRUE(message.has_default_sint32 ());
394 EXPECT_TRUE(message.has_default_sint64 ()); 421 EXPECT_TRUE(message.has_default_sint64 ());
395 EXPECT_TRUE(message.has_default_fixed32 ()); 422 EXPECT_TRUE(message.has_default_fixed32 ());
396 EXPECT_TRUE(message.has_default_fixed64 ()); 423 EXPECT_TRUE(message.has_default_fixed64 ());
397 EXPECT_TRUE(message.has_default_sfixed32()); 424 EXPECT_TRUE(message.has_default_sfixed32());
398 EXPECT_TRUE(message.has_default_sfixed64()); 425 EXPECT_TRUE(message.has_default_sfixed64());
399 EXPECT_TRUE(message.has_default_float ()); 426 EXPECT_TRUE(message.has_default_float ());
400 EXPECT_TRUE(message.has_default_double ()); 427 EXPECT_TRUE(message.has_default_double ());
401 EXPECT_TRUE(message.has_default_bool ()); 428 EXPECT_TRUE(message.has_default_bool ());
402 EXPECT_TRUE(message.has_default_string ()); 429 EXPECT_TRUE(message.has_default_string ());
403 EXPECT_TRUE(message.has_default_bytes ()); 430 EXPECT_TRUE(message.has_default_bytes ());
404 431
405 EXPECT_TRUE(message.has_default_nested_enum ()); 432 EXPECT_TRUE(message.has_default_nested_enum ());
406 EXPECT_TRUE(message.has_default_foreign_enum()); 433 EXPECT_TRUE(message.has_default_foreign_enum());
407 EXPECT_TRUE(message.has_default_import_enum ()); 434 EXPECT_TRUE(message.has_default_import_enum ());
408 435
409 436
410 EXPECT_EQ(401 , message.default_int32 ()); 437 EXPECT_EQ(401 , message.default_int32 ());
411 EXPECT_EQ(402 , message.default_int64 ()); 438 EXPECT_EQ(402 , message.default_int64 ());
412 EXPECT_EQ(403 , message.default_uint32 ()); 439 EXPECT_EQ(403 , message.default_uint32 ());
413 EXPECT_EQ(404 , message.default_uint64 ()); 440 EXPECT_EQ(404 , message.default_uint64 ());
414 EXPECT_EQ(405 , message.default_sint32 ()); 441 EXPECT_EQ(405 , message.default_sint32 ());
415 EXPECT_EQ(406 , message.default_sint64 ()); 442 EXPECT_EQ(406 , message.default_sint64 ());
416 EXPECT_EQ(407 , message.default_fixed32 ()); 443 EXPECT_EQ(407 , message.default_fixed32 ());
417 EXPECT_EQ(408 , message.default_fixed64 ()); 444 EXPECT_EQ(408 , message.default_fixed64 ());
418 EXPECT_EQ(409 , message.default_sfixed32()); 445 EXPECT_EQ(409 , message.default_sfixed32());
419 EXPECT_EQ(410 , message.default_sfixed64()); 446 EXPECT_EQ(410 , message.default_sfixed64());
420 EXPECT_EQ(411 , message.default_float ()); 447 EXPECT_EQ(411 , message.default_float ());
421 EXPECT_EQ(412 , message.default_double ()); 448 EXPECT_EQ(412 , message.default_double ());
422 EXPECT_EQ(false, message.default_bool ()); 449 EXPECT_EQ(false, message.default_bool ());
423 EXPECT_EQ("415", message.default_string ()); 450 EXPECT_EQ("415", message.default_string ());
424 EXPECT_EQ("416", message.default_bytes ()); 451 EXPECT_EQ("416", message.default_bytes ());
425 452
426 EXPECT_EQ(unittest::TestAllTypes::FOO, message.default_nested_enum ()); 453 EXPECT_EQ(unittest::TestAllTypes::FOO, message.default_nested_enum ());
427 EXPECT_EQ(unittest::FOREIGN_FOO , message.default_foreign_enum()); 454 EXPECT_EQ(unittest::FOREIGN_FOO , message.default_foreign_enum());
428 EXPECT_EQ(unittest_import::IMPORT_FOO, message.default_import_enum ()); 455 EXPECT_EQ(unittest_import::IMPORT_FOO, message.default_import_enum ());
429 456
430 } 457 }
431 458
432 // ------------------------------------------------------------------- 459 // -------------------------------------------------------------------
433 460
434 void TestUtil::ExpectClear(const unittest::TestAllTypes& message) { 461 void TestUtil::ExpectClear(const unittest::TestAllTypes& message) {
435 // has_blah() should initially be false for all optional fields. 462 // has_blah() should initially be false for all optional fields.
436 EXPECT_FALSE(message.has_optional_int32 ()); 463 EXPECT_FALSE(message.has_optional_int32 ());
437 EXPECT_FALSE(message.has_optional_int64 ()); 464 EXPECT_FALSE(message.has_optional_int64 ());
438 EXPECT_FALSE(message.has_optional_uint32 ()); 465 EXPECT_FALSE(message.has_optional_uint32 ());
439 EXPECT_FALSE(message.has_optional_uint64 ()); 466 EXPECT_FALSE(message.has_optional_uint64 ());
440 EXPECT_FALSE(message.has_optional_sint32 ()); 467 EXPECT_FALSE(message.has_optional_sint32 ());
441 EXPECT_FALSE(message.has_optional_sint64 ()); 468 EXPECT_FALSE(message.has_optional_sint64 ());
442 EXPECT_FALSE(message.has_optional_fixed32 ()); 469 EXPECT_FALSE(message.has_optional_fixed32 ());
443 EXPECT_FALSE(message.has_optional_fixed64 ()); 470 EXPECT_FALSE(message.has_optional_fixed64 ());
444 EXPECT_FALSE(message.has_optional_sfixed32()); 471 EXPECT_FALSE(message.has_optional_sfixed32());
445 EXPECT_FALSE(message.has_optional_sfixed64()); 472 EXPECT_FALSE(message.has_optional_sfixed64());
446 EXPECT_FALSE(message.has_optional_float ()); 473 EXPECT_FALSE(message.has_optional_float ());
447 EXPECT_FALSE(message.has_optional_double ()); 474 EXPECT_FALSE(message.has_optional_double ());
448 EXPECT_FALSE(message.has_optional_bool ()); 475 EXPECT_FALSE(message.has_optional_bool ());
449 EXPECT_FALSE(message.has_optional_string ()); 476 EXPECT_FALSE(message.has_optional_string ());
450 EXPECT_FALSE(message.has_optional_bytes ()); 477 EXPECT_FALSE(message.has_optional_bytes ());
451 478
452 EXPECT_FALSE(message.has_optionalgroup ()); 479 EXPECT_FALSE(message.has_optionalgroup ());
453 EXPECT_FALSE(message.has_optional_nested_message ()); 480 EXPECT_FALSE(message.has_optional_nested_message ());
454 EXPECT_FALSE(message.has_optional_foreign_message()); 481 EXPECT_FALSE(message.has_optional_foreign_message ());
455 EXPECT_FALSE(message.has_optional_import_message ()); 482 EXPECT_FALSE(message.has_optional_import_message ());
483 EXPECT_FALSE(message.has_optional_public_import_message());
484 EXPECT_FALSE(message.has_optional_lazy_message ());
456 485
457 EXPECT_FALSE(message.has_optional_nested_enum ()); 486 EXPECT_FALSE(message.has_optional_nested_enum ());
458 EXPECT_FALSE(message.has_optional_foreign_enum()); 487 EXPECT_FALSE(message.has_optional_foreign_enum());
459 EXPECT_FALSE(message.has_optional_import_enum ()); 488 EXPECT_FALSE(message.has_optional_import_enum ());
460 489
461 EXPECT_FALSE(message.has_optional_string_piece()); 490 EXPECT_FALSE(message.has_optional_string_piece());
462 EXPECT_FALSE(message.has_optional_cord()); 491 EXPECT_FALSE(message.has_optional_cord());
463 492
464 // Optional fields without defaults are set to zero or something like it. 493 // Optional fields without defaults are set to zero or something like it.
465 EXPECT_EQ(0 , message.optional_int32 ()); 494 EXPECT_EQ(0 , message.optional_int32 ());
466 EXPECT_EQ(0 , message.optional_int64 ()); 495 EXPECT_EQ(0 , message.optional_int64 ());
467 EXPECT_EQ(0 , message.optional_uint32 ()); 496 EXPECT_EQ(0 , message.optional_uint32 ());
468 EXPECT_EQ(0 , message.optional_uint64 ()); 497 EXPECT_EQ(0 , message.optional_uint64 ());
469 EXPECT_EQ(0 , message.optional_sint32 ()); 498 EXPECT_EQ(0 , message.optional_sint32 ());
470 EXPECT_EQ(0 , message.optional_sint64 ()); 499 EXPECT_EQ(0 , message.optional_sint64 ());
471 EXPECT_EQ(0 , message.optional_fixed32 ()); 500 EXPECT_EQ(0 , message.optional_fixed32 ());
472 EXPECT_EQ(0 , message.optional_fixed64 ()); 501 EXPECT_EQ(0 , message.optional_fixed64 ());
473 EXPECT_EQ(0 , message.optional_sfixed32()); 502 EXPECT_EQ(0 , message.optional_sfixed32());
474 EXPECT_EQ(0 , message.optional_sfixed64()); 503 EXPECT_EQ(0 , message.optional_sfixed64());
475 EXPECT_EQ(0 , message.optional_float ()); 504 EXPECT_EQ(0 , message.optional_float ());
476 EXPECT_EQ(0 , message.optional_double ()); 505 EXPECT_EQ(0 , message.optional_double ());
477 EXPECT_EQ(false, message.optional_bool ()); 506 EXPECT_EQ(false, message.optional_bool ());
478 EXPECT_EQ("" , message.optional_string ()); 507 EXPECT_EQ("" , message.optional_string ());
479 EXPECT_EQ("" , message.optional_bytes ()); 508 EXPECT_EQ("" , message.optional_bytes ());
480 509
481 // Embedded messages should also be clear. 510 // Embedded messages should also be clear.
482 EXPECT_FALSE(message.optionalgroup ().has_a()); 511 EXPECT_FALSE(message.optionalgroup ().has_a());
483 EXPECT_FALSE(message.optional_nested_message ().has_bb()); 512 EXPECT_FALSE(message.optional_nested_message ().has_bb());
484 EXPECT_FALSE(message.optional_foreign_message().has_c()); 513 EXPECT_FALSE(message.optional_foreign_message ().has_c());
485 EXPECT_FALSE(message.optional_import_message ().has_d()); 514 EXPECT_FALSE(message.optional_import_message ().has_d());
515 EXPECT_FALSE(message.optional_public_import_message().has_e());
516 EXPECT_FALSE(message.optional_lazy_message ().has_bb());
486 517
487 EXPECT_EQ(0, message.optionalgroup ().a()); 518 EXPECT_EQ(0, message.optionalgroup ().a());
488 EXPECT_EQ(0, message.optional_nested_message ().bb()); 519 EXPECT_EQ(0, message.optional_nested_message ().bb());
489 EXPECT_EQ(0, message.optional_foreign_message().c()); 520 EXPECT_EQ(0, message.optional_foreign_message ().c());
490 EXPECT_EQ(0, message.optional_import_message ().d()); 521 EXPECT_EQ(0, message.optional_import_message ().d());
522 EXPECT_EQ(0, message.optional_public_import_message().e());
523 EXPECT_EQ(0, message.optional_lazy_message ().bb());
491 524
492 // Enums without defaults are set to the first value in the enum. 525 // Enums without defaults are set to the first value in the enum.
493 EXPECT_EQ(unittest::TestAllTypes::FOO, message.optional_nested_enum ()); 526 EXPECT_EQ(unittest::TestAllTypes::FOO, message.optional_nested_enum ());
494 EXPECT_EQ(unittest::FOREIGN_FOO , message.optional_foreign_enum()); 527 EXPECT_EQ(unittest::FOREIGN_FOO , message.optional_foreign_enum());
495 EXPECT_EQ(unittest_import::IMPORT_FOO, message.optional_import_enum ()); 528 EXPECT_EQ(unittest_import::IMPORT_FOO, message.optional_import_enum ());
496 529
497 530
498 // Repeated fields are empty. 531 // Repeated fields are empty.
499 EXPECT_EQ(0, message.repeated_int32_size ()); 532 EXPECT_EQ(0, message.repeated_int32_size ());
500 EXPECT_EQ(0, message.repeated_int64_size ()); 533 EXPECT_EQ(0, message.repeated_int64_size ());
501 EXPECT_EQ(0, message.repeated_uint32_size ()); 534 EXPECT_EQ(0, message.repeated_uint32_size ());
502 EXPECT_EQ(0, message.repeated_uint64_size ()); 535 EXPECT_EQ(0, message.repeated_uint64_size ());
503 EXPECT_EQ(0, message.repeated_sint32_size ()); 536 EXPECT_EQ(0, message.repeated_sint32_size ());
504 EXPECT_EQ(0, message.repeated_sint64_size ()); 537 EXPECT_EQ(0, message.repeated_sint64_size ());
505 EXPECT_EQ(0, message.repeated_fixed32_size ()); 538 EXPECT_EQ(0, message.repeated_fixed32_size ());
506 EXPECT_EQ(0, message.repeated_fixed64_size ()); 539 EXPECT_EQ(0, message.repeated_fixed64_size ());
507 EXPECT_EQ(0, message.repeated_sfixed32_size()); 540 EXPECT_EQ(0, message.repeated_sfixed32_size());
508 EXPECT_EQ(0, message.repeated_sfixed64_size()); 541 EXPECT_EQ(0, message.repeated_sfixed64_size());
509 EXPECT_EQ(0, message.repeated_float_size ()); 542 EXPECT_EQ(0, message.repeated_float_size ());
510 EXPECT_EQ(0, message.repeated_double_size ()); 543 EXPECT_EQ(0, message.repeated_double_size ());
511 EXPECT_EQ(0, message.repeated_bool_size ()); 544 EXPECT_EQ(0, message.repeated_bool_size ());
512 EXPECT_EQ(0, message.repeated_string_size ()); 545 EXPECT_EQ(0, message.repeated_string_size ());
513 EXPECT_EQ(0, message.repeated_bytes_size ()); 546 EXPECT_EQ(0, message.repeated_bytes_size ());
514 547
515 EXPECT_EQ(0, message.repeatedgroup_size ()); 548 EXPECT_EQ(0, message.repeatedgroup_size ());
516 EXPECT_EQ(0, message.repeated_nested_message_size ()); 549 EXPECT_EQ(0, message.repeated_nested_message_size ());
517 EXPECT_EQ(0, message.repeated_foreign_message_size()); 550 EXPECT_EQ(0, message.repeated_foreign_message_size());
518 EXPECT_EQ(0, message.repeated_import_message_size ()); 551 EXPECT_EQ(0, message.repeated_import_message_size ());
552 EXPECT_EQ(0, message.repeated_lazy_message_size ());
519 EXPECT_EQ(0, message.repeated_nested_enum_size ()); 553 EXPECT_EQ(0, message.repeated_nested_enum_size ());
520 EXPECT_EQ(0, message.repeated_foreign_enum_size ()); 554 EXPECT_EQ(0, message.repeated_foreign_enum_size ());
521 EXPECT_EQ(0, message.repeated_import_enum_size ()); 555 EXPECT_EQ(0, message.repeated_import_enum_size ());
522 556
523 EXPECT_EQ(0, message.repeated_string_piece_size()); 557 EXPECT_EQ(0, message.repeated_string_piece_size());
524 EXPECT_EQ(0, message.repeated_cord_size()); 558 EXPECT_EQ(0, message.repeated_cord_size());
525 559
526 // has_blah() should also be false for all default fields. 560 // has_blah() should also be false for all default fields.
527 EXPECT_FALSE(message.has_default_int32 ()); 561 EXPECT_FALSE(message.has_default_int32 ());
528 EXPECT_FALSE(message.has_default_int64 ()); 562 EXPECT_FALSE(message.has_default_int64 ());
529 EXPECT_FALSE(message.has_default_uint32 ()); 563 EXPECT_FALSE(message.has_default_uint32 ());
530 EXPECT_FALSE(message.has_default_uint64 ()); 564 EXPECT_FALSE(message.has_default_uint64 ());
531 EXPECT_FALSE(message.has_default_sint32 ()); 565 EXPECT_FALSE(message.has_default_sint32 ());
532 EXPECT_FALSE(message.has_default_sint64 ()); 566 EXPECT_FALSE(message.has_default_sint64 ());
533 EXPECT_FALSE(message.has_default_fixed32 ()); 567 EXPECT_FALSE(message.has_default_fixed32 ());
534 EXPECT_FALSE(message.has_default_fixed64 ()); 568 EXPECT_FALSE(message.has_default_fixed64 ());
535 EXPECT_FALSE(message.has_default_sfixed32()); 569 EXPECT_FALSE(message.has_default_sfixed32());
536 EXPECT_FALSE(message.has_default_sfixed64()); 570 EXPECT_FALSE(message.has_default_sfixed64());
537 EXPECT_FALSE(message.has_default_float ()); 571 EXPECT_FALSE(message.has_default_float ());
538 EXPECT_FALSE(message.has_default_double ()); 572 EXPECT_FALSE(message.has_default_double ());
539 EXPECT_FALSE(message.has_default_bool ()); 573 EXPECT_FALSE(message.has_default_bool ());
540 EXPECT_FALSE(message.has_default_string ()); 574 EXPECT_FALSE(message.has_default_string ());
541 EXPECT_FALSE(message.has_default_bytes ()); 575 EXPECT_FALSE(message.has_default_bytes ());
542 576
543 EXPECT_FALSE(message.has_default_nested_enum ()); 577 EXPECT_FALSE(message.has_default_nested_enum ());
544 EXPECT_FALSE(message.has_default_foreign_enum()); 578 EXPECT_FALSE(message.has_default_foreign_enum());
545 EXPECT_FALSE(message.has_default_import_enum ()); 579 EXPECT_FALSE(message.has_default_import_enum ());
546 580
547 581
548 // Fields with defaults have their default values (duh). 582 // Fields with defaults have their default values (duh).
549 EXPECT_EQ( 41 , message.default_int32 ()); 583 EXPECT_EQ( 41 , message.default_int32 ());
550 EXPECT_EQ( 42 , message.default_int64 ()); 584 EXPECT_EQ( 42 , message.default_int64 ());
551 EXPECT_EQ( 43 , message.default_uint32 ()); 585 EXPECT_EQ( 43 , message.default_uint32 ());
552 EXPECT_EQ( 44 , message.default_uint64 ()); 586 EXPECT_EQ( 44 , message.default_uint64 ());
553 EXPECT_EQ(-45 , message.default_sint32 ()); 587 EXPECT_EQ(-45 , message.default_sint32 ());
554 EXPECT_EQ( 46 , message.default_sint64 ()); 588 EXPECT_EQ( 46 , message.default_sint64 ());
555 EXPECT_EQ( 47 , message.default_fixed32 ()); 589 EXPECT_EQ( 47 , message.default_fixed32 ());
556 EXPECT_EQ( 48 , message.default_fixed64 ()); 590 EXPECT_EQ( 48 , message.default_fixed64 ());
557 EXPECT_EQ( 49 , message.default_sfixed32()); 591 EXPECT_EQ( 49 , message.default_sfixed32());
558 EXPECT_EQ(-50 , message.default_sfixed64()); 592 EXPECT_EQ(-50 , message.default_sfixed64());
559 EXPECT_EQ( 51.5 , message.default_float ()); 593 EXPECT_EQ( 51.5 , message.default_float ());
560 EXPECT_EQ( 52e3 , message.default_double ()); 594 EXPECT_EQ( 52e3 , message.default_double ());
561 EXPECT_EQ(true , message.default_bool ()); 595 EXPECT_EQ(true , message.default_bool ());
562 EXPECT_EQ("hello", message.default_string ()); 596 EXPECT_EQ("hello", message.default_string ());
563 EXPECT_EQ("world", message.default_bytes ()); 597 EXPECT_EQ("world", message.default_bytes ());
564 598
565 EXPECT_EQ(unittest::TestAllTypes::BAR, message.default_nested_enum ()); 599 EXPECT_EQ(unittest::TestAllTypes::BAR, message.default_nested_enum ());
566 EXPECT_EQ(unittest::FOREIGN_BAR , message.default_foreign_enum()); 600 EXPECT_EQ(unittest::FOREIGN_BAR , message.default_foreign_enum());
567 EXPECT_EQ(unittest_import::IMPORT_BAR, message.default_import_enum ()); 601 EXPECT_EQ(unittest_import::IMPORT_BAR, message.default_import_enum ());
568 602
569 } 603 }
570 604
571 // ------------------------------------------------------------------- 605 // -------------------------------------------------------------------
572 606
573 void TestUtil::ExpectRepeatedFieldsModified( 607 void TestUtil::ExpectRepeatedFieldsModified(
574 const unittest::TestAllTypes& message) { 608 const unittest::TestAllTypes& message) {
575 // ModifyRepeatedFields only sets the second repeated element of each 609 // ModifyRepeatedFields only sets the second repeated element of each
576 // field. In addition to verifying this, we also verify that the first 610 // field. In addition to verifying this, we also verify that the first
577 // element and size were *not* modified. 611 // element and size were *not* modified.
578 ASSERT_EQ(2, message.repeated_int32_size ()); 612 ASSERT_EQ(2, message.repeated_int32_size ());
579 ASSERT_EQ(2, message.repeated_int64_size ()); 613 ASSERT_EQ(2, message.repeated_int64_size ());
580 ASSERT_EQ(2, message.repeated_uint32_size ()); 614 ASSERT_EQ(2, message.repeated_uint32_size ());
581 ASSERT_EQ(2, message.repeated_uint64_size ()); 615 ASSERT_EQ(2, message.repeated_uint64_size ());
582 ASSERT_EQ(2, message.repeated_sint32_size ()); 616 ASSERT_EQ(2, message.repeated_sint32_size ());
583 ASSERT_EQ(2, message.repeated_sint64_size ()); 617 ASSERT_EQ(2, message.repeated_sint64_size ());
584 ASSERT_EQ(2, message.repeated_fixed32_size ()); 618 ASSERT_EQ(2, message.repeated_fixed32_size ());
585 ASSERT_EQ(2, message.repeated_fixed64_size ()); 619 ASSERT_EQ(2, message.repeated_fixed64_size ());
586 ASSERT_EQ(2, message.repeated_sfixed32_size()); 620 ASSERT_EQ(2, message.repeated_sfixed32_size());
587 ASSERT_EQ(2, message.repeated_sfixed64_size()); 621 ASSERT_EQ(2, message.repeated_sfixed64_size());
588 ASSERT_EQ(2, message.repeated_float_size ()); 622 ASSERT_EQ(2, message.repeated_float_size ());
589 ASSERT_EQ(2, message.repeated_double_size ()); 623 ASSERT_EQ(2, message.repeated_double_size ());
590 ASSERT_EQ(2, message.repeated_bool_size ()); 624 ASSERT_EQ(2, message.repeated_bool_size ());
591 ASSERT_EQ(2, message.repeated_string_size ()); 625 ASSERT_EQ(2, message.repeated_string_size ());
592 ASSERT_EQ(2, message.repeated_bytes_size ()); 626 ASSERT_EQ(2, message.repeated_bytes_size ());
593 627
594 ASSERT_EQ(2, message.repeatedgroup_size ()); 628 ASSERT_EQ(2, message.repeatedgroup_size ());
595 ASSERT_EQ(2, message.repeated_nested_message_size ()); 629 ASSERT_EQ(2, message.repeated_nested_message_size ());
596 ASSERT_EQ(2, message.repeated_foreign_message_size()); 630 ASSERT_EQ(2, message.repeated_foreign_message_size());
597 ASSERT_EQ(2, message.repeated_import_message_size ()); 631 ASSERT_EQ(2, message.repeated_import_message_size ());
632 ASSERT_EQ(2, message.repeated_lazy_message_size ());
598 ASSERT_EQ(2, message.repeated_nested_enum_size ()); 633 ASSERT_EQ(2, message.repeated_nested_enum_size ());
599 ASSERT_EQ(2, message.repeated_foreign_enum_size ()); 634 ASSERT_EQ(2, message.repeated_foreign_enum_size ());
600 ASSERT_EQ(2, message.repeated_import_enum_size ()); 635 ASSERT_EQ(2, message.repeated_import_enum_size ());
601 636
602 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS 637 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
603 ASSERT_EQ(2, message.repeated_string_piece_size()); 638 ASSERT_EQ(2, message.repeated_string_piece_size());
604 ASSERT_EQ(2, message.repeated_cord_size()); 639 ASSERT_EQ(2, message.repeated_cord_size());
605 #endif 640 #endif
606 641
607 EXPECT_EQ(201 , message.repeated_int32 (0)); 642 EXPECT_EQ(201 , message.repeated_int32 (0));
608 EXPECT_EQ(202 , message.repeated_int64 (0)); 643 EXPECT_EQ(202 , message.repeated_int64 (0));
609 EXPECT_EQ(203 , message.repeated_uint32 (0)); 644 EXPECT_EQ(203 , message.repeated_uint32 (0));
610 EXPECT_EQ(204 , message.repeated_uint64 (0)); 645 EXPECT_EQ(204 , message.repeated_uint64 (0));
611 EXPECT_EQ(205 , message.repeated_sint32 (0)); 646 EXPECT_EQ(205 , message.repeated_sint32 (0));
612 EXPECT_EQ(206 , message.repeated_sint64 (0)); 647 EXPECT_EQ(206 , message.repeated_sint64 (0));
613 EXPECT_EQ(207 , message.repeated_fixed32 (0)); 648 EXPECT_EQ(207 , message.repeated_fixed32 (0));
614 EXPECT_EQ(208 , message.repeated_fixed64 (0)); 649 EXPECT_EQ(208 , message.repeated_fixed64 (0));
615 EXPECT_EQ(209 , message.repeated_sfixed32(0)); 650 EXPECT_EQ(209 , message.repeated_sfixed32(0));
616 EXPECT_EQ(210 , message.repeated_sfixed64(0)); 651 EXPECT_EQ(210 , message.repeated_sfixed64(0));
617 EXPECT_EQ(211 , message.repeated_float (0)); 652 EXPECT_EQ(211 , message.repeated_float (0));
618 EXPECT_EQ(212 , message.repeated_double (0)); 653 EXPECT_EQ(212 , message.repeated_double (0));
619 EXPECT_EQ(true , message.repeated_bool (0)); 654 EXPECT_EQ(true , message.repeated_bool (0));
620 EXPECT_EQ("215", message.repeated_string (0)); 655 EXPECT_EQ("215", message.repeated_string (0));
621 EXPECT_EQ("216", message.repeated_bytes (0)); 656 EXPECT_EQ("216", message.repeated_bytes (0));
622 657
623 EXPECT_EQ(217, message.repeatedgroup (0).a()); 658 EXPECT_EQ(217, message.repeatedgroup (0).a());
624 EXPECT_EQ(218, message.repeated_nested_message (0).bb()); 659 EXPECT_EQ(218, message.repeated_nested_message (0).bb());
625 EXPECT_EQ(219, message.repeated_foreign_message(0).c()); 660 EXPECT_EQ(219, message.repeated_foreign_message(0).c());
626 EXPECT_EQ(220, message.repeated_import_message (0).d()); 661 EXPECT_EQ(220, message.repeated_import_message (0).d());
662 EXPECT_EQ(227, message.repeated_lazy_message (0).bb());
627 663
628 EXPECT_EQ(unittest::TestAllTypes::BAR, message.repeated_nested_enum (0)); 664 EXPECT_EQ(unittest::TestAllTypes::BAR, message.repeated_nested_enum (0));
629 EXPECT_EQ(unittest::FOREIGN_BAR , message.repeated_foreign_enum(0)); 665 EXPECT_EQ(unittest::FOREIGN_BAR , message.repeated_foreign_enum(0));
630 EXPECT_EQ(unittest_import::IMPORT_BAR, message.repeated_import_enum (0)); 666 EXPECT_EQ(unittest_import::IMPORT_BAR, message.repeated_import_enum (0));
631 667
632 668
633 // Actually verify the second (modified) elements now. 669 // Actually verify the second (modified) elements now.
634 EXPECT_EQ(501 , message.repeated_int32 (1)); 670 EXPECT_EQ(501 , message.repeated_int32 (1));
635 EXPECT_EQ(502 , message.repeated_int64 (1)); 671 EXPECT_EQ(502 , message.repeated_int64 (1));
636 EXPECT_EQ(503 , message.repeated_uint32 (1)); 672 EXPECT_EQ(503 , message.repeated_uint32 (1));
637 EXPECT_EQ(504 , message.repeated_uint64 (1)); 673 EXPECT_EQ(504 , message.repeated_uint64 (1));
638 EXPECT_EQ(505 , message.repeated_sint32 (1)); 674 EXPECT_EQ(505 , message.repeated_sint32 (1));
639 EXPECT_EQ(506 , message.repeated_sint64 (1)); 675 EXPECT_EQ(506 , message.repeated_sint64 (1));
640 EXPECT_EQ(507 , message.repeated_fixed32 (1)); 676 EXPECT_EQ(507 , message.repeated_fixed32 (1));
641 EXPECT_EQ(508 , message.repeated_fixed64 (1)); 677 EXPECT_EQ(508 , message.repeated_fixed64 (1));
642 EXPECT_EQ(509 , message.repeated_sfixed32(1)); 678 EXPECT_EQ(509 , message.repeated_sfixed32(1));
643 EXPECT_EQ(510 , message.repeated_sfixed64(1)); 679 EXPECT_EQ(510 , message.repeated_sfixed64(1));
644 EXPECT_EQ(511 , message.repeated_float (1)); 680 EXPECT_EQ(511 , message.repeated_float (1));
645 EXPECT_EQ(512 , message.repeated_double (1)); 681 EXPECT_EQ(512 , message.repeated_double (1));
646 EXPECT_EQ(true , message.repeated_bool (1)); 682 EXPECT_EQ(true , message.repeated_bool (1));
647 EXPECT_EQ("515", message.repeated_string (1)); 683 EXPECT_EQ("515", message.repeated_string (1));
648 EXPECT_EQ("516", message.repeated_bytes (1)); 684 EXPECT_EQ("516", message.repeated_bytes (1));
649 685
650 EXPECT_EQ(517, message.repeatedgroup (1).a()); 686 EXPECT_EQ(517, message.repeatedgroup (1).a());
651 EXPECT_EQ(518, message.repeated_nested_message (1).bb()); 687 EXPECT_EQ(518, message.repeated_nested_message (1).bb());
652 EXPECT_EQ(519, message.repeated_foreign_message(1).c()); 688 EXPECT_EQ(519, message.repeated_foreign_message(1).c());
653 EXPECT_EQ(520, message.repeated_import_message (1).d()); 689 EXPECT_EQ(520, message.repeated_import_message (1).d());
690 EXPECT_EQ(527, message.repeated_lazy_message (1).bb());
654 691
655 EXPECT_EQ(unittest::TestAllTypes::FOO, message.repeated_nested_enum (1)); 692 EXPECT_EQ(unittest::TestAllTypes::FOO, message.repeated_nested_enum (1));
656 EXPECT_EQ(unittest::FOREIGN_FOO , message.repeated_foreign_enum(1)); 693 EXPECT_EQ(unittest::FOREIGN_FOO , message.repeated_foreign_enum(1));
657 EXPECT_EQ(unittest_import::IMPORT_FOO, message.repeated_import_enum (1)); 694 EXPECT_EQ(unittest_import::IMPORT_FOO, message.repeated_import_enum (1));
658 695
659 } 696 }
660 697
661 // ------------------------------------------------------------------- 698 // -------------------------------------------------------------------
662 699
663 void TestUtil::SetPackedFields(unittest::TestPackedTypes* message) { 700 void TestUtil::SetPackedFields(unittest::TestPackedTypes* message) {
664 message->add_packed_int32 (601); 701 message->add_packed_int32 (601);
665 message->add_packed_int64 (602); 702 message->add_packed_int64 (602);
666 message->add_packed_uint32 (603); 703 message->add_packed_uint32 (603);
667 message->add_packed_uint64 (604); 704 message->add_packed_uint64 (604);
668 message->add_packed_sint32 (605); 705 message->add_packed_sint32 (605);
669 message->add_packed_sint64 (606); 706 message->add_packed_sint64 (606);
670 message->add_packed_fixed32 (607); 707 message->add_packed_fixed32 (607);
671 message->add_packed_fixed64 (608); 708 message->add_packed_fixed64 (608);
672 message->add_packed_sfixed32(609); 709 message->add_packed_sfixed32(609);
673 message->add_packed_sfixed64(610); 710 message->add_packed_sfixed64(610);
674 message->add_packed_float (611); 711 message->add_packed_float (611);
675 message->add_packed_double (612); 712 message->add_packed_double (612);
676 message->add_packed_bool (true); 713 message->add_packed_bool (true);
677 message->add_packed_enum (unittest::FOREIGN_BAR); 714 message->add_packed_enum (unittest::FOREIGN_BAR);
678 // add a second one of each field 715 // add a second one of each field
679 message->add_packed_int32 (701); 716 message->add_packed_int32 (701);
680 message->add_packed_int64 (702); 717 message->add_packed_int64 (702);
681 message->add_packed_uint32 (703); 718 message->add_packed_uint32 (703);
682 message->add_packed_uint64 (704); 719 message->add_packed_uint64 (704);
683 message->add_packed_sint32 (705); 720 message->add_packed_sint32 (705);
684 message->add_packed_sint64 (706); 721 message->add_packed_sint64 (706);
685 message->add_packed_fixed32 (707); 722 message->add_packed_fixed32 (707);
686 message->add_packed_fixed64 (708); 723 message->add_packed_fixed64 (708);
687 message->add_packed_sfixed32(709); 724 message->add_packed_sfixed32(709);
688 message->add_packed_sfixed64(710); 725 message->add_packed_sfixed64(710);
689 message->add_packed_float (711); 726 message->add_packed_float (711);
690 message->add_packed_double (712); 727 message->add_packed_double (712);
691 message->add_packed_bool (false); 728 message->add_packed_bool (false);
692 message->add_packed_enum (unittest::FOREIGN_BAZ); 729 message->add_packed_enum (unittest::FOREIGN_BAZ);
693 } 730 }
694 731
695 void TestUtil::SetUnpackedFields(unittest::TestUnpackedTypes* message) { 732 void TestUtil::SetUnpackedFields(unittest::TestUnpackedTypes* message) {
696 // The values applied here must match those of SetPackedFields. 733 // The values applied here must match those of SetPackedFields.
697 734
698 message->add_unpacked_int32 (601); 735 message->add_unpacked_int32 (601);
699 message->add_unpacked_int64 (602); 736 message->add_unpacked_int64 (602);
700 message->add_unpacked_uint32 (603); 737 message->add_unpacked_uint32 (603);
701 message->add_unpacked_uint64 (604); 738 message->add_unpacked_uint64 (604);
702 message->add_unpacked_sint32 (605); 739 message->add_unpacked_sint32 (605);
703 message->add_unpacked_sint64 (606); 740 message->add_unpacked_sint64 (606);
704 message->add_unpacked_fixed32 (607); 741 message->add_unpacked_fixed32 (607);
705 message->add_unpacked_fixed64 (608); 742 message->add_unpacked_fixed64 (608);
706 message->add_unpacked_sfixed32(609); 743 message->add_unpacked_sfixed32(609);
707 message->add_unpacked_sfixed64(610); 744 message->add_unpacked_sfixed64(610);
708 message->add_unpacked_float (611); 745 message->add_unpacked_float (611);
709 message->add_unpacked_double (612); 746 message->add_unpacked_double (612);
710 message->add_unpacked_bool (true); 747 message->add_unpacked_bool (true);
711 message->add_unpacked_enum (unittest::FOREIGN_BAR); 748 message->add_unpacked_enum (unittest::FOREIGN_BAR);
712 // add a second one of each field 749 // add a second one of each field
713 message->add_unpacked_int32 (701); 750 message->add_unpacked_int32 (701);
714 message->add_unpacked_int64 (702); 751 message->add_unpacked_int64 (702);
715 message->add_unpacked_uint32 (703); 752 message->add_unpacked_uint32 (703);
716 message->add_unpacked_uint64 (704); 753 message->add_unpacked_uint64 (704);
717 message->add_unpacked_sint32 (705); 754 message->add_unpacked_sint32 (705);
718 message->add_unpacked_sint64 (706); 755 message->add_unpacked_sint64 (706);
719 message->add_unpacked_fixed32 (707); 756 message->add_unpacked_fixed32 (707);
720 message->add_unpacked_fixed64 (708); 757 message->add_unpacked_fixed64 (708);
721 message->add_unpacked_sfixed32(709); 758 message->add_unpacked_sfixed32(709);
722 message->add_unpacked_sfixed64(710); 759 message->add_unpacked_sfixed64(710);
723 message->add_unpacked_float (711); 760 message->add_unpacked_float (711);
724 message->add_unpacked_double (712); 761 message->add_unpacked_double (712);
725 message->add_unpacked_bool (false); 762 message->add_unpacked_bool (false);
726 message->add_unpacked_enum (unittest::FOREIGN_BAZ); 763 message->add_unpacked_enum (unittest::FOREIGN_BAZ);
727 } 764 }
728 765
729 // ------------------------------------------------------------------- 766 // -------------------------------------------------------------------
730 767
731 void TestUtil::ModifyPackedFields(unittest::TestPackedTypes* message) { 768 void TestUtil::ModifyPackedFields(unittest::TestPackedTypes* message) {
732 message->set_packed_int32 (1, 801); 769 message->set_packed_int32 (1, 801);
733 message->set_packed_int64 (1, 802); 770 message->set_packed_int64 (1, 802);
734 message->set_packed_uint32 (1, 803); 771 message->set_packed_uint32 (1, 803);
735 message->set_packed_uint64 (1, 804); 772 message->set_packed_uint64 (1, 804);
736 message->set_packed_sint32 (1, 805); 773 message->set_packed_sint32 (1, 805);
737 message->set_packed_sint64 (1, 806); 774 message->set_packed_sint64 (1, 806);
738 message->set_packed_fixed32 (1, 807); 775 message->set_packed_fixed32 (1, 807);
739 message->set_packed_fixed64 (1, 808); 776 message->set_packed_fixed64 (1, 808);
740 message->set_packed_sfixed32(1, 809); 777 message->set_packed_sfixed32(1, 809);
741 message->set_packed_sfixed64(1, 810); 778 message->set_packed_sfixed64(1, 810);
742 message->set_packed_float (1, 811); 779 message->set_packed_float (1, 811);
743 message->set_packed_double (1, 812); 780 message->set_packed_double (1, 812);
744 message->set_packed_bool (1, true); 781 message->set_packed_bool (1, true);
745 message->set_packed_enum (1, unittest::FOREIGN_FOO); 782 message->set_packed_enum (1, unittest::FOREIGN_FOO);
746 } 783 }
747 784
748 // ------------------------------------------------------------------- 785 // -------------------------------------------------------------------
749 786
750 void TestUtil::ExpectPackedFieldsSet(const unittest::TestPackedTypes& message) { 787 void TestUtil::ExpectPackedFieldsSet(const unittest::TestPackedTypes& message) {
751 ASSERT_EQ(2, message.packed_int32_size ()); 788 ASSERT_EQ(2, message.packed_int32_size ());
752 ASSERT_EQ(2, message.packed_int64_size ()); 789 ASSERT_EQ(2, message.packed_int64_size ());
753 ASSERT_EQ(2, message.packed_uint32_size ()); 790 ASSERT_EQ(2, message.packed_uint32_size ());
754 ASSERT_EQ(2, message.packed_uint64_size ()); 791 ASSERT_EQ(2, message.packed_uint64_size ());
755 ASSERT_EQ(2, message.packed_sint32_size ()); 792 ASSERT_EQ(2, message.packed_sint32_size ());
756 ASSERT_EQ(2, message.packed_sint64_size ()); 793 ASSERT_EQ(2, message.packed_sint64_size ());
757 ASSERT_EQ(2, message.packed_fixed32_size ()); 794 ASSERT_EQ(2, message.packed_fixed32_size ());
758 ASSERT_EQ(2, message.packed_fixed64_size ()); 795 ASSERT_EQ(2, message.packed_fixed64_size ());
759 ASSERT_EQ(2, message.packed_sfixed32_size()); 796 ASSERT_EQ(2, message.packed_sfixed32_size());
760 ASSERT_EQ(2, message.packed_sfixed64_size()); 797 ASSERT_EQ(2, message.packed_sfixed64_size());
761 ASSERT_EQ(2, message.packed_float_size ()); 798 ASSERT_EQ(2, message.packed_float_size ());
762 ASSERT_EQ(2, message.packed_double_size ()); 799 ASSERT_EQ(2, message.packed_double_size ());
763 ASSERT_EQ(2, message.packed_bool_size ()); 800 ASSERT_EQ(2, message.packed_bool_size ());
764 ASSERT_EQ(2, message.packed_enum_size ()); 801 ASSERT_EQ(2, message.packed_enum_size ());
765 802
766 EXPECT_EQ(601 , message.packed_int32 (0)); 803 EXPECT_EQ(601 , message.packed_int32 (0));
767 EXPECT_EQ(602 , message.packed_int64 (0)); 804 EXPECT_EQ(602 , message.packed_int64 (0));
768 EXPECT_EQ(603 , message.packed_uint32 (0)); 805 EXPECT_EQ(603 , message.packed_uint32 (0));
769 EXPECT_EQ(604 , message.packed_uint64 (0)); 806 EXPECT_EQ(604 , message.packed_uint64 (0));
770 EXPECT_EQ(605 , message.packed_sint32 (0)); 807 EXPECT_EQ(605 , message.packed_sint32 (0));
771 EXPECT_EQ(606 , message.packed_sint64 (0)); 808 EXPECT_EQ(606 , message.packed_sint64 (0));
772 EXPECT_EQ(607 , message.packed_fixed32 (0)); 809 EXPECT_EQ(607 , message.packed_fixed32 (0));
773 EXPECT_EQ(608 , message.packed_fixed64 (0)); 810 EXPECT_EQ(608 , message.packed_fixed64 (0));
774 EXPECT_EQ(609 , message.packed_sfixed32(0)); 811 EXPECT_EQ(609 , message.packed_sfixed32(0));
775 EXPECT_EQ(610 , message.packed_sfixed64(0)); 812 EXPECT_EQ(610 , message.packed_sfixed64(0));
776 EXPECT_EQ(611 , message.packed_float (0)); 813 EXPECT_EQ(611 , message.packed_float (0));
777 EXPECT_EQ(612 , message.packed_double (0)); 814 EXPECT_EQ(612 , message.packed_double (0));
778 EXPECT_EQ(true , message.packed_bool (0)); 815 EXPECT_EQ(true , message.packed_bool (0));
779 EXPECT_EQ(unittest::FOREIGN_BAR, message.packed_enum(0)); 816 EXPECT_EQ(unittest::FOREIGN_BAR, message.packed_enum(0));
780 817
781 EXPECT_EQ(701 , message.packed_int32 (1)); 818 EXPECT_EQ(701 , message.packed_int32 (1));
782 EXPECT_EQ(702 , message.packed_int64 (1)); 819 EXPECT_EQ(702 , message.packed_int64 (1));
783 EXPECT_EQ(703 , message.packed_uint32 (1)); 820 EXPECT_EQ(703 , message.packed_uint32 (1));
784 EXPECT_EQ(704 , message.packed_uint64 (1)); 821 EXPECT_EQ(704 , message.packed_uint64 (1));
785 EXPECT_EQ(705 , message.packed_sint32 (1)); 822 EXPECT_EQ(705 , message.packed_sint32 (1));
786 EXPECT_EQ(706 , message.packed_sint64 (1)); 823 EXPECT_EQ(706 , message.packed_sint64 (1));
787 EXPECT_EQ(707 , message.packed_fixed32 (1)); 824 EXPECT_EQ(707 , message.packed_fixed32 (1));
788 EXPECT_EQ(708 , message.packed_fixed64 (1)); 825 EXPECT_EQ(708 , message.packed_fixed64 (1));
789 EXPECT_EQ(709 , message.packed_sfixed32(1)); 826 EXPECT_EQ(709 , message.packed_sfixed32(1));
790 EXPECT_EQ(710 , message.packed_sfixed64(1)); 827 EXPECT_EQ(710 , message.packed_sfixed64(1));
791 EXPECT_EQ(711 , message.packed_float (1)); 828 EXPECT_EQ(711 , message.packed_float (1));
792 EXPECT_EQ(712 , message.packed_double (1)); 829 EXPECT_EQ(712 , message.packed_double (1));
793 EXPECT_EQ(false, message.packed_bool (1)); 830 EXPECT_EQ(false, message.packed_bool (1));
794 EXPECT_EQ(unittest::FOREIGN_BAZ, message.packed_enum(1)); 831 EXPECT_EQ(unittest::FOREIGN_BAZ, message.packed_enum(1));
795 } 832 }
796 833
797 void TestUtil::ExpectUnpackedFieldsSet( 834 void TestUtil::ExpectUnpackedFieldsSet(
798 const unittest::TestUnpackedTypes& message) { 835 const unittest::TestUnpackedTypes& message) {
799 // The values expected here must match those of ExpectPackedFieldsSet. 836 // The values expected here must match those of ExpectPackedFieldsSet.
800 837
801 ASSERT_EQ(2, message.unpacked_int32_size ()); 838 ASSERT_EQ(2, message.unpacked_int32_size ());
802 ASSERT_EQ(2, message.unpacked_int64_size ()); 839 ASSERT_EQ(2, message.unpacked_int64_size ());
803 ASSERT_EQ(2, message.unpacked_uint32_size ()); 840 ASSERT_EQ(2, message.unpacked_uint32_size ());
804 ASSERT_EQ(2, message.unpacked_uint64_size ()); 841 ASSERT_EQ(2, message.unpacked_uint64_size ());
805 ASSERT_EQ(2, message.unpacked_sint32_size ()); 842 ASSERT_EQ(2, message.unpacked_sint32_size ());
806 ASSERT_EQ(2, message.unpacked_sint64_size ()); 843 ASSERT_EQ(2, message.unpacked_sint64_size ());
807 ASSERT_EQ(2, message.unpacked_fixed32_size ()); 844 ASSERT_EQ(2, message.unpacked_fixed32_size ());
808 ASSERT_EQ(2, message.unpacked_fixed64_size ()); 845 ASSERT_EQ(2, message.unpacked_fixed64_size ());
809 ASSERT_EQ(2, message.unpacked_sfixed32_size()); 846 ASSERT_EQ(2, message.unpacked_sfixed32_size());
810 ASSERT_EQ(2, message.unpacked_sfixed64_size()); 847 ASSERT_EQ(2, message.unpacked_sfixed64_size());
811 ASSERT_EQ(2, message.unpacked_float_size ()); 848 ASSERT_EQ(2, message.unpacked_float_size ());
812 ASSERT_EQ(2, message.unpacked_double_size ()); 849 ASSERT_EQ(2, message.unpacked_double_size ());
813 ASSERT_EQ(2, message.unpacked_bool_size ()); 850 ASSERT_EQ(2, message.unpacked_bool_size ());
814 ASSERT_EQ(2, message.unpacked_enum_size ()); 851 ASSERT_EQ(2, message.unpacked_enum_size ());
815 852
816 EXPECT_EQ(601 , message.unpacked_int32 (0)); 853 EXPECT_EQ(601 , message.unpacked_int32 (0));
817 EXPECT_EQ(602 , message.unpacked_int64 (0)); 854 EXPECT_EQ(602 , message.unpacked_int64 (0));
818 EXPECT_EQ(603 , message.unpacked_uint32 (0)); 855 EXPECT_EQ(603 , message.unpacked_uint32 (0));
819 EXPECT_EQ(604 , message.unpacked_uint64 (0)); 856 EXPECT_EQ(604 , message.unpacked_uint64 (0));
820 EXPECT_EQ(605 , message.unpacked_sint32 (0)); 857 EXPECT_EQ(605 , message.unpacked_sint32 (0));
821 EXPECT_EQ(606 , message.unpacked_sint64 (0)); 858 EXPECT_EQ(606 , message.unpacked_sint64 (0));
822 EXPECT_EQ(607 , message.unpacked_fixed32 (0)); 859 EXPECT_EQ(607 , message.unpacked_fixed32 (0));
823 EXPECT_EQ(608 , message.unpacked_fixed64 (0)); 860 EXPECT_EQ(608 , message.unpacked_fixed64 (0));
824 EXPECT_EQ(609 , message.unpacked_sfixed32(0)); 861 EXPECT_EQ(609 , message.unpacked_sfixed32(0));
825 EXPECT_EQ(610 , message.unpacked_sfixed64(0)); 862 EXPECT_EQ(610 , message.unpacked_sfixed64(0));
826 EXPECT_EQ(611 , message.unpacked_float (0)); 863 EXPECT_EQ(611 , message.unpacked_float (0));
827 EXPECT_EQ(612 , message.unpacked_double (0)); 864 EXPECT_EQ(612 , message.unpacked_double (0));
828 EXPECT_EQ(true , message.unpacked_bool (0)); 865 EXPECT_EQ(true , message.unpacked_bool (0));
829 EXPECT_EQ(unittest::FOREIGN_BAR, message.unpacked_enum(0)); 866 EXPECT_EQ(unittest::FOREIGN_BAR, message.unpacked_enum(0));
830 867
831 EXPECT_EQ(701 , message.unpacked_int32 (1)); 868 EXPECT_EQ(701 , message.unpacked_int32 (1));
832 EXPECT_EQ(702 , message.unpacked_int64 (1)); 869 EXPECT_EQ(702 , message.unpacked_int64 (1));
833 EXPECT_EQ(703 , message.unpacked_uint32 (1)); 870 EXPECT_EQ(703 , message.unpacked_uint32 (1));
834 EXPECT_EQ(704 , message.unpacked_uint64 (1)); 871 EXPECT_EQ(704 , message.unpacked_uint64 (1));
835 EXPECT_EQ(705 , message.unpacked_sint32 (1)); 872 EXPECT_EQ(705 , message.unpacked_sint32 (1));
836 EXPECT_EQ(706 , message.unpacked_sint64 (1)); 873 EXPECT_EQ(706 , message.unpacked_sint64 (1));
837 EXPECT_EQ(707 , message.unpacked_fixed32 (1)); 874 EXPECT_EQ(707 , message.unpacked_fixed32 (1));
838 EXPECT_EQ(708 , message.unpacked_fixed64 (1)); 875 EXPECT_EQ(708 , message.unpacked_fixed64 (1));
839 EXPECT_EQ(709 , message.unpacked_sfixed32(1)); 876 EXPECT_EQ(709 , message.unpacked_sfixed32(1));
840 EXPECT_EQ(710 , message.unpacked_sfixed64(1)); 877 EXPECT_EQ(710 , message.unpacked_sfixed64(1));
841 EXPECT_EQ(711 , message.unpacked_float (1)); 878 EXPECT_EQ(711 , message.unpacked_float (1));
842 EXPECT_EQ(712 , message.unpacked_double (1)); 879 EXPECT_EQ(712 , message.unpacked_double (1));
843 EXPECT_EQ(false, message.unpacked_bool (1)); 880 EXPECT_EQ(false, message.unpacked_bool (1));
844 EXPECT_EQ(unittest::FOREIGN_BAZ, message.unpacked_enum(1)); 881 EXPECT_EQ(unittest::FOREIGN_BAZ, message.unpacked_enum(1));
845 } 882 }
846 883
847 // ------------------------------------------------------------------- 884 // -------------------------------------------------------------------
848 885
849 void TestUtil::ExpectPackedClear( 886 void TestUtil::ExpectPackedClear(
850 const unittest::TestPackedTypes& message) { 887 const unittest::TestPackedTypes& message) {
851 // Packed repeated fields are empty. 888 // Packed repeated fields are empty.
852 EXPECT_EQ(0, message.packed_int32_size ()); 889 EXPECT_EQ(0, message.packed_int32_size ());
853 EXPECT_EQ(0, message.packed_int64_size ()); 890 EXPECT_EQ(0, message.packed_int64_size ());
854 EXPECT_EQ(0, message.packed_uint32_size ()); 891 EXPECT_EQ(0, message.packed_uint32_size ());
855 EXPECT_EQ(0, message.packed_uint64_size ()); 892 EXPECT_EQ(0, message.packed_uint64_size ());
856 EXPECT_EQ(0, message.packed_sint32_size ()); 893 EXPECT_EQ(0, message.packed_sint32_size ());
857 EXPECT_EQ(0, message.packed_sint64_size ()); 894 EXPECT_EQ(0, message.packed_sint64_size ());
858 EXPECT_EQ(0, message.packed_fixed32_size ()); 895 EXPECT_EQ(0, message.packed_fixed32_size ());
859 EXPECT_EQ(0, message.packed_fixed64_size ()); 896 EXPECT_EQ(0, message.packed_fixed64_size ());
860 EXPECT_EQ(0, message.packed_sfixed32_size()); 897 EXPECT_EQ(0, message.packed_sfixed32_size());
861 EXPECT_EQ(0, message.packed_sfixed64_size()); 898 EXPECT_EQ(0, message.packed_sfixed64_size());
862 EXPECT_EQ(0, message.packed_float_size ()); 899 EXPECT_EQ(0, message.packed_float_size ());
863 EXPECT_EQ(0, message.packed_double_size ()); 900 EXPECT_EQ(0, message.packed_double_size ());
864 EXPECT_EQ(0, message.packed_bool_size ()); 901 EXPECT_EQ(0, message.packed_bool_size ());
865 EXPECT_EQ(0, message.packed_enum_size ()); 902 EXPECT_EQ(0, message.packed_enum_size ());
866 } 903 }
867 904
868 // ------------------------------------------------------------------- 905 // -------------------------------------------------------------------
869 906
870 void TestUtil::ExpectPackedFieldsModified( 907 void TestUtil::ExpectPackedFieldsModified(
871 const unittest::TestPackedTypes& message) { 908 const unittest::TestPackedTypes& message) {
872 // Do the same for packed repeated fields. 909 // Do the same for packed repeated fields.
873 ASSERT_EQ(2, message.packed_int32_size ()); 910 ASSERT_EQ(2, message.packed_int32_size ());
874 ASSERT_EQ(2, message.packed_int64_size ()); 911 ASSERT_EQ(2, message.packed_int64_size ());
875 ASSERT_EQ(2, message.packed_uint32_size ()); 912 ASSERT_EQ(2, message.packed_uint32_size ());
876 ASSERT_EQ(2, message.packed_uint64_size ()); 913 ASSERT_EQ(2, message.packed_uint64_size ());
877 ASSERT_EQ(2, message.packed_sint32_size ()); 914 ASSERT_EQ(2, message.packed_sint32_size ());
878 ASSERT_EQ(2, message.packed_sint64_size ()); 915 ASSERT_EQ(2, message.packed_sint64_size ());
879 ASSERT_EQ(2, message.packed_fixed32_size ()); 916 ASSERT_EQ(2, message.packed_fixed32_size ());
880 ASSERT_EQ(2, message.packed_fixed64_size ()); 917 ASSERT_EQ(2, message.packed_fixed64_size ());
881 ASSERT_EQ(2, message.packed_sfixed32_size()); 918 ASSERT_EQ(2, message.packed_sfixed32_size());
882 ASSERT_EQ(2, message.packed_sfixed64_size()); 919 ASSERT_EQ(2, message.packed_sfixed64_size());
883 ASSERT_EQ(2, message.packed_float_size ()); 920 ASSERT_EQ(2, message.packed_float_size ());
884 ASSERT_EQ(2, message.packed_double_size ()); 921 ASSERT_EQ(2, message.packed_double_size ());
885 ASSERT_EQ(2, message.packed_bool_size ()); 922 ASSERT_EQ(2, message.packed_bool_size ());
886 ASSERT_EQ(2, message.packed_enum_size ()); 923 ASSERT_EQ(2, message.packed_enum_size ());
887 924
888 EXPECT_EQ(601 , message.packed_int32 (0)); 925 EXPECT_EQ(601 , message.packed_int32 (0));
889 EXPECT_EQ(602 , message.packed_int64 (0)); 926 EXPECT_EQ(602 , message.packed_int64 (0));
890 EXPECT_EQ(603 , message.packed_uint32 (0)); 927 EXPECT_EQ(603 , message.packed_uint32 (0));
891 EXPECT_EQ(604 , message.packed_uint64 (0)); 928 EXPECT_EQ(604 , message.packed_uint64 (0));
892 EXPECT_EQ(605 , message.packed_sint32 (0)); 929 EXPECT_EQ(605 , message.packed_sint32 (0));
893 EXPECT_EQ(606 , message.packed_sint64 (0)); 930 EXPECT_EQ(606 , message.packed_sint64 (0));
894 EXPECT_EQ(607 , message.packed_fixed32 (0)); 931 EXPECT_EQ(607 , message.packed_fixed32 (0));
895 EXPECT_EQ(608 , message.packed_fixed64 (0)); 932 EXPECT_EQ(608 , message.packed_fixed64 (0));
896 EXPECT_EQ(609 , message.packed_sfixed32(0)); 933 EXPECT_EQ(609 , message.packed_sfixed32(0));
897 EXPECT_EQ(610 , message.packed_sfixed64(0)); 934 EXPECT_EQ(610 , message.packed_sfixed64(0));
898 EXPECT_EQ(611 , message.packed_float (0)); 935 EXPECT_EQ(611 , message.packed_float (0));
899 EXPECT_EQ(612 , message.packed_double (0)); 936 EXPECT_EQ(612 , message.packed_double (0));
900 EXPECT_EQ(true , message.packed_bool (0)); 937 EXPECT_EQ(true , message.packed_bool (0));
901 EXPECT_EQ(unittest::FOREIGN_BAR, message.packed_enum(0)); 938 EXPECT_EQ(unittest::FOREIGN_BAR, message.packed_enum(0));
902 // Actually verify the second (modified) elements now. 939 // Actually verify the second (modified) elements now.
903 EXPECT_EQ(801 , message.packed_int32 (1)); 940 EXPECT_EQ(801 , message.packed_int32 (1));
904 EXPECT_EQ(802 , message.packed_int64 (1)); 941 EXPECT_EQ(802 , message.packed_int64 (1));
905 EXPECT_EQ(803 , message.packed_uint32 (1)); 942 EXPECT_EQ(803 , message.packed_uint32 (1));
906 EXPECT_EQ(804 , message.packed_uint64 (1)); 943 EXPECT_EQ(804 , message.packed_uint64 (1));
907 EXPECT_EQ(805 , message.packed_sint32 (1)); 944 EXPECT_EQ(805 , message.packed_sint32 (1));
908 EXPECT_EQ(806 , message.packed_sint64 (1)); 945 EXPECT_EQ(806 , message.packed_sint64 (1));
909 EXPECT_EQ(807 , message.packed_fixed32 (1)); 946 EXPECT_EQ(807 , message.packed_fixed32 (1));
910 EXPECT_EQ(808 , message.packed_fixed64 (1)); 947 EXPECT_EQ(808 , message.packed_fixed64 (1));
911 EXPECT_EQ(809 , message.packed_sfixed32(1)); 948 EXPECT_EQ(809 , message.packed_sfixed32(1));
912 EXPECT_EQ(810 , message.packed_sfixed64(1)); 949 EXPECT_EQ(810 , message.packed_sfixed64(1));
913 EXPECT_EQ(811 , message.packed_float (1)); 950 EXPECT_EQ(811 , message.packed_float (1));
914 EXPECT_EQ(812 , message.packed_double (1)); 951 EXPECT_EQ(812 , message.packed_double (1));
915 EXPECT_EQ(true , message.packed_bool (1)); 952 EXPECT_EQ(true , message.packed_bool (1));
916 EXPECT_EQ(unittest::FOREIGN_FOO, message.packed_enum(1)); 953 EXPECT_EQ(unittest::FOREIGN_FOO, message.packed_enum(1));
917 } 954 }
918 955
919 // =================================================================== 956 // ===================================================================
920 // Extensions 957 // Extensions
921 // 958 //
922 // All this code is exactly equivalent to the above code except that it's 959 // All this code is exactly equivalent to the above code except that it's
923 // manipulating extension fields instead of normal ones. 960 // manipulating extension fields instead of normal ones.
924 // 961 //
925 // I gave up on the 80-char limit here. Sorry. 962 // I gave up on the 80-char limit here. Sorry.
926 963
927 void TestUtil::SetAllExtensions(unittest::TestAllExtensions* message) { 964 void TestUtil::SetAllExtensions(unittest::TestAllExtensions* message) {
928 message->SetExtension(unittest::optional_int32_extension , 101); 965 message->SetExtension(unittest::optional_int32_extension , 101);
929 message->SetExtension(unittest::optional_int64_extension , 102); 966 message->SetExtension(unittest::optional_int64_extension , 102);
930 message->SetExtension(unittest::optional_uint32_extension , 103); 967 message->SetExtension(unittest::optional_uint32_extension , 103);
931 message->SetExtension(unittest::optional_uint64_extension , 104); 968 message->SetExtension(unittest::optional_uint64_extension , 104);
932 message->SetExtension(unittest::optional_sint32_extension , 105); 969 message->SetExtension(unittest::optional_sint32_extension , 105);
933 message->SetExtension(unittest::optional_sint64_extension , 106); 970 message->SetExtension(unittest::optional_sint64_extension , 106);
934 message->SetExtension(unittest::optional_fixed32_extension , 107); 971 message->SetExtension(unittest::optional_fixed32_extension , 107);
935 message->SetExtension(unittest::optional_fixed64_extension , 108); 972 message->SetExtension(unittest::optional_fixed64_extension , 108);
936 message->SetExtension(unittest::optional_sfixed32_extension, 109); 973 message->SetExtension(unittest::optional_sfixed32_extension, 109);
937 message->SetExtension(unittest::optional_sfixed64_extension, 110); 974 message->SetExtension(unittest::optional_sfixed64_extension, 110);
938 message->SetExtension(unittest::optional_float_extension , 111); 975 message->SetExtension(unittest::optional_float_extension , 111);
939 message->SetExtension(unittest::optional_double_extension , 112); 976 message->SetExtension(unittest::optional_double_extension , 112);
940 message->SetExtension(unittest::optional_bool_extension , true); 977 message->SetExtension(unittest::optional_bool_extension , true);
941 message->SetExtension(unittest::optional_string_extension , "115"); 978 message->SetExtension(unittest::optional_string_extension , "115");
942 message->SetExtension(unittest::optional_bytes_extension , "116"); 979 message->SetExtension(unittest::optional_bytes_extension , "116");
943 980
944 message->MutableExtension(unittest::optionalgroup_extension )->set_a(117); 981 message->MutableExtension(unittest::optionalgroup_extension )->set_a(117);
945 message->MutableExtension(unittest::optional_nested_message_extension )->set_bb(118); 982 message->MutableExtension(unittest::optional_nested_message_extension )->set_bb(118);
946 message->MutableExtension(unittest::optional_foreign_message_extension)->set_c(119); 983 message->MutableExtension(unittest::optional_foreign_message_extension)->set_c(119);
947 message->MutableExtension(unittest::optional_import_message_extension )->set_d(120); 984 message->MutableExtension(unittest::optional_import_message_extension )->set_d(120);
948 985
949 message->SetExtension(unittest::optional_nested_enum_extension , unittest::TestAllTypes::BAZ); 986 message->SetExtension(unittest::optional_nested_enum_extension , unittest::TestAllTypes::BAZ);
950 message->SetExtension(unittest::optional_foreign_enum_extension, unittest::FOREIGN_BAZ ); 987 message->SetExtension(unittest::optional_foreign_enum_extension, unittest::FOREIGN_BAZ );
951 message->SetExtension(unittest::optional_import_enum_extension , unittest_import::IMPORT_BAZ); 988 message->SetExtension(unittest::optional_import_enum_extension , unittest_import::IMPORT_BAZ);
952 989
953 message->SetExtension(unittest::optional_string_piece_extension, "124"); 990 message->SetExtension(unittest::optional_string_piece_extension, "124");
954 message->SetExtension(unittest::optional_cord_extension, "125"); 991 message->SetExtension(unittest::optional_cord_extension, "125");
955 992
993 message->MutableExtension(unittest::optional_public_import_message_extension)->set_e(126);
994 message->MutableExtension(unittest::optional_lazy_message_extension)->set_bb(127);
995
956 // ----------------------------------------------------------------- 996 // -----------------------------------------------------------------
957 997
958 message->AddExtension(unittest::repeated_int32_extension , 201); 998 message->AddExtension(unittest::repeated_int32_extension , 201);
959 message->AddExtension(unittest::repeated_int64_extension , 202); 999 message->AddExtension(unittest::repeated_int64_extension , 202);
960 message->AddExtension(unittest::repeated_uint32_extension , 203); 1000 message->AddExtension(unittest::repeated_uint32_extension , 203);
961 message->AddExtension(unittest::repeated_uint64_extension , 204); 1001 message->AddExtension(unittest::repeated_uint64_extension , 204);
962 message->AddExtension(unittest::repeated_sint32_extension , 205); 1002 message->AddExtension(unittest::repeated_sint32_extension , 205);
963 message->AddExtension(unittest::repeated_sint64_extension , 206); 1003 message->AddExtension(unittest::repeated_sint64_extension , 206);
964 message->AddExtension(unittest::repeated_fixed32_extension , 207); 1004 message->AddExtension(unittest::repeated_fixed32_extension , 207);
965 message->AddExtension(unittest::repeated_fixed64_extension , 208); 1005 message->AddExtension(unittest::repeated_fixed64_extension , 208);
966 message->AddExtension(unittest::repeated_sfixed32_extension, 209); 1006 message->AddExtension(unittest::repeated_sfixed32_extension, 209);
967 message->AddExtension(unittest::repeated_sfixed64_extension, 210); 1007 message->AddExtension(unittest::repeated_sfixed64_extension, 210);
968 message->AddExtension(unittest::repeated_float_extension , 211); 1008 message->AddExtension(unittest::repeated_float_extension , 211);
969 message->AddExtension(unittest::repeated_double_extension , 212); 1009 message->AddExtension(unittest::repeated_double_extension , 212);
970 message->AddExtension(unittest::repeated_bool_extension , true); 1010 message->AddExtension(unittest::repeated_bool_extension , true);
971 message->AddExtension(unittest::repeated_string_extension , "215"); 1011 message->AddExtension(unittest::repeated_string_extension , "215");
972 message->AddExtension(unittest::repeated_bytes_extension , "216"); 1012 message->AddExtension(unittest::repeated_bytes_extension , "216");
973 1013
974 message->AddExtension(unittest::repeatedgroup_extension )->set_a(217); 1014 message->AddExtension(unittest::repeatedgroup_extension )->set_a(217);
975 message->AddExtension(unittest::repeated_nested_message_extension )->set_bb(218); 1015 message->AddExtension(unittest::repeated_nested_message_extension )->set_bb(218);
976 message->AddExtension(unittest::repeated_foreign_message_extension)->set_c(219); 1016 message->AddExtension(unittest::repeated_foreign_message_extension)->set_c(219);
977 message->AddExtension(unittest::repeated_import_message_extension )->set_d(220); 1017 message->AddExtension(unittest::repeated_import_message_extension )->set_d(220);
1018 message->AddExtension(unittest::repeated_lazy_message_extension )->set_bb(227);
978 1019
979 message->AddExtension(unittest::repeated_nested_enum_extension , unittest::TestAllTypes::BAR); 1020 message->AddExtension(unittest::repeated_nested_enum_extension , unittest::TestAllTypes::BAR);
980 message->AddExtension(unittest::repeated_foreign_enum_extension, unittest::FOREIGN_BAR ); 1021 message->AddExtension(unittest::repeated_foreign_enum_extension, unittest::FOREIGN_BAR );
981 message->AddExtension(unittest::repeated_import_enum_extension , unittest_import::IMPORT_BAR); 1022 message->AddExtension(unittest::repeated_import_enum_extension , unittest_import::IMPORT_BAR);
982 1023
983 message->AddExtension(unittest::repeated_string_piece_extension, "224"); 1024 message->AddExtension(unittest::repeated_string_piece_extension, "224");
984 message->AddExtension(unittest::repeated_cord_extension, "225"); 1025 message->AddExtension(unittest::repeated_cord_extension, "225");
985 1026
986 // Add a second one of each field. 1027 // Add a second one of each field.
987 message->AddExtension(unittest::repeated_int32_extension , 301); 1028 message->AddExtension(unittest::repeated_int32_extension , 301);
988 message->AddExtension(unittest::repeated_int64_extension , 302); 1029 message->AddExtension(unittest::repeated_int64_extension , 302);
989 message->AddExtension(unittest::repeated_uint32_extension , 303); 1030 message->AddExtension(unittest::repeated_uint32_extension , 303);
990 message->AddExtension(unittest::repeated_uint64_extension , 304); 1031 message->AddExtension(unittest::repeated_uint64_extension , 304);
991 message->AddExtension(unittest::repeated_sint32_extension , 305); 1032 message->AddExtension(unittest::repeated_sint32_extension , 305);
992 message->AddExtension(unittest::repeated_sint64_extension , 306); 1033 message->AddExtension(unittest::repeated_sint64_extension , 306);
993 message->AddExtension(unittest::repeated_fixed32_extension , 307); 1034 message->AddExtension(unittest::repeated_fixed32_extension , 307);
994 message->AddExtension(unittest::repeated_fixed64_extension , 308); 1035 message->AddExtension(unittest::repeated_fixed64_extension , 308);
995 message->AddExtension(unittest::repeated_sfixed32_extension, 309); 1036 message->AddExtension(unittest::repeated_sfixed32_extension, 309);
996 message->AddExtension(unittest::repeated_sfixed64_extension, 310); 1037 message->AddExtension(unittest::repeated_sfixed64_extension, 310);
997 message->AddExtension(unittest::repeated_float_extension , 311); 1038 message->AddExtension(unittest::repeated_float_extension , 311);
998 message->AddExtension(unittest::repeated_double_extension , 312); 1039 message->AddExtension(unittest::repeated_double_extension , 312);
999 message->AddExtension(unittest::repeated_bool_extension , false); 1040 message->AddExtension(unittest::repeated_bool_extension , false);
1000 message->AddExtension(unittest::repeated_string_extension , "315"); 1041 message->AddExtension(unittest::repeated_string_extension , "315");
1001 message->AddExtension(unittest::repeated_bytes_extension , "316"); 1042 message->AddExtension(unittest::repeated_bytes_extension , "316");
1002 1043
1003 message->AddExtension(unittest::repeatedgroup_extension )->set_a(317); 1044 message->AddExtension(unittest::repeatedgroup_extension )->set_a(317);
1004 message->AddExtension(unittest::repeated_nested_message_extension )->set_bb(318); 1045 message->AddExtension(unittest::repeated_nested_message_extension )->set_bb(318);
1005 message->AddExtension(unittest::repeated_foreign_message_extension)->set_c(319); 1046 message->AddExtension(unittest::repeated_foreign_message_extension)->set_c(319);
1006 message->AddExtension(unittest::repeated_import_message_extension )->set_d(320); 1047 message->AddExtension(unittest::repeated_import_message_extension )->set_d(320);
1048 message->AddExtension(unittest::repeated_lazy_message_extension )->set_bb(327);
1007 1049
1008 message->AddExtension(unittest::repeated_nested_enum_extension , unittest::TestAllTypes::BAZ); 1050 message->AddExtension(unittest::repeated_nested_enum_extension , unittest::TestAllTypes::BAZ);
1009 message->AddExtension(unittest::repeated_foreign_enum_extension, unittest::FOREIGN_BAZ ); 1051 message->AddExtension(unittest::repeated_foreign_enum_extension, unittest::FOREIGN_BAZ );
1010 message->AddExtension(unittest::repeated_import_enum_extension , unittest_import::IMPORT_BAZ); 1052 message->AddExtension(unittest::repeated_import_enum_extension , unittest_import::IMPORT_BAZ);
1011 1053
1012 message->AddExtension(unittest::repeated_string_piece_extension, "324"); 1054 message->AddExtension(unittest::repeated_string_piece_extension, "324");
1013 message->AddExtension(unittest::repeated_cord_extension, "325"); 1055 message->AddExtension(unittest::repeated_cord_extension, "325");
1014 1056
1015 // ----------------------------------------------------------------- 1057 // -----------------------------------------------------------------
1016 1058
1017 message->SetExtension(unittest::default_int32_extension , 401); 1059 message->SetExtension(unittest::default_int32_extension , 401);
1018 message->SetExtension(unittest::default_int64_extension , 402); 1060 message->SetExtension(unittest::default_int64_extension , 402);
1019 message->SetExtension(unittest::default_uint32_extension , 403); 1061 message->SetExtension(unittest::default_uint32_extension , 403);
1020 message->SetExtension(unittest::default_uint64_extension , 404); 1062 message->SetExtension(unittest::default_uint64_extension , 404);
1021 message->SetExtension(unittest::default_sint32_extension , 405); 1063 message->SetExtension(unittest::default_sint32_extension , 405);
1022 message->SetExtension(unittest::default_sint64_extension , 406); 1064 message->SetExtension(unittest::default_sint64_extension , 406);
1023 message->SetExtension(unittest::default_fixed32_extension , 407); 1065 message->SetExtension(unittest::default_fixed32_extension , 407);
1024 message->SetExtension(unittest::default_fixed64_extension , 408); 1066 message->SetExtension(unittest::default_fixed64_extension , 408);
1025 message->SetExtension(unittest::default_sfixed32_extension, 409); 1067 message->SetExtension(unittest::default_sfixed32_extension, 409);
1026 message->SetExtension(unittest::default_sfixed64_extension, 410); 1068 message->SetExtension(unittest::default_sfixed64_extension, 410);
1027 message->SetExtension(unittest::default_float_extension , 411); 1069 message->SetExtension(unittest::default_float_extension , 411);
1028 message->SetExtension(unittest::default_double_extension , 412); 1070 message->SetExtension(unittest::default_double_extension , 412);
1029 message->SetExtension(unittest::default_bool_extension , false); 1071 message->SetExtension(unittest::default_bool_extension , false);
1030 message->SetExtension(unittest::default_string_extension , "415"); 1072 message->SetExtension(unittest::default_string_extension , "415");
1031 message->SetExtension(unittest::default_bytes_extension , "416"); 1073 message->SetExtension(unittest::default_bytes_extension , "416");
1032 1074
1033 message->SetExtension(unittest::default_nested_enum_extension , unittest::TestAllTypes::FOO); 1075 message->SetExtension(unittest::default_nested_enum_extension , unittest::TestAllTypes::FOO);
1034 message->SetExtension(unittest::default_foreign_enum_extension, unittest::FOREIGN_FOO ); 1076 message->SetExtension(unittest::default_foreign_enum_extension, unittest::FOREIGN_FOO );
1035 message->SetExtension(unittest::default_import_enum_extension , unittest_import::IMPORT_FOO); 1077 message->SetExtension(unittest::default_import_enum_extension , unittest_import::IMPORT_FOO);
1036 1078
1037 message->SetExtension(unittest::default_string_piece_extension, "424"); 1079 message->SetExtension(unittest::default_string_piece_extension, "424");
1038 message->SetExtension(unittest::default_cord_extension, "425"); 1080 message->SetExtension(unittest::default_cord_extension, "425");
1039 } 1081 }
1040 1082
1041 // ------------------------------------------------------------------- 1083 // -------------------------------------------------------------------
1042 1084
1043 void TestUtil::SetAllFieldsAndExtensions( 1085 void TestUtil::SetAllFieldsAndExtensions(
1044 unittest::TestFieldOrderings* message) { 1086 unittest::TestFieldOrderings* message) {
1045 GOOGLE_CHECK(message); 1087 GOOGLE_CHECK(message);
1046 message->set_my_int(1); 1088 message->set_my_int(1);
1047 message->set_my_string("foo"); 1089 message->set_my_string("foo");
1048 message->set_my_float(1.0); 1090 message->set_my_float(1.0);
1049 message->SetExtension(unittest::my_extension_int, 23); 1091 message->SetExtension(unittest::my_extension_int, 23);
1050 message->SetExtension(unittest::my_extension_string, "bar"); 1092 message->SetExtension(unittest::my_extension_string, "bar");
1051 } 1093 }
1052 1094
1053 // ------------------------------------------------------------------- 1095 // -------------------------------------------------------------------
1054 1096
1055 void TestUtil::ModifyRepeatedExtensions(unittest::TestAllExtensions* message) { 1097 void TestUtil::ModifyRepeatedExtensions(unittest::TestAllExtensions* message) {
1056 message->SetExtension(unittest::repeated_int32_extension , 1, 501); 1098 message->SetExtension(unittest::repeated_int32_extension , 1, 501);
1057 message->SetExtension(unittest::repeated_int64_extension , 1, 502); 1099 message->SetExtension(unittest::repeated_int64_extension , 1, 502);
1058 message->SetExtension(unittest::repeated_uint32_extension , 1, 503); 1100 message->SetExtension(unittest::repeated_uint32_extension , 1, 503);
1059 message->SetExtension(unittest::repeated_uint64_extension , 1, 504); 1101 message->SetExtension(unittest::repeated_uint64_extension , 1, 504);
1060 message->SetExtension(unittest::repeated_sint32_extension , 1, 505); 1102 message->SetExtension(unittest::repeated_sint32_extension , 1, 505);
1061 message->SetExtension(unittest::repeated_sint64_extension , 1, 506); 1103 message->SetExtension(unittest::repeated_sint64_extension , 1, 506);
1062 message->SetExtension(unittest::repeated_fixed32_extension , 1, 507); 1104 message->SetExtension(unittest::repeated_fixed32_extension , 1, 507);
1063 message->SetExtension(unittest::repeated_fixed64_extension , 1, 508); 1105 message->SetExtension(unittest::repeated_fixed64_extension , 1, 508);
1064 message->SetExtension(unittest::repeated_sfixed32_extension, 1, 509); 1106 message->SetExtension(unittest::repeated_sfixed32_extension, 1, 509);
1065 message->SetExtension(unittest::repeated_sfixed64_extension, 1, 510); 1107 message->SetExtension(unittest::repeated_sfixed64_extension, 1, 510);
1066 message->SetExtension(unittest::repeated_float_extension , 1, 511); 1108 message->SetExtension(unittest::repeated_float_extension , 1, 511);
1067 message->SetExtension(unittest::repeated_double_extension , 1, 512); 1109 message->SetExtension(unittest::repeated_double_extension , 1, 512);
1068 message->SetExtension(unittest::repeated_bool_extension , 1, true); 1110 message->SetExtension(unittest::repeated_bool_extension , 1, true);
1069 message->SetExtension(unittest::repeated_string_extension , 1, "515"); 1111 message->SetExtension(unittest::repeated_string_extension , 1, "515");
1070 message->SetExtension(unittest::repeated_bytes_extension , 1, "516"); 1112 message->SetExtension(unittest::repeated_bytes_extension , 1, "516");
1071 1113
1072 message->MutableExtension(unittest::repeatedgroup_extension , 1)->set_a(517); 1114 message->MutableExtension(unittest::repeatedgroup_extension , 1)->set_a(517);
1073 message->MutableExtension(unittest::repeated_nested_message_extension , 1)->set_bb(518); 1115 message->MutableExtension(unittest::repeated_nested_message_extension , 1)->set_bb(518);
1074 message->MutableExtension(unittest::repeated_foreign_message_extension, 1)->set_c(519); 1116 message->MutableExtension(unittest::repeated_foreign_message_extension, 1)->set_c(519);
1075 message->MutableExtension(unittest::repeated_import_message_extension , 1)->set_d(520); 1117 message->MutableExtension(unittest::repeated_import_message_extension , 1)->set_d(520);
1118 message->MutableExtension(unittest::repeated_lazy_message_extension , 1)->set_bb(527);
1076 1119
1077 message->SetExtension(unittest::repeated_nested_enum_extension , 1, unittest::TestAllTypes::FOO); 1120 message->SetExtension(unittest::repeated_nested_enum_extension , 1, unittest::TestAllTypes::FOO);
1078 message->SetExtension(unittest::repeated_foreign_enum_extension, 1, unittest::FOREIGN_FOO ); 1121 message->SetExtension(unittest::repeated_foreign_enum_extension, 1, unittest::FOREIGN_FOO );
1079 message->SetExtension(unittest::repeated_import_enum_extension , 1, unittest_import::IMPORT_FOO); 1122 message->SetExtension(unittest::repeated_import_enum_extension , 1, unittest_import::IMPORT_FOO);
1080 1123
1081 message->SetExtension(unittest::repeated_string_piece_extension, 1, "524"); 1124 message->SetExtension(unittest::repeated_string_piece_extension, 1, "524");
1082 message->SetExtension(unittest::repeated_cord_extension, 1, "525"); 1125 message->SetExtension(unittest::repeated_cord_extension, 1, "525");
1083 } 1126 }
1084 1127
1085 // ------------------------------------------------------------------- 1128 // -------------------------------------------------------------------
1086 1129
1087 void TestUtil::ExpectAllExtensionsSet( 1130 void TestUtil::ExpectAllExtensionsSet(
1088 const unittest::TestAllExtensions& message) { 1131 const unittest::TestAllExtensions& message) {
1089 EXPECT_TRUE(message.HasExtension(unittest::optional_int32_extension )); 1132 EXPECT_TRUE(message.HasExtension(unittest::optional_int32_extension ));
1090 EXPECT_TRUE(message.HasExtension(unittest::optional_int64_extension )); 1133 EXPECT_TRUE(message.HasExtension(unittest::optional_int64_extension ));
1091 EXPECT_TRUE(message.HasExtension(unittest::optional_uint32_extension )); 1134 EXPECT_TRUE(message.HasExtension(unittest::optional_uint32_extension ));
1092 EXPECT_TRUE(message.HasExtension(unittest::optional_uint64_extension )); 1135 EXPECT_TRUE(message.HasExtension(unittest::optional_uint64_extension ));
1093 EXPECT_TRUE(message.HasExtension(unittest::optional_sint32_extension )); 1136 EXPECT_TRUE(message.HasExtension(unittest::optional_sint32_extension ));
1094 EXPECT_TRUE(message.HasExtension(unittest::optional_sint64_extension )); 1137 EXPECT_TRUE(message.HasExtension(unittest::optional_sint64_extension ));
1095 EXPECT_TRUE(message.HasExtension(unittest::optional_fixed32_extension )); 1138 EXPECT_TRUE(message.HasExtension(unittest::optional_fixed32_extension ));
1096 EXPECT_TRUE(message.HasExtension(unittest::optional_fixed64_extension )); 1139 EXPECT_TRUE(message.HasExtension(unittest::optional_fixed64_extension ));
1097 EXPECT_TRUE(message.HasExtension(unittest::optional_sfixed32_extension)); 1140 EXPECT_TRUE(message.HasExtension(unittest::optional_sfixed32_extension));
1098 EXPECT_TRUE(message.HasExtension(unittest::optional_sfixed64_extension)); 1141 EXPECT_TRUE(message.HasExtension(unittest::optional_sfixed64_extension));
1099 EXPECT_TRUE(message.HasExtension(unittest::optional_float_extension )); 1142 EXPECT_TRUE(message.HasExtension(unittest::optional_float_extension ));
1100 EXPECT_TRUE(message.HasExtension(unittest::optional_double_extension )); 1143 EXPECT_TRUE(message.HasExtension(unittest::optional_double_extension ));
1101 EXPECT_TRUE(message.HasExtension(unittest::optional_bool_extension )); 1144 EXPECT_TRUE(message.HasExtension(unittest::optional_bool_extension ));
1102 EXPECT_TRUE(message.HasExtension(unittest::optional_string_extension )); 1145 EXPECT_TRUE(message.HasExtension(unittest::optional_string_extension ));
1103 EXPECT_TRUE(message.HasExtension(unittest::optional_bytes_extension )); 1146 EXPECT_TRUE(message.HasExtension(unittest::optional_bytes_extension ));
1104 1147
1105 EXPECT_TRUE(message.HasExtension(unittest::optionalgroup_extension )); 1148 EXPECT_TRUE(message.HasExtension(unittest::optionalgroup_extension ));
1106 EXPECT_TRUE(message.HasExtension(unittest::optional_nested_message_extension )); 1149 EXPECT_TRUE(message.HasExtension(unittest::optional_nested_message_extension ));
1107 EXPECT_TRUE(message.HasExtension(unittest::optional_foreign_message_extension)); 1150 EXPECT_TRUE(message.HasExtension(unittest::optional_foreign_message_extension ));
1108 EXPECT_TRUE(message.HasExtension(unittest::optional_import_message_extension )); 1151 EXPECT_TRUE(message.HasExtension(unittest::optional_import_message_extension ));
1152 EXPECT_TRUE(message.HasExtension(unittest::optional_public_import_message_extension));
1153 EXPECT_TRUE(message.HasExtension(unittest::optional_lazy_message_extension ));
1109 1154
1110 EXPECT_TRUE(message.GetExtension(unittest::optionalgroup_extension ).has_a()); 1155 EXPECT_TRUE(message.GetExtension(unittest::optionalgroup_extension ).has_a());
1111 EXPECT_TRUE(message.GetExtension(unittest::optional_nested_message_extension ).has_bb()); 1156 EXPECT_TRUE(message.GetExtension(unittest::optional_nested_message_extension ).has_bb());
1112 EXPECT_TRUE(message.GetExtension(unittest::optional_foreign_message_extension).has_c()); 1157 EXPECT_TRUE(message.GetExtension(unittest::optional_foreign_message_extension ).has_c());
1113 EXPECT_TRUE(message.GetExtension(unittest::optional_import_message_extension ).has_d()); 1158 EXPECT_TRUE(message.GetExtension(unittest::optional_import_message_extension ).has_d());
1159 EXPECT_TRUE(message.GetExtension(unittest::optional_public_import_message_extension).has_e());
1160 EXPECT_TRUE(message.GetExtension(unittest::optional_lazy_message_extension ).has_bb());
1114 1161
1115 EXPECT_TRUE(message.HasExtension(unittest::optional_nested_enum_extension )); 1162 EXPECT_TRUE(message.HasExtension(unittest::optional_nested_enum_extension ));
1116 EXPECT_TRUE(message.HasExtension(unittest::optional_foreign_enum_extension)); 1163 EXPECT_TRUE(message.HasExtension(unittest::optional_foreign_enum_extension));
1117 EXPECT_TRUE(message.HasExtension(unittest::optional_import_enum_extension )); 1164 EXPECT_TRUE(message.HasExtension(unittest::optional_import_enum_extension ));
1118 1165
1119 EXPECT_TRUE(message.HasExtension(unittest::optional_string_piece_extension)); 1166 EXPECT_TRUE(message.HasExtension(unittest::optional_string_piece_extension));
1120 EXPECT_TRUE(message.HasExtension(unittest::optional_cord_extension)); 1167 EXPECT_TRUE(message.HasExtension(unittest::optional_cord_extension));
1121 1168
1122 EXPECT_EQ(101 , message.GetExtension(unittest::optional_int32_extension )); 1169 EXPECT_EQ(101 , message.GetExtension(unittest::optional_int32_extension ));
1123 EXPECT_EQ(102 , message.GetExtension(unittest::optional_int64_extension )); 1170 EXPECT_EQ(102 , message.GetExtension(unittest::optional_int64_extension ));
1124 EXPECT_EQ(103 , message.GetExtension(unittest::optional_uint32_extension )); 1171 EXPECT_EQ(103 , message.GetExtension(unittest::optional_uint32_extension ));
1125 EXPECT_EQ(104 , message.GetExtension(unittest::optional_uint64_extension )); 1172 EXPECT_EQ(104 , message.GetExtension(unittest::optional_uint64_extension ));
1126 EXPECT_EQ(105 , message.GetExtension(unittest::optional_sint32_extension )); 1173 EXPECT_EQ(105 , message.GetExtension(unittest::optional_sint32_extension ));
1127 EXPECT_EQ(106 , message.GetExtension(unittest::optional_sint64_extension )); 1174 EXPECT_EQ(106 , message.GetExtension(unittest::optional_sint64_extension ));
1128 EXPECT_EQ(107 , message.GetExtension(unittest::optional_fixed32_extension )); 1175 EXPECT_EQ(107 , message.GetExtension(unittest::optional_fixed32_extension ));
1129 EXPECT_EQ(108 , message.GetExtension(unittest::optional_fixed64_extension )); 1176 EXPECT_EQ(108 , message.GetExtension(unittest::optional_fixed64_extension ));
1130 EXPECT_EQ(109 , message.GetExtension(unittest::optional_sfixed32_extension)); 1177 EXPECT_EQ(109 , message.GetExtension(unittest::optional_sfixed32_extension));
1131 EXPECT_EQ(110 , message.GetExtension(unittest::optional_sfixed64_extension)); 1178 EXPECT_EQ(110 , message.GetExtension(unittest::optional_sfixed64_extension));
1132 EXPECT_EQ(111 , message.GetExtension(unittest::optional_float_extension )); 1179 EXPECT_EQ(111 , message.GetExtension(unittest::optional_float_extension ));
1133 EXPECT_EQ(112 , message.GetExtension(unittest::optional_double_extension )); 1180 EXPECT_EQ(112 , message.GetExtension(unittest::optional_double_extension ));
1134 EXPECT_EQ(true , message.GetExtension(unittest::optional_bool_extension )); 1181 EXPECT_EQ(true , message.GetExtension(unittest::optional_bool_extension ));
1135 EXPECT_EQ("115", message.GetExtension(unittest::optional_string_extension )); 1182 EXPECT_EQ("115", message.GetExtension(unittest::optional_string_extension ));
1136 EXPECT_EQ("116", message.GetExtension(unittest::optional_bytes_extension )); 1183 EXPECT_EQ("116", message.GetExtension(unittest::optional_bytes_extension ));
1137 1184
1138 EXPECT_EQ(117, message.GetExtension(unittest::optionalgroup_extension ).a()); 1185 EXPECT_EQ(117, message.GetExtension(unittest::optionalgroup_extension ).a());
1139 EXPECT_EQ(118, message.GetExtension(unittest::optional_nested_message_extension ).bb()); 1186 EXPECT_EQ(118, message.GetExtension(unittest::optional_nested_message_extension ).bb());
1140 EXPECT_EQ(119, message.GetExtension(unittest::optional_foreign_message_extension).c()); 1187 EXPECT_EQ(119, message.GetExtension(unittest::optional_foreign_message_extension).c());
1141 EXPECT_EQ(120, message.GetExtension(unittest::optional_import_message_extension ).d()); 1188 EXPECT_EQ(120, message.GetExtension(unittest::optional_import_message_extension ).d());
1142 1189
1143 EXPECT_EQ(unittest::TestAllTypes::BAZ, message.GetExtension(unittest::optional_nested_enum_extension )); 1190 EXPECT_EQ(unittest::TestAllTypes::BAZ, message.GetExtension(unittest::optional_nested_enum_extension ));
1144 EXPECT_EQ(unittest::FOREIGN_BAZ , message.GetExtension(unittest::optional_foreign_enum_extension)); 1191 EXPECT_EQ(unittest::FOREIGN_BAZ , message.GetExtension(unittest::optional_foreign_enum_extension));
1145 EXPECT_EQ(unittest_import::IMPORT_BAZ, message.GetExtension(unittest::optional_import_enum_extension )); 1192 EXPECT_EQ(unittest_import::IMPORT_BAZ, message.GetExtension(unittest::optional_import_enum_extension ));
1146 1193
1147 EXPECT_EQ("124", message.GetExtension(unittest::optional_string_piece_extension)); 1194 EXPECT_EQ("124", message.GetExtension(unittest::optional_string_piece_extension));
1148 EXPECT_EQ("125", message.GetExtension(unittest::optional_cord_extension)); 1195 EXPECT_EQ("125", message.GetExtension(unittest::optional_cord_extension));
1196 EXPECT_EQ(126, message.GetExtension(unittest::optional_public_import_message_extension ).e());
1197 EXPECT_EQ(127, message.GetExtension(unittest::optional_lazy_message_extension).bb());
1149 1198
1150 // ----------------------------------------------------------------- 1199 // -----------------------------------------------------------------
1151 1200
1152 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int32_extension )); 1201 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int32_extension ));
1153 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int64_extension )); 1202 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int64_extension ));
1154 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint32_extension )); 1203 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint32_extension ));
1155 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint64_extension )); 1204 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint64_extension ));
1156 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint32_extension )); 1205 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint32_extension ));
1157 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint64_extension )); 1206 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint64_extension ));
1158 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed32_extension )); 1207 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed32_extension ));
1159 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed64_extension )); 1208 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed64_extension ));
1160 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed32_extension)); 1209 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed32_extension));
1161 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed64_extension)); 1210 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed64_extension));
1162 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_float_extension )); 1211 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_float_extension ));
1163 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_double_extension )); 1212 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_double_extension ));
1164 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bool_extension )); 1213 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bool_extension ));
1165 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_extension )); 1214 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_extension ));
1166 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bytes_extension )); 1215 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bytes_extension ));
1167 1216
1168 ASSERT_EQ(2, message.ExtensionSize(unittest::repeatedgroup_extension )); 1217 ASSERT_EQ(2, message.ExtensionSize(unittest::repeatedgroup_extension ));
1169 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_message_extension )); 1218 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_message_extension ));
1170 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_message_extension)); 1219 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_message_extension));
1171 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_message_extension )); 1220 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_message_extension ));
1221 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_lazy_message_extension ));
1172 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_enum_extension )); 1222 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_enum_extension ));
1173 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_enum_extension )); 1223 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_enum_extension ));
1174 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_enum_extension )); 1224 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_enum_extension ));
1175 1225
1176 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_piece_extension)); 1226 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_piece_extension));
1177 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_cord_extension)); 1227 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_cord_extension));
1178 1228
1179 EXPECT_EQ(201 , message.GetExtension(unittest::repeated_int32_extension , 0)); 1229 EXPECT_EQ(201 , message.GetExtension(unittest::repeated_int32_extension , 0));
1180 EXPECT_EQ(202 , message.GetExtension(unittest::repeated_int64_extension , 0)); 1230 EXPECT_EQ(202 , message.GetExtension(unittest::repeated_int64_extension , 0));
1181 EXPECT_EQ(203 , message.GetExtension(unittest::repeated_uint32_extension , 0)); 1231 EXPECT_EQ(203 , message.GetExtension(unittest::repeated_uint32_extension , 0));
1182 EXPECT_EQ(204 , message.GetExtension(unittest::repeated_uint64_extension , 0)); 1232 EXPECT_EQ(204 , message.GetExtension(unittest::repeated_uint64_extension , 0));
1183 EXPECT_EQ(205 , message.GetExtension(unittest::repeated_sint32_extension , 0)); 1233 EXPECT_EQ(205 , message.GetExtension(unittest::repeated_sint32_extension , 0));
1184 EXPECT_EQ(206 , message.GetExtension(unittest::repeated_sint64_extension , 0)); 1234 EXPECT_EQ(206 , message.GetExtension(unittest::repeated_sint64_extension , 0));
1185 EXPECT_EQ(207 , message.GetExtension(unittest::repeated_fixed32_extension , 0)); 1235 EXPECT_EQ(207 , message.GetExtension(unittest::repeated_fixed32_extension , 0));
1186 EXPECT_EQ(208 , message.GetExtension(unittest::repeated_fixed64_extension , 0)); 1236 EXPECT_EQ(208 , message.GetExtension(unittest::repeated_fixed64_extension , 0));
1187 EXPECT_EQ(209 , message.GetExtension(unittest::repeated_sfixed32_extension, 0)); 1237 EXPECT_EQ(209 , message.GetExtension(unittest::repeated_sfixed32_extension, 0));
1188 EXPECT_EQ(210 , message.GetExtension(unittest::repeated_sfixed64_extension, 0)); 1238 EXPECT_EQ(210 , message.GetExtension(unittest::repeated_sfixed64_extension, 0));
1189 EXPECT_EQ(211 , message.GetExtension(unittest::repeated_float_extension , 0)); 1239 EXPECT_EQ(211 , message.GetExtension(unittest::repeated_float_extension , 0));
1190 EXPECT_EQ(212 , message.GetExtension(unittest::repeated_double_extension , 0)); 1240 EXPECT_EQ(212 , message.GetExtension(unittest::repeated_double_extension , 0));
1191 EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension , 0)); 1241 EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension , 0));
1192 EXPECT_EQ("215", message.GetExtension(unittest::repeated_string_extension , 0)); 1242 EXPECT_EQ("215", message.GetExtension(unittest::repeated_string_extension , 0));
1193 EXPECT_EQ("216", message.GetExtension(unittest::repeated_bytes_extension , 0)); 1243 EXPECT_EQ("216", message.GetExtension(unittest::repeated_bytes_extension , 0));
1194 1244
1195 EXPECT_EQ(217, message.GetExtension(unittest::repeatedgroup_extension , 0).a()); 1245 EXPECT_EQ(217, message.GetExtension(unittest::repeatedgroup_extension , 0).a());
1196 EXPECT_EQ(218, message.GetExtension(unittest::repeated_nested_message_extension , 0).bb()); 1246 EXPECT_EQ(218, message.GetExtension(unittest::repeated_nested_message_extension , 0).bb());
1197 EXPECT_EQ(219, message.GetExtension(unittest::repeated_foreign_message_extension, 0).c()); 1247 EXPECT_EQ(219, message.GetExtension(unittest::repeated_foreign_message_extension, 0).c());
1198 EXPECT_EQ(220, message.GetExtension(unittest::repeated_import_message_extension , 0).d()); 1248 EXPECT_EQ(220, message.GetExtension(unittest::repeated_import_message_extension , 0).d());
1249 EXPECT_EQ(227, message.GetExtension(unittest::repeated_lazy_message_extension , 0).bb());
1199 1250
1200 EXPECT_EQ(unittest::TestAllTypes::BAR, message.GetExtension(unittest::repeated_nested_enum_extension , 0)); 1251 EXPECT_EQ(unittest::TestAllTypes::BAR, message.GetExtension(unittest::repeated_nested_enum_extension , 0));
1201 EXPECT_EQ(unittest::FOREIGN_BAR , message.GetExtension(unittest::repeated_foreign_enum_extension, 0)); 1252 EXPECT_EQ(unittest::FOREIGN_BAR , message.GetExtension(unittest::repeated_foreign_enum_extension, 0));
1202 EXPECT_EQ(unittest_import::IMPORT_BAR, message.GetExtension(unittest::repeated_import_enum_extension , 0)); 1253 EXPECT_EQ(unittest_import::IMPORT_BAR, message.GetExtension(unittest::repeated_import_enum_extension , 0));
1203 1254
1204 EXPECT_EQ("224", message.GetExtension(unittest::repeated_string_piece_extension, 0)); 1255 EXPECT_EQ("224", message.GetExtension(unittest::repeated_string_piece_extension, 0));
1205 EXPECT_EQ("225", message.GetExtension(unittest::repeated_cord_extension, 0)); 1256 EXPECT_EQ("225", message.GetExtension(unittest::repeated_cord_extension, 0));
1206 1257
1207 EXPECT_EQ(301 , message.GetExtension(unittest::repeated_int32_extension , 1)); 1258 EXPECT_EQ(301 , message.GetExtension(unittest::repeated_int32_extension , 1));
1208 EXPECT_EQ(302 , message.GetExtension(unittest::repeated_int64_extension , 1)); 1259 EXPECT_EQ(302 , message.GetExtension(unittest::repeated_int64_extension , 1));
1209 EXPECT_EQ(303 , message.GetExtension(unittest::repeated_uint32_extension , 1)); 1260 EXPECT_EQ(303 , message.GetExtension(unittest::repeated_uint32_extension , 1));
1210 EXPECT_EQ(304 , message.GetExtension(unittest::repeated_uint64_extension , 1)); 1261 EXPECT_EQ(304 , message.GetExtension(unittest::repeated_uint64_extension , 1));
1211 EXPECT_EQ(305 , message.GetExtension(unittest::repeated_sint32_extension , 1)); 1262 EXPECT_EQ(305 , message.GetExtension(unittest::repeated_sint32_extension , 1));
1212 EXPECT_EQ(306 , message.GetExtension(unittest::repeated_sint64_extension , 1)); 1263 EXPECT_EQ(306 , message.GetExtension(unittest::repeated_sint64_extension , 1));
1213 EXPECT_EQ(307 , message.GetExtension(unittest::repeated_fixed32_extension , 1)); 1264 EXPECT_EQ(307 , message.GetExtension(unittest::repeated_fixed32_extension , 1));
1214 EXPECT_EQ(308 , message.GetExtension(unittest::repeated_fixed64_extension , 1)); 1265 EXPECT_EQ(308 , message.GetExtension(unittest::repeated_fixed64_extension , 1));
1215 EXPECT_EQ(309 , message.GetExtension(unittest::repeated_sfixed32_extension, 1)); 1266 EXPECT_EQ(309 , message.GetExtension(unittest::repeated_sfixed32_extension, 1));
1216 EXPECT_EQ(310 , message.GetExtension(unittest::repeated_sfixed64_extension, 1)); 1267 EXPECT_EQ(310 , message.GetExtension(unittest::repeated_sfixed64_extension, 1));
1217 EXPECT_EQ(311 , message.GetExtension(unittest::repeated_float_extension , 1)); 1268 EXPECT_EQ(311 , message.GetExtension(unittest::repeated_float_extension , 1));
1218 EXPECT_EQ(312 , message.GetExtension(unittest::repeated_double_extension , 1)); 1269 EXPECT_EQ(312 , message.GetExtension(unittest::repeated_double_extension , 1));
1219 EXPECT_EQ(false, message.GetExtension(unittest::repeated_bool_extension , 1)); 1270 EXPECT_EQ(false, message.GetExtension(unittest::repeated_bool_extension , 1));
1220 EXPECT_EQ("315", message.GetExtension(unittest::repeated_string_extension , 1)); 1271 EXPECT_EQ("315", message.GetExtension(unittest::repeated_string_extension , 1));
1221 EXPECT_EQ("316", message.GetExtension(unittest::repeated_bytes_extension , 1)); 1272 EXPECT_EQ("316", message.GetExtension(unittest::repeated_bytes_extension , 1));
1222 1273
1223 EXPECT_EQ(317, message.GetExtension(unittest::repeatedgroup_extension , 1).a()); 1274 EXPECT_EQ(317, message.GetExtension(unittest::repeatedgroup_extension , 1).a());
1224 EXPECT_EQ(318, message.GetExtension(unittest::repeated_nested_message_extension , 1).bb()); 1275 EXPECT_EQ(318, message.GetExtension(unittest::repeated_nested_message_extension , 1).bb());
1225 EXPECT_EQ(319, message.GetExtension(unittest::repeated_foreign_message_extension, 1).c()); 1276 EXPECT_EQ(319, message.GetExtension(unittest::repeated_foreign_message_extension, 1).c());
1226 EXPECT_EQ(320, message.GetExtension(unittest::repeated_import_message_extension , 1).d()); 1277 EXPECT_EQ(320, message.GetExtension(unittest::repeated_import_message_extension , 1).d());
1278 EXPECT_EQ(327, message.GetExtension(unittest::repeated_lazy_message_extension , 1).bb());
1227 1279
1228 EXPECT_EQ(unittest::TestAllTypes::BAZ, message.GetExtension(unittest::repeated_nested_enum_extension , 1)); 1280 EXPECT_EQ(unittest::TestAllTypes::BAZ, message.GetExtension(unittest::repeated_nested_enum_extension , 1));
1229 EXPECT_EQ(unittest::FOREIGN_BAZ , message.GetExtension(unittest::repeated_foreign_enum_extension, 1)); 1281 EXPECT_EQ(unittest::FOREIGN_BAZ , message.GetExtension(unittest::repeated_foreign_enum_extension, 1));
1230 EXPECT_EQ(unittest_import::IMPORT_BAZ, message.GetExtension(unittest::repeated_import_enum_extension , 1)); 1282 EXPECT_EQ(unittest_import::IMPORT_BAZ, message.GetExtension(unittest::repeated_import_enum_extension , 1));
1231 1283
1232 EXPECT_EQ("324", message.GetExtension(unittest::repeated_string_piece_extension, 1)); 1284 EXPECT_EQ("324", message.GetExtension(unittest::repeated_string_piece_extension, 1));
1233 EXPECT_EQ("325", message.GetExtension(unittest::repeated_cord_extension, 1)); 1285 EXPECT_EQ("325", message.GetExtension(unittest::repeated_cord_extension, 1));
1234 1286
1235 // ----------------------------------------------------------------- 1287 // -----------------------------------------------------------------
1236 1288
1237 EXPECT_TRUE(message.HasExtension(unittest::default_int32_extension )); 1289 EXPECT_TRUE(message.HasExtension(unittest::default_int32_extension ));
1238 EXPECT_TRUE(message.HasExtension(unittest::default_int64_extension )); 1290 EXPECT_TRUE(message.HasExtension(unittest::default_int64_extension ));
1239 EXPECT_TRUE(message.HasExtension(unittest::default_uint32_extension )); 1291 EXPECT_TRUE(message.HasExtension(unittest::default_uint32_extension ));
1240 EXPECT_TRUE(message.HasExtension(unittest::default_uint64_extension )); 1292 EXPECT_TRUE(message.HasExtension(unittest::default_uint64_extension ));
1241 EXPECT_TRUE(message.HasExtension(unittest::default_sint32_extension )); 1293 EXPECT_TRUE(message.HasExtension(unittest::default_sint32_extension ));
1242 EXPECT_TRUE(message.HasExtension(unittest::default_sint64_extension )); 1294 EXPECT_TRUE(message.HasExtension(unittest::default_sint64_extension ));
1243 EXPECT_TRUE(message.HasExtension(unittest::default_fixed32_extension )); 1295 EXPECT_TRUE(message.HasExtension(unittest::default_fixed32_extension ));
1244 EXPECT_TRUE(message.HasExtension(unittest::default_fixed64_extension )); 1296 EXPECT_TRUE(message.HasExtension(unittest::default_fixed64_extension ));
1245 EXPECT_TRUE(message.HasExtension(unittest::default_sfixed32_extension)); 1297 EXPECT_TRUE(message.HasExtension(unittest::default_sfixed32_extension));
1246 EXPECT_TRUE(message.HasExtension(unittest::default_sfixed64_extension)); 1298 EXPECT_TRUE(message.HasExtension(unittest::default_sfixed64_extension));
1247 EXPECT_TRUE(message.HasExtension(unittest::default_float_extension )); 1299 EXPECT_TRUE(message.HasExtension(unittest::default_float_extension ));
1248 EXPECT_TRUE(message.HasExtension(unittest::default_double_extension )); 1300 EXPECT_TRUE(message.HasExtension(unittest::default_double_extension ));
1249 EXPECT_TRUE(message.HasExtension(unittest::default_bool_extension )); 1301 EXPECT_TRUE(message.HasExtension(unittest::default_bool_extension ));
1250 EXPECT_TRUE(message.HasExtension(unittest::default_string_extension )); 1302 EXPECT_TRUE(message.HasExtension(unittest::default_string_extension ));
1251 EXPECT_TRUE(message.HasExtension(unittest::default_bytes_extension )); 1303 EXPECT_TRUE(message.HasExtension(unittest::default_bytes_extension ));
1252 1304
1253 EXPECT_TRUE(message.HasExtension(unittest::default_nested_enum_extension )); 1305 EXPECT_TRUE(message.HasExtension(unittest::default_nested_enum_extension ));
1254 EXPECT_TRUE(message.HasExtension(unittest::default_foreign_enum_extension)); 1306 EXPECT_TRUE(message.HasExtension(unittest::default_foreign_enum_extension));
1255 EXPECT_TRUE(message.HasExtension(unittest::default_import_enum_extension )); 1307 EXPECT_TRUE(message.HasExtension(unittest::default_import_enum_extension ));
1256 1308
1257 EXPECT_TRUE(message.HasExtension(unittest::default_string_piece_extension)); 1309 EXPECT_TRUE(message.HasExtension(unittest::default_string_piece_extension));
1258 EXPECT_TRUE(message.HasExtension(unittest::default_cord_extension)); 1310 EXPECT_TRUE(message.HasExtension(unittest::default_cord_extension));
1259 1311
1260 EXPECT_EQ(401 , message.GetExtension(unittest::default_int32_extension )); 1312 EXPECT_EQ(401 , message.GetExtension(unittest::default_int32_extension ));
1261 EXPECT_EQ(402 , message.GetExtension(unittest::default_int64_extension )); 1313 EXPECT_EQ(402 , message.GetExtension(unittest::default_int64_extension ));
1262 EXPECT_EQ(403 , message.GetExtension(unittest::default_uint32_extension )); 1314 EXPECT_EQ(403 , message.GetExtension(unittest::default_uint32_extension ));
1263 EXPECT_EQ(404 , message.GetExtension(unittest::default_uint64_extension )); 1315 EXPECT_EQ(404 , message.GetExtension(unittest::default_uint64_extension ));
1264 EXPECT_EQ(405 , message.GetExtension(unittest::default_sint32_extension )); 1316 EXPECT_EQ(405 , message.GetExtension(unittest::default_sint32_extension ));
1265 EXPECT_EQ(406 , message.GetExtension(unittest::default_sint64_extension )); 1317 EXPECT_EQ(406 , message.GetExtension(unittest::default_sint64_extension ));
1266 EXPECT_EQ(407 , message.GetExtension(unittest::default_fixed32_extension )); 1318 EXPECT_EQ(407 , message.GetExtension(unittest::default_fixed32_extension ));
1267 EXPECT_EQ(408 , message.GetExtension(unittest::default_fixed64_extension )); 1319 EXPECT_EQ(408 , message.GetExtension(unittest::default_fixed64_extension ));
1268 EXPECT_EQ(409 , message.GetExtension(unittest::default_sfixed32_extension)); 1320 EXPECT_EQ(409 , message.GetExtension(unittest::default_sfixed32_extension));
1269 EXPECT_EQ(410 , message.GetExtension(unittest::default_sfixed64_extension)); 1321 EXPECT_EQ(410 , message.GetExtension(unittest::default_sfixed64_extension));
1270 EXPECT_EQ(411 , message.GetExtension(unittest::default_float_extension )); 1322 EXPECT_EQ(411 , message.GetExtension(unittest::default_float_extension ));
1271 EXPECT_EQ(412 , message.GetExtension(unittest::default_double_extension )); 1323 EXPECT_EQ(412 , message.GetExtension(unittest::default_double_extension ));
1272 EXPECT_EQ(false, message.GetExtension(unittest::default_bool_extension )); 1324 EXPECT_EQ(false, message.GetExtension(unittest::default_bool_extension ));
1273 EXPECT_EQ("415", message.GetExtension(unittest::default_string_extension )); 1325 EXPECT_EQ("415", message.GetExtension(unittest::default_string_extension ));
1274 EXPECT_EQ("416", message.GetExtension(unittest::default_bytes_extension )); 1326 EXPECT_EQ("416", message.GetExtension(unittest::default_bytes_extension ));
1275 1327
1276 EXPECT_EQ(unittest::TestAllTypes::FOO, message.GetExtension(unittest::default_nested_enum_extension )); 1328 EXPECT_EQ(unittest::TestAllTypes::FOO, message.GetExtension(unittest::default_nested_enum_extension ));
1277 EXPECT_EQ(unittest::FOREIGN_FOO , message.GetExtension(unittest::default_foreign_enum_extension)); 1329 EXPECT_EQ(unittest::FOREIGN_FOO , message.GetExtension(unittest::default_foreign_enum_extension));
1278 EXPECT_EQ(unittest_import::IMPORT_FOO, message.GetExtension(unittest::default_import_enum_extension )); 1330 EXPECT_EQ(unittest_import::IMPORT_FOO, message.GetExtension(unittest::default_import_enum_extension ));
1279 1331
1280 EXPECT_EQ("424", message.GetExtension(unittest::default_string_piece_extension)); 1332 EXPECT_EQ("424", message.GetExtension(unittest::default_string_piece_extension));
1281 EXPECT_EQ("425", message.GetExtension(unittest::default_cord_extension)); 1333 EXPECT_EQ("425", message.GetExtension(unittest::default_cord_extension));
1282 } 1334 }
1283 1335
1284 // ------------------------------------------------------------------- 1336 // -------------------------------------------------------------------
1285 1337
1286 void TestUtil::ExpectExtensionsClear( 1338 void TestUtil::ExpectExtensionsClear(
1287 const unittest::TestAllExtensions& message) { 1339 const unittest::TestAllExtensions& message) {
1288 string serialized; 1340 string serialized;
1289 ASSERT_TRUE(message.SerializeToString(&serialized)); 1341 ASSERT_TRUE(message.SerializeToString(&serialized));
1290 EXPECT_EQ("", serialized); 1342 EXPECT_EQ("", serialized);
1291 EXPECT_EQ(0, message.ByteSize()); 1343 EXPECT_EQ(0, message.ByteSize());
1292 1344
1293 // has_blah() should initially be false for all optional fields. 1345 // has_blah() should initially be false for all optional fields.
1294 EXPECT_FALSE(message.HasExtension(unittest::optional_int32_extension )); 1346 EXPECT_FALSE(message.HasExtension(unittest::optional_int32_extension ));
1295 EXPECT_FALSE(message.HasExtension(unittest::optional_int64_extension )); 1347 EXPECT_FALSE(message.HasExtension(unittest::optional_int64_extension ));
1296 EXPECT_FALSE(message.HasExtension(unittest::optional_uint32_extension )); 1348 EXPECT_FALSE(message.HasExtension(unittest::optional_uint32_extension ));
1297 EXPECT_FALSE(message.HasExtension(unittest::optional_uint64_extension )); 1349 EXPECT_FALSE(message.HasExtension(unittest::optional_uint64_extension ));
1298 EXPECT_FALSE(message.HasExtension(unittest::optional_sint32_extension )); 1350 EXPECT_FALSE(message.HasExtension(unittest::optional_sint32_extension ));
1299 EXPECT_FALSE(message.HasExtension(unittest::optional_sint64_extension )); 1351 EXPECT_FALSE(message.HasExtension(unittest::optional_sint64_extension ));
1300 EXPECT_FALSE(message.HasExtension(unittest::optional_fixed32_extension )); 1352 EXPECT_FALSE(message.HasExtension(unittest::optional_fixed32_extension ));
1301 EXPECT_FALSE(message.HasExtension(unittest::optional_fixed64_extension )); 1353 EXPECT_FALSE(message.HasExtension(unittest::optional_fixed64_extension ));
1302 EXPECT_FALSE(message.HasExtension(unittest::optional_sfixed32_extension)); 1354 EXPECT_FALSE(message.HasExtension(unittest::optional_sfixed32_extension));
1303 EXPECT_FALSE(message.HasExtension(unittest::optional_sfixed64_extension)); 1355 EXPECT_FALSE(message.HasExtension(unittest::optional_sfixed64_extension));
1304 EXPECT_FALSE(message.HasExtension(unittest::optional_float_extension )); 1356 EXPECT_FALSE(message.HasExtension(unittest::optional_float_extension ));
1305 EXPECT_FALSE(message.HasExtension(unittest::optional_double_extension )); 1357 EXPECT_FALSE(message.HasExtension(unittest::optional_double_extension ));
1306 EXPECT_FALSE(message.HasExtension(unittest::optional_bool_extension )); 1358 EXPECT_FALSE(message.HasExtension(unittest::optional_bool_extension ));
1307 EXPECT_FALSE(message.HasExtension(unittest::optional_string_extension )); 1359 EXPECT_FALSE(message.HasExtension(unittest::optional_string_extension ));
1308 EXPECT_FALSE(message.HasExtension(unittest::optional_bytes_extension )); 1360 EXPECT_FALSE(message.HasExtension(unittest::optional_bytes_extension ));
1309 1361
1310 EXPECT_FALSE(message.HasExtension(unittest::optionalgroup_extension )); 1362 EXPECT_FALSE(message.HasExtension(unittest::optionalgroup_extension ));
1311 EXPECT_FALSE(message.HasExtension(unittest::optional_nested_message_extension )); 1363 EXPECT_FALSE(message.HasExtension(unittest::optional_nested_message_extension ));
1312 EXPECT_FALSE(message.HasExtension(unittest::optional_foreign_message_extension)); 1364 EXPECT_FALSE(message.HasExtension(unittest::optional_foreign_message_extension ));
1313 EXPECT_FALSE(message.HasExtension(unittest::optional_import_message_extension )); 1365 EXPECT_FALSE(message.HasExtension(unittest::optional_import_message_extension ));
1366 EXPECT_FALSE(message.HasExtension(unittest::optional_public_import_message_extension));
1367 EXPECT_FALSE(message.HasExtension(unittest::optional_lazy_message_extension ));
1314 1368
1315 EXPECT_FALSE(message.HasExtension(unittest::optional_nested_enum_extension )); 1369 EXPECT_FALSE(message.HasExtension(unittest::optional_nested_enum_extension ));
1316 EXPECT_FALSE(message.HasExtension(unittest::optional_foreign_enum_extension)); 1370 EXPECT_FALSE(message.HasExtension(unittest::optional_foreign_enum_extension));
1317 EXPECT_FALSE(message.HasExtension(unittest::optional_import_enum_extension )); 1371 EXPECT_FALSE(message.HasExtension(unittest::optional_import_enum_extension ));
1318 1372
1319 EXPECT_FALSE(message.HasExtension(unittest::optional_string_piece_extension)); 1373 EXPECT_FALSE(message.HasExtension(unittest::optional_string_piece_extension));
1320 EXPECT_FALSE(message.HasExtension(unittest::optional_cord_extension)); 1374 EXPECT_FALSE(message.HasExtension(unittest::optional_cord_extension));
1321 1375
1322 // Optional fields without defaults are set to zero or something like it. 1376 // Optional fields without defaults are set to zero or something like it.
1323 EXPECT_EQ(0 , message.GetExtension(unittest::optional_int32_extension )); 1377 EXPECT_EQ(0 , message.GetExtension(unittest::optional_int32_extension ));
1324 EXPECT_EQ(0 , message.GetExtension(unittest::optional_int64_extension )); 1378 EXPECT_EQ(0 , message.GetExtension(unittest::optional_int64_extension ));
1325 EXPECT_EQ(0 , message.GetExtension(unittest::optional_uint32_extension )); 1379 EXPECT_EQ(0 , message.GetExtension(unittest::optional_uint32_extension ));
1326 EXPECT_EQ(0 , message.GetExtension(unittest::optional_uint64_extension )); 1380 EXPECT_EQ(0 , message.GetExtension(unittest::optional_uint64_extension ));
1327 EXPECT_EQ(0 , message.GetExtension(unittest::optional_sint32_extension )); 1381 EXPECT_EQ(0 , message.GetExtension(unittest::optional_sint32_extension ));
1328 EXPECT_EQ(0 , message.GetExtension(unittest::optional_sint64_extension )); 1382 EXPECT_EQ(0 , message.GetExtension(unittest::optional_sint64_extension ));
1329 EXPECT_EQ(0 , message.GetExtension(unittest::optional_fixed32_extension )); 1383 EXPECT_EQ(0 , message.GetExtension(unittest::optional_fixed32_extension ));
1330 EXPECT_EQ(0 , message.GetExtension(unittest::optional_fixed64_extension )); 1384 EXPECT_EQ(0 , message.GetExtension(unittest::optional_fixed64_extension ));
1331 EXPECT_EQ(0 , message.GetExtension(unittest::optional_sfixed32_extension)); 1385 EXPECT_EQ(0 , message.GetExtension(unittest::optional_sfixed32_extension));
1332 EXPECT_EQ(0 , message.GetExtension(unittest::optional_sfixed64_extension)); 1386 EXPECT_EQ(0 , message.GetExtension(unittest::optional_sfixed64_extension));
1333 EXPECT_EQ(0 , message.GetExtension(unittest::optional_float_extension )); 1387 EXPECT_EQ(0 , message.GetExtension(unittest::optional_float_extension ));
1334 EXPECT_EQ(0 , message.GetExtension(unittest::optional_double_extension )); 1388 EXPECT_EQ(0 , message.GetExtension(unittest::optional_double_extension ));
1335 EXPECT_EQ(false, message.GetExtension(unittest::optional_bool_extension )); 1389 EXPECT_EQ(false, message.GetExtension(unittest::optional_bool_extension ));
1336 EXPECT_EQ("" , message.GetExtension(unittest::optional_string_extension )); 1390 EXPECT_EQ("" , message.GetExtension(unittest::optional_string_extension ));
1337 EXPECT_EQ("" , message.GetExtension(unittest::optional_bytes_extension )); 1391 EXPECT_EQ("" , message.GetExtension(unittest::optional_bytes_extension ));
1338 1392
1339 // Embedded messages should also be clear. 1393 // Embedded messages should also be clear.
1340 EXPECT_FALSE(message.GetExtension(unittest::optionalgroup_extension ).has_a()); 1394 EXPECT_FALSE(message.GetExtension(unittest::optionalgroup_extension ).has_a());
1341 EXPECT_FALSE(message.GetExtension(unittest::optional_nested_message_extension ).has_bb()); 1395 EXPECT_FALSE(message.GetExtension(unittest::optional_nested_message_extension ).has_bb());
1342 EXPECT_FALSE(message.GetExtension(unittest::optional_foreign_message_extension).has_c()); 1396 EXPECT_FALSE(message.GetExtension(unittest::optional_foreign_message_extension ).has_c());
1343 EXPECT_FALSE(message.GetExtension(unittest::optional_import_message_extension ).has_d()); 1397 EXPECT_FALSE(message.GetExtension(unittest::optional_import_message_extension ).has_d());
1398 EXPECT_FALSE(message.GetExtension(unittest::optional_public_import_message_extension).has_e());
1399 EXPECT_FALSE(message.GetExtension(unittest::optional_lazy_message_extension ).has_bb());
1344 1400
1345 EXPECT_EQ(0, message.GetExtension(unittest::optionalgroup_extension ).a()); 1401 EXPECT_EQ(0, message.GetExtension(unittest::optionalgroup_extension ).a());
1346 EXPECT_EQ(0, message.GetExtension(unittest::optional_nested_message_extension ).bb()); 1402 EXPECT_EQ(0, message.GetExtension(unittest::optional_nested_message_extension ).bb());
1347 EXPECT_EQ(0, message.GetExtension(unittest::optional_foreign_message_extension).c()); 1403 EXPECT_EQ(0, message.GetExtension(unittest::optional_foreign_message_extension ).c());
1348 EXPECT_EQ(0, message.GetExtension(unittest::optional_import_message_extension ).d()); 1404 EXPECT_EQ(0, message.GetExtension(unittest::optional_import_message_extension ).d());
1405 EXPECT_EQ(0, message.GetExtension(unittest::optional_public_import_message_extension).e());
1406 EXPECT_EQ(0, message.GetExtension(unittest::optional_lazy_message_extension ).bb());
1349 1407
1350 // Enums without defaults are set to the first value in the enum. 1408 // Enums without defaults are set to the first value in the enum.
1351 EXPECT_EQ(unittest::TestAllTypes::FOO, message.GetExtension(unittest::optional_nested_enum_extension )); 1409 EXPECT_EQ(unittest::TestAllTypes::FOO, message.GetExtension(unittest::optional_nested_enum_extension ));
1352 EXPECT_EQ(unittest::FOREIGN_FOO , message.GetExtension(unittest::optional_foreign_enum_extension)); 1410 EXPECT_EQ(unittest::FOREIGN_FOO , message.GetExtension(unittest::optional_foreign_enum_extension));
1353 EXPECT_EQ(unittest_import::IMPORT_FOO, message.GetExtension(unittest::optional_import_enum_extension )); 1411 EXPECT_EQ(unittest_import::IMPORT_FOO, message.GetExtension(unittest::optional_import_enum_extension ));
1354 1412
1355 EXPECT_EQ("", message.GetExtension(unittest::optional_string_piece_extension)); 1413 EXPECT_EQ("", message.GetExtension(unittest::optional_string_piece_extension));
1356 EXPECT_EQ("", message.GetExtension(unittest::optional_cord_extension)); 1414 EXPECT_EQ("", message.GetExtension(unittest::optional_cord_extension));
1357 1415
1358 // Repeated fields are empty. 1416 // Repeated fields are empty.
1359 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_int32_extension )); 1417 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_int32_extension ));
1360 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_int64_extension )); 1418 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_int64_extension ));
1361 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_uint32_extension )); 1419 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_uint32_extension ));
1362 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_uint64_extension )); 1420 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_uint64_extension ));
1363 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sint32_extension )); 1421 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sint32_extension ));
1364 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sint64_extension )); 1422 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sint64_extension ));
1365 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_fixed32_extension )); 1423 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_fixed32_extension ));
1366 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_fixed64_extension )); 1424 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_fixed64_extension ));
1367 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sfixed32_extension)); 1425 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sfixed32_extension));
1368 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sfixed64_extension)); 1426 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sfixed64_extension));
1369 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_float_extension )); 1427 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_float_extension ));
1370 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_double_extension )); 1428 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_double_extension ));
1371 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_bool_extension )); 1429 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_bool_extension ));
1372 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_string_extension )); 1430 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_string_extension ));
1373 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_bytes_extension )); 1431 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_bytes_extension ));
1374 1432
1375 EXPECT_EQ(0, message.ExtensionSize(unittest::repeatedgroup_extension )); 1433 EXPECT_EQ(0, message.ExtensionSize(unittest::repeatedgroup_extension ));
1376 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_nested_message_extension )); 1434 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_nested_message_extension ));
1377 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_foreign_message_extension)); 1435 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_foreign_message_extension));
1378 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_import_message_extension )); 1436 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_import_message_extension ));
1437 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_lazy_message_extension ));
1379 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_nested_enum_extension )); 1438 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_nested_enum_extension ));
1380 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_foreign_enum_extension )); 1439 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_foreign_enum_extension ));
1381 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_import_enum_extension )); 1440 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_import_enum_extension ));
1382 1441
1383 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_string_piece_extension)); 1442 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_string_piece_extension));
1384 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_cord_extension)); 1443 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_cord_extension));
1385 1444
1386 // has_blah() should also be false for all default fields. 1445 // has_blah() should also be false for all default fields.
1387 EXPECT_FALSE(message.HasExtension(unittest::default_int32_extension )); 1446 EXPECT_FALSE(message.HasExtension(unittest::default_int32_extension ));
1388 EXPECT_FALSE(message.HasExtension(unittest::default_int64_extension )); 1447 EXPECT_FALSE(message.HasExtension(unittest::default_int64_extension ));
1389 EXPECT_FALSE(message.HasExtension(unittest::default_uint32_extension )); 1448 EXPECT_FALSE(message.HasExtension(unittest::default_uint32_extension ));
1390 EXPECT_FALSE(message.HasExtension(unittest::default_uint64_extension )); 1449 EXPECT_FALSE(message.HasExtension(unittest::default_uint64_extension ));
1391 EXPECT_FALSE(message.HasExtension(unittest::default_sint32_extension )); 1450 EXPECT_FALSE(message.HasExtension(unittest::default_sint32_extension ));
1392 EXPECT_FALSE(message.HasExtension(unittest::default_sint64_extension )); 1451 EXPECT_FALSE(message.HasExtension(unittest::default_sint64_extension ));
1393 EXPECT_FALSE(message.HasExtension(unittest::default_fixed32_extension )); 1452 EXPECT_FALSE(message.HasExtension(unittest::default_fixed32_extension ));
1394 EXPECT_FALSE(message.HasExtension(unittest::default_fixed64_extension )); 1453 EXPECT_FALSE(message.HasExtension(unittest::default_fixed64_extension ));
1395 EXPECT_FALSE(message.HasExtension(unittest::default_sfixed32_extension)); 1454 EXPECT_FALSE(message.HasExtension(unittest::default_sfixed32_extension));
1396 EXPECT_FALSE(message.HasExtension(unittest::default_sfixed64_extension)); 1455 EXPECT_FALSE(message.HasExtension(unittest::default_sfixed64_extension));
1397 EXPECT_FALSE(message.HasExtension(unittest::default_float_extension )); 1456 EXPECT_FALSE(message.HasExtension(unittest::default_float_extension ));
1398 EXPECT_FALSE(message.HasExtension(unittest::default_double_extension )); 1457 EXPECT_FALSE(message.HasExtension(unittest::default_double_extension ));
1399 EXPECT_FALSE(message.HasExtension(unittest::default_bool_extension )); 1458 EXPECT_FALSE(message.HasExtension(unittest::default_bool_extension ));
1400 EXPECT_FALSE(message.HasExtension(unittest::default_string_extension )); 1459 EXPECT_FALSE(message.HasExtension(unittest::default_string_extension ));
1401 EXPECT_FALSE(message.HasExtension(unittest::default_bytes_extension )); 1460 EXPECT_FALSE(message.HasExtension(unittest::default_bytes_extension ));
1402 1461
1403 EXPECT_FALSE(message.HasExtension(unittest::default_nested_enum_extension )); 1462 EXPECT_FALSE(message.HasExtension(unittest::default_nested_enum_extension ));
1404 EXPECT_FALSE(message.HasExtension(unittest::default_foreign_enum_extension)); 1463 EXPECT_FALSE(message.HasExtension(unittest::default_foreign_enum_extension));
1405 EXPECT_FALSE(message.HasExtension(unittest::default_import_enum_extension )); 1464 EXPECT_FALSE(message.HasExtension(unittest::default_import_enum_extension ));
1406 1465
1407 EXPECT_FALSE(message.HasExtension(unittest::default_string_piece_extension)); 1466 EXPECT_FALSE(message.HasExtension(unittest::default_string_piece_extension));
1408 EXPECT_FALSE(message.HasExtension(unittest::default_cord_extension)); 1467 EXPECT_FALSE(message.HasExtension(unittest::default_cord_extension));
1409 1468
1410 // Fields with defaults have their default values (duh). 1469 // Fields with defaults have their default values (duh).
1411 EXPECT_EQ( 41 , message.GetExtension(unittest::default_int32_extension )); 1470 EXPECT_EQ( 41 , message.GetExtension(unittest::default_int32_extension ));
1412 EXPECT_EQ( 42 , message.GetExtension(unittest::default_int64_extension )); 1471 EXPECT_EQ( 42 , message.GetExtension(unittest::default_int64_extension ));
1413 EXPECT_EQ( 43 , message.GetExtension(unittest::default_uint32_extension )); 1472 EXPECT_EQ( 43 , message.GetExtension(unittest::default_uint32_extension ));
1414 EXPECT_EQ( 44 , message.GetExtension(unittest::default_uint64_extension )); 1473 EXPECT_EQ( 44 , message.GetExtension(unittest::default_uint64_extension ));
1415 EXPECT_EQ(-45 , message.GetExtension(unittest::default_sint32_extension )); 1474 EXPECT_EQ(-45 , message.GetExtension(unittest::default_sint32_extension ));
1416 EXPECT_EQ( 46 , message.GetExtension(unittest::default_sint64_extension )); 1475 EXPECT_EQ( 46 , message.GetExtension(unittest::default_sint64_extension ));
1417 EXPECT_EQ( 47 , message.GetExtension(unittest::default_fixed32_extension )); 1476 EXPECT_EQ( 47 , message.GetExtension(unittest::default_fixed32_extension ));
1418 EXPECT_EQ( 48 , message.GetExtension(unittest::default_fixed64_extension )); 1477 EXPECT_EQ( 48 , message.GetExtension(unittest::default_fixed64_extension ));
1419 EXPECT_EQ( 49 , message.GetExtension(unittest::default_sfixed32_extension)); 1478 EXPECT_EQ( 49 , message.GetExtension(unittest::default_sfixed32_extension));
1420 EXPECT_EQ(-50 , message.GetExtension(unittest::default_sfixed64_extension)); 1479 EXPECT_EQ(-50 , message.GetExtension(unittest::default_sfixed64_extension));
1421 EXPECT_EQ( 51.5 , message.GetExtension(unittest::default_float_extension )); 1480 EXPECT_EQ( 51.5 , message.GetExtension(unittest::default_float_extension ));
1422 EXPECT_EQ( 52e3 , message.GetExtension(unittest::default_double_extension )); 1481 EXPECT_EQ( 52e3 , message.GetExtension(unittest::default_double_extension ));
1423 EXPECT_EQ(true , message.GetExtension(unittest::default_bool_extension )); 1482 EXPECT_EQ(true , message.GetExtension(unittest::default_bool_extension ));
1424 EXPECT_EQ("hello", message.GetExtension(unittest::default_string_extension )); 1483 EXPECT_EQ("hello", message.GetExtension(unittest::default_string_extension ));
1425 EXPECT_EQ("world", message.GetExtension(unittest::default_bytes_extension )); 1484 EXPECT_EQ("world", message.GetExtension(unittest::default_bytes_extension ));
1426 1485
1427 EXPECT_EQ(unittest::TestAllTypes::BAR, message.GetExtension(unittest::default_nested_enum_extension )); 1486 EXPECT_EQ(unittest::TestAllTypes::BAR, message.GetExtension(unittest::default_nested_enum_extension ));
1428 EXPECT_EQ(unittest::FOREIGN_BAR , message.GetExtension(unittest::default_foreign_enum_extension)); 1487 EXPECT_EQ(unittest::FOREIGN_BAR , message.GetExtension(unittest::default_foreign_enum_extension));
1429 EXPECT_EQ(unittest_import::IMPORT_BAR, message.GetExtension(unittest::default_import_enum_extension )); 1488 EXPECT_EQ(unittest_import::IMPORT_BAR, message.GetExtension(unittest::default_import_enum_extension ));
1430 1489
1431 EXPECT_EQ("abc", message.GetExtension(unittest::default_string_piece_extension)); 1490 EXPECT_EQ("abc", message.GetExtension(unittest::default_string_piece_extension));
1432 EXPECT_EQ("123", message.GetExtension(unittest::default_cord_extension)); 1491 EXPECT_EQ("123", message.GetExtension(unittest::default_cord_extension));
1433 } 1492 }
1434 1493
1435 // ------------------------------------------------------------------- 1494 // -------------------------------------------------------------------
1436 1495
1437 void TestUtil::ExpectRepeatedExtensionsModified( 1496 void TestUtil::ExpectRepeatedExtensionsModified(
1438 const unittest::TestAllExtensions& message) { 1497 const unittest::TestAllExtensions& message) {
1439 // ModifyRepeatedFields only sets the second repeated element of each 1498 // ModifyRepeatedFields only sets the second repeated element of each
1440 // field. In addition to verifying this, we also verify that the first 1499 // field. In addition to verifying this, we also verify that the first
1441 // element and size were *not* modified. 1500 // element and size were *not* modified.
1442 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int32_extension )); 1501 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int32_extension ));
1443 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int64_extension )); 1502 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int64_extension ));
1444 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint32_extension )); 1503 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint32_extension ));
1445 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint64_extension )); 1504 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint64_extension ));
1446 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint32_extension )); 1505 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint32_extension ));
1447 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint64_extension )); 1506 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint64_extension ));
1448 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed32_extension )); 1507 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed32_extension ));
1449 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed64_extension )); 1508 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed64_extension ));
1450 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed32_extension)); 1509 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed32_extension));
1451 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed64_extension)); 1510 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed64_extension));
1452 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_float_extension )); 1511 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_float_extension ));
1453 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_double_extension )); 1512 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_double_extension ));
1454 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bool_extension )); 1513 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bool_extension ));
1455 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_extension )); 1514 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_extension ));
1456 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bytes_extension )); 1515 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bytes_extension ));
1457 1516
1458 ASSERT_EQ(2, message.ExtensionSize(unittest::repeatedgroup_extension )); 1517 ASSERT_EQ(2, message.ExtensionSize(unittest::repeatedgroup_extension ));
1459 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_message_extension )); 1518 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_message_extension ));
1460 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_message_extension)); 1519 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_message_extension));
1461 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_message_extension )); 1520 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_message_extension ));
1521 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_lazy_message_extension ));
1462 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_enum_extension )); 1522 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_enum_extension ));
1463 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_enum_extension )); 1523 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_enum_extension ));
1464 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_enum_extension )); 1524 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_enum_extension ));
1465 1525
1466 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_piece_extension)); 1526 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_piece_extension));
1467 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_cord_extension)); 1527 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_cord_extension));
1468 1528
1469 EXPECT_EQ(201 , message.GetExtension(unittest::repeated_int32_extension , 0)); 1529 EXPECT_EQ(201 , message.GetExtension(unittest::repeated_int32_extension , 0));
1470 EXPECT_EQ(202 , message.GetExtension(unittest::repeated_int64_extension , 0)); 1530 EXPECT_EQ(202 , message.GetExtension(unittest::repeated_int64_extension , 0));
1471 EXPECT_EQ(203 , message.GetExtension(unittest::repeated_uint32_extension , 0)); 1531 EXPECT_EQ(203 , message.GetExtension(unittest::repeated_uint32_extension , 0));
1472 EXPECT_EQ(204 , message.GetExtension(unittest::repeated_uint64_extension , 0)); 1532 EXPECT_EQ(204 , message.GetExtension(unittest::repeated_uint64_extension , 0));
1473 EXPECT_EQ(205 , message.GetExtension(unittest::repeated_sint32_extension , 0)); 1533 EXPECT_EQ(205 , message.GetExtension(unittest::repeated_sint32_extension , 0));
1474 EXPECT_EQ(206 , message.GetExtension(unittest::repeated_sint64_extension , 0)); 1534 EXPECT_EQ(206 , message.GetExtension(unittest::repeated_sint64_extension , 0));
1475 EXPECT_EQ(207 , message.GetExtension(unittest::repeated_fixed32_extension , 0)); 1535 EXPECT_EQ(207 , message.GetExtension(unittest::repeated_fixed32_extension , 0));
1476 EXPECT_EQ(208 , message.GetExtension(unittest::repeated_fixed64_extension , 0)); 1536 EXPECT_EQ(208 , message.GetExtension(unittest::repeated_fixed64_extension , 0));
1477 EXPECT_EQ(209 , message.GetExtension(unittest::repeated_sfixed32_extension, 0)); 1537 EXPECT_EQ(209 , message.GetExtension(unittest::repeated_sfixed32_extension, 0));
1478 EXPECT_EQ(210 , message.GetExtension(unittest::repeated_sfixed64_extension, 0)); 1538 EXPECT_EQ(210 , message.GetExtension(unittest::repeated_sfixed64_extension, 0));
1479 EXPECT_EQ(211 , message.GetExtension(unittest::repeated_float_extension , 0)); 1539 EXPECT_EQ(211 , message.GetExtension(unittest::repeated_float_extension , 0));
1480 EXPECT_EQ(212 , message.GetExtension(unittest::repeated_double_extension , 0)); 1540 EXPECT_EQ(212 , message.GetExtension(unittest::repeated_double_extension , 0));
1481 EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension , 0)); 1541 EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension , 0));
1482 EXPECT_EQ("215", message.GetExtension(unittest::repeated_string_extension , 0)); 1542 EXPECT_EQ("215", message.GetExtension(unittest::repeated_string_extension , 0));
1483 EXPECT_EQ("216", message.GetExtension(unittest::repeated_bytes_extension , 0)); 1543 EXPECT_EQ("216", message.GetExtension(unittest::repeated_bytes_extension , 0));
1484 1544
1485 EXPECT_EQ(217, message.GetExtension(unittest::repeatedgroup_extension , 0).a()); 1545 EXPECT_EQ(217, message.GetExtension(unittest::repeatedgroup_extension , 0).a());
1486 EXPECT_EQ(218, message.GetExtension(unittest::repeated_nested_message_extension , 0).bb()); 1546 EXPECT_EQ(218, message.GetExtension(unittest::repeated_nested_message_extension , 0).bb());
1487 EXPECT_EQ(219, message.GetExtension(unittest::repeated_foreign_message_extension, 0).c()); 1547 EXPECT_EQ(219, message.GetExtension(unittest::repeated_foreign_message_extension, 0).c());
1488 EXPECT_EQ(220, message.GetExtension(unittest::repeated_import_message_extension , 0).d()); 1548 EXPECT_EQ(220, message.GetExtension(unittest::repeated_import_message_extension , 0).d());
1549 EXPECT_EQ(227, message.GetExtension(unittest::repeated_lazy_message_extension , 0).bb());
1489 1550
1490 EXPECT_EQ(unittest::TestAllTypes::BAR, message.GetExtension(unittest::repeated_nested_enum_extension , 0)); 1551 EXPECT_EQ(unittest::TestAllTypes::BAR, message.GetExtension(unittest::repeated_nested_enum_extension , 0));
1491 EXPECT_EQ(unittest::FOREIGN_BAR , message.GetExtension(unittest::repeated_foreign_enum_extension, 0)); 1552 EXPECT_EQ(unittest::FOREIGN_BAR , message.GetExtension(unittest::repeated_foreign_enum_extension, 0));
1492 EXPECT_EQ(unittest_import::IMPORT_BAR, message.GetExtension(unittest::repeated_import_enum_extension , 0)); 1553 EXPECT_EQ(unittest_import::IMPORT_BAR, message.GetExtension(unittest::repeated_import_enum_extension , 0));
1493 1554
1494 EXPECT_EQ("224", message.GetExtension(unittest::repeated_string_piece_extension, 0)); 1555 EXPECT_EQ("224", message.GetExtension(unittest::repeated_string_piece_extension, 0));
1495 EXPECT_EQ("225", message.GetExtension(unittest::repeated_cord_extension, 0)); 1556 EXPECT_EQ("225", message.GetExtension(unittest::repeated_cord_extension, 0));
1496 1557
1497 // Actually verify the second (modified) elements now. 1558 // Actually verify the second (modified) elements now.
1498 EXPECT_EQ(501 , message.GetExtension(unittest::repeated_int32_extension , 1)); 1559 EXPECT_EQ(501 , message.GetExtension(unittest::repeated_int32_extension , 1));
1499 EXPECT_EQ(502 , message.GetExtension(unittest::repeated_int64_extension , 1)); 1560 EXPECT_EQ(502 , message.GetExtension(unittest::repeated_int64_extension , 1));
1500 EXPECT_EQ(503 , message.GetExtension(unittest::repeated_uint32_extension , 1)); 1561 EXPECT_EQ(503 , message.GetExtension(unittest::repeated_uint32_extension , 1));
1501 EXPECT_EQ(504 , message.GetExtension(unittest::repeated_uint64_extension , 1)); 1562 EXPECT_EQ(504 , message.GetExtension(unittest::repeated_uint64_extension , 1));
1502 EXPECT_EQ(505 , message.GetExtension(unittest::repeated_sint32_extension , 1)); 1563 EXPECT_EQ(505 , message.GetExtension(unittest::repeated_sint32_extension , 1));
1503 EXPECT_EQ(506 , message.GetExtension(unittest::repeated_sint64_extension , 1)); 1564 EXPECT_EQ(506 , message.GetExtension(unittest::repeated_sint64_extension , 1));
1504 EXPECT_EQ(507 , message.GetExtension(unittest::repeated_fixed32_extension , 1)); 1565 EXPECT_EQ(507 , message.GetExtension(unittest::repeated_fixed32_extension , 1));
1505 EXPECT_EQ(508 , message.GetExtension(unittest::repeated_fixed64_extension , 1)); 1566 EXPECT_EQ(508 , message.GetExtension(unittest::repeated_fixed64_extension , 1));
1506 EXPECT_EQ(509 , message.GetExtension(unittest::repeated_sfixed32_extension, 1)); 1567 EXPECT_EQ(509 , message.GetExtension(unittest::repeated_sfixed32_extension, 1));
1507 EXPECT_EQ(510 , message.GetExtension(unittest::repeated_sfixed64_extension, 1)); 1568 EXPECT_EQ(510 , message.GetExtension(unittest::repeated_sfixed64_extension, 1));
1508 EXPECT_EQ(511 , message.GetExtension(unittest::repeated_float_extension , 1)); 1569 EXPECT_EQ(511 , message.GetExtension(unittest::repeated_float_extension , 1));
1509 EXPECT_EQ(512 , message.GetExtension(unittest::repeated_double_extension , 1)); 1570 EXPECT_EQ(512 , message.GetExtension(unittest::repeated_double_extension , 1));
1510 EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension , 1)); 1571 EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension , 1));
1511 EXPECT_EQ("515", message.GetExtension(unittest::repeated_string_extension , 1)); 1572 EXPECT_EQ("515", message.GetExtension(unittest::repeated_string_extension , 1));
1512 EXPECT_EQ("516", message.GetExtension(unittest::repeated_bytes_extension , 1)); 1573 EXPECT_EQ("516", message.GetExtension(unittest::repeated_bytes_extension , 1));
1513 1574
1514 EXPECT_EQ(517, message.GetExtension(unittest::repeatedgroup_extension , 1).a()); 1575 EXPECT_EQ(517, message.GetExtension(unittest::repeatedgroup_extension , 1).a());
1515 EXPECT_EQ(518, message.GetExtension(unittest::repeated_nested_message_extension , 1).bb()); 1576 EXPECT_EQ(518, message.GetExtension(unittest::repeated_nested_message_extension , 1).bb());
1516 EXPECT_EQ(519, message.GetExtension(unittest::repeated_foreign_message_extension, 1).c()); 1577 EXPECT_EQ(519, message.GetExtension(unittest::repeated_foreign_message_extension, 1).c());
1517 EXPECT_EQ(520, message.GetExtension(unittest::repeated_import_message_extension , 1).d()); 1578 EXPECT_EQ(520, message.GetExtension(unittest::repeated_import_message_extension , 1).d());
1579 EXPECT_EQ(527, message.GetExtension(unittest::repeated_lazy_message_extension , 1).bb());
1518 1580
1519 EXPECT_EQ(unittest::TestAllTypes::FOO, message.GetExtension(unittest::repeated_nested_enum_extension , 1)); 1581 EXPECT_EQ(unittest::TestAllTypes::FOO, message.GetExtension(unittest::repeated_nested_enum_extension , 1));
1520 EXPECT_EQ(unittest::FOREIGN_FOO , message.GetExtension(unittest::repeated_foreign_enum_extension, 1)); 1582 EXPECT_EQ(unittest::FOREIGN_FOO , message.GetExtension(unittest::repeated_foreign_enum_extension, 1));
1521 EXPECT_EQ(unittest_import::IMPORT_FOO, message.GetExtension(unittest::repeated_import_enum_extension , 1)); 1583 EXPECT_EQ(unittest_import::IMPORT_FOO, message.GetExtension(unittest::repeated_import_enum_extension , 1));
1522 1584
1523 EXPECT_EQ("524", message.GetExtension(unittest::repeated_string_piece_extension, 1)); 1585 EXPECT_EQ("524", message.GetExtension(unittest::repeated_string_piece_extension, 1));
1524 EXPECT_EQ("525", message.GetExtension(unittest::repeated_cord_extension, 1)); 1586 EXPECT_EQ("525", message.GetExtension(unittest::repeated_cord_extension, 1));
1525 } 1587 }
1526 1588
1527 // ------------------------------------------------------------------- 1589 // -------------------------------------------------------------------
1528 1590
1529 void TestUtil::SetPackedExtensions(unittest::TestPackedExtensions* message) { 1591 void TestUtil::SetPackedExtensions(unittest::TestPackedExtensions* message) {
1530 message->AddExtension(unittest::packed_int32_extension , 601); 1592 message->AddExtension(unittest::packed_int32_extension , 601);
1531 message->AddExtension(unittest::packed_int64_extension , 602); 1593 message->AddExtension(unittest::packed_int64_extension , 602);
1532 message->AddExtension(unittest::packed_uint32_extension , 603); 1594 message->AddExtension(unittest::packed_uint32_extension , 603);
1533 message->AddExtension(unittest::packed_uint64_extension , 604); 1595 message->AddExtension(unittest::packed_uint64_extension , 604);
1534 message->AddExtension(unittest::packed_sint32_extension , 605); 1596 message->AddExtension(unittest::packed_sint32_extension , 605);
1535 message->AddExtension(unittest::packed_sint64_extension , 606); 1597 message->AddExtension(unittest::packed_sint64_extension , 606);
1536 message->AddExtension(unittest::packed_fixed32_extension , 607); 1598 message->AddExtension(unittest::packed_fixed32_extension , 607);
1537 message->AddExtension(unittest::packed_fixed64_extension , 608); 1599 message->AddExtension(unittest::packed_fixed64_extension , 608);
1538 message->AddExtension(unittest::packed_sfixed32_extension, 609); 1600 message->AddExtension(unittest::packed_sfixed32_extension, 609);
1539 message->AddExtension(unittest::packed_sfixed64_extension, 610); 1601 message->AddExtension(unittest::packed_sfixed64_extension, 610);
1540 message->AddExtension(unittest::packed_float_extension , 611); 1602 message->AddExtension(unittest::packed_float_extension , 611);
1541 message->AddExtension(unittest::packed_double_extension , 612); 1603 message->AddExtension(unittest::packed_double_extension , 612);
1542 message->AddExtension(unittest::packed_bool_extension , true); 1604 message->AddExtension(unittest::packed_bool_extension , true);
1543 message->AddExtension(unittest::packed_enum_extension, unittest::FOREIGN_BAR); 1605 message->AddExtension(unittest::packed_enum_extension, unittest::FOREIGN_BAR);
1544 // add a second one of each field 1606 // add a second one of each field
1545 message->AddExtension(unittest::packed_int32_extension , 701); 1607 message->AddExtension(unittest::packed_int32_extension , 701);
1546 message->AddExtension(unittest::packed_int64_extension , 702); 1608 message->AddExtension(unittest::packed_int64_extension , 702);
1547 message->AddExtension(unittest::packed_uint32_extension , 703); 1609 message->AddExtension(unittest::packed_uint32_extension , 703);
1548 message->AddExtension(unittest::packed_uint64_extension , 704); 1610 message->AddExtension(unittest::packed_uint64_extension , 704);
1549 message->AddExtension(unittest::packed_sint32_extension , 705); 1611 message->AddExtension(unittest::packed_sint32_extension , 705);
1550 message->AddExtension(unittest::packed_sint64_extension , 706); 1612 message->AddExtension(unittest::packed_sint64_extension , 706);
1551 message->AddExtension(unittest::packed_fixed32_extension , 707); 1613 message->AddExtension(unittest::packed_fixed32_extension , 707);
1552 message->AddExtension(unittest::packed_fixed64_extension , 708); 1614 message->AddExtension(unittest::packed_fixed64_extension , 708);
1553 message->AddExtension(unittest::packed_sfixed32_extension, 709); 1615 message->AddExtension(unittest::packed_sfixed32_extension, 709);
1554 message->AddExtension(unittest::packed_sfixed64_extension, 710); 1616 message->AddExtension(unittest::packed_sfixed64_extension, 710);
1555 message->AddExtension(unittest::packed_float_extension , 711); 1617 message->AddExtension(unittest::packed_float_extension , 711);
1556 message->AddExtension(unittest::packed_double_extension , 712); 1618 message->AddExtension(unittest::packed_double_extension , 712);
1557 message->AddExtension(unittest::packed_bool_extension , false); 1619 message->AddExtension(unittest::packed_bool_extension , false);
1558 message->AddExtension(unittest::packed_enum_extension, unittest::FOREIGN_BAZ); 1620 message->AddExtension(unittest::packed_enum_extension, unittest::FOREIGN_BAZ);
1559 } 1621 }
1560 1622
1561 // ------------------------------------------------------------------- 1623 // -------------------------------------------------------------------
1562 1624
1563 void TestUtil::ModifyPackedExtensions(unittest::TestPackedExtensions* message) { 1625 void TestUtil::ModifyPackedExtensions(unittest::TestPackedExtensions* message) {
1564 message->SetExtension(unittest::packed_int32_extension , 1, 801); 1626 message->SetExtension(unittest::packed_int32_extension , 1, 801);
1565 message->SetExtension(unittest::packed_int64_extension , 1, 802); 1627 message->SetExtension(unittest::packed_int64_extension , 1, 802);
1566 message->SetExtension(unittest::packed_uint32_extension , 1, 803); 1628 message->SetExtension(unittest::packed_uint32_extension , 1, 803);
1567 message->SetExtension(unittest::packed_uint64_extension , 1, 804); 1629 message->SetExtension(unittest::packed_uint64_extension , 1, 804);
1568 message->SetExtension(unittest::packed_sint32_extension , 1, 805); 1630 message->SetExtension(unittest::packed_sint32_extension , 1, 805);
1569 message->SetExtension(unittest::packed_sint64_extension , 1, 806); 1631 message->SetExtension(unittest::packed_sint64_extension , 1, 806);
1570 message->SetExtension(unittest::packed_fixed32_extension , 1, 807); 1632 message->SetExtension(unittest::packed_fixed32_extension , 1, 807);
1571 message->SetExtension(unittest::packed_fixed64_extension , 1, 808); 1633 message->SetExtension(unittest::packed_fixed64_extension , 1, 808);
1572 message->SetExtension(unittest::packed_sfixed32_extension, 1, 809); 1634 message->SetExtension(unittest::packed_sfixed32_extension, 1, 809);
1573 message->SetExtension(unittest::packed_sfixed64_extension, 1, 810); 1635 message->SetExtension(unittest::packed_sfixed64_extension, 1, 810);
1574 message->SetExtension(unittest::packed_float_extension , 1, 811); 1636 message->SetExtension(unittest::packed_float_extension , 1, 811);
1575 message->SetExtension(unittest::packed_double_extension , 1, 812); 1637 message->SetExtension(unittest::packed_double_extension , 1, 812);
1576 message->SetExtension(unittest::packed_bool_extension , 1, true); 1638 message->SetExtension(unittest::packed_bool_extension , 1, true);
1577 message->SetExtension(unittest::packed_enum_extension , 1, 1639 message->SetExtension(unittest::packed_enum_extension , 1,
1578 unittest::FOREIGN_FOO); 1640 unittest::FOREIGN_FOO);
1579 } 1641 }
1580 1642
1581 // ------------------------------------------------------------------- 1643 // -------------------------------------------------------------------
1582 1644
1583 void TestUtil::ExpectPackedExtensionsSet( 1645 void TestUtil::ExpectPackedExtensionsSet(
1584 const unittest::TestPackedExtensions& message) { 1646 const unittest::TestPackedExtensions& message) {
1585 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int32_extension )); 1647 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int32_extension ));
1586 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int64_extension )); 1648 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int64_extension ));
1587 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint32_extension )); 1649 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint32_extension ));
1588 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint64_extension )); 1650 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint64_extension ));
1589 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint32_extension )); 1651 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint32_extension ));
1590 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint64_extension )); 1652 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint64_extension ));
1591 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed32_extension )); 1653 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed32_extension ));
1592 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed64_extension )); 1654 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed64_extension ));
1593 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed32_extension)); 1655 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed32_extension));
1594 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed64_extension)); 1656 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed64_extension));
1595 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_float_extension )); 1657 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_float_extension ));
1596 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_double_extension )); 1658 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_double_extension ));
1597 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_bool_extension )); 1659 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_bool_extension ));
1598 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_enum_extension )); 1660 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_enum_extension ));
1599 1661
1600 EXPECT_EQ(601 , message.GetExtension(unittest::packed_int32_extension , 0)); 1662 EXPECT_EQ(601 , message.GetExtension(unittest::packed_int32_extension , 0));
1601 EXPECT_EQ(602 , message.GetExtension(unittest::packed_int64_extension , 0)); 1663 EXPECT_EQ(602 , message.GetExtension(unittest::packed_int64_extension , 0));
1602 EXPECT_EQ(603 , message.GetExtension(unittest::packed_uint32_extension , 0)); 1664 EXPECT_EQ(603 , message.GetExtension(unittest::packed_uint32_extension , 0));
1603 EXPECT_EQ(604 , message.GetExtension(unittest::packed_uint64_extension , 0)); 1665 EXPECT_EQ(604 , message.GetExtension(unittest::packed_uint64_extension , 0));
1604 EXPECT_EQ(605 , message.GetExtension(unittest::packed_sint32_extension , 0)); 1666 EXPECT_EQ(605 , message.GetExtension(unittest::packed_sint32_extension , 0));
1605 EXPECT_EQ(606 , message.GetExtension(unittest::packed_sint64_extension , 0)); 1667 EXPECT_EQ(606 , message.GetExtension(unittest::packed_sint64_extension , 0));
1606 EXPECT_EQ(607 , message.GetExtension(unittest::packed_fixed32_extension , 0)); 1668 EXPECT_EQ(607 , message.GetExtension(unittest::packed_fixed32_extension , 0));
1607 EXPECT_EQ(608 , message.GetExtension(unittest::packed_fixed64_extension , 0)); 1669 EXPECT_EQ(608 , message.GetExtension(unittest::packed_fixed64_extension , 0));
1608 EXPECT_EQ(609 , message.GetExtension(unittest::packed_sfixed32_extension, 0)); 1670 EXPECT_EQ(609 , message.GetExtension(unittest::packed_sfixed32_extension, 0));
1609 EXPECT_EQ(610 , message.GetExtension(unittest::packed_sfixed64_extension, 0)); 1671 EXPECT_EQ(610 , message.GetExtension(unittest::packed_sfixed64_extension, 0));
1610 EXPECT_EQ(611 , message.GetExtension(unittest::packed_float_extension , 0)); 1672 EXPECT_EQ(611 , message.GetExtension(unittest::packed_float_extension , 0));
1611 EXPECT_EQ(612 , message.GetExtension(unittest::packed_double_extension , 0)); 1673 EXPECT_EQ(612 , message.GetExtension(unittest::packed_double_extension , 0));
1612 EXPECT_EQ(true , message.GetExtension(unittest::packed_bool_extension , 0)); 1674 EXPECT_EQ(true , message.GetExtension(unittest::packed_bool_extension , 0));
1613 EXPECT_EQ(unittest::FOREIGN_BAR, 1675 EXPECT_EQ(unittest::FOREIGN_BAR,
1614 message.GetExtension(unittest::packed_enum_extension, 0)); 1676 message.GetExtension(unittest::packed_enum_extension, 0));
1615 EXPECT_EQ(701 , message.GetExtension(unittest::packed_int32_extension , 1)); 1677 EXPECT_EQ(701 , message.GetExtension(unittest::packed_int32_extension , 1));
1616 EXPECT_EQ(702 , message.GetExtension(unittest::packed_int64_extension , 1)); 1678 EXPECT_EQ(702 , message.GetExtension(unittest::packed_int64_extension , 1));
1617 EXPECT_EQ(703 , message.GetExtension(unittest::packed_uint32_extension , 1)); 1679 EXPECT_EQ(703 , message.GetExtension(unittest::packed_uint32_extension , 1));
1618 EXPECT_EQ(704 , message.GetExtension(unittest::packed_uint64_extension , 1)); 1680 EXPECT_EQ(704 , message.GetExtension(unittest::packed_uint64_extension , 1));
1619 EXPECT_EQ(705 , message.GetExtension(unittest::packed_sint32_extension , 1)); 1681 EXPECT_EQ(705 , message.GetExtension(unittest::packed_sint32_extension , 1));
1620 EXPECT_EQ(706 , message.GetExtension(unittest::packed_sint64_extension , 1)); 1682 EXPECT_EQ(706 , message.GetExtension(unittest::packed_sint64_extension , 1));
1621 EXPECT_EQ(707 , message.GetExtension(unittest::packed_fixed32_extension , 1)); 1683 EXPECT_EQ(707 , message.GetExtension(unittest::packed_fixed32_extension , 1));
1622 EXPECT_EQ(708 , message.GetExtension(unittest::packed_fixed64_extension , 1)); 1684 EXPECT_EQ(708 , message.GetExtension(unittest::packed_fixed64_extension , 1));
1623 EXPECT_EQ(709 , message.GetExtension(unittest::packed_sfixed32_extension, 1)); 1685 EXPECT_EQ(709 , message.GetExtension(unittest::packed_sfixed32_extension, 1));
1624 EXPECT_EQ(710 , message.GetExtension(unittest::packed_sfixed64_extension, 1)); 1686 EXPECT_EQ(710 , message.GetExtension(unittest::packed_sfixed64_extension, 1));
1625 EXPECT_EQ(711 , message.GetExtension(unittest::packed_float_extension , 1)); 1687 EXPECT_EQ(711 , message.GetExtension(unittest::packed_float_extension , 1));
1626 EXPECT_EQ(712 , message.GetExtension(unittest::packed_double_extension , 1)); 1688 EXPECT_EQ(712 , message.GetExtension(unittest::packed_double_extension , 1));
1627 EXPECT_EQ(false, message.GetExtension(unittest::packed_bool_extension , 1)); 1689 EXPECT_EQ(false, message.GetExtension(unittest::packed_bool_extension , 1));
1628 EXPECT_EQ(unittest::FOREIGN_BAZ, 1690 EXPECT_EQ(unittest::FOREIGN_BAZ,
1629 message.GetExtension(unittest::packed_enum_extension, 1)); 1691 message.GetExtension(unittest::packed_enum_extension, 1));
1630 } 1692 }
1631 1693
1632 // ------------------------------------------------------------------- 1694 // -------------------------------------------------------------------
1633 1695
1634 void TestUtil::ExpectPackedExtensionsClear( 1696 void TestUtil::ExpectPackedExtensionsClear(
1635 const unittest::TestPackedExtensions& message) { 1697 const unittest::TestPackedExtensions& message) {
1636 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_int32_extension )); 1698 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_int32_extension ));
1637 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_int64_extension )); 1699 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_int64_extension ));
1638 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_uint32_extension )); 1700 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_uint32_extension ));
1639 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_uint64_extension )); 1701 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_uint64_extension ));
1640 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sint32_extension )); 1702 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sint32_extension ));
1641 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sint64_extension )); 1703 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sint64_extension ));
1642 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_fixed32_extension )); 1704 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_fixed32_extension ));
1643 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_fixed64_extension )); 1705 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_fixed64_extension ));
1644 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sfixed32_extension)); 1706 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sfixed32_extension));
1645 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sfixed64_extension)); 1707 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sfixed64_extension));
1646 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_float_extension )); 1708 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_float_extension ));
1647 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_double_extension )); 1709 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_double_extension ));
1648 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_bool_extension )); 1710 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_bool_extension ));
1649 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_enum_extension )); 1711 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_enum_extension ));
1650 } 1712 }
1651 1713
1652 // ------------------------------------------------------------------- 1714 // -------------------------------------------------------------------
1653 1715
1654 void TestUtil::ExpectPackedExtensionsModified( 1716 void TestUtil::ExpectPackedExtensionsModified(
1655 const unittest::TestPackedExtensions& message) { 1717 const unittest::TestPackedExtensions& message) {
1656 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int32_extension )); 1718 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int32_extension ));
1657 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int64_extension )); 1719 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int64_extension ));
1658 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint32_extension )); 1720 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint32_extension ));
1659 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint64_extension )); 1721 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint64_extension ));
1660 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint32_extension )); 1722 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint32_extension ));
1661 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint64_extension )); 1723 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint64_extension ));
1662 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed32_extension )); 1724 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed32_extension ));
1663 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed64_extension )); 1725 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed64_extension ));
1664 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed32_extension)); 1726 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed32_extension));
1665 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed64_extension)); 1727 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed64_extension));
1666 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_float_extension )); 1728 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_float_extension ));
1667 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_double_extension )); 1729 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_double_extension ));
1668 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_bool_extension )); 1730 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_bool_extension ));
1669 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_enum_extension )); 1731 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_enum_extension ));
1670 EXPECT_EQ(601 , message.GetExtension(unittest::packed_int32_extension , 0)); 1732 EXPECT_EQ(601 , message.GetExtension(unittest::packed_int32_extension , 0));
1671 EXPECT_EQ(602 , message.GetExtension(unittest::packed_int64_extension , 0)); 1733 EXPECT_EQ(602 , message.GetExtension(unittest::packed_int64_extension , 0));
1672 EXPECT_EQ(603 , message.GetExtension(unittest::packed_uint32_extension , 0)); 1734 EXPECT_EQ(603 , message.GetExtension(unittest::packed_uint32_extension , 0));
1673 EXPECT_EQ(604 , message.GetExtension(unittest::packed_uint64_extension , 0)); 1735 EXPECT_EQ(604 , message.GetExtension(unittest::packed_uint64_extension , 0));
1674 EXPECT_EQ(605 , message.GetExtension(unittest::packed_sint32_extension , 0)); 1736 EXPECT_EQ(605 , message.GetExtension(unittest::packed_sint32_extension , 0));
1675 EXPECT_EQ(606 , message.GetExtension(unittest::packed_sint64_extension , 0)); 1737 EXPECT_EQ(606 , message.GetExtension(unittest::packed_sint64_extension , 0));
1676 EXPECT_EQ(607 , message.GetExtension(unittest::packed_fixed32_extension , 0)); 1738 EXPECT_EQ(607 , message.GetExtension(unittest::packed_fixed32_extension , 0));
1677 EXPECT_EQ(608 , message.GetExtension(unittest::packed_fixed64_extension , 0)); 1739 EXPECT_EQ(608 , message.GetExtension(unittest::packed_fixed64_extension , 0));
1678 EXPECT_EQ(609 , message.GetExtension(unittest::packed_sfixed32_extension, 0)); 1740 EXPECT_EQ(609 , message.GetExtension(unittest::packed_sfixed32_extension, 0));
1679 EXPECT_EQ(610 , message.GetExtension(unittest::packed_sfixed64_extension, 0)); 1741 EXPECT_EQ(610 , message.GetExtension(unittest::packed_sfixed64_extension, 0));
1680 EXPECT_EQ(611 , message.GetExtension(unittest::packed_float_extension , 0)); 1742 EXPECT_EQ(611 , message.GetExtension(unittest::packed_float_extension , 0));
1681 EXPECT_EQ(612 , message.GetExtension(unittest::packed_double_extension , 0)); 1743 EXPECT_EQ(612 , message.GetExtension(unittest::packed_double_extension , 0));
1682 EXPECT_EQ(true , message.GetExtension(unittest::packed_bool_extension , 0)); 1744 EXPECT_EQ(true , message.GetExtension(unittest::packed_bool_extension , 0));
1683 EXPECT_EQ(unittest::FOREIGN_BAR, 1745 EXPECT_EQ(unittest::FOREIGN_BAR,
1684 message.GetExtension(unittest::packed_enum_extension, 0)); 1746 message.GetExtension(unittest::packed_enum_extension, 0));
1685 1747
1686 // Actually verify the second (modified) elements now. 1748 // Actually verify the second (modified) elements now.
1687 EXPECT_EQ(801 , message.GetExtension(unittest::packed_int32_extension , 1)); 1749 EXPECT_EQ(801 , message.GetExtension(unittest::packed_int32_extension , 1));
1688 EXPECT_EQ(802 , message.GetExtension(unittest::packed_int64_extension , 1)); 1750 EXPECT_EQ(802 , message.GetExtension(unittest::packed_int64_extension , 1));
1689 EXPECT_EQ(803 , message.GetExtension(unittest::packed_uint32_extension , 1)); 1751 EXPECT_EQ(803 , message.GetExtension(unittest::packed_uint32_extension , 1));
1690 EXPECT_EQ(804 , message.GetExtension(unittest::packed_uint64_extension , 1)); 1752 EXPECT_EQ(804 , message.GetExtension(unittest::packed_uint64_extension , 1));
1691 EXPECT_EQ(805 , message.GetExtension(unittest::packed_sint32_extension , 1)); 1753 EXPECT_EQ(805 , message.GetExtension(unittest::packed_sint32_extension , 1));
1692 EXPECT_EQ(806 , message.GetExtension(unittest::packed_sint64_extension , 1)); 1754 EXPECT_EQ(806 , message.GetExtension(unittest::packed_sint64_extension , 1));
1693 EXPECT_EQ(807 , message.GetExtension(unittest::packed_fixed32_extension , 1)); 1755 EXPECT_EQ(807 , message.GetExtension(unittest::packed_fixed32_extension , 1));
1694 EXPECT_EQ(808 , message.GetExtension(unittest::packed_fixed64_extension , 1)); 1756 EXPECT_EQ(808 , message.GetExtension(unittest::packed_fixed64_extension , 1));
1695 EXPECT_EQ(809 , message.GetExtension(unittest::packed_sfixed32_extension, 1)); 1757 EXPECT_EQ(809 , message.GetExtension(unittest::packed_sfixed32_extension, 1));
1696 EXPECT_EQ(810 , message.GetExtension(unittest::packed_sfixed64_extension, 1)); 1758 EXPECT_EQ(810 , message.GetExtension(unittest::packed_sfixed64_extension, 1));
1697 EXPECT_EQ(811 , message.GetExtension(unittest::packed_float_extension , 1)); 1759 EXPECT_EQ(811 , message.GetExtension(unittest::packed_float_extension , 1));
1698 EXPECT_EQ(812 , message.GetExtension(unittest::packed_double_extension , 1)); 1760 EXPECT_EQ(812 , message.GetExtension(unittest::packed_double_extension , 1));
1699 EXPECT_EQ(true , message.GetExtension(unittest::packed_bool_extension , 1)); 1761 EXPECT_EQ(true , message.GetExtension(unittest::packed_bool_extension , 1));
1700 EXPECT_EQ(unittest::FOREIGN_FOO, 1762 EXPECT_EQ(unittest::FOREIGN_FOO,
1701 message.GetExtension(unittest::packed_enum_extension, 1)); 1763 message.GetExtension(unittest::packed_enum_extension, 1));
1702 } 1764 }
1703 1765
1704 // ------------------------------------------------------------------- 1766 // -------------------------------------------------------------------
1705 1767
1706 void TestUtil::ExpectAllFieldsAndExtensionsInOrder(const string& serialized) { 1768 void TestUtil::ExpectAllFieldsAndExtensionsInOrder(const string& serialized) {
1707 // We set each field individually, serialize separately, and concatenate all 1769 // We set each field individually, serialize separately, and concatenate all
1708 // the strings in canonical order to determine the expected serialization. 1770 // the strings in canonical order to determine the expected serialization.
1709 string expected; 1771 string expected;
1710 unittest::TestFieldOrderings message; 1772 unittest::TestFieldOrderings message;
1711 message.set_my_int(1); // Field 1. 1773 message.set_my_int(1); // Field 1.
1712 message.AppendToString(&expected); 1774 message.AppendToString(&expected);
1713 message.Clear(); 1775 message.Clear();
1714 message.SetExtension(unittest::my_extension_int, 23); // Field 5. 1776 message.SetExtension(unittest::my_extension_int, 23); // Field 5.
1715 message.AppendToString(&expected); 1777 message.AppendToString(&expected);
1716 message.Clear(); 1778 message.Clear();
1717 message.set_my_string("foo"); // Field 11. 1779 message.set_my_string("foo"); // Field 11.
1718 message.AppendToString(&expected); 1780 message.AppendToString(&expected);
1719 message.Clear(); 1781 message.Clear();
1720 message.SetExtension(unittest::my_extension_string, "bar"); // Field 50. 1782 message.SetExtension(unittest::my_extension_string, "bar"); // Field 50.
1721 message.AppendToString(&expected); 1783 message.AppendToString(&expected);
1722 message.Clear(); 1784 message.Clear();
1723 message.set_my_float(1.0); // Field 101. 1785 message.set_my_float(1.0); // Field 101.
1724 message.AppendToString(&expected); 1786 message.AppendToString(&expected);
1725 message.Clear(); 1787 message.Clear();
1726 1788
1727 // We don't EXPECT_EQ() since we don't want to print raw bytes to stdout. 1789 // We don't EXPECT_EQ() since we don't want to print raw bytes to stdout.
1728 EXPECT_TRUE(serialized == expected); 1790 EXPECT_TRUE(serialized == expected);
1729 } 1791 }
1730 1792
1731 void TestUtil::ExpectLastRepeatedsRemoved( 1793 void TestUtil::ExpectLastRepeatedsRemoved(
1732 const unittest::TestAllTypes& message) { 1794 const unittest::TestAllTypes& message) {
1733 ASSERT_EQ(1, message.repeated_int32_size ()); 1795 ASSERT_EQ(1, message.repeated_int32_size ());
1734 ASSERT_EQ(1, message.repeated_int64_size ()); 1796 ASSERT_EQ(1, message.repeated_int64_size ());
1735 ASSERT_EQ(1, message.repeated_uint32_size ()); 1797 ASSERT_EQ(1, message.repeated_uint32_size ());
1736 ASSERT_EQ(1, message.repeated_uint64_size ()); 1798 ASSERT_EQ(1, message.repeated_uint64_size ());
1737 ASSERT_EQ(1, message.repeated_sint32_size ()); 1799 ASSERT_EQ(1, message.repeated_sint32_size ());
1738 ASSERT_EQ(1, message.repeated_sint64_size ()); 1800 ASSERT_EQ(1, message.repeated_sint64_size ());
1739 ASSERT_EQ(1, message.repeated_fixed32_size ()); 1801 ASSERT_EQ(1, message.repeated_fixed32_size ());
1740 ASSERT_EQ(1, message.repeated_fixed64_size ()); 1802 ASSERT_EQ(1, message.repeated_fixed64_size ());
1741 ASSERT_EQ(1, message.repeated_sfixed32_size()); 1803 ASSERT_EQ(1, message.repeated_sfixed32_size());
1742 ASSERT_EQ(1, message.repeated_sfixed64_size()); 1804 ASSERT_EQ(1, message.repeated_sfixed64_size());
1743 ASSERT_EQ(1, message.repeated_float_size ()); 1805 ASSERT_EQ(1, message.repeated_float_size ());
1744 ASSERT_EQ(1, message.repeated_double_size ()); 1806 ASSERT_EQ(1, message.repeated_double_size ());
1745 ASSERT_EQ(1, message.repeated_bool_size ()); 1807 ASSERT_EQ(1, message.repeated_bool_size ());
1746 ASSERT_EQ(1, message.repeated_string_size ()); 1808 ASSERT_EQ(1, message.repeated_string_size ());
1747 ASSERT_EQ(1, message.repeated_bytes_size ()); 1809 ASSERT_EQ(1, message.repeated_bytes_size ());
1748 1810
1749 ASSERT_EQ(1, message.repeatedgroup_size ()); 1811 ASSERT_EQ(1, message.repeatedgroup_size ());
1750 ASSERT_EQ(1, message.repeated_nested_message_size ()); 1812 ASSERT_EQ(1, message.repeated_nested_message_size ());
1751 ASSERT_EQ(1, message.repeated_foreign_message_size()); 1813 ASSERT_EQ(1, message.repeated_foreign_message_size());
1814 ASSERT_EQ(1, message.repeated_import_message_size ());
1752 ASSERT_EQ(1, message.repeated_import_message_size ()); 1815 ASSERT_EQ(1, message.repeated_import_message_size ());
1753 ASSERT_EQ(1, message.repeated_nested_enum_size ()); 1816 ASSERT_EQ(1, message.repeated_nested_enum_size ());
1754 ASSERT_EQ(1, message.repeated_foreign_enum_size ()); 1817 ASSERT_EQ(1, message.repeated_foreign_enum_size ());
1755 ASSERT_EQ(1, message.repeated_import_enum_size ()); 1818 ASSERT_EQ(1, message.repeated_import_enum_size ());
1756 1819
1757 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS 1820 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
1758 ASSERT_EQ(1, message.repeated_string_piece_size()); 1821 ASSERT_EQ(1, message.repeated_string_piece_size());
1759 ASSERT_EQ(1, message.repeated_cord_size()); 1822 ASSERT_EQ(1, message.repeated_cord_size());
1760 #endif 1823 #endif
1761 1824
1762 // Test that the remaining element is the correct one. 1825 // Test that the remaining element is the correct one.
1763 EXPECT_EQ(201 , message.repeated_int32 (0)); 1826 EXPECT_EQ(201 , message.repeated_int32 (0));
1764 EXPECT_EQ(202 , message.repeated_int64 (0)); 1827 EXPECT_EQ(202 , message.repeated_int64 (0));
1765 EXPECT_EQ(203 , message.repeated_uint32 (0)); 1828 EXPECT_EQ(203 , message.repeated_uint32 (0));
1766 EXPECT_EQ(204 , message.repeated_uint64 (0)); 1829 EXPECT_EQ(204 , message.repeated_uint64 (0));
1767 EXPECT_EQ(205 , message.repeated_sint32 (0)); 1830 EXPECT_EQ(205 , message.repeated_sint32 (0));
1768 EXPECT_EQ(206 , message.repeated_sint64 (0)); 1831 EXPECT_EQ(206 , message.repeated_sint64 (0));
1769 EXPECT_EQ(207 , message.repeated_fixed32 (0)); 1832 EXPECT_EQ(207 , message.repeated_fixed32 (0));
1770 EXPECT_EQ(208 , message.repeated_fixed64 (0)); 1833 EXPECT_EQ(208 , message.repeated_fixed64 (0));
1771 EXPECT_EQ(209 , message.repeated_sfixed32(0)); 1834 EXPECT_EQ(209 , message.repeated_sfixed32(0));
1772 EXPECT_EQ(210 , message.repeated_sfixed64(0)); 1835 EXPECT_EQ(210 , message.repeated_sfixed64(0));
1773 EXPECT_EQ(211 , message.repeated_float (0)); 1836 EXPECT_EQ(211 , message.repeated_float (0));
1774 EXPECT_EQ(212 , message.repeated_double (0)); 1837 EXPECT_EQ(212 , message.repeated_double (0));
1775 EXPECT_EQ(true , message.repeated_bool (0)); 1838 EXPECT_EQ(true , message.repeated_bool (0));
1776 EXPECT_EQ("215", message.repeated_string (0)); 1839 EXPECT_EQ("215", message.repeated_string (0));
1777 EXPECT_EQ("216", message.repeated_bytes (0)); 1840 EXPECT_EQ("216", message.repeated_bytes (0));
1778 1841
1779 EXPECT_EQ(217, message.repeatedgroup (0).a()); 1842 EXPECT_EQ(217, message.repeatedgroup (0).a());
1780 EXPECT_EQ(218, message.repeated_nested_message (0).bb()); 1843 EXPECT_EQ(218, message.repeated_nested_message (0).bb());
1781 EXPECT_EQ(219, message.repeated_foreign_message(0).c()); 1844 EXPECT_EQ(219, message.repeated_foreign_message(0).c());
1782 EXPECT_EQ(220, message.repeated_import_message (0).d()); 1845 EXPECT_EQ(220, message.repeated_import_message (0).d());
1846 EXPECT_EQ(220, message.repeated_import_message (0).d());
1783 1847
1784 EXPECT_EQ(unittest::TestAllTypes::BAR, message.repeated_nested_enum (0)); 1848 EXPECT_EQ(unittest::TestAllTypes::BAR, message.repeated_nested_enum (0));
1785 EXPECT_EQ(unittest::FOREIGN_BAR , message.repeated_foreign_enum(0)); 1849 EXPECT_EQ(unittest::FOREIGN_BAR , message.repeated_foreign_enum(0));
1786 EXPECT_EQ(unittest_import::IMPORT_BAR, message.repeated_import_enum (0)); 1850 EXPECT_EQ(unittest_import::IMPORT_BAR, message.repeated_import_enum (0));
1787 } 1851 }
1788 1852
1789 void TestUtil::ExpectLastRepeatedExtensionsRemoved( 1853 void TestUtil::ExpectLastRepeatedExtensionsRemoved(
1790 const unittest::TestAllExtensions& message) { 1854 const unittest::TestAllExtensions& message) {
1791 1855
1792 // Test that one element was removed. 1856 // Test that one element was removed.
1793 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_int32_extension )); 1857 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_int32_extension ));
1794 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_int64_extension )); 1858 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_int64_extension ));
1795 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_uint32_extension )); 1859 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_uint32_extension ));
1796 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_uint64_extension )); 1860 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_uint64_extension ));
1797 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_sint32_extension )); 1861 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_sint32_extension ));
1798 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_sint64_extension )); 1862 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_sint64_extension ));
1799 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_fixed32_extension )); 1863 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_fixed32_extension ));
1800 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_fixed64_extension )); 1864 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_fixed64_extension ));
1801 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_sfixed32_extension)); 1865 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_sfixed32_extension));
1802 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_sfixed64_extension)); 1866 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_sfixed64_extension));
1803 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_float_extension )); 1867 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_float_extension ));
1804 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_double_extension )); 1868 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_double_extension ));
1805 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_bool_extension )); 1869 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_bool_extension ));
1806 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_string_extension )); 1870 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_string_extension ));
1807 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_bytes_extension )); 1871 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_bytes_extension ));
1808 1872
1809 ASSERT_EQ(1, message.ExtensionSize(unittest::repeatedgroup_extension )); 1873 ASSERT_EQ(1, message.ExtensionSize(unittest::repeatedgroup_extension ));
1810 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_nested_message_extension )); 1874 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_nested_message_extension ));
1811 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_foreign_message_extension)); 1875 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_foreign_message_extension));
1812 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_import_message_extension )); 1876 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_import_message_extension ));
1877 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_lazy_message_extension ));
1813 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_nested_enum_extension )); 1878 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_nested_enum_extension ));
1814 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_foreign_enum_extension )); 1879 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_foreign_enum_extension ));
1815 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_import_enum_extension )); 1880 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_import_enum_extension ));
1816 1881
1817 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_string_piece_extension)); 1882 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_string_piece_extension));
1818 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_cord_extension)); 1883 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_cord_extension));
1819 1884
1820 // Test that the remaining element is the correct one. 1885 // Test that the remaining element is the correct one.
1821 EXPECT_EQ(201 , message.GetExtension(unittest::repeated_int32_extension , 0)); 1886 EXPECT_EQ(201 , message.GetExtension(unittest::repeated_int32_extension , 0));
1822 EXPECT_EQ(202 , message.GetExtension(unittest::repeated_int64_extension , 0)); 1887 EXPECT_EQ(202 , message.GetExtension(unittest::repeated_int64_extension , 0));
1823 EXPECT_EQ(203 , message.GetExtension(unittest::repeated_uint32_extension , 0)); 1888 EXPECT_EQ(203 , message.GetExtension(unittest::repeated_uint32_extension , 0));
1824 EXPECT_EQ(204 , message.GetExtension(unittest::repeated_uint64_extension , 0)); 1889 EXPECT_EQ(204 , message.GetExtension(unittest::repeated_uint64_extension , 0));
1825 EXPECT_EQ(205 , message.GetExtension(unittest::repeated_sint32_extension , 0)); 1890 EXPECT_EQ(205 , message.GetExtension(unittest::repeated_sint32_extension , 0));
1826 EXPECT_EQ(206 , message.GetExtension(unittest::repeated_sint64_extension , 0)); 1891 EXPECT_EQ(206 , message.GetExtension(unittest::repeated_sint64_extension , 0));
1827 EXPECT_EQ(207 , message.GetExtension(unittest::repeated_fixed32_extension , 0)); 1892 EXPECT_EQ(207 , message.GetExtension(unittest::repeated_fixed32_extension , 0));
1828 EXPECT_EQ(208 , message.GetExtension(unittest::repeated_fixed64_extension , 0)); 1893 EXPECT_EQ(208 , message.GetExtension(unittest::repeated_fixed64_extension , 0));
1829 EXPECT_EQ(209 , message.GetExtension(unittest::repeated_sfixed32_extension, 0)); 1894 EXPECT_EQ(209 , message.GetExtension(unittest::repeated_sfixed32_extension, 0));
1830 EXPECT_EQ(210 , message.GetExtension(unittest::repeated_sfixed64_extension, 0)); 1895 EXPECT_EQ(210 , message.GetExtension(unittest::repeated_sfixed64_extension, 0));
1831 EXPECT_EQ(211 , message.GetExtension(unittest::repeated_float_extension , 0)); 1896 EXPECT_EQ(211 , message.GetExtension(unittest::repeated_float_extension , 0));
1832 EXPECT_EQ(212 , message.GetExtension(unittest::repeated_double_extension , 0)); 1897 EXPECT_EQ(212 , message.GetExtension(unittest::repeated_double_extension , 0));
1833 EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension , 0)); 1898 EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension , 0));
1834 EXPECT_EQ("215", message.GetExtension(unittest::repeated_string_extension , 0)); 1899 EXPECT_EQ("215", message.GetExtension(unittest::repeated_string_extension , 0));
1835 EXPECT_EQ("216", message.GetExtension(unittest::repeated_bytes_extension , 0)); 1900 EXPECT_EQ("216", message.GetExtension(unittest::repeated_bytes_extension , 0));
1836 1901
1837 EXPECT_EQ(217, message.GetExtension(unittest::repeatedgroup_extension , 0).a()); 1902 EXPECT_EQ(217, message.GetExtension(unittest::repeatedgroup_extension , 0).a());
1838 EXPECT_EQ(218, message.GetExtension(unittest::repeated_nested_message_extension , 0).bb()); 1903 EXPECT_EQ(218, message.GetExtension(unittest::repeated_nested_message_extension , 0).bb());
1839 EXPECT_EQ(219, message.GetExtension(unittest::repeated_foreign_message_extension, 0).c()); 1904 EXPECT_EQ(219, message.GetExtension(unittest::repeated_foreign_message_extension, 0).c());
1840 EXPECT_EQ(220, message.GetExtension(unittest::repeated_import_message_extension , 0).d()); 1905 EXPECT_EQ(220, message.GetExtension(unittest::repeated_import_message_extension , 0).d());
1906 EXPECT_EQ(227, message.GetExtension(unittest::repeated_lazy_message_extension , 0).bb());
1841 1907
1842 EXPECT_EQ(unittest::TestAllTypes::BAR, message.GetExtension(unittest::repeated_nested_enum_extension , 0)); 1908 EXPECT_EQ(unittest::TestAllTypes::BAR, message.GetExtension(unittest::repeated_nested_enum_extension , 0));
1843 EXPECT_EQ(unittest::FOREIGN_BAR , message.GetExtension(unittest::repeated_foreign_enum_extension, 0)); 1909 EXPECT_EQ(unittest::FOREIGN_BAR , message.GetExtension(unittest::repeated_foreign_enum_extension, 0));
1844 EXPECT_EQ(unittest_import::IMPORT_BAR, message.GetExtension(unittest::repeated_import_enum_extension , 0)); 1910 EXPECT_EQ(unittest_import::IMPORT_BAR, message.GetExtension(unittest::repeated_import_enum_extension , 0));
1845 1911
1846 EXPECT_EQ("224", message.GetExtension(unittest::repeated_string_piece_extension, 0)); 1912 EXPECT_EQ("224", message.GetExtension(unittest::repeated_string_piece_extension, 0));
1847 EXPECT_EQ("225", message.GetExtension(unittest::repeated_cord_extension, 0)); 1913 EXPECT_EQ("225", message.GetExtension(unittest::repeated_cord_extension, 0));
1848 } 1914 }
1915
1916 void TestUtil::ExpectLastRepeatedsReleased(
1917 const unittest::TestAllTypes& message) {
1918 ASSERT_EQ(1, message.repeatedgroup_size ());
1919 ASSERT_EQ(1, message.repeated_nested_message_size ());
1920 ASSERT_EQ(1, message.repeated_foreign_message_size());
1921 ASSERT_EQ(1, message.repeated_import_message_size ());
1922 ASSERT_EQ(1, message.repeated_import_message_size ());
1923
1924 EXPECT_EQ(217, message.repeatedgroup (0).a());
1925 EXPECT_EQ(218, message.repeated_nested_message (0).bb());
1926 EXPECT_EQ(219, message.repeated_foreign_message(0).c());
1927 EXPECT_EQ(220, message.repeated_import_message (0).d());
1928 EXPECT_EQ(220, message.repeated_import_message (0).d());
1929 }
1930
1931 void TestUtil::ExpectLastRepeatedExtensionsReleased(
1932 const unittest::TestAllExtensions& message) {
1933 ASSERT_EQ(1, message.ExtensionSize(unittest::repeatedgroup_extension ));
1934 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_nested_message_extension ));
1935 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_foreign_message_extension));
1936 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_import_message_extension ));
1937 ASSERT_EQ(1, message.ExtensionSize(unittest::repeated_lazy_message_extension ));
1938
1939 EXPECT_EQ(217, message.GetExtension(unittest::repeatedgroup_extension , 0).a());
1940 EXPECT_EQ(218, message.GetExtension(unittest::repeated_nested_message_extension , 0).bb());
1941 EXPECT_EQ(219, message.GetExtension(unittest::repeated_foreign_message_extension, 0).c());
1942 EXPECT_EQ(220, message.GetExtension(unittest::repeated_import_message_extension , 0).d());
1943 EXPECT_EQ(227, message.GetExtension(unittest::repeated_lazy_message_extension , 0).bb());
1944 }
1849 1945
1850 void TestUtil::ExpectRepeatedsSwapped( 1946 void TestUtil::ExpectRepeatedsSwapped(
1851 const unittest::TestAllTypes& message) { 1947 const unittest::TestAllTypes& message) {
1852 ASSERT_EQ(2, message.repeated_int32_size ()); 1948 ASSERT_EQ(2, message.repeated_int32_size ());
1853 ASSERT_EQ(2, message.repeated_int64_size ()); 1949 ASSERT_EQ(2, message.repeated_int64_size ());
1854 ASSERT_EQ(2, message.repeated_uint32_size ()); 1950 ASSERT_EQ(2, message.repeated_uint32_size ());
1855 ASSERT_EQ(2, message.repeated_uint64_size ()); 1951 ASSERT_EQ(2, message.repeated_uint64_size ());
1856 ASSERT_EQ(2, message.repeated_sint32_size ()); 1952 ASSERT_EQ(2, message.repeated_sint32_size ());
1857 ASSERT_EQ(2, message.repeated_sint64_size ()); 1953 ASSERT_EQ(2, message.repeated_sint64_size ());
1858 ASSERT_EQ(2, message.repeated_fixed32_size ()); 1954 ASSERT_EQ(2, message.repeated_fixed32_size ());
1859 ASSERT_EQ(2, message.repeated_fixed64_size ()); 1955 ASSERT_EQ(2, message.repeated_fixed64_size ());
1860 ASSERT_EQ(2, message.repeated_sfixed32_size()); 1956 ASSERT_EQ(2, message.repeated_sfixed32_size());
1861 ASSERT_EQ(2, message.repeated_sfixed64_size()); 1957 ASSERT_EQ(2, message.repeated_sfixed64_size());
1862 ASSERT_EQ(2, message.repeated_float_size ()); 1958 ASSERT_EQ(2, message.repeated_float_size ());
1863 ASSERT_EQ(2, message.repeated_double_size ()); 1959 ASSERT_EQ(2, message.repeated_double_size ());
1864 ASSERT_EQ(2, message.repeated_bool_size ()); 1960 ASSERT_EQ(2, message.repeated_bool_size ());
1865 ASSERT_EQ(2, message.repeated_string_size ()); 1961 ASSERT_EQ(2, message.repeated_string_size ());
1866 ASSERT_EQ(2, message.repeated_bytes_size ()); 1962 ASSERT_EQ(2, message.repeated_bytes_size ());
1867 1963
1868 ASSERT_EQ(2, message.repeatedgroup_size ()); 1964 ASSERT_EQ(2, message.repeatedgroup_size ());
1869 ASSERT_EQ(2, message.repeated_nested_message_size ()); 1965 ASSERT_EQ(2, message.repeated_nested_message_size ());
1870 ASSERT_EQ(2, message.repeated_foreign_message_size()); 1966 ASSERT_EQ(2, message.repeated_foreign_message_size());
1967 ASSERT_EQ(2, message.repeated_import_message_size ());
1871 ASSERT_EQ(2, message.repeated_import_message_size ()); 1968 ASSERT_EQ(2, message.repeated_import_message_size ());
1872 ASSERT_EQ(2, message.repeated_nested_enum_size ()); 1969 ASSERT_EQ(2, message.repeated_nested_enum_size ());
1873 ASSERT_EQ(2, message.repeated_foreign_enum_size ()); 1970 ASSERT_EQ(2, message.repeated_foreign_enum_size ());
1874 ASSERT_EQ(2, message.repeated_import_enum_size ()); 1971 ASSERT_EQ(2, message.repeated_import_enum_size ());
1875 1972
1876 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS 1973 #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
1877 ASSERT_EQ(2, message.repeated_string_piece_size()); 1974 ASSERT_EQ(2, message.repeated_string_piece_size());
1878 ASSERT_EQ(2, message.repeated_cord_size()); 1975 ASSERT_EQ(2, message.repeated_cord_size());
1879 #endif 1976 #endif
1880 1977
1881 // Test that the first element and second element are flipped. 1978 // Test that the first element and second element are flipped.
1882 EXPECT_EQ(201 , message.repeated_int32 (1)); 1979 EXPECT_EQ(201 , message.repeated_int32 (1));
1883 EXPECT_EQ(202 , message.repeated_int64 (1)); 1980 EXPECT_EQ(202 , message.repeated_int64 (1));
1884 EXPECT_EQ(203 , message.repeated_uint32 (1)); 1981 EXPECT_EQ(203 , message.repeated_uint32 (1));
1885 EXPECT_EQ(204 , message.repeated_uint64 (1)); 1982 EXPECT_EQ(204 , message.repeated_uint64 (1));
1886 EXPECT_EQ(205 , message.repeated_sint32 (1)); 1983 EXPECT_EQ(205 , message.repeated_sint32 (1));
1887 EXPECT_EQ(206 , message.repeated_sint64 (1)); 1984 EXPECT_EQ(206 , message.repeated_sint64 (1));
1888 EXPECT_EQ(207 , message.repeated_fixed32 (1)); 1985 EXPECT_EQ(207 , message.repeated_fixed32 (1));
1889 EXPECT_EQ(208 , message.repeated_fixed64 (1)); 1986 EXPECT_EQ(208 , message.repeated_fixed64 (1));
1890 EXPECT_EQ(209 , message.repeated_sfixed32(1)); 1987 EXPECT_EQ(209 , message.repeated_sfixed32(1));
1891 EXPECT_EQ(210 , message.repeated_sfixed64(1)); 1988 EXPECT_EQ(210 , message.repeated_sfixed64(1));
1892 EXPECT_EQ(211 , message.repeated_float (1)); 1989 EXPECT_EQ(211 , message.repeated_float (1));
1893 EXPECT_EQ(212 , message.repeated_double (1)); 1990 EXPECT_EQ(212 , message.repeated_double (1));
1894 EXPECT_EQ(true , message.repeated_bool (1)); 1991 EXPECT_EQ(true , message.repeated_bool (1));
1895 EXPECT_EQ("215", message.repeated_string (1)); 1992 EXPECT_EQ("215", message.repeated_string (1));
1896 EXPECT_EQ("216", message.repeated_bytes (1)); 1993 EXPECT_EQ("216", message.repeated_bytes (1));
1897 1994
1898 EXPECT_EQ(217, message.repeatedgroup (1).a()); 1995 EXPECT_EQ(217, message.repeatedgroup (1).a());
1899 EXPECT_EQ(218, message.repeated_nested_message (1).bb()); 1996 EXPECT_EQ(218, message.repeated_nested_message (1).bb());
1900 EXPECT_EQ(219, message.repeated_foreign_message(1).c()); 1997 EXPECT_EQ(219, message.repeated_foreign_message(1).c());
1901 EXPECT_EQ(220, message.repeated_import_message (1).d()); 1998 EXPECT_EQ(220, message.repeated_import_message (1).d());
1999 EXPECT_EQ(220, message.repeated_import_message (1).d());
1902 2000
1903 EXPECT_EQ(unittest::TestAllTypes::BAR, message.repeated_nested_enum (1)); 2001 EXPECT_EQ(unittest::TestAllTypes::BAR, message.repeated_nested_enum (1));
1904 EXPECT_EQ(unittest::FOREIGN_BAR , message.repeated_foreign_enum(1)); 2002 EXPECT_EQ(unittest::FOREIGN_BAR , message.repeated_foreign_enum(1));
1905 EXPECT_EQ(unittest_import::IMPORT_BAR, message.repeated_import_enum (1)); 2003 EXPECT_EQ(unittest_import::IMPORT_BAR, message.repeated_import_enum (1));
1906 2004
1907 EXPECT_EQ(301 , message.repeated_int32 (0)); 2005 EXPECT_EQ(301 , message.repeated_int32 (0));
1908 EXPECT_EQ(302 , message.repeated_int64 (0)); 2006 EXPECT_EQ(302 , message.repeated_int64 (0));
1909 EXPECT_EQ(303 , message.repeated_uint32 (0)); 2007 EXPECT_EQ(303 , message.repeated_uint32 (0));
1910 EXPECT_EQ(304 , message.repeated_uint64 (0)); 2008 EXPECT_EQ(304 , message.repeated_uint64 (0));
1911 EXPECT_EQ(305 , message.repeated_sint32 (0)); 2009 EXPECT_EQ(305 , message.repeated_sint32 (0));
1912 EXPECT_EQ(306 , message.repeated_sint64 (0)); 2010 EXPECT_EQ(306 , message.repeated_sint64 (0));
1913 EXPECT_EQ(307 , message.repeated_fixed32 (0)); 2011 EXPECT_EQ(307 , message.repeated_fixed32 (0));
1914 EXPECT_EQ(308 , message.repeated_fixed64 (0)); 2012 EXPECT_EQ(308 , message.repeated_fixed64 (0));
1915 EXPECT_EQ(309 , message.repeated_sfixed32(0)); 2013 EXPECT_EQ(309 , message.repeated_sfixed32(0));
1916 EXPECT_EQ(310 , message.repeated_sfixed64(0)); 2014 EXPECT_EQ(310 , message.repeated_sfixed64(0));
1917 EXPECT_EQ(311 , message.repeated_float (0)); 2015 EXPECT_EQ(311 , message.repeated_float (0));
1918 EXPECT_EQ(312 , message.repeated_double (0)); 2016 EXPECT_EQ(312 , message.repeated_double (0));
1919 EXPECT_EQ(false, message.repeated_bool (0)); 2017 EXPECT_EQ(false, message.repeated_bool (0));
1920 EXPECT_EQ("315", message.repeated_string (0)); 2018 EXPECT_EQ("315", message.repeated_string (0));
1921 EXPECT_EQ("316", message.repeated_bytes (0)); 2019 EXPECT_EQ("316", message.repeated_bytes (0));
1922 2020
1923 EXPECT_EQ(317, message.repeatedgroup (0).a()); 2021 EXPECT_EQ(317, message.repeatedgroup (0).a());
1924 EXPECT_EQ(318, message.repeated_nested_message (0).bb()); 2022 EXPECT_EQ(318, message.repeated_nested_message (0).bb());
1925 EXPECT_EQ(319, message.repeated_foreign_message(0).c()); 2023 EXPECT_EQ(319, message.repeated_foreign_message(0).c());
1926 EXPECT_EQ(320, message.repeated_import_message (0).d()); 2024 EXPECT_EQ(320, message.repeated_import_message (0).d());
2025 EXPECT_EQ(320, message.repeated_import_message (0).d());
1927 2026
1928 EXPECT_EQ(unittest::TestAllTypes::BAZ, message.repeated_nested_enum (0)); 2027 EXPECT_EQ(unittest::TestAllTypes::BAZ, message.repeated_nested_enum (0));
1929 EXPECT_EQ(unittest::FOREIGN_BAZ , message.repeated_foreign_enum(0)); 2028 EXPECT_EQ(unittest::FOREIGN_BAZ , message.repeated_foreign_enum(0));
1930 EXPECT_EQ(unittest_import::IMPORT_BAZ, message.repeated_import_enum (0)); 2029 EXPECT_EQ(unittest_import::IMPORT_BAZ, message.repeated_import_enum (0));
1931 } 2030 }
1932 2031
1933 void TestUtil::ExpectRepeatedExtensionsSwapped( 2032 void TestUtil::ExpectRepeatedExtensionsSwapped(
1934 const unittest::TestAllExtensions& message) { 2033 const unittest::TestAllExtensions& message) {
1935 2034
1936 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int32_extension )); 2035 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int32_extension ));
1937 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int64_extension )); 2036 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int64_extension ));
1938 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint32_extension )); 2037 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint32_extension ));
1939 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint64_extension )); 2038 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint64_extension ));
1940 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint32_extension )); 2039 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint32_extension ));
1941 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint64_extension )); 2040 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint64_extension ));
1942 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed32_extension )); 2041 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed32_extension ));
1943 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed64_extension )); 2042 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed64_extension ));
1944 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed32_extension)); 2043 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed32_extension));
1945 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed64_extension)); 2044 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed64_extension));
1946 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_float_extension )); 2045 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_float_extension ));
1947 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_double_extension )); 2046 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_double_extension ));
1948 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bool_extension )); 2047 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bool_extension ));
1949 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_extension )); 2048 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_extension ));
1950 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bytes_extension )); 2049 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bytes_extension ));
1951 2050
1952 ASSERT_EQ(2, message.ExtensionSize(unittest::repeatedgroup_extension )); 2051 ASSERT_EQ(2, message.ExtensionSize(unittest::repeatedgroup_extension ));
1953 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_message_extension )); 2052 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_message_extension ));
1954 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_message_extension)); 2053 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_message_extension));
1955 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_message_extension )); 2054 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_message_extension ));
2055 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_lazy_message_extension ));
1956 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_enum_extension )); 2056 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_enum_extension ));
1957 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_enum_extension )); 2057 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_enum_extension ));
1958 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_enum_extension )); 2058 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_enum_extension ));
1959 2059
1960 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_piece_extension)); 2060 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_piece_extension));
1961 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_cord_extension)); 2061 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_cord_extension));
1962 2062
1963 EXPECT_EQ(201 , message.GetExtension(unittest::repeated_int32_extension , 1)); 2063 EXPECT_EQ(201 , message.GetExtension(unittest::repeated_int32_extension , 1));
1964 EXPECT_EQ(202 , message.GetExtension(unittest::repeated_int64_extension , 1)); 2064 EXPECT_EQ(202 , message.GetExtension(unittest::repeated_int64_extension , 1));
1965 EXPECT_EQ(203 , message.GetExtension(unittest::repeated_uint32_extension , 1)); 2065 EXPECT_EQ(203 , message.GetExtension(unittest::repeated_uint32_extension , 1));
1966 EXPECT_EQ(204 , message.GetExtension(unittest::repeated_uint64_extension , 1)); 2066 EXPECT_EQ(204 , message.GetExtension(unittest::repeated_uint64_extension , 1));
1967 EXPECT_EQ(205 , message.GetExtension(unittest::repeated_sint32_extension , 1)); 2067 EXPECT_EQ(205 , message.GetExtension(unittest::repeated_sint32_extension , 1));
1968 EXPECT_EQ(206 , message.GetExtension(unittest::repeated_sint64_extension , 1)); 2068 EXPECT_EQ(206 , message.GetExtension(unittest::repeated_sint64_extension , 1));
1969 EXPECT_EQ(207 , message.GetExtension(unittest::repeated_fixed32_extension , 1)); 2069 EXPECT_EQ(207 , message.GetExtension(unittest::repeated_fixed32_extension , 1));
1970 EXPECT_EQ(208 , message.GetExtension(unittest::repeated_fixed64_extension , 1)); 2070 EXPECT_EQ(208 , message.GetExtension(unittest::repeated_fixed64_extension , 1));
1971 EXPECT_EQ(209 , message.GetExtension(unittest::repeated_sfixed32_extension, 1)); 2071 EXPECT_EQ(209 , message.GetExtension(unittest::repeated_sfixed32_extension, 1));
1972 EXPECT_EQ(210 , message.GetExtension(unittest::repeated_sfixed64_extension, 1)); 2072 EXPECT_EQ(210 , message.GetExtension(unittest::repeated_sfixed64_extension, 1));
1973 EXPECT_EQ(211 , message.GetExtension(unittest::repeated_float_extension , 1)); 2073 EXPECT_EQ(211 , message.GetExtension(unittest::repeated_float_extension , 1));
1974 EXPECT_EQ(212 , message.GetExtension(unittest::repeated_double_extension , 1)); 2074 EXPECT_EQ(212 , message.GetExtension(unittest::repeated_double_extension , 1));
1975 EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension , 1)); 2075 EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension , 1));
1976 EXPECT_EQ("215", message.GetExtension(unittest::repeated_string_extension , 1)); 2076 EXPECT_EQ("215", message.GetExtension(unittest::repeated_string_extension , 1));
1977 EXPECT_EQ("216", message.GetExtension(unittest::repeated_bytes_extension , 1)); 2077 EXPECT_EQ("216", message.GetExtension(unittest::repeated_bytes_extension , 1));
1978 2078
1979 EXPECT_EQ(217, message.GetExtension(unittest::repeatedgroup_extension , 1).a()); 2079 EXPECT_EQ(217, message.GetExtension(unittest::repeatedgroup_extension , 1).a());
1980 EXPECT_EQ(218, message.GetExtension(unittest::repeated_nested_message_extension , 1).bb()); 2080 EXPECT_EQ(218, message.GetExtension(unittest::repeated_nested_message_extension , 1).bb());
1981 EXPECT_EQ(219, message.GetExtension(unittest::repeated_foreign_message_extension, 1).c()); 2081 EXPECT_EQ(219, message.GetExtension(unittest::repeated_foreign_message_extension, 1).c());
1982 EXPECT_EQ(220, message.GetExtension(unittest::repeated_import_message_extension , 1).d()); 2082 EXPECT_EQ(220, message.GetExtension(unittest::repeated_import_message_extension , 1).d());
2083 EXPECT_EQ(227, message.GetExtension(unittest::repeated_lazy_message_extension , 1).bb());
1983 2084
1984 EXPECT_EQ(unittest::TestAllTypes::BAR, message.GetExtension(unittest::repeated_nested_enum_extension , 1)); 2085 EXPECT_EQ(unittest::TestAllTypes::BAR, message.GetExtension(unittest::repeated_nested_enum_extension , 1));
1985 EXPECT_EQ(unittest::FOREIGN_BAR , message.GetExtension(unittest::repeated_foreign_enum_extension, 1)); 2086 EXPECT_EQ(unittest::FOREIGN_BAR , message.GetExtension(unittest::repeated_foreign_enum_extension, 1));
1986 EXPECT_EQ(unittest_import::IMPORT_BAR, message.GetExtension(unittest::repeated_import_enum_extension , 1)); 2087 EXPECT_EQ(unittest_import::IMPORT_BAR, message.GetExtension(unittest::repeated_import_enum_extension , 1));
1987 2088
1988 EXPECT_EQ("224", message.GetExtension(unittest::repeated_string_piece_extension, 1)); 2089 EXPECT_EQ("224", message.GetExtension(unittest::repeated_string_piece_extension, 1));
1989 EXPECT_EQ("225", message.GetExtension(unittest::repeated_cord_extension, 1)); 2090 EXPECT_EQ("225", message.GetExtension(unittest::repeated_cord_extension, 1));
1990 2091
1991 EXPECT_EQ(301 , message.GetExtension(unittest::repeated_int32_extension , 0)); 2092 EXPECT_EQ(301 , message.GetExtension(unittest::repeated_int32_extension , 0));
1992 EXPECT_EQ(302 , message.GetExtension(unittest::repeated_int64_extension , 0)); 2093 EXPECT_EQ(302 , message.GetExtension(unittest::repeated_int64_extension , 0));
1993 EXPECT_EQ(303 , message.GetExtension(unittest::repeated_uint32_extension , 0)); 2094 EXPECT_EQ(303 , message.GetExtension(unittest::repeated_uint32_extension , 0));
1994 EXPECT_EQ(304 , message.GetExtension(unittest::repeated_uint64_extension , 0)); 2095 EXPECT_EQ(304 , message.GetExtension(unittest::repeated_uint64_extension , 0));
1995 EXPECT_EQ(305 , message.GetExtension(unittest::repeated_sint32_extension , 0)); 2096 EXPECT_EQ(305 , message.GetExtension(unittest::repeated_sint32_extension , 0));
1996 EXPECT_EQ(306 , message.GetExtension(unittest::repeated_sint64_extension , 0)); 2097 EXPECT_EQ(306 , message.GetExtension(unittest::repeated_sint64_extension , 0));
1997 EXPECT_EQ(307 , message.GetExtension(unittest::repeated_fixed32_extension , 0)); 2098 EXPECT_EQ(307 , message.GetExtension(unittest::repeated_fixed32_extension , 0));
1998 EXPECT_EQ(308 , message.GetExtension(unittest::repeated_fixed64_extension , 0)); 2099 EXPECT_EQ(308 , message.GetExtension(unittest::repeated_fixed64_extension , 0));
1999 EXPECT_EQ(309 , message.GetExtension(unittest::repeated_sfixed32_extension, 0)); 2100 EXPECT_EQ(309 , message.GetExtension(unittest::repeated_sfixed32_extension, 0));
2000 EXPECT_EQ(310 , message.GetExtension(unittest::repeated_sfixed64_extension, 0)); 2101 EXPECT_EQ(310 , message.GetExtension(unittest::repeated_sfixed64_extension, 0));
2001 EXPECT_EQ(311 , message.GetExtension(unittest::repeated_float_extension , 0)); 2102 EXPECT_EQ(311 , message.GetExtension(unittest::repeated_float_extension , 0));
2002 EXPECT_EQ(312 , message.GetExtension(unittest::repeated_double_extension , 0)); 2103 EXPECT_EQ(312 , message.GetExtension(unittest::repeated_double_extension , 0));
2003 EXPECT_EQ(false, message.GetExtension(unittest::repeated_bool_extension , 0)); 2104 EXPECT_EQ(false, message.GetExtension(unittest::repeated_bool_extension , 0));
2004 EXPECT_EQ("315", message.GetExtension(unittest::repeated_string_extension , 0)); 2105 EXPECT_EQ("315", message.GetExtension(unittest::repeated_string_extension , 0));
2005 EXPECT_EQ("316", message.GetExtension(unittest::repeated_bytes_extension , 0)); 2106 EXPECT_EQ("316", message.GetExtension(unittest::repeated_bytes_extension , 0));
2006 2107
2007 EXPECT_EQ(317, message.GetExtension(unittest::repeatedgroup_extension , 0).a()); 2108 EXPECT_EQ(317, message.GetExtension(unittest::repeatedgroup_extension , 0).a());
2008 EXPECT_EQ(318, message.GetExtension(unittest::repeated_nested_message_extension , 0).bb()); 2109 EXPECT_EQ(318, message.GetExtension(unittest::repeated_nested_message_extension , 0).bb());
2009 EXPECT_EQ(319, message.GetExtension(unittest::repeated_foreign_message_extension, 0).c()); 2110 EXPECT_EQ(319, message.GetExtension(unittest::repeated_foreign_message_extension, 0).c());
2010 EXPECT_EQ(320, message.GetExtension(unittest::repeated_import_message_extension , 0).d()); 2111 EXPECT_EQ(320, message.GetExtension(unittest::repeated_import_message_extension , 0).d());
2112 EXPECT_EQ(327, message.GetExtension(unittest::repeated_lazy_message_extension , 0).bb());
2011 2113
2012 EXPECT_EQ(unittest::TestAllTypes::BAZ, message.GetExtension(unittest::repeated_nested_enum_extension , 0)); 2114 EXPECT_EQ(unittest::TestAllTypes::BAZ, message.GetExtension(unittest::repeated_nested_enum_extension , 0));
2013 EXPECT_EQ(unittest::FOREIGN_BAZ , message.GetExtension(unittest::repeated_foreign_enum_extension, 0)); 2115 EXPECT_EQ(unittest::FOREIGN_BAZ , message.GetExtension(unittest::repeated_foreign_enum_extension, 0));
2014 EXPECT_EQ(unittest_import::IMPORT_BAZ, message.GetExtension(unittest::repeated_import_enum_extension , 0)); 2116 EXPECT_EQ(unittest_import::IMPORT_BAZ, message.GetExtension(unittest::repeated_import_enum_extension , 0));
2015 2117
2016 EXPECT_EQ("324", message.GetExtension(unittest::repeated_string_piece_extension, 0)); 2118 EXPECT_EQ("324", message.GetExtension(unittest::repeated_string_piece_extension, 0));
2017 EXPECT_EQ("325", message.GetExtension(unittest::repeated_cord_extension, 0)); 2119 EXPECT_EQ("325", message.GetExtension(unittest::repeated_cord_extension, 0));
2018 } 2120 }
2019 2121
2020 // =================================================================== 2122 // ===================================================================
2021 2123
2022 TestUtil::ReflectionTester::ReflectionTester( 2124 TestUtil::ReflectionTester::ReflectionTester(
2023 const Descriptor* base_descriptor) 2125 const Descriptor* base_descriptor)
2024 : base_descriptor_(base_descriptor) { 2126 : base_descriptor_(base_descriptor) {
2025 2127
2026 const DescriptorPool* pool = base_descriptor->file()->pool(); 2128 const DescriptorPool* pool = base_descriptor->file()->pool();
2027 2129
2028 nested_b_ = 2130 nested_b_ =
2029 pool->FindFieldByName("protobuf_unittest.TestAllTypes.NestedMessage.bb"); 2131 pool->FindFieldByName("protobuf_unittest.TestAllTypes.NestedMessage.bb");
2030 foreign_c_ = 2132 foreign_c_ =
2031 pool->FindFieldByName("protobuf_unittest.ForeignMessage.c"); 2133 pool->FindFieldByName("protobuf_unittest.ForeignMessage.c");
2032 import_d_ = 2134 import_d_ =
2033 pool->FindFieldByName("protobuf_unittest_import.ImportMessage.d"); 2135 pool->FindFieldByName("protobuf_unittest_import.ImportMessage.d");
2136 import_e_ =
2137 pool->FindFieldByName("protobuf_unittest_import.PublicImportMessage.e");
2034 nested_foo_ = 2138 nested_foo_ =
2035 pool->FindEnumValueByName("protobuf_unittest.TestAllTypes.FOO"); 2139 pool->FindEnumValueByName("protobuf_unittest.TestAllTypes.FOO");
2036 nested_bar_ = 2140 nested_bar_ =
2037 pool->FindEnumValueByName("protobuf_unittest.TestAllTypes.BAR"); 2141 pool->FindEnumValueByName("protobuf_unittest.TestAllTypes.BAR");
2038 nested_baz_ = 2142 nested_baz_ =
2039 pool->FindEnumValueByName("protobuf_unittest.TestAllTypes.BAZ"); 2143 pool->FindEnumValueByName("protobuf_unittest.TestAllTypes.BAZ");
2040 foreign_foo_ = 2144 foreign_foo_ =
2041 pool->FindEnumValueByName("protobuf_unittest.FOREIGN_FOO"); 2145 pool->FindEnumValueByName("protobuf_unittest.FOREIGN_FOO");
2042 foreign_bar_ = 2146 foreign_bar_ =
2043 pool->FindEnumValueByName("protobuf_unittest.FOREIGN_BAR"); 2147 pool->FindEnumValueByName("protobuf_unittest.FOREIGN_BAR");
2044 foreign_baz_ = 2148 foreign_baz_ =
2045 pool->FindEnumValueByName("protobuf_unittest.FOREIGN_BAZ"); 2149 pool->FindEnumValueByName("protobuf_unittest.FOREIGN_BAZ");
2046 import_foo_ = 2150 import_foo_ =
2047 pool->FindEnumValueByName("protobuf_unittest_import.IMPORT_FOO"); 2151 pool->FindEnumValueByName("protobuf_unittest_import.IMPORT_FOO");
2048 import_bar_ = 2152 import_bar_ =
2049 pool->FindEnumValueByName("protobuf_unittest_import.IMPORT_BAR"); 2153 pool->FindEnumValueByName("protobuf_unittest_import.IMPORT_BAR");
2050 import_baz_ = 2154 import_baz_ =
2051 pool->FindEnumValueByName("protobuf_unittest_import.IMPORT_BAZ"); 2155 pool->FindEnumValueByName("protobuf_unittest_import.IMPORT_BAZ");
2052 2156
2053 if (base_descriptor_->name() == "TestAllExtensions") { 2157 if (base_descriptor_->name() == "TestAllExtensions") {
2054 group_a_ = 2158 group_a_ =
2055 pool->FindFieldByName("protobuf_unittest.OptionalGroup_extension.a"); 2159 pool->FindFieldByName("protobuf_unittest.OptionalGroup_extension.a");
2056 repeated_group_a_ = 2160 repeated_group_a_ =
2057 pool->FindFieldByName("protobuf_unittest.RepeatedGroup_extension.a"); 2161 pool->FindFieldByName("protobuf_unittest.RepeatedGroup_extension.a");
2058 } else { 2162 } else {
2059 group_a_ = 2163 group_a_ =
2060 pool->FindFieldByName("protobuf_unittest.TestAllTypes.OptionalGroup.a"); 2164 pool->FindFieldByName("protobuf_unittest.TestAllTypes.OptionalGroup.a");
2061 repeated_group_a_ = 2165 repeated_group_a_ =
2062 pool->FindFieldByName("protobuf_unittest.TestAllTypes.RepeatedGroup.a"); 2166 pool->FindFieldByName("protobuf_unittest.TestAllTypes.RepeatedGroup.a");
2063 } 2167 }
2064 2168
2065 EXPECT_TRUE(group_a_ != NULL); 2169 EXPECT_TRUE(group_a_ != NULL);
2066 EXPECT_TRUE(repeated_group_a_ != NULL); 2170 EXPECT_TRUE(repeated_group_a_ != NULL);
2067 EXPECT_TRUE(nested_b_ != NULL); 2171 EXPECT_TRUE(nested_b_ != NULL);
2068 EXPECT_TRUE(foreign_c_ != NULL); 2172 EXPECT_TRUE(foreign_c_ != NULL);
2069 EXPECT_TRUE(import_d_ != NULL); 2173 EXPECT_TRUE(import_d_ != NULL);
2174 EXPECT_TRUE(import_e_ != NULL);
2070 EXPECT_TRUE(nested_foo_ != NULL); 2175 EXPECT_TRUE(nested_foo_ != NULL);
2071 EXPECT_TRUE(nested_bar_ != NULL); 2176 EXPECT_TRUE(nested_bar_ != NULL);
2072 EXPECT_TRUE(nested_baz_ != NULL); 2177 EXPECT_TRUE(nested_baz_ != NULL);
2073 EXPECT_TRUE(foreign_foo_ != NULL); 2178 EXPECT_TRUE(foreign_foo_ != NULL);
2074 EXPECT_TRUE(foreign_bar_ != NULL); 2179 EXPECT_TRUE(foreign_bar_ != NULL);
2075 EXPECT_TRUE(foreign_baz_ != NULL); 2180 EXPECT_TRUE(foreign_baz_ != NULL);
2076 EXPECT_TRUE(import_foo_ != NULL); 2181 EXPECT_TRUE(import_foo_ != NULL);
2077 EXPECT_TRUE(import_bar_ != NULL); 2182 EXPECT_TRUE(import_bar_ != NULL);
2078 EXPECT_TRUE(import_baz_ != NULL); 2183 EXPECT_TRUE(import_baz_ != NULL);
2079 } 2184 }
2080 2185
2081 // Shorthand to get a FieldDescriptor for a field of unittest::TestAllTypes. 2186 // Shorthand to get a FieldDescriptor for a field of unittest::TestAllTypes.
2082 const FieldDescriptor* TestUtil::ReflectionTester::F(const string& name) { 2187 const FieldDescriptor* TestUtil::ReflectionTester::F(const string& name) {
2083 const FieldDescriptor* result = NULL; 2188 const FieldDescriptor* result = NULL;
2084 if (base_descriptor_->name() == "TestAllExtensions" || 2189 if (base_descriptor_->name() == "TestAllExtensions" ||
2085 base_descriptor_->name() == "TestPackedExtensions") { 2190 base_descriptor_->name() == "TestPackedExtensions") {
2086 result = base_descriptor_->file()->FindExtensionByName(name + "_extension"); 2191 result = base_descriptor_->file()->FindExtensionByName(name + "_extension");
2087 } else { 2192 } else {
2088 result = base_descriptor_->FindFieldByName(name); 2193 result = base_descriptor_->FindFieldByName(name);
2089 } 2194 }
2090 GOOGLE_CHECK(result != NULL); 2195 GOOGLE_CHECK(result != NULL);
2091 return result; 2196 return result;
2092 } 2197 }
2093 2198
2094 // ------------------------------------------------------------------- 2199 // -------------------------------------------------------------------
2095 2200
2096 void TestUtil::ReflectionTester::SetAllFieldsViaReflection(Message* message) { 2201 void TestUtil::ReflectionTester::SetAllFieldsViaReflection(Message* message) {
2097 const Reflection* reflection = message->GetReflection(); 2202 const Reflection* reflection = message->GetReflection();
2098 Message* sub_message; 2203 Message* sub_message;
2099 2204
2100 reflection->SetInt32 (message, F("optional_int32" ), 101); 2205 reflection->SetInt32 (message, F("optional_int32" ), 101);
2101 reflection->SetInt64 (message, F("optional_int64" ), 102); 2206 reflection->SetInt64 (message, F("optional_int64" ), 102);
2102 reflection->SetUInt32(message, F("optional_uint32" ), 103); 2207 reflection->SetUInt32(message, F("optional_uint32" ), 103);
2103 reflection->SetUInt64(message, F("optional_uint64" ), 104); 2208 reflection->SetUInt64(message, F("optional_uint64" ), 104);
2104 reflection->SetInt32 (message, F("optional_sint32" ), 105); 2209 reflection->SetInt32 (message, F("optional_sint32" ), 105);
2105 reflection->SetInt64 (message, F("optional_sint64" ), 106); 2210 reflection->SetInt64 (message, F("optional_sint64" ), 106);
2106 reflection->SetUInt32(message, F("optional_fixed32" ), 107); 2211 reflection->SetUInt32(message, F("optional_fixed32" ), 107);
2107 reflection->SetUInt64(message, F("optional_fixed64" ), 108); 2212 reflection->SetUInt64(message, F("optional_fixed64" ), 108);
2108 reflection->SetInt32 (message, F("optional_sfixed32"), 109); 2213 reflection->SetInt32 (message, F("optional_sfixed32"), 109);
2109 reflection->SetInt64 (message, F("optional_sfixed64"), 110); 2214 reflection->SetInt64 (message, F("optional_sfixed64"), 110);
2110 reflection->SetFloat (message, F("optional_float" ), 111); 2215 reflection->SetFloat (message, F("optional_float" ), 111);
2111 reflection->SetDouble(message, F("optional_double" ), 112); 2216 reflection->SetDouble(message, F("optional_double" ), 112);
2112 reflection->SetBool (message, F("optional_bool" ), true); 2217 reflection->SetBool (message, F("optional_bool" ), true);
2113 reflection->SetString(message, F("optional_string" ), "115"); 2218 reflection->SetString(message, F("optional_string" ), "115");
2114 reflection->SetString(message, F("optional_bytes" ), "116"); 2219 reflection->SetString(message, F("optional_bytes" ), "116");
2115 2220
2116 sub_message = reflection->MutableMessage(message, F("optionalgroup")); 2221 sub_message = reflection->MutableMessage(message, F("optionalgroup"));
2117 sub_message->GetReflection()->SetInt32(sub_message, group_a_, 117); 2222 sub_message->GetReflection()->SetInt32(sub_message, group_a_, 117);
2118 sub_message = reflection->MutableMessage(message, F("optional_nested_message")); 2223 sub_message = reflection->MutableMessage(message, F("optional_nested_message"));
2119 sub_message->GetReflection()->SetInt32(sub_message, nested_b_, 118); 2224 sub_message->GetReflection()->SetInt32(sub_message, nested_b_, 118);
2120 sub_message = reflection->MutableMessage(message, F("optional_foreign_message")); 2225 sub_message = reflection->MutableMessage(message, F("optional_foreign_message"));
2121 sub_message->GetReflection()->SetInt32(sub_message, foreign_c_, 119); 2226 sub_message->GetReflection()->SetInt32(sub_message, foreign_c_, 119);
2122 sub_message = reflection->MutableMessage(message, F("optional_import_message")); 2227 sub_message = reflection->MutableMessage(message, F("optional_import_message"));
2123 sub_message->GetReflection()->SetInt32(sub_message, import_d_, 120); 2228 sub_message->GetReflection()->SetInt32(sub_message, import_d_, 120);
2124 2229
2125 reflection->SetEnum(message, F("optional_nested_enum" ), nested_baz_); 2230 reflection->SetEnum(message, F("optional_nested_enum" ), nested_baz_);
2126 reflection->SetEnum(message, F("optional_foreign_enum"), foreign_baz_); 2231 reflection->SetEnum(message, F("optional_foreign_enum"), foreign_baz_);
2127 reflection->SetEnum(message, F("optional_import_enum" ), import_baz_); 2232 reflection->SetEnum(message, F("optional_import_enum" ), import_baz_);
2128 2233
2129 reflection->SetString(message, F("optional_string_piece"), "124"); 2234 reflection->SetString(message, F("optional_string_piece"), "124");
2130 reflection->SetString(message, F("optional_cord"), "125"); 2235 reflection->SetString(message, F("optional_cord"), "125");
2131 2236
2237 sub_message = reflection->MutableMessage(message, F("optional_public_import_message"));
2238 sub_message->GetReflection()->SetInt32(sub_message, import_e_, 126);
2239
2240 sub_message = reflection->MutableMessage(message, F("optional_lazy_message"));
2241 sub_message->GetReflection()->SetInt32(sub_message, nested_b_, 127);
2242
2132 // ----------------------------------------------------------------- 2243 // -----------------------------------------------------------------
2133 2244
2134 reflection->AddInt32 (message, F("repeated_int32" ), 201); 2245 reflection->AddInt32 (message, F("repeated_int32" ), 201);
2135 reflection->AddInt64 (message, F("repeated_int64" ), 202); 2246 reflection->AddInt64 (message, F("repeated_int64" ), 202);
2136 reflection->AddUInt32(message, F("repeated_uint32" ), 203); 2247 reflection->AddUInt32(message, F("repeated_uint32" ), 203);
2137 reflection->AddUInt64(message, F("repeated_uint64" ), 204); 2248 reflection->AddUInt64(message, F("repeated_uint64" ), 204);
2138 reflection->AddInt32 (message, F("repeated_sint32" ), 205); 2249 reflection->AddInt32 (message, F("repeated_sint32" ), 205);
2139 reflection->AddInt64 (message, F("repeated_sint64" ), 206); 2250 reflection->AddInt64 (message, F("repeated_sint64" ), 206);
2140 reflection->AddUInt32(message, F("repeated_fixed32" ), 207); 2251 reflection->AddUInt32(message, F("repeated_fixed32" ), 207);
2141 reflection->AddUInt64(message, F("repeated_fixed64" ), 208); 2252 reflection->AddUInt64(message, F("repeated_fixed64" ), 208);
2142 reflection->AddInt32 (message, F("repeated_sfixed32"), 209); 2253 reflection->AddInt32 (message, F("repeated_sfixed32"), 209);
2143 reflection->AddInt64 (message, F("repeated_sfixed64"), 210); 2254 reflection->AddInt64 (message, F("repeated_sfixed64"), 210);
2144 reflection->AddFloat (message, F("repeated_float" ), 211); 2255 reflection->AddFloat (message, F("repeated_float" ), 211);
2145 reflection->AddDouble(message, F("repeated_double" ), 212); 2256 reflection->AddDouble(message, F("repeated_double" ), 212);
2146 reflection->AddBool (message, F("repeated_bool" ), true); 2257 reflection->AddBool (message, F("repeated_bool" ), true);
2147 reflection->AddString(message, F("repeated_string" ), "215"); 2258 reflection->AddString(message, F("repeated_string" ), "215");
2148 reflection->AddString(message, F("repeated_bytes" ), "216"); 2259 reflection->AddString(message, F("repeated_bytes" ), "216");
2149 2260
2150 sub_message = reflection->AddMessage(message, F("repeatedgroup")); 2261 sub_message = reflection->AddMessage(message, F("repeatedgroup"));
2151 sub_message->GetReflection()->SetInt32(sub_message, repeated_group_a_, 217); 2262 sub_message->GetReflection()->SetInt32(sub_message, repeated_group_a_, 217);
2152 sub_message = reflection->AddMessage(message, F("repeated_nested_message")); 2263 sub_message = reflection->AddMessage(message, F("repeated_nested_message"));
2153 sub_message->GetReflection()->SetInt32(sub_message, nested_b_, 218); 2264 sub_message->GetReflection()->SetInt32(sub_message, nested_b_, 218);
2154 sub_message = reflection->AddMessage(message, F("repeated_foreign_message")); 2265 sub_message = reflection->AddMessage(message, F("repeated_foreign_message"));
2155 sub_message->GetReflection()->SetInt32(sub_message, foreign_c_, 219); 2266 sub_message->GetReflection()->SetInt32(sub_message, foreign_c_, 219);
2156 sub_message = reflection->AddMessage(message, F("repeated_import_message")); 2267 sub_message = reflection->AddMessage(message, F("repeated_import_message"));
2157 sub_message->GetReflection()->SetInt32(sub_message, import_d_, 220); 2268 sub_message->GetReflection()->SetInt32(sub_message, import_d_, 220);
2269 sub_message = reflection->AddMessage(message, F("repeated_lazy_message"));
2270 sub_message->GetReflection()->SetInt32(sub_message, nested_b_, 227);
2158 2271
2159 reflection->AddEnum(message, F("repeated_nested_enum" ), nested_bar_); 2272 reflection->AddEnum(message, F("repeated_nested_enum" ), nested_bar_);
2160 reflection->AddEnum(message, F("repeated_foreign_enum"), foreign_bar_); 2273 reflection->AddEnum(message, F("repeated_foreign_enum"), foreign_bar_);
2161 reflection->AddEnum(message, F("repeated_import_enum" ), import_bar_); 2274 reflection->AddEnum(message, F("repeated_import_enum" ), import_bar_);
2162 2275
2163 reflection->AddString(message, F("repeated_string_piece"), "224"); 2276 reflection->AddString(message, F("repeated_string_piece"), "224");
2164 reflection->AddString(message, F("repeated_cord"), "225"); 2277 reflection->AddString(message, F("repeated_cord"), "225");
2165 2278
2166 // Add a second one of each field. 2279 // Add a second one of each field.
2167 reflection->AddInt32 (message, F("repeated_int32" ), 301); 2280 reflection->AddInt32 (message, F("repeated_int32" ), 301);
2168 reflection->AddInt64 (message, F("repeated_int64" ), 302); 2281 reflection->AddInt64 (message, F("repeated_int64" ), 302);
2169 reflection->AddUInt32(message, F("repeated_uint32" ), 303); 2282 reflection->AddUInt32(message, F("repeated_uint32" ), 303);
2170 reflection->AddUInt64(message, F("repeated_uint64" ), 304); 2283 reflection->AddUInt64(message, F("repeated_uint64" ), 304);
2171 reflection->AddInt32 (message, F("repeated_sint32" ), 305); 2284 reflection->AddInt32 (message, F("repeated_sint32" ), 305);
2172 reflection->AddInt64 (message, F("repeated_sint64" ), 306); 2285 reflection->AddInt64 (message, F("repeated_sint64" ), 306);
2173 reflection->AddUInt32(message, F("repeated_fixed32" ), 307); 2286 reflection->AddUInt32(message, F("repeated_fixed32" ), 307);
2174 reflection->AddUInt64(message, F("repeated_fixed64" ), 308); 2287 reflection->AddUInt64(message, F("repeated_fixed64" ), 308);
2175 reflection->AddInt32 (message, F("repeated_sfixed32"), 309); 2288 reflection->AddInt32 (message, F("repeated_sfixed32"), 309);
2176 reflection->AddInt64 (message, F("repeated_sfixed64"), 310); 2289 reflection->AddInt64 (message, F("repeated_sfixed64"), 310);
2177 reflection->AddFloat (message, F("repeated_float" ), 311); 2290 reflection->AddFloat (message, F("repeated_float" ), 311);
2178 reflection->AddDouble(message, F("repeated_double" ), 312); 2291 reflection->AddDouble(message, F("repeated_double" ), 312);
2179 reflection->AddBool (message, F("repeated_bool" ), false); 2292 reflection->AddBool (message, F("repeated_bool" ), false);
2180 reflection->AddString(message, F("repeated_string" ), "315"); 2293 reflection->AddString(message, F("repeated_string" ), "315");
2181 reflection->AddString(message, F("repeated_bytes" ), "316"); 2294 reflection->AddString(message, F("repeated_bytes" ), "316");
2182 2295
2183 sub_message = reflection->AddMessage(message, F("repeatedgroup")); 2296 sub_message = reflection->AddMessage(message, F("repeatedgroup"));
2184 sub_message->GetReflection()->SetInt32(sub_message, repeated_group_a_, 317); 2297 sub_message->GetReflection()->SetInt32(sub_message, repeated_group_a_, 317);
2185 sub_message = reflection->AddMessage(message, F("repeated_nested_message")); 2298 sub_message = reflection->AddMessage(message, F("repeated_nested_message"));
2186 sub_message->GetReflection()->SetInt32(sub_message, nested_b_, 318); 2299 sub_message->GetReflection()->SetInt32(sub_message, nested_b_, 318);
2187 sub_message = reflection->AddMessage(message, F("repeated_foreign_message")); 2300 sub_message = reflection->AddMessage(message, F("repeated_foreign_message"));
2188 sub_message->GetReflection()->SetInt32(sub_message, foreign_c_, 319); 2301 sub_message->GetReflection()->SetInt32(sub_message, foreign_c_, 319);
2189 sub_message = reflection->AddMessage(message, F("repeated_import_message")); 2302 sub_message = reflection->AddMessage(message, F("repeated_import_message"));
2190 sub_message->GetReflection()->SetInt32(sub_message, import_d_, 320); 2303 sub_message->GetReflection()->SetInt32(sub_message, import_d_, 320);
2304 sub_message = reflection->AddMessage(message, F("repeated_lazy_message"));
2305 sub_message->GetReflection()->SetInt32(sub_message, nested_b_, 327);
2191 2306
2192 reflection->AddEnum(message, F("repeated_nested_enum" ), nested_baz_); 2307 reflection->AddEnum(message, F("repeated_nested_enum" ), nested_baz_);
2193 reflection->AddEnum(message, F("repeated_foreign_enum"), foreign_baz_); 2308 reflection->AddEnum(message, F("repeated_foreign_enum"), foreign_baz_);
2194 reflection->AddEnum(message, F("repeated_import_enum" ), import_baz_); 2309 reflection->AddEnum(message, F("repeated_import_enum" ), import_baz_);
2195 2310
2196 reflection->AddString(message, F("repeated_string_piece"), "324"); 2311 reflection->AddString(message, F("repeated_string_piece"), "324");
2197 reflection->AddString(message, F("repeated_cord"), "325"); 2312 reflection->AddString(message, F("repeated_cord"), "325");
2198 2313
2199 // ----------------------------------------------------------------- 2314 // -----------------------------------------------------------------
2200 2315
2201 reflection->SetInt32 (message, F("default_int32" ), 401); 2316 reflection->SetInt32 (message, F("default_int32" ), 401);
2202 reflection->SetInt64 (message, F("default_int64" ), 402); 2317 reflection->SetInt64 (message, F("default_int64" ), 402);
2203 reflection->SetUInt32(message, F("default_uint32" ), 403); 2318 reflection->SetUInt32(message, F("default_uint32" ), 403);
2204 reflection->SetUInt64(message, F("default_uint64" ), 404); 2319 reflection->SetUInt64(message, F("default_uint64" ), 404);
2205 reflection->SetInt32 (message, F("default_sint32" ), 405); 2320 reflection->SetInt32 (message, F("default_sint32" ), 405);
2206 reflection->SetInt64 (message, F("default_sint64" ), 406); 2321 reflection->SetInt64 (message, F("default_sint64" ), 406);
2207 reflection->SetUInt32(message, F("default_fixed32" ), 407); 2322 reflection->SetUInt32(message, F("default_fixed32" ), 407);
2208 reflection->SetUInt64(message, F("default_fixed64" ), 408); 2323 reflection->SetUInt64(message, F("default_fixed64" ), 408);
2209 reflection->SetInt32 (message, F("default_sfixed32"), 409); 2324 reflection->SetInt32 (message, F("default_sfixed32"), 409);
2210 reflection->SetInt64 (message, F("default_sfixed64"), 410); 2325 reflection->SetInt64 (message, F("default_sfixed64"), 410);
2211 reflection->SetFloat (message, F("default_float" ), 411); 2326 reflection->SetFloat (message, F("default_float" ), 411);
2212 reflection->SetDouble(message, F("default_double" ), 412); 2327 reflection->SetDouble(message, F("default_double" ), 412);
2213 reflection->SetBool (message, F("default_bool" ), false); 2328 reflection->SetBool (message, F("default_bool" ), false);
2214 reflection->SetString(message, F("default_string" ), "415"); 2329 reflection->SetString(message, F("default_string" ), "415");
2215 reflection->SetString(message, F("default_bytes" ), "416"); 2330 reflection->SetString(message, F("default_bytes" ), "416");
2216 2331
2217 reflection->SetEnum(message, F("default_nested_enum" ), nested_foo_); 2332 reflection->SetEnum(message, F("default_nested_enum" ), nested_foo_);
2218 reflection->SetEnum(message, F("default_foreign_enum"), foreign_foo_); 2333 reflection->SetEnum(message, F("default_foreign_enum"), foreign_foo_);
2219 reflection->SetEnum(message, F("default_import_enum" ), import_foo_); 2334 reflection->SetEnum(message, F("default_import_enum" ), import_foo_);
2220 2335
2221 reflection->SetString(message, F("default_string_piece"), "424"); 2336 reflection->SetString(message, F("default_string_piece"), "424");
2222 reflection->SetString(message, F("default_cord"), "425"); 2337 reflection->SetString(message, F("default_cord"), "425");
2223 } 2338 }
2224 2339
2225 void TestUtil::ReflectionTester::SetPackedFieldsViaReflection( 2340 void TestUtil::ReflectionTester::SetPackedFieldsViaReflection(
2226 Message* message) { 2341 Message* message) {
2227 const Reflection* reflection = message->GetReflection(); 2342 const Reflection* reflection = message->GetReflection();
2228 reflection->AddInt32 (message, F("packed_int32" ), 601); 2343 reflection->AddInt32 (message, F("packed_int32" ), 601);
2229 reflection->AddInt64 (message, F("packed_int64" ), 602); 2344 reflection->AddInt64 (message, F("packed_int64" ), 602);
2230 reflection->AddUInt32(message, F("packed_uint32" ), 603); 2345 reflection->AddUInt32(message, F("packed_uint32" ), 603);
2231 reflection->AddUInt64(message, F("packed_uint64" ), 604); 2346 reflection->AddUInt64(message, F("packed_uint64" ), 604);
2232 reflection->AddInt32 (message, F("packed_sint32" ), 605); 2347 reflection->AddInt32 (message, F("packed_sint32" ), 605);
2233 reflection->AddInt64 (message, F("packed_sint64" ), 606); 2348 reflection->AddInt64 (message, F("packed_sint64" ), 606);
2234 reflection->AddUInt32(message, F("packed_fixed32" ), 607); 2349 reflection->AddUInt32(message, F("packed_fixed32" ), 607);
2235 reflection->AddUInt64(message, F("packed_fixed64" ), 608); 2350 reflection->AddUInt64(message, F("packed_fixed64" ), 608);
2236 reflection->AddInt32 (message, F("packed_sfixed32"), 609); 2351 reflection->AddInt32 (message, F("packed_sfixed32"), 609);
2237 reflection->AddInt64 (message, F("packed_sfixed64"), 610); 2352 reflection->AddInt64 (message, F("packed_sfixed64"), 610);
2238 reflection->AddFloat (message, F("packed_float" ), 611); 2353 reflection->AddFloat (message, F("packed_float" ), 611);
2239 reflection->AddDouble(message, F("packed_double" ), 612); 2354 reflection->AddDouble(message, F("packed_double" ), 612);
2240 reflection->AddBool (message, F("packed_bool" ), true); 2355 reflection->AddBool (message, F("packed_bool" ), true);
2241 reflection->AddEnum (message, F("packed_enum" ), foreign_bar_); 2356 reflection->AddEnum (message, F("packed_enum" ), foreign_bar_);
2242 2357
2243 reflection->AddInt32 (message, F("packed_int32" ), 701); 2358 reflection->AddInt32 (message, F("packed_int32" ), 701);
2244 reflection->AddInt64 (message, F("packed_int64" ), 702); 2359 reflection->AddInt64 (message, F("packed_int64" ), 702);
2245 reflection->AddUInt32(message, F("packed_uint32" ), 703); 2360 reflection->AddUInt32(message, F("packed_uint32" ), 703);
2246 reflection->AddUInt64(message, F("packed_uint64" ), 704); 2361 reflection->AddUInt64(message, F("packed_uint64" ), 704);
2247 reflection->AddInt32 (message, F("packed_sint32" ), 705); 2362 reflection->AddInt32 (message, F("packed_sint32" ), 705);
2248 reflection->AddInt64 (message, F("packed_sint64" ), 706); 2363 reflection->AddInt64 (message, F("packed_sint64" ), 706);
2249 reflection->AddUInt32(message, F("packed_fixed32" ), 707); 2364 reflection->AddUInt32(message, F("packed_fixed32" ), 707);
2250 reflection->AddUInt64(message, F("packed_fixed64" ), 708); 2365 reflection->AddUInt64(message, F("packed_fixed64" ), 708);
2251 reflection->AddInt32 (message, F("packed_sfixed32"), 709); 2366 reflection->AddInt32 (message, F("packed_sfixed32"), 709);
2252 reflection->AddInt64 (message, F("packed_sfixed64"), 710); 2367 reflection->AddInt64 (message, F("packed_sfixed64"), 710);
2253 reflection->AddFloat (message, F("packed_float" ), 711); 2368 reflection->AddFloat (message, F("packed_float" ), 711);
2254 reflection->AddDouble(message, F("packed_double" ), 712); 2369 reflection->AddDouble(message, F("packed_double" ), 712);
2255 reflection->AddBool (message, F("packed_bool" ), false); 2370 reflection->AddBool (message, F("packed_bool" ), false);
2256 reflection->AddEnum (message, F("packed_enum" ), foreign_baz_); 2371 reflection->AddEnum (message, F("packed_enum" ), foreign_baz_);
2257 } 2372 }
2258 2373
2259 // ------------------------------------------------------------------- 2374 // -------------------------------------------------------------------
2260 2375
2261 void TestUtil::ReflectionTester::ExpectAllFieldsSetViaReflection( 2376 void TestUtil::ReflectionTester::ExpectAllFieldsSetViaReflection(
2262 const Message& message) { 2377 const Message& message) {
2263 // We have to split this into three function otherwise it creates a stack 2378 // We have to split this into three function otherwise it creates a stack
2264 // frame so large that it triggers a warning. 2379 // frame so large that it triggers a warning.
2265 ExpectAllFieldsSetViaReflection1(message); 2380 ExpectAllFieldsSetViaReflection1(message);
2266 ExpectAllFieldsSetViaReflection2(message); 2381 ExpectAllFieldsSetViaReflection2(message);
2267 ExpectAllFieldsSetViaReflection3(message); 2382 ExpectAllFieldsSetViaReflection3(message);
2268 } 2383 }
2269 2384
2270 void TestUtil::ReflectionTester::ExpectAllFieldsSetViaReflection1( 2385 void TestUtil::ReflectionTester::ExpectAllFieldsSetViaReflection1(
2271 const Message& message) { 2386 const Message& message) {
2272 const Reflection* reflection = message.GetReflection(); 2387 const Reflection* reflection = message.GetReflection();
2273 string scratch; 2388 string scratch;
2274 const Message* sub_message; 2389 const Message* sub_message;
2275 2390
2276 EXPECT_TRUE(reflection->HasField(message, F("optional_int32" ))); 2391 EXPECT_TRUE(reflection->HasField(message, F("optional_int32" )));
2277 EXPECT_TRUE(reflection->HasField(message, F("optional_int64" ))); 2392 EXPECT_TRUE(reflection->HasField(message, F("optional_int64" )));
2278 EXPECT_TRUE(reflection->HasField(message, F("optional_uint32" ))); 2393 EXPECT_TRUE(reflection->HasField(message, F("optional_uint32" )));
2279 EXPECT_TRUE(reflection->HasField(message, F("optional_uint64" ))); 2394 EXPECT_TRUE(reflection->HasField(message, F("optional_uint64" )));
2280 EXPECT_TRUE(reflection->HasField(message, F("optional_sint32" ))); 2395 EXPECT_TRUE(reflection->HasField(message, F("optional_sint32" )));
2281 EXPECT_TRUE(reflection->HasField(message, F("optional_sint64" ))); 2396 EXPECT_TRUE(reflection->HasField(message, F("optional_sint64" )));
2282 EXPECT_TRUE(reflection->HasField(message, F("optional_fixed32" ))); 2397 EXPECT_TRUE(reflection->HasField(message, F("optional_fixed32" )));
2283 EXPECT_TRUE(reflection->HasField(message, F("optional_fixed64" ))); 2398 EXPECT_TRUE(reflection->HasField(message, F("optional_fixed64" )));
2284 EXPECT_TRUE(reflection->HasField(message, F("optional_sfixed32"))); 2399 EXPECT_TRUE(reflection->HasField(message, F("optional_sfixed32")));
2285 EXPECT_TRUE(reflection->HasField(message, F("optional_sfixed64"))); 2400 EXPECT_TRUE(reflection->HasField(message, F("optional_sfixed64")));
2286 EXPECT_TRUE(reflection->HasField(message, F("optional_float" ))); 2401 EXPECT_TRUE(reflection->HasField(message, F("optional_float" )));
2287 EXPECT_TRUE(reflection->HasField(message, F("optional_double" ))); 2402 EXPECT_TRUE(reflection->HasField(message, F("optional_double" )));
2288 EXPECT_TRUE(reflection->HasField(message, F("optional_bool" ))); 2403 EXPECT_TRUE(reflection->HasField(message, F("optional_bool" )));
2289 EXPECT_TRUE(reflection->HasField(message, F("optional_string" ))); 2404 EXPECT_TRUE(reflection->HasField(message, F("optional_string" )));
2290 EXPECT_TRUE(reflection->HasField(message, F("optional_bytes" ))); 2405 EXPECT_TRUE(reflection->HasField(message, F("optional_bytes" )));
2291 2406
2292 EXPECT_TRUE(reflection->HasField(message, F("optionalgroup" ))); 2407 EXPECT_TRUE(reflection->HasField(message, F("optionalgroup" )));
2293 EXPECT_TRUE(reflection->HasField(message, F("optional_nested_message" ))); 2408 EXPECT_TRUE(reflection->HasField(message, F("optional_nested_message" )));
2294 EXPECT_TRUE(reflection->HasField(message, F("optional_foreign_message"))); 2409 EXPECT_TRUE(reflection->HasField(message, F("optional_foreign_message" )));
2295 EXPECT_TRUE(reflection->HasField(message, F("optional_import_message" ))); 2410 EXPECT_TRUE(reflection->HasField(message, F("optional_import_message" )));
2411 EXPECT_TRUE(reflection->HasField(message, F("optional_public_import_message")));
2412 EXPECT_TRUE(reflection->HasField(message, F("optional_lazy_message" )));
2296 2413
2297 sub_message = &reflection->GetMessage(message, F("optionalgroup")); 2414 sub_message = &reflection->GetMessage(message, F("optionalgroup"));
2298 EXPECT_TRUE(sub_message->GetReflection()->HasField(*sub_message, group_a_)); 2415 EXPECT_TRUE(sub_message->GetReflection()->HasField(*sub_message, group_a_));
2299 sub_message = &reflection->GetMessage(message, F("optional_nested_message")); 2416 sub_message = &reflection->GetMessage(message, F("optional_nested_message"));
2300 EXPECT_TRUE(sub_message->GetReflection()->HasField(*sub_message, nested_b_)); 2417 EXPECT_TRUE(sub_message->GetReflection()->HasField(*sub_message, nested_b_));
2301 sub_message = &reflection->GetMessage(message, F("optional_foreign_message")); 2418 sub_message = &reflection->GetMessage(message, F("optional_foreign_message"));
2302 EXPECT_TRUE(sub_message->GetReflection()->HasField(*sub_message, foreign_c_)); 2419 EXPECT_TRUE(sub_message->GetReflection()->HasField(*sub_message, foreign_c_));
2303 sub_message = &reflection->GetMessage(message, F("optional_import_message")); 2420 sub_message = &reflection->GetMessage(message, F("optional_import_message"));
2304 EXPECT_TRUE(sub_message->GetReflection()->HasField(*sub_message, import_d_)); 2421 EXPECT_TRUE(sub_message->GetReflection()->HasField(*sub_message, import_d_));
2422 sub_message = &reflection->GetMessage(message, F("optional_public_import_message"));
2423 EXPECT_TRUE(sub_message->GetReflection()->HasField(*sub_message, import_e_));
2424 sub_message = &reflection->GetMessage(message, F("optional_lazy_message"));
2425 EXPECT_TRUE(sub_message->GetReflection()->HasField(*sub_message, nested_b_));
2305 2426
2306 EXPECT_TRUE(reflection->HasField(message, F("optional_nested_enum" ))); 2427 EXPECT_TRUE(reflection->HasField(message, F("optional_nested_enum" )));
2307 EXPECT_TRUE(reflection->HasField(message, F("optional_foreign_enum"))); 2428 EXPECT_TRUE(reflection->HasField(message, F("optional_foreign_enum")));
2308 EXPECT_TRUE(reflection->HasField(message, F("optional_import_enum" ))); 2429 EXPECT_TRUE(reflection->HasField(message, F("optional_import_enum" )));
2309 2430
2310 EXPECT_TRUE(reflection->HasField(message, F("optional_string_piece"))); 2431 EXPECT_TRUE(reflection->HasField(message, F("optional_string_piece")));
2311 EXPECT_TRUE(reflection->HasField(message, F("optional_cord"))); 2432 EXPECT_TRUE(reflection->HasField(message, F("optional_cord")));
2312 2433
2313 EXPECT_EQ(101 , reflection->GetInt32 (message, F("optional_int32" ))); 2434 EXPECT_EQ(101 , reflection->GetInt32 (message, F("optional_int32" )));
2314 EXPECT_EQ(102 , reflection->GetInt64 (message, F("optional_int64" ))); 2435 EXPECT_EQ(102 , reflection->GetInt64 (message, F("optional_int64" )));
2315 EXPECT_EQ(103 , reflection->GetUInt32(message, F("optional_uint32" ))); 2436 EXPECT_EQ(103 , reflection->GetUInt32(message, F("optional_uint32" )));
2316 EXPECT_EQ(104 , reflection->GetUInt64(message, F("optional_uint64" ))); 2437 EXPECT_EQ(104 , reflection->GetUInt64(message, F("optional_uint64" )));
2317 EXPECT_EQ(105 , reflection->GetInt32 (message, F("optional_sint32" ))); 2438 EXPECT_EQ(105 , reflection->GetInt32 (message, F("optional_sint32" )));
2318 EXPECT_EQ(106 , reflection->GetInt64 (message, F("optional_sint64" ))); 2439 EXPECT_EQ(106 , reflection->GetInt64 (message, F("optional_sint64" )));
2319 EXPECT_EQ(107 , reflection->GetUInt32(message, F("optional_fixed32" ))); 2440 EXPECT_EQ(107 , reflection->GetUInt32(message, F("optional_fixed32" )));
2320 EXPECT_EQ(108 , reflection->GetUInt64(message, F("optional_fixed64" ))); 2441 EXPECT_EQ(108 , reflection->GetUInt64(message, F("optional_fixed64" )));
2321 EXPECT_EQ(109 , reflection->GetInt32 (message, F("optional_sfixed32"))); 2442 EXPECT_EQ(109 , reflection->GetInt32 (message, F("optional_sfixed32")));
2322 EXPECT_EQ(110 , reflection->GetInt64 (message, F("optional_sfixed64"))); 2443 EXPECT_EQ(110 , reflection->GetInt64 (message, F("optional_sfixed64")));
2323 EXPECT_EQ(111 , reflection->GetFloat (message, F("optional_float" ))); 2444 EXPECT_EQ(111 , reflection->GetFloat (message, F("optional_float" )));
2324 EXPECT_EQ(112 , reflection->GetDouble(message, F("optional_double" ))); 2445 EXPECT_EQ(112 , reflection->GetDouble(message, F("optional_double" )));
2325 EXPECT_EQ(true , reflection->GetBool (message, F("optional_bool" ))); 2446 EXPECT_EQ(true , reflection->GetBool (message, F("optional_bool" )));
2326 EXPECT_EQ("115", reflection->GetString(message, F("optional_string" ))); 2447 EXPECT_EQ("115", reflection->GetString(message, F("optional_string" )));
2327 EXPECT_EQ("116", reflection->GetString(message, F("optional_bytes" ))); 2448 EXPECT_EQ("116", reflection->GetString(message, F("optional_bytes" )));
2328 2449
2329 EXPECT_EQ("115", reflection->GetStringReference(message, F("optional_string"), &scratch)); 2450 EXPECT_EQ("115", reflection->GetStringReference(message, F("optional_string"), &scratch));
2330 EXPECT_EQ("116", reflection->GetStringReference(message, F("optional_bytes" ), &scratch)); 2451 EXPECT_EQ("116", reflection->GetStringReference(message, F("optional_bytes" ), &scratch));
2331 2452
2332 sub_message = &reflection->GetMessage(message, F("optionalgroup")); 2453 sub_message = &reflection->GetMessage(message, F("optionalgroup"));
2333 EXPECT_EQ(117, sub_message->GetReflection()->GetInt32(*sub_message, group_a_)); 2454 EXPECT_EQ(117, sub_message->GetReflection()->GetInt32(*sub_message, group_a_));
2334 sub_message = &reflection->GetMessage(message, F("optional_nested_message")); 2455 sub_message = &reflection->GetMessage(message, F("optional_nested_message"));
2335 EXPECT_EQ(118, sub_message->GetReflection()->GetInt32(*sub_message, nested_b_)); 2456 EXPECT_EQ(118, sub_message->GetReflection()->GetInt32(*sub_message, nested_b_));
2336 sub_message = &reflection->GetMessage(message, F("optional_foreign_message")); 2457 sub_message = &reflection->GetMessage(message, F("optional_foreign_message"));
2337 EXPECT_EQ(119, sub_message->GetReflection()->GetInt32(*sub_message, foreign_c_)); 2458 EXPECT_EQ(119, sub_message->GetReflection()->GetInt32(*sub_message, foreign_c_));
2338 sub_message = &reflection->GetMessage(message, F("optional_import_message")); 2459 sub_message = &reflection->GetMessage(message, F("optional_import_message"));
2339 EXPECT_EQ(120, sub_message->GetReflection()->GetInt32(*sub_message, import_d_)); 2460 EXPECT_EQ(120, sub_message->GetReflection()->GetInt32(*sub_message, import_d_));
2461 sub_message = &reflection->GetMessage(message, F("optional_public_import_message"));
2462 EXPECT_EQ(126, sub_message->GetReflection()->GetInt32(*sub_message, import_e_));
2463 sub_message = &reflection->GetMessage(message, F("optional_lazy_message"));
2464 EXPECT_EQ(127, sub_message->GetReflection()->GetInt32(*sub_message, nested_b_));
2340 2465
2341 EXPECT_EQ( nested_baz_, reflection->GetEnum(message, F("optional_nested_enum" ))); 2466 EXPECT_EQ( nested_baz_, reflection->GetEnum(message, F("optional_nested_enum" )));
2342 EXPECT_EQ(foreign_baz_, reflection->GetEnum(message, F("optional_foreign_enum"))); 2467 EXPECT_EQ(foreign_baz_, reflection->GetEnum(message, F("optional_foreign_enum")));
2343 EXPECT_EQ( import_baz_, reflection->GetEnum(message, F("optional_import_enum" ))); 2468 EXPECT_EQ( import_baz_, reflection->GetEnum(message, F("optional_import_enum" )));
2344 2469
2345 EXPECT_EQ("124", reflection->GetString(message, F("optional_string_piece"))); 2470 EXPECT_EQ("124", reflection->GetString(message, F("optional_string_piece")));
2346 EXPECT_EQ("124", reflection->GetStringReference(message, F("optional_string_piece"), &scratch)); 2471 EXPECT_EQ("124", reflection->GetStringReference(message, F("optional_string_piece"), &scratch));
2347 2472
2348 EXPECT_EQ("125", reflection->GetString(message, F("optional_cord"))); 2473 EXPECT_EQ("125", reflection->GetString(message, F("optional_cord")));
2349 EXPECT_EQ("125", reflection->GetStringReference(message, F("optional_cord"), &scratch)); 2474 EXPECT_EQ("125", reflection->GetStringReference(message, F("optional_cord"), &scratch));
2475
2350 } 2476 }
2351 2477
2352 void TestUtil::ReflectionTester::ExpectAllFieldsSetViaReflection2( 2478 void TestUtil::ReflectionTester::ExpectAllFieldsSetViaReflection2(
2353 const Message& message) { 2479 const Message& message) {
2354 const Reflection* reflection = message.GetReflection(); 2480 const Reflection* reflection = message.GetReflection();
2355 string scratch; 2481 string scratch;
2356 const Message* sub_message; 2482 const Message* sub_message;
2357 2483
2358 // ----------------------------------------------------------------- 2484 // -----------------------------------------------------------------
2359 2485
2360 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_int32" ))); 2486 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_int32" )));
2361 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_int64" ))); 2487 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_int64" )));
2362 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_uint32" ))); 2488 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_uint32" )));
2363 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_uint64" ))); 2489 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_uint64" )));
2364 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_sint32" ))); 2490 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_sint32" )));
2365 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_sint64" ))); 2491 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_sint64" )));
2366 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_fixed32" ))); 2492 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_fixed32" )));
2367 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_fixed64" ))); 2493 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_fixed64" )));
2368 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_sfixed32"))); 2494 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_sfixed32")));
2369 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_sfixed64"))); 2495 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_sfixed64")));
2370 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_float" ))); 2496 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_float" )));
2371 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_double" ))); 2497 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_double" )));
2372 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_bool" ))); 2498 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_bool" )));
2373 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_string" ))); 2499 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_string" )));
2374 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_bytes" ))); 2500 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_bytes" )));
2375 2501
2376 ASSERT_EQ(2, reflection->FieldSize(message, F("repeatedgroup" ))); 2502 ASSERT_EQ(2, reflection->FieldSize(message, F("repeatedgroup" )));
2377 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_nested_message" ))); 2503 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_nested_message" )));
2378 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_foreign_message"))); 2504 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_foreign_message")));
2379 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_import_message" ))); 2505 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_import_message" )));
2506 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_lazy_message" )));
2380 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_nested_enum" ))); 2507 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_nested_enum" )));
2381 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_foreign_enum" ))); 2508 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_foreign_enum" )));
2382 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_import_enum" ))); 2509 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_import_enum" )));
2383 2510
2384 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_string_piece"))); 2511 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_string_piece")));
2385 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_cord"))); 2512 ASSERT_EQ(2, reflection->FieldSize(message, F("repeated_cord")));
2386 2513
2387 EXPECT_EQ(201 , reflection->GetRepeatedInt32 (message, F("repeated_int32" ), 0)); 2514 EXPECT_EQ(201 , reflection->GetRepeatedInt32 (message, F("repeated_int32" ), 0));
2388 EXPECT_EQ(202 , reflection->GetRepeatedInt64 (message, F("repeated_int64" ), 0)); 2515 EXPECT_EQ(202 , reflection->GetRepeatedInt64 (message, F("repeated_int64" ), 0));
2389 EXPECT_EQ(203 , reflection->GetRepeatedUInt32(message, F("repeated_uint32" ), 0)); 2516 EXPECT_EQ(203 , reflection->GetRepeatedUInt32(message, F("repeated_uint32" ), 0));
2390 EXPECT_EQ(204 , reflection->GetRepeatedUInt64(message, F("repeated_uint64" ), 0)); 2517 EXPECT_EQ(204 , reflection->GetRepeatedUInt64(message, F("repeated_uint64" ), 0));
2391 EXPECT_EQ(205 , reflection->GetRepeatedInt32 (message, F("repeated_sint32" ), 0)); 2518 EXPECT_EQ(205 , reflection->GetRepeatedInt32 (message, F("repeated_sint32" ), 0));
2392 EXPECT_EQ(206 , reflection->GetRepeatedInt64 (message, F("repeated_sint64" ), 0)); 2519 EXPECT_EQ(206 , reflection->GetRepeatedInt64 (message, F("repeated_sint64" ), 0));
2393 EXPECT_EQ(207 , reflection->GetRepeatedUInt32(message, F("repeated_fixed32" ), 0)); 2520 EXPECT_EQ(207 , reflection->GetRepeatedUInt32(message, F("repeated_fixed32" ), 0));
2394 EXPECT_EQ(208 , reflection->GetRepeatedUInt64(message, F("repeated_fixed64" ), 0)); 2521 EXPECT_EQ(208 , reflection->GetRepeatedUInt64(message, F("repeated_fixed64" ), 0));
2395 EXPECT_EQ(209 , reflection->GetRepeatedInt32 (message, F("repeated_sfixed32"), 0)); 2522 EXPECT_EQ(209 , reflection->GetRepeatedInt32 (message, F("repeated_sfixed32"), 0));
2396 EXPECT_EQ(210 , reflection->GetRepeatedInt64 (message, F("repeated_sfixed64"), 0)); 2523 EXPECT_EQ(210 , reflection->GetRepeatedInt64 (message, F("repeated_sfixed64"), 0));
2397 EXPECT_EQ(211 , reflection->GetRepeatedFloat (message, F("repeated_float" ), 0)); 2524 EXPECT_EQ(211 , reflection->GetRepeatedFloat (message, F("repeated_float" ), 0));
2398 EXPECT_EQ(212 , reflection->GetRepeatedDouble(message, F("repeated_double" ), 0)); 2525 EXPECT_EQ(212 , reflection->GetRepeatedDouble(message, F("repeated_double" ), 0));
2399 EXPECT_EQ(true , reflection->GetRepeatedBool (message, F("repeated_bool" ), 0)); 2526 EXPECT_EQ(true , reflection->GetRepeatedBool (message, F("repeated_bool" ), 0));
2400 EXPECT_EQ("215", reflection->GetRepeatedString(message, F("repeated_string" ), 0)); 2527 EXPECT_EQ("215", reflection->GetRepeatedString(message, F("repeated_string" ), 0));
2401 EXPECT_EQ("216", reflection->GetRepeatedString(message, F("repeated_bytes" ), 0)); 2528 EXPECT_EQ("216", reflection->GetRepeatedString(message, F("repeated_bytes" ), 0));
2402 2529
2403 EXPECT_EQ("215", reflection->GetRepeatedStringReference(message, F("repeated_string"), 0, &scratch)); 2530 EXPECT_EQ("215", reflection->GetRepeatedStringReference(message, F("repeated_string"), 0, &scratch));
2404 EXPECT_EQ("216", reflection->GetRepeatedStringReference(message, F("repeated_bytes"), 0, &scratch)); 2531 EXPECT_EQ("216", reflection->GetRepeatedStringReference(message, F("repeated_bytes"), 0, &scratch));
2405 2532
2406 sub_message = &reflection->GetRepeatedMessage(message, F("repeatedgroup"), 0); 2533 sub_message = &reflection->GetRepeatedMessage(message, F("repeatedgroup"), 0);
2407 EXPECT_EQ(217, sub_message->GetReflection()->GetInt32(*sub_message, repeated_group_a_)); 2534 EXPECT_EQ(217, sub_message->GetReflection()->GetInt32(*sub_message, repeated_group_a_));
2408 sub_message = &reflection->GetRepeatedMessage(message, F("repeated_nested_message"), 0); 2535 sub_message = &reflection->GetRepeatedMessage(message, F("repeated_nested_message"), 0);
2409 EXPECT_EQ(218, sub_message->GetReflection()->GetInt32(*sub_message, nested_b_)); 2536 EXPECT_EQ(218, sub_message->GetReflection()->GetInt32(*sub_message, nested_b_));
2410 sub_message = &reflection->GetRepeatedMessage(message, F("repeated_foreign_message"), 0); 2537 sub_message = &reflection->GetRepeatedMessage(message, F("repeated_foreign_message"), 0);
2411 EXPECT_EQ(219, sub_message->GetReflection()->GetInt32(*sub_message, foreign_c_)); 2538 EXPECT_EQ(219, sub_message->GetReflection()->GetInt32(*sub_message, foreign_c_));
2412 sub_message = &reflection->GetRepeatedMessage(message, F("repeated_import_message"), 0); 2539 sub_message = &reflection->GetRepeatedMessage(message, F("repeated_import_message"), 0);
2413 EXPECT_EQ(220, sub_message->GetReflection()->GetInt32(*sub_message, import_d_)); 2540 EXPECT_EQ(220, sub_message->GetReflection()->GetInt32(*sub_message, import_d_));
2541 sub_message = &reflection->GetRepeatedMessage(message, F("repeated_lazy_message"), 0);
2542 EXPECT_EQ(227, sub_message->GetReflection()->GetInt32(*sub_message, nested_b_));
2414 2543
2415 EXPECT_EQ( nested_bar_, reflection->GetRepeatedEnum(message, F("repeated_nested_enum" ),0)); 2544 EXPECT_EQ( nested_bar_, reflection->GetRepeatedEnum(message, F("repeated_nested_enum" ),0));
2416 EXPECT_EQ(foreign_bar_, reflection->GetRepeatedEnum(message, F("repeated_foreign_enum"),0)); 2545 EXPECT_EQ(foreign_bar_, reflection->GetRepeatedEnum(message, F("repeated_foreign_enum"),0));
2417 EXPECT_EQ( import_bar_, reflection->GetRepeatedEnum(message, F("repeated_import_enum" ),0)); 2546 EXPECT_EQ( import_bar_, reflection->GetRepeatedEnum(message, F("repeated_import_enum" ),0));
2418 2547
2419 EXPECT_EQ("224", reflection->GetRepeatedString(message, F("repeated_string_piece"), 0)); 2548 EXPECT_EQ("224", reflection->GetRepeatedString(message, F("repeated_string_piece"), 0));
2420 EXPECT_EQ("224", reflection->GetRepeatedStringReference( 2549 EXPECT_EQ("224", reflection->GetRepeatedStringReference(
2421 message, F("repeated_string_piece"), 0, &scratch)); 2550 message, F("repeated_string_piece"), 0, &scratch));
2422 2551
2423 EXPECT_EQ("225", reflection->GetRepeatedString(message, F("repeated_cord"), 0)); 2552 EXPECT_EQ("225", reflection->GetRepeatedString(message, F("repeated_cord"), 0));
2424 EXPECT_EQ("225", reflection->GetRepeatedStringReference( 2553 EXPECT_EQ("225", reflection->GetRepeatedStringReference(
2425 message, F("repeated_cord"), 0, &scratch)); 2554 message, F("repeated_cord"), 0, &scratch));
2426 2555
2427 EXPECT_EQ(301 , reflection->GetRepeatedInt32 (message, F("repeated_int32" ), 1)); 2556 EXPECT_EQ(301 , reflection->GetRepeatedInt32 (message, F("repeated_int32" ), 1));
2428 EXPECT_EQ(302 , reflection->GetRepeatedInt64 (message, F("repeated_int64" ), 1)); 2557 EXPECT_EQ(302 , reflection->GetRepeatedInt64 (message, F("repeated_int64" ), 1));
2429 EXPECT_EQ(303 , reflection->GetRepeatedUInt32(message, F("repeated_uint32" ), 1)); 2558 EXPECT_EQ(303 , reflection->GetRepeatedUInt32(message, F("repeated_uint32" ), 1));
2430 EXPECT_EQ(304 , reflection->GetRepeatedUInt64(message, F("repeated_uint64" ), 1)); 2559 EXPECT_EQ(304 , reflection->GetRepeatedUInt64(message, F("repeated_uint64" ), 1));
2431 EXPECT_EQ(305 , reflection->GetRepeatedInt32 (message, F("repeated_sint32" ), 1)); 2560 EXPECT_EQ(305 , reflection->GetRepeatedInt32 (message, F("repeated_sint32" ), 1));
2432 EXPECT_EQ(306 , reflection->GetRepeatedInt64 (message, F("repeated_sint64" ), 1)); 2561 EXPECT_EQ(306 , reflection->GetRepeatedInt64 (message, F("repeated_sint64" ), 1));
2433 EXPECT_EQ(307 , reflection->GetRepeatedUInt32(message, F("repeated_fixed32" ), 1)); 2562 EXPECT_EQ(307 , reflection->GetRepeatedUInt32(message, F("repeated_fixed32" ), 1));
2434 EXPECT_EQ(308 , reflection->GetRepeatedUInt64(message, F("repeated_fixed64" ), 1)); 2563 EXPECT_EQ(308 , reflection->GetRepeatedUInt64(message, F("repeated_fixed64" ), 1));
2435 EXPECT_EQ(309 , reflection->GetRepeatedInt32 (message, F("repeated_sfixed32"), 1)); 2564 EXPECT_EQ(309 , reflection->GetRepeatedInt32 (message, F("repeated_sfixed32"), 1));
2436 EXPECT_EQ(310 , reflection->GetRepeatedInt64 (message, F("repeated_sfixed64"), 1)); 2565 EXPECT_EQ(310 , reflection->GetRepeatedInt64 (message, F("repeated_sfixed64"), 1));
2437 EXPECT_EQ(311 , reflection->GetRepeatedFloat (message, F("repeated_float" ), 1)); 2566 EXPECT_EQ(311 , reflection->GetRepeatedFloat (message, F("repeated_float" ), 1));
2438 EXPECT_EQ(312 , reflection->GetRepeatedDouble(message, F("repeated_double" ), 1)); 2567 EXPECT_EQ(312 , reflection->GetRepeatedDouble(message, F("repeated_double" ), 1));
2439 EXPECT_EQ(false, reflection->GetRepeatedBool (message, F("repeated_bool" ), 1)); 2568 EXPECT_EQ(false, reflection->GetRepeatedBool (message, F("repeated_bool" ), 1));
2440 EXPECT_EQ("315", reflection->GetRepeatedString(message, F("repeated_string" ), 1)); 2569 EXPECT_EQ("315", reflection->GetRepeatedString(message, F("repeated_string" ), 1));
2441 EXPECT_EQ("316", reflection->GetRepeatedString(message, F("repeated_bytes" ), 1)); 2570 EXPECT_EQ("316", reflection->GetRepeatedString(message, F("repeated_bytes" ), 1));
2442 2571
2443 EXPECT_EQ("315", reflection->GetRepeatedStringReference(message, F("repeated_string"), 2572 EXPECT_EQ("315", reflection->GetRepeatedStringReference(message, F("repeated_string"),
2444 1, &scratch)); 2573 1, &scratch));
2445 EXPECT_EQ("316", reflection->GetRepeatedStringReference(message, F("repeated_bytes"), 2574 EXPECT_EQ("316", reflection->GetRepeatedStringReference(message, F("repeated_bytes"),
2446 1, &scratch)); 2575 1, &scratch));
2447 2576
2448 sub_message = &reflection->GetRepeatedMessage(message, F("repeatedgroup"), 1); 2577 sub_message = &reflection->GetRepeatedMessage(message, F("repeatedgroup"), 1);
2449 EXPECT_EQ(317, sub_message->GetReflection()->GetInt32(*sub_message, repeated_group_a_)); 2578 EXPECT_EQ(317, sub_message->GetReflection()->GetInt32(*sub_message, repeated_group_a_));
2450 sub_message = &reflection->GetRepeatedMessage(message, F("repeated_nested_message"), 1); 2579 sub_message = &reflection->GetRepeatedMessage(message, F("repeated_nested_message"), 1);
2451 EXPECT_EQ(318, sub_message->GetReflection()->GetInt32(*sub_message, nested_b_)); 2580 EXPECT_EQ(318, sub_message->GetReflection()->GetInt32(*sub_message, nested_b_));
2452 sub_message = &reflection->GetRepeatedMessage(message, F("repeated_foreign_message"), 1); 2581 sub_message = &reflection->GetRepeatedMessage(message, F("repeated_foreign_message"), 1);
2453 EXPECT_EQ(319, sub_message->GetReflection()->GetInt32(*sub_message, foreign_c_)); 2582 EXPECT_EQ(319, sub_message->GetReflection()->GetInt32(*sub_message, foreign_c_));
2454 sub_message = &reflection->GetRepeatedMessage(message, F("repeated_import_message"), 1); 2583 sub_message = &reflection->GetRepeatedMessage(message, F("repeated_import_message"), 1);
2455 EXPECT_EQ(320, sub_message->GetReflection()->GetInt32(*sub_message, import_d_)); 2584 EXPECT_EQ(320, sub_message->GetReflection()->GetInt32(*sub_message, import_d_));
2585 sub_message = &reflection->GetRepeatedMessage(message, F("repeated_lazy_message"), 1);
2586 EXPECT_EQ(327, sub_message->GetReflection()->GetInt32(*sub_message, nested_b_));
2456 2587
2457 EXPECT_EQ( nested_baz_, reflection->GetRepeatedEnum(message, F("repeated_nested_enum" ),1)); 2588 EXPECT_EQ( nested_baz_, reflection->GetRepeatedEnum(message, F("repeated_nested_enum" ),1));
2458 EXPECT_EQ(foreign_baz_, reflection->GetRepeatedEnum(message, F("repeated_foreign_enum"),1)); 2589 EXPECT_EQ(foreign_baz_, reflection->GetRepeatedEnum(message, F("repeated_foreign_enum"),1));
2459 EXPECT_EQ( import_baz_, reflection->GetRepeatedEnum(message, F("repeated_import_enum" ),1)); 2590 EXPECT_EQ( import_baz_, reflection->GetRepeatedEnum(message, F("repeated_import_enum" ),1));
2460 2591
2461 EXPECT_EQ("324", reflection->GetRepeatedString(message, F("repeated_string_piece"), 1)); 2592 EXPECT_EQ("324", reflection->GetRepeatedString(message, F("repeated_string_piece"), 1));
2462 EXPECT_EQ("324", reflection->GetRepeatedStringReference( 2593 EXPECT_EQ("324", reflection->GetRepeatedStringReference(
2463 message, F("repeated_string_piece"), 1, &scratch)); 2594 message, F("repeated_string_piece"), 1, &scratch));
2464 2595
2465 EXPECT_EQ("325", reflection->GetRepeatedString(message, F("repeated_cord"), 1)); 2596 EXPECT_EQ("325", reflection->GetRepeatedString(message, F("repeated_cord"), 1));
2466 EXPECT_EQ("325", reflection->GetRepeatedStringReference( 2597 EXPECT_EQ("325", reflection->GetRepeatedStringReference(
2467 message, F("repeated_cord"), 1, &scratch)); 2598 message, F("repeated_cord"), 1, &scratch));
2468 } 2599 }
2469 2600
2470 void TestUtil::ReflectionTester::ExpectAllFieldsSetViaReflection3( 2601 void TestUtil::ReflectionTester::ExpectAllFieldsSetViaReflection3(
2471 const Message& message) { 2602 const Message& message) {
2472 const Reflection* reflection = message.GetReflection(); 2603 const Reflection* reflection = message.GetReflection();
2473 string scratch; 2604 string scratch;
2474 2605
2475 // ----------------------------------------------------------------- 2606 // -----------------------------------------------------------------
2476 2607
2477 EXPECT_TRUE(reflection->HasField(message, F("default_int32" ))); 2608 EXPECT_TRUE(reflection->HasField(message, F("default_int32" )));
2478 EXPECT_TRUE(reflection->HasField(message, F("default_int64" ))); 2609 EXPECT_TRUE(reflection->HasField(message, F("default_int64" )));
2479 EXPECT_TRUE(reflection->HasField(message, F("default_uint32" ))); 2610 EXPECT_TRUE(reflection->HasField(message, F("default_uint32" )));
2480 EXPECT_TRUE(reflection->HasField(message, F("default_uint64" ))); 2611 EXPECT_TRUE(reflection->HasField(message, F("default_uint64" )));
2481 EXPECT_TRUE(reflection->HasField(message, F("default_sint32" ))); 2612 EXPECT_TRUE(reflection->HasField(message, F("default_sint32" )));
2482 EXPECT_TRUE(reflection->HasField(message, F("default_sint64" ))); 2613 EXPECT_TRUE(reflection->HasField(message, F("default_sint64" )));
2483 EXPECT_TRUE(reflection->HasField(message, F("default_fixed32" ))); 2614 EXPECT_TRUE(reflection->HasField(message, F("default_fixed32" )));
2484 EXPECT_TRUE(reflection->HasField(message, F("default_fixed64" ))); 2615 EXPECT_TRUE(reflection->HasField(message, F("default_fixed64" )));
2485 EXPECT_TRUE(reflection->HasField(message, F("default_sfixed32"))); 2616 EXPECT_TRUE(reflection->HasField(message, F("default_sfixed32")));
2486 EXPECT_TRUE(reflection->HasField(message, F("default_sfixed64"))); 2617 EXPECT_TRUE(reflection->HasField(message, F("default_sfixed64")));
2487 EXPECT_TRUE(reflection->HasField(message, F("default_float" ))); 2618 EXPECT_TRUE(reflection->HasField(message, F("default_float" )));
2488 EXPECT_TRUE(reflection->HasField(message, F("default_double" ))); 2619 EXPECT_TRUE(reflection->HasField(message, F("default_double" )));
2489 EXPECT_TRUE(reflection->HasField(message, F("default_bool" ))); 2620 EXPECT_TRUE(reflection->HasField(message, F("default_bool" )));
2490 EXPECT_TRUE(reflection->HasField(message, F("default_string" ))); 2621 EXPECT_TRUE(reflection->HasField(message, F("default_string" )));
2491 EXPECT_TRUE(reflection->HasField(message, F("default_bytes" ))); 2622 EXPECT_TRUE(reflection->HasField(message, F("default_bytes" )));
2492 2623
2493 EXPECT_TRUE(reflection->HasField(message, F("default_nested_enum" ))); 2624 EXPECT_TRUE(reflection->HasField(message, F("default_nested_enum" )));
2494 EXPECT_TRUE(reflection->HasField(message, F("default_foreign_enum"))); 2625 EXPECT_TRUE(reflection->HasField(message, F("default_foreign_enum")));
2495 EXPECT_TRUE(reflection->HasField(message, F("default_import_enum" ))); 2626 EXPECT_TRUE(reflection->HasField(message, F("default_import_enum" )));
2496 2627
2497 EXPECT_TRUE(reflection->HasField(message, F("default_string_piece"))); 2628 EXPECT_TRUE(reflection->HasField(message, F("default_string_piece")));
2498 EXPECT_TRUE(reflection->HasField(message, F("default_cord"))); 2629 EXPECT_TRUE(reflection->HasField(message, F("default_cord")));
2499 2630
2500 EXPECT_EQ(401 , reflection->GetInt32 (message, F("default_int32" ))); 2631 EXPECT_EQ(401 , reflection->GetInt32 (message, F("default_int32" )));
2501 EXPECT_EQ(402 , reflection->GetInt64 (message, F("default_int64" ))); 2632 EXPECT_EQ(402 , reflection->GetInt64 (message, F("default_int64" )));
2502 EXPECT_EQ(403 , reflection->GetUInt32(message, F("default_uint32" ))); 2633 EXPECT_EQ(403 , reflection->GetUInt32(message, F("default_uint32" )));
2503 EXPECT_EQ(404 , reflection->GetUInt64(message, F("default_uint64" ))); 2634 EXPECT_EQ(404 , reflection->GetUInt64(message, F("default_uint64" )));
2504 EXPECT_EQ(405 , reflection->GetInt32 (message, F("default_sint32" ))); 2635 EXPECT_EQ(405 , reflection->GetInt32 (message, F("default_sint32" )));
2505 EXPECT_EQ(406 , reflection->GetInt64 (message, F("default_sint64" ))); 2636 EXPECT_EQ(406 , reflection->GetInt64 (message, F("default_sint64" )));
2506 EXPECT_EQ(407 , reflection->GetUInt32(message, F("default_fixed32" ))); 2637 EXPECT_EQ(407 , reflection->GetUInt32(message, F("default_fixed32" )));
2507 EXPECT_EQ(408 , reflection->GetUInt64(message, F("default_fixed64" ))); 2638 EXPECT_EQ(408 , reflection->GetUInt64(message, F("default_fixed64" )));
2508 EXPECT_EQ(409 , reflection->GetInt32 (message, F("default_sfixed32"))); 2639 EXPECT_EQ(409 , reflection->GetInt32 (message, F("default_sfixed32")));
2509 EXPECT_EQ(410 , reflection->GetInt64 (message, F("default_sfixed64"))); 2640 EXPECT_EQ(410 , reflection->GetInt64 (message, F("default_sfixed64")));
2510 EXPECT_EQ(411 , reflection->GetFloat (message, F("default_float" ))); 2641 EXPECT_EQ(411 , reflection->GetFloat (message, F("default_float" )));
2511 EXPECT_EQ(412 , reflection->GetDouble(message, F("default_double" ))); 2642 EXPECT_EQ(412 , reflection->GetDouble(message, F("default_double" )));
2512 EXPECT_EQ(false, reflection->GetBool (message, F("default_bool" ))); 2643 EXPECT_EQ(false, reflection->GetBool (message, F("default_bool" )));
2513 EXPECT_EQ("415", reflection->GetString(message, F("default_string" ))); 2644 EXPECT_EQ("415", reflection->GetString(message, F("default_string" )));
2514 EXPECT_EQ("416", reflection->GetString(message, F("default_bytes" ))); 2645 EXPECT_EQ("416", reflection->GetString(message, F("default_bytes" )));
2515 2646
2516 EXPECT_EQ("415", reflection->GetStringReference(message, F("default_string"), &scratch)); 2647 EXPECT_EQ("415", reflection->GetStringReference(message, F("default_string"), &scratch));
2517 EXPECT_EQ("416", reflection->GetStringReference(message, F("default_bytes" ), &scratch)); 2648 EXPECT_EQ("416", reflection->GetStringReference(message, F("default_bytes" ), &scratch));
2518 2649
2519 EXPECT_EQ( nested_foo_, reflection->GetEnum(message, F("default_nested_enum" ))); 2650 EXPECT_EQ( nested_foo_, reflection->GetEnum(message, F("default_nested_enum" )));
2520 EXPECT_EQ(foreign_foo_, reflection->GetEnum(message, F("default_foreign_enum"))); 2651 EXPECT_EQ(foreign_foo_, reflection->GetEnum(message, F("default_foreign_enum")));
2521 EXPECT_EQ( import_foo_, reflection->GetEnum(message, F("default_import_enum" ))); 2652 EXPECT_EQ( import_foo_, reflection->GetEnum(message, F("default_import_enum" )));
2522 2653
2523 EXPECT_EQ("424", reflection->GetString(message, F("default_string_piece"))); 2654 EXPECT_EQ("424", reflection->GetString(message, F("default_string_piece")));
2524 EXPECT_EQ("424", reflection->GetStringReference(message, F("default_string_piece"), 2655 EXPECT_EQ("424", reflection->GetStringReference(message, F("default_string_piece"),
2525 &scratch)); 2656 &scratch));
2526 2657
2527 EXPECT_EQ("425", reflection->GetString(message, F("default_cord"))); 2658 EXPECT_EQ("425", reflection->GetString(message, F("default_cord")));
2528 EXPECT_EQ("425", reflection->GetStringReference(message, F("default_cord"), &scratch)); 2659 EXPECT_EQ("425", reflection->GetStringReference(message, F("default_cord"), &scratch));
2529 } 2660 }
2530 2661
2531 void TestUtil::ReflectionTester::ExpectPackedFieldsSetViaReflection( 2662 void TestUtil::ReflectionTester::ExpectPackedFieldsSetViaReflection(
2532 const Message& message) { 2663 const Message& message) {
2533 const Reflection* reflection = message.GetReflection(); 2664 const Reflection* reflection = message.GetReflection();
2534 2665
2535 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_int32" ))); 2666 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_int32" )));
2536 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_int64" ))); 2667 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_int64" )));
2537 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_uint32" ))); 2668 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_uint32" )));
2538 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_uint64" ))); 2669 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_uint64" )));
2539 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_sint32" ))); 2670 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_sint32" )));
2540 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_sint64" ))); 2671 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_sint64" )));
2541 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_fixed32" ))); 2672 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_fixed32" )));
2542 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_fixed64" ))); 2673 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_fixed64" )));
2543 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_sfixed32"))); 2674 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_sfixed32")));
2544 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_sfixed64"))); 2675 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_sfixed64")));
2545 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_float" ))); 2676 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_float" )));
2546 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_double" ))); 2677 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_double" )));
2547 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_bool" ))); 2678 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_bool" )));
2548 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_enum" ))); 2679 ASSERT_EQ(2, reflection->FieldSize(message, F("packed_enum" )));
2549 2680
2550 EXPECT_EQ(601 , reflection->GetRepeatedInt32 (message, F("packed_int32" ), 0)); 2681 EXPECT_EQ(601 , reflection->GetRepeatedInt32 (message, F("packed_int32" ), 0));
2551 EXPECT_EQ(602 , reflection->GetRepeatedInt64 (message, F("packed_int64" ), 0)); 2682 EXPECT_EQ(602 , reflection->GetRepeatedInt64 (message, F("packed_int64" ), 0));
2552 EXPECT_EQ(603 , reflection->GetRepeatedUInt32(message, F("packed_uint32" ), 0)); 2683 EXPECT_EQ(603 , reflection->GetRepeatedUInt32(message, F("packed_uint32" ), 0));
2553 EXPECT_EQ(604 , reflection->GetRepeatedUInt64(message, F("packed_uint64" ), 0)); 2684 EXPECT_EQ(604 , reflection->GetRepeatedUInt64(message, F("packed_uint64" ), 0));
2554 EXPECT_EQ(605 , reflection->GetRepeatedInt32 (message, F("packed_sint32" ), 0)); 2685 EXPECT_EQ(605 , reflection->GetRepeatedInt32 (message, F("packed_sint32" ), 0));
2555 EXPECT_EQ(606 , reflection->GetRepeatedInt64 (message, F("packed_sint64" ), 0)); 2686 EXPECT_EQ(606 , reflection->GetRepeatedInt64 (message, F("packed_sint64" ), 0));
2556 EXPECT_EQ(607 , reflection->GetRepeatedUInt32(message, F("packed_fixed32" ), 0)); 2687 EXPECT_EQ(607 , reflection->GetRepeatedUInt32(message, F("packed_fixed32" ), 0));
2557 EXPECT_EQ(608 , reflection->GetRepeatedUInt64(message, F("packed_fixed64" ), 0)); 2688 EXPECT_EQ(608 , reflection->GetRepeatedUInt64(message, F("packed_fixed64" ), 0));
2558 EXPECT_EQ(609 , reflection->GetRepeatedInt32 (message, F("packed_sfixed32"), 0)); 2689 EXPECT_EQ(609 , reflection->GetRepeatedInt32 (message, F("packed_sfixed32"), 0));
2559 EXPECT_EQ(610 , reflection->GetRepeatedInt64 (message, F("packed_sfixed64"), 0)); 2690 EXPECT_EQ(610 , reflection->GetRepeatedInt64 (message, F("packed_sfixed64"), 0));
2560 EXPECT_EQ(611 , reflection->GetRepeatedFloat (message, F("packed_float" ), 0)); 2691 EXPECT_EQ(611 , reflection->GetRepeatedFloat (message, F("packed_float" ), 0));
2561 EXPECT_EQ(612 , reflection->GetRepeatedDouble(message, F("packed_double" ), 0)); 2692 EXPECT_EQ(612 , reflection->GetRepeatedDouble(message, F("packed_double" ), 0));
2562 EXPECT_EQ(true , reflection->GetRepeatedBool (message, F("packed_bool" ), 0)); 2693 EXPECT_EQ(true , reflection->GetRepeatedBool (message, F("packed_bool" ), 0));
2563 EXPECT_EQ(foreign_bar_, 2694 EXPECT_EQ(foreign_bar_,
2564 reflection->GetRepeatedEnum(message, F("packed_enum"), 0)); 2695 reflection->GetRepeatedEnum(message, F("packed_enum"), 0));
2565 2696
2566 EXPECT_EQ(701 , reflection->GetRepeatedInt32 (message, F("packed_int32" ), 1)); 2697 EXPECT_EQ(701 , reflection->GetRepeatedInt32 (message, F("packed_int32" ), 1));
2567 EXPECT_EQ(702 , reflection->GetRepeatedInt64 (message, F("packed_int64" ), 1)); 2698 EXPECT_EQ(702 , reflection->GetRepeatedInt64 (message, F("packed_int64" ), 1));
2568 EXPECT_EQ(703 , reflection->GetRepeatedUInt32(message, F("packed_uint32" ), 1)); 2699 EXPECT_EQ(703 , reflection->GetRepeatedUInt32(message, F("packed_uint32" ), 1));
2569 EXPECT_EQ(704 , reflection->GetRepeatedUInt64(message, F("packed_uint64" ), 1)); 2700 EXPECT_EQ(704 , reflection->GetRepeatedUInt64(message, F("packed_uint64" ), 1));
2570 EXPECT_EQ(705 , reflection->GetRepeatedInt32 (message, F("packed_sint32" ), 1)); 2701 EXPECT_EQ(705 , reflection->GetRepeatedInt32 (message, F("packed_sint32" ), 1));
2571 EXPECT_EQ(706 , reflection->GetRepeatedInt64 (message, F("packed_sint64" ), 1)); 2702 EXPECT_EQ(706 , reflection->GetRepeatedInt64 (message, F("packed_sint64" ), 1));
2572 EXPECT_EQ(707 , reflection->GetRepeatedUInt32(message, F("packed_fixed32" ), 1)); 2703 EXPECT_EQ(707 , reflection->GetRepeatedUInt32(message, F("packed_fixed32" ), 1));
2573 EXPECT_EQ(708 , reflection->GetRepeatedUInt64(message, F("packed_fixed64" ), 1)); 2704 EXPECT_EQ(708 , reflection->GetRepeatedUInt64(message, F("packed_fixed64" ), 1));
2574 EXPECT_EQ(709 , reflection->GetRepeatedInt32 (message, F("packed_sfixed32"), 1)); 2705 EXPECT_EQ(709 , reflection->GetRepeatedInt32 (message, F("packed_sfixed32"), 1));
2575 EXPECT_EQ(710 , reflection->GetRepeatedInt64 (message, F("packed_sfixed64"), 1)); 2706 EXPECT_EQ(710 , reflection->GetRepeatedInt64 (message, F("packed_sfixed64"), 1));
2576 EXPECT_EQ(711 , reflection->GetRepeatedFloat (message, F("packed_float" ), 1)); 2707 EXPECT_EQ(711 , reflection->GetRepeatedFloat (message, F("packed_float" ), 1));
2577 EXPECT_EQ(712 , reflection->GetRepeatedDouble(message, F("packed_double" ), 1)); 2708 EXPECT_EQ(712 , reflection->GetRepeatedDouble(message, F("packed_double" ), 1));
2578 EXPECT_EQ(false, reflection->GetRepeatedBool (message, F("packed_bool" ), 1)); 2709 EXPECT_EQ(false, reflection->GetRepeatedBool (message, F("packed_bool" ), 1));
2579 EXPECT_EQ(foreign_baz_, 2710 EXPECT_EQ(foreign_baz_,
2580 reflection->GetRepeatedEnum(message, F("packed_enum"), 1)); 2711 reflection->GetRepeatedEnum(message, F("packed_enum"), 1));
2581 } 2712 }
2582 2713
2583 // ------------------------------------------------------------------- 2714 // -------------------------------------------------------------------
2584 2715
2585 void TestUtil::ReflectionTester::ExpectClearViaReflection( 2716 void TestUtil::ReflectionTester::ExpectClearViaReflection(
2586 const Message& message) { 2717 const Message& message) {
2587 const Reflection* reflection = message.GetReflection(); 2718 const Reflection* reflection = message.GetReflection();
2588 string scratch; 2719 string scratch;
2589 const Message* sub_message; 2720 const Message* sub_message;
2590 2721
2591 // has_blah() should initially be false for all optional fields. 2722 // has_blah() should initially be false for all optional fields.
2592 EXPECT_FALSE(reflection->HasField(message, F("optional_int32" ))); 2723 EXPECT_FALSE(reflection->HasField(message, F("optional_int32" )));
2593 EXPECT_FALSE(reflection->HasField(message, F("optional_int64" ))); 2724 EXPECT_FALSE(reflection->HasField(message, F("optional_int64" )));
2594 EXPECT_FALSE(reflection->HasField(message, F("optional_uint32" ))); 2725 EXPECT_FALSE(reflection->HasField(message, F("optional_uint32" )));
2595 EXPECT_FALSE(reflection->HasField(message, F("optional_uint64" ))); 2726 EXPECT_FALSE(reflection->HasField(message, F("optional_uint64" )));
2596 EXPECT_FALSE(reflection->HasField(message, F("optional_sint32" ))); 2727 EXPECT_FALSE(reflection->HasField(message, F("optional_sint32" )));
2597 EXPECT_FALSE(reflection->HasField(message, F("optional_sint64" ))); 2728 EXPECT_FALSE(reflection->HasField(message, F("optional_sint64" )));
2598 EXPECT_FALSE(reflection->HasField(message, F("optional_fixed32" ))); 2729 EXPECT_FALSE(reflection->HasField(message, F("optional_fixed32" )));
2599 EXPECT_FALSE(reflection->HasField(message, F("optional_fixed64" ))); 2730 EXPECT_FALSE(reflection->HasField(message, F("optional_fixed64" )));
2600 EXPECT_FALSE(reflection->HasField(message, F("optional_sfixed32"))); 2731 EXPECT_FALSE(reflection->HasField(message, F("optional_sfixed32")));
2601 EXPECT_FALSE(reflection->HasField(message, F("optional_sfixed64"))); 2732 EXPECT_FALSE(reflection->HasField(message, F("optional_sfixed64")));
2602 EXPECT_FALSE(reflection->HasField(message, F("optional_float" ))); 2733 EXPECT_FALSE(reflection->HasField(message, F("optional_float" )));
2603 EXPECT_FALSE(reflection->HasField(message, F("optional_double" ))); 2734 EXPECT_FALSE(reflection->HasField(message, F("optional_double" )));
2604 EXPECT_FALSE(reflection->HasField(message, F("optional_bool" ))); 2735 EXPECT_FALSE(reflection->HasField(message, F("optional_bool" )));
2605 EXPECT_FALSE(reflection->HasField(message, F("optional_string" ))); 2736 EXPECT_FALSE(reflection->HasField(message, F("optional_string" )));
2606 EXPECT_FALSE(reflection->HasField(message, F("optional_bytes" ))); 2737 EXPECT_FALSE(reflection->HasField(message, F("optional_bytes" )));
2607 2738
2608 EXPECT_FALSE(reflection->HasField(message, F("optionalgroup" ))); 2739 EXPECT_FALSE(reflection->HasField(message, F("optionalgroup" )));
2609 EXPECT_FALSE(reflection->HasField(message, F("optional_nested_message" ))); 2740 EXPECT_FALSE(reflection->HasField(message, F("optional_nested_message" )));
2610 EXPECT_FALSE(reflection->HasField(message, F("optional_foreign_message"))); 2741 EXPECT_FALSE(reflection->HasField(message, F("optional_foreign_message")));
2611 EXPECT_FALSE(reflection->HasField(message, F("optional_import_message" ))); 2742 EXPECT_FALSE(reflection->HasField(message, F("optional_import_message" )));
2743 EXPECT_FALSE(reflection->HasField(message, F("optional_public_import_message")));
2744 EXPECT_FALSE(reflection->HasField(message, F("optional_lazy_message")));
2612 2745
2613 EXPECT_FALSE(reflection->HasField(message, F("optional_nested_enum" ))); 2746 EXPECT_FALSE(reflection->HasField(message, F("optional_nested_enum" )));
2614 EXPECT_FALSE(reflection->HasField(message, F("optional_foreign_enum"))); 2747 EXPECT_FALSE(reflection->HasField(message, F("optional_foreign_enum")));
2615 EXPECT_FALSE(reflection->HasField(message, F("optional_import_enum" ))); 2748 EXPECT_FALSE(reflection->HasField(message, F("optional_import_enum" )));
2616 2749
2617 EXPECT_FALSE(reflection->HasField(message, F("optional_string_piece"))); 2750 EXPECT_FALSE(reflection->HasField(message, F("optional_string_piece")));
2618 EXPECT_FALSE(reflection->HasField(message, F("optional_cord"))); 2751 EXPECT_FALSE(reflection->HasField(message, F("optional_cord")));
2619 2752
2620 // Optional fields without defaults are set to zero or something like it. 2753 // Optional fields without defaults are set to zero or something like it.
2621 EXPECT_EQ(0 , reflection->GetInt32 (message, F("optional_int32" ))); 2754 EXPECT_EQ(0 , reflection->GetInt32 (message, F("optional_int32" )));
2622 EXPECT_EQ(0 , reflection->GetInt64 (message, F("optional_int64" ))); 2755 EXPECT_EQ(0 , reflection->GetInt64 (message, F("optional_int64" )));
2623 EXPECT_EQ(0 , reflection->GetUInt32(message, F("optional_uint32" ))); 2756 EXPECT_EQ(0 , reflection->GetUInt32(message, F("optional_uint32" )));
2624 EXPECT_EQ(0 , reflection->GetUInt64(message, F("optional_uint64" ))); 2757 EXPECT_EQ(0 , reflection->GetUInt64(message, F("optional_uint64" )));
2625 EXPECT_EQ(0 , reflection->GetInt32 (message, F("optional_sint32" ))); 2758 EXPECT_EQ(0 , reflection->GetInt32 (message, F("optional_sint32" )));
2626 EXPECT_EQ(0 , reflection->GetInt64 (message, F("optional_sint64" ))); 2759 EXPECT_EQ(0 , reflection->GetInt64 (message, F("optional_sint64" )));
2627 EXPECT_EQ(0 , reflection->GetUInt32(message, F("optional_fixed32" ))); 2760 EXPECT_EQ(0 , reflection->GetUInt32(message, F("optional_fixed32" )));
2628 EXPECT_EQ(0 , reflection->GetUInt64(message, F("optional_fixed64" ))); 2761 EXPECT_EQ(0 , reflection->GetUInt64(message, F("optional_fixed64" )));
2629 EXPECT_EQ(0 , reflection->GetInt32 (message, F("optional_sfixed32"))); 2762 EXPECT_EQ(0 , reflection->GetInt32 (message, F("optional_sfixed32")));
2630 EXPECT_EQ(0 , reflection->GetInt64 (message, F("optional_sfixed64"))); 2763 EXPECT_EQ(0 , reflection->GetInt64 (message, F("optional_sfixed64")));
2631 EXPECT_EQ(0 , reflection->GetFloat (message, F("optional_float" ))); 2764 EXPECT_EQ(0 , reflection->GetFloat (message, F("optional_float" )));
2632 EXPECT_EQ(0 , reflection->GetDouble(message, F("optional_double" ))); 2765 EXPECT_EQ(0 , reflection->GetDouble(message, F("optional_double" )));
2633 EXPECT_EQ(false, reflection->GetBool (message, F("optional_bool" ))); 2766 EXPECT_EQ(false, reflection->GetBool (message, F("optional_bool" )));
2634 EXPECT_EQ("" , reflection->GetString(message, F("optional_string" ))); 2767 EXPECT_EQ("" , reflection->GetString(message, F("optional_string" )));
2635 EXPECT_EQ("" , reflection->GetString(message, F("optional_bytes" ))); 2768 EXPECT_EQ("" , reflection->GetString(message, F("optional_bytes" )));
2636 2769
2637 EXPECT_EQ("", reflection->GetStringReference(message, F("optional_string"), &scratch)); 2770 EXPECT_EQ("", reflection->GetStringReference(message, F("optional_string"), &scratch));
2638 EXPECT_EQ("", reflection->GetStringReference(message, F("optional_bytes" ), &scratch)); 2771 EXPECT_EQ("", reflection->GetStringReference(message, F("optional_bytes" ), &scratch));
2639 2772
2640 // Embedded messages should also be clear. 2773 // Embedded messages should also be clear.
2641 sub_message = &reflection->GetMessage(message, F("optionalgroup")); 2774 sub_message = &reflection->GetMessage(message, F("optionalgroup"));
2642 EXPECT_FALSE(sub_message->GetReflection()->HasField(*sub_message, group_a_)); 2775 EXPECT_FALSE(sub_message->GetReflection()->HasField(*sub_message, group_a_));
2643 EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message, group_a_)); 2776 EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message, group_a_));
2644 sub_message = &reflection->GetMessage(message, F("optional_nested_message")); 2777 sub_message = &reflection->GetMessage(message, F("optional_nested_message"));
2645 EXPECT_FALSE(sub_message->GetReflection()->HasField(*sub_message, nested_b_)); 2778 EXPECT_FALSE(sub_message->GetReflection()->HasField(*sub_message, nested_b_));
2646 EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message, nested_b_)); 2779 EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message, nested_b_));
2647 sub_message = &reflection->GetMessage(message, F("optional_foreign_message")); 2780 sub_message = &reflection->GetMessage(message, F("optional_foreign_message"));
2648 EXPECT_FALSE(sub_message->GetReflection()->HasField(*sub_message, foreign_c_)); 2781 EXPECT_FALSE(sub_message->GetReflection()->HasField(*sub_message, foreign_c_));
2649 EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message, foreign_c_)); 2782 EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message, foreign_c_));
2650 sub_message = &reflection->GetMessage(message, F("optional_import_message")); 2783 sub_message = &reflection->GetMessage(message, F("optional_import_message"));
2651 EXPECT_FALSE(sub_message->GetReflection()->HasField(*sub_message, import_d_)); 2784 EXPECT_FALSE(sub_message->GetReflection()->HasField(*sub_message, import_d_));
2652 EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message, import_d_)); 2785 EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message, import_d_));
2786 sub_message = &reflection->GetMessage(message, F("optional_public_import_message"));
2787 EXPECT_FALSE(sub_message->GetReflection()->HasField(*sub_message, import_e_));
2788 EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message, import_e_));
2789 sub_message = &reflection->GetMessage(message, F("optional_lazy_message"));
2790 EXPECT_FALSE(sub_message->GetReflection()->HasField(*sub_message, nested_b_));
2791 EXPECT_EQ(0, sub_message->GetReflection()->GetInt32(*sub_message, nested_b_));
2653 2792
2654 // Enums without defaults are set to the first value in the enum. 2793 // Enums without defaults are set to the first value in the enum.
2655 EXPECT_EQ( nested_foo_, reflection->GetEnum(message, F("optional_nested_enum" ))); 2794 EXPECT_EQ( nested_foo_, reflection->GetEnum(message, F("optional_nested_enum" )));
2656 EXPECT_EQ(foreign_foo_, reflection->GetEnum(message, F("optional_foreign_enum"))); 2795 EXPECT_EQ(foreign_foo_, reflection->GetEnum(message, F("optional_foreign_enum")));
2657 EXPECT_EQ( import_foo_, reflection->GetEnum(message, F("optional_import_enum" ))); 2796 EXPECT_EQ( import_foo_, reflection->GetEnum(message, F("optional_import_enum" )));
2658 2797
2659 EXPECT_EQ("", reflection->GetString(message, F("optional_string_piece"))); 2798 EXPECT_EQ("", reflection->GetString(message, F("optional_string_piece")));
2660 EXPECT_EQ("", reflection->GetStringReference(message, F("optional_string_piece"), &scratch)); 2799 EXPECT_EQ("", reflection->GetStringReference(message, F("optional_string_piece"), &scratch));
2661 2800
2662 EXPECT_EQ("", reflection->GetString(message, F("optional_cord"))); 2801 EXPECT_EQ("", reflection->GetString(message, F("optional_cord")));
2663 EXPECT_EQ("", reflection->GetStringReference(message, F("optional_cord"), &scratch)); 2802 EXPECT_EQ("", reflection->GetStringReference(message, F("optional_cord"), &scratch));
2664 2803
2665 // Repeated fields are empty. 2804 // Repeated fields are empty.
2666 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_int32" ))); 2805 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_int32" )));
2667 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_int64" ))); 2806 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_int64" )));
2668 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_uint32" ))); 2807 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_uint32" )));
2669 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_uint64" ))); 2808 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_uint64" )));
2670 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_sint32" ))); 2809 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_sint32" )));
2671 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_sint64" ))); 2810 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_sint64" )));
2672 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_fixed32" ))); 2811 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_fixed32" )));
2673 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_fixed64" ))); 2812 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_fixed64" )));
2674 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_sfixed32"))); 2813 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_sfixed32")));
2675 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_sfixed64"))); 2814 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_sfixed64")));
2676 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_float" ))); 2815 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_float" )));
2677 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_double" ))); 2816 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_double" )));
2678 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_bool" ))); 2817 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_bool" )));
2679 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_string" ))); 2818 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_string" )));
2680 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_bytes" ))); 2819 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_bytes" )));
2681 2820
2682 EXPECT_EQ(0, reflection->FieldSize(message, F("repeatedgroup" ))); 2821 EXPECT_EQ(0, reflection->FieldSize(message, F("repeatedgroup" )));
2683 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_nested_message" ))); 2822 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_nested_message" )));
2684 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_foreign_message"))); 2823 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_foreign_message")));
2685 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_import_message" ))); 2824 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_import_message" )));
2825 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_lazy_message" )));
2686 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_nested_enum" ))); 2826 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_nested_enum" )));
2687 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_foreign_enum" ))); 2827 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_foreign_enum" )));
2688 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_import_enum" ))); 2828 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_import_enum" )));
2689 2829
2690 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_string_piece"))); 2830 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_string_piece")));
2691 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_cord"))); 2831 EXPECT_EQ(0, reflection->FieldSize(message, F("repeated_cord")));
2692 2832
2693 // has_blah() should also be false for all default fields. 2833 // has_blah() should also be false for all default fields.
2694 EXPECT_FALSE(reflection->HasField(message, F("default_int32" ))); 2834 EXPECT_FALSE(reflection->HasField(message, F("default_int32" )));
2695 EXPECT_FALSE(reflection->HasField(message, F("default_int64" ))); 2835 EXPECT_FALSE(reflection->HasField(message, F("default_int64" )));
2696 EXPECT_FALSE(reflection->HasField(message, F("default_uint32" ))); 2836 EXPECT_FALSE(reflection->HasField(message, F("default_uint32" )));
2697 EXPECT_FALSE(reflection->HasField(message, F("default_uint64" ))); 2837 EXPECT_FALSE(reflection->HasField(message, F("default_uint64" )));
2698 EXPECT_FALSE(reflection->HasField(message, F("default_sint32" ))); 2838 EXPECT_FALSE(reflection->HasField(message, F("default_sint32" )));
2699 EXPECT_FALSE(reflection->HasField(message, F("default_sint64" ))); 2839 EXPECT_FALSE(reflection->HasField(message, F("default_sint64" )));
2700 EXPECT_FALSE(reflection->HasField(message, F("default_fixed32" ))); 2840 EXPECT_FALSE(reflection->HasField(message, F("default_fixed32" )));
2701 EXPECT_FALSE(reflection->HasField(message, F("default_fixed64" ))); 2841 EXPECT_FALSE(reflection->HasField(message, F("default_fixed64" )));
2702 EXPECT_FALSE(reflection->HasField(message, F("default_sfixed32"))); 2842 EXPECT_FALSE(reflection->HasField(message, F("default_sfixed32")));
2703 EXPECT_FALSE(reflection->HasField(message, F("default_sfixed64"))); 2843 EXPECT_FALSE(reflection->HasField(message, F("default_sfixed64")));
2704 EXPECT_FALSE(reflection->HasField(message, F("default_float" ))); 2844 EXPECT_FALSE(reflection->HasField(message, F("default_float" )));
2705 EXPECT_FALSE(reflection->HasField(message, F("default_double" ))); 2845 EXPECT_FALSE(reflection->HasField(message, F("default_double" )));
2706 EXPECT_FALSE(reflection->HasField(message, F("default_bool" ))); 2846 EXPECT_FALSE(reflection->HasField(message, F("default_bool" )));
2707 EXPECT_FALSE(reflection->HasField(message, F("default_string" ))); 2847 EXPECT_FALSE(reflection->HasField(message, F("default_string" )));
2708 EXPECT_FALSE(reflection->HasField(message, F("default_bytes" ))); 2848 EXPECT_FALSE(reflection->HasField(message, F("default_bytes" )));
2709 2849
2710 EXPECT_FALSE(reflection->HasField(message, F("default_nested_enum" ))); 2850 EXPECT_FALSE(reflection->HasField(message, F("default_nested_enum" )));
2711 EXPECT_FALSE(reflection->HasField(message, F("default_foreign_enum"))); 2851 EXPECT_FALSE(reflection->HasField(message, F("default_foreign_enum")));
2712 EXPECT_FALSE(reflection->HasField(message, F("default_import_enum" ))); 2852 EXPECT_FALSE(reflection->HasField(message, F("default_import_enum" )));
2713 2853
2714 EXPECT_FALSE(reflection->HasField(message, F("default_string_piece"))); 2854 EXPECT_FALSE(reflection->HasField(message, F("default_string_piece")));
2715 EXPECT_FALSE(reflection->HasField(message, F("default_cord"))); 2855 EXPECT_FALSE(reflection->HasField(message, F("default_cord")));
2716 2856
2717 // Fields with defaults have their default values (duh). 2857 // Fields with defaults have their default values (duh).
2718 EXPECT_EQ( 41 , reflection->GetInt32 (message, F("default_int32" ))); 2858 EXPECT_EQ( 41 , reflection->GetInt32 (message, F("default_int32" )));
2719 EXPECT_EQ( 42 , reflection->GetInt64 (message, F("default_int64" ))); 2859 EXPECT_EQ( 42 , reflection->GetInt64 (message, F("default_int64" )));
2720 EXPECT_EQ( 43 , reflection->GetUInt32(message, F("default_uint32" ))); 2860 EXPECT_EQ( 43 , reflection->GetUInt32(message, F("default_uint32" )));
2721 EXPECT_EQ( 44 , reflection->GetUInt64(message, F("default_uint64" ))); 2861 EXPECT_EQ( 44 , reflection->GetUInt64(message, F("default_uint64" )));
2722 EXPECT_EQ(-45 , reflection->GetInt32 (message, F("default_sint32" ))); 2862 EXPECT_EQ(-45 , reflection->GetInt32 (message, F("default_sint32" )));
2723 EXPECT_EQ( 46 , reflection->GetInt64 (message, F("default_sint64" ))); 2863 EXPECT_EQ( 46 , reflection->GetInt64 (message, F("default_sint64" )));
2724 EXPECT_EQ( 47 , reflection->GetUInt32(message, F("default_fixed32" ))); 2864 EXPECT_EQ( 47 , reflection->GetUInt32(message, F("default_fixed32" )));
2725 EXPECT_EQ( 48 , reflection->GetUInt64(message, F("default_fixed64" ))); 2865 EXPECT_EQ( 48 , reflection->GetUInt64(message, F("default_fixed64" )));
2726 EXPECT_EQ( 49 , reflection->GetInt32 (message, F("default_sfixed32"))); 2866 EXPECT_EQ( 49 , reflection->GetInt32 (message, F("default_sfixed32")));
2727 EXPECT_EQ(-50 , reflection->GetInt64 (message, F("default_sfixed64"))); 2867 EXPECT_EQ(-50 , reflection->GetInt64 (message, F("default_sfixed64")));
2728 EXPECT_EQ( 51.5 , reflection->GetFloat (message, F("default_float" ))); 2868 EXPECT_EQ( 51.5 , reflection->GetFloat (message, F("default_float" )));
2729 EXPECT_EQ( 52e3 , reflection->GetDouble(message, F("default_double" ))); 2869 EXPECT_EQ( 52e3 , reflection->GetDouble(message, F("default_double" )));
2730 EXPECT_EQ(true , reflection->GetBool (message, F("default_bool" ))); 2870 EXPECT_EQ(true , reflection->GetBool (message, F("default_bool" )));
2731 EXPECT_EQ("hello", reflection->GetString(message, F("default_string" ))); 2871 EXPECT_EQ("hello", reflection->GetString(message, F("default_string" )));
2732 EXPECT_EQ("world", reflection->GetString(message, F("default_bytes" ))); 2872 EXPECT_EQ("world", reflection->GetString(message, F("default_bytes" )));
2733 2873
2734 EXPECT_EQ("hello", reflection->GetStringReference(message, F("default_string"), &scratch)); 2874 EXPECT_EQ("hello", reflection->GetStringReference(message, F("default_string"), &scratch));
2735 EXPECT_EQ("world", reflection->GetStringReference(message, F("default_bytes" ), &scratch)); 2875 EXPECT_EQ("world", reflection->GetStringReference(message, F("default_bytes" ), &scratch));
2736 2876
2737 EXPECT_EQ( nested_bar_, reflection->GetEnum(message, F("default_nested_enum" ))); 2877 EXPECT_EQ( nested_bar_, reflection->GetEnum(message, F("default_nested_enum" )));
2738 EXPECT_EQ(foreign_bar_, reflection->GetEnum(message, F("default_foreign_enum"))); 2878 EXPECT_EQ(foreign_bar_, reflection->GetEnum(message, F("default_foreign_enum")));
2739 EXPECT_EQ( import_bar_, reflection->GetEnum(message, F("default_import_enum" ))); 2879 EXPECT_EQ( import_bar_, reflection->GetEnum(message, F("default_import_enum" )));
2740 2880
2741 EXPECT_EQ("abc", reflection->GetString(message, F("default_string_piece"))); 2881 EXPECT_EQ("abc", reflection->GetString(message, F("default_string_piece")));
2742 EXPECT_EQ("abc", reflection->GetStringReference(message, F("default_string_piece"), &scratch)); 2882 EXPECT_EQ("abc", reflection->GetStringReference(message, F("default_string_piece"), &scratch));
2743 2883
2744 EXPECT_EQ("123", reflection->GetString(message, F("default_cord"))); 2884 EXPECT_EQ("123", reflection->GetString(message, F("default_cord")));
2745 EXPECT_EQ("123", reflection->GetStringReference(message, F("default_cord"), &scratch)); 2885 EXPECT_EQ("123", reflection->GetStringReference(message, F("default_cord"), &scratch));
2746 } 2886 }
2747 2887
2748 void TestUtil::ReflectionTester::ExpectPackedClearViaReflection( 2888 void TestUtil::ReflectionTester::ExpectPackedClearViaReflection(
2749 const Message& message) { 2889 const Message& message) {
2750 const Reflection* reflection = message.GetReflection(); 2890 const Reflection* reflection = message.GetReflection();
2751 2891
2752 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_int32" ))); 2892 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_int32" )));
2753 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_int64" ))); 2893 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_int64" )));
2754 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_uint32" ))); 2894 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_uint32" )));
2755 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_uint64" ))); 2895 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_uint64" )));
2756 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_sint32" ))); 2896 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_sint32" )));
2757 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_sint64" ))); 2897 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_sint64" )));
2758 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_fixed32" ))); 2898 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_fixed32" )));
2759 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_fixed64" ))); 2899 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_fixed64" )));
2760 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_sfixed32"))); 2900 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_sfixed32")));
2761 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_sfixed64"))); 2901 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_sfixed64")));
2762 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_float" ))); 2902 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_float" )));
2763 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_double" ))); 2903 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_double" )));
2764 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_bool" ))); 2904 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_bool" )));
2765 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_enum" ))); 2905 EXPECT_EQ(0, reflection->FieldSize(message, F("packed_enum" )));
2766 } 2906 }
2767 2907
2768 // ------------------------------------------------------------------- 2908 // -------------------------------------------------------------------
2769 2909
2770 void TestUtil::ReflectionTester::ModifyRepeatedFieldsViaReflection( 2910 void TestUtil::ReflectionTester::ModifyRepeatedFieldsViaReflection(
2771 Message* message) { 2911 Message* message) {
2772 const Reflection* reflection = message->GetReflection(); 2912 const Reflection* reflection = message->GetReflection();
2773 Message* sub_message; 2913 Message* sub_message;
2774 2914
2775 reflection->SetRepeatedInt32 (message, F("repeated_int32" ), 1, 501); 2915 reflection->SetRepeatedInt32 (message, F("repeated_int32" ), 1, 501);
2776 reflection->SetRepeatedInt64 (message, F("repeated_int64" ), 1, 502); 2916 reflection->SetRepeatedInt64 (message, F("repeated_int64" ), 1, 502);
2777 reflection->SetRepeatedUInt32(message, F("repeated_uint32" ), 1, 503); 2917 reflection->SetRepeatedUInt32(message, F("repeated_uint32" ), 1, 503);
2778 reflection->SetRepeatedUInt64(message, F("repeated_uint64" ), 1, 504); 2918 reflection->SetRepeatedUInt64(message, F("repeated_uint64" ), 1, 504);
2779 reflection->SetRepeatedInt32 (message, F("repeated_sint32" ), 1, 505); 2919 reflection->SetRepeatedInt32 (message, F("repeated_sint32" ), 1, 505);
2780 reflection->SetRepeatedInt64 (message, F("repeated_sint64" ), 1, 506); 2920 reflection->SetRepeatedInt64 (message, F("repeated_sint64" ), 1, 506);
2781 reflection->SetRepeatedUInt32(message, F("repeated_fixed32" ), 1, 507); 2921 reflection->SetRepeatedUInt32(message, F("repeated_fixed32" ), 1, 507);
2782 reflection->SetRepeatedUInt64(message, F("repeated_fixed64" ), 1, 508); 2922 reflection->SetRepeatedUInt64(message, F("repeated_fixed64" ), 1, 508);
2783 reflection->SetRepeatedInt32 (message, F("repeated_sfixed32"), 1, 509); 2923 reflection->SetRepeatedInt32 (message, F("repeated_sfixed32"), 1, 509);
2784 reflection->SetRepeatedInt64 (message, F("repeated_sfixed64"), 1, 510); 2924 reflection->SetRepeatedInt64 (message, F("repeated_sfixed64"), 1, 510);
2785 reflection->SetRepeatedFloat (message, F("repeated_float" ), 1, 511); 2925 reflection->SetRepeatedFloat (message, F("repeated_float" ), 1, 511);
2786 reflection->SetRepeatedDouble(message, F("repeated_double" ), 1, 512); 2926 reflection->SetRepeatedDouble(message, F("repeated_double" ), 1, 512);
2787 reflection->SetRepeatedBool (message, F("repeated_bool" ), 1, true); 2927 reflection->SetRepeatedBool (message, F("repeated_bool" ), 1, true);
2788 reflection->SetRepeatedString(message, F("repeated_string" ), 1, "515"); 2928 reflection->SetRepeatedString(message, F("repeated_string" ), 1, "515");
2789 reflection->SetRepeatedString(message, F("repeated_bytes" ), 1, "516"); 2929 reflection->SetRepeatedString(message, F("repeated_bytes" ), 1, "516");
2790 2930
2791 sub_message = reflection->MutableRepeatedMessage(message, F("repeatedgroup"), 1); 2931 sub_message = reflection->MutableRepeatedMessage(message, F("repeatedgroup"), 1);
2792 sub_message->GetReflection()->SetInt32(sub_message, repeated_group_a_, 517); 2932 sub_message->GetReflection()->SetInt32(sub_message, repeated_group_a_, 517);
2793 sub_message = reflection->MutableRepeatedMessage(message, F("repeated_nested_message"), 1); 2933 sub_message = reflection->MutableRepeatedMessage(message, F("repeated_nested_message"), 1);
2794 sub_message->GetReflection()->SetInt32(sub_message, nested_b_, 518); 2934 sub_message->GetReflection()->SetInt32(sub_message, nested_b_, 518);
2795 sub_message = reflection->MutableRepeatedMessage(message, F("repeated_foreign_message"), 1); 2935 sub_message = reflection->MutableRepeatedMessage(message, F("repeated_foreign_message"), 1);
2796 sub_message->GetReflection()->SetInt32(sub_message, foreign_c_, 519); 2936 sub_message->GetReflection()->SetInt32(sub_message, foreign_c_, 519);
2797 sub_message = reflection->MutableRepeatedMessage(message, F("repeated_import_message"), 1); 2937 sub_message = reflection->MutableRepeatedMessage(message, F("repeated_import_message"), 1);
2798 sub_message->GetReflection()->SetInt32(sub_message, import_d_, 520); 2938 sub_message->GetReflection()->SetInt32(sub_message, import_d_, 520);
2939 sub_message = reflection->MutableRepeatedMessage(message, F("repeated_lazy_message"), 1);
2940 sub_message->GetReflection()->SetInt32(sub_message, nested_b_, 527);
2799 2941
2800 reflection->SetRepeatedEnum(message, F("repeated_nested_enum" ), 1, nested_foo_); 2942 reflection->SetRepeatedEnum(message, F("repeated_nested_enum" ), 1, nested_foo_);
2801 reflection->SetRepeatedEnum(message, F("repeated_foreign_enum"), 1, foreign_foo_); 2943 reflection->SetRepeatedEnum(message, F("repeated_foreign_enum"), 1, foreign_foo_);
2802 reflection->SetRepeatedEnum(message, F("repeated_import_enum" ), 1, import_foo_); 2944 reflection->SetRepeatedEnum(message, F("repeated_import_enum" ), 1, import_foo_);
2803 2945
2804 reflection->SetRepeatedString(message, F("repeated_string_piece"), 1, "524"); 2946 reflection->SetRepeatedString(message, F("repeated_string_piece"), 1, "524");
2805 reflection->SetRepeatedString(message, F("repeated_cord"), 1, "525"); 2947 reflection->SetRepeatedString(message, F("repeated_cord"), 1, "525");
2806 } 2948 }
2807 2949
2808 void TestUtil::ReflectionTester::ModifyPackedFieldsViaReflection( 2950 void TestUtil::ReflectionTester::ModifyPackedFieldsViaReflection(
2809 Message* message) { 2951 Message* message) {
2810 const Reflection* reflection = message->GetReflection(); 2952 const Reflection* reflection = message->GetReflection();
2811 reflection->SetRepeatedInt32 (message, F("packed_int32" ), 1, 801); 2953 reflection->SetRepeatedInt32 (message, F("packed_int32" ), 1, 801);
2812 reflection->SetRepeatedInt64 (message, F("packed_int64" ), 1, 802); 2954 reflection->SetRepeatedInt64 (message, F("packed_int64" ), 1, 802);
2813 reflection->SetRepeatedUInt32(message, F("packed_uint32" ), 1, 803); 2955 reflection->SetRepeatedUInt32(message, F("packed_uint32" ), 1, 803);
2814 reflection->SetRepeatedUInt64(message, F("packed_uint64" ), 1, 804); 2956 reflection->SetRepeatedUInt64(message, F("packed_uint64" ), 1, 804);
2815 reflection->SetRepeatedInt32 (message, F("packed_sint32" ), 1, 805); 2957 reflection->SetRepeatedInt32 (message, F("packed_sint32" ), 1, 805);
2816 reflection->SetRepeatedInt64 (message, F("packed_sint64" ), 1, 806); 2958 reflection->SetRepeatedInt64 (message, F("packed_sint64" ), 1, 806);
2817 reflection->SetRepeatedUInt32(message, F("packed_fixed32" ), 1, 807); 2959 reflection->SetRepeatedUInt32(message, F("packed_fixed32" ), 1, 807);
2818 reflection->SetRepeatedUInt64(message, F("packed_fixed64" ), 1, 808); 2960 reflection->SetRepeatedUInt64(message, F("packed_fixed64" ), 1, 808);
2819 reflection->SetRepeatedInt32 (message, F("packed_sfixed32"), 1, 809); 2961 reflection->SetRepeatedInt32 (message, F("packed_sfixed32"), 1, 809);
2820 reflection->SetRepeatedInt64 (message, F("packed_sfixed64"), 1, 810); 2962 reflection->SetRepeatedInt64 (message, F("packed_sfixed64"), 1, 810);
2821 reflection->SetRepeatedFloat (message, F("packed_float" ), 1, 811); 2963 reflection->SetRepeatedFloat (message, F("packed_float" ), 1, 811);
2822 reflection->SetRepeatedDouble(message, F("packed_double" ), 1, 812); 2964 reflection->SetRepeatedDouble(message, F("packed_double" ), 1, 812);
2823 reflection->SetRepeatedBool (message, F("packed_bool" ), 1, true); 2965 reflection->SetRepeatedBool (message, F("packed_bool" ), 1, true);
2824 reflection->SetRepeatedEnum (message, F("packed_enum" ), 1, foreign_foo_); 2966 reflection->SetRepeatedEnum (message, F("packed_enum" ), 1, foreign_foo_);
2825 } 2967 }
2826 2968
2827 void TestUtil::ReflectionTester::RemoveLastRepeatedsViaReflection(Message* message) { 2969 void TestUtil::ReflectionTester::RemoveLastRepeatedsViaReflection(
2970 Message* message) {
2828 const Reflection* reflection = message->GetReflection(); 2971 const Reflection* reflection = message->GetReflection();
2829 2972
2830 vector<const FieldDescriptor*> output; 2973 vector<const FieldDescriptor*> output;
2831 reflection->ListFields(*message, &output); 2974 reflection->ListFields(*message, &output);
2832 for (int i=0; i<output.size(); ++i) { 2975 for (int i=0; i<output.size(); ++i) {
2833 const FieldDescriptor* field = output[i]; 2976 const FieldDescriptor* field = output[i];
2834 if (!field->is_repeated()) continue; 2977 if (!field->is_repeated()) continue;
2835 2978
2836 reflection->RemoveLast(message, field); 2979 reflection->RemoveLast(message, field);
2837 } 2980 }
2838 } 2981 }
2982
2983 void TestUtil::ReflectionTester::ReleaseLastRepeatedsViaReflection(
2984 Message* message, bool expect_extensions_notnull) {
2985 const Reflection* reflection = message->GetReflection();
2986
2987 vector<const FieldDescriptor*> output;
2988 reflection->ListFields(*message, &output);
2989 for (int i=0; i<output.size(); ++i) {
2990 const FieldDescriptor* field = output[i];
2991 if (!field->is_repeated()) continue;
2992 if (field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) continue;
2993
2994 Message* released = reflection->ReleaseLast(message, field);
2995 if (!field->is_extension() || expect_extensions_notnull) {
2996 ASSERT_TRUE(released != NULL) << "ReleaseLast returned NULL for: "
2997 << field->name();
2998 }
2999 delete released;
3000 }
3001 }
2839 3002
2840 void TestUtil::ReflectionTester::SwapRepeatedsViaReflection(Message* message) { 3003 void TestUtil::ReflectionTester::SwapRepeatedsViaReflection(Message* message) {
2841 const Reflection* reflection = message->GetReflection(); 3004 const Reflection* reflection = message->GetReflection();
2842 3005
2843 vector<const FieldDescriptor*> output; 3006 vector<const FieldDescriptor*> output;
2844 reflection->ListFields(*message, &output); 3007 reflection->ListFields(*message, &output);
2845 for (int i=0; i<output.size(); ++i) { 3008 for (int i=0; i<output.size(); ++i) {
2846 const FieldDescriptor* field = output[i]; 3009 const FieldDescriptor* field = output[i];
2847 if (!field->is_repeated()) continue; 3010 if (!field->is_repeated()) continue;
2848 3011
2849 reflection->SwapElements(message, field, 0, 1); 3012 reflection->SwapElements(message, field, 0, 1);
2850 } 3013 }
2851 } 3014 }
3015
3016 void TestUtil::ReflectionTester::ExpectMessagesReleasedViaReflection(
3017 Message* message,
3018 TestUtil::ReflectionTester::MessageReleaseState expected_release_state) {
3019 const Reflection* reflection = message->GetReflection();
3020
3021 static const char* fields[] = {
3022 "optionalgroup",
3023 "optional_nested_message",
3024 "optional_foreign_message",
3025 "optional_import_message",
3026 };
3027 for (int i = 0; i < GOOGLE_ARRAYSIZE(fields); i++) {
3028 const Message& sub_message = reflection->GetMessage(*message, F(fields[i]));
3029 Message* released = reflection->ReleaseMessage(message, F(fields[i]));
3030 switch (expected_release_state) {
3031 case IS_NULL:
3032 EXPECT_TRUE(released == NULL);
3033 break;
3034 case NOT_NULL:
3035 EXPECT_TRUE(released != NULL);
3036 EXPECT_EQ(&sub_message, released);
3037 break;
3038 case CAN_BE_NULL:
3039 break;
3040 }
3041 delete released;
3042 EXPECT_FALSE(reflection->HasField(*message, F(fields[i])));
3043 }
3044 }
2852 3045
2853 } // namespace protobuf 3046 } // namespace protobuf
2854 } // namespace google 3047 } // namespace google
Powered by Google Project Hosting