72 MockErrorCollector() {}
73 ~MockErrorCollector() {}
78 void AddError(
const std::string& filename,
int line,
int column,
85 class MockGeneratorContext :
public GeneratorContext {
87 MockGeneratorContext() {}
90 void ExpectFileMatches(
const std::string& virtual_filename,
95 <<
"Generator failed to generate file: " << virtual_filename;
100 &actual_contents,
true))
101 << physical_filename;
104 #ifdef WRITE_FILES // Define to debug mismatched files.
111 ASSERT_EQ(*expected_contents, actual_contents)
113 <<
" needs to be regenerated. Please run "
114 "generate_descriptor_proto.sh. "
115 "Then add this file to your CL.";
120 virtual io::ZeroCopyOutputStream* Open(
const std::string& filename) {
125 return new io::StringOutputStream(*map_slot);
129 std::map<std::string, std::string*>
files_;
132 const char kDescriptorParameter[] =
"dllexport_decl=PROTOBUF_EXPORT";
133 const char kPluginParameter[] =
"dllexport_decl=PROTOC_EXPORT";
136 const char* test_protos[][2] = {
137 {
"google/protobuf/descriptor", kDescriptorParameter},
138 {
"google/protobuf/compiler/plugin", kPluginParameter},
141 TEST(BootstrapTest, GeneratedFilesMatch) {
144 std::map<std::string, std::string> vpath_map;
145 std::map<std::string, std::string> rpath_map;
147 [
"third_party/protobuf_legacy_opensource/src/google/protobuf/"
148 "test_messages_proto2"] =
149 "net/proto2/z_generated_example/test_messages_proto2";
151 [
"third_party/protobuf_legacy_opensource/src/google/protobuf/"
152 "test_messages_proto3"] =
153 "net/proto2/z_generated_example/test_messages_proto3";
154 rpath_map[
"net/proto2/internal/proto2_weak"] =
155 "net/proto2/z_generated_example/proto2_weak";
157 DiskSourceTree source_tree;
160 for (
auto file_parameter : test_protos) {
161 MockErrorCollector error_collector;
162 Importer importer(&source_tree, &error_collector);
164 importer.Import(file_parameter[0] +
std::string(
".proto"));
166 <<
"Can't import file " << file_parameter[0] +
string(
".proto") <<
"\n";
168 CppGenerator generator;
169 MockGeneratorContext context;
170 #ifdef GOOGLE_PROTOBUF_RUNTIME_INCLUDE_BASE
171 generator.set_opensource_runtime(
true);
172 generator.set_runtime_include_base(GOOGLE_PROTOBUF_RUNTIME_INCLUDE_BASE);
181 context.ExpectFileMatches(vpath +
".pb.cc", rpath +
".pb.cc");
182 context.ExpectFileMatches(vpath +
".pb.h", rpath +
".pb.h");