34
34
// generated automatically at build time.
35
35
//
36
36
// If this test fails, run the script
37
- // "generate_descriptor_proto.sh" and add
38
- // csharp/src/Google.Protobuf/Reflection/Descriptor.cs to your changelist.
37
+ // "generate_descriptor_proto.sh" and add the changed files under
38
+ // csharp/src/ to your changelist.
39
39
40
40
#include < map>
41
41
@@ -91,7 +91,8 @@ class MockGeneratorContext : public GeneratorContext {
91
91
string actual_contents;
92
92
GOOGLE_CHECK_OK (
93
93
File::GetContents (TestSourceDir () + " /" + physical_filename,
94
- &actual_contents, true ));
94
+ &actual_contents, true ))
95
+ << " Unable to get " << physical_filename;
95
96
EXPECT_TRUE (actual_contents == *expected_contents)
96
97
<< physical_filename << " needs to be regenerated. Please run "
97
98
" generate_descriptor_proto.sh. Then add this file "
@@ -112,26 +113,80 @@ class MockGeneratorContext : public GeneratorContext {
112
113
std::map<string, string*> files_;
113
114
};
114
115
116
+ class GenerateAndTest {
117
+ public:
118
+ GenerateAndTest () {}
119
+ void Run (const FileDescriptor* proto_file, string file1, string file2) {
120
+ ASSERT_TRUE (proto_file != NULL ) << TestSourceDir ();
121
+ ASSERT_TRUE (generator_.Generate (proto_file, parameter_,
122
+ &context_, &error_));
123
+ context_.ExpectFileMatches (file1, file2);
124
+ }
125
+ void SetParameter (string parameter) {
126
+ parameter_ = parameter;
127
+ }
128
+
129
+ private:
130
+ Generator generator_;
131
+ MockGeneratorContext context_;
132
+ string error_;
133
+ string parameter_;
134
+ };
135
+
115
136
TEST (CsharpBootstrapTest, GeneratedCsharpDescriptorMatches) {
116
137
MockErrorCollector error_collector;
117
138
DiskSourceTree source_tree;
118
- source_tree.MapPath (" " , TestSourceDir ());
119
139
Importer importer (&source_tree, &error_collector);
120
- const FileDescriptor* proto_file =
121
- importer.Import (" google/protobuf/descriptor.proto" );
140
+ GenerateAndTest generate_test;
141
+
142
+ generate_test.SetParameter (" base_namespace=Google.Protobuf" );
143
+ source_tree.MapPath (" " , TestSourceDir ());
144
+ generate_test.Run (importer.Import (" google/protobuf/descriptor.proto" ),
145
+ " Reflection/Descriptor.cs" ,
146
+ " ../csharp/src/Google.Protobuf/Reflection/Descriptor.cs" );
147
+ generate_test.Run (importer.Import (" google/protobuf/any.proto" ),
148
+ " WellKnownTypes/Any.cs" ,
149
+ " ../csharp/src/Google.Protobuf/WellKnownTypes/Any.cs" );
150
+ generate_test.Run (importer.Import (" google/protobuf/api.proto" ),
151
+ " WellKnownTypes/Api.cs" ,
152
+ " ../csharp/src/Google.Protobuf/WellKnownTypes/Api.cs" );
153
+ generate_test.Run (importer.Import (" google/protobuf/duration.proto" ),
154
+ " WellKnownTypes/Duration.cs" ,
155
+ " ../csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs" );
156
+ generate_test.Run (importer.Import (" google/protobuf/empty.proto" ),
157
+ " WellKnownTypes/Empty.cs" ,
158
+ " ../csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs" );
159
+ generate_test.Run (importer.Import (" google/protobuf/field_mask.proto" ),
160
+ " WellKnownTypes/FieldMask.cs" ,
161
+ " ../csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs" );
162
+ generate_test.Run (importer.Import (" google/protobuf/source_context.proto" ),
163
+ " WellKnownTypes/SourceContext.cs" ,
164
+ " ../csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs" );
165
+ generate_test.Run (importer.Import (" google/protobuf/struct.proto" ),
166
+ " WellKnownTypes/Struct.cs" ,
167
+ " ../csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs" );
168
+ generate_test.Run (importer.Import (" google/protobuf/timestamp.proto" ),
169
+ " WellKnownTypes/Timestamp.cs" ,
170
+ " ../csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs" );
171
+ generate_test.Run (importer.Import (" google/protobuf/type.proto" ),
172
+ " WellKnownTypes/Type.cs" ,
173
+ " ../csharp/src/Google.Protobuf/WellKnownTypes/Type.cs" );
174
+ generate_test.Run (importer.Import (" google/protobuf/wrappers.proto" ),
175
+ " WellKnownTypes/Wrappers.cs" ,
176
+ " ../csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs" );
177
+
178
+ generate_test.SetParameter (" " );
179
+ source_tree.MapPath (" " , TestSourceDir () + " /../examples" );
180
+ generate_test.Run (importer.Import (" addressbook.proto" ),
181
+ " Addressbook.cs" ,
182
+ " ../csharp/src/AddressBook/Addressbook.cs" );
183
+
184
+ source_tree.MapPath (" " , TestSourceDir () + " /../conformance" );
185
+ generate_test.Run (importer.Import (" conformance.proto" ),
186
+ " Conformance.cs" ,
187
+ " ../csharp/src/Google.Protobuf.Conformance/Conformance.cs" );
188
+
122
189
EXPECT_EQ (" " , error_collector.text_ );
123
- ASSERT_TRUE (proto_file != NULL );
124
-
125
- Generator generator;
126
- MockGeneratorContext context;
127
- string error;
128
- string parameter = " base_namespace=Google.Protobuf" ;
129
- ASSERT_TRUE (generator.Generate (proto_file, parameter,
130
- &context, &error));
131
-
132
- context.ExpectFileMatches (
133
- " Reflection/Descriptor.cs" ,
134
- " ../csharp/src/Google.Protobuf/Reflection/Descriptor.cs" );
135
190
}
136
191
137
192
} // namespace
0 commit comments