1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 //     * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //     * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 //     * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef GOOGLE_PROTOBUF_MAP_TEST_UTIL_IMPL_H__
32 #define GOOGLE_PROTOBUF_MAP_TEST_UTIL_IMPL_H__
33 
34 #include <google/protobuf/stubs/logging.h>
35 #include <google/protobuf/stubs/common.h>
36 #include <gtest/gtest.h>
37 
38 
39 namespace protobuf_unittest {}  // namespace protobuf_unittest
40 
41 namespace google {
42 namespace protobuf {
43 
44 namespace unittest = ::protobuf_unittest;
45 
46 class MapTestUtilImpl {
47  public:
48   // Set every field in the TestMap message to a unique value.
49   template <typename EnumType, EnumType enum_value0, EnumType enum_value1,
50             typename MapMessage>
51   static void SetMapFields(MapMessage* message);
52 
53   // Set every field in the TestArenaMap message to a unique value.
54   template <typename EnumType, EnumType enum_value0, EnumType enum_value1,
55             typename MapMessage>
56   static void SetArenaMapFields(MapMessage* message);
57 
58   // Set every field in the message to a default value.
59   template <typename MapMessage>
60   static void SetMapFieldsInitialized(MapMessage* message);
61 
62   // Modify all the map fields of the message (which should already have been
63   // initialized with SetMapFields()).
64   template <typename EnumType, EnumType enum_value, typename MapMessage>
65   static void ModifyMapFields(MapMessage* message);
66 
67   // Check that all fields have the values that they should have after
68   // SetMapFields() is called.
69   template <typename EnumType, EnumType enum_value0, EnumType enum_value1,
70             typename MapMessage>
71   static void ExpectMapFieldsSet(const MapMessage& message);
72 
73   // Check that all fields have the values that they should have after
74   // SetMapFields() is called for TestArenaMap.
75   template <typename EnumType, EnumType enum_value0, EnumType enum_value1,
76             typename MapMessage>
77   static void ExpectArenaMapFieldsSet(const MapMessage& message);
78 
79   // Check that all fields have the values that they should have after
80   // SetMapFieldsInitialized() is called.
81   template <typename EnumType, EnumType enum_value, typename MapMessage>
82   static void ExpectMapFieldsSetInitialized(const MapMessage& message);
83 
84   // Expect that the message is modified as would be expected from
85   // ModifyMapFields().
86   template <typename EnumType, EnumType enum_value0, EnumType enum_value1,
87             typename MapMessage>
88   static void ExpectMapFieldsModified(const MapMessage& message);
89 
90   // Check that all fields are empty.
91   template <typename MapMessage>
92   static void ExpectClear(const MapMessage& message);
93 
94   // // Check that all map fields have the given size.
95   // template <typename MapMessage>
96   // static void ExpectMapsSize(const MapMessage& message, int size);
97 
98   // // Get pointers of map entries at given index.
99   // static std::vector<const Message*> GetMapEntries(
100   //     const MapMessage& message, int index);
101 
102   // // Get pointers of map entries from release.
103   // static std::vector<const Message*> GetMapEntriesFromRelease(
104   //     MapMessage* message);
105 };
106 
107 template <typename EnumType, EnumType enum_value0, EnumType enum_value1,
108           typename MapMessage>
SetMapFields(MapMessage * message)109 void MapTestUtilImpl::SetMapFields(MapMessage* message) {
110   // Add first element.
111   (*message->mutable_map_int32_int32())[0] = 0;
112   (*message->mutable_map_int64_int64())[0] = 0;
113   (*message->mutable_map_uint32_uint32())[0] = 0;
114   (*message->mutable_map_uint64_uint64())[0] = 0;
115   (*message->mutable_map_sint32_sint32())[0] = 0;
116   (*message->mutable_map_sint64_sint64())[0] = 0;
117   (*message->mutable_map_fixed32_fixed32())[0] = 0;
118   (*message->mutable_map_fixed64_fixed64())[0] = 0;
119   (*message->mutable_map_sfixed32_sfixed32())[0] = 0;
120   (*message->mutable_map_sfixed64_sfixed64())[0] = 0;
121   (*message->mutable_map_int32_float())[0] = 0.0;
122   (*message->mutable_map_int32_double())[0] = 0.0;
123   (*message->mutable_map_bool_bool())[0] = false;
124   (*message->mutable_map_string_string())["0"] = "0";
125   (*message->mutable_map_int32_bytes())[0] = "0";
126   (*message->mutable_map_int32_enum())[0] = enum_value0;
127   (*message->mutable_map_int32_foreign_message())[0].set_c(0);
128 
129   // Add second element
130   (*message->mutable_map_int32_int32())[1] = 1;
131   (*message->mutable_map_int64_int64())[1] = 1;
132   (*message->mutable_map_uint32_uint32())[1] = 1;
133   (*message->mutable_map_uint64_uint64())[1] = 1;
134   (*message->mutable_map_sint32_sint32())[1] = 1;
135   (*message->mutable_map_sint64_sint64())[1] = 1;
136   (*message->mutable_map_fixed32_fixed32())[1] = 1;
137   (*message->mutable_map_fixed64_fixed64())[1] = 1;
138   (*message->mutable_map_sfixed32_sfixed32())[1] = 1;
139   (*message->mutable_map_sfixed64_sfixed64())[1] = 1;
140   (*message->mutable_map_int32_float())[1] = 1.0;
141   (*message->mutable_map_int32_double())[1] = 1.0;
142   (*message->mutable_map_bool_bool())[1] = true;
143   (*message->mutable_map_string_string())["1"] = "1";
144   (*message->mutable_map_int32_bytes())[1] = "1";
145   (*message->mutable_map_int32_enum())[1] = enum_value1;
146   (*message->mutable_map_int32_foreign_message())[1].set_c(1);
147 }
148 
149 template <typename EnumType, EnumType enum_value0, EnumType enum_value1,
150           typename MapMessage>
SetArenaMapFields(MapMessage * message)151 void MapTestUtilImpl::SetArenaMapFields(MapMessage* message) {
152   // Add first element.
153   (*message->mutable_map_int32_int32())[0] = 0;
154   (*message->mutable_map_int64_int64())[0] = 0;
155   (*message->mutable_map_uint32_uint32())[0] = 0;
156   (*message->mutable_map_uint64_uint64())[0] = 0;
157   (*message->mutable_map_sint32_sint32())[0] = 0;
158   (*message->mutable_map_sint64_sint64())[0] = 0;
159   (*message->mutable_map_fixed32_fixed32())[0] = 0;
160   (*message->mutable_map_fixed64_fixed64())[0] = 0;
161   (*message->mutable_map_sfixed32_sfixed32())[0] = 0;
162   (*message->mutable_map_sfixed64_sfixed64())[0] = 0;
163   (*message->mutable_map_int32_float())[0] = 0.0;
164   (*message->mutable_map_int32_double())[0] = 0.0;
165   (*message->mutable_map_bool_bool())[0] = false;
166   (*message->mutable_map_string_string())["0"] = "0";
167   (*message->mutable_map_int32_bytes())[0] = "0";
168   (*message->mutable_map_int32_enum())[0] = enum_value0;
169   (*message->mutable_map_int32_foreign_message())[0].set_c(0);
170 
171   // Add second element
172   (*message->mutable_map_int32_int32())[1] = 1;
173   (*message->mutable_map_int64_int64())[1] = 1;
174   (*message->mutable_map_uint32_uint32())[1] = 1;
175   (*message->mutable_map_uint64_uint64())[1] = 1;
176   (*message->mutable_map_sint32_sint32())[1] = 1;
177   (*message->mutable_map_sint64_sint64())[1] = 1;
178   (*message->mutable_map_fixed32_fixed32())[1] = 1;
179   (*message->mutable_map_fixed64_fixed64())[1] = 1;
180   (*message->mutable_map_sfixed32_sfixed32())[1] = 1;
181   (*message->mutable_map_sfixed64_sfixed64())[1] = 1;
182   (*message->mutable_map_int32_float())[1] = 1.0;
183   (*message->mutable_map_int32_double())[1] = 1.0;
184   (*message->mutable_map_bool_bool())[1] = true;
185   (*message->mutable_map_string_string())["1"] = "1";
186   (*message->mutable_map_int32_bytes())[1] = "1";
187   (*message->mutable_map_int32_enum())[1] = enum_value1;
188   (*message->mutable_map_int32_foreign_message())[1].set_c(1);
189 }
190 
191 template <typename MapMessage>
SetMapFieldsInitialized(MapMessage * message)192 void MapTestUtilImpl::SetMapFieldsInitialized(MapMessage* message) {
193   // Add first element using bracket operator, which should assign default
194   // value automatically.
195   (*message->mutable_map_int32_int32())[0];
196   (*message->mutable_map_int64_int64())[0];
197   (*message->mutable_map_uint32_uint32())[0];
198   (*message->mutable_map_uint64_uint64())[0];
199   (*message->mutable_map_sint32_sint32())[0];
200   (*message->mutable_map_sint64_sint64())[0];
201   (*message->mutable_map_fixed32_fixed32())[0];
202   (*message->mutable_map_fixed64_fixed64())[0];
203   (*message->mutable_map_sfixed32_sfixed32())[0];
204   (*message->mutable_map_sfixed64_sfixed64())[0];
205   (*message->mutable_map_int32_float())[0];
206   (*message->mutable_map_int32_double())[0];
207   (*message->mutable_map_bool_bool())[0];
208   (*message->mutable_map_string_string())["0"];
209   (*message->mutable_map_int32_bytes())[0];
210   (*message->mutable_map_int32_enum())[0];
211   (*message->mutable_map_int32_foreign_message())[0];
212 }
213 
214 template <typename EnumType, EnumType enum_value, typename MapMessage>
ModifyMapFields(MapMessage * message)215 void MapTestUtilImpl::ModifyMapFields(MapMessage* message) {
216   (*message->mutable_map_int32_int32())[1] = 2;
217   (*message->mutable_map_int64_int64())[1] = 2;
218   (*message->mutable_map_uint32_uint32())[1] = 2;
219   (*message->mutable_map_uint64_uint64())[1] = 2;
220   (*message->mutable_map_sint32_sint32())[1] = 2;
221   (*message->mutable_map_sint64_sint64())[1] = 2;
222   (*message->mutable_map_fixed32_fixed32())[1] = 2;
223   (*message->mutable_map_fixed64_fixed64())[1] = 2;
224   (*message->mutable_map_sfixed32_sfixed32())[1] = 2;
225   (*message->mutable_map_sfixed64_sfixed64())[1] = 2;
226   (*message->mutable_map_int32_float())[1] = 2.0;
227   (*message->mutable_map_int32_double())[1] = 2.0;
228   (*message->mutable_map_bool_bool())[1] = false;
229   (*message->mutable_map_string_string())["1"] = "2";
230   (*message->mutable_map_int32_bytes())[1] = "2";
231   (*message->mutable_map_int32_enum())[1] = enum_value;
232   (*message->mutable_map_int32_foreign_message())[1].set_c(2);
233 }
234 
235 template <typename MapMessage>
ExpectClear(const MapMessage & message)236 void MapTestUtilImpl::ExpectClear(const MapMessage& message) {
237   EXPECT_EQ(0, message.map_int32_int32().size());
238   EXPECT_EQ(0, message.map_int64_int64().size());
239   EXPECT_EQ(0, message.map_uint32_uint32().size());
240   EXPECT_EQ(0, message.map_uint64_uint64().size());
241   EXPECT_EQ(0, message.map_sint32_sint32().size());
242   EXPECT_EQ(0, message.map_sint64_sint64().size());
243   EXPECT_EQ(0, message.map_fixed32_fixed32().size());
244   EXPECT_EQ(0, message.map_fixed64_fixed64().size());
245   EXPECT_EQ(0, message.map_sfixed32_sfixed32().size());
246   EXPECT_EQ(0, message.map_sfixed64_sfixed64().size());
247   EXPECT_EQ(0, message.map_int32_float().size());
248   EXPECT_EQ(0, message.map_int32_double().size());
249   EXPECT_EQ(0, message.map_bool_bool().size());
250   EXPECT_EQ(0, message.map_string_string().size());
251   EXPECT_EQ(0, message.map_int32_bytes().size());
252   EXPECT_EQ(0, message.map_int32_enum().size());
253   EXPECT_EQ(0, message.map_int32_foreign_message().size());
254 }
255 
256 template <typename EnumType, EnumType enum_value0, EnumType enum_value1,
257           typename MapMessage>
ExpectMapFieldsSet(const MapMessage & message)258 void MapTestUtilImpl::ExpectMapFieldsSet(const MapMessage& message) {
259   ASSERT_EQ(2, message.map_int32_int32().size());
260   ASSERT_EQ(2, message.map_int64_int64().size());
261   ASSERT_EQ(2, message.map_uint32_uint32().size());
262   ASSERT_EQ(2, message.map_uint64_uint64().size());
263   ASSERT_EQ(2, message.map_sint32_sint32().size());
264   ASSERT_EQ(2, message.map_sint64_sint64().size());
265   ASSERT_EQ(2, message.map_fixed32_fixed32().size());
266   ASSERT_EQ(2, message.map_fixed64_fixed64().size());
267   ASSERT_EQ(2, message.map_sfixed32_sfixed32().size());
268   ASSERT_EQ(2, message.map_sfixed64_sfixed64().size());
269   ASSERT_EQ(2, message.map_int32_float().size());
270   ASSERT_EQ(2, message.map_int32_double().size());
271   ASSERT_EQ(2, message.map_bool_bool().size());
272   ASSERT_EQ(2, message.map_string_string().size());
273   ASSERT_EQ(2, message.map_int32_bytes().size());
274   ASSERT_EQ(2, message.map_int32_enum().size());
275   ASSERT_EQ(2, message.map_int32_foreign_message().size());
276 
277   EXPECT_EQ(0, message.map_int32_int32().at(0));
278   EXPECT_EQ(0, message.map_int64_int64().at(0));
279   EXPECT_EQ(0, message.map_uint32_uint32().at(0));
280   EXPECT_EQ(0, message.map_uint64_uint64().at(0));
281   EXPECT_EQ(0, message.map_sint32_sint32().at(0));
282   EXPECT_EQ(0, message.map_sint64_sint64().at(0));
283   EXPECT_EQ(0, message.map_fixed32_fixed32().at(0));
284   EXPECT_EQ(0, message.map_fixed64_fixed64().at(0));
285   EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0));
286   EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0));
287   EXPECT_EQ(0, message.map_int32_float().at(0));
288   EXPECT_EQ(0, message.map_int32_double().at(0));
289   EXPECT_EQ(false, message.map_bool_bool().at(0));
290   EXPECT_EQ("0", message.map_string_string().at("0"));
291   EXPECT_EQ("0", message.map_int32_bytes().at(0));
292   EXPECT_EQ(enum_value0, message.map_int32_enum().at(0));
293   EXPECT_EQ(0, message.map_int32_foreign_message().at(0).c());
294 
295   EXPECT_EQ(1, message.map_int32_int32().at(1));
296   EXPECT_EQ(1, message.map_int64_int64().at(1));
297   EXPECT_EQ(1, message.map_uint32_uint32().at(1));
298   EXPECT_EQ(1, message.map_uint64_uint64().at(1));
299   EXPECT_EQ(1, message.map_sint32_sint32().at(1));
300   EXPECT_EQ(1, message.map_sint64_sint64().at(1));
301   EXPECT_EQ(1, message.map_fixed32_fixed32().at(1));
302   EXPECT_EQ(1, message.map_fixed64_fixed64().at(1));
303   EXPECT_EQ(1, message.map_sfixed32_sfixed32().at(1));
304   EXPECT_EQ(1, message.map_sfixed64_sfixed64().at(1));
305   EXPECT_EQ(1, message.map_int32_float().at(1));
306   EXPECT_EQ(1, message.map_int32_double().at(1));
307   EXPECT_EQ(true, message.map_bool_bool().at(1));
308   EXPECT_EQ("1", message.map_string_string().at("1"));
309   EXPECT_EQ("1", message.map_int32_bytes().at(1));
310   EXPECT_EQ(enum_value1, message.map_int32_enum().at(1));
311   EXPECT_EQ(1, message.map_int32_foreign_message().at(1).c());
312 }
313 
314 template <typename EnumType, EnumType enum_value0, EnumType enum_value1,
315           typename MapMessage>
ExpectArenaMapFieldsSet(const MapMessage & message)316 void MapTestUtilImpl::ExpectArenaMapFieldsSet(const MapMessage& message) {
317   EXPECT_EQ(2, message.map_int32_int32().size());
318   EXPECT_EQ(2, message.map_int64_int64().size());
319   EXPECT_EQ(2, message.map_uint32_uint32().size());
320   EXPECT_EQ(2, message.map_uint64_uint64().size());
321   EXPECT_EQ(2, message.map_sint32_sint32().size());
322   EXPECT_EQ(2, message.map_sint64_sint64().size());
323   EXPECT_EQ(2, message.map_fixed32_fixed32().size());
324   EXPECT_EQ(2, message.map_fixed64_fixed64().size());
325   EXPECT_EQ(2, message.map_sfixed32_sfixed32().size());
326   EXPECT_EQ(2, message.map_sfixed64_sfixed64().size());
327   EXPECT_EQ(2, message.map_int32_float().size());
328   EXPECT_EQ(2, message.map_int32_double().size());
329   EXPECT_EQ(2, message.map_bool_bool().size());
330   EXPECT_EQ(2, message.map_string_string().size());
331   EXPECT_EQ(2, message.map_int32_bytes().size());
332   EXPECT_EQ(2, message.map_int32_enum().size());
333   EXPECT_EQ(2, message.map_int32_foreign_message().size());
334 
335   EXPECT_EQ(0, message.map_int32_int32().at(0));
336   EXPECT_EQ(0, message.map_int64_int64().at(0));
337   EXPECT_EQ(0, message.map_uint32_uint32().at(0));
338   EXPECT_EQ(0, message.map_uint64_uint64().at(0));
339   EXPECT_EQ(0, message.map_sint32_sint32().at(0));
340   EXPECT_EQ(0, message.map_sint64_sint64().at(0));
341   EXPECT_EQ(0, message.map_fixed32_fixed32().at(0));
342   EXPECT_EQ(0, message.map_fixed64_fixed64().at(0));
343   EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0));
344   EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0));
345   EXPECT_EQ(0, message.map_int32_float().at(0));
346   EXPECT_EQ(0, message.map_int32_double().at(0));
347   EXPECT_EQ(false, message.map_bool_bool().at(0));
348   EXPECT_EQ("0", message.map_string_string().at("0"));
349   EXPECT_EQ("0", message.map_int32_bytes().at(0));
350   EXPECT_EQ(enum_value0, message.map_int32_enum().at(0));
351   EXPECT_EQ(0, message.map_int32_foreign_message().at(0).c());
352 
353   EXPECT_EQ(1, message.map_int32_int32().at(1));
354   EXPECT_EQ(1, message.map_int64_int64().at(1));
355   EXPECT_EQ(1, message.map_uint32_uint32().at(1));
356   EXPECT_EQ(1, message.map_uint64_uint64().at(1));
357   EXPECT_EQ(1, message.map_sint32_sint32().at(1));
358   EXPECT_EQ(1, message.map_sint64_sint64().at(1));
359   EXPECT_EQ(1, message.map_fixed32_fixed32().at(1));
360   EXPECT_EQ(1, message.map_fixed64_fixed64().at(1));
361   EXPECT_EQ(1, message.map_sfixed32_sfixed32().at(1));
362   EXPECT_EQ(1, message.map_sfixed64_sfixed64().at(1));
363   EXPECT_EQ(1, message.map_int32_float().at(1));
364   EXPECT_EQ(1, message.map_int32_double().at(1));
365   EXPECT_EQ(true, message.map_bool_bool().at(1));
366   EXPECT_EQ("1", message.map_string_string().at("1"));
367   EXPECT_EQ("1", message.map_int32_bytes().at(1));
368   EXPECT_EQ(enum_value1, message.map_int32_enum().at(1));
369   EXPECT_EQ(1, message.map_int32_foreign_message().at(1).c());
370 }
371 
372 template <typename EnumType, EnumType enum_value, typename MapMessage>
ExpectMapFieldsSetInitialized(const MapMessage & message)373 void MapTestUtilImpl::ExpectMapFieldsSetInitialized(const MapMessage& message) {
374   EXPECT_EQ(1, message.map_int32_int32().size());
375   EXPECT_EQ(1, message.map_int64_int64().size());
376   EXPECT_EQ(1, message.map_uint32_uint32().size());
377   EXPECT_EQ(1, message.map_uint64_uint64().size());
378   EXPECT_EQ(1, message.map_sint32_sint32().size());
379   EXPECT_EQ(1, message.map_sint64_sint64().size());
380   EXPECT_EQ(1, message.map_fixed32_fixed32().size());
381   EXPECT_EQ(1, message.map_fixed64_fixed64().size());
382   EXPECT_EQ(1, message.map_sfixed32_sfixed32().size());
383   EXPECT_EQ(1, message.map_sfixed64_sfixed64().size());
384   EXPECT_EQ(1, message.map_int32_float().size());
385   EXPECT_EQ(1, message.map_int32_double().size());
386   EXPECT_EQ(1, message.map_bool_bool().size());
387   EXPECT_EQ(1, message.map_string_string().size());
388   EXPECT_EQ(1, message.map_int32_bytes().size());
389   EXPECT_EQ(1, message.map_int32_enum().size());
390   EXPECT_EQ(1, message.map_int32_foreign_message().size());
391 
392   EXPECT_EQ(0, message.map_int32_int32().at(0));
393   EXPECT_EQ(0, message.map_int64_int64().at(0));
394   EXPECT_EQ(0, message.map_uint32_uint32().at(0));
395   EXPECT_EQ(0, message.map_uint64_uint64().at(0));
396   EXPECT_EQ(0, message.map_sint32_sint32().at(0));
397   EXPECT_EQ(0, message.map_sint64_sint64().at(0));
398   EXPECT_EQ(0, message.map_fixed32_fixed32().at(0));
399   EXPECT_EQ(0, message.map_fixed64_fixed64().at(0));
400   EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0));
401   EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0));
402   EXPECT_EQ(0, message.map_int32_float().at(0));
403   EXPECT_EQ(0, message.map_int32_double().at(0));
404   EXPECT_EQ(false, message.map_bool_bool().at(0));
405   EXPECT_EQ("", message.map_string_string().at("0"));
406   EXPECT_EQ("", message.map_int32_bytes().at(0));
407   EXPECT_EQ(enum_value, message.map_int32_enum().at(0));
408   EXPECT_EQ(0, message.map_int32_foreign_message().at(0).ByteSizeLong());
409 }
410 
411 template <typename EnumType, EnumType enum_value0, EnumType enum_value1,
412           typename MapMessage>
ExpectMapFieldsModified(const MapMessage & message)413 void MapTestUtilImpl::ExpectMapFieldsModified(const MapMessage& message) {
414   // ModifyMapFields only sets the second element of each field.  In addition to
415   // verifying this, we also verify that the first element and size were *not*
416   // modified.
417   EXPECT_EQ(2, message.map_int32_int32().size());
418   EXPECT_EQ(2, message.map_int64_int64().size());
419   EXPECT_EQ(2, message.map_uint32_uint32().size());
420   EXPECT_EQ(2, message.map_uint64_uint64().size());
421   EXPECT_EQ(2, message.map_sint32_sint32().size());
422   EXPECT_EQ(2, message.map_sint64_sint64().size());
423   EXPECT_EQ(2, message.map_fixed32_fixed32().size());
424   EXPECT_EQ(2, message.map_fixed64_fixed64().size());
425   EXPECT_EQ(2, message.map_sfixed32_sfixed32().size());
426   EXPECT_EQ(2, message.map_sfixed64_sfixed64().size());
427   EXPECT_EQ(2, message.map_int32_float().size());
428   EXPECT_EQ(2, message.map_int32_double().size());
429   EXPECT_EQ(2, message.map_bool_bool().size());
430   EXPECT_EQ(2, message.map_string_string().size());
431   EXPECT_EQ(2, message.map_int32_bytes().size());
432   EXPECT_EQ(2, message.map_int32_enum().size());
433   EXPECT_EQ(2, message.map_int32_foreign_message().size());
434 
435   EXPECT_EQ(0, message.map_int32_int32().at(0));
436   EXPECT_EQ(0, message.map_int64_int64().at(0));
437   EXPECT_EQ(0, message.map_uint32_uint32().at(0));
438   EXPECT_EQ(0, message.map_uint64_uint64().at(0));
439   EXPECT_EQ(0, message.map_sint32_sint32().at(0));
440   EXPECT_EQ(0, message.map_sint64_sint64().at(0));
441   EXPECT_EQ(0, message.map_fixed32_fixed32().at(0));
442   EXPECT_EQ(0, message.map_fixed64_fixed64().at(0));
443   EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0));
444   EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0));
445   EXPECT_EQ(0, message.map_int32_float().at(0));
446   EXPECT_EQ(0, message.map_int32_double().at(0));
447   EXPECT_EQ(false, message.map_bool_bool().at(0));
448   EXPECT_EQ("0", message.map_string_string().at("0"));
449   EXPECT_EQ("0", message.map_int32_bytes().at(0));
450   EXPECT_EQ(enum_value0, message.map_int32_enum().at(0));
451   EXPECT_EQ(0, message.map_int32_foreign_message().at(0).c());
452 
453   // Actually verify the second (modified) elements now.
454   EXPECT_EQ(2, message.map_int32_int32().at(1));
455   EXPECT_EQ(2, message.map_int64_int64().at(1));
456   EXPECT_EQ(2, message.map_uint32_uint32().at(1));
457   EXPECT_EQ(2, message.map_uint64_uint64().at(1));
458   EXPECT_EQ(2, message.map_sint32_sint32().at(1));
459   EXPECT_EQ(2, message.map_sint64_sint64().at(1));
460   EXPECT_EQ(2, message.map_fixed32_fixed32().at(1));
461   EXPECT_EQ(2, message.map_fixed64_fixed64().at(1));
462   EXPECT_EQ(2, message.map_sfixed32_sfixed32().at(1));
463   EXPECT_EQ(2, message.map_sfixed64_sfixed64().at(1));
464   EXPECT_EQ(2, message.map_int32_float().at(1));
465   EXPECT_EQ(2, message.map_int32_double().at(1));
466   EXPECT_EQ(false, message.map_bool_bool().at(1));
467   EXPECT_EQ("2", message.map_string_string().at("1"));
468   EXPECT_EQ("2", message.map_int32_bytes().at(1));
469   EXPECT_EQ(enum_value1, message.map_int32_enum().at(1));
470   EXPECT_EQ(2, message.map_int32_foreign_message().at(1).c());
471 }
472 
473 }  // namespace protobuf
474 }  // namespace google
475 
476 #endif  // GOOGLE_PROTOBUF_MAP_TEST_UTIL_IMPL_H__
477