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