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