• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 //     * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //     * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 //     * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #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   (*message->mutable_map_int32_foreign_message_no_arena())[0].set_c(0);
171 
172   // Add second element
173   (*message->mutable_map_int32_int32())[1] = 1;
174   (*message->mutable_map_int64_int64())[1] = 1;
175   (*message->mutable_map_uint32_uint32())[1] = 1;
176   (*message->mutable_map_uint64_uint64())[1] = 1;
177   (*message->mutable_map_sint32_sint32())[1] = 1;
178   (*message->mutable_map_sint64_sint64())[1] = 1;
179   (*message->mutable_map_fixed32_fixed32())[1] = 1;
180   (*message->mutable_map_fixed64_fixed64())[1] = 1;
181   (*message->mutable_map_sfixed32_sfixed32())[1] = 1;
182   (*message->mutable_map_sfixed64_sfixed64())[1] = 1;
183   (*message->mutable_map_int32_float())[1] = 1.0;
184   (*message->mutable_map_int32_double())[1] = 1.0;
185   (*message->mutable_map_bool_bool())[1] = true;
186   (*message->mutable_map_string_string())["1"] = "1";
187   (*message->mutable_map_int32_bytes())[1] = "1";
188   (*message->mutable_map_int32_enum())[1] = enum_value1;
189   (*message->mutable_map_int32_foreign_message())[1].set_c(1);
190   (*message->mutable_map_int32_foreign_message_no_arena())[1].set_c(1);
191 }
192 
193 template <typename MapMessage>
SetMapFieldsInitialized(MapMessage * message)194 void MapTestUtilImpl::SetMapFieldsInitialized(MapMessage* message) {
195   // Add first element using bracket operator, which should assign default
196   // value automatically.
197   (*message->mutable_map_int32_int32())[0];
198   (*message->mutable_map_int64_int64())[0];
199   (*message->mutable_map_uint32_uint32())[0];
200   (*message->mutable_map_uint64_uint64())[0];
201   (*message->mutable_map_sint32_sint32())[0];
202   (*message->mutable_map_sint64_sint64())[0];
203   (*message->mutable_map_fixed32_fixed32())[0];
204   (*message->mutable_map_fixed64_fixed64())[0];
205   (*message->mutable_map_sfixed32_sfixed32())[0];
206   (*message->mutable_map_sfixed64_sfixed64())[0];
207   (*message->mutable_map_int32_float())[0];
208   (*message->mutable_map_int32_double())[0];
209   (*message->mutable_map_bool_bool())[0];
210   (*message->mutable_map_string_string())["0"];
211   (*message->mutable_map_int32_bytes())[0];
212   (*message->mutable_map_int32_enum())[0];
213   (*message->mutable_map_int32_foreign_message())[0];
214 }
215 
216 template <typename EnumType, EnumType enum_value, typename MapMessage>
ModifyMapFields(MapMessage * message)217 void MapTestUtilImpl::ModifyMapFields(MapMessage* message) {
218   (*message->mutable_map_int32_int32())[1] = 2;
219   (*message->mutable_map_int64_int64())[1] = 2;
220   (*message->mutable_map_uint32_uint32())[1] = 2;
221   (*message->mutable_map_uint64_uint64())[1] = 2;
222   (*message->mutable_map_sint32_sint32())[1] = 2;
223   (*message->mutable_map_sint64_sint64())[1] = 2;
224   (*message->mutable_map_fixed32_fixed32())[1] = 2;
225   (*message->mutable_map_fixed64_fixed64())[1] = 2;
226   (*message->mutable_map_sfixed32_sfixed32())[1] = 2;
227   (*message->mutable_map_sfixed64_sfixed64())[1] = 2;
228   (*message->mutable_map_int32_float())[1] = 2.0;
229   (*message->mutable_map_int32_double())[1] = 2.0;
230   (*message->mutable_map_bool_bool())[1] = false;
231   (*message->mutable_map_string_string())["1"] = "2";
232   (*message->mutable_map_int32_bytes())[1] = "2";
233   (*message->mutable_map_int32_enum())[1] = enum_value;
234   (*message->mutable_map_int32_foreign_message())[1].set_c(2);
235 }
236 
237 template <typename MapMessage>
ExpectClear(const MapMessage & message)238 void MapTestUtilImpl::ExpectClear(const MapMessage& message) {
239   EXPECT_EQ(0, message.map_int32_int32().size());
240   EXPECT_EQ(0, message.map_int64_int64().size());
241   EXPECT_EQ(0, message.map_uint32_uint32().size());
242   EXPECT_EQ(0, message.map_uint64_uint64().size());
243   EXPECT_EQ(0, message.map_sint32_sint32().size());
244   EXPECT_EQ(0, message.map_sint64_sint64().size());
245   EXPECT_EQ(0, message.map_fixed32_fixed32().size());
246   EXPECT_EQ(0, message.map_fixed64_fixed64().size());
247   EXPECT_EQ(0, message.map_sfixed32_sfixed32().size());
248   EXPECT_EQ(0, message.map_sfixed64_sfixed64().size());
249   EXPECT_EQ(0, message.map_int32_float().size());
250   EXPECT_EQ(0, message.map_int32_double().size());
251   EXPECT_EQ(0, message.map_bool_bool().size());
252   EXPECT_EQ(0, message.map_string_string().size());
253   EXPECT_EQ(0, message.map_int32_bytes().size());
254   EXPECT_EQ(0, message.map_int32_enum().size());
255   EXPECT_EQ(0, message.map_int32_foreign_message().size());
256 }
257 
258 template <typename EnumType, EnumType enum_value0, EnumType enum_value1,
259           typename MapMessage>
ExpectMapFieldsSet(const MapMessage & message)260 void MapTestUtilImpl::ExpectMapFieldsSet(const MapMessage& message) {
261   ASSERT_EQ(2, message.map_int32_int32().size());
262   ASSERT_EQ(2, message.map_int64_int64().size());
263   ASSERT_EQ(2, message.map_uint32_uint32().size());
264   ASSERT_EQ(2, message.map_uint64_uint64().size());
265   ASSERT_EQ(2, message.map_sint32_sint32().size());
266   ASSERT_EQ(2, message.map_sint64_sint64().size());
267   ASSERT_EQ(2, message.map_fixed32_fixed32().size());
268   ASSERT_EQ(2, message.map_fixed64_fixed64().size());
269   ASSERT_EQ(2, message.map_sfixed32_sfixed32().size());
270   ASSERT_EQ(2, message.map_sfixed64_sfixed64().size());
271   ASSERT_EQ(2, message.map_int32_float().size());
272   ASSERT_EQ(2, message.map_int32_double().size());
273   ASSERT_EQ(2, message.map_bool_bool().size());
274   ASSERT_EQ(2, message.map_string_string().size());
275   ASSERT_EQ(2, message.map_int32_bytes().size());
276   ASSERT_EQ(2, message.map_int32_enum().size());
277   ASSERT_EQ(2, message.map_int32_foreign_message().size());
278 
279   EXPECT_EQ(0, message.map_int32_int32().at(0));
280   EXPECT_EQ(0, message.map_int64_int64().at(0));
281   EXPECT_EQ(0, message.map_uint32_uint32().at(0));
282   EXPECT_EQ(0, message.map_uint64_uint64().at(0));
283   EXPECT_EQ(0, message.map_sint32_sint32().at(0));
284   EXPECT_EQ(0, message.map_sint64_sint64().at(0));
285   EXPECT_EQ(0, message.map_fixed32_fixed32().at(0));
286   EXPECT_EQ(0, message.map_fixed64_fixed64().at(0));
287   EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0));
288   EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0));
289   EXPECT_EQ(0, message.map_int32_float().at(0));
290   EXPECT_EQ(0, message.map_int32_double().at(0));
291   EXPECT_EQ(false, message.map_bool_bool().at(0));
292   EXPECT_EQ("0", message.map_string_string().at("0"));
293   EXPECT_EQ("0", message.map_int32_bytes().at(0));
294   EXPECT_EQ(enum_value0, message.map_int32_enum().at(0));
295   EXPECT_EQ(0, message.map_int32_foreign_message().at(0).c());
296 
297   EXPECT_EQ(1, message.map_int32_int32().at(1));
298   EXPECT_EQ(1, message.map_int64_int64().at(1));
299   EXPECT_EQ(1, message.map_uint32_uint32().at(1));
300   EXPECT_EQ(1, message.map_uint64_uint64().at(1));
301   EXPECT_EQ(1, message.map_sint32_sint32().at(1));
302   EXPECT_EQ(1, message.map_sint64_sint64().at(1));
303   EXPECT_EQ(1, message.map_fixed32_fixed32().at(1));
304   EXPECT_EQ(1, message.map_fixed64_fixed64().at(1));
305   EXPECT_EQ(1, message.map_sfixed32_sfixed32().at(1));
306   EXPECT_EQ(1, message.map_sfixed64_sfixed64().at(1));
307   EXPECT_EQ(1, message.map_int32_float().at(1));
308   EXPECT_EQ(1, message.map_int32_double().at(1));
309   EXPECT_EQ(true, message.map_bool_bool().at(1));
310   EXPECT_EQ("1", message.map_string_string().at("1"));
311   EXPECT_EQ("1", message.map_int32_bytes().at(1));
312   EXPECT_EQ(enum_value1, message.map_int32_enum().at(1));
313   EXPECT_EQ(1, message.map_int32_foreign_message().at(1).c());
314 }
315 
316 template <typename EnumType, EnumType enum_value0, EnumType enum_value1,
317           typename MapMessage>
ExpectArenaMapFieldsSet(const MapMessage & message)318 void MapTestUtilImpl::ExpectArenaMapFieldsSet(const MapMessage& message) {
319   EXPECT_EQ(2, message.map_int32_int32().size());
320   EXPECT_EQ(2, message.map_int64_int64().size());
321   EXPECT_EQ(2, message.map_uint32_uint32().size());
322   EXPECT_EQ(2, message.map_uint64_uint64().size());
323   EXPECT_EQ(2, message.map_sint32_sint32().size());
324   EXPECT_EQ(2, message.map_sint64_sint64().size());
325   EXPECT_EQ(2, message.map_fixed32_fixed32().size());
326   EXPECT_EQ(2, message.map_fixed64_fixed64().size());
327   EXPECT_EQ(2, message.map_sfixed32_sfixed32().size());
328   EXPECT_EQ(2, message.map_sfixed64_sfixed64().size());
329   EXPECT_EQ(2, message.map_int32_float().size());
330   EXPECT_EQ(2, message.map_int32_double().size());
331   EXPECT_EQ(2, message.map_bool_bool().size());
332   EXPECT_EQ(2, message.map_string_string().size());
333   EXPECT_EQ(2, message.map_int32_bytes().size());
334   EXPECT_EQ(2, message.map_int32_enum().size());
335   EXPECT_EQ(2, message.map_int32_foreign_message().size());
336   EXPECT_EQ(2, message.map_int32_foreign_message_no_arena().size());
337 
338   EXPECT_EQ(0, message.map_int32_int32().at(0));
339   EXPECT_EQ(0, message.map_int64_int64().at(0));
340   EXPECT_EQ(0, message.map_uint32_uint32().at(0));
341   EXPECT_EQ(0, message.map_uint64_uint64().at(0));
342   EXPECT_EQ(0, message.map_sint32_sint32().at(0));
343   EXPECT_EQ(0, message.map_sint64_sint64().at(0));
344   EXPECT_EQ(0, message.map_fixed32_fixed32().at(0));
345   EXPECT_EQ(0, message.map_fixed64_fixed64().at(0));
346   EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0));
347   EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0));
348   EXPECT_EQ(0, message.map_int32_float().at(0));
349   EXPECT_EQ(0, message.map_int32_double().at(0));
350   EXPECT_EQ(false, message.map_bool_bool().at(0));
351   EXPECT_EQ("0", message.map_string_string().at("0"));
352   EXPECT_EQ("0", message.map_int32_bytes().at(0));
353   EXPECT_EQ(enum_value0, message.map_int32_enum().at(0));
354   EXPECT_EQ(0, message.map_int32_foreign_message().at(0).c());
355   EXPECT_EQ(0, message.map_int32_foreign_message_no_arena().at(0).c());
356 
357   EXPECT_EQ(1, message.map_int32_int32().at(1));
358   EXPECT_EQ(1, message.map_int64_int64().at(1));
359   EXPECT_EQ(1, message.map_uint32_uint32().at(1));
360   EXPECT_EQ(1, message.map_uint64_uint64().at(1));
361   EXPECT_EQ(1, message.map_sint32_sint32().at(1));
362   EXPECT_EQ(1, message.map_sint64_sint64().at(1));
363   EXPECT_EQ(1, message.map_fixed32_fixed32().at(1));
364   EXPECT_EQ(1, message.map_fixed64_fixed64().at(1));
365   EXPECT_EQ(1, message.map_sfixed32_sfixed32().at(1));
366   EXPECT_EQ(1, message.map_sfixed64_sfixed64().at(1));
367   EXPECT_EQ(1, message.map_int32_float().at(1));
368   EXPECT_EQ(1, message.map_int32_double().at(1));
369   EXPECT_EQ(true, message.map_bool_bool().at(1));
370   EXPECT_EQ("1", message.map_string_string().at("1"));
371   EXPECT_EQ("1", message.map_int32_bytes().at(1));
372   EXPECT_EQ(enum_value1, message.map_int32_enum().at(1));
373   EXPECT_EQ(1, message.map_int32_foreign_message().at(1).c());
374   EXPECT_EQ(1, message.map_int32_foreign_message_no_arena().at(1).c());
375 }
376 
377 template <typename EnumType, EnumType enum_value, typename MapMessage>
ExpectMapFieldsSetInitialized(const MapMessage & message)378 void MapTestUtilImpl::ExpectMapFieldsSetInitialized(const MapMessage& message) {
379   EXPECT_EQ(1, message.map_int32_int32().size());
380   EXPECT_EQ(1, message.map_int64_int64().size());
381   EXPECT_EQ(1, message.map_uint32_uint32().size());
382   EXPECT_EQ(1, message.map_uint64_uint64().size());
383   EXPECT_EQ(1, message.map_sint32_sint32().size());
384   EXPECT_EQ(1, message.map_sint64_sint64().size());
385   EXPECT_EQ(1, message.map_fixed32_fixed32().size());
386   EXPECT_EQ(1, message.map_fixed64_fixed64().size());
387   EXPECT_EQ(1, message.map_sfixed32_sfixed32().size());
388   EXPECT_EQ(1, message.map_sfixed64_sfixed64().size());
389   EXPECT_EQ(1, message.map_int32_float().size());
390   EXPECT_EQ(1, message.map_int32_double().size());
391   EXPECT_EQ(1, message.map_bool_bool().size());
392   EXPECT_EQ(1, message.map_string_string().size());
393   EXPECT_EQ(1, message.map_int32_bytes().size());
394   EXPECT_EQ(1, message.map_int32_enum().size());
395   EXPECT_EQ(1, message.map_int32_foreign_message().size());
396 
397   EXPECT_EQ(0, message.map_int32_int32().at(0));
398   EXPECT_EQ(0, message.map_int64_int64().at(0));
399   EXPECT_EQ(0, message.map_uint32_uint32().at(0));
400   EXPECT_EQ(0, message.map_uint64_uint64().at(0));
401   EXPECT_EQ(0, message.map_sint32_sint32().at(0));
402   EXPECT_EQ(0, message.map_sint64_sint64().at(0));
403   EXPECT_EQ(0, message.map_fixed32_fixed32().at(0));
404   EXPECT_EQ(0, message.map_fixed64_fixed64().at(0));
405   EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0));
406   EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0));
407   EXPECT_EQ(0, message.map_int32_float().at(0));
408   EXPECT_EQ(0, message.map_int32_double().at(0));
409   EXPECT_EQ(false, message.map_bool_bool().at(0));
410   EXPECT_EQ("", message.map_string_string().at("0"));
411   EXPECT_EQ("", message.map_int32_bytes().at(0));
412   EXPECT_EQ(enum_value, message.map_int32_enum().at(0));
413   EXPECT_EQ(0, message.map_int32_foreign_message().at(0).ByteSize());
414 }
415 
416 template <typename EnumType, EnumType enum_value0, EnumType enum_value1,
417           typename MapMessage>
ExpectMapFieldsModified(const MapMessage & message)418 void MapTestUtilImpl::ExpectMapFieldsModified(const MapMessage& message) {
419   // ModifyMapFields only sets the second element of each field.  In addition to
420   // verifying this, we also verify that the first element and size were *not*
421   // modified.
422   EXPECT_EQ(2, message.map_int32_int32().size());
423   EXPECT_EQ(2, message.map_int64_int64().size());
424   EXPECT_EQ(2, message.map_uint32_uint32().size());
425   EXPECT_EQ(2, message.map_uint64_uint64().size());
426   EXPECT_EQ(2, message.map_sint32_sint32().size());
427   EXPECT_EQ(2, message.map_sint64_sint64().size());
428   EXPECT_EQ(2, message.map_fixed32_fixed32().size());
429   EXPECT_EQ(2, message.map_fixed64_fixed64().size());
430   EXPECT_EQ(2, message.map_sfixed32_sfixed32().size());
431   EXPECT_EQ(2, message.map_sfixed64_sfixed64().size());
432   EXPECT_EQ(2, message.map_int32_float().size());
433   EXPECT_EQ(2, message.map_int32_double().size());
434   EXPECT_EQ(2, message.map_bool_bool().size());
435   EXPECT_EQ(2, message.map_string_string().size());
436   EXPECT_EQ(2, message.map_int32_bytes().size());
437   EXPECT_EQ(2, message.map_int32_enum().size());
438   EXPECT_EQ(2, message.map_int32_foreign_message().size());
439 
440   EXPECT_EQ(0, message.map_int32_int32().at(0));
441   EXPECT_EQ(0, message.map_int64_int64().at(0));
442   EXPECT_EQ(0, message.map_uint32_uint32().at(0));
443   EXPECT_EQ(0, message.map_uint64_uint64().at(0));
444   EXPECT_EQ(0, message.map_sint32_sint32().at(0));
445   EXPECT_EQ(0, message.map_sint64_sint64().at(0));
446   EXPECT_EQ(0, message.map_fixed32_fixed32().at(0));
447   EXPECT_EQ(0, message.map_fixed64_fixed64().at(0));
448   EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0));
449   EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0));
450   EXPECT_EQ(0, message.map_int32_float().at(0));
451   EXPECT_EQ(0, message.map_int32_double().at(0));
452   EXPECT_EQ(false, message.map_bool_bool().at(0));
453   EXPECT_EQ("0", message.map_string_string().at("0"));
454   EXPECT_EQ("0", message.map_int32_bytes().at(0));
455   EXPECT_EQ(enum_value0, message.map_int32_enum().at(0));
456   EXPECT_EQ(0, message.map_int32_foreign_message().at(0).c());
457 
458   // Actually verify the second (modified) elements now.
459   EXPECT_EQ(2, message.map_int32_int32().at(1));
460   EXPECT_EQ(2, message.map_int64_int64().at(1));
461   EXPECT_EQ(2, message.map_uint32_uint32().at(1));
462   EXPECT_EQ(2, message.map_uint64_uint64().at(1));
463   EXPECT_EQ(2, message.map_sint32_sint32().at(1));
464   EXPECT_EQ(2, message.map_sint64_sint64().at(1));
465   EXPECT_EQ(2, message.map_fixed32_fixed32().at(1));
466   EXPECT_EQ(2, message.map_fixed64_fixed64().at(1));
467   EXPECT_EQ(2, message.map_sfixed32_sfixed32().at(1));
468   EXPECT_EQ(2, message.map_sfixed64_sfixed64().at(1));
469   EXPECT_EQ(2, message.map_int32_float().at(1));
470   EXPECT_EQ(2, message.map_int32_double().at(1));
471   EXPECT_EQ(false, message.map_bool_bool().at(1));
472   EXPECT_EQ("2", message.map_string_string().at("1"));
473   EXPECT_EQ("2", message.map_int32_bytes().at(1));
474   EXPECT_EQ(enum_value1, message.map_int32_enum().at(1));
475   EXPECT_EQ(2, message.map_int32_foreign_message().at(1).c());
476 }
477 
478 }  // namespace protobuf
479 }  // namespace google
480 
481 #endif  // GOOGLE_PROTOBUF_MAP_TEST_UTIL_IMPL_H__
482