Test that generated code has proper descriptors: Parse a descriptor directly (using google::protobuf::compiler::Importer) and compare it to the one that was produced by generated code.
| 96 | // Parse a descriptor directly (using google::protobuf::compiler::Importer) and |
| 97 | // compare it to the one that was produced by generated code. |
| 98 | TEST(GeneratedDescriptorTest, IdenticalDescriptors) { |
| 99 | const FileDescriptor* generated_descriptor = |
| 100 | unittest::TestAllTypes::descriptor()->file(); |
| 101 | |
| 102 | // Set up the Importer. |
| 103 | MockErrorCollector error_collector; |
| 104 | DiskSourceTree source_tree; |
| 105 | source_tree.MapPath("", TestSourceDir()); |
| 106 | Importer importer(&source_tree, &error_collector); |
| 107 | |
| 108 | // Import (parse) unittest.proto. |
| 109 | const FileDescriptor* parsed_descriptor = |
| 110 | importer.Import("google/protobuf/unittest.proto"); |
| 111 | EXPECT_EQ("", error_collector.text_); |
| 112 | ASSERT_TRUE(parsed_descriptor != NULL); |
| 113 | |
| 114 | // Test that descriptors are generated correctly by converting them to |
| 115 | // FileDescriptorProtos and comparing. |
| 116 | FileDescriptorProto generated_decsriptor_proto, parsed_descriptor_proto; |
| 117 | generated_descriptor->CopyTo(&generated_decsriptor_proto); |
| 118 | parsed_descriptor->CopyTo(&parsed_descriptor_proto); |
| 119 | |
| 120 | EXPECT_EQ(parsed_descriptor_proto.DebugString(), |
| 121 | generated_decsriptor_proto.DebugString()); |
| 122 | } |
| 123 | |
| 124 | #endif // !PROTOBUF_TEST_NO_DESCRIPTORS |
| 125 |
nothing calls this directly
no test coverage detected