65 MockErrorCollector() {}
66 ~MockErrorCollector() {}
71 void AddError(
const string& filename,
int line,
int column,
74 filename, line, column,
message);
78 class MockGeneratorContext :
public GeneratorContext {
80 void ExpectFileMatches(
const string& virtual_filename,
81 const string& physical_filename) {
82 auto it =
files_.find(virtual_filename);
84 <<
"Generator failed to generate file: " << virtual_filename;
85 string expected_contents = *
it->second;
87 string actual_contents;
90 &actual_contents,
true))
91 <<
"Unable to get " << physical_filename;
93 << physical_filename <<
" needs to be regenerated. Please run "
94 "generate_descriptor_proto.sh. Then add this file "
100 virtual io::ZeroCopyOutputStream* Open(
const string& filename) {
101 auto& map_slot =
files_[filename];
103 return new io::StringOutputStream(map_slot.get());
107 std::map<std::string, std::unique_ptr<std::string>>
files_;
110 class GenerateAndTest {
117 context_.ExpectFileMatches(file1, file2);
119 void SetParameter(
string parameter) {
130 TEST(CsharpBootstrapTest, GeneratedCsharpDescriptorMatches) {
133 string descriptor_file_name =
134 "../csharp/src/Google.Protobuf/Reflection/Descriptor.cs";
139 MockErrorCollector error_collector;
140 DiskSourceTree source_tree;
141 Importer importer(&source_tree, &error_collector);
142 GenerateAndTest generate_test;
144 generate_test.SetParameter(
"base_namespace=Google.Protobuf");
146 generate_test.Run(importer.Import(
"google/protobuf/descriptor.proto"),
147 "Reflection/Descriptor.cs",
148 "../csharp/src/Google.Protobuf/Reflection/Descriptor.cs");
149 generate_test.Run(importer.Import(
"google/protobuf/any.proto"),
150 "WellKnownTypes/Any.cs",
151 "../csharp/src/Google.Protobuf/WellKnownTypes/Any.cs");
152 generate_test.Run(importer.Import(
"google/protobuf/api.proto"),
153 "WellKnownTypes/Api.cs",
154 "../csharp/src/Google.Protobuf/WellKnownTypes/Api.cs");
155 generate_test.Run(importer.Import(
"google/protobuf/duration.proto"),
156 "WellKnownTypes/Duration.cs",
157 "../csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs");
158 generate_test.Run(importer.Import(
"google/protobuf/empty.proto"),
159 "WellKnownTypes/Empty.cs",
160 "../csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs");
161 generate_test.Run(importer.Import(
"google/protobuf/field_mask.proto"),
162 "WellKnownTypes/FieldMask.cs",
163 "../csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs");
164 generate_test.Run(importer.Import(
"google/protobuf/source_context.proto"),
165 "WellKnownTypes/SourceContext.cs",
166 "../csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs");
167 generate_test.Run(importer.Import(
"google/protobuf/struct.proto"),
168 "WellKnownTypes/Struct.cs",
169 "../csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs");
170 generate_test.Run(importer.Import(
"google/protobuf/timestamp.proto"),
171 "WellKnownTypes/Timestamp.cs",
172 "../csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs");
173 generate_test.Run(importer.Import(
"google/protobuf/type.proto"),
174 "WellKnownTypes/Type.cs",
175 "../csharp/src/Google.Protobuf/WellKnownTypes/Type.cs");
176 generate_test.Run(importer.Import(
"google/protobuf/wrappers.proto"),
177 "WellKnownTypes/Wrappers.cs",
178 "../csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs");
180 generate_test.SetParameter(
"");
181 source_tree.MapPath(
"",
TestSourceDir() +
"/../conformance");
182 generate_test.Run(importer.Import(
"conformance.proto"),
184 "../csharp/src/Google.Protobuf.Conformance/Conformance.cs");