Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc

Issue 21208003: Update protobuf to r428, part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // http://code.google.com/p/protobuf/ 3 // http://code.google.com/p/protobuf/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 218
219 TestUtil::ExpectLastRepeatedsRemoved(message); 219 TestUtil::ExpectLastRepeatedsRemoved(message);
220 } 220 }
221 221
222 TEST(GeneratedMessageReflectionTest, RemoveLastExtensions) { 222 TEST(GeneratedMessageReflectionTest, RemoveLastExtensions) {
223 unittest::TestAllExtensions message; 223 unittest::TestAllExtensions message;
224 TestUtil::ReflectionTester reflection_tester( 224 TestUtil::ReflectionTester reflection_tester(
225 unittest::TestAllExtensions::descriptor()); 225 unittest::TestAllExtensions::descriptor());
226 226
227 TestUtil::SetAllExtensions(&message); 227 TestUtil::SetAllExtensions(&message);
228
228 reflection_tester.RemoveLastRepeatedsViaReflection(&message); 229 reflection_tester.RemoveLastRepeatedsViaReflection(&message);
229 230
230 TestUtil::ExpectLastRepeatedExtensionsRemoved(message); 231 TestUtil::ExpectLastRepeatedExtensionsRemoved(message);
231 } 232 }
232 233
234 TEST(GeneratedMessageReflectionTest, ReleaseLast) {
235 unittest::TestAllTypes message;
236 const Descriptor* descriptor = message.GetDescriptor();
237 TestUtil::ReflectionTester reflection_tester(descriptor);
238
239 TestUtil::SetAllFields(&message);
240
241 reflection_tester.ReleaseLastRepeatedsViaReflection(&message, false);
242
243 TestUtil::ExpectLastRepeatedsReleased(message);
244
245 // Now test that we actually release the right message.
246 message.Clear();
247 TestUtil::SetAllFields(&message);
248 ASSERT_EQ(2, message.repeated_foreign_message_size());
249 const protobuf_unittest::ForeignMessage* expected =
250 message.mutable_repeated_foreign_message(1);
251 scoped_ptr<Message> released(message.GetReflection()->ReleaseLast(
252 &message, descriptor->FindFieldByName("repeated_foreign_message")));
253 EXPECT_EQ(expected, released.get());
254 }
255
256 TEST(GeneratedMessageReflectionTest, ReleaseLastExtensions) {
257 unittest::TestAllExtensions message;
258 const Descriptor* descriptor = message.GetDescriptor();
259 TestUtil::ReflectionTester reflection_tester(descriptor);
260
261 TestUtil::SetAllExtensions(&message);
262
263 reflection_tester.ReleaseLastRepeatedsViaReflection(&message, true);
264
265 TestUtil::ExpectLastRepeatedExtensionsReleased(message);
266
267 // Now test that we actually release the right message.
268 message.Clear();
269 TestUtil::SetAllExtensions(&message);
270 ASSERT_EQ(2, message.ExtensionSize(
271 unittest::repeated_foreign_message_extension));
272 const protobuf_unittest::ForeignMessage* expected = message.MutableExtension(
273 unittest::repeated_foreign_message_extension, 1);
274 scoped_ptr<Message> released(message.GetReflection()->ReleaseLast(
275 &message, descriptor->file()->FindExtensionByName(
276 "repeated_foreign_message_extension")));
277 EXPECT_EQ(expected, released.get());
278
279 }
280
233 TEST(GeneratedMessageReflectionTest, SwapRepeatedElements) { 281 TEST(GeneratedMessageReflectionTest, SwapRepeatedElements) {
234 unittest::TestAllTypes message; 282 unittest::TestAllTypes message;
235 TestUtil::ReflectionTester reflection_tester( 283 TestUtil::ReflectionTester reflection_tester(
236 unittest::TestAllTypes::descriptor()); 284 unittest::TestAllTypes::descriptor());
237 285
238 TestUtil::SetAllFields(&message); 286 TestUtil::SetAllFields(&message);
239 287
240 // Swap and test that fields are all swapped. 288 // Swap and test that fields are all swapped.
241 reflection_tester.SwapRepeatedsViaReflection(&message); 289 reflection_tester.SwapRepeatedsViaReflection(&message);
242 TestUtil::ExpectRepeatedsSwapped(message); 290 TestUtil::ExpectRepeatedsSwapped(message);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 368
321 // Non-existent extension. 369 // Non-existent extension.
322 EXPECT_TRUE(reflection->FindKnownExtensionByName("no_such_ext") == NULL); 370 EXPECT_TRUE(reflection->FindKnownExtensionByName("no_such_ext") == NULL);
323 371
324 // Extensions of TestAllExtensions should not show up as extensions of 372 // Extensions of TestAllExtensions should not show up as extensions of
325 // other types. 373 // other types.
326 EXPECT_TRUE(unittest::TestAllTypes::default_instance().GetReflection()-> 374 EXPECT_TRUE(unittest::TestAllTypes::default_instance().GetReflection()->
327 FindKnownExtensionByName(extension1->full_name()) == NULL); 375 FindKnownExtensionByName(extension1->full_name()) == NULL);
328 } 376 }
329 377
378 TEST(GeneratedMessageReflectionTest, ReleaseMessageTest) {
379 unittest::TestAllTypes message;
380 TestUtil::ReflectionTester reflection_tester(
381 unittest::TestAllTypes::descriptor());
382
383 // When nothing is set, we expect all released messages to be NULL.
384 reflection_tester.ExpectMessagesReleasedViaReflection(
385 &message, TestUtil::ReflectionTester::IS_NULL);
386
387 // After fields are set we should get non-NULL releases.
388 reflection_tester.SetAllFieldsViaReflection(&message);
389 reflection_tester.ExpectMessagesReleasedViaReflection(
390 &message, TestUtil::ReflectionTester::NOT_NULL);
391
392 // After Clear() we may or may not get a message from ReleaseMessage().
393 // This is implementation specific.
394 reflection_tester.SetAllFieldsViaReflection(&message);
395 message.Clear();
396 reflection_tester.ExpectMessagesReleasedViaReflection(
397 &message, TestUtil::ReflectionTester::CAN_BE_NULL);
398
399 // Test a different code path for setting after releasing.
400 TestUtil::SetAllFields(&message);
401 TestUtil::ExpectAllFieldsSet(message);
402 }
403
404 TEST(GeneratedMessageReflectionTest, ReleaseExtensionMessageTest) {
405 unittest::TestAllExtensions message;
406 TestUtil::ReflectionTester reflection_tester(
407 unittest::TestAllExtensions::descriptor());
408
409 // When nothing is set, we expect all released messages to be NULL.
410 reflection_tester.ExpectMessagesReleasedViaReflection(
411 &message, TestUtil::ReflectionTester::IS_NULL);
412
413 // After fields are set we should get non-NULL releases.
414 reflection_tester.SetAllFieldsViaReflection(&message);
415 reflection_tester.ExpectMessagesReleasedViaReflection(
416 &message, TestUtil::ReflectionTester::NOT_NULL);
417
418 // After Clear() we may or may not get a message from ReleaseMessage().
419 // This is implementation specific.
420 reflection_tester.SetAllFieldsViaReflection(&message);
421 message.Clear();
422 reflection_tester.ExpectMessagesReleasedViaReflection(
423 &message, TestUtil::ReflectionTester::CAN_BE_NULL);
424
425 // Test a different code path for setting after releasing.
426 TestUtil::SetAllExtensions(&message);
427 TestUtil::ExpectAllExtensionsSet(message);
428 }
429
330 #ifdef GTEST_HAS_DEATH_TEST 430 #ifdef GTEST_HAS_DEATH_TEST
331 431
332 TEST(GeneratedMessageReflectionTest, UsageErrors) { 432 TEST(GeneratedMessageReflectionTest, UsageErrors) {
333 unittest::TestAllTypes message; 433 unittest::TestAllTypes message;
334 const Reflection* reflection = message.GetReflection(); 434 const Reflection* reflection = message.GetReflection();
335 const Descriptor* descriptor = message.GetDescriptor(); 435 const Descriptor* descriptor = message.GetDescriptor();
336 436
337 #define f(NAME) descriptor->FindFieldByName(NAME) 437 #define f(NAME) descriptor->FindFieldByName(NAME)
338 438
339 // Testing every single failure mode would be too much work. Let's just 439 // Testing every single failure mode would be too much work. Let's just
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 475
376 #undef f 476 #undef f
377 } 477 }
378 478
379 #endif // GTEST_HAS_DEATH_TEST 479 #endif // GTEST_HAS_DEATH_TEST
380 480
381 481
382 } // namespace 482 } // namespace
383 } // namespace protobuf 483 } // namespace protobuf
384 } // namespace google 484 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698