map_test_util.cc
Go to the documentation of this file.
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 
35 
36 namespace google {
37 namespace protobuf {
38 
39 void MapTestUtil::SetMapFields(unittest::TestMap* message) {
40  MapTestUtilImpl::SetMapFields<unittest::MapEnum, unittest::MAP_ENUM_BAR,
41  unittest::MAP_ENUM_BAZ>(message);
42 }
43 
44 void MapTestUtil::SetArenaMapFields(unittest::TestArenaMap* message) {
45  MapTestUtilImpl::SetArenaMapFields<unittest::MapEnum, unittest::MAP_ENUM_BAR,
46  unittest::MAP_ENUM_BAZ>(message);
47 }
48 
51 }
52 
53 void MapTestUtil::ModifyMapFields(unittest::TestMap* message) {
54  MapTestUtilImpl::ModifyMapFields<unittest::MapEnum, unittest::MAP_ENUM_FOO>(
55  message);
56 }
57 
58 void MapTestUtil::ExpectClear(const unittest::TestMap& message) {
60 }
61 
62 void MapTestUtil::ExpectMapFieldsSet(const unittest::TestMap& message) {
63  MapTestUtilImpl::ExpectMapFieldsSet<unittest::MapEnum, unittest::MAP_ENUM_BAR,
64  unittest::MAP_ENUM_BAZ>(message);
65 }
66 
68  const unittest::TestArenaMap& message) {
70  unittest::MapEnum, unittest::MAP_ENUM_BAR, unittest::MAP_ENUM_BAZ>(
71  message);
72 }
73 
75  const unittest::TestMap& message) {
77  unittest::MAP_ENUM_FOO>(
78  message);
79 }
80 
81 void MapTestUtil::ExpectMapFieldsModified(const unittest::TestMap& message) {
83  unittest::MapEnum, unittest::MAP_ENUM_BAR, unittest::MAP_ENUM_FOO>(
84  message);
85 }
86 
87 void MapTestUtil::ExpectMapsSize(const unittest::TestMap& message, int size) {
88  const Descriptor* descriptor = message.GetDescriptor();
89 
90  EXPECT_EQ(size, message.GetReflection()->FieldSize(
91  message, descriptor->FindFieldByName("map_int32_int32")));
92  EXPECT_EQ(size, message.GetReflection()->FieldSize(
93  message, descriptor->FindFieldByName("map_int64_int64")));
95  message.GetReflection()->FieldSize(
96  message, descriptor->FindFieldByName("map_uint32_uint32")));
98  message.GetReflection()->FieldSize(
99  message, descriptor->FindFieldByName("map_uint64_uint64")));
100  EXPECT_EQ(size,
101  message.GetReflection()->FieldSize(
102  message, descriptor->FindFieldByName("map_sint32_sint32")));
103  EXPECT_EQ(size,
104  message.GetReflection()->FieldSize(
105  message, descriptor->FindFieldByName("map_sint64_sint64")));
106  EXPECT_EQ(size,
107  message.GetReflection()->FieldSize(
108  message, descriptor->FindFieldByName("map_fixed32_fixed32")));
109  EXPECT_EQ(size,
110  message.GetReflection()->FieldSize(
111  message, descriptor->FindFieldByName("map_fixed64_fixed64")));
112  EXPECT_EQ(size,
113  message.GetReflection()->FieldSize(
114  message, descriptor->FindFieldByName("map_sfixed32_sfixed32")));
115  EXPECT_EQ(size,
116  message.GetReflection()->FieldSize(
117  message, descriptor->FindFieldByName("map_sfixed64_sfixed64")));
118  EXPECT_EQ(size, message.GetReflection()->FieldSize(
119  message, descriptor->FindFieldByName("map_int32_float")));
120  EXPECT_EQ(size,
121  message.GetReflection()->FieldSize(
122  message, descriptor->FindFieldByName("map_int32_double")));
123  EXPECT_EQ(size, message.GetReflection()->FieldSize(
124  message, descriptor->FindFieldByName("map_bool_bool")));
125  EXPECT_EQ(size,
126  message.GetReflection()->FieldSize(
127  message, descriptor->FindFieldByName("map_string_string")));
128  EXPECT_EQ(size, message.GetReflection()->FieldSize(
129  message, descriptor->FindFieldByName("map_int32_bytes")));
130  EXPECT_EQ(
131  size,
132  message.GetReflection()->FieldSize(
133  message, descriptor->FindFieldByName("map_int32_foreign_message")));
134 }
135 
136 std::vector<const Message*> MapTestUtil::GetMapEntries(
137  const unittest::TestMap& message, int index) {
138  const Descriptor* descriptor = message.GetDescriptor();
139  std::vector<const Message*> result;
140 
141  result.push_back(&message.GetReflection()->GetRepeatedMessage(
142  message, descriptor->FindFieldByName("map_int32_int32"), index));
143  result.push_back(&message.GetReflection()->GetRepeatedMessage(
144  message, descriptor->FindFieldByName("map_int64_int64"), index));
145  result.push_back(&message.GetReflection()->GetRepeatedMessage(
146  message, descriptor->FindFieldByName("map_uint32_uint32"), index));
147  result.push_back(&message.GetReflection()->GetRepeatedMessage(
148  message, descriptor->FindFieldByName("map_uint64_uint64"), index));
149  result.push_back(&message.GetReflection()->GetRepeatedMessage(
150  message, descriptor->FindFieldByName("map_sint32_sint32"), index));
151  result.push_back(&message.GetReflection()->GetRepeatedMessage(
152  message, descriptor->FindFieldByName("map_sint64_sint64"), index));
153  result.push_back(&message.GetReflection()->GetRepeatedMessage(
154  message, descriptor->FindFieldByName("map_fixed32_fixed32"), index));
155  result.push_back(&message.GetReflection()->GetRepeatedMessage(
156  message, descriptor->FindFieldByName("map_fixed64_fixed64"), index));
157  result.push_back(&message.GetReflection()->GetRepeatedMessage(
158  message, descriptor->FindFieldByName("map_sfixed32_sfixed32"), index));
159  result.push_back(&message.GetReflection()->GetRepeatedMessage(
160  message, descriptor->FindFieldByName("map_sfixed64_sfixed64"), index));
161  result.push_back(&message.GetReflection()->GetRepeatedMessage(
162  message, descriptor->FindFieldByName("map_int32_float"), index));
163  result.push_back(&message.GetReflection()->GetRepeatedMessage(
164  message, descriptor->FindFieldByName("map_int32_double"), index));
165  result.push_back(&message.GetReflection()->GetRepeatedMessage(
166  message, descriptor->FindFieldByName("map_bool_bool"), index));
167  result.push_back(&message.GetReflection()->GetRepeatedMessage(
168  message, descriptor->FindFieldByName("map_string_string"), index));
169  result.push_back(&message.GetReflection()->GetRepeatedMessage(
170  message, descriptor->FindFieldByName("map_int32_bytes"), index));
171  result.push_back(&message.GetReflection()->GetRepeatedMessage(
172  message, descriptor->FindFieldByName("map_int32_enum"), index));
173  result.push_back(&message.GetReflection()->GetRepeatedMessage(
174  message, descriptor->FindFieldByName("map_int32_foreign_message"),
175  index));
176 
177  return result;
178 }
179 
180 std::vector<const Message*> MapTestUtil::GetMapEntriesFromRelease(
181  unittest::TestMap* message) {
182  const Descriptor* descriptor = message->GetDescriptor();
183  std::vector<const Message*> result;
184 
185  result.push_back(message->GetReflection()->ReleaseLast(
186  message, descriptor->FindFieldByName("map_int32_int32")));
187  result.push_back(message->GetReflection()->ReleaseLast(
188  message, descriptor->FindFieldByName("map_int64_int64")));
189  result.push_back(message->GetReflection()->ReleaseLast(
190  message, descriptor->FindFieldByName("map_uint32_uint32")));
191  result.push_back(message->GetReflection()->ReleaseLast(
192  message, descriptor->FindFieldByName("map_uint64_uint64")));
193  result.push_back(message->GetReflection()->ReleaseLast(
194  message, descriptor->FindFieldByName("map_sint32_sint32")));
195  result.push_back(message->GetReflection()->ReleaseLast(
196  message, descriptor->FindFieldByName("map_sint64_sint64")));
197  result.push_back(message->GetReflection()->ReleaseLast(
198  message, descriptor->FindFieldByName("map_fixed32_fixed32")));
199  result.push_back(message->GetReflection()->ReleaseLast(
200  message, descriptor->FindFieldByName("map_fixed64_fixed64")));
201  result.push_back(message->GetReflection()->ReleaseLast(
202  message, descriptor->FindFieldByName("map_sfixed32_sfixed32")));
203  result.push_back(message->GetReflection()->ReleaseLast(
204  message, descriptor->FindFieldByName("map_sfixed64_sfixed64")));
205  result.push_back(message->GetReflection()->ReleaseLast(
206  message, descriptor->FindFieldByName("map_int32_float")));
207  result.push_back(message->GetReflection()->ReleaseLast(
208  message, descriptor->FindFieldByName("map_int32_double")));
209  result.push_back(message->GetReflection()->ReleaseLast(
210  message, descriptor->FindFieldByName("map_bool_bool")));
211  result.push_back(message->GetReflection()->ReleaseLast(
212  message, descriptor->FindFieldByName("map_string_string")));
213  result.push_back(message->GetReflection()->ReleaseLast(
214  message, descriptor->FindFieldByName("map_int32_bytes")));
215  result.push_back(message->GetReflection()->ReleaseLast(
216  message, descriptor->FindFieldByName("map_int32_enum")));
217  result.push_back(message->GetReflection()->ReleaseLast(
218  message, descriptor->FindFieldByName("map_int32_foreign_message")));
219 
220  return result;
221 }
222 
224  : base_descriptor_(base_descriptor) {
225  const DescriptorPool* pool = base_descriptor->file()->pool();
226 
227  map_enum_foo_ = pool->FindEnumValueByName("protobuf_unittest.MAP_ENUM_FOO");
228  map_enum_bar_ = pool->FindEnumValueByName("protobuf_unittest.MAP_ENUM_BAR");
229  map_enum_baz_ = pool->FindEnumValueByName("protobuf_unittest.MAP_ENUM_BAZ");
230 
231  foreign_c_ = pool->FindFieldByName("protobuf_unittest.ForeignMessage.c");
233  pool->FindFieldByName("protobuf_unittest.TestMap.MapInt32Int32Entry.key");
235  pool->FindFieldByName("protobuf_unittest.TestMap.MapInt32Int32Entry.value");
237  pool->FindFieldByName("protobuf_unittest.TestMap.MapInt64Int64Entry.key");
239  pool->FindFieldByName("protobuf_unittest.TestMap.MapInt64Int64Entry.value");
241  pool->FindFieldByName("protobuf_unittest.TestMap.MapUint32Uint32Entry.key");
242  map_uint32_uint32_val_ = pool->FindFieldByName(
243  "protobuf_unittest.TestMap.MapUint32Uint32Entry.value");
245  pool->FindFieldByName("protobuf_unittest.TestMap.MapUint64Uint64Entry.key");
246  map_uint64_uint64_val_ = pool->FindFieldByName(
247  "protobuf_unittest.TestMap.MapUint64Uint64Entry.value");
249  pool->FindFieldByName("protobuf_unittest.TestMap.MapSint32Sint32Entry.key");
250  map_sint32_sint32_val_ = pool->FindFieldByName(
251  "protobuf_unittest.TestMap.MapSint32Sint32Entry.value");
253  pool->FindFieldByName("protobuf_unittest.TestMap.MapSint64Sint64Entry.key");
254  map_sint64_sint64_val_ = pool->FindFieldByName(
255  "protobuf_unittest.TestMap.MapSint64Sint64Entry.value");
256  map_fixed32_fixed32_key_ = pool->FindFieldByName(
257  "protobuf_unittest.TestMap.MapFixed32Fixed32Entry.key");
258  map_fixed32_fixed32_val_ = pool->FindFieldByName(
259  "protobuf_unittest.TestMap.MapFixed32Fixed32Entry.value");
260  map_fixed64_fixed64_key_ = pool->FindFieldByName(
261  "protobuf_unittest.TestMap.MapFixed64Fixed64Entry.key");
262  map_fixed64_fixed64_val_ = pool->FindFieldByName(
263  "protobuf_unittest.TestMap.MapFixed64Fixed64Entry.value");
264  map_sfixed32_sfixed32_key_ = pool->FindFieldByName(
265  "protobuf_unittest.TestMap.MapSfixed32Sfixed32Entry.key");
266  map_sfixed32_sfixed32_val_ = pool->FindFieldByName(
267  "protobuf_unittest.TestMap.MapSfixed32Sfixed32Entry.value");
268  map_sfixed64_sfixed64_key_ = pool->FindFieldByName(
269  "protobuf_unittest.TestMap.MapSfixed64Sfixed64Entry.key");
270  map_sfixed64_sfixed64_val_ = pool->FindFieldByName(
271  "protobuf_unittest.TestMap.MapSfixed64Sfixed64Entry.value");
273  pool->FindFieldByName("protobuf_unittest.TestMap.MapInt32FloatEntry.key");
275  pool->FindFieldByName("protobuf_unittest.TestMap.MapInt32FloatEntry.value");
277  pool->FindFieldByName("protobuf_unittest.TestMap.MapInt32DoubleEntry.key");
278  map_int32_double_val_ = pool->FindFieldByName(
279  "protobuf_unittest.TestMap.MapInt32DoubleEntry.value");
281  pool->FindFieldByName("protobuf_unittest.TestMap.MapBoolBoolEntry.key");
283  pool->FindFieldByName("protobuf_unittest.TestMap.MapBoolBoolEntry.value");
285  pool->FindFieldByName("protobuf_unittest.TestMap.MapStringStringEntry.key");
286  map_string_string_val_ = pool->FindFieldByName(
287  "protobuf_unittest.TestMap.MapStringStringEntry.value");
289  pool->FindFieldByName("protobuf_unittest.TestMap.MapInt32BytesEntry.key");
291  pool->FindFieldByName("protobuf_unittest.TestMap.MapInt32BytesEntry.value");
293  pool->FindFieldByName("protobuf_unittest.TestMap.MapInt32EnumEntry.key");
295  pool->FindFieldByName("protobuf_unittest.TestMap.MapInt32EnumEntry.value");
296  map_int32_foreign_message_key_ = pool->FindFieldByName(
297  "protobuf_unittest.TestMap.MapInt32ForeignMessageEntry.key");
298  map_int32_foreign_message_val_ = pool->FindFieldByName(
299  "protobuf_unittest.TestMap.MapInt32ForeignMessageEntry.value");
300 
338 }
339 
340 // Shorthand to get a FieldDescriptor for a field of unittest::TestMap.
342  const FieldDescriptor* result = NULL;
344  GOOGLE_CHECK(result != NULL);
345  return result;
346 }
347 
349  const Reflection* reflection = message->GetReflection();
350  Message* sub_message = NULL;
351  Message* sub_foreign_message = NULL;
352 
353  // Add first element.
354  sub_message = reflection->AddMessage(message, F("map_int32_int32"));
355  sub_message->GetReflection()->SetInt32(sub_message, map_int32_int32_key_, 0);
356  sub_message->GetReflection()->SetInt32(sub_message, map_int32_int32_val_, 0);
357 
358  sub_message = reflection->AddMessage(message, F("map_int64_int64"));
359  sub_message->GetReflection()->SetInt64(sub_message, map_int64_int64_key_, 0);
360  sub_message->GetReflection()->SetInt64(sub_message, map_int64_int64_val_, 0);
361 
362  sub_message = reflection->AddMessage(message, F("map_uint32_uint32"));
363  sub_message->GetReflection()->SetUInt32(sub_message, map_uint32_uint32_key_,
364  0);
365  sub_message->GetReflection()->SetUInt32(sub_message, map_uint32_uint32_val_,
366  0);
367 
368  sub_message = reflection->AddMessage(message, F("map_uint64_uint64"));
369  sub_message->GetReflection()->SetUInt64(sub_message, map_uint64_uint64_key_,
370  0);
371  sub_message->GetReflection()->SetUInt64(sub_message, map_uint64_uint64_val_,
372  0);
373 
374  sub_message = reflection->AddMessage(message, F("map_sint32_sint32"));
375  sub_message->GetReflection()->SetInt32(sub_message, map_sint32_sint32_key_,
376  0);
377  sub_message->GetReflection()->SetInt32(sub_message, map_sint32_sint32_val_,
378  0);
379 
380  sub_message = reflection->AddMessage(message, F("map_sint64_sint64"));
381  sub_message->GetReflection()->SetInt64(sub_message, map_sint64_sint64_key_,
382  0);
383  sub_message->GetReflection()->SetInt64(sub_message, map_sint64_sint64_val_,
384  0);
385 
386  sub_message = reflection->AddMessage(message, F("map_fixed32_fixed32"));
387  sub_message->GetReflection()->SetUInt32(sub_message, map_fixed32_fixed32_key_,
388  0);
389  sub_message->GetReflection()->SetUInt32(sub_message, map_fixed32_fixed32_val_,
390  0);
391 
392  sub_message = reflection->AddMessage(message, F("map_fixed64_fixed64"));
393  sub_message->GetReflection()->SetUInt64(sub_message, map_fixed64_fixed64_key_,
394  0);
395  sub_message->GetReflection()->SetUInt64(sub_message, map_fixed64_fixed64_val_,
396  0);
397 
398  sub_message = reflection->AddMessage(message, F("map_sfixed32_sfixed32"));
399  sub_message->GetReflection()->SetInt32(sub_message,
401  sub_message->GetReflection()->SetInt32(sub_message,
403 
404  sub_message = reflection->AddMessage(message, F("map_sfixed64_sfixed64"));
405  sub_message->GetReflection()->SetInt64(sub_message,
407  sub_message->GetReflection()->SetInt64(sub_message,
409 
410  sub_message = reflection->AddMessage(message, F("map_int32_float"));
411  sub_message->GetReflection()->SetInt32(sub_message, map_int32_float_key_, 0);
412  sub_message->GetReflection()->SetFloat(sub_message, map_int32_float_val_,
413  0.0);
414 
415  sub_message = reflection->AddMessage(message, F("map_int32_double"));
416  sub_message->GetReflection()->SetInt32(sub_message, map_int32_double_key_, 0);
417  sub_message->GetReflection()->SetDouble(sub_message, map_int32_double_val_,
418  0.0);
419 
420  sub_message = reflection->AddMessage(message, F("map_bool_bool"));
421  sub_message->GetReflection()->SetBool(sub_message, map_bool_bool_key_, false);
422  sub_message->GetReflection()->SetBool(sub_message, map_bool_bool_val_, false);
423 
424  sub_message = reflection->AddMessage(message, F("map_string_string"));
425  sub_message->GetReflection()->SetString(sub_message, map_string_string_key_,
426  "0");
427  sub_message->GetReflection()->SetString(sub_message, map_string_string_val_,
428  "0");
429 
430  sub_message = reflection->AddMessage(message, F("map_int32_bytes"));
431  sub_message->GetReflection()->SetInt32(sub_message, map_int32_bytes_key_, 0);
432  sub_message->GetReflection()->SetString(sub_message, map_int32_bytes_val_,
433  "0");
434 
435  sub_message = reflection->AddMessage(message, F("map_int32_enum"));
436  sub_message->GetReflection()->SetInt32(sub_message, map_int32_enum_key_, 0);
437  sub_message->GetReflection()->SetEnum(sub_message, map_int32_enum_val_,
438  map_enum_bar_);
439 
440  sub_message = reflection->AddMessage(message, F("map_int32_foreign_message"));
441  sub_message->GetReflection()->SetInt32(sub_message,
443  sub_foreign_message = sub_message->GetReflection()->MutableMessage(
444  sub_message, map_int32_foreign_message_val_, NULL);
445  sub_foreign_message->GetReflection()->SetInt32(sub_foreign_message,
446  foreign_c_, 0);
447 
448  // Add second element
449  sub_message = reflection->AddMessage(message, F("map_int32_int32"));
450  sub_message->GetReflection()->SetInt32(sub_message, map_int32_int32_key_, 1);
451  sub_message->GetReflection()->SetInt32(sub_message, map_int32_int32_val_, 1);
452 
453  sub_message = reflection->AddMessage(message, F("map_int64_int64"));
454  sub_message->GetReflection()->SetInt64(sub_message, map_int64_int64_key_, 1);
455  sub_message->GetReflection()->SetInt64(sub_message, map_int64_int64_val_, 1);
456 
457  sub_message = reflection->AddMessage(message, F("map_uint32_uint32"));
458  sub_message->GetReflection()->SetUInt32(sub_message, map_uint32_uint32_key_,
459  1);
460  sub_message->GetReflection()->SetUInt32(sub_message, map_uint32_uint32_val_,
461  1);
462 
463  sub_message = reflection->AddMessage(message, F("map_uint64_uint64"));
464  sub_message->GetReflection()->SetUInt64(sub_message, map_uint64_uint64_key_,
465  1);
466  sub_message->GetReflection()->SetUInt64(sub_message, map_uint64_uint64_val_,
467  1);
468 
469  sub_message = reflection->AddMessage(message, F("map_sint32_sint32"));
470  sub_message->GetReflection()->SetInt32(sub_message, map_sint32_sint32_key_,
471  1);
472  sub_message->GetReflection()->SetInt32(sub_message, map_sint32_sint32_val_,
473  1);
474 
475  sub_message = reflection->AddMessage(message, F("map_sint64_sint64"));
476  sub_message->GetReflection()->SetInt64(sub_message, map_sint64_sint64_key_,
477  1);
478  sub_message->GetReflection()->SetInt64(sub_message, map_sint64_sint64_val_,
479  1);
480 
481  sub_message = reflection->AddMessage(message, F("map_fixed32_fixed32"));
482  sub_message->GetReflection()->SetUInt32(sub_message, map_fixed32_fixed32_key_,
483  1);
484  sub_message->GetReflection()->SetUInt32(sub_message, map_fixed32_fixed32_val_,
485  1);
486 
487  sub_message = reflection->AddMessage(message, F("map_fixed64_fixed64"));
488  sub_message->GetReflection()->SetUInt64(sub_message, map_fixed64_fixed64_key_,
489  1);
490  sub_message->GetReflection()->SetUInt64(sub_message, map_fixed64_fixed64_val_,
491  1);
492 
493  sub_message = reflection->AddMessage(message, F("map_sfixed32_sfixed32"));
494  sub_message->GetReflection()->SetInt32(sub_message,
496  sub_message->GetReflection()->SetInt32(sub_message,
498 
499  sub_message = reflection->AddMessage(message, F("map_sfixed64_sfixed64"));
500  sub_message->GetReflection()->SetInt64(sub_message,
502  sub_message->GetReflection()->SetInt64(sub_message,
504 
505  sub_message = reflection->AddMessage(message, F("map_int32_float"));
506  sub_message->GetReflection()->SetInt32(sub_message, map_int32_float_key_, 1);
507  sub_message->GetReflection()->SetFloat(sub_message, map_int32_float_val_,
508  1.0);
509 
510  sub_message = reflection->AddMessage(message, F("map_int32_double"));
511  sub_message->GetReflection()->SetInt32(sub_message, map_int32_double_key_, 1);
512  sub_message->GetReflection()->SetDouble(sub_message, map_int32_double_val_,
513  1.0);
514 
515  sub_message = reflection->AddMessage(message, F("map_bool_bool"));
516  sub_message->GetReflection()->SetBool(sub_message, map_bool_bool_key_, true);
517  sub_message->GetReflection()->SetBool(sub_message, map_bool_bool_val_, true);
518 
519  sub_message = reflection->AddMessage(message, F("map_string_string"));
520  sub_message->GetReflection()->SetString(sub_message, map_string_string_key_,
521  "1");
522  sub_message->GetReflection()->SetString(sub_message, map_string_string_val_,
523  "1");
524 
525  sub_message = reflection->AddMessage(message, F("map_int32_bytes"));
526  sub_message->GetReflection()->SetInt32(sub_message, map_int32_bytes_key_, 1);
527  sub_message->GetReflection()->SetString(sub_message, map_int32_bytes_val_,
528  "1");
529 
530  sub_message = reflection->AddMessage(message, F("map_int32_enum"));
531  sub_message->GetReflection()->SetInt32(sub_message, map_int32_enum_key_, 1);
532  sub_message->GetReflection()->SetEnum(sub_message, map_int32_enum_val_,
533  map_enum_baz_);
534 
535  sub_message = reflection->AddMessage(message, F("map_int32_foreign_message"));
536  sub_message->GetReflection()->SetInt32(sub_message,
538  sub_foreign_message = sub_message->GetReflection()->MutableMessage(
539  sub_message, map_int32_foreign_message_val_, NULL);
540  sub_foreign_message->GetReflection()->SetInt32(sub_foreign_message,
541  foreign_c_, 1);
542 }
543 
545  const Reflection* reflection = message->GetReflection();
546 
547  Message* sub_foreign_message = NULL;
548  MapValueRef map_val;
549 
550  // Add first element.
551  MapKey map_key;
552  map_key.SetInt32Value(0);
553  EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int32_int32"),
554  map_key, &map_val));
555  map_val.SetInt32Value(0);
556 
557  map_key.SetInt64Value(0);
558  EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int64_int64"),
559  map_key, &map_val));
560  map_val.SetInt64Value(0);
561 
562  map_key.SetUInt32Value(0);
564  message, F("map_uint32_uint32"), map_key, &map_val));
565  map_val.SetUInt32Value(0);
566 
567  map_key.SetUInt64Value(0);
569  message, F("map_uint64_uint64"), map_key, &map_val));
570  map_val.SetUInt64Value(0);
571 
572  map_key.SetInt32Value(0);
574  message, F("map_sint32_sint32"), map_key, &map_val));
575  map_val.SetInt32Value(0);
576 
577  map_key.SetInt64Value(0);
579  message, F("map_sint64_sint64"), map_key, &map_val));
580  map_val.SetInt64Value(0);
581 
582  map_key.SetUInt32Value(0);
584  message, F("map_fixed32_fixed32"), map_key, &map_val));
585  map_val.SetUInt32Value(0);
586 
587  map_key.SetUInt64Value(0);
589  message, F("map_fixed64_fixed64"), map_key, &map_val));
590  map_val.SetUInt64Value(0);
591 
592  map_key.SetInt32Value(0);
594  message, F("map_sfixed32_sfixed32"), map_key, &map_val));
595  map_val.SetInt32Value(0);
596 
597  map_key.SetInt64Value(0);
599  message, F("map_sfixed64_sfixed64"), map_key, &map_val));
600  map_val.SetInt64Value(0);
601 
602  map_key.SetInt32Value(0);
603  EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int32_float"),
604  map_key, &map_val));
605  map_val.SetFloatValue(0.0);
606 
607  map_key.SetInt32Value(0);
608  EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int32_double"),
609  map_key, &map_val));
610  map_val.SetDoubleValue(0.0);
611 
612  map_key.SetBoolValue(false);
613  EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_bool_bool"),
614  map_key, &map_val));
615  map_val.SetBoolValue(false);
616 
617  map_key.SetStringValue("0");
619  message, F("map_string_string"), map_key, &map_val));
620  map_val.SetStringValue("0");
621 
622  map_key.SetInt32Value(0);
623  EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int32_bytes"),
624  map_key, &map_val));
625  map_val.SetStringValue("0");
626 
627  map_key.SetInt32Value(0);
628  EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int32_enum"),
629  map_key, &map_val));
630  map_val.SetEnumValue(map_enum_bar_->number());
631 
632  map_key.SetInt32Value(0);
634  message, F("map_int32_foreign_message"), map_key, &map_val));
635  sub_foreign_message = map_val.MutableMessageValue();
636  sub_foreign_message->GetReflection()->SetInt32(sub_foreign_message,
637  foreign_c_, 0);
638 
639  // Add second element
640  map_key.SetInt32Value(1);
641  EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int32_int32"),
642  map_key, &map_val));
643  map_val.SetInt32Value(1);
644  EXPECT_FALSE(reflection->InsertOrLookupMapValue(message, F("map_int32_int32"),
645  map_key, &map_val));
646 
647  map_key.SetInt64Value(1);
648  EXPECT_TRUE(reflection->InsertOrLookupMapValue(message, F("map_int64_int64"),
649  map_key, &map_val));
650  map_val.SetInt64Value(1);
651  EXPECT_FALSE(reflection->InsertOrLookupMapValue(message, F("map_int64_int64"),
652  map_key, &map_val));
653 
654  map_key.SetUInt32Value(1);
655  reflection->InsertOrLookupMapValue(message, F("map_uint32_uint32"), map_key,
656  &map_val);
657  map_val.SetUInt32Value(1);
658 
659  map_key.SetUInt64Value(1);
660  reflection->InsertOrLookupMapValue(message, F("map_uint64_uint64"), map_key,
661  &map_val);
662  map_val.SetUInt64Value(1);
663 
664  map_key.SetInt32Value(1);
665  reflection->InsertOrLookupMapValue(message, F("map_sint32_sint32"), map_key,
666  &map_val);
667  map_val.SetInt32Value(1);
668 
669  map_key.SetInt64Value(1);
670  reflection->InsertOrLookupMapValue(message, F("map_sint64_sint64"), map_key,
671  &map_val);
672  map_val.SetInt64Value(1);
673 
674  map_key.SetUInt32Value(1);
675  reflection->InsertOrLookupMapValue(message, F("map_fixed32_fixed32"), map_key,
676  &map_val);
677  map_val.SetUInt32Value(1);
678 
679  map_key.SetUInt64Value(1);
680  reflection->InsertOrLookupMapValue(message, F("map_fixed64_fixed64"), map_key,
681  &map_val);
682  map_val.SetUInt64Value(1);
683 
684  map_key.SetInt32Value(1);
685  reflection->InsertOrLookupMapValue(message, F("map_sfixed32_sfixed32"),
686  map_key, &map_val);
687  map_val.SetInt32Value(1);
688 
689  map_key.SetInt64Value(1);
690  reflection->InsertOrLookupMapValue(message, F("map_sfixed64_sfixed64"),
691  map_key, &map_val);
692  map_val.SetInt64Value(1);
693 
694  map_key.SetInt32Value(1);
695  reflection->InsertOrLookupMapValue(message, F("map_int32_float"), map_key,
696  &map_val);
697  map_val.SetFloatValue(1.0);
698 
699  map_key.SetInt32Value(1);
700  reflection->InsertOrLookupMapValue(message, F("map_int32_double"), map_key,
701  &map_val);
702  map_val.SetDoubleValue(1.0);
703 
704  map_key.SetBoolValue(true);
705  reflection->InsertOrLookupMapValue(message, F("map_bool_bool"), map_key,
706  &map_val);
707  map_val.SetBoolValue(true);
708 
709  map_key.SetStringValue("1");
710  reflection->InsertOrLookupMapValue(message, F("map_string_string"), map_key,
711  &map_val);
712  map_val.SetStringValue("1");
713 
714  map_key.SetInt32Value(1);
715  reflection->InsertOrLookupMapValue(message, F("map_int32_bytes"), map_key,
716  &map_val);
717  map_val.SetStringValue("1");
718 
719  map_key.SetInt32Value(1);
720  reflection->InsertOrLookupMapValue(message, F("map_int32_enum"), map_key,
721  &map_val);
722  map_val.SetEnumValue(map_enum_baz_->number());
723 
724  map_key.SetInt32Value(1);
726  message, F("map_int32_foreign_message"), map_key, &map_val));
727  sub_foreign_message = map_val.MutableMessageValue();
728  sub_foreign_message->GetReflection()->SetInt32(sub_foreign_message,
729  foreign_c_, 1);
730 }
731 
733  Message* message, const std::string& field_name, const MapKey& map_key,
734  MapValueRef* map_val) {
735  const Reflection* reflection = message->GetReflection();
736  EXPECT_FALSE(reflection->InsertOrLookupMapValue(message, F(field_name),
737  map_key, map_val));
738 }
739 
741  Message* message, const std::string& field_name, int index) {
742  const Reflection* reflection = message->GetReflection();
743  return reflection->MutableRepeatedMessage(message, F(field_name), index);
744 }
745 
747  const std::string& field_name) {
748  const Reflection* reflection = message->GetReflection();
749  return reflection->MapBegin(message, F(field_name));
750 }
751 
753  const std::string& field_name) {
754  const Reflection* reflection = message->GetReflection();
755  return reflection->MapEnd(message, F(field_name));
756 }
757 
759  const Reflection* reflection = message->GetReflection();
760 
761  reflection->ClearField(message, F("map_int32_int32"));
762  reflection->ClearField(message, F("map_int64_int64"));
763  reflection->ClearField(message, F("map_uint32_uint32"));
764  reflection->ClearField(message, F("map_uint64_uint64"));
765  reflection->ClearField(message, F("map_sint32_sint32"));
766  reflection->ClearField(message, F("map_sint64_sint64"));
767  reflection->ClearField(message, F("map_fixed32_fixed32"));
768  reflection->ClearField(message, F("map_fixed64_fixed64"));
769  reflection->ClearField(message, F("map_sfixed32_sfixed32"));
770  reflection->ClearField(message, F("map_sfixed64_sfixed64"));
771  reflection->ClearField(message, F("map_int32_float"));
772  reflection->ClearField(message, F("map_int32_double"));
773  reflection->ClearField(message, F("map_bool_bool"));
774  reflection->ClearField(message, F("map_string_string"));
775  reflection->ClearField(message, F("map_int32_bytes"));
776  reflection->ClearField(message, F("map_int32_enum"));
777  reflection->ClearField(message, F("map_int32_foreign_message"));
778 }
779 
781  const Reflection* reflection = message->GetReflection();
782  MapValueRef map_val;
783  Message* sub_foreign_message;
784 
785  // Modify the second element
786  MapKey map_key;
787  map_key.SetInt32Value(1);
788  EXPECT_FALSE(reflection->InsertOrLookupMapValue(message, F("map_int32_int32"),
789  map_key, &map_val));
790  map_val.SetInt32Value(2);
791 
792  map_key.SetInt64Value(1);
793  EXPECT_FALSE(reflection->InsertOrLookupMapValue(message, F("map_int64_int64"),
794  map_key, &map_val));
795  map_val.SetInt64Value(2);
796 
797  map_key.SetUInt32Value(1);
799  message, F("map_uint32_uint32"), map_key, &map_val));
800  map_val.SetUInt32Value(2);
801 
802  map_key.SetUInt64Value(1);
803  reflection->InsertOrLookupMapValue(message, F("map_uint64_uint64"), map_key,
804  &map_val);
805  map_val.SetUInt64Value(2);
806 
807  map_key.SetInt32Value(1);
808  reflection->InsertOrLookupMapValue(message, F("map_sint32_sint32"), map_key,
809  &map_val);
810  map_val.SetInt32Value(2);
811 
812  map_key.SetInt64Value(1);
813  reflection->InsertOrLookupMapValue(message, F("map_sint64_sint64"), map_key,
814  &map_val);
815  map_val.SetInt64Value(2);
816 
817  map_key.SetUInt32Value(1);
818  reflection->InsertOrLookupMapValue(message, F("map_fixed32_fixed32"), map_key,
819  &map_val);
820  map_val.SetUInt32Value(2);
821 
822  map_key.SetUInt64Value(1);
823  reflection->InsertOrLookupMapValue(message, F("map_fixed64_fixed64"), map_key,
824  &map_val);
825  map_val.SetUInt64Value(2);
826 
827  map_key.SetInt32Value(1);
828  reflection->InsertOrLookupMapValue(message, F("map_sfixed32_sfixed32"),
829  map_key, &map_val);
830  map_val.SetInt32Value(2);
831 
832  map_key.SetInt64Value(1);
833  reflection->InsertOrLookupMapValue(message, F("map_sfixed64_sfixed64"),
834  map_key, &map_val);
835  map_val.SetInt64Value(2);
836 
837  map_key.SetInt32Value(1);
838  reflection->InsertOrLookupMapValue(message, F("map_int32_float"), map_key,
839  &map_val);
840  map_val.SetFloatValue(2.0);
841 
842  map_key.SetInt32Value(1);
843  reflection->InsertOrLookupMapValue(message, F("map_int32_double"), map_key,
844  &map_val);
845  map_val.SetDoubleValue(2.0);
846 
847  map_key.SetBoolValue(true);
848  reflection->InsertOrLookupMapValue(message, F("map_bool_bool"), map_key,
849  &map_val);
850  map_val.SetBoolValue(false);
851 
852  map_key.SetStringValue("1");
853  reflection->InsertOrLookupMapValue(message, F("map_string_string"), map_key,
854  &map_val);
855  map_val.SetStringValue("2");
856 
857  map_key.SetInt32Value(1);
858  reflection->InsertOrLookupMapValue(message, F("map_int32_bytes"), map_key,
859  &map_val);
860  map_val.SetStringValue("2");
861 
862  map_key.SetInt32Value(1);
863  reflection->InsertOrLookupMapValue(message, F("map_int32_enum"), map_key,
864  &map_val);
865  map_val.SetEnumValue(map_enum_foo_->number());
866 
867  map_key.SetInt32Value(1);
869  message, F("map_int32_foreign_message"), map_key, &map_val));
870  sub_foreign_message = map_val.MutableMessageValue();
871  sub_foreign_message->GetReflection()->SetInt32(sub_foreign_message,
872  foreign_c_, 2);
873 }
874 
876  const Reflection* reflection = message->GetReflection();
877 
878  std::vector<const FieldDescriptor*> output;
879  reflection->ListFields(*message, &output);
880  for (int i = 0; i < output.size(); ++i) {
881  const FieldDescriptor* field = output[i];
882  if (!field->is_repeated()) continue;
883  reflection->RemoveLast(message, field);
884  }
885 }
886 
888  const Reflection* reflection = message->GetReflection();
889 
890  std::vector<const FieldDescriptor*> output;
891  reflection->ListFields(*message, &output);
892  for (int i = 0; i < output.size(); ++i) {
893  const FieldDescriptor* field = output[i];
894  if (!field->is_repeated()) continue;
895  if (field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) continue;
896 
897  Message* released = reflection->ReleaseLast(message, field);
898  ASSERT_TRUE(released != NULL)
899  << "ReleaseLast returned NULL for: " << field->name();
900  delete released;
901  }
902 }
903 
905  const Reflection* reflection = message->GetReflection();
906  std::vector<const FieldDescriptor*> output;
907  reflection->ListFields(*message, &output);
908  for (int i = 0; i < output.size(); ++i) {
909  const FieldDescriptor* field = output[i];
910  if (!field->is_repeated()) continue;
911  reflection->SwapElements(message, field, 0, 1);
912  }
913 }
914 
916  Message* message) {
917  const Reflection* reflection = message->GetReflection();
918  Message* sub_message = NULL;
919 
920  sub_message = reflection->AddMessage(message, F("map_int32_int32"));
921  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
922  NULL);
923  sub_message = reflection->AddMessage(message, F("map_int64_int64"));
924  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
925  NULL);
926  sub_message = reflection->AddMessage(message, F("map_uint32_uint32"));
927  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
928  NULL);
929  sub_message = reflection->AddMessage(message, F("map_uint64_uint64"));
930  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
931  NULL);
932  sub_message = reflection->AddMessage(message, F("map_sint32_sint32"));
933  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
934  NULL);
935  sub_message = reflection->AddMessage(message, F("map_sint64_sint64"));
936  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
937  NULL);
938  sub_message = reflection->AddMessage(message, F("map_fixed32_fixed32"));
939  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
940  NULL);
941  sub_message = reflection->AddMessage(message, F("map_fixed64_fixed64"));
942  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
943  NULL);
944  sub_message = reflection->AddMessage(message, F("map_sfixed32_sfixed32"));
945  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
946  NULL);
947  sub_message = reflection->AddMessage(message, F("map_sfixed64_sfixed64"));
948  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
949  NULL);
950  sub_message = reflection->AddMessage(message, F("map_int32_float"));
951  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
952  NULL);
953  sub_message = reflection->AddMessage(message, F("map_int32_double"));
954  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
955  NULL);
956  sub_message = reflection->AddMessage(message, F("map_bool_bool"));
957  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
958  NULL);
959  sub_message = reflection->AddMessage(message, F("map_string_string"));
960  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
961  NULL);
962  sub_message = reflection->AddMessage(message, F("map_int32_bytes"));
963  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
964  NULL);
965  sub_message = reflection->AddMessage(message, F("map_int32_enum"));
966  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
967  NULL);
968  sub_message = reflection->AddMessage(message, F("map_int32_foreign_message"));
969  EXPECT_TRUE(sub_message->GetReflection()->MutableUnknownFields(sub_message) !=
970  NULL);
971 }
972 
974  const Message& message) {
975  std::string scratch;
976  const Reflection* reflection = message.GetReflection();
977  const Message* sub_message;
978  MapKey map_key;
979 
980  // -----------------------------------------------------------------
981 
982  ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_int32")));
983  ASSERT_EQ(2, reflection->FieldSize(message, F("map_int64_int64")));
984  ASSERT_EQ(2, reflection->FieldSize(message, F("map_uint32_uint32")));
985  ASSERT_EQ(2, reflection->FieldSize(message, F("map_uint64_uint64")));
986  ASSERT_EQ(2, reflection->FieldSize(message, F("map_sint32_sint32")));
987  ASSERT_EQ(2, reflection->FieldSize(message, F("map_sint64_sint64")));
988  ASSERT_EQ(2, reflection->FieldSize(message, F("map_fixed32_fixed32")));
989  ASSERT_EQ(2, reflection->FieldSize(message, F("map_fixed64_fixed64")));
990  ASSERT_EQ(2, reflection->FieldSize(message, F("map_sfixed32_sfixed32")));
991  ASSERT_EQ(2, reflection->FieldSize(message, F("map_sfixed64_sfixed64")));
992  ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_float")));
993  ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_double")));
994  ASSERT_EQ(2, reflection->FieldSize(message, F("map_bool_bool")));
995  ASSERT_EQ(2, reflection->FieldSize(message, F("map_string_string")));
996  ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_bytes")));
997  ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_enum")));
998  ASSERT_EQ(2, reflection->FieldSize(message, F("map_int32_foreign_message")));
999 
1000  {
1001  std::map<int32, int32> map;
1002  map[0] = 0;
1003  map[1] = 1;
1004  for (int i = 0; i < 2; i++) {
1005  // Check with RepeatedField Reflection
1006  sub_message =
1007  &reflection->GetRepeatedMessage(message, F("map_int32_int32"), i);
1008  int32 key = sub_message->GetReflection()->GetInt32(*sub_message,
1010  int32 val = sub_message->GetReflection()->GetInt32(*sub_message,
1012  EXPECT_EQ(map[key], val);
1013  // Check with Map Reflection
1014  map_key.SetInt32Value(key);
1015  EXPECT_TRUE(
1016  reflection->ContainsMapKey(message, F("map_int32_int32"), map_key));
1017  }
1018  }
1019  {
1020  std::map<int64, int64> map;
1021  map[0] = 0;
1022  map[1] = 1;
1023  for (int i = 0; i < 2; i++) {
1024  // Check with RepeatedField Reflection
1025  sub_message =
1026  &reflection->GetRepeatedMessage(message, F("map_int64_int64"), i);
1027  int64 key = sub_message->GetReflection()->GetInt64(*sub_message,
1029  int64 val = sub_message->GetReflection()->GetInt64(*sub_message,
1031  EXPECT_EQ(map[key], val);
1032  // Check with Map Reflection
1033  map_key.SetInt64Value(key);
1034  EXPECT_TRUE(
1035  reflection->ContainsMapKey(message, F("map_int64_int64"), map_key));
1036  }
1037  }
1038  {
1039  std::map<uint32, uint32> map;
1040  map[0] = 0;
1041  map[1] = 1;
1042  for (int i = 0; i < 2; i++) {
1043  // Check with RepeatedField Reflection
1044  sub_message =
1045  &reflection->GetRepeatedMessage(message, F("map_uint32_uint32"), i);
1046  uint32 key = sub_message->GetReflection()->GetUInt32(
1047  *sub_message, map_uint32_uint32_key_);
1048  uint32 val = sub_message->GetReflection()->GetUInt32(
1049  *sub_message, map_uint32_uint32_val_);
1050  EXPECT_EQ(map[key], val);
1051  // Check with Map Reflection
1052  map_key.SetUInt32Value(key);
1053  EXPECT_TRUE(
1054  reflection->ContainsMapKey(message, F("map_uint32_uint32"), map_key));
1055  }
1056  }
1057  {
1058  std::map<uint64, uint64> map;
1059  map[0] = 0;
1060  map[1] = 1;
1061  for (int i = 0; i < 2; i++) {
1062  sub_message =
1063  &reflection->GetRepeatedMessage(message, F("map_uint64_uint64"), i);
1064  uint64 key = sub_message->GetReflection()->GetUInt64(
1065  *sub_message, map_uint64_uint64_key_);
1066  uint64 val = sub_message->GetReflection()->GetUInt64(
1067  *sub_message, map_uint64_uint64_val_);
1068  EXPECT_EQ(map[key], val);
1069  // Check with Map Reflection
1070  map_key.SetUInt64Value(key);
1071  EXPECT_TRUE(
1072  reflection->ContainsMapKey(message, F("map_uint64_uint64"), map_key));
1073  }
1074  }
1075  {
1076  std::map<int32, int32> map;
1077  map[0] = 0;
1078  map[1] = 1;
1079  for (int i = 0; i < 2; i++) {
1080  sub_message =
1081  &reflection->GetRepeatedMessage(message, F("map_sint32_sint32"), i);
1082  int32 key = sub_message->GetReflection()->GetInt32(
1083  *sub_message, map_sint32_sint32_key_);
1084  int32 val = sub_message->GetReflection()->GetInt32(
1085  *sub_message, map_sint32_sint32_val_);
1086  EXPECT_EQ(map[key], val);
1087  // Check with Map Reflection
1088  map_key.SetInt32Value(key);
1089  EXPECT_EQ(true, reflection->ContainsMapKey(
1090  message, F("map_sint32_sint32"), map_key));
1091  }
1092  }
1093  {
1094  std::map<int64, int64> map;
1095  map[0] = 0;
1096  map[1] = 1;
1097  for (int i = 0; i < 2; i++) {
1098  sub_message =
1099  &reflection->GetRepeatedMessage(message, F("map_sint64_sint64"), i);
1100  int64 key = sub_message->GetReflection()->GetInt64(
1101  *sub_message, map_sint64_sint64_key_);
1102  int64 val = sub_message->GetReflection()->GetInt64(
1103  *sub_message, map_sint64_sint64_val_);
1104  EXPECT_EQ(map[key], val);
1105  // Check with Map Reflection
1106  map_key.SetInt64Value(key);
1107  EXPECT_EQ(true, reflection->ContainsMapKey(
1108  message, F("map_sint64_sint64"), map_key));
1109  }
1110  }
1111  {
1112  std::map<uint32, uint32> map;
1113  map[0] = 0;
1114  map[1] = 1;
1115  for (int i = 0; i < 2; i++) {
1116  sub_message =
1117  &reflection->GetRepeatedMessage(message, F("map_fixed32_fixed32"), i);
1118  uint32 key = sub_message->GetReflection()->GetUInt32(
1119  *sub_message, map_fixed32_fixed32_key_);
1120  uint32 val = sub_message->GetReflection()->GetUInt32(
1121  *sub_message, map_fixed32_fixed32_val_);
1122  EXPECT_EQ(map[key], val);
1123  // Check with Map Reflection
1124  map_key.SetUInt32Value(key);
1125  EXPECT_EQ(true, reflection->ContainsMapKey(
1126  message, F("map_fixed32_fixed32"), map_key));
1127  }
1128  }
1129  {
1130  std::map<uint64, uint64> map;
1131  map[0] = 0;
1132  map[1] = 1;
1133  for (int i = 0; i < 2; i++) {
1134  sub_message =
1135  &reflection->GetRepeatedMessage(message, F("map_fixed64_fixed64"), i);
1136  uint64 key = sub_message->GetReflection()->GetUInt64(
1137  *sub_message, map_fixed64_fixed64_key_);
1138  uint64 val = sub_message->GetReflection()->GetUInt64(
1139  *sub_message, map_fixed64_fixed64_val_);
1140  EXPECT_EQ(map[key], val);
1141  // Check with Map Reflection
1142  map_key.SetUInt64Value(key);
1143  EXPECT_EQ(true, reflection->ContainsMapKey(
1144  message, F("map_fixed64_fixed64"), map_key));
1145  }
1146  }
1147  {
1148  std::map<int32, int32> map;
1149  map[0] = 0;
1150  map[1] = 1;
1151  for (int i = 0; i < 2; i++) {
1152  sub_message = &reflection->GetRepeatedMessage(
1153  message, F("map_sfixed32_sfixed32"), i);
1154  int32 key = sub_message->GetReflection()->GetInt32(
1155  *sub_message, map_sfixed32_sfixed32_key_);
1156  int32 val = sub_message->GetReflection()->GetInt32(
1157  *sub_message, map_sfixed32_sfixed32_val_);
1158  EXPECT_EQ(map[key], val);
1159  // Check with Map Reflection
1160  map_key.SetInt32Value(key);
1161  EXPECT_EQ(true, reflection->ContainsMapKey(
1162  message, F("map_sfixed32_sfixed32"), map_key));
1163  }
1164  }
1165  {
1166  std::map<int64, int64> map;
1167  map[0] = 0;
1168  map[1] = 1;
1169  for (int i = 0; i < 2; i++) {
1170  sub_message = &reflection->GetRepeatedMessage(
1171  message, F("map_sfixed64_sfixed64"), i);
1172  int64 key = sub_message->GetReflection()->GetInt64(
1173  *sub_message, map_sfixed64_sfixed64_key_);
1174  int64 val = sub_message->GetReflection()->GetInt64(
1175  *sub_message, map_sfixed64_sfixed64_val_);
1176  EXPECT_EQ(map[key], val);
1177  // Check with Map Reflection
1178  map_key.SetInt64Value(key);
1179  EXPECT_EQ(true, reflection->ContainsMapKey(
1180  message, F("map_sfixed64_sfixed64"), map_key));
1181  }
1182  }
1183  {
1184  std::map<int32, float> map;
1185  map[0] = 0.0;
1186  map[1] = 1.0;
1187  for (int i = 0; i < 2; i++) {
1188  sub_message =
1189  &reflection->GetRepeatedMessage(message, F("map_int32_float"), i);
1190  int32 key = sub_message->GetReflection()->GetInt32(*sub_message,
1192  float val = sub_message->GetReflection()->GetFloat(*sub_message,
1194  EXPECT_EQ(map[key], val);
1195  // Check with Map Reflection
1196  map_key.SetInt32Value(key);
1197  EXPECT_EQ(true, reflection->ContainsMapKey(message, F("map_int32_float"),
1198  map_key));
1199  }
1200  }
1201  {
1202  std::map<int32, double> map;
1203  map[0] = 0.0;
1204  map[1] = 1.0;
1205  for (int i = 0; i < 2; i++) {
1206  sub_message =
1207  &reflection->GetRepeatedMessage(message, F("map_int32_double"), i);
1208  int32 key = sub_message->GetReflection()->GetInt32(*sub_message,
1210  double val = sub_message->GetReflection()->GetDouble(
1211  *sub_message, map_int32_double_val_);
1212  EXPECT_EQ(map[key], val);
1213  // Check with Map Reflection
1214  map_key.SetInt32Value(key);
1215  EXPECT_EQ(true, reflection->ContainsMapKey(message, F("map_int32_double"),
1216  map_key));
1217  }
1218  }
1219  {
1220  std::map<bool, bool> map;
1221  map[false] = false;
1222  map[true] = true;
1223  for (int i = 0; i < 2; i++) {
1224  sub_message =
1225  &reflection->GetRepeatedMessage(message, F("map_bool_bool"), i);
1226  bool key = sub_message->GetReflection()->GetBool(*sub_message,
1228  bool val = sub_message->GetReflection()->GetBool(*sub_message,
1230  EXPECT_EQ(map[key], val);
1231  // Check with Map Reflection
1232  map_key.SetBoolValue(key);
1233  EXPECT_EQ(true, reflection->ContainsMapKey(message, F("map_bool_bool"),
1234  map_key));
1235  }
1236  }
1237  {
1238  std::map<std::string, std::string> map;
1239  map["0"] = "0";
1240  map["1"] = "1";
1241  for (int i = 0; i < 2; i++) {
1242  sub_message =
1243  &reflection->GetRepeatedMessage(message, F("map_string_string"), i);
1244  std::string key = sub_message->GetReflection()->GetString(
1245  *sub_message, map_string_string_key_);
1246  std::string val = sub_message->GetReflection()->GetString(
1247  *sub_message, map_string_string_val_);
1248  EXPECT_EQ(map[key], val);
1249  // Check with Map Reflection
1250  map_key.SetStringValue(key);
1251  EXPECT_EQ(true, reflection->ContainsMapKey(
1252  message, F("map_string_string"), map_key));
1253  }
1254  }
1255  {
1256  std::map<int32, std::string> map;
1257  map[0] = "0";
1258  map[1] = "1";
1259  for (int i = 0; i < 2; i++) {
1260  sub_message =
1261  &reflection->GetRepeatedMessage(message, F("map_int32_bytes"), i);
1262  int32 key = sub_message->GetReflection()->GetInt32(*sub_message,
1264  std::string val = sub_message->GetReflection()->GetString(
1265  *sub_message, map_int32_bytes_val_);
1266  EXPECT_EQ(map[key], val);
1267  // Check with Map Reflection
1268  map_key.SetInt32Value(key);
1269  EXPECT_EQ(true, reflection->ContainsMapKey(message, F("map_int32_bytes"),
1270  map_key));
1271  }
1272  }
1273  {
1274  std::map<int32, const EnumValueDescriptor*> map;
1275  map[0] = map_enum_bar_;
1276  map[1] = map_enum_baz_;
1277  for (int i = 0; i < 2; i++) {
1278  sub_message =
1279  &reflection->GetRepeatedMessage(message, F("map_int32_enum"), i);
1280  int32 key = sub_message->GetReflection()->GetInt32(*sub_message,
1282  const EnumValueDescriptor* val = sub_message->GetReflection()->GetEnum(
1283  *sub_message, map_int32_enum_val_);
1284  EXPECT_EQ(map[key], val);
1285  // Check with Map Reflection
1286  map_key.SetInt32Value(key);
1287  EXPECT_EQ(true, reflection->ContainsMapKey(message, F("map_int32_enum"),
1288  map_key));
1289  }
1290  }
1291  {
1292  std::map<int32, int32> map;
1293  map[0] = 0;
1294  map[1] = 1;
1295  for (int i = 0; i < 2; i++) {
1296  sub_message = &reflection->GetRepeatedMessage(
1297  message, F("map_int32_foreign_message"), i);
1298  int32 key = sub_message->GetReflection()->GetInt32(
1299  *sub_message, map_int32_foreign_message_key_);
1300  const Message& foreign_message = sub_message->GetReflection()->GetMessage(
1301  *sub_message, map_int32_foreign_message_val_);
1302  int32 val = foreign_message.GetReflection()->GetInt32(foreign_message,
1303  foreign_c_);
1304  EXPECT_EQ(map[key], val);
1305  // Check with Map Reflection
1306  map_key.SetInt32Value(key);
1307  EXPECT_EQ(true, reflection->ContainsMapKey(
1308  message, F("map_int32_foreign_message"), map_key));
1309  }
1310  }
1311 }
1312 
1314  Message* message) {
1315  std::string scratch;
1316  std::string serialized;
1317  const Reflection* reflection = message->GetReflection();
1318 
1319  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_int32")));
1320  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int64_int64")));
1321  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_uint32_uint32")));
1322  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_uint64_uint64")));
1323  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_sint32_sint32")));
1324  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_sint64_sint64")));
1325  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_fixed32_fixed32")));
1326  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_fixed64_fixed64")));
1327  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_sfixed32_sfixed32")));
1328  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_sfixed64_sfixed64")));
1329  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_float")));
1330  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_double")));
1331  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_bool_bool")));
1332  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_string_string")));
1333  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_bytes")));
1334  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_enum")));
1335  ASSERT_EQ(2, reflection->FieldSize(*message, F("map_int32_foreign_message")));
1336 
1337  {
1338  std::map<int32, int32> map;
1339  map[0] = 0;
1340  map[1] = 1;
1341  int size = 0;
1342  for (MapIterator iter = reflection->MapBegin(message, F("map_int32_int32"));
1343  iter != reflection->MapEnd(message, F("map_int32_int32"));
1344  ++iter, ++size) {
1345  // Check const methods do not invalidate map.
1346  message->DebugString();
1347  message->ShortDebugString();
1348  message->SerializeToString(&serialized);
1349  message->SpaceUsed();
1350  message->ByteSize();
1351  EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
1352  iter.GetValueRef().GetInt32Value());
1353  }
1354  EXPECT_EQ(size, 2);
1355  }
1356  {
1357  std::map<int64, int64> map;
1358  map[0] = 0;
1359  map[1] = 1;
1360  for (MapIterator iter = reflection->MapBegin(message, F("map_int64_int64"));
1361  iter != reflection->MapEnd(message, F("map_int64_int64")); ++iter) {
1362  EXPECT_EQ(map[iter.GetKey().GetInt64Value()],
1363  iter.GetValueRef().GetInt64Value());
1364  }
1365  }
1366  {
1367  std::map<uint32, uint32> map;
1368  map[0] = 0;
1369  map[1] = 1;
1370  for (MapIterator iter =
1371  reflection->MapBegin(message, F("map_uint32_uint32"));
1372  iter != reflection->MapEnd(message, F("map_uint32_uint32")); ++iter) {
1373  EXPECT_EQ(map[iter.GetKey().GetUInt32Value()],
1374  iter.GetValueRef().GetUInt32Value());
1375  }
1376  }
1377  {
1378  std::map<uint64, uint64> map;
1379  map[0] = 0;
1380  map[1] = 1;
1381  for (MapIterator iter =
1382  reflection->MapBegin(message, F("map_uint64_uint64"));
1383  iter != reflection->MapEnd(message, F("map_uint64_uint64")); ++iter) {
1384  EXPECT_EQ(map[iter.GetKey().GetUInt64Value()],
1385  iter.GetValueRef().GetUInt64Value());
1386  }
1387  }
1388  {
1389  std::map<int32, int32> map;
1390  map[0] = 0;
1391  map[1] = 1;
1392  for (MapIterator iter =
1393  reflection->MapBegin(message, F("map_sint32_sint32"));
1394  iter != reflection->MapEnd(message, F("map_sint32_sint32")); ++iter) {
1395  EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
1396  iter.GetValueRef().GetInt32Value());
1397  }
1398  }
1399  {
1400  std::map<int64, int64> map;
1401  map[0] = 0;
1402  map[1] = 1;
1403  for (MapIterator iter =
1404  reflection->MapBegin(message, F("map_sint64_sint64"));
1405  iter != reflection->MapEnd(message, F("map_sint64_sint64")); ++iter) {
1406  EXPECT_EQ(map[iter.GetKey().GetInt64Value()],
1407  iter.GetValueRef().GetInt64Value());
1408  }
1409  }
1410  {
1411  std::map<uint32, uint32> map;
1412  map[0] = 0;
1413  map[1] = 1;
1414  for (MapIterator iter =
1415  reflection->MapBegin(message, F("map_fixed32_fixed32"));
1416  iter != reflection->MapEnd(message, F("map_fixed32_fixed32"));
1417  ++iter) {
1418  EXPECT_EQ(map[iter.GetKey().GetUInt32Value()],
1419  iter.GetValueRef().GetUInt32Value());
1420  }
1421  }
1422  {
1423  std::map<uint64, uint64> map;
1424  map[0] = 0;
1425  map[1] = 1;
1426  for (MapIterator iter =
1427  reflection->MapBegin(message, F("map_fixed64_fixed64"));
1428  iter != reflection->MapEnd(message, F("map_fixed64_fixed64"));
1429  ++iter) {
1430  EXPECT_EQ(map[iter.GetKey().GetUInt64Value()],
1431  iter.GetValueRef().GetUInt64Value());
1432  }
1433  }
1434  {
1435  std::map<int32, int32> map;
1436  map[0] = 0;
1437  map[1] = 1;
1438  for (MapIterator iter =
1439  reflection->MapBegin(message, F("map_sfixed32_sfixed32"));
1440  iter != reflection->MapEnd(message, F("map_sfixed32_sfixed32"));
1441  ++iter) {
1442  EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
1443  iter.GetValueRef().GetInt32Value());
1444  }
1445  }
1446  {
1447  std::map<int32, float> map;
1448  map[0] = 0.0;
1449  map[1] = 1.0;
1450  for (MapIterator iter = reflection->MapBegin(message, F("map_int32_float"));
1451  iter != reflection->MapEnd(message, F("map_int32_float")); ++iter) {
1452  EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
1453  iter.GetValueRef().GetFloatValue());
1454  }
1455  }
1456  {
1457  std::map<int32, double> map;
1458  map[0] = 0.0;
1459  map[1] = 1.0;
1460  for (MapIterator iter =
1461  reflection->MapBegin(message, F("map_int32_double"));
1462  iter != reflection->MapEnd(message, F("map_int32_double")); ++iter) {
1463  EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
1464  iter.GetValueRef().GetDoubleValue());
1465  }
1466  }
1467  {
1468  std::map<bool, bool> map;
1469  map[false] = false;
1470  map[true] = true;
1471  for (MapIterator iter = reflection->MapBegin(message, F("map_bool_bool"));
1472  iter != reflection->MapEnd(message, F("map_bool_bool")); ++iter) {
1473  EXPECT_EQ(map[iter.GetKey().GetBoolValue()],
1474  iter.GetValueRef().GetBoolValue());
1475  }
1476  }
1477  {
1478  std::map<std::string, std::string> map;
1479  map["0"] = "0";
1480  map["1"] = "1";
1481  int size = 0;
1482  for (MapIterator iter =
1483  reflection->MapBegin(message, F("map_string_string"));
1484  iter != reflection->MapEnd(message, F("map_string_string"));
1485  ++iter, ++size) {
1486  // Check const methods do not invalidate map.
1487  message->DebugString();
1488  message->ShortDebugString();
1489  message->SerializeToString(&serialized);
1490  message->SpaceUsed();
1491  message->ByteSize();
1492  EXPECT_EQ(map[iter.GetKey().GetStringValue()],
1493  iter.GetValueRef().GetStringValue());
1494  }
1495  EXPECT_EQ(size, 2);
1496  }
1497  {
1498  std::map<int32, std::string> map;
1499  map[0] = "0";
1500  map[1] = "1";
1501  for (MapIterator iter = reflection->MapBegin(message, F("map_int32_bytes"));
1502  iter != reflection->MapEnd(message, F("map_int32_bytes")); ++iter) {
1503  EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
1504  iter.GetValueRef().GetStringValue());
1505  }
1506  }
1507  {
1508  std::map<int32, const EnumValueDescriptor*> map;
1509  map[0] = map_enum_bar_;
1510  map[1] = map_enum_baz_;
1511  for (MapIterator iter = reflection->MapBegin(message, F("map_int32_enum"));
1512  iter != reflection->MapEnd(message, F("map_int32_enum")); ++iter) {
1513  EXPECT_EQ(map[iter.GetKey().GetInt32Value()]->number(),
1514  iter.GetValueRef().GetEnumValue());
1515  }
1516  }
1517  {
1518  std::map<int32, int32> map;
1519  map[0] = 0;
1520  map[1] = 1;
1521  int size = 0;
1522  for (MapIterator iter =
1523  reflection->MapBegin(message, F("map_int32_foreign_message"));
1524  iter != reflection->MapEnd(message, F("map_int32_foreign_message"));
1525  ++iter, ++size) {
1526  // Check const methods do not invalidate map.
1527  message->DebugString();
1528  message->ShortDebugString();
1529  message->SerializeToString(&serialized);
1530  message->SpaceUsed();
1531  message->ByteSize();
1532  const Message& sub_message = iter.GetValueRef().GetMessageValue();
1533  EXPECT_EQ(map[iter.GetKey().GetInt32Value()],
1534  sub_message.GetReflection()->GetInt32(sub_message, foreign_c_));
1535  }
1536  EXPECT_EQ(size, 2);
1537  }
1538 }
1539 
1541  const Reflection* reflection = message.GetReflection();
1542  // Map fields are empty.
1543  EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_int32")));
1544  EXPECT_EQ(0, reflection->FieldSize(message, F("map_int64_int64")));
1545  EXPECT_EQ(0, reflection->FieldSize(message, F("map_uint32_uint32")));
1546  EXPECT_EQ(0, reflection->FieldSize(message, F("map_uint64_uint64")));
1547  EXPECT_EQ(0, reflection->FieldSize(message, F("map_sint32_sint32")));
1548  EXPECT_EQ(0, reflection->FieldSize(message, F("map_sint64_sint64")));
1549  EXPECT_EQ(0, reflection->FieldSize(message, F("map_fixed32_fixed32")));
1550  EXPECT_EQ(0, reflection->FieldSize(message, F("map_fixed64_fixed64")));
1551  EXPECT_EQ(0, reflection->FieldSize(message, F("map_sfixed32_sfixed32")));
1552  EXPECT_EQ(0, reflection->FieldSize(message, F("map_sfixed64_sfixed64")));
1553  EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_float")));
1554  EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_double")));
1555  EXPECT_EQ(0, reflection->FieldSize(message, F("map_bool_bool")));
1556  EXPECT_EQ(0, reflection->FieldSize(message, F("map_string_string")));
1557  EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_bytes")));
1558  EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_enum")));
1559  EXPECT_EQ(0, reflection->FieldSize(message, F("map_int32_foreign_message")));
1560  EXPECT_TRUE(reflection->GetMapData(message, F("map_int32_foreign_message"))
1561  ->IsMapValid());
1562 }
1563 
1565  const Reflection* reflection = message->GetReflection();
1566  EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_int32")) ==
1567  reflection->MapEnd(message, F("map_int32_int32")));
1568  EXPECT_TRUE(reflection->MapBegin(message, F("map_int64_int64")) ==
1569  reflection->MapEnd(message, F("map_int64_int64")));
1570  EXPECT_TRUE(reflection->MapBegin(message, F("map_uint32_uint32")) ==
1571  reflection->MapEnd(message, F("map_uint32_uint32")));
1572  EXPECT_TRUE(reflection->MapBegin(message, F("map_uint64_uint64")) ==
1573  reflection->MapEnd(message, F("map_uint64_uint64")));
1574  EXPECT_TRUE(reflection->MapBegin(message, F("map_sint32_sint32")) ==
1575  reflection->MapEnd(message, F("map_sint32_sint32")));
1576  EXPECT_TRUE(reflection->MapBegin(message, F("map_sint64_sint64")) ==
1577  reflection->MapEnd(message, F("map_sint64_sint64")));
1578  EXPECT_TRUE(reflection->MapBegin(message, F("map_fixed32_fixed32")) ==
1579  reflection->MapEnd(message, F("map_fixed32_fixed32")));
1580  EXPECT_TRUE(reflection->MapBegin(message, F("map_fixed64_fixed64")) ==
1581  reflection->MapEnd(message, F("map_fixed64_fixed64")));
1582  EXPECT_TRUE(reflection->MapBegin(message, F("map_sfixed32_sfixed32")) ==
1583  reflection->MapEnd(message, F("map_sfixed32_sfixed32")));
1584  EXPECT_TRUE(reflection->MapBegin(message, F("map_sfixed64_sfixed64")) ==
1585  reflection->MapEnd(message, F("map_sfixed64_sfixed64")));
1586  EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_float")) ==
1587  reflection->MapEnd(message, F("map_int32_float")));
1588  EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_double")) ==
1589  reflection->MapEnd(message, F("map_int32_double")));
1590  EXPECT_TRUE(reflection->MapBegin(message, F("map_bool_bool")) ==
1591  reflection->MapEnd(message, F("map_bool_bool")));
1592  EXPECT_TRUE(reflection->MapBegin(message, F("map_string_string")) ==
1593  reflection->MapEnd(message, F("map_string_string")));
1594  EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_bytes")) ==
1595  reflection->MapEnd(message, F("map_int32_bytes")));
1596  EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_enum")) ==
1597  reflection->MapEnd(message, F("map_int32_enum")));
1598  EXPECT_TRUE(reflection->MapBegin(message, F("map_int32_foreign_message")) ==
1599  reflection->MapEnd(message, F("map_int32_foreign_message")));
1600 }
1601 
1602 } // namespace protobuf
1603 } // namespace google
google::protobuf::MapTestUtilImpl::ExpectMapFieldsModified
static void ExpectMapFieldsModified(const MapMessage &message)
Definition: map_test_util_impl.h:418
google::protobuf::MapReflectionTester::F
const FieldDescriptor * F(const std::string &name)
Definition: map_test_util.cc:341
google::protobuf::MapTestUtil::ExpectMapFieldsSet
static void ExpectMapFieldsSet(const unittest::TestMap &message)
Definition: map_test_util.cc:62
google::protobuf::Reflection::GetString
std::string GetString(const Message &message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:1151
google::protobuf::MapReflectionTester::map_bool_bool_val_
const FieldDescriptor * map_bool_bool_val_
Definition: map_test_util.h:150
google::protobuf::MapTestUtil::ModifyMapFields
static void ModifyMapFields(unittest::TestMap *message)
Definition: map_test_util.cc:53
name
GLuint const GLchar * name
Definition: glcorearb.h:3055
google::protobuf::MapValueRef::SetBoolValue
void SetBoolValue(bool value)
Definition: map_field.h:585
google::protobuf::FieldDescriptor
Definition: src/google/protobuf/descriptor.h:515
google::protobuf::MapTestUtil::SetArenaMapFields
static void SetArenaMapFields(unittest::TestArenaMap *message)
Definition: map_test_util.cc:44
google::protobuf::Reflection::SetBool
void SetBool(Message *message, const FieldDescriptor *field, bool value) const
google::protobuf::MapTestUtil::ExpectClear
static void ExpectClear(const unittest::TestMap &message)
Definition: map_test_util.cc:58
NULL
NULL
Definition: test_security_zap.cpp:405
google::protobuf::MapReflectionTester::map_int32_enum_val_
const FieldDescriptor * map_int32_enum_val_
Definition: map_test_util.h:156
google::protobuf::int64
int64_t int64
Definition: protobuf/src/google/protobuf/stubs/port.h:151
google::protobuf::MapTestUtilImpl::ExpectMapFieldsSetInitialized
static void ExpectMapFieldsSetInitialized(const MapMessage &message)
Definition: map_test_util_impl.h:378
google::protobuf::MapReflectionTester::map_int32_foreign_message_key_
const FieldDescriptor * map_int32_foreign_message_key_
Definition: map_test_util.h:157
google::protobuf::Reflection::GetFloat
float GetFloat(const Message &message, const FieldDescriptor *field) const
google::protobuf::Reflection::GetUInt32
uint32 GetUInt32(const Message &message, const FieldDescriptor *field) const
google::protobuf::MapTestUtilImpl::ExpectArenaMapFieldsSet
static void ExpectArenaMapFieldsSet(const MapMessage &message)
Definition: map_test_util_impl.h:318
google::protobuf::MapReflectionTester::map_sfixed64_sfixed64_val_
const FieldDescriptor * map_sfixed64_sfixed64_val_
Definition: map_test_util.h:144
google::protobuf::MapKey::SetUInt64Value
void SetUInt64Value(uint64 value)
Definition: map_field.h:399
google::protobuf::MapKey::SetStringValue
void SetStringValue(const std::string &val)
Definition: map_field.h:415
google::protobuf::Message::GetReflection
const Reflection * GetReflection() const
Definition: src/google/protobuf/message.h:335
google::protobuf::MapReflectionTester::map_sint32_sint32_val_
const FieldDescriptor * map_sint32_sint32_val_
Definition: map_test_util.h:134
google::protobuf::MapReflectionTester::map_fixed64_fixed64_val_
const FieldDescriptor * map_fixed64_fixed64_val_
Definition: map_test_util.h:140
EXPECT_EQ
#define EXPECT_EQ(val1, val2)
Definition: glog/src/googletest.h:155
google::protobuf::uint32
uint32_t uint32
Definition: protobuf/src/google/protobuf/stubs/port.h:155
google::protobuf::Reflection::SetDouble
void SetDouble(Message *message, const FieldDescriptor *field, double value) const
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
google::protobuf::Reflection::SetInt64
void SetInt64(Message *message, const FieldDescriptor *field, int64 value) const
google::protobuf::MapTestUtil::SetMapFieldsInitialized
static void SetMapFieldsInitialized(unittest::TestMap *message)
Definition: map_test_util.cc:49
google::protobuf::Reflection::SetString
void SetString(Message *message, const FieldDescriptor *field, const std::string &value) const
Definition: generated_message_reflection.cc:1193
google::protobuf::MapReflectionTester::GetMapEntryViaReflection
Message * GetMapEntryViaReflection(Message *message, const std::string &field_name, int index)
Definition: map_test_util.cc:740
google::protobuf::MapReflectionTester::map_string_string_val_
const FieldDescriptor * map_string_string_val_
Definition: map_test_util.h:152
google::protobuf::Reflection
Definition: src/google/protobuf/message.h:400
descriptor
Descriptor * descriptor
Definition: php/ext/google/protobuf/protobuf.h:936
google::protobuf::MapTestUtil::SetMapFields
static void SetMapFields(unittest::TestMap *message)
Definition: map_test_util.cc:39
google::protobuf::MapReflectionTester::SetMapFieldsViaReflection
void SetMapFieldsViaReflection(Message *message)
Definition: map_test_util.cc:348
map
zval * map
Definition: php/ext/google/protobuf/encode_decode.c:473
google::protobuf::Reflection::ContainsMapKey
bool ContainsMapKey(const Message &message, const FieldDescriptor *field, const MapKey &key) const
Definition: generated_message_reflection.cc:1761
google::protobuf::MapReflectionTester::map_fixed32_fixed32_val_
const FieldDescriptor * map_fixed32_fixed32_val_
Definition: map_test_util.h:138
google::protobuf::Reflection::GetBool
bool GetBool(const Message &message, const FieldDescriptor *field) const
google::protobuf::MapReflectionTester::map_sint64_sint64_val_
const FieldDescriptor * map_sint64_sint64_val_
Definition: map_test_util.h:136
google::protobuf::MapValueRef::SetUInt32Value
void SetUInt32Value(uint32 value)
Definition: map_field.h:581
google::protobuf::MapTestUtil::GetMapEntries
static std::vector< const Message * > GetMapEntries(const unittest::TestMap &message, int index)
Definition: map_test_util.cc:136
google::protobuf::MapReflectionTester::SwapMapsViaReflection
void SwapMapsViaReflection(Message *message)
Definition: map_test_util.cc:904
google::protobuf::MapReflectionTester::ExpectMapFieldsSetViaReflection
void ExpectMapFieldsSetViaReflection(const Message &message)
Definition: map_test_util.cc:973
google::protobuf::Reflection::SetUInt64
void SetUInt64(Message *message, const FieldDescriptor *field, uint64 value) const
ASSERT_EQ
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:2082
google::protobuf::MapReflectionTester::map_enum_baz_
const EnumValueDescriptor * map_enum_baz_
Definition: map_test_util.h:121
google::protobuf::MapReflectionTester::map_int32_bytes_val_
const FieldDescriptor * map_int32_bytes_val_
Definition: map_test_util.h:154
google::protobuf::MapReflectionTester::map_int32_enum_key_
const FieldDescriptor * map_int32_enum_key_
Definition: map_test_util.h:155
google::protobuf::MapReflectionTester::RemoveLastMapsViaReflection
void RemoveLastMapsViaReflection(Message *message)
Definition: map_test_util.cc:875
google::protobuf::MapReflectionTester::MutableUnknownFieldsOfMapFieldsViaReflection
void MutableUnknownFieldsOfMapFieldsViaReflection(Message *message)
Definition: map_test_util.cc:915
google::protobuf::int32
int32_t int32
Definition: protobuf/src/google/protobuf/stubs/port.h:150
google::protobuf::MapReflectionTester::map_sint64_sint64_key_
const FieldDescriptor * map_sint64_sint64_key_
Definition: map_test_util.h:135
google::protobuf::MapReflectionTester::map_int32_int32_key_
const FieldDescriptor * map_int32_int32_key_
Definition: map_test_util.h:125
google::protobuf::MapReflectionTester::ExpectMapFieldsSetViaReflectionIterator
void ExpectMapFieldsSetViaReflectionIterator(Message *message)
Definition: map_test_util.cc:1313
google::protobuf::MapTestUtil::ExpectMapFieldsModified
static void ExpectMapFieldsModified(const unittest::TestMap &message)
Definition: map_test_util.cc:81
google::protobuf::MapReflectionTester::ModifyMapFieldsViaReflection
void ModifyMapFieldsViaReflection(Message *message)
Definition: map_test_util.cc:780
google::protobuf::MapReflectionTester::map_int64_int64_val_
const FieldDescriptor * map_int64_int64_val_
Definition: map_test_util.h:128
google::protobuf::MapReflectionTester::MapBegin
MapIterator MapBegin(Message *message, const std::string &field_name)
Definition: map_test_util.cc:746
google::protobuf::Reflection::MutableUnknownFields
UnknownFieldSet * MutableUnknownFields(Message *message) const
Definition: generated_message_reflection.cc:237
google::protobuf::FileDescriptor::pool
const DescriptorPool * pool() const
google::protobuf::MapValueRef::SetFloatValue
void SetFloatValue(float value)
Definition: map_field.h:598
google::protobuf::MapTestUtilImpl::SetMapFields
static void SetMapFields(MapMessage *message)
Definition: map_test_util_impl.h:109
google::protobuf::MapReflectionTester::SetMapFieldsViaMapReflection
void SetMapFieldsViaMapReflection(Message *message)
Definition: map_test_util.cc:544
google::protobuf::EnumValueDescriptor::number
int number() const
google::protobuf::MapReflectionTester::map_string_string_key_
const FieldDescriptor * map_string_string_key_
Definition: map_test_util.h:151
google::protobuf::MapValueRef::SetEnumValue
void SetEnumValue(int value)
Definition: map_field.h:590
google::protobuf::MapReflectionTester::map_int32_foreign_message_val_
const FieldDescriptor * map_int32_foreign_message_val_
Definition: map_test_util.h:158
google::protobuf::DescriptorPool
Definition: src/google/protobuf/descriptor.h:1539
message.h
map_test_util_impl.h
google::protobuf::Reflection::SetInt32
void SetInt32(Message *message, const FieldDescriptor *field, int32 value) const
google::protobuf::MapReflectionTester::ReleaseLastMapsViaReflection
void ReleaseLastMapsViaReflection(Message *message)
Definition: map_test_util.cc:887
google::protobuf::Reflection::ClearField
void ClearField(Message *message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:789
google::protobuf::MapValueRef::SetUInt64Value
void SetUInt64Value(uint64 value)
Definition: map_field.h:573
google::protobuf::MapReflectionTester::foreign_c_
const FieldDescriptor * foreign_c_
Definition: map_test_util.h:124
google::protobuf::Reflection::GetEnum
const EnumValueDescriptor * GetEnum(const Message &message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:1294
google::protobuf::Reflection::MapBegin
MapIterator MapBegin(Message *message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:1787
google::protobuf::MapValueRef::SetInt32Value
void SetInt32Value(int32 value)
Definition: map_field.h:577
google::protobuf::uint64
uint64_t uint64
Definition: protobuf/src/google/protobuf/stubs/port.h:156
size
#define size
Definition: glcorearb.h:2944
google::protobuf::MapReflectionTester::map_sfixed64_sfixed64_key_
const FieldDescriptor * map_sfixed64_sfixed64_key_
Definition: map_test_util.h:143
google::protobuf::MapTestUtilImpl::SetMapFieldsInitialized
static void SetMapFieldsInitialized(MapMessage *message)
Definition: map_test_util_impl.h:194
google::protobuf::Reflection::InsertOrLookupMapValue
bool InsertOrLookupMapValue(Message *message, const FieldDescriptor *field, const MapKey &key, MapValueRef *val) const
Definition: generated_message_reflection.cc:1769
google::protobuf::Reflection::SwapElements
void SwapElements(Message *message, const FieldDescriptor *field, int index1, int index2) const
Definition: generated_message_reflection.cc:969
google::protobuf::Reflection::RemoveLast
void RemoveLast(Message *message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:902
EXPECT_TRUE
#define EXPECT_TRUE(cond)
Definition: glog/src/googletest.h:137
ASSERT_TRUE
#define ASSERT_TRUE(condition)
Definition: gtest.h:1995
google::protobuf::Reflection::SetEnum
void SetEnum(Message *message, const FieldDescriptor *field, const EnumValueDescriptor *value) const
Definition: generated_message_reflection.cc:1315
google::protobuf::MapTestUtil::ExpectArenaMapFieldsSet
static void ExpectArenaMapFieldsSet(const unittest::TestArenaMap &message)
Definition: map_test_util.cc:67
google::protobuf::MapKey::SetInt64Value
void SetInt64Value(int64 value)
Definition: map_field.h:395
map_test_util.h
google::protobuf::MapReflectionTester::map_sfixed32_sfixed32_key_
const FieldDescriptor * map_sfixed32_sfixed32_key_
Definition: map_test_util.h:141
field
const FieldDescriptor * field
Definition: parser_unittest.cc:2694
google::protobuf::Reflection::FieldSize
int FieldSize(const Message &message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:744
key
const SETUP_TEARDOWN_TESTCONTEXT char * key
Definition: test_wss_transport.cpp:10
google::protobuf::Reflection::GetInt32
int32 GetInt32(const Message &message, const FieldDescriptor *field) const
google::protobuf::Reflection::MutableMessage
Message * MutableMessage(Message *message, const FieldDescriptor *field, MessageFactory *factory=nullptr) const
Definition: generated_message_reflection.cc:1462
google::protobuf::MapReflectionTester::MapReflectionTester
MapReflectionTester(const Descriptor *base_descriptor)
Definition: map_test_util.cc:223
GOOGLE_CHECK
#define GOOGLE_CHECK(EXPRESSION)
Definition: logging.h:153
google::protobuf::MapReflectionTester::map_enum_bar_
const EnumValueDescriptor * map_enum_bar_
Definition: map_test_util.h:120
pool
InternalDescriptorPool * pool
Definition: php/ext/google/protobuf/protobuf.h:798
google::protobuf::MapTestUtil::ExpectMapsSize
static void ExpectMapsSize(const unittest::TestMap &message, int size)
Definition: map_test_util.cc:87
google::protobuf::MapTestUtilImpl::ExpectMapFieldsSet
static void ExpectMapFieldsSet(const MapMessage &message)
Definition: map_test_util_impl.h:260
i
int i
Definition: gmock-matchers_test.cc:764
google::protobuf::MapValueRef::SetInt64Value
void SetInt64Value(int64 value)
Definition: map_field.h:569
google::protobuf::MapKey::SetInt32Value
void SetInt32Value(int32 value)
Definition: map_field.h:403
google::protobuf::MapReflectionTester::map_int32_float_val_
const FieldDescriptor * map_int32_float_val_
Definition: map_test_util.h:146
google::protobuf::MapReflectionTester::map_sint32_sint32_key_
const FieldDescriptor * map_sint32_sint32_key_
Definition: map_test_util.h:133
google::protobuf::Reflection::ReleaseLast
Message * ReleaseLast(Message *message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:950
google::protobuf::MapReflectionTester::GetMapValueViaMapReflection
void GetMapValueViaMapReflection(Message *message, const std::string &field_name, const MapKey &map_key, MapValueRef *map_val)
Definition: map_test_util.cc:732
google::protobuf::Message
Definition: src/google/protobuf/message.h:205
google::protobuf::MapReflectionTester::map_int32_bytes_key_
const FieldDescriptor * map_int32_bytes_key_
Definition: map_test_util.h:153
google::protobuf::MapReflectionTester::map_fixed64_fixed64_key_
const FieldDescriptor * map_fixed64_fixed64_key_
Definition: map_test_util.h:139
google::protobuf::MapReflectionTester::ExpectClearViaReflection
void ExpectClearViaReflection(const Message &message)
Definition: map_test_util.cc:1540
google::protobuf::Reflection::MutableRepeatedMessage
Message * MutableRepeatedMessage(Message *message, const FieldDescriptor *field, int index) const
Definition: generated_message_reflection.cc:1617
google::protobuf::MapReflectionTester::map_uint32_uint32_key_
const FieldDescriptor * map_uint32_uint32_key_
Definition: map_test_util.h:129
google::protobuf::MapReflectionTester::map_uint32_uint32_val_
const FieldDescriptor * map_uint32_uint32_val_
Definition: map_test_util.h:130
google::protobuf::Descriptor::FindFieldByName
const FieldDescriptor * FindFieldByName(const std::string &name) const
Definition: src/google/protobuf/descriptor.cc:1615
size
GLsizeiptr size
Definition: glcorearb.h:2943
google::protobuf::MapKey
Definition: map_field.h:371
google::protobuf::MapTestUtilImpl::ExpectClear
static void ExpectClear(const MapMessage &message)
Definition: map_test_util_impl.h:238
EXPECT_FALSE
#define EXPECT_FALSE(cond)
Definition: glog/src/googletest.h:145
google::protobuf::MapReflectionTester::map_bool_bool_key_
const FieldDescriptor * map_bool_bool_key_
Definition: map_test_util.h:149
google::protobuf::MapValueRef::SetDoubleValue
void SetDoubleValue(double value)
Definition: map_field.h:602
google::protobuf::Descriptor::file
const FileDescriptor * file() const
google::protobuf::EnumValueDescriptor
Definition: src/google/protobuf/descriptor.h:1075
google::protobuf::Descriptor
Definition: src/google/protobuf/descriptor.h:231
descriptor.h
google::protobuf::MapTestUtil::ExpectMapFieldsSetInitialized
static void ExpectMapFieldsSetInitialized(const unittest::TestMap &message)
Definition: map_test_util.cc:74
google::protobuf::MapReflectionTester::map_int32_float_key_
const FieldDescriptor * map_int32_float_key_
Definition: map_test_util.h:145
google::protobuf::MapValueRef::SetStringValue
void SetStringValue(const std::string &value)
Definition: map_field.h:594
google::protobuf::Reflection::GetInt64
int64 GetInt64(const Message &message, const FieldDescriptor *field) const
google::protobuf::MapTestUtilImpl::SetArenaMapFields
static void SetArenaMapFields(MapMessage *message)
Definition: map_test_util_impl.h:151
google::protobuf::MapReflectionTester::map_int32_int32_val_
const FieldDescriptor * map_int32_int32_val_
Definition: map_test_util.h:126
google::protobuf::MapReflectionTester::map_enum_foo_
const EnumValueDescriptor * map_enum_foo_
Definition: map_test_util.h:122
google::protobuf::MapReflectionTester::map_sfixed32_sfixed32_val_
const FieldDescriptor * map_sfixed32_sfixed32_val_
Definition: map_test_util.h:142
google::protobuf::MapReflectionTester::base_descriptor_
const Descriptor * base_descriptor_
Definition: map_test_util.h:118
google::protobuf::MapReflectionTester::map_int32_double_key_
const FieldDescriptor * map_int32_double_key_
Definition: map_test_util.h:147
google::protobuf::MapReflectionTester::MapEnd
MapIterator MapEnd(Message *message, const std::string &field_name)
Definition: map_test_util.cc:752
val
GLuint GLfloat * val
Definition: glcorearb.h:3604
google::protobuf::MapReflectionTester::map_int64_int64_key_
const FieldDescriptor * map_int64_int64_key_
Definition: map_test_util.h:127
google::protobuf::Reflection::GetMapData
const internal::MapFieldBase * GetMapData(const Message &message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:2218
google::protobuf::MapKey::SetBoolValue
void SetBoolValue(bool value)
Definition: map_field.h:411
google::protobuf::MapReflectionTester::map_uint64_uint64_val_
const FieldDescriptor * map_uint64_uint64_val_
Definition: map_test_util.h:132
google::protobuf::Reflection::AddMessage
Message * AddMessage(Message *message, const FieldDescriptor *field, MessageFactory *factory=nullptr) const
Definition: generated_message_reflection.cc:1638
google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE
@ CPPTYPE_MESSAGE
Definition: src/google/protobuf/descriptor.h:563
output
const upb_json_parsermethod const upb_symtab upb_sink * output
Definition: ruby/ext/google/protobuf_c/upb.h:10503
google::protobuf::MapIterator
Definition: map_field.h:712
google::protobuf::MapReflectionTester::map_uint64_uint64_key_
const FieldDescriptor * map_uint64_uint64_key_
Definition: map_test_util.h:131
google::protobuf::MapTestUtil::GetMapEntriesFromRelease
static std::vector< const Message * > GetMapEntriesFromRelease(unittest::TestMap *message)
Definition: map_test_util.cc:180
index
GLuint index
Definition: glcorearb.h:3055
google::protobuf::MapReflectionTester::map_int32_double_val_
const FieldDescriptor * map_int32_double_val_
Definition: map_test_util.h:148
google::protobuf::Reflection::ListFields
void ListFields(const Message &message, std::vector< const FieldDescriptor * > *output) const
Definition: generated_message_reflection.cc:1029
google::protobuf::MapReflectionTester::map_fixed32_fixed32_key_
const FieldDescriptor * map_fixed32_fixed32_key_
Definition: map_test_util.h:137
google::protobuf::MapKey::SetUInt32Value
void SetUInt32Value(uint32 value)
Definition: map_field.h:407
google::protobuf::Reflection::SetFloat
void SetFloat(Message *message, const FieldDescriptor *field, float value) const
google
Definition: data_proto2_to_proto3_util.h:11
message
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glcorearb.h:2695
google::protobuf::MapReflectionTester::ExpectClearViaReflectionIterator
void ExpectClearViaReflectionIterator(Message *message)
Definition: map_test_util.cc:1564
google::protobuf::Reflection::GetUInt64
uint64 GetUInt64(const Message &message, const FieldDescriptor *field) const
google::protobuf::Reflection::GetRepeatedMessage
const Message & GetRepeatedMessage(const Message &message, const FieldDescriptor *field, int index) const
Definition: generated_message_reflection.cc:1597
google::protobuf::MapValueRef::MutableMessageValue
Message * MutableMessageValue()
Definition: map_field.h:650
google::protobuf::MapReflectionTester::ClearMapFieldsViaReflection
void ClearMapFieldsViaReflection(Message *message)
Definition: map_test_util.cc:758
google::protobuf::Reflection::GetMessage
const Message & GetMessage(const Message &message, const FieldDescriptor *field, MessageFactory *factory=nullptr) const
Definition: generated_message_reflection.cc:1443
google::protobuf::MapValueRef
Definition: map_field.h:565
google::protobuf::Reflection::MapEnd
MapIterator MapEnd(Message *message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:1795
google::protobuf::Reflection::GetDouble
double GetDouble(const Message &message, const FieldDescriptor *field) const
google::protobuf::Reflection::SetUInt32
void SetUInt32(Message *message, const FieldDescriptor *field, uint32 value) const


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:56