1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 // Author: kenton@google.com (Kenton Varda)
32 // Based on original Protocol Buffers design by
33 // Sanjay Ghemawat, Jeff Dean, and others.
34
35 #include <google/protobuf/test_util_lite.h>
36 #include <google/protobuf/stubs/logging.h>
37 #include <google/protobuf/stubs/common.h>
38
39
40 #define EXPECT_TRUE GOOGLE_CHECK
41 #define ASSERT_TRUE GOOGLE_CHECK
42 #define EXPECT_FALSE(COND) GOOGLE_CHECK(!(COND))
43 #define EXPECT_EQ GOOGLE_CHECK_EQ
44 #define ASSERT_EQ GOOGLE_CHECK_EQ
45
46 namespace google {
47 namespace protobuf {
48
SetAllFields(unittest::TestAllTypesLite * message)49 void TestUtilLite::SetAllFields(unittest::TestAllTypesLite* message) {
50 message->set_optional_int32 (101);
51 message->set_optional_int64 (102);
52 message->set_optional_uint32 (103);
53 message->set_optional_uint64 (104);
54 message->set_optional_sint32 (105);
55 message->set_optional_sint64 (106);
56 message->set_optional_fixed32 (107);
57 message->set_optional_fixed64 (108);
58 message->set_optional_sfixed32(109);
59 message->set_optional_sfixed64(110);
60 message->set_optional_float (111);
61 message->set_optional_double (112);
62 message->set_optional_bool (true);
63 message->set_optional_string ("115");
64 message->set_optional_bytes ("116");
65
66 message->mutable_optionalgroup ()->set_a(117);
67 message->mutable_optional_nested_message ()->set_bb(118);
68 message->mutable_optional_foreign_message ()->set_c(119);
69 message->mutable_optional_import_message ()->set_d(120);
70 message->mutable_optional_public_import_message()->set_e(126);
71 message->mutable_optional_lazy_message ()->set_bb(127);
72
73 message->set_optional_nested_enum (unittest::TestAllTypesLite::BAZ );
74 message->set_optional_foreign_enum(unittest::FOREIGN_LITE_BAZ );
75 message->set_optional_import_enum (unittest_import::IMPORT_LITE_BAZ);
76
77
78 // -----------------------------------------------------------------
79
80 message->add_repeated_int32 (201);
81 message->add_repeated_int64 (202);
82 message->add_repeated_uint32 (203);
83 message->add_repeated_uint64 (204);
84 message->add_repeated_sint32 (205);
85 message->add_repeated_sint64 (206);
86 message->add_repeated_fixed32 (207);
87 message->add_repeated_fixed64 (208);
88 message->add_repeated_sfixed32(209);
89 message->add_repeated_sfixed64(210);
90 message->add_repeated_float (211);
91 message->add_repeated_double (212);
92 message->add_repeated_bool (true);
93 message->add_repeated_string ("215");
94 message->add_repeated_bytes ("216");
95
96 message->add_repeatedgroup ()->set_a(217);
97 message->add_repeated_nested_message ()->set_bb(218);
98 message->add_repeated_foreign_message()->set_c(219);
99 message->add_repeated_import_message ()->set_d(220);
100 message->add_repeated_lazy_message ()->set_bb(227);
101
102 message->add_repeated_nested_enum (unittest::TestAllTypesLite::BAR );
103 message->add_repeated_foreign_enum(unittest::FOREIGN_LITE_BAR );
104 message->add_repeated_import_enum (unittest_import::IMPORT_LITE_BAR);
105
106
107 // Add a second one of each field.
108 message->add_repeated_int32 (301);
109 message->add_repeated_int64 (302);
110 message->add_repeated_uint32 (303);
111 message->add_repeated_uint64 (304);
112 message->add_repeated_sint32 (305);
113 message->add_repeated_sint64 (306);
114 message->add_repeated_fixed32 (307);
115 message->add_repeated_fixed64 (308);
116 message->add_repeated_sfixed32(309);
117 message->add_repeated_sfixed64(310);
118 message->add_repeated_float (311);
119 message->add_repeated_double (312);
120 message->add_repeated_bool (false);
121 message->add_repeated_string ("315");
122 message->add_repeated_bytes ("316");
123
124 message->add_repeatedgroup ()->set_a(317);
125 message->add_repeated_nested_message ()->set_bb(318);
126 message->add_repeated_foreign_message()->set_c(319);
127 message->add_repeated_import_message ()->set_d(320);
128 message->add_repeated_lazy_message ()->set_bb(327);
129
130 message->add_repeated_nested_enum (unittest::TestAllTypesLite::BAZ );
131 message->add_repeated_foreign_enum(unittest::FOREIGN_LITE_BAZ );
132 message->add_repeated_import_enum (unittest_import::IMPORT_LITE_BAZ);
133
134
135 // -----------------------------------------------------------------
136
137 message->set_default_int32 (401);
138 message->set_default_int64 (402);
139 message->set_default_uint32 (403);
140 message->set_default_uint64 (404);
141 message->set_default_sint32 (405);
142 message->set_default_sint64 (406);
143 message->set_default_fixed32 (407);
144 message->set_default_fixed64 (408);
145 message->set_default_sfixed32(409);
146 message->set_default_sfixed64(410);
147 message->set_default_float (411);
148 message->set_default_double (412);
149 message->set_default_bool (false);
150 message->set_default_string ("415");
151 message->set_default_bytes ("416");
152
153 message->set_default_nested_enum (unittest::TestAllTypesLite::FOO );
154 message->set_default_foreign_enum(unittest::FOREIGN_LITE_FOO );
155 message->set_default_import_enum (unittest_import::IMPORT_LITE_FOO);
156
157
158 message->set_oneof_uint32(601);
159 message->mutable_oneof_nested_message()->set_bb(602);
160 message->set_oneof_string("603");
161 message->set_oneof_bytes("604");
162 }
163
164 // -------------------------------------------------------------------
165
ModifyRepeatedFields(unittest::TestAllTypesLite * message)166 void TestUtilLite::ModifyRepeatedFields(unittest::TestAllTypesLite* message) {
167 message->set_repeated_int32 (1, 501);
168 message->set_repeated_int64 (1, 502);
169 message->set_repeated_uint32 (1, 503);
170 message->set_repeated_uint64 (1, 504);
171 message->set_repeated_sint32 (1, 505);
172 message->set_repeated_sint64 (1, 506);
173 message->set_repeated_fixed32 (1, 507);
174 message->set_repeated_fixed64 (1, 508);
175 message->set_repeated_sfixed32(1, 509);
176 message->set_repeated_sfixed64(1, 510);
177 message->set_repeated_float (1, 511);
178 message->set_repeated_double (1, 512);
179 message->set_repeated_bool (1, true);
180 message->set_repeated_string (1, "515");
181 message->set_repeated_bytes (1, "516");
182
183 message->mutable_repeatedgroup (1)->set_a(517);
184 message->mutable_repeated_nested_message (1)->set_bb(518);
185 message->mutable_repeated_foreign_message(1)->set_c(519);
186 message->mutable_repeated_import_message (1)->set_d(520);
187 message->mutable_repeated_lazy_message (1)->set_bb(527);
188
189 message->set_repeated_nested_enum (1, unittest::TestAllTypesLite::FOO );
190 message->set_repeated_foreign_enum(1, unittest::FOREIGN_LITE_FOO );
191 message->set_repeated_import_enum (1, unittest_import::IMPORT_LITE_FOO);
192
193 }
194
195 // -------------------------------------------------------------------
196
ExpectAllFieldsSet(const unittest::TestAllTypesLite & message)197 void TestUtilLite::ExpectAllFieldsSet(
198 const unittest::TestAllTypesLite& message) {
199 EXPECT_TRUE(message.has_optional_int32 ());
200 EXPECT_TRUE(message.has_optional_int64 ());
201 EXPECT_TRUE(message.has_optional_uint32 ());
202 EXPECT_TRUE(message.has_optional_uint64 ());
203 EXPECT_TRUE(message.has_optional_sint32 ());
204 EXPECT_TRUE(message.has_optional_sint64 ());
205 EXPECT_TRUE(message.has_optional_fixed32 ());
206 EXPECT_TRUE(message.has_optional_fixed64 ());
207 EXPECT_TRUE(message.has_optional_sfixed32());
208 EXPECT_TRUE(message.has_optional_sfixed64());
209 EXPECT_TRUE(message.has_optional_float ());
210 EXPECT_TRUE(message.has_optional_double ());
211 EXPECT_TRUE(message.has_optional_bool ());
212 EXPECT_TRUE(message.has_optional_string ());
213 EXPECT_TRUE(message.has_optional_bytes ());
214
215 EXPECT_TRUE(message.has_optionalgroup ());
216 EXPECT_TRUE(message.has_optional_nested_message ());
217 EXPECT_TRUE(message.has_optional_foreign_message ());
218 EXPECT_TRUE(message.has_optional_import_message ());
219 EXPECT_TRUE(message.has_optional_public_import_message());
220 EXPECT_TRUE(message.has_optional_lazy_message ());
221
222 EXPECT_TRUE(message.optionalgroup ().has_a());
223 EXPECT_TRUE(message.optional_nested_message ().has_bb());
224 EXPECT_TRUE(message.optional_foreign_message ().has_c());
225 EXPECT_TRUE(message.optional_import_message ().has_d());
226 EXPECT_TRUE(message.optional_public_import_message().has_e());
227 EXPECT_TRUE(message.optional_lazy_message ().has_bb());
228
229 EXPECT_TRUE(message.has_optional_nested_enum ());
230 EXPECT_TRUE(message.has_optional_foreign_enum());
231 EXPECT_TRUE(message.has_optional_import_enum ());
232
233
234 EXPECT_EQ(101 , message.optional_int32 ());
235 EXPECT_EQ(102 , message.optional_int64 ());
236 EXPECT_EQ(103 , message.optional_uint32 ());
237 EXPECT_EQ(104 , message.optional_uint64 ());
238 EXPECT_EQ(105 , message.optional_sint32 ());
239 EXPECT_EQ(106 , message.optional_sint64 ());
240 EXPECT_EQ(107 , message.optional_fixed32 ());
241 EXPECT_EQ(108 , message.optional_fixed64 ());
242 EXPECT_EQ(109 , message.optional_sfixed32());
243 EXPECT_EQ(110 , message.optional_sfixed64());
244 EXPECT_EQ(111 , message.optional_float ());
245 EXPECT_EQ(112 , message.optional_double ());
246 EXPECT_EQ(true , message.optional_bool ());
247 EXPECT_EQ("115", message.optional_string ());
248 EXPECT_EQ("116", message.optional_bytes ());
249
250 EXPECT_EQ(117, message.optionalgroup ().a());
251 EXPECT_EQ(118, message.optional_nested_message ().bb());
252 EXPECT_EQ(119, message.optional_foreign_message ().c());
253 EXPECT_EQ(120, message.optional_import_message ().d());
254 EXPECT_EQ(126, message.optional_public_import_message().e());
255 EXPECT_EQ(127, message.optional_lazy_message ().bb());
256
257 EXPECT_EQ(unittest::TestAllTypesLite::BAZ , message.optional_nested_enum ());
258 EXPECT_EQ(unittest::FOREIGN_LITE_BAZ , message.optional_foreign_enum());
259 EXPECT_EQ(unittest_import::IMPORT_LITE_BAZ, message.optional_import_enum ());
260
261
262 // -----------------------------------------------------------------
263
264 ASSERT_EQ(2, message.repeated_int32_size ());
265 ASSERT_EQ(2, message.repeated_int64_size ());
266 ASSERT_EQ(2, message.repeated_uint32_size ());
267 ASSERT_EQ(2, message.repeated_uint64_size ());
268 ASSERT_EQ(2, message.repeated_sint32_size ());
269 ASSERT_EQ(2, message.repeated_sint64_size ());
270 ASSERT_EQ(2, message.repeated_fixed32_size ());
271 ASSERT_EQ(2, message.repeated_fixed64_size ());
272 ASSERT_EQ(2, message.repeated_sfixed32_size());
273 ASSERT_EQ(2, message.repeated_sfixed64_size());
274 ASSERT_EQ(2, message.repeated_float_size ());
275 ASSERT_EQ(2, message.repeated_double_size ());
276 ASSERT_EQ(2, message.repeated_bool_size ());
277 ASSERT_EQ(2, message.repeated_string_size ());
278 ASSERT_EQ(2, message.repeated_bytes_size ());
279
280 ASSERT_EQ(2, message.repeatedgroup_size ());
281 ASSERT_EQ(2, message.repeated_nested_message_size ());
282 ASSERT_EQ(2, message.repeated_foreign_message_size());
283 ASSERT_EQ(2, message.repeated_import_message_size ());
284 ASSERT_EQ(2, message.repeated_lazy_message_size ());
285 ASSERT_EQ(2, message.repeated_nested_enum_size ());
286 ASSERT_EQ(2, message.repeated_foreign_enum_size ());
287 ASSERT_EQ(2, message.repeated_import_enum_size ());
288
289
290 EXPECT_EQ(201 , message.repeated_int32 (0));
291 EXPECT_EQ(202 , message.repeated_int64 (0));
292 EXPECT_EQ(203 , message.repeated_uint32 (0));
293 EXPECT_EQ(204 , message.repeated_uint64 (0));
294 EXPECT_EQ(205 , message.repeated_sint32 (0));
295 EXPECT_EQ(206 , message.repeated_sint64 (0));
296 EXPECT_EQ(207 , message.repeated_fixed32 (0));
297 EXPECT_EQ(208 , message.repeated_fixed64 (0));
298 EXPECT_EQ(209 , message.repeated_sfixed32(0));
299 EXPECT_EQ(210 , message.repeated_sfixed64(0));
300 EXPECT_EQ(211 , message.repeated_float (0));
301 EXPECT_EQ(212 , message.repeated_double (0));
302 EXPECT_EQ(true , message.repeated_bool (0));
303 EXPECT_EQ("215", message.repeated_string (0));
304 EXPECT_EQ("216", message.repeated_bytes (0));
305
306 EXPECT_EQ(217, message.repeatedgroup (0).a());
307 EXPECT_EQ(218, message.repeated_nested_message (0).bb());
308 EXPECT_EQ(219, message.repeated_foreign_message(0).c());
309 EXPECT_EQ(220, message.repeated_import_message (0).d());
310 EXPECT_EQ(227, message.repeated_lazy_message (0).bb());
311
312
313 EXPECT_EQ(unittest::TestAllTypesLite::BAR , message.repeated_nested_enum (0));
314 EXPECT_EQ(unittest::FOREIGN_LITE_BAR , message.repeated_foreign_enum(0));
315 EXPECT_EQ(unittest_import::IMPORT_LITE_BAR, message.repeated_import_enum (0));
316
317 EXPECT_EQ(301 , message.repeated_int32 (1));
318 EXPECT_EQ(302 , message.repeated_int64 (1));
319 EXPECT_EQ(303 , message.repeated_uint32 (1));
320 EXPECT_EQ(304 , message.repeated_uint64 (1));
321 EXPECT_EQ(305 , message.repeated_sint32 (1));
322 EXPECT_EQ(306 , message.repeated_sint64 (1));
323 EXPECT_EQ(307 , message.repeated_fixed32 (1));
324 EXPECT_EQ(308 , message.repeated_fixed64 (1));
325 EXPECT_EQ(309 , message.repeated_sfixed32(1));
326 EXPECT_EQ(310 , message.repeated_sfixed64(1));
327 EXPECT_EQ(311 , message.repeated_float (1));
328 EXPECT_EQ(312 , message.repeated_double (1));
329 EXPECT_EQ(false, message.repeated_bool (1));
330 EXPECT_EQ("315", message.repeated_string (1));
331 EXPECT_EQ("316", message.repeated_bytes (1));
332
333 EXPECT_EQ(317, message.repeatedgroup (1).a());
334 EXPECT_EQ(318, message.repeated_nested_message (1).bb());
335 EXPECT_EQ(319, message.repeated_foreign_message(1).c());
336 EXPECT_EQ(320, message.repeated_import_message (1).d());
337 EXPECT_EQ(327, message.repeated_lazy_message (1).bb());
338
339 EXPECT_EQ(unittest::TestAllTypesLite::BAZ , message.repeated_nested_enum (1));
340 EXPECT_EQ(unittest::FOREIGN_LITE_BAZ , message.repeated_foreign_enum(1));
341 EXPECT_EQ(unittest_import::IMPORT_LITE_BAZ, message.repeated_import_enum (1));
342
343
344 // -----------------------------------------------------------------
345
346 EXPECT_TRUE(message.has_default_int32 ());
347 EXPECT_TRUE(message.has_default_int64 ());
348 EXPECT_TRUE(message.has_default_uint32 ());
349 EXPECT_TRUE(message.has_default_uint64 ());
350 EXPECT_TRUE(message.has_default_sint32 ());
351 EXPECT_TRUE(message.has_default_sint64 ());
352 EXPECT_TRUE(message.has_default_fixed32 ());
353 EXPECT_TRUE(message.has_default_fixed64 ());
354 EXPECT_TRUE(message.has_default_sfixed32());
355 EXPECT_TRUE(message.has_default_sfixed64());
356 EXPECT_TRUE(message.has_default_float ());
357 EXPECT_TRUE(message.has_default_double ());
358 EXPECT_TRUE(message.has_default_bool ());
359 EXPECT_TRUE(message.has_default_string ());
360 EXPECT_TRUE(message.has_default_bytes ());
361
362 EXPECT_TRUE(message.has_default_nested_enum ());
363 EXPECT_TRUE(message.has_default_foreign_enum());
364 EXPECT_TRUE(message.has_default_import_enum ());
365
366
367 EXPECT_EQ(401 , message.default_int32 ());
368 EXPECT_EQ(402 , message.default_int64 ());
369 EXPECT_EQ(403 , message.default_uint32 ());
370 EXPECT_EQ(404 , message.default_uint64 ());
371 EXPECT_EQ(405 , message.default_sint32 ());
372 EXPECT_EQ(406 , message.default_sint64 ());
373 EXPECT_EQ(407 , message.default_fixed32 ());
374 EXPECT_EQ(408 , message.default_fixed64 ());
375 EXPECT_EQ(409 , message.default_sfixed32());
376 EXPECT_EQ(410 , message.default_sfixed64());
377 EXPECT_EQ(411 , message.default_float ());
378 EXPECT_EQ(412 , message.default_double ());
379 EXPECT_EQ(false, message.default_bool ());
380 EXPECT_EQ("415", message.default_string ());
381 EXPECT_EQ("416", message.default_bytes ());
382
383 EXPECT_EQ(unittest::TestAllTypesLite::FOO , message.default_nested_enum ());
384 EXPECT_EQ(unittest::FOREIGN_LITE_FOO , message.default_foreign_enum());
385 EXPECT_EQ(unittest_import::IMPORT_LITE_FOO, message.default_import_enum ());
386
387
388 EXPECT_FALSE(message.has_oneof_uint32 ());
389 EXPECT_FALSE(message.has_oneof_nested_message());
390 EXPECT_FALSE(message.has_oneof_string ());
391 EXPECT_TRUE(message.has_oneof_bytes ());
392
393 EXPECT_EQ("604", message.oneof_bytes());
394 }
395
396 // -------------------------------------------------------------------
397
ExpectClear(const unittest::TestAllTypesLite & message)398 void TestUtilLite::ExpectClear(const unittest::TestAllTypesLite& message) {
399 // has_blah() should initially be false for all optional fields.
400 EXPECT_FALSE(message.has_optional_int32 ());
401 EXPECT_FALSE(message.has_optional_int64 ());
402 EXPECT_FALSE(message.has_optional_uint32 ());
403 EXPECT_FALSE(message.has_optional_uint64 ());
404 EXPECT_FALSE(message.has_optional_sint32 ());
405 EXPECT_FALSE(message.has_optional_sint64 ());
406 EXPECT_FALSE(message.has_optional_fixed32 ());
407 EXPECT_FALSE(message.has_optional_fixed64 ());
408 EXPECT_FALSE(message.has_optional_sfixed32());
409 EXPECT_FALSE(message.has_optional_sfixed64());
410 EXPECT_FALSE(message.has_optional_float ());
411 EXPECT_FALSE(message.has_optional_double ());
412 EXPECT_FALSE(message.has_optional_bool ());
413 EXPECT_FALSE(message.has_optional_string ());
414 EXPECT_FALSE(message.has_optional_bytes ());
415
416 EXPECT_FALSE(message.has_optionalgroup ());
417 EXPECT_FALSE(message.has_optional_nested_message ());
418 EXPECT_FALSE(message.has_optional_foreign_message ());
419 EXPECT_FALSE(message.has_optional_import_message ());
420 EXPECT_FALSE(message.has_optional_public_import_message());
421 EXPECT_FALSE(message.has_optional_lazy_message ());
422
423 EXPECT_FALSE(message.has_optional_nested_enum ());
424 EXPECT_FALSE(message.has_optional_foreign_enum());
425 EXPECT_FALSE(message.has_optional_import_enum ());
426
427
428 // Optional fields without defaults are set to zero or something like it.
429 EXPECT_EQ(0 , message.optional_int32 ());
430 EXPECT_EQ(0 , message.optional_int64 ());
431 EXPECT_EQ(0 , message.optional_uint32 ());
432 EXPECT_EQ(0 , message.optional_uint64 ());
433 EXPECT_EQ(0 , message.optional_sint32 ());
434 EXPECT_EQ(0 , message.optional_sint64 ());
435 EXPECT_EQ(0 , message.optional_fixed32 ());
436 EXPECT_EQ(0 , message.optional_fixed64 ());
437 EXPECT_EQ(0 , message.optional_sfixed32());
438 EXPECT_EQ(0 , message.optional_sfixed64());
439 EXPECT_EQ(0 , message.optional_float ());
440 EXPECT_EQ(0 , message.optional_double ());
441 EXPECT_EQ(false, message.optional_bool ());
442 EXPECT_EQ("" , message.optional_string ());
443 EXPECT_EQ("" , message.optional_bytes ());
444
445 // Embedded messages should also be clear.
446 EXPECT_FALSE(message.optionalgroup ().has_a());
447 EXPECT_FALSE(message.optional_nested_message ().has_bb());
448 EXPECT_FALSE(message.optional_foreign_message ().has_c());
449 EXPECT_FALSE(message.optional_import_message ().has_d());
450 EXPECT_FALSE(message.optional_public_import_message().has_e());
451 EXPECT_FALSE(message.optional_lazy_message ().has_bb());
452
453 EXPECT_EQ(0, message.optionalgroup ().a());
454 EXPECT_EQ(0, message.optional_nested_message ().bb());
455 EXPECT_EQ(0, message.optional_foreign_message().c());
456 EXPECT_EQ(0, message.optional_import_message ().d());
457
458 // Enums without defaults are set to the first value in the enum.
459 EXPECT_EQ(unittest::TestAllTypesLite::FOO , message.optional_nested_enum ());
460 EXPECT_EQ(unittest::FOREIGN_LITE_FOO , message.optional_foreign_enum());
461 EXPECT_EQ(unittest_import::IMPORT_LITE_FOO, message.optional_import_enum ());
462
463
464 // Repeated fields are empty.
465 EXPECT_EQ(0, message.repeated_int32_size ());
466 EXPECT_EQ(0, message.repeated_int64_size ());
467 EXPECT_EQ(0, message.repeated_uint32_size ());
468 EXPECT_EQ(0, message.repeated_uint64_size ());
469 EXPECT_EQ(0, message.repeated_sint32_size ());
470 EXPECT_EQ(0, message.repeated_sint64_size ());
471 EXPECT_EQ(0, message.repeated_fixed32_size ());
472 EXPECT_EQ(0, message.repeated_fixed64_size ());
473 EXPECT_EQ(0, message.repeated_sfixed32_size());
474 EXPECT_EQ(0, message.repeated_sfixed64_size());
475 EXPECT_EQ(0, message.repeated_float_size ());
476 EXPECT_EQ(0, message.repeated_double_size ());
477 EXPECT_EQ(0, message.repeated_bool_size ());
478 EXPECT_EQ(0, message.repeated_string_size ());
479 EXPECT_EQ(0, message.repeated_bytes_size ());
480
481 EXPECT_EQ(0, message.repeatedgroup_size ());
482 EXPECT_EQ(0, message.repeated_nested_message_size ());
483 EXPECT_EQ(0, message.repeated_foreign_message_size());
484 EXPECT_EQ(0, message.repeated_import_message_size ());
485 EXPECT_EQ(0, message.repeated_lazy_message_size ());
486 EXPECT_EQ(0, message.repeated_nested_enum_size ());
487 EXPECT_EQ(0, message.repeated_foreign_enum_size ());
488 EXPECT_EQ(0, message.repeated_import_enum_size ());
489
490
491 // has_blah() should also be false for all default fields.
492 EXPECT_FALSE(message.has_default_int32 ());
493 EXPECT_FALSE(message.has_default_int64 ());
494 EXPECT_FALSE(message.has_default_uint32 ());
495 EXPECT_FALSE(message.has_default_uint64 ());
496 EXPECT_FALSE(message.has_default_sint32 ());
497 EXPECT_FALSE(message.has_default_sint64 ());
498 EXPECT_FALSE(message.has_default_fixed32 ());
499 EXPECT_FALSE(message.has_default_fixed64 ());
500 EXPECT_FALSE(message.has_default_sfixed32());
501 EXPECT_FALSE(message.has_default_sfixed64());
502 EXPECT_FALSE(message.has_default_float ());
503 EXPECT_FALSE(message.has_default_double ());
504 EXPECT_FALSE(message.has_default_bool ());
505 EXPECT_FALSE(message.has_default_string ());
506 EXPECT_FALSE(message.has_default_bytes ());
507
508 EXPECT_FALSE(message.has_default_nested_enum ());
509 EXPECT_FALSE(message.has_default_foreign_enum());
510 EXPECT_FALSE(message.has_default_import_enum ());
511
512
513 // Fields with defaults have their default values (duh).
514 EXPECT_EQ( 41 , message.default_int32 ());
515 EXPECT_EQ( 42 , message.default_int64 ());
516 EXPECT_EQ( 43 , message.default_uint32 ());
517 EXPECT_EQ( 44 , message.default_uint64 ());
518 EXPECT_EQ(-45 , message.default_sint32 ());
519 EXPECT_EQ( 46 , message.default_sint64 ());
520 EXPECT_EQ( 47 , message.default_fixed32 ());
521 EXPECT_EQ( 48 , message.default_fixed64 ());
522 EXPECT_EQ( 49 , message.default_sfixed32());
523 EXPECT_EQ(-50 , message.default_sfixed64());
524 EXPECT_EQ( 51.5 , message.default_float ());
525 EXPECT_EQ( 52e3 , message.default_double ());
526 EXPECT_EQ(true , message.default_bool ());
527 EXPECT_EQ("hello", message.default_string ());
528 EXPECT_EQ("world", message.default_bytes ());
529
530 EXPECT_EQ(unittest::TestAllTypesLite::BAR , message.default_nested_enum ());
531 EXPECT_EQ(unittest::FOREIGN_LITE_BAR , message.default_foreign_enum());
532 EXPECT_EQ(unittest_import::IMPORT_LITE_BAR, message.default_import_enum ());
533
534
535 EXPECT_FALSE(message.has_oneof_uint32 ());
536 EXPECT_FALSE(message.has_oneof_nested_message());
537 EXPECT_FALSE(message.has_oneof_string ());
538 EXPECT_FALSE(message.has_oneof_bytes ());
539 }
540
541 // -------------------------------------------------------------------
542
ExpectRepeatedFieldsModified(const unittest::TestAllTypesLite & message)543 void TestUtilLite::ExpectRepeatedFieldsModified(
544 const unittest::TestAllTypesLite& message) {
545 // ModifyRepeatedFields only sets the second repeated element of each
546 // field. In addition to verifying this, we also verify that the first
547 // element and size were *not* modified.
548 ASSERT_EQ(2, message.repeated_int32_size ());
549 ASSERT_EQ(2, message.repeated_int64_size ());
550 ASSERT_EQ(2, message.repeated_uint32_size ());
551 ASSERT_EQ(2, message.repeated_uint64_size ());
552 ASSERT_EQ(2, message.repeated_sint32_size ());
553 ASSERT_EQ(2, message.repeated_sint64_size ());
554 ASSERT_EQ(2, message.repeated_fixed32_size ());
555 ASSERT_EQ(2, message.repeated_fixed64_size ());
556 ASSERT_EQ(2, message.repeated_sfixed32_size());
557 ASSERT_EQ(2, message.repeated_sfixed64_size());
558 ASSERT_EQ(2, message.repeated_float_size ());
559 ASSERT_EQ(2, message.repeated_double_size ());
560 ASSERT_EQ(2, message.repeated_bool_size ());
561 ASSERT_EQ(2, message.repeated_string_size ());
562 ASSERT_EQ(2, message.repeated_bytes_size ());
563
564 ASSERT_EQ(2, message.repeatedgroup_size ());
565 ASSERT_EQ(2, message.repeated_nested_message_size ());
566 ASSERT_EQ(2, message.repeated_foreign_message_size());
567 ASSERT_EQ(2, message.repeated_import_message_size ());
568 ASSERT_EQ(2, message.repeated_lazy_message_size ());
569 ASSERT_EQ(2, message.repeated_nested_enum_size ());
570 ASSERT_EQ(2, message.repeated_foreign_enum_size ());
571 ASSERT_EQ(2, message.repeated_import_enum_size ());
572
573
574 EXPECT_EQ(201 , message.repeated_int32 (0));
575 EXPECT_EQ(202 , message.repeated_int64 (0));
576 EXPECT_EQ(203 , message.repeated_uint32 (0));
577 EXPECT_EQ(204 , message.repeated_uint64 (0));
578 EXPECT_EQ(205 , message.repeated_sint32 (0));
579 EXPECT_EQ(206 , message.repeated_sint64 (0));
580 EXPECT_EQ(207 , message.repeated_fixed32 (0));
581 EXPECT_EQ(208 , message.repeated_fixed64 (0));
582 EXPECT_EQ(209 , message.repeated_sfixed32(0));
583 EXPECT_EQ(210 , message.repeated_sfixed64(0));
584 EXPECT_EQ(211 , message.repeated_float (0));
585 EXPECT_EQ(212 , message.repeated_double (0));
586 EXPECT_EQ(true , message.repeated_bool (0));
587 EXPECT_EQ("215", message.repeated_string (0));
588 EXPECT_EQ("216", message.repeated_bytes (0));
589
590 EXPECT_EQ(217, message.repeatedgroup (0).a());
591 EXPECT_EQ(218, message.repeated_nested_message (0).bb());
592 EXPECT_EQ(219, message.repeated_foreign_message(0).c());
593 EXPECT_EQ(220, message.repeated_import_message (0).d());
594 EXPECT_EQ(227, message.repeated_lazy_message (0).bb());
595
596 EXPECT_EQ(unittest::TestAllTypesLite::BAR , message.repeated_nested_enum (0));
597 EXPECT_EQ(unittest::FOREIGN_LITE_BAR , message.repeated_foreign_enum(0));
598 EXPECT_EQ(unittest_import::IMPORT_LITE_BAR, message.repeated_import_enum (0));
599
600
601 // Actually verify the second (modified) elements now.
602 EXPECT_EQ(501 , message.repeated_int32 (1));
603 EXPECT_EQ(502 , message.repeated_int64 (1));
604 EXPECT_EQ(503 , message.repeated_uint32 (1));
605 EXPECT_EQ(504 , message.repeated_uint64 (1));
606 EXPECT_EQ(505 , message.repeated_sint32 (1));
607 EXPECT_EQ(506 , message.repeated_sint64 (1));
608 EXPECT_EQ(507 , message.repeated_fixed32 (1));
609 EXPECT_EQ(508 , message.repeated_fixed64 (1));
610 EXPECT_EQ(509 , message.repeated_sfixed32(1));
611 EXPECT_EQ(510 , message.repeated_sfixed64(1));
612 EXPECT_EQ(511 , message.repeated_float (1));
613 EXPECT_EQ(512 , message.repeated_double (1));
614 EXPECT_EQ(true , message.repeated_bool (1));
615 EXPECT_EQ("515", message.repeated_string (1));
616 EXPECT_EQ("516", message.repeated_bytes (1));
617
618 EXPECT_EQ(517, message.repeatedgroup (1).a());
619 EXPECT_EQ(518, message.repeated_nested_message (1).bb());
620 EXPECT_EQ(519, message.repeated_foreign_message(1).c());
621 EXPECT_EQ(520, message.repeated_import_message (1).d());
622 EXPECT_EQ(527, message.repeated_lazy_message (1).bb());
623
624 EXPECT_EQ(unittest::TestAllTypesLite::FOO , message.repeated_nested_enum (1));
625 EXPECT_EQ(unittest::FOREIGN_LITE_FOO , message.repeated_foreign_enum(1));
626 EXPECT_EQ(unittest_import::IMPORT_LITE_FOO, message.repeated_import_enum (1));
627
628 }
629
630 // -------------------------------------------------------------------
631
SetPackedFields(unittest::TestPackedTypesLite * message)632 void TestUtilLite::SetPackedFields(unittest::TestPackedTypesLite* message) {
633 message->add_packed_int32 (601);
634 message->add_packed_int64 (602);
635 message->add_packed_uint32 (603);
636 message->add_packed_uint64 (604);
637 message->add_packed_sint32 (605);
638 message->add_packed_sint64 (606);
639 message->add_packed_fixed32 (607);
640 message->add_packed_fixed64 (608);
641 message->add_packed_sfixed32(609);
642 message->add_packed_sfixed64(610);
643 message->add_packed_float (611);
644 message->add_packed_double (612);
645 message->add_packed_bool (true);
646 message->add_packed_enum (unittest::FOREIGN_LITE_BAR);
647 // add a second one of each field
648 message->add_packed_int32 (701);
649 message->add_packed_int64 (702);
650 message->add_packed_uint32 (703);
651 message->add_packed_uint64 (704);
652 message->add_packed_sint32 (705);
653 message->add_packed_sint64 (706);
654 message->add_packed_fixed32 (707);
655 message->add_packed_fixed64 (708);
656 message->add_packed_sfixed32(709);
657 message->add_packed_sfixed64(710);
658 message->add_packed_float (711);
659 message->add_packed_double (712);
660 message->add_packed_bool (false);
661 message->add_packed_enum (unittest::FOREIGN_LITE_BAZ);
662 }
663
664 // -------------------------------------------------------------------
665
ModifyPackedFields(unittest::TestPackedTypesLite * message)666 void TestUtilLite::ModifyPackedFields(unittest::TestPackedTypesLite* message) {
667 message->set_packed_int32 (1, 801);
668 message->set_packed_int64 (1, 802);
669 message->set_packed_uint32 (1, 803);
670 message->set_packed_uint64 (1, 804);
671 message->set_packed_sint32 (1, 805);
672 message->set_packed_sint64 (1, 806);
673 message->set_packed_fixed32 (1, 807);
674 message->set_packed_fixed64 (1, 808);
675 message->set_packed_sfixed32(1, 809);
676 message->set_packed_sfixed64(1, 810);
677 message->set_packed_float (1, 811);
678 message->set_packed_double (1, 812);
679 message->set_packed_bool (1, true);
680 message->set_packed_enum (1, unittest::FOREIGN_LITE_FOO);
681 }
682
683 // -------------------------------------------------------------------
684
ExpectPackedFieldsSet(const unittest::TestPackedTypesLite & message)685 void TestUtilLite::ExpectPackedFieldsSet(
686 const unittest::TestPackedTypesLite& message) {
687 ASSERT_EQ(2, message.packed_int32_size ());
688 ASSERT_EQ(2, message.packed_int64_size ());
689 ASSERT_EQ(2, message.packed_uint32_size ());
690 ASSERT_EQ(2, message.packed_uint64_size ());
691 ASSERT_EQ(2, message.packed_sint32_size ());
692 ASSERT_EQ(2, message.packed_sint64_size ());
693 ASSERT_EQ(2, message.packed_fixed32_size ());
694 ASSERT_EQ(2, message.packed_fixed64_size ());
695 ASSERT_EQ(2, message.packed_sfixed32_size());
696 ASSERT_EQ(2, message.packed_sfixed64_size());
697 ASSERT_EQ(2, message.packed_float_size ());
698 ASSERT_EQ(2, message.packed_double_size ());
699 ASSERT_EQ(2, message.packed_bool_size ());
700 ASSERT_EQ(2, message.packed_enum_size ());
701
702 EXPECT_EQ(601 , message.packed_int32 (0));
703 EXPECT_EQ(602 , message.packed_int64 (0));
704 EXPECT_EQ(603 , message.packed_uint32 (0));
705 EXPECT_EQ(604 , message.packed_uint64 (0));
706 EXPECT_EQ(605 , message.packed_sint32 (0));
707 EXPECT_EQ(606 , message.packed_sint64 (0));
708 EXPECT_EQ(607 , message.packed_fixed32 (0));
709 EXPECT_EQ(608 , message.packed_fixed64 (0));
710 EXPECT_EQ(609 , message.packed_sfixed32(0));
711 EXPECT_EQ(610 , message.packed_sfixed64(0));
712 EXPECT_EQ(611 , message.packed_float (0));
713 EXPECT_EQ(612 , message.packed_double (0));
714 EXPECT_EQ(true , message.packed_bool (0));
715 EXPECT_EQ(unittest::FOREIGN_LITE_BAR, message.packed_enum(0));
716
717 EXPECT_EQ(701 , message.packed_int32 (1));
718 EXPECT_EQ(702 , message.packed_int64 (1));
719 EXPECT_EQ(703 , message.packed_uint32 (1));
720 EXPECT_EQ(704 , message.packed_uint64 (1));
721 EXPECT_EQ(705 , message.packed_sint32 (1));
722 EXPECT_EQ(706 , message.packed_sint64 (1));
723 EXPECT_EQ(707 , message.packed_fixed32 (1));
724 EXPECT_EQ(708 , message.packed_fixed64 (1));
725 EXPECT_EQ(709 , message.packed_sfixed32(1));
726 EXPECT_EQ(710 , message.packed_sfixed64(1));
727 EXPECT_EQ(711 , message.packed_float (1));
728 EXPECT_EQ(712 , message.packed_double (1));
729 EXPECT_EQ(false, message.packed_bool (1));
730 EXPECT_EQ(unittest::FOREIGN_LITE_BAZ, message.packed_enum(1));
731 }
732
733 // -------------------------------------------------------------------
734
ExpectPackedClear(const unittest::TestPackedTypesLite & message)735 void TestUtilLite::ExpectPackedClear(
736 const unittest::TestPackedTypesLite& message) {
737 // Packed repeated fields are empty.
738 EXPECT_EQ(0, message.packed_int32_size ());
739 EXPECT_EQ(0, message.packed_int64_size ());
740 EXPECT_EQ(0, message.packed_uint32_size ());
741 EXPECT_EQ(0, message.packed_uint64_size ());
742 EXPECT_EQ(0, message.packed_sint32_size ());
743 EXPECT_EQ(0, message.packed_sint64_size ());
744 EXPECT_EQ(0, message.packed_fixed32_size ());
745 EXPECT_EQ(0, message.packed_fixed64_size ());
746 EXPECT_EQ(0, message.packed_sfixed32_size());
747 EXPECT_EQ(0, message.packed_sfixed64_size());
748 EXPECT_EQ(0, message.packed_float_size ());
749 EXPECT_EQ(0, message.packed_double_size ());
750 EXPECT_EQ(0, message.packed_bool_size ());
751 EXPECT_EQ(0, message.packed_enum_size ());
752 }
753
754 // -------------------------------------------------------------------
755
ExpectPackedFieldsModified(const unittest::TestPackedTypesLite & message)756 void TestUtilLite::ExpectPackedFieldsModified(
757 const unittest::TestPackedTypesLite& message) {
758 // Do the same for packed repeated fields.
759 ASSERT_EQ(2, message.packed_int32_size ());
760 ASSERT_EQ(2, message.packed_int64_size ());
761 ASSERT_EQ(2, message.packed_uint32_size ());
762 ASSERT_EQ(2, message.packed_uint64_size ());
763 ASSERT_EQ(2, message.packed_sint32_size ());
764 ASSERT_EQ(2, message.packed_sint64_size ());
765 ASSERT_EQ(2, message.packed_fixed32_size ());
766 ASSERT_EQ(2, message.packed_fixed64_size ());
767 ASSERT_EQ(2, message.packed_sfixed32_size());
768 ASSERT_EQ(2, message.packed_sfixed64_size());
769 ASSERT_EQ(2, message.packed_float_size ());
770 ASSERT_EQ(2, message.packed_double_size ());
771 ASSERT_EQ(2, message.packed_bool_size ());
772 ASSERT_EQ(2, message.packed_enum_size ());
773
774 EXPECT_EQ(601 , message.packed_int32 (0));
775 EXPECT_EQ(602 , message.packed_int64 (0));
776 EXPECT_EQ(603 , message.packed_uint32 (0));
777 EXPECT_EQ(604 , message.packed_uint64 (0));
778 EXPECT_EQ(605 , message.packed_sint32 (0));
779 EXPECT_EQ(606 , message.packed_sint64 (0));
780 EXPECT_EQ(607 , message.packed_fixed32 (0));
781 EXPECT_EQ(608 , message.packed_fixed64 (0));
782 EXPECT_EQ(609 , message.packed_sfixed32(0));
783 EXPECT_EQ(610 , message.packed_sfixed64(0));
784 EXPECT_EQ(611 , message.packed_float (0));
785 EXPECT_EQ(612 , message.packed_double (0));
786 EXPECT_EQ(true , message.packed_bool (0));
787 EXPECT_EQ(unittest::FOREIGN_LITE_BAR, message.packed_enum(0));
788 // Actually verify the second (modified) elements now.
789 EXPECT_EQ(801 , message.packed_int32 (1));
790 EXPECT_EQ(802 , message.packed_int64 (1));
791 EXPECT_EQ(803 , message.packed_uint32 (1));
792 EXPECT_EQ(804 , message.packed_uint64 (1));
793 EXPECT_EQ(805 , message.packed_sint32 (1));
794 EXPECT_EQ(806 , message.packed_sint64 (1));
795 EXPECT_EQ(807 , message.packed_fixed32 (1));
796 EXPECT_EQ(808 , message.packed_fixed64 (1));
797 EXPECT_EQ(809 , message.packed_sfixed32(1));
798 EXPECT_EQ(810 , message.packed_sfixed64(1));
799 EXPECT_EQ(811 , message.packed_float (1));
800 EXPECT_EQ(812 , message.packed_double (1));
801 EXPECT_EQ(true , message.packed_bool (1));
802 EXPECT_EQ(unittest::FOREIGN_LITE_FOO, message.packed_enum(1));
803 }
804
805 // ===================================================================
806 // Extensions
807 //
808 // All this code is exactly equivalent to the above code except that it's
809 // manipulating extension fields instead of normal ones.
810 //
811 // I gave up on the 80-char limit here. Sorry.
812
SetAllExtensions(unittest::TestAllExtensionsLite * message)813 void TestUtilLite::SetAllExtensions(unittest::TestAllExtensionsLite* message) {
814 message->SetExtension(unittest::optional_int32_extension_lite , 101);
815 message->SetExtension(unittest::optional_int64_extension_lite , 102);
816 message->SetExtension(unittest::optional_uint32_extension_lite , 103);
817 message->SetExtension(unittest::optional_uint64_extension_lite , 104);
818 message->SetExtension(unittest::optional_sint32_extension_lite , 105);
819 message->SetExtension(unittest::optional_sint64_extension_lite , 106);
820 message->SetExtension(unittest::optional_fixed32_extension_lite , 107);
821 message->SetExtension(unittest::optional_fixed64_extension_lite , 108);
822 message->SetExtension(unittest::optional_sfixed32_extension_lite, 109);
823 message->SetExtension(unittest::optional_sfixed64_extension_lite, 110);
824 message->SetExtension(unittest::optional_float_extension_lite , 111);
825 message->SetExtension(unittest::optional_double_extension_lite , 112);
826 message->SetExtension(unittest::optional_bool_extension_lite , true);
827 message->SetExtension(unittest::optional_string_extension_lite , "115");
828 message->SetExtension(unittest::optional_bytes_extension_lite , "116");
829
830 message->MutableExtension(unittest::optionalgroup_extension_lite )->set_a(117);
831 message->MutableExtension(unittest::optional_nested_message_extension_lite )->set_bb(118);
832 message->MutableExtension(unittest::optional_foreign_message_extension_lite )->set_c(119);
833 message->MutableExtension(unittest::optional_import_message_extension_lite )->set_d(120);
834 message->MutableExtension(unittest::optional_public_import_message_extension_lite)->set_e(126);
835 message->MutableExtension(unittest::optional_lazy_message_extension_lite )->set_bb(127);
836
837 message->SetExtension(unittest::optional_nested_enum_extension_lite , unittest::TestAllTypesLite::BAZ );
838 message->SetExtension(unittest::optional_foreign_enum_extension_lite, unittest::FOREIGN_LITE_BAZ );
839 message->SetExtension(unittest::optional_import_enum_extension_lite , unittest_import::IMPORT_LITE_BAZ);
840
841
842 // -----------------------------------------------------------------
843
844 message->AddExtension(unittest::repeated_int32_extension_lite , 201);
845 message->AddExtension(unittest::repeated_int64_extension_lite , 202);
846 message->AddExtension(unittest::repeated_uint32_extension_lite , 203);
847 message->AddExtension(unittest::repeated_uint64_extension_lite , 204);
848 message->AddExtension(unittest::repeated_sint32_extension_lite , 205);
849 message->AddExtension(unittest::repeated_sint64_extension_lite , 206);
850 message->AddExtension(unittest::repeated_fixed32_extension_lite , 207);
851 message->AddExtension(unittest::repeated_fixed64_extension_lite , 208);
852 message->AddExtension(unittest::repeated_sfixed32_extension_lite, 209);
853 message->AddExtension(unittest::repeated_sfixed64_extension_lite, 210);
854 message->AddExtension(unittest::repeated_float_extension_lite , 211);
855 message->AddExtension(unittest::repeated_double_extension_lite , 212);
856 message->AddExtension(unittest::repeated_bool_extension_lite , true);
857 message->AddExtension(unittest::repeated_string_extension_lite , "215");
858 message->AddExtension(unittest::repeated_bytes_extension_lite , "216");
859
860 message->AddExtension(unittest::repeatedgroup_extension_lite )->set_a(217);
861 message->AddExtension(unittest::repeated_nested_message_extension_lite )->set_bb(218);
862 message->AddExtension(unittest::repeated_foreign_message_extension_lite)->set_c(219);
863 message->AddExtension(unittest::repeated_import_message_extension_lite )->set_d(220);
864 message->AddExtension(unittest::repeated_lazy_message_extension_lite )->set_bb(227);
865
866 message->AddExtension(unittest::repeated_nested_enum_extension_lite , unittest::TestAllTypesLite::BAR );
867 message->AddExtension(unittest::repeated_foreign_enum_extension_lite, unittest::FOREIGN_LITE_BAR );
868 message->AddExtension(unittest::repeated_import_enum_extension_lite , unittest_import::IMPORT_LITE_BAR);
869
870
871 // Add a second one of each field.
872 message->AddExtension(unittest::repeated_int32_extension_lite , 301);
873 message->AddExtension(unittest::repeated_int64_extension_lite , 302);
874 message->AddExtension(unittest::repeated_uint32_extension_lite , 303);
875 message->AddExtension(unittest::repeated_uint64_extension_lite , 304);
876 message->AddExtension(unittest::repeated_sint32_extension_lite , 305);
877 message->AddExtension(unittest::repeated_sint64_extension_lite , 306);
878 message->AddExtension(unittest::repeated_fixed32_extension_lite , 307);
879 message->AddExtension(unittest::repeated_fixed64_extension_lite , 308);
880 message->AddExtension(unittest::repeated_sfixed32_extension_lite, 309);
881 message->AddExtension(unittest::repeated_sfixed64_extension_lite, 310);
882 message->AddExtension(unittest::repeated_float_extension_lite , 311);
883 message->AddExtension(unittest::repeated_double_extension_lite , 312);
884 message->AddExtension(unittest::repeated_bool_extension_lite , false);
885 message->AddExtension(unittest::repeated_string_extension_lite , "315");
886 message->AddExtension(unittest::repeated_bytes_extension_lite , "316");
887
888 message->AddExtension(unittest::repeatedgroup_extension_lite )->set_a(317);
889 message->AddExtension(unittest::repeated_nested_message_extension_lite )->set_bb(318);
890 message->AddExtension(unittest::repeated_foreign_message_extension_lite)->set_c(319);
891 message->AddExtension(unittest::repeated_import_message_extension_lite )->set_d(320);
892 message->AddExtension(unittest::repeated_lazy_message_extension_lite )->set_bb(327);
893
894 message->AddExtension(unittest::repeated_nested_enum_extension_lite , unittest::TestAllTypesLite::BAZ );
895 message->AddExtension(unittest::repeated_foreign_enum_extension_lite, unittest::FOREIGN_LITE_BAZ );
896 message->AddExtension(unittest::repeated_import_enum_extension_lite , unittest_import::IMPORT_LITE_BAZ);
897
898
899 // -----------------------------------------------------------------
900
901 message->SetExtension(unittest::default_int32_extension_lite , 401);
902 message->SetExtension(unittest::default_int64_extension_lite , 402);
903 message->SetExtension(unittest::default_uint32_extension_lite , 403);
904 message->SetExtension(unittest::default_uint64_extension_lite , 404);
905 message->SetExtension(unittest::default_sint32_extension_lite , 405);
906 message->SetExtension(unittest::default_sint64_extension_lite , 406);
907 message->SetExtension(unittest::default_fixed32_extension_lite , 407);
908 message->SetExtension(unittest::default_fixed64_extension_lite , 408);
909 message->SetExtension(unittest::default_sfixed32_extension_lite, 409);
910 message->SetExtension(unittest::default_sfixed64_extension_lite, 410);
911 message->SetExtension(unittest::default_float_extension_lite , 411);
912 message->SetExtension(unittest::default_double_extension_lite , 412);
913 message->SetExtension(unittest::default_bool_extension_lite , false);
914 message->SetExtension(unittest::default_string_extension_lite , "415");
915 message->SetExtension(unittest::default_bytes_extension_lite , "416");
916
917 message->SetExtension(unittest::default_nested_enum_extension_lite , unittest::TestAllTypesLite::FOO );
918 message->SetExtension(unittest::default_foreign_enum_extension_lite, unittest::FOREIGN_LITE_FOO );
919 message->SetExtension(unittest::default_import_enum_extension_lite , unittest_import::IMPORT_LITE_FOO);
920
921
922 message->SetExtension(unittest::oneof_uint32_extension_lite, 601);
923 message->MutableExtension(unittest::oneof_nested_message_extension_lite)->set_bb(602);;
924 message->SetExtension(unittest::oneof_string_extension_lite, "603");
925 message->SetExtension(unittest::oneof_bytes_extension_lite, "604");
926 }
927
928 // -------------------------------------------------------------------
929
ModifyRepeatedExtensions(unittest::TestAllExtensionsLite * message)930 void TestUtilLite::ModifyRepeatedExtensions(
931 unittest::TestAllExtensionsLite* message) {
932 message->SetExtension(unittest::repeated_int32_extension_lite , 1, 501);
933 message->SetExtension(unittest::repeated_int64_extension_lite , 1, 502);
934 message->SetExtension(unittest::repeated_uint32_extension_lite , 1, 503);
935 message->SetExtension(unittest::repeated_uint64_extension_lite , 1, 504);
936 message->SetExtension(unittest::repeated_sint32_extension_lite , 1, 505);
937 message->SetExtension(unittest::repeated_sint64_extension_lite , 1, 506);
938 message->SetExtension(unittest::repeated_fixed32_extension_lite , 1, 507);
939 message->SetExtension(unittest::repeated_fixed64_extension_lite , 1, 508);
940 message->SetExtension(unittest::repeated_sfixed32_extension_lite, 1, 509);
941 message->SetExtension(unittest::repeated_sfixed64_extension_lite, 1, 510);
942 message->SetExtension(unittest::repeated_float_extension_lite , 1, 511);
943 message->SetExtension(unittest::repeated_double_extension_lite , 1, 512);
944 message->SetExtension(unittest::repeated_bool_extension_lite , 1, true);
945 message->SetExtension(unittest::repeated_string_extension_lite , 1, "515");
946 message->SetExtension(unittest::repeated_bytes_extension_lite , 1, "516");
947
948 message->MutableExtension(unittest::repeatedgroup_extension_lite , 1)->set_a(517);
949 message->MutableExtension(unittest::repeated_nested_message_extension_lite , 1)->set_bb(518);
950 message->MutableExtension(unittest::repeated_foreign_message_extension_lite, 1)->set_c(519);
951 message->MutableExtension(unittest::repeated_import_message_extension_lite , 1)->set_d(520);
952 message->MutableExtension(unittest::repeated_lazy_message_extension_lite , 1)->set_bb(527);
953
954 message->SetExtension(unittest::repeated_nested_enum_extension_lite , 1, unittest::TestAllTypesLite::FOO );
955 message->SetExtension(unittest::repeated_foreign_enum_extension_lite, 1, unittest::FOREIGN_LITE_FOO );
956 message->SetExtension(unittest::repeated_import_enum_extension_lite , 1, unittest_import::IMPORT_LITE_FOO);
957
958 }
959
960 // -------------------------------------------------------------------
961
ExpectAllExtensionsSet(const unittest::TestAllExtensionsLite & message)962 void TestUtilLite::ExpectAllExtensionsSet(
963 const unittest::TestAllExtensionsLite& message) {
964 EXPECT_TRUE(message.HasExtension(unittest::optional_int32_extension_lite ));
965 EXPECT_TRUE(message.HasExtension(unittest::optional_int64_extension_lite ));
966 EXPECT_TRUE(message.HasExtension(unittest::optional_uint32_extension_lite ));
967 EXPECT_TRUE(message.HasExtension(unittest::optional_uint64_extension_lite ));
968 EXPECT_TRUE(message.HasExtension(unittest::optional_sint32_extension_lite ));
969 EXPECT_TRUE(message.HasExtension(unittest::optional_sint64_extension_lite ));
970 EXPECT_TRUE(message.HasExtension(unittest::optional_fixed32_extension_lite ));
971 EXPECT_TRUE(message.HasExtension(unittest::optional_fixed64_extension_lite ));
972 EXPECT_TRUE(message.HasExtension(unittest::optional_sfixed32_extension_lite));
973 EXPECT_TRUE(message.HasExtension(unittest::optional_sfixed64_extension_lite));
974 EXPECT_TRUE(message.HasExtension(unittest::optional_float_extension_lite ));
975 EXPECT_TRUE(message.HasExtension(unittest::optional_double_extension_lite ));
976 EXPECT_TRUE(message.HasExtension(unittest::optional_bool_extension_lite ));
977 EXPECT_TRUE(message.HasExtension(unittest::optional_string_extension_lite ));
978 EXPECT_TRUE(message.HasExtension(unittest::optional_bytes_extension_lite ));
979
980 EXPECT_TRUE(message.HasExtension(unittest::optionalgroup_extension_lite ));
981 EXPECT_TRUE(message.HasExtension(unittest::optional_nested_message_extension_lite ));
982 EXPECT_TRUE(message.HasExtension(unittest::optional_foreign_message_extension_lite ));
983 EXPECT_TRUE(message.HasExtension(unittest::optional_import_message_extension_lite ));
984 EXPECT_TRUE(message.HasExtension(unittest::optional_public_import_message_extension_lite));
985 EXPECT_TRUE(message.HasExtension(unittest::optional_lazy_message_extension_lite ));
986
987 EXPECT_TRUE(message.GetExtension(unittest::optionalgroup_extension_lite ).has_a());
988 EXPECT_TRUE(message.GetExtension(unittest::optional_nested_message_extension_lite ).has_bb());
989 EXPECT_TRUE(message.GetExtension(unittest::optional_foreign_message_extension_lite ).has_c());
990 EXPECT_TRUE(message.GetExtension(unittest::optional_import_message_extension_lite ).has_d());
991 EXPECT_TRUE(message.GetExtension(unittest::optional_public_import_message_extension_lite).has_e());
992 EXPECT_TRUE(message.GetExtension(unittest::optional_lazy_message_extension_lite ).has_bb());
993
994 EXPECT_TRUE(message.HasExtension(unittest::optional_nested_enum_extension_lite ));
995 EXPECT_TRUE(message.HasExtension(unittest::optional_foreign_enum_extension_lite));
996 EXPECT_TRUE(message.HasExtension(unittest::optional_import_enum_extension_lite ));
997
998
999 EXPECT_EQ(101 , message.GetExtension(unittest::optional_int32_extension_lite ));
1000 EXPECT_EQ(102 , message.GetExtension(unittest::optional_int64_extension_lite ));
1001 EXPECT_EQ(103 , message.GetExtension(unittest::optional_uint32_extension_lite ));
1002 EXPECT_EQ(104 , message.GetExtension(unittest::optional_uint64_extension_lite ));
1003 EXPECT_EQ(105 , message.GetExtension(unittest::optional_sint32_extension_lite ));
1004 EXPECT_EQ(106 , message.GetExtension(unittest::optional_sint64_extension_lite ));
1005 EXPECT_EQ(107 , message.GetExtension(unittest::optional_fixed32_extension_lite ));
1006 EXPECT_EQ(108 , message.GetExtension(unittest::optional_fixed64_extension_lite ));
1007 EXPECT_EQ(109 , message.GetExtension(unittest::optional_sfixed32_extension_lite));
1008 EXPECT_EQ(110 , message.GetExtension(unittest::optional_sfixed64_extension_lite));
1009 EXPECT_EQ(111 , message.GetExtension(unittest::optional_float_extension_lite ));
1010 EXPECT_EQ(112 , message.GetExtension(unittest::optional_double_extension_lite ));
1011 EXPECT_EQ(true , message.GetExtension(unittest::optional_bool_extension_lite ));
1012 EXPECT_EQ("115", message.GetExtension(unittest::optional_string_extension_lite ));
1013 EXPECT_EQ("116", message.GetExtension(unittest::optional_bytes_extension_lite ));
1014
1015 EXPECT_EQ(117, message.GetExtension(unittest::optionalgroup_extension_lite ).a());
1016 EXPECT_EQ(118, message.GetExtension(unittest::optional_nested_message_extension_lite ).bb());
1017 EXPECT_EQ(119, message.GetExtension(unittest::optional_foreign_message_extension_lite ).c());
1018 EXPECT_EQ(120, message.GetExtension(unittest::optional_import_message_extension_lite ).d());
1019 EXPECT_EQ(126, message.GetExtension(unittest::optional_public_import_message_extension_lite).e());
1020 EXPECT_EQ(127, message.GetExtension(unittest::optional_lazy_message_extension_lite ).bb());
1021
1022 EXPECT_EQ(unittest::TestAllTypesLite::BAZ , message.GetExtension(unittest::optional_nested_enum_extension_lite ));
1023 EXPECT_EQ(unittest::FOREIGN_LITE_BAZ , message.GetExtension(unittest::optional_foreign_enum_extension_lite));
1024 EXPECT_EQ(unittest_import::IMPORT_LITE_BAZ, message.GetExtension(unittest::optional_import_enum_extension_lite ));
1025
1026
1027 // -----------------------------------------------------------------
1028
1029 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int32_extension_lite ));
1030 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int64_extension_lite ));
1031 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint32_extension_lite ));
1032 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint64_extension_lite ));
1033 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint32_extension_lite ));
1034 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint64_extension_lite ));
1035 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed32_extension_lite ));
1036 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed64_extension_lite ));
1037 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed32_extension_lite));
1038 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed64_extension_lite));
1039 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_float_extension_lite ));
1040 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_double_extension_lite ));
1041 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bool_extension_lite ));
1042 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_extension_lite ));
1043 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bytes_extension_lite ));
1044
1045 ASSERT_EQ(2, message.ExtensionSize(unittest::repeatedgroup_extension_lite ));
1046 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_message_extension_lite ));
1047 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_message_extension_lite));
1048 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_message_extension_lite ));
1049 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_lazy_message_extension_lite ));
1050 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_enum_extension_lite ));
1051 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_enum_extension_lite ));
1052 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_enum_extension_lite ));
1053
1054
1055 EXPECT_EQ(201 , message.GetExtension(unittest::repeated_int32_extension_lite , 0));
1056 EXPECT_EQ(202 , message.GetExtension(unittest::repeated_int64_extension_lite , 0));
1057 EXPECT_EQ(203 , message.GetExtension(unittest::repeated_uint32_extension_lite , 0));
1058 EXPECT_EQ(204 , message.GetExtension(unittest::repeated_uint64_extension_lite , 0));
1059 EXPECT_EQ(205 , message.GetExtension(unittest::repeated_sint32_extension_lite , 0));
1060 EXPECT_EQ(206 , message.GetExtension(unittest::repeated_sint64_extension_lite , 0));
1061 EXPECT_EQ(207 , message.GetExtension(unittest::repeated_fixed32_extension_lite , 0));
1062 EXPECT_EQ(208 , message.GetExtension(unittest::repeated_fixed64_extension_lite , 0));
1063 EXPECT_EQ(209 , message.GetExtension(unittest::repeated_sfixed32_extension_lite, 0));
1064 EXPECT_EQ(210 , message.GetExtension(unittest::repeated_sfixed64_extension_lite, 0));
1065 EXPECT_EQ(211 , message.GetExtension(unittest::repeated_float_extension_lite , 0));
1066 EXPECT_EQ(212 , message.GetExtension(unittest::repeated_double_extension_lite , 0));
1067 EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension_lite , 0));
1068 EXPECT_EQ("215", message.GetExtension(unittest::repeated_string_extension_lite , 0));
1069 EXPECT_EQ("216", message.GetExtension(unittest::repeated_bytes_extension_lite , 0));
1070
1071 EXPECT_EQ(217, message.GetExtension(unittest::repeatedgroup_extension_lite , 0).a());
1072 EXPECT_EQ(218, message.GetExtension(unittest::repeated_nested_message_extension_lite , 0).bb());
1073 EXPECT_EQ(219, message.GetExtension(unittest::repeated_foreign_message_extension_lite, 0).c());
1074 EXPECT_EQ(220, message.GetExtension(unittest::repeated_import_message_extension_lite , 0).d());
1075 EXPECT_EQ(227, message.GetExtension(unittest::repeated_lazy_message_extension_lite , 0).bb());
1076
1077 EXPECT_EQ(unittest::TestAllTypesLite::BAR , message.GetExtension(unittest::repeated_nested_enum_extension_lite , 0));
1078 EXPECT_EQ(unittest::FOREIGN_LITE_BAR , message.GetExtension(unittest::repeated_foreign_enum_extension_lite, 0));
1079 EXPECT_EQ(unittest_import::IMPORT_LITE_BAR, message.GetExtension(unittest::repeated_import_enum_extension_lite , 0));
1080
1081
1082 EXPECT_EQ(301 , message.GetExtension(unittest::repeated_int32_extension_lite , 1));
1083 EXPECT_EQ(302 , message.GetExtension(unittest::repeated_int64_extension_lite , 1));
1084 EXPECT_EQ(303 , message.GetExtension(unittest::repeated_uint32_extension_lite , 1));
1085 EXPECT_EQ(304 , message.GetExtension(unittest::repeated_uint64_extension_lite , 1));
1086 EXPECT_EQ(305 , message.GetExtension(unittest::repeated_sint32_extension_lite , 1));
1087 EXPECT_EQ(306 , message.GetExtension(unittest::repeated_sint64_extension_lite , 1));
1088 EXPECT_EQ(307 , message.GetExtension(unittest::repeated_fixed32_extension_lite , 1));
1089 EXPECT_EQ(308 , message.GetExtension(unittest::repeated_fixed64_extension_lite , 1));
1090 EXPECT_EQ(309 , message.GetExtension(unittest::repeated_sfixed32_extension_lite, 1));
1091 EXPECT_EQ(310 , message.GetExtension(unittest::repeated_sfixed64_extension_lite, 1));
1092 EXPECT_EQ(311 , message.GetExtension(unittest::repeated_float_extension_lite , 1));
1093 EXPECT_EQ(312 , message.GetExtension(unittest::repeated_double_extension_lite , 1));
1094 EXPECT_EQ(false, message.GetExtension(unittest::repeated_bool_extension_lite , 1));
1095 EXPECT_EQ("315", message.GetExtension(unittest::repeated_string_extension_lite , 1));
1096 EXPECT_EQ("316", message.GetExtension(unittest::repeated_bytes_extension_lite , 1));
1097
1098 EXPECT_EQ(317, message.GetExtension(unittest::repeatedgroup_extension_lite , 1).a());
1099 EXPECT_EQ(318, message.GetExtension(unittest::repeated_nested_message_extension_lite , 1).bb());
1100 EXPECT_EQ(319, message.GetExtension(unittest::repeated_foreign_message_extension_lite, 1).c());
1101 EXPECT_EQ(320, message.GetExtension(unittest::repeated_import_message_extension_lite , 1).d());
1102 EXPECT_EQ(327, message.GetExtension(unittest::repeated_lazy_message_extension_lite , 1).bb());
1103
1104 EXPECT_EQ(unittest::TestAllTypesLite::BAZ , message.GetExtension(unittest::repeated_nested_enum_extension_lite , 1));
1105 EXPECT_EQ(unittest::FOREIGN_LITE_BAZ , message.GetExtension(unittest::repeated_foreign_enum_extension_lite, 1));
1106 EXPECT_EQ(unittest_import::IMPORT_LITE_BAZ, message.GetExtension(unittest::repeated_import_enum_extension_lite , 1));
1107
1108
1109 // -----------------------------------------------------------------
1110
1111 EXPECT_TRUE(message.HasExtension(unittest::default_int32_extension_lite ));
1112 EXPECT_TRUE(message.HasExtension(unittest::default_int64_extension_lite ));
1113 EXPECT_TRUE(message.HasExtension(unittest::default_uint32_extension_lite ));
1114 EXPECT_TRUE(message.HasExtension(unittest::default_uint64_extension_lite ));
1115 EXPECT_TRUE(message.HasExtension(unittest::default_sint32_extension_lite ));
1116 EXPECT_TRUE(message.HasExtension(unittest::default_sint64_extension_lite ));
1117 EXPECT_TRUE(message.HasExtension(unittest::default_fixed32_extension_lite ));
1118 EXPECT_TRUE(message.HasExtension(unittest::default_fixed64_extension_lite ));
1119 EXPECT_TRUE(message.HasExtension(unittest::default_sfixed32_extension_lite));
1120 EXPECT_TRUE(message.HasExtension(unittest::default_sfixed64_extension_lite));
1121 EXPECT_TRUE(message.HasExtension(unittest::default_float_extension_lite ));
1122 EXPECT_TRUE(message.HasExtension(unittest::default_double_extension_lite ));
1123 EXPECT_TRUE(message.HasExtension(unittest::default_bool_extension_lite ));
1124 EXPECT_TRUE(message.HasExtension(unittest::default_string_extension_lite ));
1125 EXPECT_TRUE(message.HasExtension(unittest::default_bytes_extension_lite ));
1126
1127 EXPECT_TRUE(message.HasExtension(unittest::default_nested_enum_extension_lite ));
1128 EXPECT_TRUE(message.HasExtension(unittest::default_foreign_enum_extension_lite));
1129 EXPECT_TRUE(message.HasExtension(unittest::default_import_enum_extension_lite ));
1130
1131
1132 EXPECT_EQ(401 , message.GetExtension(unittest::default_int32_extension_lite ));
1133 EXPECT_EQ(402 , message.GetExtension(unittest::default_int64_extension_lite ));
1134 EXPECT_EQ(403 , message.GetExtension(unittest::default_uint32_extension_lite ));
1135 EXPECT_EQ(404 , message.GetExtension(unittest::default_uint64_extension_lite ));
1136 EXPECT_EQ(405 , message.GetExtension(unittest::default_sint32_extension_lite ));
1137 EXPECT_EQ(406 , message.GetExtension(unittest::default_sint64_extension_lite ));
1138 EXPECT_EQ(407 , message.GetExtension(unittest::default_fixed32_extension_lite ));
1139 EXPECT_EQ(408 , message.GetExtension(unittest::default_fixed64_extension_lite ));
1140 EXPECT_EQ(409 , message.GetExtension(unittest::default_sfixed32_extension_lite));
1141 EXPECT_EQ(410 , message.GetExtension(unittest::default_sfixed64_extension_lite));
1142 EXPECT_EQ(411 , message.GetExtension(unittest::default_float_extension_lite ));
1143 EXPECT_EQ(412 , message.GetExtension(unittest::default_double_extension_lite ));
1144 EXPECT_EQ(false, message.GetExtension(unittest::default_bool_extension_lite ));
1145 EXPECT_EQ("415", message.GetExtension(unittest::default_string_extension_lite ));
1146 EXPECT_EQ("416", message.GetExtension(unittest::default_bytes_extension_lite ));
1147
1148 EXPECT_EQ(unittest::TestAllTypesLite::FOO , message.GetExtension(unittest::default_nested_enum_extension_lite ));
1149 EXPECT_EQ(unittest::FOREIGN_LITE_FOO , message.GetExtension(unittest::default_foreign_enum_extension_lite));
1150 EXPECT_EQ(unittest_import::IMPORT_LITE_FOO, message.GetExtension(unittest::default_import_enum_extension_lite ));
1151
1152
1153 EXPECT_TRUE(message.HasExtension(unittest::oneof_uint32_extension_lite));
1154 EXPECT_TRUE(message.GetExtension(unittest::oneof_nested_message_extension_lite).has_bb());
1155 EXPECT_TRUE(message.HasExtension(unittest::oneof_string_extension_lite));
1156 EXPECT_TRUE(message.HasExtension(unittest::oneof_bytes_extension_lite));
1157
1158 EXPECT_EQ(601, message.GetExtension(unittest::oneof_uint32_extension_lite));
1159 EXPECT_EQ(602, message.GetExtension(unittest::oneof_nested_message_extension_lite).bb());
1160 EXPECT_EQ("603", message.GetExtension(unittest::oneof_string_extension_lite));
1161 EXPECT_EQ("604", message.GetExtension(unittest::oneof_bytes_extension_lite));
1162 }
1163
1164 // -------------------------------------------------------------------
1165
ExpectExtensionsClear(const unittest::TestAllExtensionsLite & message)1166 void TestUtilLite::ExpectExtensionsClear(
1167 const unittest::TestAllExtensionsLite& message) {
1168 string serialized;
1169 ASSERT_TRUE(message.SerializeToString(&serialized));
1170 EXPECT_EQ("", serialized);
1171 EXPECT_EQ(0, message.ByteSize());
1172
1173 // has_blah() should initially be false for all optional fields.
1174 EXPECT_FALSE(message.HasExtension(unittest::optional_int32_extension_lite ));
1175 EXPECT_FALSE(message.HasExtension(unittest::optional_int64_extension_lite ));
1176 EXPECT_FALSE(message.HasExtension(unittest::optional_uint32_extension_lite ));
1177 EXPECT_FALSE(message.HasExtension(unittest::optional_uint64_extension_lite ));
1178 EXPECT_FALSE(message.HasExtension(unittest::optional_sint32_extension_lite ));
1179 EXPECT_FALSE(message.HasExtension(unittest::optional_sint64_extension_lite ));
1180 EXPECT_FALSE(message.HasExtension(unittest::optional_fixed32_extension_lite ));
1181 EXPECT_FALSE(message.HasExtension(unittest::optional_fixed64_extension_lite ));
1182 EXPECT_FALSE(message.HasExtension(unittest::optional_sfixed32_extension_lite));
1183 EXPECT_FALSE(message.HasExtension(unittest::optional_sfixed64_extension_lite));
1184 EXPECT_FALSE(message.HasExtension(unittest::optional_float_extension_lite ));
1185 EXPECT_FALSE(message.HasExtension(unittest::optional_double_extension_lite ));
1186 EXPECT_FALSE(message.HasExtension(unittest::optional_bool_extension_lite ));
1187 EXPECT_FALSE(message.HasExtension(unittest::optional_string_extension_lite ));
1188 EXPECT_FALSE(message.HasExtension(unittest::optional_bytes_extension_lite ));
1189
1190 EXPECT_FALSE(message.HasExtension(unittest::optionalgroup_extension_lite ));
1191 EXPECT_FALSE(message.HasExtension(unittest::optional_nested_message_extension_lite ));
1192 EXPECT_FALSE(message.HasExtension(unittest::optional_foreign_message_extension_lite ));
1193 EXPECT_FALSE(message.HasExtension(unittest::optional_import_message_extension_lite ));
1194 EXPECT_FALSE(message.HasExtension(unittest::optional_public_import_message_extension_lite));
1195 EXPECT_FALSE(message.HasExtension(unittest::optional_lazy_message_extension_lite ));
1196
1197 EXPECT_FALSE(message.HasExtension(unittest::optional_nested_enum_extension_lite ));
1198 EXPECT_FALSE(message.HasExtension(unittest::optional_foreign_enum_extension_lite));
1199 EXPECT_FALSE(message.HasExtension(unittest::optional_import_enum_extension_lite ));
1200
1201
1202 // Optional fields without defaults are set to zero or something like it.
1203 EXPECT_EQ(0 , message.GetExtension(unittest::optional_int32_extension_lite ));
1204 EXPECT_EQ(0 , message.GetExtension(unittest::optional_int64_extension_lite ));
1205 EXPECT_EQ(0 , message.GetExtension(unittest::optional_uint32_extension_lite ));
1206 EXPECT_EQ(0 , message.GetExtension(unittest::optional_uint64_extension_lite ));
1207 EXPECT_EQ(0 , message.GetExtension(unittest::optional_sint32_extension_lite ));
1208 EXPECT_EQ(0 , message.GetExtension(unittest::optional_sint64_extension_lite ));
1209 EXPECT_EQ(0 , message.GetExtension(unittest::optional_fixed32_extension_lite ));
1210 EXPECT_EQ(0 , message.GetExtension(unittest::optional_fixed64_extension_lite ));
1211 EXPECT_EQ(0 , message.GetExtension(unittest::optional_sfixed32_extension_lite));
1212 EXPECT_EQ(0 , message.GetExtension(unittest::optional_sfixed64_extension_lite));
1213 EXPECT_EQ(0 , message.GetExtension(unittest::optional_float_extension_lite ));
1214 EXPECT_EQ(0 , message.GetExtension(unittest::optional_double_extension_lite ));
1215 EXPECT_EQ(false, message.GetExtension(unittest::optional_bool_extension_lite ));
1216 EXPECT_EQ("" , message.GetExtension(unittest::optional_string_extension_lite ));
1217 EXPECT_EQ("" , message.GetExtension(unittest::optional_bytes_extension_lite ));
1218
1219 // Embedded messages should also be clear.
1220 EXPECT_FALSE(message.GetExtension(unittest::optionalgroup_extension_lite ).has_a());
1221 EXPECT_FALSE(message.GetExtension(unittest::optional_nested_message_extension_lite ).has_bb());
1222 EXPECT_FALSE(message.GetExtension(unittest::optional_foreign_message_extension_lite ).has_c());
1223 EXPECT_FALSE(message.GetExtension(unittest::optional_import_message_extension_lite ).has_d());
1224 EXPECT_FALSE(message.GetExtension(unittest::optional_public_import_message_extension_lite).has_e());
1225 EXPECT_FALSE(message.GetExtension(unittest::optional_lazy_message_extension_lite ).has_bb());
1226
1227 EXPECT_EQ(0, message.GetExtension(unittest::optionalgroup_extension_lite ).a());
1228 EXPECT_EQ(0, message.GetExtension(unittest::optional_nested_message_extension_lite ).bb());
1229 EXPECT_EQ(0, message.GetExtension(unittest::optional_foreign_message_extension_lite ).c());
1230 EXPECT_EQ(0, message.GetExtension(unittest::optional_import_message_extension_lite ).d());
1231 EXPECT_EQ(0, message.GetExtension(unittest::optional_public_import_message_extension_lite).e());
1232 EXPECT_EQ(0, message.GetExtension(unittest::optional_lazy_message_extension_lite ).bb());
1233
1234 // Enums without defaults are set to the first value in the enum.
1235 EXPECT_EQ(unittest::TestAllTypesLite::FOO , message.GetExtension(unittest::optional_nested_enum_extension_lite ));
1236 EXPECT_EQ(unittest::FOREIGN_LITE_FOO , message.GetExtension(unittest::optional_foreign_enum_extension_lite));
1237 EXPECT_EQ(unittest_import::IMPORT_LITE_FOO, message.GetExtension(unittest::optional_import_enum_extension_lite ));
1238
1239
1240 // Repeated fields are empty.
1241 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_int32_extension_lite ));
1242 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_int64_extension_lite ));
1243 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_uint32_extension_lite ));
1244 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_uint64_extension_lite ));
1245 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sint32_extension_lite ));
1246 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sint64_extension_lite ));
1247 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_fixed32_extension_lite ));
1248 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_fixed64_extension_lite ));
1249 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sfixed32_extension_lite));
1250 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_sfixed64_extension_lite));
1251 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_float_extension_lite ));
1252 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_double_extension_lite ));
1253 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_bool_extension_lite ));
1254 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_string_extension_lite ));
1255 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_bytes_extension_lite ));
1256
1257 EXPECT_EQ(0, message.ExtensionSize(unittest::repeatedgroup_extension_lite ));
1258 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_nested_message_extension_lite ));
1259 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_foreign_message_extension_lite));
1260 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_import_message_extension_lite ));
1261 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_lazy_message_extension_lite ));
1262 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_nested_enum_extension_lite ));
1263 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_foreign_enum_extension_lite ));
1264 EXPECT_EQ(0, message.ExtensionSize(unittest::repeated_import_enum_extension_lite ));
1265
1266
1267 // has_blah() should also be false for all default fields.
1268 EXPECT_FALSE(message.HasExtension(unittest::default_int32_extension_lite ));
1269 EXPECT_FALSE(message.HasExtension(unittest::default_int64_extension_lite ));
1270 EXPECT_FALSE(message.HasExtension(unittest::default_uint32_extension_lite ));
1271 EXPECT_FALSE(message.HasExtension(unittest::default_uint64_extension_lite ));
1272 EXPECT_FALSE(message.HasExtension(unittest::default_sint32_extension_lite ));
1273 EXPECT_FALSE(message.HasExtension(unittest::default_sint64_extension_lite ));
1274 EXPECT_FALSE(message.HasExtension(unittest::default_fixed32_extension_lite ));
1275 EXPECT_FALSE(message.HasExtension(unittest::default_fixed64_extension_lite ));
1276 EXPECT_FALSE(message.HasExtension(unittest::default_sfixed32_extension_lite));
1277 EXPECT_FALSE(message.HasExtension(unittest::default_sfixed64_extension_lite));
1278 EXPECT_FALSE(message.HasExtension(unittest::default_float_extension_lite ));
1279 EXPECT_FALSE(message.HasExtension(unittest::default_double_extension_lite ));
1280 EXPECT_FALSE(message.HasExtension(unittest::default_bool_extension_lite ));
1281 EXPECT_FALSE(message.HasExtension(unittest::default_string_extension_lite ));
1282 EXPECT_FALSE(message.HasExtension(unittest::default_bytes_extension_lite ));
1283
1284 EXPECT_FALSE(message.HasExtension(unittest::default_nested_enum_extension_lite ));
1285 EXPECT_FALSE(message.HasExtension(unittest::default_foreign_enum_extension_lite));
1286 EXPECT_FALSE(message.HasExtension(unittest::default_import_enum_extension_lite ));
1287
1288
1289 // Fields with defaults have their default values (duh).
1290 EXPECT_EQ( 41 , message.GetExtension(unittest::default_int32_extension_lite ));
1291 EXPECT_EQ( 42 , message.GetExtension(unittest::default_int64_extension_lite ));
1292 EXPECT_EQ( 43 , message.GetExtension(unittest::default_uint32_extension_lite ));
1293 EXPECT_EQ( 44 , message.GetExtension(unittest::default_uint64_extension_lite ));
1294 EXPECT_EQ(-45 , message.GetExtension(unittest::default_sint32_extension_lite ));
1295 EXPECT_EQ( 46 , message.GetExtension(unittest::default_sint64_extension_lite ));
1296 EXPECT_EQ( 47 , message.GetExtension(unittest::default_fixed32_extension_lite ));
1297 EXPECT_EQ( 48 , message.GetExtension(unittest::default_fixed64_extension_lite ));
1298 EXPECT_EQ( 49 , message.GetExtension(unittest::default_sfixed32_extension_lite));
1299 EXPECT_EQ(-50 , message.GetExtension(unittest::default_sfixed64_extension_lite));
1300 EXPECT_EQ( 51.5 , message.GetExtension(unittest::default_float_extension_lite ));
1301 EXPECT_EQ( 52e3 , message.GetExtension(unittest::default_double_extension_lite ));
1302 EXPECT_EQ(true , message.GetExtension(unittest::default_bool_extension_lite ));
1303 EXPECT_EQ("hello", message.GetExtension(unittest::default_string_extension_lite ));
1304 EXPECT_EQ("world", message.GetExtension(unittest::default_bytes_extension_lite ));
1305
1306 EXPECT_EQ(unittest::TestAllTypesLite::BAR , message.GetExtension(unittest::default_nested_enum_extension_lite ));
1307 EXPECT_EQ(unittest::FOREIGN_LITE_BAR , message.GetExtension(unittest::default_foreign_enum_extension_lite));
1308 EXPECT_EQ(unittest_import::IMPORT_LITE_BAR, message.GetExtension(unittest::default_import_enum_extension_lite ));
1309
1310
1311 EXPECT_FALSE(message.HasExtension(unittest::oneof_uint32_extension_lite));
1312 EXPECT_FALSE(message.GetExtension(unittest::oneof_nested_message_extension_lite).has_bb());
1313 EXPECT_FALSE(message.HasExtension(unittest::oneof_string_extension_lite));
1314 EXPECT_FALSE(message.HasExtension(unittest::oneof_bytes_extension_lite));
1315 }
1316
1317 // -------------------------------------------------------------------
1318
ExpectRepeatedExtensionsModified(const unittest::TestAllExtensionsLite & message)1319 void TestUtilLite::ExpectRepeatedExtensionsModified(
1320 const unittest::TestAllExtensionsLite& message) {
1321 // ModifyRepeatedFields only sets the second repeated element of each
1322 // field. In addition to verifying this, we also verify that the first
1323 // element and size were *not* modified.
1324 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int32_extension_lite ));
1325 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_int64_extension_lite ));
1326 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint32_extension_lite ));
1327 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_uint64_extension_lite ));
1328 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint32_extension_lite ));
1329 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sint64_extension_lite ));
1330 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed32_extension_lite ));
1331 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_fixed64_extension_lite ));
1332 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed32_extension_lite));
1333 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_sfixed64_extension_lite));
1334 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_float_extension_lite ));
1335 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_double_extension_lite ));
1336 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bool_extension_lite ));
1337 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_string_extension_lite ));
1338 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_bytes_extension_lite ));
1339
1340 ASSERT_EQ(2, message.ExtensionSize(unittest::repeatedgroup_extension_lite ));
1341 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_message_extension_lite ));
1342 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_message_extension_lite));
1343 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_message_extension_lite ));
1344 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_lazy_message_extension_lite ));
1345 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_nested_enum_extension_lite ));
1346 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_foreign_enum_extension_lite ));
1347 ASSERT_EQ(2, message.ExtensionSize(unittest::repeated_import_enum_extension_lite ));
1348
1349
1350 EXPECT_EQ(201 , message.GetExtension(unittest::repeated_int32_extension_lite , 0));
1351 EXPECT_EQ(202 , message.GetExtension(unittest::repeated_int64_extension_lite , 0));
1352 EXPECT_EQ(203 , message.GetExtension(unittest::repeated_uint32_extension_lite , 0));
1353 EXPECT_EQ(204 , message.GetExtension(unittest::repeated_uint64_extension_lite , 0));
1354 EXPECT_EQ(205 , message.GetExtension(unittest::repeated_sint32_extension_lite , 0));
1355 EXPECT_EQ(206 , message.GetExtension(unittest::repeated_sint64_extension_lite , 0));
1356 EXPECT_EQ(207 , message.GetExtension(unittest::repeated_fixed32_extension_lite , 0));
1357 EXPECT_EQ(208 , message.GetExtension(unittest::repeated_fixed64_extension_lite , 0));
1358 EXPECT_EQ(209 , message.GetExtension(unittest::repeated_sfixed32_extension_lite, 0));
1359 EXPECT_EQ(210 , message.GetExtension(unittest::repeated_sfixed64_extension_lite, 0));
1360 EXPECT_EQ(211 , message.GetExtension(unittest::repeated_float_extension_lite , 0));
1361 EXPECT_EQ(212 , message.GetExtension(unittest::repeated_double_extension_lite , 0));
1362 EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension_lite , 0));
1363 EXPECT_EQ("215", message.GetExtension(unittest::repeated_string_extension_lite , 0));
1364 EXPECT_EQ("216", message.GetExtension(unittest::repeated_bytes_extension_lite , 0));
1365
1366 EXPECT_EQ(217, message.GetExtension(unittest::repeatedgroup_extension_lite , 0).a());
1367 EXPECT_EQ(218, message.GetExtension(unittest::repeated_nested_message_extension_lite , 0).bb());
1368 EXPECT_EQ(219, message.GetExtension(unittest::repeated_foreign_message_extension_lite, 0).c());
1369 EXPECT_EQ(220, message.GetExtension(unittest::repeated_import_message_extension_lite , 0).d());
1370 EXPECT_EQ(227, message.GetExtension(unittest::repeated_lazy_message_extension_lite , 0).bb());
1371
1372 EXPECT_EQ(unittest::TestAllTypesLite::BAR , message.GetExtension(unittest::repeated_nested_enum_extension_lite , 0));
1373 EXPECT_EQ(unittest::FOREIGN_LITE_BAR , message.GetExtension(unittest::repeated_foreign_enum_extension_lite, 0));
1374 EXPECT_EQ(unittest_import::IMPORT_LITE_BAR, message.GetExtension(unittest::repeated_import_enum_extension_lite , 0));
1375
1376
1377 // Actually verify the second (modified) elements now.
1378 EXPECT_EQ(501 , message.GetExtension(unittest::repeated_int32_extension_lite , 1));
1379 EXPECT_EQ(502 , message.GetExtension(unittest::repeated_int64_extension_lite , 1));
1380 EXPECT_EQ(503 , message.GetExtension(unittest::repeated_uint32_extension_lite , 1));
1381 EXPECT_EQ(504 , message.GetExtension(unittest::repeated_uint64_extension_lite , 1));
1382 EXPECT_EQ(505 , message.GetExtension(unittest::repeated_sint32_extension_lite , 1));
1383 EXPECT_EQ(506 , message.GetExtension(unittest::repeated_sint64_extension_lite , 1));
1384 EXPECT_EQ(507 , message.GetExtension(unittest::repeated_fixed32_extension_lite , 1));
1385 EXPECT_EQ(508 , message.GetExtension(unittest::repeated_fixed64_extension_lite , 1));
1386 EXPECT_EQ(509 , message.GetExtension(unittest::repeated_sfixed32_extension_lite, 1));
1387 EXPECT_EQ(510 , message.GetExtension(unittest::repeated_sfixed64_extension_lite, 1));
1388 EXPECT_EQ(511 , message.GetExtension(unittest::repeated_float_extension_lite , 1));
1389 EXPECT_EQ(512 , message.GetExtension(unittest::repeated_double_extension_lite , 1));
1390 EXPECT_EQ(true , message.GetExtension(unittest::repeated_bool_extension_lite , 1));
1391 EXPECT_EQ("515", message.GetExtension(unittest::repeated_string_extension_lite , 1));
1392 EXPECT_EQ("516", message.GetExtension(unittest::repeated_bytes_extension_lite , 1));
1393
1394 EXPECT_EQ(517, message.GetExtension(unittest::repeatedgroup_extension_lite , 1).a());
1395 EXPECT_EQ(518, message.GetExtension(unittest::repeated_nested_message_extension_lite , 1).bb());
1396 EXPECT_EQ(519, message.GetExtension(unittest::repeated_foreign_message_extension_lite, 1).c());
1397 EXPECT_EQ(520, message.GetExtension(unittest::repeated_import_message_extension_lite , 1).d());
1398 EXPECT_EQ(527, message.GetExtension(unittest::repeated_lazy_message_extension_lite , 1).bb());
1399
1400 EXPECT_EQ(unittest::TestAllTypesLite::FOO , message.GetExtension(unittest::repeated_nested_enum_extension_lite , 1));
1401 EXPECT_EQ(unittest::FOREIGN_LITE_FOO , message.GetExtension(unittest::repeated_foreign_enum_extension_lite, 1));
1402 EXPECT_EQ(unittest_import::IMPORT_LITE_FOO, message.GetExtension(unittest::repeated_import_enum_extension_lite , 1));
1403
1404 }
1405
1406 // -------------------------------------------------------------------
1407
SetPackedExtensions(unittest::TestPackedExtensionsLite * message)1408 void TestUtilLite::SetPackedExtensions(
1409 unittest::TestPackedExtensionsLite* message) {
1410 message->AddExtension(unittest::packed_int32_extension_lite , 601);
1411 message->AddExtension(unittest::packed_int64_extension_lite , 602);
1412 message->AddExtension(unittest::packed_uint32_extension_lite , 603);
1413 message->AddExtension(unittest::packed_uint64_extension_lite , 604);
1414 message->AddExtension(unittest::packed_sint32_extension_lite , 605);
1415 message->AddExtension(unittest::packed_sint64_extension_lite , 606);
1416 message->AddExtension(unittest::packed_fixed32_extension_lite , 607);
1417 message->AddExtension(unittest::packed_fixed64_extension_lite , 608);
1418 message->AddExtension(unittest::packed_sfixed32_extension_lite, 609);
1419 message->AddExtension(unittest::packed_sfixed64_extension_lite, 610);
1420 message->AddExtension(unittest::packed_float_extension_lite , 611);
1421 message->AddExtension(unittest::packed_double_extension_lite , 612);
1422 message->AddExtension(unittest::packed_bool_extension_lite , true);
1423 message->AddExtension(unittest::packed_enum_extension_lite, unittest::FOREIGN_LITE_BAR);
1424 // add a second one of each field
1425 message->AddExtension(unittest::packed_int32_extension_lite , 701);
1426 message->AddExtension(unittest::packed_int64_extension_lite , 702);
1427 message->AddExtension(unittest::packed_uint32_extension_lite , 703);
1428 message->AddExtension(unittest::packed_uint64_extension_lite , 704);
1429 message->AddExtension(unittest::packed_sint32_extension_lite , 705);
1430 message->AddExtension(unittest::packed_sint64_extension_lite , 706);
1431 message->AddExtension(unittest::packed_fixed32_extension_lite , 707);
1432 message->AddExtension(unittest::packed_fixed64_extension_lite , 708);
1433 message->AddExtension(unittest::packed_sfixed32_extension_lite, 709);
1434 message->AddExtension(unittest::packed_sfixed64_extension_lite, 710);
1435 message->AddExtension(unittest::packed_float_extension_lite , 711);
1436 message->AddExtension(unittest::packed_double_extension_lite , 712);
1437 message->AddExtension(unittest::packed_bool_extension_lite , false);
1438 message->AddExtension(unittest::packed_enum_extension_lite, unittest::FOREIGN_LITE_BAZ);
1439 }
1440
1441 // -------------------------------------------------------------------
1442
ModifyPackedExtensions(unittest::TestPackedExtensionsLite * message)1443 void TestUtilLite::ModifyPackedExtensions(
1444 unittest::TestPackedExtensionsLite* message) {
1445 message->SetExtension(unittest::packed_int32_extension_lite , 1, 801);
1446 message->SetExtension(unittest::packed_int64_extension_lite , 1, 802);
1447 message->SetExtension(unittest::packed_uint32_extension_lite , 1, 803);
1448 message->SetExtension(unittest::packed_uint64_extension_lite , 1, 804);
1449 message->SetExtension(unittest::packed_sint32_extension_lite , 1, 805);
1450 message->SetExtension(unittest::packed_sint64_extension_lite , 1, 806);
1451 message->SetExtension(unittest::packed_fixed32_extension_lite , 1, 807);
1452 message->SetExtension(unittest::packed_fixed64_extension_lite , 1, 808);
1453 message->SetExtension(unittest::packed_sfixed32_extension_lite, 1, 809);
1454 message->SetExtension(unittest::packed_sfixed64_extension_lite, 1, 810);
1455 message->SetExtension(unittest::packed_float_extension_lite , 1, 811);
1456 message->SetExtension(unittest::packed_double_extension_lite , 1, 812);
1457 message->SetExtension(unittest::packed_bool_extension_lite , 1, true);
1458 message->SetExtension(unittest::packed_enum_extension_lite , 1,
1459 unittest::FOREIGN_LITE_FOO);
1460 }
1461
1462 // -------------------------------------------------------------------
1463
ExpectPackedExtensionsSet(const unittest::TestPackedExtensionsLite & message)1464 void TestUtilLite::ExpectPackedExtensionsSet(
1465 const unittest::TestPackedExtensionsLite& message) {
1466 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int32_extension_lite ));
1467 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int64_extension_lite ));
1468 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint32_extension_lite ));
1469 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint64_extension_lite ));
1470 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint32_extension_lite ));
1471 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint64_extension_lite ));
1472 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed32_extension_lite ));
1473 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed64_extension_lite ));
1474 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed32_extension_lite));
1475 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed64_extension_lite));
1476 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_float_extension_lite ));
1477 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_double_extension_lite ));
1478 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_bool_extension_lite ));
1479 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_enum_extension_lite ));
1480
1481 EXPECT_EQ(601 , message.GetExtension(unittest::packed_int32_extension_lite , 0));
1482 EXPECT_EQ(602 , message.GetExtension(unittest::packed_int64_extension_lite , 0));
1483 EXPECT_EQ(603 , message.GetExtension(unittest::packed_uint32_extension_lite , 0));
1484 EXPECT_EQ(604 , message.GetExtension(unittest::packed_uint64_extension_lite , 0));
1485 EXPECT_EQ(605 , message.GetExtension(unittest::packed_sint32_extension_lite , 0));
1486 EXPECT_EQ(606 , message.GetExtension(unittest::packed_sint64_extension_lite , 0));
1487 EXPECT_EQ(607 , message.GetExtension(unittest::packed_fixed32_extension_lite , 0));
1488 EXPECT_EQ(608 , message.GetExtension(unittest::packed_fixed64_extension_lite , 0));
1489 EXPECT_EQ(609 , message.GetExtension(unittest::packed_sfixed32_extension_lite, 0));
1490 EXPECT_EQ(610 , message.GetExtension(unittest::packed_sfixed64_extension_lite, 0));
1491 EXPECT_EQ(611 , message.GetExtension(unittest::packed_float_extension_lite , 0));
1492 EXPECT_EQ(612 , message.GetExtension(unittest::packed_double_extension_lite , 0));
1493 EXPECT_EQ(true , message.GetExtension(unittest::packed_bool_extension_lite , 0));
1494 EXPECT_EQ(unittest::FOREIGN_LITE_BAR,
1495 message.GetExtension(unittest::packed_enum_extension_lite, 0));
1496 EXPECT_EQ(701 , message.GetExtension(unittest::packed_int32_extension_lite , 1));
1497 EXPECT_EQ(702 , message.GetExtension(unittest::packed_int64_extension_lite , 1));
1498 EXPECT_EQ(703 , message.GetExtension(unittest::packed_uint32_extension_lite , 1));
1499 EXPECT_EQ(704 , message.GetExtension(unittest::packed_uint64_extension_lite , 1));
1500 EXPECT_EQ(705 , message.GetExtension(unittest::packed_sint32_extension_lite , 1));
1501 EXPECT_EQ(706 , message.GetExtension(unittest::packed_sint64_extension_lite , 1));
1502 EXPECT_EQ(707 , message.GetExtension(unittest::packed_fixed32_extension_lite , 1));
1503 EXPECT_EQ(708 , message.GetExtension(unittest::packed_fixed64_extension_lite , 1));
1504 EXPECT_EQ(709 , message.GetExtension(unittest::packed_sfixed32_extension_lite, 1));
1505 EXPECT_EQ(710 , message.GetExtension(unittest::packed_sfixed64_extension_lite, 1));
1506 EXPECT_EQ(711 , message.GetExtension(unittest::packed_float_extension_lite , 1));
1507 EXPECT_EQ(712 , message.GetExtension(unittest::packed_double_extension_lite , 1));
1508 EXPECT_EQ(false, message.GetExtension(unittest::packed_bool_extension_lite , 1));
1509 EXPECT_EQ(unittest::FOREIGN_LITE_BAZ,
1510 message.GetExtension(unittest::packed_enum_extension_lite, 1));
1511 }
1512
1513 // -------------------------------------------------------------------
1514
ExpectPackedExtensionsClear(const unittest::TestPackedExtensionsLite & message)1515 void TestUtilLite::ExpectPackedExtensionsClear(
1516 const unittest::TestPackedExtensionsLite& message) {
1517 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_int32_extension_lite ));
1518 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_int64_extension_lite ));
1519 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_uint32_extension_lite ));
1520 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_uint64_extension_lite ));
1521 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sint32_extension_lite ));
1522 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sint64_extension_lite ));
1523 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_fixed32_extension_lite ));
1524 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_fixed64_extension_lite ));
1525 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sfixed32_extension_lite));
1526 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_sfixed64_extension_lite));
1527 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_float_extension_lite ));
1528 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_double_extension_lite ));
1529 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_bool_extension_lite ));
1530 EXPECT_EQ(0, message.ExtensionSize(unittest::packed_enum_extension_lite ));
1531 }
1532
1533 // -------------------------------------------------------------------
1534
ExpectPackedExtensionsModified(const unittest::TestPackedExtensionsLite & message)1535 void TestUtilLite::ExpectPackedExtensionsModified(
1536 const unittest::TestPackedExtensionsLite& message) {
1537 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int32_extension_lite ));
1538 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_int64_extension_lite ));
1539 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint32_extension_lite ));
1540 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_uint64_extension_lite ));
1541 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint32_extension_lite ));
1542 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sint64_extension_lite ));
1543 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed32_extension_lite ));
1544 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_fixed64_extension_lite ));
1545 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed32_extension_lite));
1546 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_sfixed64_extension_lite));
1547 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_float_extension_lite ));
1548 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_double_extension_lite ));
1549 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_bool_extension_lite ));
1550 ASSERT_EQ(2, message.ExtensionSize(unittest::packed_enum_extension_lite ));
1551 EXPECT_EQ(601 , message.GetExtension(unittest::packed_int32_extension_lite , 0));
1552 EXPECT_EQ(602 , message.GetExtension(unittest::packed_int64_extension_lite , 0));
1553 EXPECT_EQ(603 , message.GetExtension(unittest::packed_uint32_extension_lite , 0));
1554 EXPECT_EQ(604 , message.GetExtension(unittest::packed_uint64_extension_lite , 0));
1555 EXPECT_EQ(605 , message.GetExtension(unittest::packed_sint32_extension_lite , 0));
1556 EXPECT_EQ(606 , message.GetExtension(unittest::packed_sint64_extension_lite , 0));
1557 EXPECT_EQ(607 , message.GetExtension(unittest::packed_fixed32_extension_lite , 0));
1558 EXPECT_EQ(608 , message.GetExtension(unittest::packed_fixed64_extension_lite , 0));
1559 EXPECT_EQ(609 , message.GetExtension(unittest::packed_sfixed32_extension_lite, 0));
1560 EXPECT_EQ(610 , message.GetExtension(unittest::packed_sfixed64_extension_lite, 0));
1561 EXPECT_EQ(611 , message.GetExtension(unittest::packed_float_extension_lite , 0));
1562 EXPECT_EQ(612 , message.GetExtension(unittest::packed_double_extension_lite , 0));
1563 EXPECT_EQ(true , message.GetExtension(unittest::packed_bool_extension_lite , 0));
1564 EXPECT_EQ(unittest::FOREIGN_LITE_BAR,
1565 message.GetExtension(unittest::packed_enum_extension_lite, 0));
1566
1567 // Actually verify the second (modified) elements now.
1568 EXPECT_EQ(801 , message.GetExtension(unittest::packed_int32_extension_lite , 1));
1569 EXPECT_EQ(802 , message.GetExtension(unittest::packed_int64_extension_lite , 1));
1570 EXPECT_EQ(803 , message.GetExtension(unittest::packed_uint32_extension_lite , 1));
1571 EXPECT_EQ(804 , message.GetExtension(unittest::packed_uint64_extension_lite , 1));
1572 EXPECT_EQ(805 , message.GetExtension(unittest::packed_sint32_extension_lite , 1));
1573 EXPECT_EQ(806 , message.GetExtension(unittest::packed_sint64_extension_lite , 1));
1574 EXPECT_EQ(807 , message.GetExtension(unittest::packed_fixed32_extension_lite , 1));
1575 EXPECT_EQ(808 , message.GetExtension(unittest::packed_fixed64_extension_lite , 1));
1576 EXPECT_EQ(809 , message.GetExtension(unittest::packed_sfixed32_extension_lite, 1));
1577 EXPECT_EQ(810 , message.GetExtension(unittest::packed_sfixed64_extension_lite, 1));
1578 EXPECT_EQ(811 , message.GetExtension(unittest::packed_float_extension_lite , 1));
1579 EXPECT_EQ(812 , message.GetExtension(unittest::packed_double_extension_lite , 1));
1580 EXPECT_EQ(true , message.GetExtension(unittest::packed_bool_extension_lite , 1));
1581 EXPECT_EQ(unittest::FOREIGN_LITE_FOO,
1582 message.GetExtension(unittest::packed_enum_extension_lite, 1));
1583 }
1584
1585 } // namespace protobuf
1586 } // namespace google
1587