| OLD | NEW |
| 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 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 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 30 matching lines...) Expand all Loading... |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 #include <google/protobuf/descriptor_database.h> | 43 #include <google/protobuf/descriptor_database.h> |
| 44 #include <google/protobuf/descriptor.h> | 44 #include <google/protobuf/descriptor.h> |
| 45 #include <google/protobuf/descriptor.pb.h> | 45 #include <google/protobuf/descriptor.pb.h> |
| 46 #include <google/protobuf/text_format.h> | 46 #include <google/protobuf/text_format.h> |
| 47 #include <google/protobuf/stubs/strutil.h> | 47 #include <google/protobuf/stubs/strutil.h> |
| 48 | 48 |
| 49 #include <google/protobuf/stubs/logging.h> | 49 #include <google/protobuf/stubs/logging.h> |
| 50 #include <google/protobuf/stubs/common.h> | 50 #include <google/protobuf/stubs/common.h> |
| 51 #include <google/protobuf/stubs/scoped_ptr.h> |
| 51 #include <google/protobuf/testing/googletest.h> | 52 #include <google/protobuf/testing/googletest.h> |
| 52 #include <gtest/gtest.h> | 53 #include <gtest/gtest.h> |
| 53 | 54 |
| 54 namespace google { | 55 namespace google { |
| 55 namespace protobuf { | 56 namespace protobuf { |
| 56 namespace { | 57 namespace { |
| 57 | 58 |
| 58 static void AddToDatabase(SimpleDescriptorDatabase* database, | 59 static void AddToDatabase(SimpleDescriptorDatabase* database, |
| 59 const char* file_text) { | 60 const char* file_text) { |
| 60 FileDescriptorProto file_proto; | 61 FileDescriptorProto file_proto; |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 "dependency: \"foo.proto\" " | 404 "dependency: \"foo.proto\" " |
| 404 "message_type { " | 405 "message_type { " |
| 405 " name: \"Bar\" " | 406 " name: \"Bar\" " |
| 406 " extension_range { start: 1 end: 1000 } " | 407 " extension_range { start: 1 end: 1000 } " |
| 407 "} " | 408 "} " |
| 408 "extension { name:\"grault\" extendee: \".Foo\" number:32 } " | 409 "extension { name:\"grault\" extendee: \".Foo\" number:32 } " |
| 409 "extension { name:\"garply\" extendee: \".corge.Bar\" number:70 } " | 410 "extension { name:\"garply\" extendee: \".corge.Bar\" number:70 } " |
| 410 "extension { name:\"waldo\" extendee: \"Bar\" number:56 } "); | 411 "extension { name:\"waldo\" extendee: \"Bar\" number:56 } "); |
| 411 | 412 |
| 412 { | 413 { |
| 413 std::vector<int> numbers; | 414 vector<int> numbers; |
| 414 EXPECT_TRUE(database_->FindAllExtensionNumbers("Foo", &numbers)); | 415 EXPECT_TRUE(database_->FindAllExtensionNumbers("Foo", &numbers)); |
| 415 ASSERT_EQ(2, numbers.size()); | 416 ASSERT_EQ(2, numbers.size()); |
| 416 std::sort(numbers.begin(), numbers.end()); | 417 std::sort(numbers.begin(), numbers.end()); |
| 417 EXPECT_EQ(5, numbers[0]); | 418 EXPECT_EQ(5, numbers[0]); |
| 418 EXPECT_EQ(32, numbers[1]); | 419 EXPECT_EQ(32, numbers[1]); |
| 419 } | 420 } |
| 420 | 421 |
| 421 { | 422 { |
| 422 std::vector<int> numbers; | 423 vector<int> numbers; |
| 423 EXPECT_TRUE(database_->FindAllExtensionNumbers("corge.Bar", &numbers)); | 424 EXPECT_TRUE(database_->FindAllExtensionNumbers("corge.Bar", &numbers)); |
| 424 // Note: won't find extension 56 due to the name not being fully qualified. | 425 // Note: won't find extension 56 due to the name not being fully qualified. |
| 425 ASSERT_EQ(1, numbers.size()); | 426 ASSERT_EQ(1, numbers.size()); |
| 426 EXPECT_EQ(70, numbers[0]); | 427 EXPECT_EQ(70, numbers[0]); |
| 427 } | 428 } |
| 428 | 429 |
| 429 { | 430 { |
| 430 // Can't find extensions for non-existent types. | 431 // Can't find extensions for non-existent types. |
| 431 std::vector<int> numbers; | 432 vector<int> numbers; |
| 432 EXPECT_FALSE(database_->FindAllExtensionNumbers("NoSuchType", &numbers)); | 433 EXPECT_FALSE(database_->FindAllExtensionNumbers("NoSuchType", &numbers)); |
| 433 } | 434 } |
| 434 | 435 |
| 435 { | 436 { |
| 436 // Can't find extensions for unqualified types. | 437 // Can't find extensions for unqualified types. |
| 437 std::vector<int> numbers; | 438 vector<int> numbers; |
| 438 EXPECT_FALSE(database_->FindAllExtensionNumbers("Bar", &numbers)); | 439 EXPECT_FALSE(database_->FindAllExtensionNumbers("Bar", &numbers)); |
| 439 } | 440 } |
| 440 } | 441 } |
| 441 | 442 |
| 442 TEST_P(DescriptorDatabaseTest, ConflictingFileError) { | 443 TEST_P(DescriptorDatabaseTest, ConflictingFileError) { |
| 443 AddToDatabase( | 444 AddToDatabase( |
| 444 "name: \"foo.proto\" " | 445 "name: \"foo.proto\" " |
| 445 "message_type { " | 446 "message_type { " |
| 446 " name: \"Foo\" " | 447 " name: \"Foo\" " |
| 447 "}"); | 448 "}"); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 // Can't find non-existent extension. | 702 // Can't find non-existent extension. |
| 702 FileDescriptorProto file; | 703 FileDescriptorProto file; |
| 703 EXPECT_FALSE( | 704 EXPECT_FALSE( |
| 704 forward_merged_.FindFileContainingExtension("Foo", 6, &file)); | 705 forward_merged_.FindFileContainingExtension("Foo", 6, &file)); |
| 705 } | 706 } |
| 706 } | 707 } |
| 707 | 708 |
| 708 TEST_F(MergedDescriptorDatabaseTest, FindAllExtensionNumbers) { | 709 TEST_F(MergedDescriptorDatabaseTest, FindAllExtensionNumbers) { |
| 709 { | 710 { |
| 710 // Message only has extension in database1_ | 711 // Message only has extension in database1_ |
| 711 std::vector<int> numbers; | 712 vector<int> numbers; |
| 712 EXPECT_TRUE(forward_merged_.FindAllExtensionNumbers("Foo", &numbers)); | 713 EXPECT_TRUE(forward_merged_.FindAllExtensionNumbers("Foo", &numbers)); |
| 713 ASSERT_EQ(1, numbers.size()); | 714 ASSERT_EQ(1, numbers.size()); |
| 714 EXPECT_EQ(3, numbers[0]); | 715 EXPECT_EQ(3, numbers[0]); |
| 715 } | 716 } |
| 716 | 717 |
| 717 { | 718 { |
| 718 // Message only has extension in database2_ | 719 // Message only has extension in database2_ |
| 719 std::vector<int> numbers; | 720 vector<int> numbers; |
| 720 EXPECT_TRUE(forward_merged_.FindAllExtensionNumbers("Bar", &numbers)); | 721 EXPECT_TRUE(forward_merged_.FindAllExtensionNumbers("Bar", &numbers)); |
| 721 ASSERT_EQ(1, numbers.size()); | 722 ASSERT_EQ(1, numbers.size()); |
| 722 EXPECT_EQ(5, numbers[0]); | 723 EXPECT_EQ(5, numbers[0]); |
| 723 } | 724 } |
| 724 | 725 |
| 725 { | 726 { |
| 726 // Merge results from the two databases. | 727 // Merge results from the two databases. |
| 727 std::vector<int> numbers; | 728 vector<int> numbers; |
| 728 EXPECT_TRUE(forward_merged_.FindAllExtensionNumbers("Baz", &numbers)); | 729 EXPECT_TRUE(forward_merged_.FindAllExtensionNumbers("Baz", &numbers)); |
| 729 ASSERT_EQ(2, numbers.size()); | 730 ASSERT_EQ(2, numbers.size()); |
| 730 std::sort(numbers.begin(), numbers.end()); | 731 std::sort(numbers.begin(), numbers.end()); |
| 731 EXPECT_EQ(12, numbers[0]); | 732 EXPECT_EQ(12, numbers[0]); |
| 732 EXPECT_EQ(13, numbers[1]); | 733 EXPECT_EQ(13, numbers[1]); |
| 733 } | 734 } |
| 734 | 735 |
| 735 { | 736 { |
| 736 std::vector<int> numbers; | 737 vector<int> numbers; |
| 737 EXPECT_TRUE(reverse_merged_.FindAllExtensionNumbers("Baz", &numbers)); | 738 EXPECT_TRUE(reverse_merged_.FindAllExtensionNumbers("Baz", &numbers)); |
| 738 ASSERT_EQ(2, numbers.size()); | 739 ASSERT_EQ(2, numbers.size()); |
| 739 std::sort(numbers.begin(), numbers.end()); | 740 std::sort(numbers.begin(), numbers.end()); |
| 740 EXPECT_EQ(12, numbers[0]); | 741 EXPECT_EQ(12, numbers[0]); |
| 741 EXPECT_EQ(13, numbers[1]); | 742 EXPECT_EQ(13, numbers[1]); |
| 742 } | 743 } |
| 743 | 744 |
| 744 { | 745 { |
| 745 // Can't find extensions for a non-existent message. | 746 // Can't find extensions for a non-existent message. |
| 746 std::vector<int> numbers; | 747 vector<int> numbers; |
| 747 EXPECT_FALSE(reverse_merged_.FindAllExtensionNumbers("Blah", &numbers)); | 748 EXPECT_FALSE(reverse_merged_.FindAllExtensionNumbers("Blah", &numbers)); |
| 748 } | 749 } |
| 749 } | 750 } |
| 750 | 751 |
| 751 } // anonymous namespace | 752 } // anonymous namespace |
| 752 } // namespace protobuf | 753 } // namespace protobuf |
| 753 } // namespace google | 754 } // namespace google |
| OLD | NEW |