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