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 37 38#define EXPECT_TRUE GOOGLE_CHECK 39#define ASSERT_TRUE GOOGLE_CHECK 40#define EXPECT_FALSE(COND) GOOGLE_CHECK(!(COND)) 41#define EXPECT_EQ GOOGLE_CHECK_EQ 42#define ASSERT_EQ GOOGLE_CHECK_EQ 43 44namespace google { 45namespace protobuf_unittest {} // forward declaration 46 47namespace protobuf { 48 49namespace unittest = ::protobuf_unittest; 50 51class MapTestUtilImpl { 52 public: 53 // Set every field in the TestMap message to a unique value. 54 template <typename EnumType, EnumType enum_value0, 55 EnumType enum_value1, typename MapMessage> 56 static void SetMapFields(MapMessage* message); 57 58 // Set every field in the TestArenaMap message to a unique value. 59 template <typename EnumType, EnumType enum_value0, 60 EnumType enum_value1, typename MapMessage> 61 static void SetArenaMapFields(MapMessage* message); 62 63 // Set every field in the message to a default value. 64 template <typename MapMessage> 65 static void SetMapFieldsInitialized(MapMessage* message); 66 67 // Modify all the map fields of the message (which should already have been 68 // initialized with SetMapFields()). 69 template <typename EnumType, EnumType enum_value, typename MapMessage> 70 static void ModifyMapFields(MapMessage* message); 71 72 // Check that all fields have the values that they should have after 73 // SetMapFields() is called. 74 template <typename EnumType, EnumType enum_value0, 75 EnumType enum_value1, typename MapMessage> 76 static void ExpectMapFieldsSet(const MapMessage& message); 77 78 // Check that all fields have the values that they should have after 79 // SetMapFields() is called for TestArenaMap. 80 template <typename EnumType, EnumType enum_value0, 81 EnumType enum_value1, typename MapMessage> 82 static void ExpectArenaMapFieldsSet(const MapMessage& message); 83 84 // Check that all fields have the values that they should have after 85 // SetMapFieldsInitialized() is called. 86 template <typename EnumType, EnumType enum_value, typename MapMessage> 87 static void ExpectMapFieldsSetInitialized(const MapMessage& message); 88 89 // Expect that the message is modified as would be expected from 90 // ModifyMapFields(). 91 template <typename EnumType, EnumType enum_value0, 92 EnumType enum_value1, typename MapMessage> 93 static void ExpectMapFieldsModified(const MapMessage& message); 94 95 // Check that all fields are empty. 96 template <typename MapMessage> 97 static void ExpectClear(const MapMessage& message); 98 99 // // Check that all map fields have the given size. 100 // template <typename MapMessage> 101 // static void ExpectMapsSize(const MapMessage& message, int size); 102 103 // // Get pointers of map entries at given index. 104 // static std::vector<const Message*> GetMapEntries( 105 // const MapMessage& message, int index); 106 107 // // Get pointers of map entries from release. 108 // static std::vector<const Message*> GetMapEntriesFromRelease( 109 // MapMessage* message); 110}; 111 112template <typename EnumType, EnumType enum_value0, 113 EnumType enum_value1, typename MapMessage> 114void MapTestUtilImpl::SetMapFields(MapMessage* message) { 115 // Add first element. 116 (*message->mutable_map_int32_int32())[0] = 0; 117 (*message->mutable_map_int64_int64())[0] = 0; 118 (*message->mutable_map_uint32_uint32())[0] = 0; 119 (*message->mutable_map_uint64_uint64())[0] = 0; 120 (*message->mutable_map_sint32_sint32())[0] = 0; 121 (*message->mutable_map_sint64_sint64())[0] = 0; 122 (*message->mutable_map_fixed32_fixed32())[0] = 0; 123 (*message->mutable_map_fixed64_fixed64())[0] = 0; 124 (*message->mutable_map_sfixed32_sfixed32())[0] = 0; 125 (*message->mutable_map_sfixed64_sfixed64())[0] = 0; 126 (*message->mutable_map_int32_float())[0] = 0.0; 127 (*message->mutable_map_int32_double())[0] = 0.0; 128 (*message->mutable_map_bool_bool())[0] = false; 129 (*message->mutable_map_string_string())["0"] = "0"; 130 (*message->mutable_map_int32_bytes())[0] = "0"; 131 (*message->mutable_map_int32_enum())[0] = enum_value0; 132 (*message->mutable_map_int32_foreign_message())[0].set_c(0); 133 134 // Add second element 135 (*message->mutable_map_int32_int32())[1] = 1; 136 (*message->mutable_map_int64_int64())[1] = 1; 137 (*message->mutable_map_uint32_uint32())[1] = 1; 138 (*message->mutable_map_uint64_uint64())[1] = 1; 139 (*message->mutable_map_sint32_sint32())[1] = 1; 140 (*message->mutable_map_sint64_sint64())[1] = 1; 141 (*message->mutable_map_fixed32_fixed32())[1] = 1; 142 (*message->mutable_map_fixed64_fixed64())[1] = 1; 143 (*message->mutable_map_sfixed32_sfixed32())[1] = 1; 144 (*message->mutable_map_sfixed64_sfixed64())[1] = 1; 145 (*message->mutable_map_int32_float())[1] = 1.0; 146 (*message->mutable_map_int32_double())[1] = 1.0; 147 (*message->mutable_map_bool_bool())[1] = true; 148 (*message->mutable_map_string_string())["1"] = "1"; 149 (*message->mutable_map_int32_bytes())[1] = "1"; 150 (*message->mutable_map_int32_enum())[1] = enum_value1; 151 (*message->mutable_map_int32_foreign_message())[1].set_c(1); 152} 153 154template <typename EnumType, EnumType enum_value0, 155 EnumType enum_value1, typename MapMessage> 156void MapTestUtilImpl::SetArenaMapFields(MapMessage* message) { 157 // Add first element. 158 (*message->mutable_map_int32_int32())[0] = 0; 159 (*message->mutable_map_int64_int64())[0] = 0; 160 (*message->mutable_map_uint32_uint32())[0] = 0; 161 (*message->mutable_map_uint64_uint64())[0] = 0; 162 (*message->mutable_map_sint32_sint32())[0] = 0; 163 (*message->mutable_map_sint64_sint64())[0] = 0; 164 (*message->mutable_map_fixed32_fixed32())[0] = 0; 165 (*message->mutable_map_fixed64_fixed64())[0] = 0; 166 (*message->mutable_map_sfixed32_sfixed32())[0] = 0; 167 (*message->mutable_map_sfixed64_sfixed64())[0] = 0; 168 (*message->mutable_map_int32_float())[0] = 0.0; 169 (*message->mutable_map_int32_double())[0] = 0.0; 170 (*message->mutable_map_bool_bool())[0] = false; 171 (*message->mutable_map_string_string())["0"] = "0"; 172 (*message->mutable_map_int32_bytes())[0] = "0"; 173 (*message->mutable_map_int32_enum())[0] = enum_value0; 174 (*message->mutable_map_int32_foreign_message())[0].set_c(0); 175 (*message->mutable_map_int32_foreign_message_no_arena())[0].set_c(0); 176 177 // Add second element 178 (*message->mutable_map_int32_int32())[1] = 1; 179 (*message->mutable_map_int64_int64())[1] = 1; 180 (*message->mutable_map_uint32_uint32())[1] = 1; 181 (*message->mutable_map_uint64_uint64())[1] = 1; 182 (*message->mutable_map_sint32_sint32())[1] = 1; 183 (*message->mutable_map_sint64_sint64())[1] = 1; 184 (*message->mutable_map_fixed32_fixed32())[1] = 1; 185 (*message->mutable_map_fixed64_fixed64())[1] = 1; 186 (*message->mutable_map_sfixed32_sfixed32())[1] = 1; 187 (*message->mutable_map_sfixed64_sfixed64())[1] = 1; 188 (*message->mutable_map_int32_float())[1] = 1.0; 189 (*message->mutable_map_int32_double())[1] = 1.0; 190 (*message->mutable_map_bool_bool())[1] = true; 191 (*message->mutable_map_string_string())["1"] = "1"; 192 (*message->mutable_map_int32_bytes())[1] = "1"; 193 (*message->mutable_map_int32_enum())[1] = enum_value1; 194 (*message->mutable_map_int32_foreign_message())[1].set_c(1); 195 (*message->mutable_map_int32_foreign_message_no_arena())[1].set_c(1); 196} 197 198template <typename MapMessage> 199void MapTestUtilImpl::SetMapFieldsInitialized(MapMessage* message) { 200 // Add first element using bracket operator, which should assign default 201 // value automatically. 202 (*message->mutable_map_int32_int32())[0]; 203 (*message->mutable_map_int64_int64())[0]; 204 (*message->mutable_map_uint32_uint32())[0]; 205 (*message->mutable_map_uint64_uint64())[0]; 206 (*message->mutable_map_sint32_sint32())[0]; 207 (*message->mutable_map_sint64_sint64())[0]; 208 (*message->mutable_map_fixed32_fixed32())[0]; 209 (*message->mutable_map_fixed64_fixed64())[0]; 210 (*message->mutable_map_sfixed32_sfixed32())[0]; 211 (*message->mutable_map_sfixed64_sfixed64())[0]; 212 (*message->mutable_map_int32_float())[0]; 213 (*message->mutable_map_int32_double())[0]; 214 (*message->mutable_map_bool_bool())[0]; 215 (*message->mutable_map_string_string())["0"]; 216 (*message->mutable_map_int32_bytes())[0]; 217 (*message->mutable_map_int32_enum())[0]; 218 (*message->mutable_map_int32_foreign_message())[0]; 219} 220 221template <typename EnumType, EnumType enum_value, typename MapMessage> 222void MapTestUtilImpl::ModifyMapFields(MapMessage* message) { 223 (*message->mutable_map_int32_int32())[1] = 2; 224 (*message->mutable_map_int64_int64())[1] = 2; 225 (*message->mutable_map_uint32_uint32())[1] = 2; 226 (*message->mutable_map_uint64_uint64())[1] = 2; 227 (*message->mutable_map_sint32_sint32())[1] = 2; 228 (*message->mutable_map_sint64_sint64())[1] = 2; 229 (*message->mutable_map_fixed32_fixed32())[1] = 2; 230 (*message->mutable_map_fixed64_fixed64())[1] = 2; 231 (*message->mutable_map_sfixed32_sfixed32())[1] = 2; 232 (*message->mutable_map_sfixed64_sfixed64())[1] = 2; 233 (*message->mutable_map_int32_float())[1] = 2.0; 234 (*message->mutable_map_int32_double())[1] = 2.0; 235 (*message->mutable_map_bool_bool())[1] = false; 236 (*message->mutable_map_string_string())["1"] = "2"; 237 (*message->mutable_map_int32_bytes())[1] = "2"; 238 (*message->mutable_map_int32_enum())[1] = enum_value; 239 (*message->mutable_map_int32_foreign_message())[1].set_c(2); 240} 241 242template <typename MapMessage> 243void MapTestUtilImpl::ExpectClear(const MapMessage& message) { 244 EXPECT_EQ(0, message.map_int32_int32().size()); 245 EXPECT_EQ(0, message.map_int64_int64().size()); 246 EXPECT_EQ(0, message.map_uint32_uint32().size()); 247 EXPECT_EQ(0, message.map_uint64_uint64().size()); 248 EXPECT_EQ(0, message.map_sint32_sint32().size()); 249 EXPECT_EQ(0, message.map_sint64_sint64().size()); 250 EXPECT_EQ(0, message.map_fixed32_fixed32().size()); 251 EXPECT_EQ(0, message.map_fixed64_fixed64().size()); 252 EXPECT_EQ(0, message.map_sfixed32_sfixed32().size()); 253 EXPECT_EQ(0, message.map_sfixed64_sfixed64().size()); 254 EXPECT_EQ(0, message.map_int32_float().size()); 255 EXPECT_EQ(0, message.map_int32_double().size()); 256 EXPECT_EQ(0, message.map_bool_bool().size()); 257 EXPECT_EQ(0, message.map_string_string().size()); 258 EXPECT_EQ(0, message.map_int32_bytes().size()); 259 EXPECT_EQ(0, message.map_int32_enum().size()); 260 EXPECT_EQ(0, message.map_int32_foreign_message().size()); 261} 262 263 264 265template <typename EnumType, EnumType enum_value0, 266 EnumType enum_value1, typename MapMessage> 267void MapTestUtilImpl::ExpectMapFieldsSet(const MapMessage& message) { 268 EXPECT_EQ(2, message.map_int32_int32().size()); 269 EXPECT_EQ(2, message.map_int64_int64().size()); 270 EXPECT_EQ(2, message.map_uint32_uint32().size()); 271 EXPECT_EQ(2, message.map_uint64_uint64().size()); 272 EXPECT_EQ(2, message.map_sint32_sint32().size()); 273 EXPECT_EQ(2, message.map_sint64_sint64().size()); 274 EXPECT_EQ(2, message.map_fixed32_fixed32().size()); 275 EXPECT_EQ(2, message.map_fixed64_fixed64().size()); 276 EXPECT_EQ(2, message.map_sfixed32_sfixed32().size()); 277 EXPECT_EQ(2, message.map_sfixed64_sfixed64().size()); 278 EXPECT_EQ(2, message.map_int32_float().size()); 279 EXPECT_EQ(2, message.map_int32_double().size()); 280 EXPECT_EQ(2, message.map_bool_bool().size()); 281 EXPECT_EQ(2, message.map_string_string().size()); 282 EXPECT_EQ(2, message.map_int32_bytes().size()); 283 EXPECT_EQ(2, message.map_int32_enum().size()); 284 EXPECT_EQ(2, message.map_int32_foreign_message().size()); 285 286 EXPECT_EQ(0, message.map_int32_int32().at(0)); 287 EXPECT_EQ(0, message.map_int64_int64().at(0)); 288 EXPECT_EQ(0, message.map_uint32_uint32().at(0)); 289 EXPECT_EQ(0, message.map_uint64_uint64().at(0)); 290 EXPECT_EQ(0, message.map_sint32_sint32().at(0)); 291 EXPECT_EQ(0, message.map_sint64_sint64().at(0)); 292 EXPECT_EQ(0, message.map_fixed32_fixed32().at(0)); 293 EXPECT_EQ(0, message.map_fixed64_fixed64().at(0)); 294 EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0)); 295 EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0)); 296 EXPECT_EQ(0, message.map_int32_float().at(0)); 297 EXPECT_EQ(0, message.map_int32_double().at(0)); 298 EXPECT_EQ(false, message.map_bool_bool().at(0)); 299 EXPECT_EQ("0", message.map_string_string().at("0")); 300 EXPECT_EQ("0", message.map_int32_bytes().at(0)); 301 EXPECT_EQ(enum_value0, message.map_int32_enum().at(0)); 302 EXPECT_EQ(0, message.map_int32_foreign_message().at(0).c()); 303 304 EXPECT_EQ(1, message.map_int32_int32().at(1)); 305 EXPECT_EQ(1, message.map_int64_int64().at(1)); 306 EXPECT_EQ(1, message.map_uint32_uint32().at(1)); 307 EXPECT_EQ(1, message.map_uint64_uint64().at(1)); 308 EXPECT_EQ(1, message.map_sint32_sint32().at(1)); 309 EXPECT_EQ(1, message.map_sint64_sint64().at(1)); 310 EXPECT_EQ(1, message.map_fixed32_fixed32().at(1)); 311 EXPECT_EQ(1, message.map_fixed64_fixed64().at(1)); 312 EXPECT_EQ(1, message.map_sfixed32_sfixed32().at(1)); 313 EXPECT_EQ(1, message.map_sfixed64_sfixed64().at(1)); 314 EXPECT_EQ(1, message.map_int32_float().at(1)); 315 EXPECT_EQ(1, message.map_int32_double().at(1)); 316 EXPECT_EQ(true, message.map_bool_bool().at(1)); 317 EXPECT_EQ("1", message.map_string_string().at("1")); 318 EXPECT_EQ("1", message.map_int32_bytes().at(1)); 319 EXPECT_EQ(enum_value1, message.map_int32_enum().at(1)); 320 EXPECT_EQ(1, message.map_int32_foreign_message().at(1).c()); 321} 322 323template <typename EnumType, EnumType enum_value0, 324 EnumType enum_value1, typename MapMessage> 325void MapTestUtilImpl::ExpectArenaMapFieldsSet(const MapMessage& message) { 326 EXPECT_EQ(2, message.map_int32_int32().size()); 327 EXPECT_EQ(2, message.map_int64_int64().size()); 328 EXPECT_EQ(2, message.map_uint32_uint32().size()); 329 EXPECT_EQ(2, message.map_uint64_uint64().size()); 330 EXPECT_EQ(2, message.map_sint32_sint32().size()); 331 EXPECT_EQ(2, message.map_sint64_sint64().size()); 332 EXPECT_EQ(2, message.map_fixed32_fixed32().size()); 333 EXPECT_EQ(2, message.map_fixed64_fixed64().size()); 334 EXPECT_EQ(2, message.map_sfixed32_sfixed32().size()); 335 EXPECT_EQ(2, message.map_sfixed64_sfixed64().size()); 336 EXPECT_EQ(2, message.map_int32_float().size()); 337 EXPECT_EQ(2, message.map_int32_double().size()); 338 EXPECT_EQ(2, message.map_bool_bool().size()); 339 EXPECT_EQ(2, message.map_string_string().size()); 340 EXPECT_EQ(2, message.map_int32_bytes().size()); 341 EXPECT_EQ(2, message.map_int32_enum().size()); 342 EXPECT_EQ(2, message.map_int32_foreign_message().size()); 343 EXPECT_EQ(2, message.map_int32_foreign_message_no_arena().size()); 344 345 EXPECT_EQ(0, message.map_int32_int32().at(0)); 346 EXPECT_EQ(0, message.map_int64_int64().at(0)); 347 EXPECT_EQ(0, message.map_uint32_uint32().at(0)); 348 EXPECT_EQ(0, message.map_uint64_uint64().at(0)); 349 EXPECT_EQ(0, message.map_sint32_sint32().at(0)); 350 EXPECT_EQ(0, message.map_sint64_sint64().at(0)); 351 EXPECT_EQ(0, message.map_fixed32_fixed32().at(0)); 352 EXPECT_EQ(0, message.map_fixed64_fixed64().at(0)); 353 EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0)); 354 EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0)); 355 EXPECT_EQ(0, message.map_int32_float().at(0)); 356 EXPECT_EQ(0, message.map_int32_double().at(0)); 357 EXPECT_EQ(false, message.map_bool_bool().at(0)); 358 EXPECT_EQ("0", message.map_string_string().at("0")); 359 EXPECT_EQ("0", message.map_int32_bytes().at(0)); 360 EXPECT_EQ(enum_value0, message.map_int32_enum().at(0)); 361 EXPECT_EQ(0, message.map_int32_foreign_message().at(0).c()); 362 EXPECT_EQ(0, message.map_int32_foreign_message_no_arena().at(0).c()); 363 364 EXPECT_EQ(1, message.map_int32_int32().at(1)); 365 EXPECT_EQ(1, message.map_int64_int64().at(1)); 366 EXPECT_EQ(1, message.map_uint32_uint32().at(1)); 367 EXPECT_EQ(1, message.map_uint64_uint64().at(1)); 368 EXPECT_EQ(1, message.map_sint32_sint32().at(1)); 369 EXPECT_EQ(1, message.map_sint64_sint64().at(1)); 370 EXPECT_EQ(1, message.map_fixed32_fixed32().at(1)); 371 EXPECT_EQ(1, message.map_fixed64_fixed64().at(1)); 372 EXPECT_EQ(1, message.map_sfixed32_sfixed32().at(1)); 373 EXPECT_EQ(1, message.map_sfixed64_sfixed64().at(1)); 374 EXPECT_EQ(1, message.map_int32_float().at(1)); 375 EXPECT_EQ(1, message.map_int32_double().at(1)); 376 EXPECT_EQ(true, message.map_bool_bool().at(1)); 377 EXPECT_EQ("1", message.map_string_string().at("1")); 378 EXPECT_EQ("1", message.map_int32_bytes().at(1)); 379 EXPECT_EQ(enum_value1, message.map_int32_enum().at(1)); 380 EXPECT_EQ(1, message.map_int32_foreign_message().at(1).c()); 381 EXPECT_EQ(1, message.map_int32_foreign_message_no_arena().at(1).c()); 382} 383 384template <typename EnumType, EnumType enum_value, typename MapMessage> 385void MapTestUtilImpl::ExpectMapFieldsSetInitialized( 386 const MapMessage& message) { 387 EXPECT_EQ(1, message.map_int32_int32().size()); 388 EXPECT_EQ(1, message.map_int64_int64().size()); 389 EXPECT_EQ(1, message.map_uint32_uint32().size()); 390 EXPECT_EQ(1, message.map_uint64_uint64().size()); 391 EXPECT_EQ(1, message.map_sint32_sint32().size()); 392 EXPECT_EQ(1, message.map_sint64_sint64().size()); 393 EXPECT_EQ(1, message.map_fixed32_fixed32().size()); 394 EXPECT_EQ(1, message.map_fixed64_fixed64().size()); 395 EXPECT_EQ(1, message.map_sfixed32_sfixed32().size()); 396 EXPECT_EQ(1, message.map_sfixed64_sfixed64().size()); 397 EXPECT_EQ(1, message.map_int32_float().size()); 398 EXPECT_EQ(1, message.map_int32_double().size()); 399 EXPECT_EQ(1, message.map_bool_bool().size()); 400 EXPECT_EQ(1, message.map_string_string().size()); 401 EXPECT_EQ(1, message.map_int32_bytes().size()); 402 EXPECT_EQ(1, message.map_int32_enum().size()); 403 EXPECT_EQ(1, message.map_int32_foreign_message().size()); 404 405 EXPECT_EQ(0, message.map_int32_int32().at(0)); 406 EXPECT_EQ(0, message.map_int64_int64().at(0)); 407 EXPECT_EQ(0, message.map_uint32_uint32().at(0)); 408 EXPECT_EQ(0, message.map_uint64_uint64().at(0)); 409 EXPECT_EQ(0, message.map_sint32_sint32().at(0)); 410 EXPECT_EQ(0, message.map_sint64_sint64().at(0)); 411 EXPECT_EQ(0, message.map_fixed32_fixed32().at(0)); 412 EXPECT_EQ(0, message.map_fixed64_fixed64().at(0)); 413 EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0)); 414 EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0)); 415 EXPECT_EQ(0, message.map_int32_float().at(0)); 416 EXPECT_EQ(0, message.map_int32_double().at(0)); 417 EXPECT_EQ(false, message.map_bool_bool().at(0)); 418 EXPECT_EQ("", message.map_string_string().at("0")); 419 EXPECT_EQ("", message.map_int32_bytes().at(0)); 420 EXPECT_EQ(enum_value, message.map_int32_enum().at(0)); 421 EXPECT_EQ(0, message.map_int32_foreign_message().at(0).ByteSize()); 422} 423 424template <typename EnumType, EnumType enum_value0, 425 EnumType enum_value1, typename MapMessage> 426void MapTestUtilImpl::ExpectMapFieldsModified( 427 const MapMessage& message) { 428 // ModifyMapFields only sets the second element of each field. In addition to 429 // verifying this, we also verify that the first element and size were *not* 430 // modified. 431 EXPECT_EQ(2, message.map_int32_int32().size()); 432 EXPECT_EQ(2, message.map_int64_int64().size()); 433 EXPECT_EQ(2, message.map_uint32_uint32().size()); 434 EXPECT_EQ(2, message.map_uint64_uint64().size()); 435 EXPECT_EQ(2, message.map_sint32_sint32().size()); 436 EXPECT_EQ(2, message.map_sint64_sint64().size()); 437 EXPECT_EQ(2, message.map_fixed32_fixed32().size()); 438 EXPECT_EQ(2, message.map_fixed64_fixed64().size()); 439 EXPECT_EQ(2, message.map_sfixed32_sfixed32().size()); 440 EXPECT_EQ(2, message.map_sfixed64_sfixed64().size()); 441 EXPECT_EQ(2, message.map_int32_float().size()); 442 EXPECT_EQ(2, message.map_int32_double().size()); 443 EXPECT_EQ(2, message.map_bool_bool().size()); 444 EXPECT_EQ(2, message.map_string_string().size()); 445 EXPECT_EQ(2, message.map_int32_bytes().size()); 446 EXPECT_EQ(2, message.map_int32_enum().size()); 447 EXPECT_EQ(2, message.map_int32_foreign_message().size()); 448 449 EXPECT_EQ(0, message.map_int32_int32().at(0)); 450 EXPECT_EQ(0, message.map_int64_int64().at(0)); 451 EXPECT_EQ(0, message.map_uint32_uint32().at(0)); 452 EXPECT_EQ(0, message.map_uint64_uint64().at(0)); 453 EXPECT_EQ(0, message.map_sint32_sint32().at(0)); 454 EXPECT_EQ(0, message.map_sint64_sint64().at(0)); 455 EXPECT_EQ(0, message.map_fixed32_fixed32().at(0)); 456 EXPECT_EQ(0, message.map_fixed64_fixed64().at(0)); 457 EXPECT_EQ(0, message.map_sfixed32_sfixed32().at(0)); 458 EXPECT_EQ(0, message.map_sfixed64_sfixed64().at(0)); 459 EXPECT_EQ(0, message.map_int32_float().at(0)); 460 EXPECT_EQ(0, message.map_int32_double().at(0)); 461 EXPECT_EQ(false, message.map_bool_bool().at(0)); 462 EXPECT_EQ("0", message.map_string_string().at("0")); 463 EXPECT_EQ("0", message.map_int32_bytes().at(0)); 464 EXPECT_EQ(enum_value0, message.map_int32_enum().at(0)); 465 EXPECT_EQ(0, message.map_int32_foreign_message().at(0).c()); 466 467 // Actually verify the second (modified) elements now. 468 EXPECT_EQ(2, message.map_int32_int32().at(1)); 469 EXPECT_EQ(2, message.map_int64_int64().at(1)); 470 EXPECT_EQ(2, message.map_uint32_uint32().at(1)); 471 EXPECT_EQ(2, message.map_uint64_uint64().at(1)); 472 EXPECT_EQ(2, message.map_sint32_sint32().at(1)); 473 EXPECT_EQ(2, message.map_sint64_sint64().at(1)); 474 EXPECT_EQ(2, message.map_fixed32_fixed32().at(1)); 475 EXPECT_EQ(2, message.map_fixed64_fixed64().at(1)); 476 EXPECT_EQ(2, message.map_sfixed32_sfixed32().at(1)); 477 EXPECT_EQ(2, message.map_sfixed64_sfixed64().at(1)); 478 EXPECT_EQ(2, message.map_int32_float().at(1)); 479 EXPECT_EQ(2, message.map_int32_double().at(1)); 480 EXPECT_EQ(false, message.map_bool_bool().at(1)); 481 EXPECT_EQ("2", message.map_string_string().at("1")); 482 EXPECT_EQ("2", message.map_int32_bytes().at(1)); 483 EXPECT_EQ(enum_value1, message.map_int32_enum().at(1)); 484 EXPECT_EQ(2, message.map_int32_foreign_message().at(1).c()); 485} 486 487} // namespace protobuf 488 489} // namespace google 490#endif // GOOGLE_PROTOBUF_MAP_TEST_UTIL_IMPL_H__ 491