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