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// Author: kenton@google.com (Kenton Varda) 32// Based on original Protocol Buffers design by 33// Sanjay Ghemawat, Jeff Dean, and others. 34// 35// This file needs to be included as .inc as it depends on the namespaces 36// (unittest and unittest_import) being set up properly. It is also included 37// within an enclosing namespace and requires header files to be included 38// out of this file. 39 40#include <google/protobuf/stubs/logging.h> 41#include <google/protobuf/stubs/common.h> 42#include <google/protobuf/descriptor.h> 43#include <google/protobuf/message.h> 44#include <gtest/gtest.h> 45 46namespace google { 47namespace protobuf { 48namespace TestUtil { 49 50// Set every field in the message to a unique value. 51inline void SetAllFields(UNITTEST::TestAllTypes* message); 52inline void SetOptionalFields(UNITTEST::TestAllTypes* message); 53inline void AddRepeatedFields1(UNITTEST::TestAllTypes* message); 54inline void AddRepeatedFields2(UNITTEST::TestAllTypes* message); 55inline void SetDefaultFields(UNITTEST::TestAllTypes* message); 56inline void SetOneofFields(UNITTEST::TestAllTypes* message); 57inline void SetAllExtensions(UNITTEST::TestAllExtensions* message); 58inline void SetOneofFields(UNITTEST::TestAllExtensions* message); 59inline void SetAllFieldsAndExtensions(UNITTEST::TestFieldOrderings* message); 60inline void SetPackedFields(UNITTEST::TestPackedTypes* message); 61inline void SetPackedExtensions(UNITTEST::TestPackedExtensions* message); 62inline void SetUnpackedFields(UNITTEST::TestUnpackedTypes* message); 63inline void SetOneof1(UNITTEST::TestOneof2* message); 64inline void SetOneof2(UNITTEST::TestOneof2* message); 65 66// Use the repeated versions of the set_*() accessors to modify all the 67// repeated fields of the message (which should already have been 68// initialized with Set*Fields()). Set*Fields() itself only tests 69// the add_*() accessors. 70inline void ModifyRepeatedFields(UNITTEST::TestAllTypes* message); 71inline void ModifyRepeatedExtensions(UNITTEST::TestAllExtensions* message); 72 73// Check that all fields have the values that they should have after 74// Set*Fields() is called. 75inline void ExpectAllFieldsSet(const UNITTEST::TestAllTypes& message); 76inline void ExpectAllExtensionsSet(const UNITTEST::TestAllExtensions& message); 77inline void ExpectPackedFieldsSet(const UNITTEST::TestPackedTypes& message); 78inline void ExpectPackedExtensionsSet( 79 const UNITTEST::TestPackedExtensions& message); 80inline void ExpectUnpackedFieldsSet(const UNITTEST::TestUnpackedTypes& message); 81inline void ExpectUnpackedExtensionsSet( 82 const UNITTEST::TestUnpackedExtensions& message); 83inline void ExpectOneofSet1(const UNITTEST::TestOneof2& message); 84inline void ExpectOneofSet2(const UNITTEST::TestOneof2& message); 85 86// Expect that the message is modified as would be expected from 87// Modify*Fields(). 88inline void ExpectRepeatedFieldsModified(const UNITTEST::TestAllTypes& message); 89inline void ExpectRepeatedExtensionsModified( 90 const UNITTEST::TestAllExtensions& message); 91 92// Check that all fields have their default values. 93inline void ExpectClear(const UNITTEST::TestAllTypes& message); 94inline void ExpectExtensionsClear(const UNITTEST::TestAllExtensions& message); 95inline void ExpectOneofClear(const UNITTEST::TestOneof2& message); 96 97// Check that all repeated fields have had their last elements removed. 98inline void ExpectLastRepeatedsRemoved(const UNITTEST::TestAllTypes& message); 99inline void ExpectLastRepeatedExtensionsRemoved( 100 const UNITTEST::TestAllExtensions& message); 101inline void ExpectLastRepeatedsReleased(const UNITTEST::TestAllTypes& message); 102inline void ExpectLastRepeatedExtensionsReleased( 103 const UNITTEST::TestAllExtensions& message); 104 105// Check that all repeated fields have had their first and last elements 106// swapped. 107inline void ExpectRepeatedsSwapped(const UNITTEST::TestAllTypes& message); 108inline void ExpectRepeatedExtensionsSwapped( 109 const UNITTEST::TestAllExtensions& message); 110 111inline void ExpectAtMostOneFieldSetInOneof(const UNITTEST::TestOneof2& message); 112 113} // namespace TestUtil 114 115inline void TestUtil::SetAllFields(UNITTEST::TestAllTypes* message) { 116 SetOptionalFields(message); 117 AddRepeatedFields1(message); 118 AddRepeatedFields2(message); 119 SetDefaultFields(message); 120 SetOneofFields(message); 121} 122 123inline void TestUtil::SetOptionalFields(UNITTEST::TestAllTypes* message) { 124 message->set_optional_int32(101); 125 message->set_optional_int64(102); 126 message->set_optional_uint32(103); 127 message->set_optional_uint64(104); 128 message->set_optional_sint32(105); 129 message->set_optional_sint64(106); 130 message->set_optional_fixed32(107); 131 message->set_optional_fixed64(108); 132 message->set_optional_sfixed32(109); 133 message->set_optional_sfixed64(110); 134 message->set_optional_float(111); 135 message->set_optional_double(112); 136 message->set_optional_bool(true); 137 message->set_optional_string("115"); 138 message->set_optional_bytes("116"); 139 140 message->mutable_optionalgroup()->set_a(117); 141 message->mutable_optional_nested_message()->set_bb(118); 142 message->mutable_optional_foreign_message()->set_c(119); 143 message->mutable_optional_import_message()->set_d(120); 144 message->mutable_optional_public_import_message()->set_e(126); 145 message->mutable_optional_lazy_message()->set_bb(127); 146 147 message->set_optional_nested_enum(UNITTEST::TestAllTypes::BAZ); 148 message->set_optional_foreign_enum(UNITTEST::FOREIGN_BAZ); 149 message->set_optional_import_enum(UNITTEST_IMPORT::IMPORT_BAZ); 150 151 // StringPiece and Cord fields are only accessible via reflection in the 152 // open source release; see comments in compiler/cpp/string_field.cc. 153#ifndef PROTOBUF_TEST_NO_DESCRIPTORS 154 message->GetReflection()->SetString( 155 message, 156 message->GetDescriptor()->FindFieldByName("optional_string_piece"), 157 "124"); 158 message->GetReflection()->SetString( 159 message, message->GetDescriptor()->FindFieldByName("optional_cord"), 160 "125"); 161#endif // !PROTOBUF_TEST_NO_DESCRIPTORS 162} 163 164// ------------------------------------------------------------------- 165 166inline void TestUtil::AddRepeatedFields1(UNITTEST::TestAllTypes* message) { 167 message->add_repeated_int32(201); 168 message->add_repeated_int64(202); 169 message->add_repeated_uint32(203); 170 message->add_repeated_uint64(204); 171 message->add_repeated_sint32(205); 172 message->add_repeated_sint64(206); 173 message->add_repeated_fixed32(207); 174 message->add_repeated_fixed64(208); 175 message->add_repeated_sfixed32(209); 176 message->add_repeated_sfixed64(210); 177 message->add_repeated_float(211); 178 message->add_repeated_double(212); 179 message->add_repeated_bool(true); 180 message->add_repeated_string("215"); 181 message->add_repeated_bytes("216"); 182 183 message->add_repeatedgroup()->set_a(217); 184 message->add_repeated_nested_message()->set_bb(218); 185 message->add_repeated_foreign_message()->set_c(219); 186 message->add_repeated_import_message()->set_d(220); 187 message->add_repeated_lazy_message()->set_bb(227); 188 189 message->add_repeated_nested_enum(UNITTEST::TestAllTypes::BAR); 190 message->add_repeated_foreign_enum(UNITTEST::FOREIGN_BAR); 191 message->add_repeated_import_enum(UNITTEST_IMPORT::IMPORT_BAR); 192 193#ifndef PROTOBUF_TEST_NO_DESCRIPTORS 194 message->GetReflection()->AddString( 195 message, 196 message->GetDescriptor()->FindFieldByName("repeated_string_piece"), 197 "224"); 198 message->GetReflection()->AddString( 199 message, message->GetDescriptor()->FindFieldByName("repeated_cord"), 200 "225"); 201#endif // !PROTOBUF_TEST_NO_DESCRIPTORS 202} 203 204inline void TestUtil::AddRepeatedFields2(UNITTEST::TestAllTypes* message) { 205 // Add a second one of each field. 206 message->add_repeated_int32(301); 207 message->add_repeated_int64(302); 208 message->add_repeated_uint32(303); 209 message->add_repeated_uint64(304); 210 message->add_repeated_sint32(305); 211 message->add_repeated_sint64(306); 212 message->add_repeated_fixed32(307); 213 message->add_repeated_fixed64(308); 214 message->add_repeated_sfixed32(309); 215 message->add_repeated_sfixed64(310); 216 message->add_repeated_float(311); 217 message->add_repeated_double(312); 218 message->add_repeated_bool(false); 219 message->add_repeated_string("315"); 220 message->add_repeated_bytes("316"); 221 222 message->add_repeatedgroup()->set_a(317); 223 message->add_repeated_nested_message()->set_bb(318); 224 message->add_repeated_foreign_message()->set_c(319); 225 message->add_repeated_import_message()->set_d(320); 226 message->add_repeated_lazy_message()->set_bb(327); 227 228 message->add_repeated_nested_enum(UNITTEST::TestAllTypes::BAZ); 229 message->add_repeated_foreign_enum(UNITTEST::FOREIGN_BAZ); 230 message->add_repeated_import_enum(UNITTEST_IMPORT::IMPORT_BAZ); 231 232#ifndef PROTOBUF_TEST_NO_DESCRIPTORS 233 message->GetReflection()->AddString( 234 message, 235 message->GetDescriptor()->FindFieldByName("repeated_string_piece"), 236 "324"); 237 message->GetReflection()->AddString( 238 message, message->GetDescriptor()->FindFieldByName("repeated_cord"), 239 "325"); 240#endif // !PROTOBUF_TEST_NO_DESCRIPTORS 241} 242 243// ------------------------------------------------------------------- 244 245inline void TestUtil::SetDefaultFields(UNITTEST::TestAllTypes* message) { 246 message->set_default_int32(401); 247 message->set_default_int64(402); 248 message->set_default_uint32(403); 249 message->set_default_uint64(404); 250 message->set_default_sint32(405); 251 message->set_default_sint64(406); 252 message->set_default_fixed32(407); 253 message->set_default_fixed64(408); 254 message->set_default_sfixed32(409); 255 message->set_default_sfixed64(410); 256 message->set_default_float(411); 257 message->set_default_double(412); 258 message->set_default_bool(false); 259 message->set_default_string("415"); 260 message->set_default_bytes("416"); 261 262 message->set_default_nested_enum(UNITTEST::TestAllTypes::FOO); 263 message->set_default_foreign_enum(UNITTEST::FOREIGN_FOO); 264 message->set_default_import_enum(UNITTEST_IMPORT::IMPORT_FOO); 265 266#ifndef PROTOBUF_TEST_NO_DESCRIPTORS 267 message->GetReflection()->SetString( 268 message, 269 message->GetDescriptor()->FindFieldByName("default_string_piece"), "424"); 270 message->GetReflection()->SetString( 271 message, message->GetDescriptor()->FindFieldByName("default_cord"), 272 "425"); 273#endif // !PROTOBUF_TEST_NO_DESCRIPTORS 274} 275 276// ------------------------------------------------------------------- 277 278inline void TestUtil::ModifyRepeatedFields(UNITTEST::TestAllTypes* message) { 279 message->set_repeated_int32(1, 501); 280 message->set_repeated_int64(1, 502); 281 message->set_repeated_uint32(1, 503); 282 message->set_repeated_uint64(1, 504); 283 message->set_repeated_sint32(1, 505); 284 message->set_repeated_sint64(1, 506); 285 message->set_repeated_fixed32(1, 507); 286 message->set_repeated_fixed64(1, 508); 287 message->set_repeated_sfixed32(1, 509); 288 message->set_repeated_sfixed64(1, 510); 289 message->set_repeated_float(1, 511); 290 message->set_repeated_double(1, 512); 291 message->set_repeated_bool(1, true); 292 message->set_repeated_string(1, "515"); 293 message->set_repeated_bytes(1, "516"); 294 295 message->mutable_repeatedgroup(1)->set_a(517); 296 message->mutable_repeated_nested_message(1)->set_bb(518); 297 message->mutable_repeated_foreign_message(1)->set_c(519); 298 message->mutable_repeated_import_message(1)->set_d(520); 299 message->mutable_repeated_lazy_message(1)->set_bb(527); 300 301 message->set_repeated_nested_enum(1, UNITTEST::TestAllTypes::FOO); 302 message->set_repeated_foreign_enum(1, UNITTEST::FOREIGN_FOO); 303 message->set_repeated_import_enum(1, UNITTEST_IMPORT::IMPORT_FOO); 304 305#ifndef PROTOBUF_TEST_NO_DESCRIPTORS 306 message->GetReflection()->SetRepeatedString( 307 message, 308 message->GetDescriptor()->FindFieldByName("repeated_string_piece"), 1, 309 "524"); 310 message->GetReflection()->SetRepeatedString( 311 message, message->GetDescriptor()->FindFieldByName("repeated_cord"), 1, 312 "525"); 313#endif // !PROTOBUF_TEST_NO_DESCRIPTORS 314} 315 316// ------------------------------------------------------------------ 317inline void TestUtil::SetOneofFields(UNITTEST::TestAllTypes* message) { 318 message->set_oneof_uint32(601); 319 message->mutable_oneof_nested_message()->set_bb(602); 320 message->set_oneof_string("603"); 321 message->set_oneof_bytes("604"); 322} 323 324// ------------------------------------------------------------------- 325 326inline void TestUtil::ExpectAllFieldsSet( 327 const UNITTEST::TestAllTypes& message) { 328 EXPECT_TRUE(message.has_optional_int32()); 329 EXPECT_TRUE(message.has_optional_int64()); 330 EXPECT_TRUE(message.has_optional_uint32()); 331 EXPECT_TRUE(message.has_optional_uint64()); 332 EXPECT_TRUE(message.has_optional_sint32()); 333 EXPECT_TRUE(message.has_optional_sint64()); 334 EXPECT_TRUE(message.has_optional_fixed32()); 335 EXPECT_TRUE(message.has_optional_fixed64()); 336 EXPECT_TRUE(message.has_optional_sfixed32()); 337 EXPECT_TRUE(message.has_optional_sfixed64()); 338 EXPECT_TRUE(message.has_optional_float()); 339 EXPECT_TRUE(message.has_optional_double()); 340 EXPECT_TRUE(message.has_optional_bool()); 341 EXPECT_TRUE(message.has_optional_string()); 342 EXPECT_TRUE(message.has_optional_bytes()); 343 344 EXPECT_TRUE(message.has_optionalgroup()); 345 EXPECT_TRUE(message.has_optional_nested_message()); 346 EXPECT_TRUE(message.has_optional_foreign_message()); 347 EXPECT_TRUE(message.has_optional_import_message()); 348 EXPECT_TRUE(message.has_optional_public_import_message()); 349 EXPECT_TRUE(message.has_optional_lazy_message()); 350 351 EXPECT_TRUE(message.optionalgroup().has_a()); 352 EXPECT_TRUE(message.optional_nested_message().has_bb()); 353 EXPECT_TRUE(message.optional_foreign_message().has_c()); 354 EXPECT_TRUE(message.optional_import_message().has_d()); 355 EXPECT_TRUE(message.optional_public_import_message().has_e()); 356 EXPECT_TRUE(message.optional_lazy_message().has_bb()); 357 358 EXPECT_TRUE(message.has_optional_nested_enum()); 359 EXPECT_TRUE(message.has_optional_foreign_enum()); 360 EXPECT_TRUE(message.has_optional_import_enum()); 361 362#ifndef PROTOBUF_TEST_NO_DESCRIPTORS 363 EXPECT_TRUE(message.has_optional_string_piece()); 364 EXPECT_TRUE(message.has_optional_cord()); 365#endif 366 367 EXPECT_EQ(101, message.optional_int32()); 368 EXPECT_EQ(102, message.optional_int64()); 369 EXPECT_EQ(103, message.optional_uint32()); 370 EXPECT_EQ(104, message.optional_uint64()); 371 EXPECT_EQ(105, message.optional_sint32()); 372 EXPECT_EQ(106, message.optional_sint64()); 373 EXPECT_EQ(107, message.optional_fixed32()); 374 EXPECT_EQ(108, message.optional_fixed64()); 375 EXPECT_EQ(109, message.optional_sfixed32()); 376 EXPECT_EQ(110, message.optional_sfixed64()); 377 EXPECT_EQ(111, message.optional_float()); 378 EXPECT_EQ(112, message.optional_double()); 379 EXPECT_TRUE(message.optional_bool()); 380 EXPECT_EQ("115", message.optional_string()); 381 EXPECT_EQ("116", message.optional_bytes()); 382 383 EXPECT_EQ(117, message.optionalgroup().a()); 384 EXPECT_EQ(118, message.optional_nested_message().bb()); 385 EXPECT_EQ(119, message.optional_foreign_message().c()); 386 EXPECT_EQ(120, message.optional_import_message().d()); 387 EXPECT_EQ(126, message.optional_public_import_message().e()); 388 EXPECT_EQ(127, message.optional_lazy_message().bb()); 389 390 EXPECT_EQ(UNITTEST::TestAllTypes::BAZ, message.optional_nested_enum()); 391 EXPECT_EQ(UNITTEST::FOREIGN_BAZ, message.optional_foreign_enum()); 392 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAZ, message.optional_import_enum()); 393 394 395 // ----------------------------------------------------------------- 396 397 ASSERT_EQ(2, message.repeated_int32_size()); 398 ASSERT_EQ(2, message.repeated_int64_size()); 399 ASSERT_EQ(2, message.repeated_uint32_size()); 400 ASSERT_EQ(2, message.repeated_uint64_size()); 401 ASSERT_EQ(2, message.repeated_sint32_size()); 402 ASSERT_EQ(2, message.repeated_sint64_size()); 403 ASSERT_EQ(2, message.repeated_fixed32_size()); 404 ASSERT_EQ(2, message.repeated_fixed64_size()); 405 ASSERT_EQ(2, message.repeated_sfixed32_size()); 406 ASSERT_EQ(2, message.repeated_sfixed64_size()); 407 ASSERT_EQ(2, message.repeated_float_size()); 408 ASSERT_EQ(2, message.repeated_double_size()); 409 ASSERT_EQ(2, message.repeated_bool_size()); 410 ASSERT_EQ(2, message.repeated_string_size()); 411 ASSERT_EQ(2, message.repeated_bytes_size()); 412 413 ASSERT_EQ(2, message.repeatedgroup_size()); 414 ASSERT_EQ(2, message.repeated_nested_message_size()); 415 ASSERT_EQ(2, message.repeated_foreign_message_size()); 416 ASSERT_EQ(2, message.repeated_import_message_size()); 417 ASSERT_EQ(2, message.repeated_lazy_message_size()); 418 ASSERT_EQ(2, message.repeated_nested_enum_size()); 419 ASSERT_EQ(2, message.repeated_foreign_enum_size()); 420 ASSERT_EQ(2, message.repeated_import_enum_size()); 421 422#ifndef PROTOBUF_TEST_NO_DESCRIPTORS 423 ASSERT_EQ(2, message.repeated_string_piece_size()); 424 ASSERT_EQ(2, message.repeated_cord_size()); 425#endif 426 427 EXPECT_EQ(201, message.repeated_int32(0)); 428 EXPECT_EQ(202, message.repeated_int64(0)); 429 EXPECT_EQ(203, message.repeated_uint32(0)); 430 EXPECT_EQ(204, message.repeated_uint64(0)); 431 EXPECT_EQ(205, message.repeated_sint32(0)); 432 EXPECT_EQ(206, message.repeated_sint64(0)); 433 EXPECT_EQ(207, message.repeated_fixed32(0)); 434 EXPECT_EQ(208, message.repeated_fixed64(0)); 435 EXPECT_EQ(209, message.repeated_sfixed32(0)); 436 EXPECT_EQ(210, message.repeated_sfixed64(0)); 437 EXPECT_EQ(211, message.repeated_float(0)); 438 EXPECT_EQ(212, message.repeated_double(0)); 439 EXPECT_TRUE(message.repeated_bool(0)); 440 EXPECT_EQ("215", message.repeated_string(0)); 441 EXPECT_EQ("216", message.repeated_bytes(0)); 442 443 EXPECT_EQ(217, message.repeatedgroup(0).a()); 444 EXPECT_EQ(218, message.repeated_nested_message(0).bb()); 445 EXPECT_EQ(219, message.repeated_foreign_message(0).c()); 446 EXPECT_EQ(220, message.repeated_import_message(0).d()); 447 EXPECT_EQ(227, message.repeated_lazy_message(0).bb()); 448 449 450 EXPECT_EQ(UNITTEST::TestAllTypes::BAR, message.repeated_nested_enum(0)); 451 EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.repeated_foreign_enum(0)); 452 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, message.repeated_import_enum(0)); 453 454 EXPECT_EQ(301, message.repeated_int32(1)); 455 EXPECT_EQ(302, message.repeated_int64(1)); 456 EXPECT_EQ(303, message.repeated_uint32(1)); 457 EXPECT_EQ(304, message.repeated_uint64(1)); 458 EXPECT_EQ(305, message.repeated_sint32(1)); 459 EXPECT_EQ(306, message.repeated_sint64(1)); 460 EXPECT_EQ(307, message.repeated_fixed32(1)); 461 EXPECT_EQ(308, message.repeated_fixed64(1)); 462 EXPECT_EQ(309, message.repeated_sfixed32(1)); 463 EXPECT_EQ(310, message.repeated_sfixed64(1)); 464 EXPECT_EQ(311, message.repeated_float(1)); 465 EXPECT_EQ(312, message.repeated_double(1)); 466 EXPECT_FALSE(message.repeated_bool(1)); 467 EXPECT_EQ("315", message.repeated_string(1)); 468 EXPECT_EQ("316", message.repeated_bytes(1)); 469 470 EXPECT_EQ(317, message.repeatedgroup(1).a()); 471 EXPECT_EQ(318, message.repeated_nested_message(1).bb()); 472 EXPECT_EQ(319, message.repeated_foreign_message(1).c()); 473 EXPECT_EQ(320, message.repeated_import_message(1).d()); 474 EXPECT_EQ(327, message.repeated_lazy_message(1).bb()); 475 476 EXPECT_EQ(UNITTEST::TestAllTypes::BAZ, message.repeated_nested_enum(1)); 477 EXPECT_EQ(UNITTEST::FOREIGN_BAZ, message.repeated_foreign_enum(1)); 478 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAZ, message.repeated_import_enum(1)); 479 480 481 // ----------------------------------------------------------------- 482 483 EXPECT_TRUE(message.has_default_int32()); 484 EXPECT_TRUE(message.has_default_int64()); 485 EXPECT_TRUE(message.has_default_uint32()); 486 EXPECT_TRUE(message.has_default_uint64()); 487 EXPECT_TRUE(message.has_default_sint32()); 488 EXPECT_TRUE(message.has_default_sint64()); 489 EXPECT_TRUE(message.has_default_fixed32()); 490 EXPECT_TRUE(message.has_default_fixed64()); 491 EXPECT_TRUE(message.has_default_sfixed32()); 492 EXPECT_TRUE(message.has_default_sfixed64()); 493 EXPECT_TRUE(message.has_default_float()); 494 EXPECT_TRUE(message.has_default_double()); 495 EXPECT_TRUE(message.has_default_bool()); 496 EXPECT_TRUE(message.has_default_string()); 497 EXPECT_TRUE(message.has_default_bytes()); 498 499 EXPECT_TRUE(message.has_default_nested_enum()); 500 EXPECT_TRUE(message.has_default_foreign_enum()); 501 EXPECT_TRUE(message.has_default_import_enum()); 502 503 504 EXPECT_EQ(401, message.default_int32()); 505 EXPECT_EQ(402, message.default_int64()); 506 EXPECT_EQ(403, message.default_uint32()); 507 EXPECT_EQ(404, message.default_uint64()); 508 EXPECT_EQ(405, message.default_sint32()); 509 EXPECT_EQ(406, message.default_sint64()); 510 EXPECT_EQ(407, message.default_fixed32()); 511 EXPECT_EQ(408, message.default_fixed64()); 512 EXPECT_EQ(409, message.default_sfixed32()); 513 EXPECT_EQ(410, message.default_sfixed64()); 514 EXPECT_EQ(411, message.default_float()); 515 EXPECT_EQ(412, message.default_double()); 516 EXPECT_FALSE(message.default_bool()); 517 EXPECT_EQ("415", message.default_string()); 518 EXPECT_EQ("416", message.default_bytes()); 519 520 EXPECT_EQ(UNITTEST::TestAllTypes::FOO, message.default_nested_enum()); 521 EXPECT_EQ(UNITTEST::FOREIGN_FOO, message.default_foreign_enum()); 522 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_FOO, message.default_import_enum()); 523 524 525 EXPECT_FALSE(message.has_oneof_uint32()); 526 EXPECT_FALSE(message.has_oneof_nested_message()); 527 EXPECT_FALSE(message.has_oneof_string()); 528 EXPECT_TRUE(message.has_oneof_bytes()); 529 530 EXPECT_EQ("604", message.oneof_bytes()); 531} 532 533// ------------------------------------------------------------------- 534 535inline void TestUtil::ExpectClear(const UNITTEST::TestAllTypes& message) { 536 // has_blah() should initially be false for all optional fields. 537 EXPECT_FALSE(message.has_optional_int32()); 538 EXPECT_FALSE(message.has_optional_int64()); 539 EXPECT_FALSE(message.has_optional_uint32()); 540 EXPECT_FALSE(message.has_optional_uint64()); 541 EXPECT_FALSE(message.has_optional_sint32()); 542 EXPECT_FALSE(message.has_optional_sint64()); 543 EXPECT_FALSE(message.has_optional_fixed32()); 544 EXPECT_FALSE(message.has_optional_fixed64()); 545 EXPECT_FALSE(message.has_optional_sfixed32()); 546 EXPECT_FALSE(message.has_optional_sfixed64()); 547 EXPECT_FALSE(message.has_optional_float()); 548 EXPECT_FALSE(message.has_optional_double()); 549 EXPECT_FALSE(message.has_optional_bool()); 550 EXPECT_FALSE(message.has_optional_string()); 551 EXPECT_FALSE(message.has_optional_bytes()); 552 553 EXPECT_FALSE(message.has_optionalgroup()); 554 EXPECT_FALSE(message.has_optional_nested_message()); 555 EXPECT_FALSE(message.has_optional_foreign_message()); 556 EXPECT_FALSE(message.has_optional_import_message()); 557 EXPECT_FALSE(message.has_optional_public_import_message()); 558 EXPECT_FALSE(message.has_optional_lazy_message()); 559 560 EXPECT_FALSE(message.has_optional_nested_enum()); 561 EXPECT_FALSE(message.has_optional_foreign_enum()); 562 EXPECT_FALSE(message.has_optional_import_enum()); 563 564 EXPECT_FALSE(message.has_optional_string_piece()); 565 EXPECT_FALSE(message.has_optional_cord()); 566 567 // Optional fields without defaults are set to zero or something like it. 568 EXPECT_EQ(0, message.optional_int32()); 569 EXPECT_EQ(0, message.optional_int64()); 570 EXPECT_EQ(0, message.optional_uint32()); 571 EXPECT_EQ(0, message.optional_uint64()); 572 EXPECT_EQ(0, message.optional_sint32()); 573 EXPECT_EQ(0, message.optional_sint64()); 574 EXPECT_EQ(0, message.optional_fixed32()); 575 EXPECT_EQ(0, message.optional_fixed64()); 576 EXPECT_EQ(0, message.optional_sfixed32()); 577 EXPECT_EQ(0, message.optional_sfixed64()); 578 EXPECT_EQ(0, message.optional_float()); 579 EXPECT_EQ(0, message.optional_double()); 580 EXPECT_FALSE(message.optional_bool()); 581 EXPECT_EQ("", message.optional_string()); 582 EXPECT_EQ("", message.optional_bytes()); 583 584 // Embedded messages should also be clear. 585 EXPECT_FALSE(message.optionalgroup().has_a()); 586 EXPECT_FALSE(message.optional_nested_message().has_bb()); 587 EXPECT_FALSE(message.optional_foreign_message().has_c()); 588 EXPECT_FALSE(message.optional_import_message().has_d()); 589 EXPECT_FALSE(message.optional_public_import_message().has_e()); 590 EXPECT_FALSE(message.optional_lazy_message().has_bb()); 591 592 EXPECT_EQ(0, message.optionalgroup().a()); 593 EXPECT_EQ(0, message.optional_nested_message().bb()); 594 EXPECT_EQ(0, message.optional_foreign_message().c()); 595 EXPECT_EQ(0, message.optional_import_message().d()); 596 EXPECT_EQ(0, message.optional_public_import_message().e()); 597 EXPECT_EQ(0, message.optional_lazy_message().bb()); 598 599 // Enums without defaults are set to the first value in the enum. 600 EXPECT_EQ(UNITTEST::TestAllTypes::FOO, message.optional_nested_enum()); 601 EXPECT_EQ(UNITTEST::FOREIGN_FOO, message.optional_foreign_enum()); 602 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_FOO, message.optional_import_enum()); 603 604 605 // Repeated fields are empty. 606 EXPECT_EQ(0, message.repeated_int32_size()); 607 EXPECT_EQ(0, message.repeated_int64_size()); 608 EXPECT_EQ(0, message.repeated_uint32_size()); 609 EXPECT_EQ(0, message.repeated_uint64_size()); 610 EXPECT_EQ(0, message.repeated_sint32_size()); 611 EXPECT_EQ(0, message.repeated_sint64_size()); 612 EXPECT_EQ(0, message.repeated_fixed32_size()); 613 EXPECT_EQ(0, message.repeated_fixed64_size()); 614 EXPECT_EQ(0, message.repeated_sfixed32_size()); 615 EXPECT_EQ(0, message.repeated_sfixed64_size()); 616 EXPECT_EQ(0, message.repeated_float_size()); 617 EXPECT_EQ(0, message.repeated_double_size()); 618 EXPECT_EQ(0, message.repeated_bool_size()); 619 EXPECT_EQ(0, message.repeated_string_size()); 620 EXPECT_EQ(0, message.repeated_bytes_size()); 621 622 EXPECT_EQ(0, message.repeatedgroup_size()); 623 EXPECT_EQ(0, message.repeated_nested_message_size()); 624 EXPECT_EQ(0, message.repeated_foreign_message_size()); 625 EXPECT_EQ(0, message.repeated_import_message_size()); 626 EXPECT_EQ(0, message.repeated_lazy_message_size()); 627 EXPECT_EQ(0, message.repeated_nested_enum_size()); 628 EXPECT_EQ(0, message.repeated_foreign_enum_size()); 629 EXPECT_EQ(0, message.repeated_import_enum_size()); 630 631 EXPECT_EQ(0, message.repeated_string_piece_size()); 632 EXPECT_EQ(0, message.repeated_cord_size()); 633 634 // has_blah() should also be false for all default fields. 635 EXPECT_FALSE(message.has_default_int32()); 636 EXPECT_FALSE(message.has_default_int64()); 637 EXPECT_FALSE(message.has_default_uint32()); 638 EXPECT_FALSE(message.has_default_uint64()); 639 EXPECT_FALSE(message.has_default_sint32()); 640 EXPECT_FALSE(message.has_default_sint64()); 641 EXPECT_FALSE(message.has_default_fixed32()); 642 EXPECT_FALSE(message.has_default_fixed64()); 643 EXPECT_FALSE(message.has_default_sfixed32()); 644 EXPECT_FALSE(message.has_default_sfixed64()); 645 EXPECT_FALSE(message.has_default_float()); 646 EXPECT_FALSE(message.has_default_double()); 647 EXPECT_FALSE(message.has_default_bool()); 648 EXPECT_FALSE(message.has_default_string()); 649 EXPECT_FALSE(message.has_default_bytes()); 650 651 EXPECT_FALSE(message.has_default_nested_enum()); 652 EXPECT_FALSE(message.has_default_foreign_enum()); 653 EXPECT_FALSE(message.has_default_import_enum()); 654 655 656 // Fields with defaults have their default values (duh). 657 EXPECT_EQ(41, message.default_int32()); 658 EXPECT_EQ(42, message.default_int64()); 659 EXPECT_EQ(43, message.default_uint32()); 660 EXPECT_EQ(44, message.default_uint64()); 661 EXPECT_EQ(-45, message.default_sint32()); 662 EXPECT_EQ(46, message.default_sint64()); 663 EXPECT_EQ(47, message.default_fixed32()); 664 EXPECT_EQ(48, message.default_fixed64()); 665 EXPECT_EQ(49, message.default_sfixed32()); 666 EXPECT_EQ(-50, message.default_sfixed64()); 667 EXPECT_EQ(51.5, message.default_float()); 668 EXPECT_EQ(52e3, message.default_double()); 669 EXPECT_TRUE(message.default_bool()); 670 EXPECT_EQ("hello", message.default_string()); 671 EXPECT_EQ("world", message.default_bytes()); 672 673 EXPECT_EQ(UNITTEST::TestAllTypes::BAR, message.default_nested_enum()); 674 EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.default_foreign_enum()); 675 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, message.default_import_enum()); 676 677 678 EXPECT_FALSE(message.has_oneof_uint32()); 679 EXPECT_FALSE(message.has_oneof_nested_message()); 680 EXPECT_FALSE(message.has_oneof_string()); 681 EXPECT_FALSE(message.has_oneof_bytes()); 682} 683 684// ------------------------------------------------------------------- 685 686inline void TestUtil::ExpectRepeatedFieldsModified( 687 const UNITTEST::TestAllTypes& message) { 688 // ModifyRepeatedFields only sets the second repeated element of each 689 // field. In addition to verifying this, we also verify that the first 690 // element and size were *not* modified. 691 ASSERT_EQ(2, message.repeated_int32_size()); 692 ASSERT_EQ(2, message.repeated_int64_size()); 693 ASSERT_EQ(2, message.repeated_uint32_size()); 694 ASSERT_EQ(2, message.repeated_uint64_size()); 695 ASSERT_EQ(2, message.repeated_sint32_size()); 696 ASSERT_EQ(2, message.repeated_sint64_size()); 697 ASSERT_EQ(2, message.repeated_fixed32_size()); 698 ASSERT_EQ(2, message.repeated_fixed64_size()); 699 ASSERT_EQ(2, message.repeated_sfixed32_size()); 700 ASSERT_EQ(2, message.repeated_sfixed64_size()); 701 ASSERT_EQ(2, message.repeated_float_size()); 702 ASSERT_EQ(2, message.repeated_double_size()); 703 ASSERT_EQ(2, message.repeated_bool_size()); 704 ASSERT_EQ(2, message.repeated_string_size()); 705 ASSERT_EQ(2, message.repeated_bytes_size()); 706 707 ASSERT_EQ(2, message.repeatedgroup_size()); 708 ASSERT_EQ(2, message.repeated_nested_message_size()); 709 ASSERT_EQ(2, message.repeated_foreign_message_size()); 710 ASSERT_EQ(2, message.repeated_import_message_size()); 711 ASSERT_EQ(2, message.repeated_lazy_message_size()); 712 ASSERT_EQ(2, message.repeated_nested_enum_size()); 713 ASSERT_EQ(2, message.repeated_foreign_enum_size()); 714 ASSERT_EQ(2, message.repeated_import_enum_size()); 715 716#ifndef PROTOBUF_TEST_NO_DESCRIPTORS 717 ASSERT_EQ(2, message.repeated_string_piece_size()); 718 ASSERT_EQ(2, message.repeated_cord_size()); 719#endif 720 721 EXPECT_EQ(201, message.repeated_int32(0)); 722 EXPECT_EQ(202, message.repeated_int64(0)); 723 EXPECT_EQ(203, message.repeated_uint32(0)); 724 EXPECT_EQ(204, message.repeated_uint64(0)); 725 EXPECT_EQ(205, message.repeated_sint32(0)); 726 EXPECT_EQ(206, message.repeated_sint64(0)); 727 EXPECT_EQ(207, message.repeated_fixed32(0)); 728 EXPECT_EQ(208, message.repeated_fixed64(0)); 729 EXPECT_EQ(209, message.repeated_sfixed32(0)); 730 EXPECT_EQ(210, message.repeated_sfixed64(0)); 731 EXPECT_EQ(211, message.repeated_float(0)); 732 EXPECT_EQ(212, message.repeated_double(0)); 733 EXPECT_TRUE(message.repeated_bool(0)); 734 EXPECT_EQ("215", message.repeated_string(0)); 735 EXPECT_EQ("216", message.repeated_bytes(0)); 736 737 EXPECT_EQ(217, message.repeatedgroup(0).a()); 738 EXPECT_EQ(218, message.repeated_nested_message(0).bb()); 739 EXPECT_EQ(219, message.repeated_foreign_message(0).c()); 740 EXPECT_EQ(220, message.repeated_import_message(0).d()); 741 EXPECT_EQ(227, message.repeated_lazy_message(0).bb()); 742 743 EXPECT_EQ(UNITTEST::TestAllTypes::BAR, message.repeated_nested_enum(0)); 744 EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.repeated_foreign_enum(0)); 745 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, message.repeated_import_enum(0)); 746 747 748 // Actually verify the second (modified) elements now. 749 EXPECT_EQ(501, message.repeated_int32(1)); 750 EXPECT_EQ(502, message.repeated_int64(1)); 751 EXPECT_EQ(503, message.repeated_uint32(1)); 752 EXPECT_EQ(504, message.repeated_uint64(1)); 753 EXPECT_EQ(505, message.repeated_sint32(1)); 754 EXPECT_EQ(506, message.repeated_sint64(1)); 755 EXPECT_EQ(507, message.repeated_fixed32(1)); 756 EXPECT_EQ(508, message.repeated_fixed64(1)); 757 EXPECT_EQ(509, message.repeated_sfixed32(1)); 758 EXPECT_EQ(510, message.repeated_sfixed64(1)); 759 EXPECT_EQ(511, message.repeated_float(1)); 760 EXPECT_EQ(512, message.repeated_double(1)); 761 EXPECT_TRUE(message.repeated_bool(1)); 762 EXPECT_EQ("515", message.repeated_string(1)); 763 EXPECT_EQ("516", message.repeated_bytes(1)); 764 765 EXPECT_EQ(517, message.repeatedgroup(1).a()); 766 EXPECT_EQ(518, message.repeated_nested_message(1).bb()); 767 EXPECT_EQ(519, message.repeated_foreign_message(1).c()); 768 EXPECT_EQ(520, message.repeated_import_message(1).d()); 769 EXPECT_EQ(527, message.repeated_lazy_message(1).bb()); 770 771 EXPECT_EQ(UNITTEST::TestAllTypes::FOO, message.repeated_nested_enum(1)); 772 EXPECT_EQ(UNITTEST::FOREIGN_FOO, message.repeated_foreign_enum(1)); 773 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_FOO, message.repeated_import_enum(1)); 774 775} 776 777// ------------------------------------------------------------------- 778 779inline void TestUtil::SetPackedFields(UNITTEST::TestPackedTypes* message) { 780 message->add_packed_int32(601); 781 message->add_packed_int64(602); 782 message->add_packed_uint32(603); 783 message->add_packed_uint64(604); 784 message->add_packed_sint32(605); 785 message->add_packed_sint64(606); 786 message->add_packed_fixed32(607); 787 message->add_packed_fixed64(608); 788 message->add_packed_sfixed32(609); 789 message->add_packed_sfixed64(610); 790 message->add_packed_float(611); 791 message->add_packed_double(612); 792 message->add_packed_bool(true); 793 message->add_packed_enum(UNITTEST::FOREIGN_BAR); 794 // add a second one of each field 795 message->add_packed_int32(701); 796 message->add_packed_int64(702); 797 message->add_packed_uint32(703); 798 message->add_packed_uint64(704); 799 message->add_packed_sint32(705); 800 message->add_packed_sint64(706); 801 message->add_packed_fixed32(707); 802 message->add_packed_fixed64(708); 803 message->add_packed_sfixed32(709); 804 message->add_packed_sfixed64(710); 805 message->add_packed_float(711); 806 message->add_packed_double(712); 807 message->add_packed_bool(false); 808 message->add_packed_enum(UNITTEST::FOREIGN_BAZ); 809} 810 811inline void TestUtil::SetUnpackedFields(UNITTEST::TestUnpackedTypes* message) { 812 // The values applied here must match those of SetPackedFields. 813 814 message->add_unpacked_int32(601); 815 message->add_unpacked_int64(602); 816 message->add_unpacked_uint32(603); 817 message->add_unpacked_uint64(604); 818 message->add_unpacked_sint32(605); 819 message->add_unpacked_sint64(606); 820 message->add_unpacked_fixed32(607); 821 message->add_unpacked_fixed64(608); 822 message->add_unpacked_sfixed32(609); 823 message->add_unpacked_sfixed64(610); 824 message->add_unpacked_float(611); 825 message->add_unpacked_double(612); 826 message->add_unpacked_bool(true); 827 message->add_unpacked_enum(UNITTEST::FOREIGN_BAR); 828 // add a second one of each field 829 message->add_unpacked_int32(701); 830 message->add_unpacked_int64(702); 831 message->add_unpacked_uint32(703); 832 message->add_unpacked_uint64(704); 833 message->add_unpacked_sint32(705); 834 message->add_unpacked_sint64(706); 835 message->add_unpacked_fixed32(707); 836 message->add_unpacked_fixed64(708); 837 message->add_unpacked_sfixed32(709); 838 message->add_unpacked_sfixed64(710); 839 message->add_unpacked_float(711); 840 message->add_unpacked_double(712); 841 message->add_unpacked_bool(false); 842 message->add_unpacked_enum(UNITTEST::FOREIGN_BAZ); 843} 844 845// ------------------------------------------------------------------- 846 847inline void TestUtil::ExpectPackedFieldsSet( 848 const UNITTEST::TestPackedTypes& message) { 849 ASSERT_EQ(2, message.packed_int32_size()); 850 ASSERT_EQ(2, message.packed_int64_size()); 851 ASSERT_EQ(2, message.packed_uint32_size()); 852 ASSERT_EQ(2, message.packed_uint64_size()); 853 ASSERT_EQ(2, message.packed_sint32_size()); 854 ASSERT_EQ(2, message.packed_sint64_size()); 855 ASSERT_EQ(2, message.packed_fixed32_size()); 856 ASSERT_EQ(2, message.packed_fixed64_size()); 857 ASSERT_EQ(2, message.packed_sfixed32_size()); 858 ASSERT_EQ(2, message.packed_sfixed64_size()); 859 ASSERT_EQ(2, message.packed_float_size()); 860 ASSERT_EQ(2, message.packed_double_size()); 861 ASSERT_EQ(2, message.packed_bool_size()); 862 ASSERT_EQ(2, message.packed_enum_size()); 863 864 EXPECT_EQ(601, message.packed_int32(0)); 865 EXPECT_EQ(602, message.packed_int64(0)); 866 EXPECT_EQ(603, message.packed_uint32(0)); 867 EXPECT_EQ(604, message.packed_uint64(0)); 868 EXPECT_EQ(605, message.packed_sint32(0)); 869 EXPECT_EQ(606, message.packed_sint64(0)); 870 EXPECT_EQ(607, message.packed_fixed32(0)); 871 EXPECT_EQ(608, message.packed_fixed64(0)); 872 EXPECT_EQ(609, message.packed_sfixed32(0)); 873 EXPECT_EQ(610, message.packed_sfixed64(0)); 874 EXPECT_EQ(611, message.packed_float(0)); 875 EXPECT_EQ(612, message.packed_double(0)); 876 EXPECT_TRUE(message.packed_bool(0)); 877 EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.packed_enum(0)); 878 879 EXPECT_EQ(701, message.packed_int32(1)); 880 EXPECT_EQ(702, message.packed_int64(1)); 881 EXPECT_EQ(703, message.packed_uint32(1)); 882 EXPECT_EQ(704, message.packed_uint64(1)); 883 EXPECT_EQ(705, message.packed_sint32(1)); 884 EXPECT_EQ(706, message.packed_sint64(1)); 885 EXPECT_EQ(707, message.packed_fixed32(1)); 886 EXPECT_EQ(708, message.packed_fixed64(1)); 887 EXPECT_EQ(709, message.packed_sfixed32(1)); 888 EXPECT_EQ(710, message.packed_sfixed64(1)); 889 EXPECT_EQ(711, message.packed_float(1)); 890 EXPECT_EQ(712, message.packed_double(1)); 891 EXPECT_FALSE(message.packed_bool(1)); 892 EXPECT_EQ(UNITTEST::FOREIGN_BAZ, message.packed_enum(1)); 893} 894 895inline void TestUtil::ExpectUnpackedFieldsSet( 896 const UNITTEST::TestUnpackedTypes& message) { 897 // The values expected here must match those of ExpectPackedFieldsSet. 898 899 ASSERT_EQ(2, message.unpacked_int32_size()); 900 ASSERT_EQ(2, message.unpacked_int64_size()); 901 ASSERT_EQ(2, message.unpacked_uint32_size()); 902 ASSERT_EQ(2, message.unpacked_uint64_size()); 903 ASSERT_EQ(2, message.unpacked_sint32_size()); 904 ASSERT_EQ(2, message.unpacked_sint64_size()); 905 ASSERT_EQ(2, message.unpacked_fixed32_size()); 906 ASSERT_EQ(2, message.unpacked_fixed64_size()); 907 ASSERT_EQ(2, message.unpacked_sfixed32_size()); 908 ASSERT_EQ(2, message.unpacked_sfixed64_size()); 909 ASSERT_EQ(2, message.unpacked_float_size()); 910 ASSERT_EQ(2, message.unpacked_double_size()); 911 ASSERT_EQ(2, message.unpacked_bool_size()); 912 ASSERT_EQ(2, message.unpacked_enum_size()); 913 914 EXPECT_EQ(601, message.unpacked_int32(0)); 915 EXPECT_EQ(602, message.unpacked_int64(0)); 916 EXPECT_EQ(603, message.unpacked_uint32(0)); 917 EXPECT_EQ(604, message.unpacked_uint64(0)); 918 EXPECT_EQ(605, message.unpacked_sint32(0)); 919 EXPECT_EQ(606, message.unpacked_sint64(0)); 920 EXPECT_EQ(607, message.unpacked_fixed32(0)); 921 EXPECT_EQ(608, message.unpacked_fixed64(0)); 922 EXPECT_EQ(609, message.unpacked_sfixed32(0)); 923 EXPECT_EQ(610, message.unpacked_sfixed64(0)); 924 EXPECT_EQ(611, message.unpacked_float(0)); 925 EXPECT_EQ(612, message.unpacked_double(0)); 926 EXPECT_TRUE(message.unpacked_bool(0)); 927 EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.unpacked_enum(0)); 928 929 EXPECT_EQ(701, message.unpacked_int32(1)); 930 EXPECT_EQ(702, message.unpacked_int64(1)); 931 EXPECT_EQ(703, message.unpacked_uint32(1)); 932 EXPECT_EQ(704, message.unpacked_uint64(1)); 933 EXPECT_EQ(705, message.unpacked_sint32(1)); 934 EXPECT_EQ(706, message.unpacked_sint64(1)); 935 EXPECT_EQ(707, message.unpacked_fixed32(1)); 936 EXPECT_EQ(708, message.unpacked_fixed64(1)); 937 EXPECT_EQ(709, message.unpacked_sfixed32(1)); 938 EXPECT_EQ(710, message.unpacked_sfixed64(1)); 939 EXPECT_EQ(711, message.unpacked_float(1)); 940 EXPECT_EQ(712, message.unpacked_double(1)); 941 EXPECT_FALSE(message.unpacked_bool(1)); 942 EXPECT_EQ(UNITTEST::FOREIGN_BAZ, message.unpacked_enum(1)); 943} 944 945// =================================================================== 946// Extensions 947// 948// All this code is exactly equivalent to the above code except that it's 949// manipulating extension fields instead of normal ones. 950 951inline void TestUtil::SetAllExtensions(UNITTEST::TestAllExtensions* message) { 952 message->SetExtension(UNITTEST::optional_int32_extension, 101); 953 message->SetExtension(UNITTEST::optional_int64_extension, 102); 954 message->SetExtension(UNITTEST::optional_uint32_extension, 103); 955 message->SetExtension(UNITTEST::optional_uint64_extension, 104); 956 message->SetExtension(UNITTEST::optional_sint32_extension, 105); 957 message->SetExtension(UNITTEST::optional_sint64_extension, 106); 958 message->SetExtension(UNITTEST::optional_fixed32_extension, 107); 959 message->SetExtension(UNITTEST::optional_fixed64_extension, 108); 960 message->SetExtension(UNITTEST::optional_sfixed32_extension, 109); 961 message->SetExtension(UNITTEST::optional_sfixed64_extension, 110); 962 message->SetExtension(UNITTEST::optional_float_extension, 111); 963 message->SetExtension(UNITTEST::optional_double_extension, 112); 964 message->SetExtension(UNITTEST::optional_bool_extension, true); 965 message->SetExtension(UNITTEST::optional_string_extension, "115"); 966 message->SetExtension(UNITTEST::optional_bytes_extension, "116"); 967 968 message->MutableExtension(UNITTEST::optionalgroup_extension)->set_a(117); 969 message->MutableExtension(UNITTEST::optional_nested_message_extension) 970 ->set_bb(118); 971 message->MutableExtension(UNITTEST::optional_foreign_message_extension) 972 ->set_c(119); 973 message->MutableExtension(UNITTEST::optional_import_message_extension) 974 ->set_d(120); 975 976 message->SetExtension(UNITTEST::optional_nested_enum_extension, 977 UNITTEST::TestAllTypes::BAZ); 978 message->SetExtension(UNITTEST::optional_foreign_enum_extension, 979 UNITTEST::FOREIGN_BAZ); 980 message->SetExtension(UNITTEST::optional_import_enum_extension, 981 UNITTEST_IMPORT::IMPORT_BAZ); 982 983 message->SetExtension(UNITTEST::optional_string_piece_extension, "124"); 984 message->SetExtension(UNITTEST::optional_cord_extension, "125"); 985 986 message->MutableExtension(UNITTEST::optional_public_import_message_extension) 987 ->set_e(126); 988 message->MutableExtension(UNITTEST::optional_lazy_message_extension) 989 ->set_bb(127); 990 991 // ----------------------------------------------------------------- 992 993 message->AddExtension(UNITTEST::repeated_int32_extension, 201); 994 message->AddExtension(UNITTEST::repeated_int64_extension, 202); 995 message->AddExtension(UNITTEST::repeated_uint32_extension, 203); 996 message->AddExtension(UNITTEST::repeated_uint64_extension, 204); 997 message->AddExtension(UNITTEST::repeated_sint32_extension, 205); 998 message->AddExtension(UNITTEST::repeated_sint64_extension, 206); 999 message->AddExtension(UNITTEST::repeated_fixed32_extension, 207); 1000 message->AddExtension(UNITTEST::repeated_fixed64_extension, 208); 1001 message->AddExtension(UNITTEST::repeated_sfixed32_extension, 209); 1002 message->AddExtension(UNITTEST::repeated_sfixed64_extension, 210); 1003 message->AddExtension(UNITTEST::repeated_float_extension, 211); 1004 message->AddExtension(UNITTEST::repeated_double_extension, 212); 1005 message->AddExtension(UNITTEST::repeated_bool_extension, true); 1006 message->AddExtension(UNITTEST::repeated_string_extension, "215"); 1007 message->AddExtension(UNITTEST::repeated_bytes_extension, "216"); 1008 1009 message->AddExtension(UNITTEST::repeatedgroup_extension)->set_a(217); 1010 message->AddExtension(UNITTEST::repeated_nested_message_extension) 1011 ->set_bb(218); 1012 message->AddExtension(UNITTEST::repeated_foreign_message_extension) 1013 ->set_c(219); 1014 message->AddExtension(UNITTEST::repeated_import_message_extension) 1015 ->set_d(220); 1016 message->AddExtension(UNITTEST::repeated_lazy_message_extension)->set_bb(227); 1017 1018 message->AddExtension(UNITTEST::repeated_nested_enum_extension, 1019 UNITTEST::TestAllTypes::BAR); 1020 message->AddExtension(UNITTEST::repeated_foreign_enum_extension, 1021 UNITTEST::FOREIGN_BAR); 1022 message->AddExtension(UNITTEST::repeated_import_enum_extension, 1023 UNITTEST_IMPORT::IMPORT_BAR); 1024 1025 message->AddExtension(UNITTEST::repeated_string_piece_extension, "224"); 1026 message->AddExtension(UNITTEST::repeated_cord_extension, "225"); 1027 1028 // Add a second one of each field. 1029 message->AddExtension(UNITTEST::repeated_int32_extension, 301); 1030 message->AddExtension(UNITTEST::repeated_int64_extension, 302); 1031 message->AddExtension(UNITTEST::repeated_uint32_extension, 303); 1032 message->AddExtension(UNITTEST::repeated_uint64_extension, 304); 1033 message->AddExtension(UNITTEST::repeated_sint32_extension, 305); 1034 message->AddExtension(UNITTEST::repeated_sint64_extension, 306); 1035 message->AddExtension(UNITTEST::repeated_fixed32_extension, 307); 1036 message->AddExtension(UNITTEST::repeated_fixed64_extension, 308); 1037 message->AddExtension(UNITTEST::repeated_sfixed32_extension, 309); 1038 message->AddExtension(UNITTEST::repeated_sfixed64_extension, 310); 1039 message->AddExtension(UNITTEST::repeated_float_extension, 311); 1040 message->AddExtension(UNITTEST::repeated_double_extension, 312); 1041 message->AddExtension(UNITTEST::repeated_bool_extension, false); 1042 message->AddExtension(UNITTEST::repeated_string_extension, "315"); 1043 message->AddExtension(UNITTEST::repeated_bytes_extension, "316"); 1044 1045 message->AddExtension(UNITTEST::repeatedgroup_extension)->set_a(317); 1046 message->AddExtension(UNITTEST::repeated_nested_message_extension) 1047 ->set_bb(318); 1048 message->AddExtension(UNITTEST::repeated_foreign_message_extension) 1049 ->set_c(319); 1050 message->AddExtension(UNITTEST::repeated_import_message_extension) 1051 ->set_d(320); 1052 message->AddExtension(UNITTEST::repeated_lazy_message_extension)->set_bb(327); 1053 1054 message->AddExtension(UNITTEST::repeated_nested_enum_extension, 1055 UNITTEST::TestAllTypes::BAZ); 1056 message->AddExtension(UNITTEST::repeated_foreign_enum_extension, 1057 UNITTEST::FOREIGN_BAZ); 1058 message->AddExtension(UNITTEST::repeated_import_enum_extension, 1059 UNITTEST_IMPORT::IMPORT_BAZ); 1060 1061 message->AddExtension(UNITTEST::repeated_string_piece_extension, "324"); 1062 message->AddExtension(UNITTEST::repeated_cord_extension, "325"); 1063 1064 // ----------------------------------------------------------------- 1065 1066 message->SetExtension(UNITTEST::default_int32_extension, 401); 1067 message->SetExtension(UNITTEST::default_int64_extension, 402); 1068 message->SetExtension(UNITTEST::default_uint32_extension, 403); 1069 message->SetExtension(UNITTEST::default_uint64_extension, 404); 1070 message->SetExtension(UNITTEST::default_sint32_extension, 405); 1071 message->SetExtension(UNITTEST::default_sint64_extension, 406); 1072 message->SetExtension(UNITTEST::default_fixed32_extension, 407); 1073 message->SetExtension(UNITTEST::default_fixed64_extension, 408); 1074 message->SetExtension(UNITTEST::default_sfixed32_extension, 409); 1075 message->SetExtension(UNITTEST::default_sfixed64_extension, 410); 1076 message->SetExtension(UNITTEST::default_float_extension, 411); 1077 message->SetExtension(UNITTEST::default_double_extension, 412); 1078 message->SetExtension(UNITTEST::default_bool_extension, false); 1079 message->SetExtension(UNITTEST::default_string_extension, "415"); 1080 message->SetExtension(UNITTEST::default_bytes_extension, "416"); 1081 1082 message->SetExtension(UNITTEST::default_nested_enum_extension, 1083 UNITTEST::TestAllTypes::FOO); 1084 message->SetExtension(UNITTEST::default_foreign_enum_extension, 1085 UNITTEST::FOREIGN_FOO); 1086 message->SetExtension(UNITTEST::default_import_enum_extension, 1087 UNITTEST_IMPORT::IMPORT_FOO); 1088 1089 message->SetExtension(UNITTEST::default_string_piece_extension, "424"); 1090 message->SetExtension(UNITTEST::default_cord_extension, "425"); 1091 1092 SetOneofFields(message); 1093} 1094 1095inline void TestUtil::SetOneofFields(UNITTEST::TestAllExtensions* message) { 1096 message->SetExtension(UNITTEST::oneof_uint32_extension, 601); 1097 message->MutableExtension(UNITTEST::oneof_nested_message_extension) 1098 ->set_bb(602); 1099 message->SetExtension(UNITTEST::oneof_string_extension, "603"); 1100 message->SetExtension(UNITTEST::oneof_bytes_extension, "604"); 1101} 1102 1103// ------------------------------------------------------------------- 1104 1105inline void TestUtil::SetAllFieldsAndExtensions( 1106 UNITTEST::TestFieldOrderings* message) { 1107 GOOGLE_CHECK(message); 1108 message->set_my_int(1); 1109 message->set_my_string("foo"); 1110 message->set_my_float(1.0); 1111 message->SetExtension(UNITTEST::my_extension_int, 23); 1112 message->SetExtension(UNITTEST::my_extension_string, "bar"); 1113} 1114 1115// ------------------------------------------------------------------- 1116 1117inline void TestUtil::ModifyRepeatedExtensions( 1118 UNITTEST::TestAllExtensions* message) { 1119 message->SetExtension(UNITTEST::repeated_int32_extension, 1, 501); 1120 message->SetExtension(UNITTEST::repeated_int64_extension, 1, 502); 1121 message->SetExtension(UNITTEST::repeated_uint32_extension, 1, 503); 1122 message->SetExtension(UNITTEST::repeated_uint64_extension, 1, 504); 1123 message->SetExtension(UNITTEST::repeated_sint32_extension, 1, 505); 1124 message->SetExtension(UNITTEST::repeated_sint64_extension, 1, 506); 1125 message->SetExtension(UNITTEST::repeated_fixed32_extension, 1, 507); 1126 message->SetExtension(UNITTEST::repeated_fixed64_extension, 1, 508); 1127 message->SetExtension(UNITTEST::repeated_sfixed32_extension, 1, 509); 1128 message->SetExtension(UNITTEST::repeated_sfixed64_extension, 1, 510); 1129 message->SetExtension(UNITTEST::repeated_float_extension, 1, 511); 1130 message->SetExtension(UNITTEST::repeated_double_extension, 1, 512); 1131 message->SetExtension(UNITTEST::repeated_bool_extension, 1, true); 1132 message->SetExtension(UNITTEST::repeated_string_extension, 1, "515"); 1133 message->SetExtension(UNITTEST::repeated_bytes_extension, 1, "516"); 1134 1135 message->MutableExtension(UNITTEST::repeatedgroup_extension, 1)->set_a(517); 1136 message->MutableExtension(UNITTEST::repeated_nested_message_extension, 1) 1137 ->set_bb(518); 1138 message->MutableExtension(UNITTEST::repeated_foreign_message_extension, 1) 1139 ->set_c(519); 1140 message->MutableExtension(UNITTEST::repeated_import_message_extension, 1) 1141 ->set_d(520); 1142 message->MutableExtension(UNITTEST::repeated_lazy_message_extension, 1) 1143 ->set_bb(527); 1144 1145 message->SetExtension(UNITTEST::repeated_nested_enum_extension, 1, 1146 UNITTEST::TestAllTypes::FOO); 1147 message->SetExtension(UNITTEST::repeated_foreign_enum_extension, 1, 1148 UNITTEST::FOREIGN_FOO); 1149 message->SetExtension(UNITTEST::repeated_import_enum_extension, 1, 1150 UNITTEST_IMPORT::IMPORT_FOO); 1151 1152 message->SetExtension(UNITTEST::repeated_string_piece_extension, 1, "524"); 1153 message->SetExtension(UNITTEST::repeated_cord_extension, 1, "525"); 1154} 1155 1156// ------------------------------------------------------------------- 1157 1158inline void TestUtil::ExpectAllExtensionsSet( 1159 const UNITTEST::TestAllExtensions& message) { 1160 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_int32_extension)); 1161 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_int64_extension)); 1162 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_uint32_extension)); 1163 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_uint64_extension)); 1164 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_sint32_extension)); 1165 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_sint64_extension)); 1166 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_fixed32_extension)); 1167 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_fixed64_extension)); 1168 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_sfixed32_extension)); 1169 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_sfixed64_extension)); 1170 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_float_extension)); 1171 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_double_extension)); 1172 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_bool_extension)); 1173 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_string_extension)); 1174 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_bytes_extension)); 1175 1176 EXPECT_TRUE(message.HasExtension(UNITTEST::optionalgroup_extension)); 1177 EXPECT_TRUE( 1178 message.HasExtension(UNITTEST::optional_nested_message_extension)); 1179 EXPECT_TRUE( 1180 message.HasExtension(UNITTEST::optional_foreign_message_extension)); 1181 EXPECT_TRUE( 1182 message.HasExtension(UNITTEST::optional_import_message_extension)); 1183 EXPECT_TRUE( 1184 message.HasExtension(UNITTEST::optional_public_import_message_extension)); 1185 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_lazy_message_extension)); 1186 1187 EXPECT_TRUE(message.GetExtension(UNITTEST::optionalgroup_extension).has_a()); 1188 EXPECT_TRUE(message.GetExtension(UNITTEST::optional_nested_message_extension) 1189 .has_bb()); 1190 EXPECT_TRUE(message.GetExtension(UNITTEST::optional_foreign_message_extension) 1191 .has_c()); 1192 EXPECT_TRUE(message.GetExtension(UNITTEST::optional_import_message_extension) 1193 .has_d()); 1194 EXPECT_TRUE( 1195 message.GetExtension(UNITTEST::optional_public_import_message_extension) 1196 .has_e()); 1197 EXPECT_TRUE( 1198 message.GetExtension(UNITTEST::optional_lazy_message_extension).has_bb()); 1199 1200 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_nested_enum_extension)); 1201 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_foreign_enum_extension)); 1202 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_import_enum_extension)); 1203 1204 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_string_piece_extension)); 1205 EXPECT_TRUE(message.HasExtension(UNITTEST::optional_cord_extension)); 1206 1207 EXPECT_EQ(101, message.GetExtension(UNITTEST::optional_int32_extension)); 1208 EXPECT_EQ(102, message.GetExtension(UNITTEST::optional_int64_extension)); 1209 EXPECT_EQ(103, message.GetExtension(UNITTEST::optional_uint32_extension)); 1210 EXPECT_EQ(104, message.GetExtension(UNITTEST::optional_uint64_extension)); 1211 EXPECT_EQ(105, message.GetExtension(UNITTEST::optional_sint32_extension)); 1212 EXPECT_EQ(106, message.GetExtension(UNITTEST::optional_sint64_extension)); 1213 EXPECT_EQ(107, message.GetExtension(UNITTEST::optional_fixed32_extension)); 1214 EXPECT_EQ(108, message.GetExtension(UNITTEST::optional_fixed64_extension)); 1215 EXPECT_EQ(109, message.GetExtension(UNITTEST::optional_sfixed32_extension)); 1216 EXPECT_EQ(110, message.GetExtension(UNITTEST::optional_sfixed64_extension)); 1217 EXPECT_EQ(111, message.GetExtension(UNITTEST::optional_float_extension)); 1218 EXPECT_EQ(112, message.GetExtension(UNITTEST::optional_double_extension)); 1219 EXPECT_TRUE(message.GetExtension(UNITTEST::optional_bool_extension)); 1220 EXPECT_EQ("115", message.GetExtension(UNITTEST::optional_string_extension)); 1221 EXPECT_EQ("116", message.GetExtension(UNITTEST::optional_bytes_extension)); 1222 1223 EXPECT_EQ(117, message.GetExtension(UNITTEST::optionalgroup_extension).a()); 1224 EXPECT_EQ( 1225 118, 1226 message.GetExtension(UNITTEST::optional_nested_message_extension).bb()); 1227 EXPECT_EQ( 1228 119, 1229 message.GetExtension(UNITTEST::optional_foreign_message_extension).c()); 1230 EXPECT_EQ( 1231 120, 1232 message.GetExtension(UNITTEST::optional_import_message_extension).d()); 1233 1234 EXPECT_EQ(UNITTEST::TestAllTypes::BAZ, 1235 message.GetExtension(UNITTEST::optional_nested_enum_extension)); 1236 EXPECT_EQ(UNITTEST::FOREIGN_BAZ, 1237 message.GetExtension(UNITTEST::optional_foreign_enum_extension)); 1238 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAZ, 1239 message.GetExtension(UNITTEST::optional_import_enum_extension)); 1240 1241 EXPECT_EQ("124", 1242 message.GetExtension(UNITTEST::optional_string_piece_extension)); 1243 EXPECT_EQ("125", message.GetExtension(UNITTEST::optional_cord_extension)); 1244 EXPECT_EQ( 1245 126, 1246 message.GetExtension(UNITTEST::optional_public_import_message_extension) 1247 .e()); 1248 EXPECT_EQ( 1249 127, 1250 message.GetExtension(UNITTEST::optional_lazy_message_extension).bb()); 1251 1252 // ----------------------------------------------------------------- 1253 1254 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_int32_extension)); 1255 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_int64_extension)); 1256 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_uint32_extension)); 1257 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_uint64_extension)); 1258 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sint32_extension)); 1259 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sint64_extension)); 1260 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_fixed32_extension)); 1261 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_fixed64_extension)); 1262 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sfixed32_extension)); 1263 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sfixed64_extension)); 1264 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_float_extension)); 1265 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_double_extension)); 1266 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_bool_extension)); 1267 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_string_extension)); 1268 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_bytes_extension)); 1269 1270 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeatedgroup_extension)); 1271 ASSERT_EQ(2, 1272 message.ExtensionSize(UNITTEST::repeated_nested_message_extension)); 1273 ASSERT_EQ( 1274 2, message.ExtensionSize(UNITTEST::repeated_foreign_message_extension)); 1275 ASSERT_EQ(2, 1276 message.ExtensionSize(UNITTEST::repeated_import_message_extension)); 1277 ASSERT_EQ(2, 1278 message.ExtensionSize(UNITTEST::repeated_lazy_message_extension)); 1279 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_nested_enum_extension)); 1280 ASSERT_EQ(2, 1281 message.ExtensionSize(UNITTEST::repeated_foreign_enum_extension)); 1282 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_import_enum_extension)); 1283 1284 ASSERT_EQ(2, 1285 message.ExtensionSize(UNITTEST::repeated_string_piece_extension)); 1286 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_cord_extension)); 1287 1288 EXPECT_EQ(201, message.GetExtension(UNITTEST::repeated_int32_extension, 0)); 1289 EXPECT_EQ(202, message.GetExtension(UNITTEST::repeated_int64_extension, 0)); 1290 EXPECT_EQ(203, message.GetExtension(UNITTEST::repeated_uint32_extension, 0)); 1291 EXPECT_EQ(204, message.GetExtension(UNITTEST::repeated_uint64_extension, 0)); 1292 EXPECT_EQ(205, message.GetExtension(UNITTEST::repeated_sint32_extension, 0)); 1293 EXPECT_EQ(206, message.GetExtension(UNITTEST::repeated_sint64_extension, 0)); 1294 EXPECT_EQ(207, message.GetExtension(UNITTEST::repeated_fixed32_extension, 0)); 1295 EXPECT_EQ(208, message.GetExtension(UNITTEST::repeated_fixed64_extension, 0)); 1296 EXPECT_EQ(209, 1297 message.GetExtension(UNITTEST::repeated_sfixed32_extension, 0)); 1298 EXPECT_EQ(210, 1299 message.GetExtension(UNITTEST::repeated_sfixed64_extension, 0)); 1300 EXPECT_EQ(211, message.GetExtension(UNITTEST::repeated_float_extension, 0)); 1301 EXPECT_EQ(212, message.GetExtension(UNITTEST::repeated_double_extension, 0)); 1302 EXPECT_TRUE(message.GetExtension(UNITTEST::repeated_bool_extension, 0)); 1303 EXPECT_EQ("215", 1304 message.GetExtension(UNITTEST::repeated_string_extension, 0)); 1305 EXPECT_EQ("216", message.GetExtension(UNITTEST::repeated_bytes_extension, 0)); 1306 1307 EXPECT_EQ(217, 1308 message.GetExtension(UNITTEST::repeatedgroup_extension, 0).a()); 1309 EXPECT_EQ(218, 1310 message.GetExtension(UNITTEST::repeated_nested_message_extension, 0) 1311 .bb()); 1312 EXPECT_EQ( 1313 219, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 0) 1314 .c()); 1315 EXPECT_EQ( 1316 220, 1317 message.GetExtension(UNITTEST::repeated_import_message_extension, 0).d()); 1318 EXPECT_EQ( 1319 227, 1320 message.GetExtension(UNITTEST::repeated_lazy_message_extension, 0).bb()); 1321 1322 EXPECT_EQ(UNITTEST::TestAllTypes::BAR, 1323 message.GetExtension(UNITTEST::repeated_nested_enum_extension, 0)); 1324 EXPECT_EQ(UNITTEST::FOREIGN_BAR, 1325 message.GetExtension(UNITTEST::repeated_foreign_enum_extension, 0)); 1326 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, 1327 message.GetExtension(UNITTEST::repeated_import_enum_extension, 0)); 1328 1329 EXPECT_EQ("224", 1330 message.GetExtension(UNITTEST::repeated_string_piece_extension, 0)); 1331 EXPECT_EQ("225", message.GetExtension(UNITTEST::repeated_cord_extension, 0)); 1332 1333 EXPECT_EQ(301, message.GetExtension(UNITTEST::repeated_int32_extension, 1)); 1334 EXPECT_EQ(302, message.GetExtension(UNITTEST::repeated_int64_extension, 1)); 1335 EXPECT_EQ(303, message.GetExtension(UNITTEST::repeated_uint32_extension, 1)); 1336 EXPECT_EQ(304, message.GetExtension(UNITTEST::repeated_uint64_extension, 1)); 1337 EXPECT_EQ(305, message.GetExtension(UNITTEST::repeated_sint32_extension, 1)); 1338 EXPECT_EQ(306, message.GetExtension(UNITTEST::repeated_sint64_extension, 1)); 1339 EXPECT_EQ(307, message.GetExtension(UNITTEST::repeated_fixed32_extension, 1)); 1340 EXPECT_EQ(308, message.GetExtension(UNITTEST::repeated_fixed64_extension, 1)); 1341 EXPECT_EQ(309, 1342 message.GetExtension(UNITTEST::repeated_sfixed32_extension, 1)); 1343 EXPECT_EQ(310, 1344 message.GetExtension(UNITTEST::repeated_sfixed64_extension, 1)); 1345 EXPECT_EQ(311, message.GetExtension(UNITTEST::repeated_float_extension, 1)); 1346 EXPECT_EQ(312, message.GetExtension(UNITTEST::repeated_double_extension, 1)); 1347 EXPECT_FALSE(message.GetExtension(UNITTEST::repeated_bool_extension, 1)); 1348 EXPECT_EQ("315", 1349 message.GetExtension(UNITTEST::repeated_string_extension, 1)); 1350 EXPECT_EQ("316", message.GetExtension(UNITTEST::repeated_bytes_extension, 1)); 1351 1352 EXPECT_EQ(317, 1353 message.GetExtension(UNITTEST::repeatedgroup_extension, 1).a()); 1354 EXPECT_EQ(318, 1355 message.GetExtension(UNITTEST::repeated_nested_message_extension, 1) 1356 .bb()); 1357 EXPECT_EQ( 1358 319, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 1) 1359 .c()); 1360 EXPECT_EQ( 1361 320, 1362 message.GetExtension(UNITTEST::repeated_import_message_extension, 1).d()); 1363 EXPECT_EQ( 1364 327, 1365 message.GetExtension(UNITTEST::repeated_lazy_message_extension, 1).bb()); 1366 1367 EXPECT_EQ(UNITTEST::TestAllTypes::BAZ, 1368 message.GetExtension(UNITTEST::repeated_nested_enum_extension, 1)); 1369 EXPECT_EQ(UNITTEST::FOREIGN_BAZ, 1370 message.GetExtension(UNITTEST::repeated_foreign_enum_extension, 1)); 1371 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAZ, 1372 message.GetExtension(UNITTEST::repeated_import_enum_extension, 1)); 1373 1374 EXPECT_EQ("324", 1375 message.GetExtension(UNITTEST::repeated_string_piece_extension, 1)); 1376 EXPECT_EQ("325", message.GetExtension(UNITTEST::repeated_cord_extension, 1)); 1377 1378 // ----------------------------------------------------------------- 1379 1380 EXPECT_TRUE(message.HasExtension(UNITTEST::default_int32_extension)); 1381 EXPECT_TRUE(message.HasExtension(UNITTEST::default_int64_extension)); 1382 EXPECT_TRUE(message.HasExtension(UNITTEST::default_uint32_extension)); 1383 EXPECT_TRUE(message.HasExtension(UNITTEST::default_uint64_extension)); 1384 EXPECT_TRUE(message.HasExtension(UNITTEST::default_sint32_extension)); 1385 EXPECT_TRUE(message.HasExtension(UNITTEST::default_sint64_extension)); 1386 EXPECT_TRUE(message.HasExtension(UNITTEST::default_fixed32_extension)); 1387 EXPECT_TRUE(message.HasExtension(UNITTEST::default_fixed64_extension)); 1388 EXPECT_TRUE(message.HasExtension(UNITTEST::default_sfixed32_extension)); 1389 EXPECT_TRUE(message.HasExtension(UNITTEST::default_sfixed64_extension)); 1390 EXPECT_TRUE(message.HasExtension(UNITTEST::default_float_extension)); 1391 EXPECT_TRUE(message.HasExtension(UNITTEST::default_double_extension)); 1392 EXPECT_TRUE(message.HasExtension(UNITTEST::default_bool_extension)); 1393 EXPECT_TRUE(message.HasExtension(UNITTEST::default_string_extension)); 1394 EXPECT_TRUE(message.HasExtension(UNITTEST::default_bytes_extension)); 1395 1396 EXPECT_TRUE(message.HasExtension(UNITTEST::default_nested_enum_extension)); 1397 EXPECT_TRUE(message.HasExtension(UNITTEST::default_foreign_enum_extension)); 1398 EXPECT_TRUE(message.HasExtension(UNITTEST::default_import_enum_extension)); 1399 1400 EXPECT_TRUE(message.HasExtension(UNITTEST::default_string_piece_extension)); 1401 EXPECT_TRUE(message.HasExtension(UNITTEST::default_cord_extension)); 1402 1403 EXPECT_EQ(401, message.GetExtension(UNITTEST::default_int32_extension)); 1404 EXPECT_EQ(402, message.GetExtension(UNITTEST::default_int64_extension)); 1405 EXPECT_EQ(403, message.GetExtension(UNITTEST::default_uint32_extension)); 1406 EXPECT_EQ(404, message.GetExtension(UNITTEST::default_uint64_extension)); 1407 EXPECT_EQ(405, message.GetExtension(UNITTEST::default_sint32_extension)); 1408 EXPECT_EQ(406, message.GetExtension(UNITTEST::default_sint64_extension)); 1409 EXPECT_EQ(407, message.GetExtension(UNITTEST::default_fixed32_extension)); 1410 EXPECT_EQ(408, message.GetExtension(UNITTEST::default_fixed64_extension)); 1411 EXPECT_EQ(409, message.GetExtension(UNITTEST::default_sfixed32_extension)); 1412 EXPECT_EQ(410, message.GetExtension(UNITTEST::default_sfixed64_extension)); 1413 EXPECT_EQ(411, message.GetExtension(UNITTEST::default_float_extension)); 1414 EXPECT_EQ(412, message.GetExtension(UNITTEST::default_double_extension)); 1415 EXPECT_FALSE(message.GetExtension(UNITTEST::default_bool_extension)); 1416 EXPECT_EQ("415", message.GetExtension(UNITTEST::default_string_extension)); 1417 EXPECT_EQ("416", message.GetExtension(UNITTEST::default_bytes_extension)); 1418 1419 EXPECT_EQ(UNITTEST::TestAllTypes::FOO, 1420 message.GetExtension(UNITTEST::default_nested_enum_extension)); 1421 EXPECT_EQ(UNITTEST::FOREIGN_FOO, 1422 message.GetExtension(UNITTEST::default_foreign_enum_extension)); 1423 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_FOO, 1424 message.GetExtension(UNITTEST::default_import_enum_extension)); 1425 1426 EXPECT_EQ("424", 1427 message.GetExtension(UNITTEST::default_string_piece_extension)); 1428 EXPECT_EQ("425", message.GetExtension(UNITTEST::default_cord_extension)); 1429 1430 EXPECT_TRUE(message.HasExtension(UNITTEST::oneof_uint32_extension)); 1431 EXPECT_TRUE( 1432 message.GetExtension(UNITTEST::oneof_nested_message_extension).has_bb()); 1433 EXPECT_TRUE(message.HasExtension(UNITTEST::oneof_string_extension)); 1434 EXPECT_TRUE(message.HasExtension(UNITTEST::oneof_bytes_extension)); 1435 1436 EXPECT_EQ(601, message.GetExtension(UNITTEST::oneof_uint32_extension)); 1437 EXPECT_EQ( 1438 602, message.GetExtension(UNITTEST::oneof_nested_message_extension).bb()); 1439 EXPECT_EQ("603", message.GetExtension(UNITTEST::oneof_string_extension)); 1440 EXPECT_EQ("604", message.GetExtension(UNITTEST::oneof_bytes_extension)); 1441} 1442 1443// ------------------------------------------------------------------- 1444 1445inline void TestUtil::ExpectExtensionsClear( 1446 const UNITTEST::TestAllExtensions& message) { 1447 std::string serialized; 1448 ASSERT_TRUE(message.SerializeToString(&serialized)); 1449 EXPECT_EQ("", serialized); 1450 EXPECT_EQ(0, message.ByteSizeLong()); 1451 1452 // has_blah() should initially be false for all optional fields. 1453 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_int32_extension)); 1454 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_int64_extension)); 1455 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_uint32_extension)); 1456 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_uint64_extension)); 1457 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_sint32_extension)); 1458 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_sint64_extension)); 1459 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_fixed32_extension)); 1460 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_fixed64_extension)); 1461 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_sfixed32_extension)); 1462 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_sfixed64_extension)); 1463 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_float_extension)); 1464 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_double_extension)); 1465 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_bool_extension)); 1466 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_string_extension)); 1467 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_bytes_extension)); 1468 1469 EXPECT_FALSE(message.HasExtension(UNITTEST::optionalgroup_extension)); 1470 EXPECT_FALSE( 1471 message.HasExtension(UNITTEST::optional_nested_message_extension)); 1472 EXPECT_FALSE( 1473 message.HasExtension(UNITTEST::optional_foreign_message_extension)); 1474 EXPECT_FALSE( 1475 message.HasExtension(UNITTEST::optional_import_message_extension)); 1476 EXPECT_FALSE( 1477 message.HasExtension(UNITTEST::optional_public_import_message_extension)); 1478 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_lazy_message_extension)); 1479 1480 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_nested_enum_extension)); 1481 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_foreign_enum_extension)); 1482 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_import_enum_extension)); 1483 1484 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_string_piece_extension)); 1485 EXPECT_FALSE(message.HasExtension(UNITTEST::optional_cord_extension)); 1486 1487 // Optional fields without defaults are set to zero or something like it. 1488 EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_int32_extension)); 1489 EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_int64_extension)); 1490 EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_uint32_extension)); 1491 EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_uint64_extension)); 1492 EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_sint32_extension)); 1493 EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_sint64_extension)); 1494 EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_fixed32_extension)); 1495 EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_fixed64_extension)); 1496 EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_sfixed32_extension)); 1497 EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_sfixed64_extension)); 1498 EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_float_extension)); 1499 EXPECT_EQ(0, message.GetExtension(UNITTEST::optional_double_extension)); 1500 EXPECT_FALSE(message.GetExtension(UNITTEST::optional_bool_extension)); 1501 EXPECT_EQ("", message.GetExtension(UNITTEST::optional_string_extension)); 1502 EXPECT_EQ("", message.GetExtension(UNITTEST::optional_bytes_extension)); 1503 1504 // Embedded messages should also be clear. 1505 EXPECT_FALSE(message.GetExtension(UNITTEST::optionalgroup_extension).has_a()); 1506 EXPECT_FALSE(message.GetExtension(UNITTEST::optional_nested_message_extension) 1507 .has_bb()); 1508 EXPECT_FALSE( 1509 message.GetExtension(UNITTEST::optional_foreign_message_extension) 1510 .has_c()); 1511 EXPECT_FALSE(message.GetExtension(UNITTEST::optional_import_message_extension) 1512 .has_d()); 1513 EXPECT_FALSE( 1514 message.GetExtension(UNITTEST::optional_public_import_message_extension) 1515 .has_e()); 1516 EXPECT_FALSE( 1517 message.GetExtension(UNITTEST::optional_lazy_message_extension).has_bb()); 1518 1519 EXPECT_EQ(0, message.GetExtension(UNITTEST::optionalgroup_extension).a()); 1520 EXPECT_EQ( 1521 0, 1522 message.GetExtension(UNITTEST::optional_nested_message_extension).bb()); 1523 EXPECT_EQ( 1524 0, 1525 message.GetExtension(UNITTEST::optional_foreign_message_extension).c()); 1526 EXPECT_EQ( 1527 0, message.GetExtension(UNITTEST::optional_import_message_extension).d()); 1528 EXPECT_EQ( 1529 0, 1530 message.GetExtension(UNITTEST::optional_public_import_message_extension) 1531 .e()); 1532 EXPECT_EQ( 1533 0, message.GetExtension(UNITTEST::optional_lazy_message_extension).bb()); 1534 1535 // Enums without defaults are set to the first value in the enum. 1536 EXPECT_EQ(UNITTEST::TestAllTypes::FOO, 1537 message.GetExtension(UNITTEST::optional_nested_enum_extension)); 1538 EXPECT_EQ(UNITTEST::FOREIGN_FOO, 1539 message.GetExtension(UNITTEST::optional_foreign_enum_extension)); 1540 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_FOO, 1541 message.GetExtension(UNITTEST::optional_import_enum_extension)); 1542 1543 EXPECT_EQ("", 1544 message.GetExtension(UNITTEST::optional_string_piece_extension)); 1545 EXPECT_EQ("", message.GetExtension(UNITTEST::optional_cord_extension)); 1546 1547 // Repeated fields are empty. 1548 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_int32_extension)); 1549 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_int64_extension)); 1550 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_uint32_extension)); 1551 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_uint64_extension)); 1552 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_sint32_extension)); 1553 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_sint64_extension)); 1554 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_fixed32_extension)); 1555 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_fixed64_extension)); 1556 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_sfixed32_extension)); 1557 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_sfixed64_extension)); 1558 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_float_extension)); 1559 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_double_extension)); 1560 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_bool_extension)); 1561 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_string_extension)); 1562 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_bytes_extension)); 1563 1564 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeatedgroup_extension)); 1565 EXPECT_EQ(0, 1566 message.ExtensionSize(UNITTEST::repeated_nested_message_extension)); 1567 EXPECT_EQ( 1568 0, message.ExtensionSize(UNITTEST::repeated_foreign_message_extension)); 1569 EXPECT_EQ(0, 1570 message.ExtensionSize(UNITTEST::repeated_import_message_extension)); 1571 EXPECT_EQ(0, 1572 message.ExtensionSize(UNITTEST::repeated_lazy_message_extension)); 1573 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_nested_enum_extension)); 1574 EXPECT_EQ(0, 1575 message.ExtensionSize(UNITTEST::repeated_foreign_enum_extension)); 1576 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_import_enum_extension)); 1577 1578 EXPECT_EQ(0, 1579 message.ExtensionSize(UNITTEST::repeated_string_piece_extension)); 1580 EXPECT_EQ(0, message.ExtensionSize(UNITTEST::repeated_cord_extension)); 1581 1582 // has_blah() should also be false for all default fields. 1583 EXPECT_FALSE(message.HasExtension(UNITTEST::default_int32_extension)); 1584 EXPECT_FALSE(message.HasExtension(UNITTEST::default_int64_extension)); 1585 EXPECT_FALSE(message.HasExtension(UNITTEST::default_uint32_extension)); 1586 EXPECT_FALSE(message.HasExtension(UNITTEST::default_uint64_extension)); 1587 EXPECT_FALSE(message.HasExtension(UNITTEST::default_sint32_extension)); 1588 EXPECT_FALSE(message.HasExtension(UNITTEST::default_sint64_extension)); 1589 EXPECT_FALSE(message.HasExtension(UNITTEST::default_fixed32_extension)); 1590 EXPECT_FALSE(message.HasExtension(UNITTEST::default_fixed64_extension)); 1591 EXPECT_FALSE(message.HasExtension(UNITTEST::default_sfixed32_extension)); 1592 EXPECT_FALSE(message.HasExtension(UNITTEST::default_sfixed64_extension)); 1593 EXPECT_FALSE(message.HasExtension(UNITTEST::default_float_extension)); 1594 EXPECT_FALSE(message.HasExtension(UNITTEST::default_double_extension)); 1595 EXPECT_FALSE(message.HasExtension(UNITTEST::default_bool_extension)); 1596 EXPECT_FALSE(message.HasExtension(UNITTEST::default_string_extension)); 1597 EXPECT_FALSE(message.HasExtension(UNITTEST::default_bytes_extension)); 1598 1599 EXPECT_FALSE(message.HasExtension(UNITTEST::default_nested_enum_extension)); 1600 EXPECT_FALSE(message.HasExtension(UNITTEST::default_foreign_enum_extension)); 1601 EXPECT_FALSE(message.HasExtension(UNITTEST::default_import_enum_extension)); 1602 1603 EXPECT_FALSE(message.HasExtension(UNITTEST::default_string_piece_extension)); 1604 EXPECT_FALSE(message.HasExtension(UNITTEST::default_cord_extension)); 1605 1606 // Fields with defaults have their default values (duh). 1607 EXPECT_EQ(41, message.GetExtension(UNITTEST::default_int32_extension)); 1608 EXPECT_EQ(42, message.GetExtension(UNITTEST::default_int64_extension)); 1609 EXPECT_EQ(43, message.GetExtension(UNITTEST::default_uint32_extension)); 1610 EXPECT_EQ(44, message.GetExtension(UNITTEST::default_uint64_extension)); 1611 EXPECT_EQ(-45, message.GetExtension(UNITTEST::default_sint32_extension)); 1612 EXPECT_EQ(46, message.GetExtension(UNITTEST::default_sint64_extension)); 1613 EXPECT_EQ(47, message.GetExtension(UNITTEST::default_fixed32_extension)); 1614 EXPECT_EQ(48, message.GetExtension(UNITTEST::default_fixed64_extension)); 1615 EXPECT_EQ(49, message.GetExtension(UNITTEST::default_sfixed32_extension)); 1616 EXPECT_EQ(-50, message.GetExtension(UNITTEST::default_sfixed64_extension)); 1617 EXPECT_EQ(51.5, message.GetExtension(UNITTEST::default_float_extension)); 1618 EXPECT_EQ(52e3, message.GetExtension(UNITTEST::default_double_extension)); 1619 EXPECT_TRUE(message.GetExtension(UNITTEST::default_bool_extension)); 1620 EXPECT_EQ("hello", message.GetExtension(UNITTEST::default_string_extension)); 1621 EXPECT_EQ("world", message.GetExtension(UNITTEST::default_bytes_extension)); 1622 1623 EXPECT_EQ(UNITTEST::TestAllTypes::BAR, 1624 message.GetExtension(UNITTEST::default_nested_enum_extension)); 1625 EXPECT_EQ(UNITTEST::FOREIGN_BAR, 1626 message.GetExtension(UNITTEST::default_foreign_enum_extension)); 1627 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, 1628 message.GetExtension(UNITTEST::default_import_enum_extension)); 1629 1630 EXPECT_EQ("abc", 1631 message.GetExtension(UNITTEST::default_string_piece_extension)); 1632 EXPECT_EQ("123", message.GetExtension(UNITTEST::default_cord_extension)); 1633 1634 EXPECT_FALSE(message.HasExtension(UNITTEST::oneof_uint32_extension)); 1635 EXPECT_FALSE( 1636 message.GetExtension(UNITTEST::oneof_nested_message_extension).has_bb()); 1637 EXPECT_FALSE(message.HasExtension(UNITTEST::oneof_string_extension)); 1638 EXPECT_FALSE(message.HasExtension(UNITTEST::oneof_bytes_extension)); 1639} 1640 1641// ------------------------------------------------------------------- 1642 1643inline void TestUtil::ExpectRepeatedExtensionsModified( 1644 const UNITTEST::TestAllExtensions& message) { 1645 // ModifyRepeatedFields only sets the second repeated element of each 1646 // field. In addition to verifying this, we also verify that the first 1647 // element and size were *not* modified. 1648 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_int32_extension)); 1649 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_int64_extension)); 1650 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_uint32_extension)); 1651 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_uint64_extension)); 1652 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sint32_extension)); 1653 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sint64_extension)); 1654 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_fixed32_extension)); 1655 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_fixed64_extension)); 1656 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sfixed32_extension)); 1657 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sfixed64_extension)); 1658 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_float_extension)); 1659 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_double_extension)); 1660 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_bool_extension)); 1661 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_string_extension)); 1662 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_bytes_extension)); 1663 1664 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeatedgroup_extension)); 1665 ASSERT_EQ(2, 1666 message.ExtensionSize(UNITTEST::repeated_nested_message_extension)); 1667 ASSERT_EQ( 1668 2, message.ExtensionSize(UNITTEST::repeated_foreign_message_extension)); 1669 ASSERT_EQ(2, 1670 message.ExtensionSize(UNITTEST::repeated_import_message_extension)); 1671 ASSERT_EQ(2, 1672 message.ExtensionSize(UNITTEST::repeated_lazy_message_extension)); 1673 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_nested_enum_extension)); 1674 ASSERT_EQ(2, 1675 message.ExtensionSize(UNITTEST::repeated_foreign_enum_extension)); 1676 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_import_enum_extension)); 1677 1678 ASSERT_EQ(2, 1679 message.ExtensionSize(UNITTEST::repeated_string_piece_extension)); 1680 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_cord_extension)); 1681 1682 EXPECT_EQ(201, message.GetExtension(UNITTEST::repeated_int32_extension, 0)); 1683 EXPECT_EQ(202, message.GetExtension(UNITTEST::repeated_int64_extension, 0)); 1684 EXPECT_EQ(203, message.GetExtension(UNITTEST::repeated_uint32_extension, 0)); 1685 EXPECT_EQ(204, message.GetExtension(UNITTEST::repeated_uint64_extension, 0)); 1686 EXPECT_EQ(205, message.GetExtension(UNITTEST::repeated_sint32_extension, 0)); 1687 EXPECT_EQ(206, message.GetExtension(UNITTEST::repeated_sint64_extension, 0)); 1688 EXPECT_EQ(207, message.GetExtension(UNITTEST::repeated_fixed32_extension, 0)); 1689 EXPECT_EQ(208, message.GetExtension(UNITTEST::repeated_fixed64_extension, 0)); 1690 EXPECT_EQ(209, 1691 message.GetExtension(UNITTEST::repeated_sfixed32_extension, 0)); 1692 EXPECT_EQ(210, 1693 message.GetExtension(UNITTEST::repeated_sfixed64_extension, 0)); 1694 EXPECT_EQ(211, message.GetExtension(UNITTEST::repeated_float_extension, 0)); 1695 EXPECT_EQ(212, message.GetExtension(UNITTEST::repeated_double_extension, 0)); 1696 EXPECT_TRUE(message.GetExtension(UNITTEST::repeated_bool_extension, 0)); 1697 EXPECT_EQ("215", 1698 message.GetExtension(UNITTEST::repeated_string_extension, 0)); 1699 EXPECT_EQ("216", message.GetExtension(UNITTEST::repeated_bytes_extension, 0)); 1700 1701 EXPECT_EQ(217, 1702 message.GetExtension(UNITTEST::repeatedgroup_extension, 0).a()); 1703 EXPECT_EQ(218, 1704 message.GetExtension(UNITTEST::repeated_nested_message_extension, 0) 1705 .bb()); 1706 EXPECT_EQ( 1707 219, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 0) 1708 .c()); 1709 EXPECT_EQ( 1710 220, 1711 message.GetExtension(UNITTEST::repeated_import_message_extension, 0).d()); 1712 EXPECT_EQ( 1713 227, 1714 message.GetExtension(UNITTEST::repeated_lazy_message_extension, 0).bb()); 1715 1716 EXPECT_EQ(UNITTEST::TestAllTypes::BAR, 1717 message.GetExtension(UNITTEST::repeated_nested_enum_extension, 0)); 1718 EXPECT_EQ(UNITTEST::FOREIGN_BAR, 1719 message.GetExtension(UNITTEST::repeated_foreign_enum_extension, 0)); 1720 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, 1721 message.GetExtension(UNITTEST::repeated_import_enum_extension, 0)); 1722 1723 EXPECT_EQ("224", 1724 message.GetExtension(UNITTEST::repeated_string_piece_extension, 0)); 1725 EXPECT_EQ("225", message.GetExtension(UNITTEST::repeated_cord_extension, 0)); 1726 1727 // Actually verify the second (modified) elements now. 1728 EXPECT_EQ(501, message.GetExtension(UNITTEST::repeated_int32_extension, 1)); 1729 EXPECT_EQ(502, message.GetExtension(UNITTEST::repeated_int64_extension, 1)); 1730 EXPECT_EQ(503, message.GetExtension(UNITTEST::repeated_uint32_extension, 1)); 1731 EXPECT_EQ(504, message.GetExtension(UNITTEST::repeated_uint64_extension, 1)); 1732 EXPECT_EQ(505, message.GetExtension(UNITTEST::repeated_sint32_extension, 1)); 1733 EXPECT_EQ(506, message.GetExtension(UNITTEST::repeated_sint64_extension, 1)); 1734 EXPECT_EQ(507, message.GetExtension(UNITTEST::repeated_fixed32_extension, 1)); 1735 EXPECT_EQ(508, message.GetExtension(UNITTEST::repeated_fixed64_extension, 1)); 1736 EXPECT_EQ(509, 1737 message.GetExtension(UNITTEST::repeated_sfixed32_extension, 1)); 1738 EXPECT_EQ(510, 1739 message.GetExtension(UNITTEST::repeated_sfixed64_extension, 1)); 1740 EXPECT_EQ(511, message.GetExtension(UNITTEST::repeated_float_extension, 1)); 1741 EXPECT_EQ(512, message.GetExtension(UNITTEST::repeated_double_extension, 1)); 1742 EXPECT_TRUE(message.GetExtension(UNITTEST::repeated_bool_extension, 1)); 1743 EXPECT_EQ("515", 1744 message.GetExtension(UNITTEST::repeated_string_extension, 1)); 1745 EXPECT_EQ("516", message.GetExtension(UNITTEST::repeated_bytes_extension, 1)); 1746 1747 EXPECT_EQ(517, 1748 message.GetExtension(UNITTEST::repeatedgroup_extension, 1).a()); 1749 EXPECT_EQ(518, 1750 message.GetExtension(UNITTEST::repeated_nested_message_extension, 1) 1751 .bb()); 1752 EXPECT_EQ( 1753 519, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 1) 1754 .c()); 1755 EXPECT_EQ( 1756 520, 1757 message.GetExtension(UNITTEST::repeated_import_message_extension, 1).d()); 1758 EXPECT_EQ( 1759 527, 1760 message.GetExtension(UNITTEST::repeated_lazy_message_extension, 1).bb()); 1761 1762 EXPECT_EQ(UNITTEST::TestAllTypes::FOO, 1763 message.GetExtension(UNITTEST::repeated_nested_enum_extension, 1)); 1764 EXPECT_EQ(UNITTEST::FOREIGN_FOO, 1765 message.GetExtension(UNITTEST::repeated_foreign_enum_extension, 1)); 1766 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_FOO, 1767 message.GetExtension(UNITTEST::repeated_import_enum_extension, 1)); 1768 1769 EXPECT_EQ("524", 1770 message.GetExtension(UNITTEST::repeated_string_piece_extension, 1)); 1771 EXPECT_EQ("525", message.GetExtension(UNITTEST::repeated_cord_extension, 1)); 1772} 1773 1774// ------------------------------------------------------------------- 1775 1776inline void TestUtil::SetPackedExtensions( 1777 UNITTEST::TestPackedExtensions* message) { 1778 message->AddExtension(UNITTEST::packed_int32_extension, 601); 1779 message->AddExtension(UNITTEST::packed_int64_extension, 602); 1780 message->AddExtension(UNITTEST::packed_uint32_extension, 603); 1781 message->AddExtension(UNITTEST::packed_uint64_extension, 604); 1782 message->AddExtension(UNITTEST::packed_sint32_extension, 605); 1783 message->AddExtension(UNITTEST::packed_sint64_extension, 606); 1784 message->AddExtension(UNITTEST::packed_fixed32_extension, 607); 1785 message->AddExtension(UNITTEST::packed_fixed64_extension, 608); 1786 message->AddExtension(UNITTEST::packed_sfixed32_extension, 609); 1787 message->AddExtension(UNITTEST::packed_sfixed64_extension, 610); 1788 message->AddExtension(UNITTEST::packed_float_extension, 611); 1789 message->AddExtension(UNITTEST::packed_double_extension, 612); 1790 message->AddExtension(UNITTEST::packed_bool_extension, true); 1791 message->AddExtension(UNITTEST::packed_enum_extension, UNITTEST::FOREIGN_BAR); 1792 // add a second one of each field 1793 message->AddExtension(UNITTEST::packed_int32_extension, 701); 1794 message->AddExtension(UNITTEST::packed_int64_extension, 702); 1795 message->AddExtension(UNITTEST::packed_uint32_extension, 703); 1796 message->AddExtension(UNITTEST::packed_uint64_extension, 704); 1797 message->AddExtension(UNITTEST::packed_sint32_extension, 705); 1798 message->AddExtension(UNITTEST::packed_sint64_extension, 706); 1799 message->AddExtension(UNITTEST::packed_fixed32_extension, 707); 1800 message->AddExtension(UNITTEST::packed_fixed64_extension, 708); 1801 message->AddExtension(UNITTEST::packed_sfixed32_extension, 709); 1802 message->AddExtension(UNITTEST::packed_sfixed64_extension, 710); 1803 message->AddExtension(UNITTEST::packed_float_extension, 711); 1804 message->AddExtension(UNITTEST::packed_double_extension, 712); 1805 message->AddExtension(UNITTEST::packed_bool_extension, false); 1806 message->AddExtension(UNITTEST::packed_enum_extension, UNITTEST::FOREIGN_BAZ); 1807} 1808 1809// ------------------------------------------------------------------- 1810 1811inline void TestUtil::ExpectPackedExtensionsSet( 1812 const UNITTEST::TestPackedExtensions& message) { 1813 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_int32_extension)); 1814 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_int64_extension)); 1815 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_uint32_extension)); 1816 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_uint64_extension)); 1817 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_sint32_extension)); 1818 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_sint64_extension)); 1819 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_fixed32_extension)); 1820 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_fixed64_extension)); 1821 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_sfixed32_extension)); 1822 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_sfixed64_extension)); 1823 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_float_extension)); 1824 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_double_extension)); 1825 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_bool_extension)); 1826 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::packed_enum_extension)); 1827 1828 EXPECT_EQ(601, message.GetExtension(UNITTEST::packed_int32_extension, 0)); 1829 EXPECT_EQ(602, message.GetExtension(UNITTEST::packed_int64_extension, 0)); 1830 EXPECT_EQ(603, message.GetExtension(UNITTEST::packed_uint32_extension, 0)); 1831 EXPECT_EQ(604, message.GetExtension(UNITTEST::packed_uint64_extension, 0)); 1832 EXPECT_EQ(605, message.GetExtension(UNITTEST::packed_sint32_extension, 0)); 1833 EXPECT_EQ(606, message.GetExtension(UNITTEST::packed_sint64_extension, 0)); 1834 EXPECT_EQ(607, message.GetExtension(UNITTEST::packed_fixed32_extension, 0)); 1835 EXPECT_EQ(608, message.GetExtension(UNITTEST::packed_fixed64_extension, 0)); 1836 EXPECT_EQ(609, message.GetExtension(UNITTEST::packed_sfixed32_extension, 0)); 1837 EXPECT_EQ(610, message.GetExtension(UNITTEST::packed_sfixed64_extension, 0)); 1838 EXPECT_EQ(611, message.GetExtension(UNITTEST::packed_float_extension, 0)); 1839 EXPECT_EQ(612, message.GetExtension(UNITTEST::packed_double_extension, 0)); 1840 EXPECT_TRUE(message.GetExtension(UNITTEST::packed_bool_extension, 0)); 1841 EXPECT_EQ(UNITTEST::FOREIGN_BAR, 1842 message.GetExtension(UNITTEST::packed_enum_extension, 0)); 1843 EXPECT_EQ(701, message.GetExtension(UNITTEST::packed_int32_extension, 1)); 1844 EXPECT_EQ(702, message.GetExtension(UNITTEST::packed_int64_extension, 1)); 1845 EXPECT_EQ(703, message.GetExtension(UNITTEST::packed_uint32_extension, 1)); 1846 EXPECT_EQ(704, message.GetExtension(UNITTEST::packed_uint64_extension, 1)); 1847 EXPECT_EQ(705, message.GetExtension(UNITTEST::packed_sint32_extension, 1)); 1848 EXPECT_EQ(706, message.GetExtension(UNITTEST::packed_sint64_extension, 1)); 1849 EXPECT_EQ(707, message.GetExtension(UNITTEST::packed_fixed32_extension, 1)); 1850 EXPECT_EQ(708, message.GetExtension(UNITTEST::packed_fixed64_extension, 1)); 1851 EXPECT_EQ(709, message.GetExtension(UNITTEST::packed_sfixed32_extension, 1)); 1852 EXPECT_EQ(710, message.GetExtension(UNITTEST::packed_sfixed64_extension, 1)); 1853 EXPECT_EQ(711, message.GetExtension(UNITTEST::packed_float_extension, 1)); 1854 EXPECT_EQ(712, message.GetExtension(UNITTEST::packed_double_extension, 1)); 1855 EXPECT_FALSE(message.GetExtension(UNITTEST::packed_bool_extension, 1)); 1856 EXPECT_EQ(UNITTEST::FOREIGN_BAZ, 1857 message.GetExtension(UNITTEST::packed_enum_extension, 1)); 1858} 1859 1860// ------------------------------------------------------------------- 1861 1862inline void TestUtil::ExpectUnpackedExtensionsSet( 1863 const UNITTEST::TestUnpackedExtensions& message) { 1864 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_int32_extension)); 1865 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_int64_extension)); 1866 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_uint32_extension)); 1867 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_uint64_extension)); 1868 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_sint32_extension)); 1869 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_sint64_extension)); 1870 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_fixed32_extension)); 1871 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_fixed64_extension)); 1872 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_sfixed32_extension)); 1873 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_sfixed64_extension)); 1874 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_float_extension)); 1875 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_double_extension)); 1876 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_bool_extension)); 1877 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::unpacked_enum_extension)); 1878 1879 EXPECT_EQ(601, message.GetExtension(UNITTEST::unpacked_int32_extension, 0)); 1880 EXPECT_EQ(602, message.GetExtension(UNITTEST::unpacked_int64_extension, 0)); 1881 EXPECT_EQ(603, message.GetExtension(UNITTEST::unpacked_uint32_extension, 0)); 1882 EXPECT_EQ(604, message.GetExtension(UNITTEST::unpacked_uint64_extension, 0)); 1883 EXPECT_EQ(605, message.GetExtension(UNITTEST::unpacked_sint32_extension, 0)); 1884 EXPECT_EQ(606, message.GetExtension(UNITTEST::unpacked_sint64_extension, 0)); 1885 EXPECT_EQ(607, message.GetExtension(UNITTEST::unpacked_fixed32_extension, 0)); 1886 EXPECT_EQ(608, message.GetExtension(UNITTEST::unpacked_fixed64_extension, 0)); 1887 EXPECT_EQ(609, 1888 message.GetExtension(UNITTEST::unpacked_sfixed32_extension, 0)); 1889 EXPECT_EQ(610, 1890 message.GetExtension(UNITTEST::unpacked_sfixed64_extension, 0)); 1891 EXPECT_EQ(611, message.GetExtension(UNITTEST::unpacked_float_extension, 0)); 1892 EXPECT_EQ(612, message.GetExtension(UNITTEST::unpacked_double_extension, 0)); 1893 EXPECT_EQ(true, message.GetExtension(UNITTEST::unpacked_bool_extension, 0)); 1894 EXPECT_EQ(UNITTEST::FOREIGN_BAR, 1895 message.GetExtension(UNITTEST::unpacked_enum_extension, 0)); 1896 EXPECT_EQ(701, message.GetExtension(UNITTEST::unpacked_int32_extension, 1)); 1897 EXPECT_EQ(702, message.GetExtension(UNITTEST::unpacked_int64_extension, 1)); 1898 EXPECT_EQ(703, message.GetExtension(UNITTEST::unpacked_uint32_extension, 1)); 1899 EXPECT_EQ(704, message.GetExtension(UNITTEST::unpacked_uint64_extension, 1)); 1900 EXPECT_EQ(705, message.GetExtension(UNITTEST::unpacked_sint32_extension, 1)); 1901 EXPECT_EQ(706, message.GetExtension(UNITTEST::unpacked_sint64_extension, 1)); 1902 EXPECT_EQ(707, message.GetExtension(UNITTEST::unpacked_fixed32_extension, 1)); 1903 EXPECT_EQ(708, message.GetExtension(UNITTEST::unpacked_fixed64_extension, 1)); 1904 EXPECT_EQ(709, 1905 message.GetExtension(UNITTEST::unpacked_sfixed32_extension, 1)); 1906 EXPECT_EQ(710, 1907 message.GetExtension(UNITTEST::unpacked_sfixed64_extension, 1)); 1908 EXPECT_EQ(711, message.GetExtension(UNITTEST::unpacked_float_extension, 1)); 1909 EXPECT_EQ(712, message.GetExtension(UNITTEST::unpacked_double_extension, 1)); 1910 EXPECT_EQ(false, message.GetExtension(UNITTEST::unpacked_bool_extension, 1)); 1911 EXPECT_EQ(UNITTEST::FOREIGN_BAZ, 1912 message.GetExtension(UNITTEST::unpacked_enum_extension, 1)); 1913} 1914 1915// ------------------------------------------------------------------- 1916 1917inline void TestUtil::ExpectLastRepeatedsRemoved( 1918 const UNITTEST::TestAllTypes& message) { 1919 ASSERT_EQ(1, message.repeated_int32_size()); 1920 ASSERT_EQ(1, message.repeated_int64_size()); 1921 ASSERT_EQ(1, message.repeated_uint32_size()); 1922 ASSERT_EQ(1, message.repeated_uint64_size()); 1923 ASSERT_EQ(1, message.repeated_sint32_size()); 1924 ASSERT_EQ(1, message.repeated_sint64_size()); 1925 ASSERT_EQ(1, message.repeated_fixed32_size()); 1926 ASSERT_EQ(1, message.repeated_fixed64_size()); 1927 ASSERT_EQ(1, message.repeated_sfixed32_size()); 1928 ASSERT_EQ(1, message.repeated_sfixed64_size()); 1929 ASSERT_EQ(1, message.repeated_float_size()); 1930 ASSERT_EQ(1, message.repeated_double_size()); 1931 ASSERT_EQ(1, message.repeated_bool_size()); 1932 ASSERT_EQ(1, message.repeated_string_size()); 1933 ASSERT_EQ(1, message.repeated_bytes_size()); 1934 1935 ASSERT_EQ(1, message.repeatedgroup_size()); 1936 ASSERT_EQ(1, message.repeated_nested_message_size()); 1937 ASSERT_EQ(1, message.repeated_foreign_message_size()); 1938 ASSERT_EQ(1, message.repeated_import_message_size()); 1939 ASSERT_EQ(1, message.repeated_import_message_size()); 1940 ASSERT_EQ(1, message.repeated_nested_enum_size()); 1941 ASSERT_EQ(1, message.repeated_foreign_enum_size()); 1942 ASSERT_EQ(1, message.repeated_import_enum_size()); 1943 1944#ifndef PROTOBUF_TEST_NO_DESCRIPTORS 1945 ASSERT_EQ(1, message.repeated_string_piece_size()); 1946 ASSERT_EQ(1, message.repeated_cord_size()); 1947#endif 1948 1949 // Test that the remaining element is the correct one. 1950 EXPECT_EQ(201, message.repeated_int32(0)); 1951 EXPECT_EQ(202, message.repeated_int64(0)); 1952 EXPECT_EQ(203, message.repeated_uint32(0)); 1953 EXPECT_EQ(204, message.repeated_uint64(0)); 1954 EXPECT_EQ(205, message.repeated_sint32(0)); 1955 EXPECT_EQ(206, message.repeated_sint64(0)); 1956 EXPECT_EQ(207, message.repeated_fixed32(0)); 1957 EXPECT_EQ(208, message.repeated_fixed64(0)); 1958 EXPECT_EQ(209, message.repeated_sfixed32(0)); 1959 EXPECT_EQ(210, message.repeated_sfixed64(0)); 1960 EXPECT_EQ(211, message.repeated_float(0)); 1961 EXPECT_EQ(212, message.repeated_double(0)); 1962 EXPECT_TRUE(message.repeated_bool(0)); 1963 EXPECT_EQ("215", message.repeated_string(0)); 1964 EXPECT_EQ("216", message.repeated_bytes(0)); 1965 1966 EXPECT_EQ(217, message.repeatedgroup(0).a()); 1967 EXPECT_EQ(218, message.repeated_nested_message(0).bb()); 1968 EXPECT_EQ(219, message.repeated_foreign_message(0).c()); 1969 EXPECT_EQ(220, message.repeated_import_message(0).d()); 1970 EXPECT_EQ(220, message.repeated_import_message(0).d()); 1971 1972 EXPECT_EQ(UNITTEST::TestAllTypes::BAR, message.repeated_nested_enum(0)); 1973 EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.repeated_foreign_enum(0)); 1974 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, message.repeated_import_enum(0)); 1975} 1976 1977inline void TestUtil::ExpectLastRepeatedExtensionsRemoved( 1978 const UNITTEST::TestAllExtensions& message) { 1979 // Test that one element was removed. 1980 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_int32_extension)); 1981 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_int64_extension)); 1982 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_uint32_extension)); 1983 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_uint64_extension)); 1984 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_sint32_extension)); 1985 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_sint64_extension)); 1986 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_fixed32_extension)); 1987 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_fixed64_extension)); 1988 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_sfixed32_extension)); 1989 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_sfixed64_extension)); 1990 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_float_extension)); 1991 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_double_extension)); 1992 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_bool_extension)); 1993 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_string_extension)); 1994 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_bytes_extension)); 1995 1996 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeatedgroup_extension)); 1997 ASSERT_EQ(1, 1998 message.ExtensionSize(UNITTEST::repeated_nested_message_extension)); 1999 ASSERT_EQ( 2000 1, message.ExtensionSize(UNITTEST::repeated_foreign_message_extension)); 2001 ASSERT_EQ(1, 2002 message.ExtensionSize(UNITTEST::repeated_import_message_extension)); 2003 ASSERT_EQ(1, 2004 message.ExtensionSize(UNITTEST::repeated_lazy_message_extension)); 2005 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_nested_enum_extension)); 2006 ASSERT_EQ(1, 2007 message.ExtensionSize(UNITTEST::repeated_foreign_enum_extension)); 2008 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_import_enum_extension)); 2009 2010 ASSERT_EQ(1, 2011 message.ExtensionSize(UNITTEST::repeated_string_piece_extension)); 2012 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeated_cord_extension)); 2013 2014 // Test that the remaining element is the correct one. 2015 EXPECT_EQ(201, message.GetExtension(UNITTEST::repeated_int32_extension, 0)); 2016 EXPECT_EQ(202, message.GetExtension(UNITTEST::repeated_int64_extension, 0)); 2017 EXPECT_EQ(203, message.GetExtension(UNITTEST::repeated_uint32_extension, 0)); 2018 EXPECT_EQ(204, message.GetExtension(UNITTEST::repeated_uint64_extension, 0)); 2019 EXPECT_EQ(205, message.GetExtension(UNITTEST::repeated_sint32_extension, 0)); 2020 EXPECT_EQ(206, message.GetExtension(UNITTEST::repeated_sint64_extension, 0)); 2021 EXPECT_EQ(207, message.GetExtension(UNITTEST::repeated_fixed32_extension, 0)); 2022 EXPECT_EQ(208, message.GetExtension(UNITTEST::repeated_fixed64_extension, 0)); 2023 EXPECT_EQ(209, 2024 message.GetExtension(UNITTEST::repeated_sfixed32_extension, 0)); 2025 EXPECT_EQ(210, 2026 message.GetExtension(UNITTEST::repeated_sfixed64_extension, 0)); 2027 EXPECT_EQ(211, message.GetExtension(UNITTEST::repeated_float_extension, 0)); 2028 EXPECT_EQ(212, message.GetExtension(UNITTEST::repeated_double_extension, 0)); 2029 EXPECT_TRUE(message.GetExtension(UNITTEST::repeated_bool_extension, 0)); 2030 EXPECT_EQ("215", 2031 message.GetExtension(UNITTEST::repeated_string_extension, 0)); 2032 EXPECT_EQ("216", message.GetExtension(UNITTEST::repeated_bytes_extension, 0)); 2033 2034 EXPECT_EQ(217, 2035 message.GetExtension(UNITTEST::repeatedgroup_extension, 0).a()); 2036 EXPECT_EQ(218, 2037 message.GetExtension(UNITTEST::repeated_nested_message_extension, 0) 2038 .bb()); 2039 EXPECT_EQ( 2040 219, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 0) 2041 .c()); 2042 EXPECT_EQ( 2043 220, 2044 message.GetExtension(UNITTEST::repeated_import_message_extension, 0).d()); 2045 EXPECT_EQ( 2046 227, 2047 message.GetExtension(UNITTEST::repeated_lazy_message_extension, 0).bb()); 2048 2049 EXPECT_EQ(UNITTEST::TestAllTypes::BAR, 2050 message.GetExtension(UNITTEST::repeated_nested_enum_extension, 0)); 2051 EXPECT_EQ(UNITTEST::FOREIGN_BAR, 2052 message.GetExtension(UNITTEST::repeated_foreign_enum_extension, 0)); 2053 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, 2054 message.GetExtension(UNITTEST::repeated_import_enum_extension, 0)); 2055 2056 EXPECT_EQ("224", 2057 message.GetExtension(UNITTEST::repeated_string_piece_extension, 0)); 2058 EXPECT_EQ("225", message.GetExtension(UNITTEST::repeated_cord_extension, 0)); 2059} 2060 2061inline void TestUtil::ExpectLastRepeatedsReleased( 2062 const UNITTEST::TestAllTypes& message) { 2063 ASSERT_EQ(1, message.repeatedgroup_size()); 2064 ASSERT_EQ(1, message.repeated_nested_message_size()); 2065 ASSERT_EQ(1, message.repeated_foreign_message_size()); 2066 ASSERT_EQ(1, message.repeated_import_message_size()); 2067 ASSERT_EQ(1, message.repeated_import_message_size()); 2068 2069 EXPECT_EQ(217, message.repeatedgroup(0).a()); 2070 EXPECT_EQ(218, message.repeated_nested_message(0).bb()); 2071 EXPECT_EQ(219, message.repeated_foreign_message(0).c()); 2072 EXPECT_EQ(220, message.repeated_import_message(0).d()); 2073 EXPECT_EQ(220, message.repeated_import_message(0).d()); 2074} 2075 2076inline void TestUtil::ExpectLastRepeatedExtensionsReleased( 2077 const UNITTEST::TestAllExtensions& message) { 2078 ASSERT_EQ(1, message.ExtensionSize(UNITTEST::repeatedgroup_extension)); 2079 ASSERT_EQ(1, 2080 message.ExtensionSize(UNITTEST::repeated_nested_message_extension)); 2081 ASSERT_EQ( 2082 1, message.ExtensionSize(UNITTEST::repeated_foreign_message_extension)); 2083 ASSERT_EQ(1, 2084 message.ExtensionSize(UNITTEST::repeated_import_message_extension)); 2085 ASSERT_EQ(1, 2086 message.ExtensionSize(UNITTEST::repeated_lazy_message_extension)); 2087 2088 EXPECT_EQ(217, 2089 message.GetExtension(UNITTEST::repeatedgroup_extension, 0).a()); 2090 EXPECT_EQ(218, 2091 message.GetExtension(UNITTEST::repeated_nested_message_extension, 0) 2092 .bb()); 2093 EXPECT_EQ( 2094 219, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 0) 2095 .c()); 2096 EXPECT_EQ( 2097 220, 2098 message.GetExtension(UNITTEST::repeated_import_message_extension, 0).d()); 2099 EXPECT_EQ( 2100 227, 2101 message.GetExtension(UNITTEST::repeated_lazy_message_extension, 0).bb()); 2102} 2103 2104inline void TestUtil::ExpectRepeatedsSwapped( 2105 const UNITTEST::TestAllTypes& message) { 2106 ASSERT_EQ(2, message.repeated_int32_size()); 2107 ASSERT_EQ(2, message.repeated_int64_size()); 2108 ASSERT_EQ(2, message.repeated_uint32_size()); 2109 ASSERT_EQ(2, message.repeated_uint64_size()); 2110 ASSERT_EQ(2, message.repeated_sint32_size()); 2111 ASSERT_EQ(2, message.repeated_sint64_size()); 2112 ASSERT_EQ(2, message.repeated_fixed32_size()); 2113 ASSERT_EQ(2, message.repeated_fixed64_size()); 2114 ASSERT_EQ(2, message.repeated_sfixed32_size()); 2115 ASSERT_EQ(2, message.repeated_sfixed64_size()); 2116 ASSERT_EQ(2, message.repeated_float_size()); 2117 ASSERT_EQ(2, message.repeated_double_size()); 2118 ASSERT_EQ(2, message.repeated_bool_size()); 2119 ASSERT_EQ(2, message.repeated_string_size()); 2120 ASSERT_EQ(2, message.repeated_bytes_size()); 2121 2122 ASSERT_EQ(2, message.repeatedgroup_size()); 2123 ASSERT_EQ(2, message.repeated_nested_message_size()); 2124 ASSERT_EQ(2, message.repeated_foreign_message_size()); 2125 ASSERT_EQ(2, message.repeated_import_message_size()); 2126 ASSERT_EQ(2, message.repeated_import_message_size()); 2127 ASSERT_EQ(2, message.repeated_nested_enum_size()); 2128 ASSERT_EQ(2, message.repeated_foreign_enum_size()); 2129 ASSERT_EQ(2, message.repeated_import_enum_size()); 2130 2131#ifndef PROTOBUF_TEST_NO_DESCRIPTORS 2132 ASSERT_EQ(2, message.repeated_string_piece_size()); 2133 ASSERT_EQ(2, message.repeated_cord_size()); 2134#endif 2135 2136 // Test that the first element and second element are flipped. 2137 EXPECT_EQ(201, message.repeated_int32(1)); 2138 EXPECT_EQ(202, message.repeated_int64(1)); 2139 EXPECT_EQ(203, message.repeated_uint32(1)); 2140 EXPECT_EQ(204, message.repeated_uint64(1)); 2141 EXPECT_EQ(205, message.repeated_sint32(1)); 2142 EXPECT_EQ(206, message.repeated_sint64(1)); 2143 EXPECT_EQ(207, message.repeated_fixed32(1)); 2144 EXPECT_EQ(208, message.repeated_fixed64(1)); 2145 EXPECT_EQ(209, message.repeated_sfixed32(1)); 2146 EXPECT_EQ(210, message.repeated_sfixed64(1)); 2147 EXPECT_EQ(211, message.repeated_float(1)); 2148 EXPECT_EQ(212, message.repeated_double(1)); 2149 EXPECT_TRUE(message.repeated_bool(1)); 2150 EXPECT_EQ("215", message.repeated_string(1)); 2151 EXPECT_EQ("216", message.repeated_bytes(1)); 2152 2153 EXPECT_EQ(217, message.repeatedgroup(1).a()); 2154 EXPECT_EQ(218, message.repeated_nested_message(1).bb()); 2155 EXPECT_EQ(219, message.repeated_foreign_message(1).c()); 2156 EXPECT_EQ(220, message.repeated_import_message(1).d()); 2157 EXPECT_EQ(220, message.repeated_import_message(1).d()); 2158 2159 EXPECT_EQ(UNITTEST::TestAllTypes::BAR, message.repeated_nested_enum(1)); 2160 EXPECT_EQ(UNITTEST::FOREIGN_BAR, message.repeated_foreign_enum(1)); 2161 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, message.repeated_import_enum(1)); 2162 2163 EXPECT_EQ(301, message.repeated_int32(0)); 2164 EXPECT_EQ(302, message.repeated_int64(0)); 2165 EXPECT_EQ(303, message.repeated_uint32(0)); 2166 EXPECT_EQ(304, message.repeated_uint64(0)); 2167 EXPECT_EQ(305, message.repeated_sint32(0)); 2168 EXPECT_EQ(306, message.repeated_sint64(0)); 2169 EXPECT_EQ(307, message.repeated_fixed32(0)); 2170 EXPECT_EQ(308, message.repeated_fixed64(0)); 2171 EXPECT_EQ(309, message.repeated_sfixed32(0)); 2172 EXPECT_EQ(310, message.repeated_sfixed64(0)); 2173 EXPECT_EQ(311, message.repeated_float(0)); 2174 EXPECT_EQ(312, message.repeated_double(0)); 2175 EXPECT_FALSE(message.repeated_bool(0)); 2176 EXPECT_EQ("315", message.repeated_string(0)); 2177 EXPECT_EQ("316", message.repeated_bytes(0)); 2178 2179 EXPECT_EQ(317, message.repeatedgroup(0).a()); 2180 EXPECT_EQ(318, message.repeated_nested_message(0).bb()); 2181 EXPECT_EQ(319, message.repeated_foreign_message(0).c()); 2182 EXPECT_EQ(320, message.repeated_import_message(0).d()); 2183 EXPECT_EQ(320, message.repeated_import_message(0).d()); 2184 2185 EXPECT_EQ(UNITTEST::TestAllTypes::BAZ, message.repeated_nested_enum(0)); 2186 EXPECT_EQ(UNITTEST::FOREIGN_BAZ, message.repeated_foreign_enum(0)); 2187 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAZ, message.repeated_import_enum(0)); 2188} 2189 2190inline void TestUtil::ExpectRepeatedExtensionsSwapped( 2191 const UNITTEST::TestAllExtensions& message) { 2192 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_int32_extension)); 2193 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_int64_extension)); 2194 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_uint32_extension)); 2195 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_uint64_extension)); 2196 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sint32_extension)); 2197 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sint64_extension)); 2198 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_fixed32_extension)); 2199 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_fixed64_extension)); 2200 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sfixed32_extension)); 2201 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_sfixed64_extension)); 2202 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_float_extension)); 2203 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_double_extension)); 2204 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_bool_extension)); 2205 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_string_extension)); 2206 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_bytes_extension)); 2207 2208 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeatedgroup_extension)); 2209 ASSERT_EQ(2, 2210 message.ExtensionSize(UNITTEST::repeated_nested_message_extension)); 2211 ASSERT_EQ( 2212 2, message.ExtensionSize(UNITTEST::repeated_foreign_message_extension)); 2213 ASSERT_EQ(2, 2214 message.ExtensionSize(UNITTEST::repeated_import_message_extension)); 2215 ASSERT_EQ(2, 2216 message.ExtensionSize(UNITTEST::repeated_lazy_message_extension)); 2217 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_nested_enum_extension)); 2218 ASSERT_EQ(2, 2219 message.ExtensionSize(UNITTEST::repeated_foreign_enum_extension)); 2220 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_import_enum_extension)); 2221 2222 ASSERT_EQ(2, 2223 message.ExtensionSize(UNITTEST::repeated_string_piece_extension)); 2224 ASSERT_EQ(2, message.ExtensionSize(UNITTEST::repeated_cord_extension)); 2225 2226 EXPECT_EQ(201, message.GetExtension(UNITTEST::repeated_int32_extension, 1)); 2227 EXPECT_EQ(202, message.GetExtension(UNITTEST::repeated_int64_extension, 1)); 2228 EXPECT_EQ(203, message.GetExtension(UNITTEST::repeated_uint32_extension, 1)); 2229 EXPECT_EQ(204, message.GetExtension(UNITTEST::repeated_uint64_extension, 1)); 2230 EXPECT_EQ(205, message.GetExtension(UNITTEST::repeated_sint32_extension, 1)); 2231 EXPECT_EQ(206, message.GetExtension(UNITTEST::repeated_sint64_extension, 1)); 2232 EXPECT_EQ(207, message.GetExtension(UNITTEST::repeated_fixed32_extension, 1)); 2233 EXPECT_EQ(208, message.GetExtension(UNITTEST::repeated_fixed64_extension, 1)); 2234 EXPECT_EQ(209, 2235 message.GetExtension(UNITTEST::repeated_sfixed32_extension, 1)); 2236 EXPECT_EQ(210, 2237 message.GetExtension(UNITTEST::repeated_sfixed64_extension, 1)); 2238 EXPECT_EQ(211, message.GetExtension(UNITTEST::repeated_float_extension, 1)); 2239 EXPECT_EQ(212, message.GetExtension(UNITTEST::repeated_double_extension, 1)); 2240 EXPECT_TRUE(message.GetExtension(UNITTEST::repeated_bool_extension, 1)); 2241 EXPECT_EQ("215", 2242 message.GetExtension(UNITTEST::repeated_string_extension, 1)); 2243 EXPECT_EQ("216", message.GetExtension(UNITTEST::repeated_bytes_extension, 1)); 2244 2245 EXPECT_EQ(217, 2246 message.GetExtension(UNITTEST::repeatedgroup_extension, 1).a()); 2247 EXPECT_EQ(218, 2248 message.GetExtension(UNITTEST::repeated_nested_message_extension, 1) 2249 .bb()); 2250 EXPECT_EQ( 2251 219, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 1) 2252 .c()); 2253 EXPECT_EQ( 2254 220, 2255 message.GetExtension(UNITTEST::repeated_import_message_extension, 1).d()); 2256 EXPECT_EQ( 2257 227, 2258 message.GetExtension(UNITTEST::repeated_lazy_message_extension, 1).bb()); 2259 2260 EXPECT_EQ(UNITTEST::TestAllTypes::BAR, 2261 message.GetExtension(UNITTEST::repeated_nested_enum_extension, 1)); 2262 EXPECT_EQ(UNITTEST::FOREIGN_BAR, 2263 message.GetExtension(UNITTEST::repeated_foreign_enum_extension, 1)); 2264 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAR, 2265 message.GetExtension(UNITTEST::repeated_import_enum_extension, 1)); 2266 2267 EXPECT_EQ("224", 2268 message.GetExtension(UNITTEST::repeated_string_piece_extension, 1)); 2269 EXPECT_EQ("225", message.GetExtension(UNITTEST::repeated_cord_extension, 1)); 2270 2271 EXPECT_EQ(301, message.GetExtension(UNITTEST::repeated_int32_extension, 0)); 2272 EXPECT_EQ(302, message.GetExtension(UNITTEST::repeated_int64_extension, 0)); 2273 EXPECT_EQ(303, message.GetExtension(UNITTEST::repeated_uint32_extension, 0)); 2274 EXPECT_EQ(304, message.GetExtension(UNITTEST::repeated_uint64_extension, 0)); 2275 EXPECT_EQ(305, message.GetExtension(UNITTEST::repeated_sint32_extension, 0)); 2276 EXPECT_EQ(306, message.GetExtension(UNITTEST::repeated_sint64_extension, 0)); 2277 EXPECT_EQ(307, message.GetExtension(UNITTEST::repeated_fixed32_extension, 0)); 2278 EXPECT_EQ(308, message.GetExtension(UNITTEST::repeated_fixed64_extension, 0)); 2279 EXPECT_EQ(309, 2280 message.GetExtension(UNITTEST::repeated_sfixed32_extension, 0)); 2281 EXPECT_EQ(310, 2282 message.GetExtension(UNITTEST::repeated_sfixed64_extension, 0)); 2283 EXPECT_EQ(311, message.GetExtension(UNITTEST::repeated_float_extension, 0)); 2284 EXPECT_EQ(312, message.GetExtension(UNITTEST::repeated_double_extension, 0)); 2285 EXPECT_FALSE(message.GetExtension(UNITTEST::repeated_bool_extension, 0)); 2286 EXPECT_EQ("315", 2287 message.GetExtension(UNITTEST::repeated_string_extension, 0)); 2288 EXPECT_EQ("316", message.GetExtension(UNITTEST::repeated_bytes_extension, 0)); 2289 2290 EXPECT_EQ(317, 2291 message.GetExtension(UNITTEST::repeatedgroup_extension, 0).a()); 2292 EXPECT_EQ(318, 2293 message.GetExtension(UNITTEST::repeated_nested_message_extension, 0) 2294 .bb()); 2295 EXPECT_EQ( 2296 319, message.GetExtension(UNITTEST::repeated_foreign_message_extension, 0) 2297 .c()); 2298 EXPECT_EQ( 2299 320, 2300 message.GetExtension(UNITTEST::repeated_import_message_extension, 0).d()); 2301 EXPECT_EQ( 2302 327, 2303 message.GetExtension(UNITTEST::repeated_lazy_message_extension, 0).bb()); 2304 2305 EXPECT_EQ(UNITTEST::TestAllTypes::BAZ, 2306 message.GetExtension(UNITTEST::repeated_nested_enum_extension, 0)); 2307 EXPECT_EQ(UNITTEST::FOREIGN_BAZ, 2308 message.GetExtension(UNITTEST::repeated_foreign_enum_extension, 0)); 2309 EXPECT_EQ(UNITTEST_IMPORT::IMPORT_BAZ, 2310 message.GetExtension(UNITTEST::repeated_import_enum_extension, 0)); 2311 2312 EXPECT_EQ("324", 2313 message.GetExtension(UNITTEST::repeated_string_piece_extension, 0)); 2314 EXPECT_EQ("325", message.GetExtension(UNITTEST::repeated_cord_extension, 0)); 2315} 2316 2317inline void TestUtil::SetOneof1(UNITTEST::TestOneof2* message) { 2318 message->mutable_foo_lazy_message()->set_qux_int(100); 2319 message->set_bar_string("101"); 2320 message->set_baz_int(102); 2321 message->set_baz_string("103"); 2322} 2323 2324inline void TestUtil::SetOneof2(UNITTEST::TestOneof2* message) { 2325 message->set_foo_int(200); 2326 message->set_bar_enum(UNITTEST::TestOneof2::BAZ); 2327 message->set_baz_int(202); 2328 message->set_baz_string("203"); 2329} 2330 2331inline void TestUtil::ExpectOneofSet1(const UNITTEST::TestOneof2& message) { 2332 ExpectAtMostOneFieldSetInOneof(message); 2333 2334 EXPECT_TRUE(message.has_foo_lazy_message()); 2335 EXPECT_TRUE(message.foo_lazy_message().has_qux_int()); 2336 2337 EXPECT_TRUE(message.has_bar_string()); 2338 EXPECT_TRUE(message.has_baz_int()); 2339 EXPECT_TRUE(message.has_baz_string()); 2340 2341 ASSERT_EQ(0, message.foo_lazy_message().corge_int_size()); 2342 2343 EXPECT_EQ(100, message.foo_lazy_message().qux_int()); 2344 EXPECT_EQ("101", message.bar_string()); 2345 EXPECT_EQ(102, message.baz_int()); 2346 EXPECT_EQ("103", message.baz_string()); 2347} 2348 2349inline void TestUtil::ExpectOneofSet2(const UNITTEST::TestOneof2& message) { 2350 ExpectAtMostOneFieldSetInOneof(message); 2351 2352 EXPECT_TRUE(message.has_foo_int()); 2353 EXPECT_TRUE(message.has_bar_enum()); 2354 EXPECT_TRUE(message.has_baz_int()); 2355 EXPECT_TRUE(message.has_baz_string()); 2356 2357 EXPECT_EQ(200, message.foo_int()); 2358 EXPECT_EQ(UNITTEST::TestOneof2::BAZ, message.bar_enum()); 2359 EXPECT_EQ(202, message.baz_int()); 2360 EXPECT_EQ("203", message.baz_string()); 2361} 2362 2363inline void TestUtil::ExpectOneofClear(const UNITTEST::TestOneof2& message) { 2364 EXPECT_FALSE(message.has_foo_int()); 2365 EXPECT_FALSE(message.has_foo_string()); 2366 EXPECT_FALSE(message.has_foo_bytes()); 2367 EXPECT_FALSE(message.has_foo_enum()); 2368 EXPECT_FALSE(message.has_foo_message()); 2369 EXPECT_FALSE(message.has_foogroup()); 2370 EXPECT_FALSE(message.has_foo_lazy_message()); 2371 2372 EXPECT_FALSE(message.has_bar_int()); 2373 EXPECT_FALSE(message.has_bar_string()); 2374 EXPECT_FALSE(message.has_bar_bytes()); 2375 EXPECT_FALSE(message.has_bar_enum()); 2376 2377 EXPECT_FALSE(message.has_baz_int()); 2378 EXPECT_FALSE(message.has_baz_string()); 2379 2380 EXPECT_EQ(UNITTEST::TestOneof2::FOO_NOT_SET, message.foo_case()); 2381 EXPECT_EQ(UNITTEST::TestOneof2::BAR_NOT_SET, message.bar_case()); 2382} 2383 2384inline void TestUtil::ExpectAtMostOneFieldSetInOneof( 2385 const UNITTEST::TestOneof2& message) { 2386 int count = 0; 2387 if (message.has_foo_int()) count++; 2388 if (message.has_foo_string()) count++; 2389 if (message.has_foo_bytes()) count++; 2390 if (message.has_foo_enum()) count++; 2391 if (message.has_foo_message()) count++; 2392 if (message.has_foogroup()) count++; 2393 if (message.has_foo_lazy_message()) count++; 2394 EXPECT_LE(count, 1); 2395 count = 0; 2396 if (message.has_bar_int()) count++; 2397 if (message.has_bar_string()) count++; 2398 if (message.has_bar_bytes()) count++; 2399 if (message.has_bar_enum()) count++; 2400 EXPECT_TRUE(count == 0 || count == 1); 2401} 2402 2403// =================================================================== 2404 2405} // namespace protobuf 2406} // namespace google 2407