Skip to content

Commit a69bc9d

Browse files
authored
Merge pull request protocolbuffers#2822 from anandolee/master
Detect generated code of WKT, addressbook and conformance protos
2 parents f54fb9d + ae220cd commit a69bc9d

File tree

1 file changed

+73
-18
lines changed

1 file changed

+73
-18
lines changed

src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc

+73-18
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
// generated automatically at build time.
3535
//
3636
// 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.
3939

4040
#include <map>
4141

@@ -91,7 +91,8 @@ class MockGeneratorContext : public GeneratorContext {
9191
string actual_contents;
9292
GOOGLE_CHECK_OK(
9393
File::GetContents(TestSourceDir() + "/" + physical_filename,
94-
&actual_contents, true));
94+
&actual_contents, true))
95+
<< "Unable to get " << physical_filename;
9596
EXPECT_TRUE(actual_contents == *expected_contents)
9697
<< physical_filename << " needs to be regenerated. Please run "
9798
"generate_descriptor_proto.sh. Then add this file "
@@ -112,26 +113,80 @@ class MockGeneratorContext : public GeneratorContext {
112113
std::map<string, string*> files_;
113114
};
114115

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+
115136
TEST(CsharpBootstrapTest, GeneratedCsharpDescriptorMatches) {
116137
MockErrorCollector error_collector;
117138
DiskSourceTree source_tree;
118-
source_tree.MapPath("", TestSourceDir());
119139
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+
122189
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");
135190
}
136191

137192
} // namespace

0 commit comments

Comments
 (0)