55 class TestGenerator :
public CodeGenerator {
61 const std::string& parameter, GeneratorContext* context,
63 TryInsert(
"test.pb.h",
"includes", context);
64 TryInsert(
"test.pb.h",
"namespace_scope", context);
65 TryInsert(
"test.pb.h",
"global_scope", context);
66 TryInsert(
"test.pb.h",
"class_scope:foo.Bar", context);
67 TryInsert(
"test.pb.h",
"class_scope:foo.Bar.Baz", context);
69 TryInsert(
"test.pb.cc",
"includes", context);
70 TryInsert(
"test.pb.cc",
"namespace_scope", context);
71 TryInsert(
"test.pb.cc",
"global_scope", context);
74 TryInsert(
"test.pb.h",
"field_get:foo.Bar.optInt", context);
75 TryInsert(
"test.pb.h",
"field_set:foo.Bar.optInt", context);
78 TryInsert(
"test.pb.h",
"field_get:foo.Bar.repeatedInt", context);
79 TryInsert(
"test.pb.h",
"field_set:foo.Bar.repeatedInt", context);
82 TryInsert(
"test.pb.h",
"field_get:foo.Bar.requiredString", context);
83 TryInsert(
"test.pb.h",
"field_set:foo.Bar.requiredString", context);
84 TryInsert(
"test.pb.h",
"field_set_char:foo.Bar.requiredString", context);
85 TryInsert(
"test.pb.h",
"field_set_pointer:foo.Bar.requiredString", context);
86 TryInsert(
"test.pb.h",
"field_mutable:foo.Bar.requiredString", context);
87 TryInsert(
"test.pb.h",
"field_set_allocated:foo.Bar.requiredString",
89 TryInsert(
"test.pb.h",
"field_set_char:foo.Bar.requiredString", context);
90 TryInsert(
"test.pb.h",
"field_set_pointer:foo.Bar.requiredString", context);
93 TryInsert(
"test.pb.h",
"field_get:foo.Bar.repeatedString", context);
94 TryInsert(
"test.pb.h",
"field_set:foo.Bar.repeatedString", context);
95 TryInsert(
"test.pb.h",
"field_set_char:foo.Bar.repeatedString", context);
96 TryInsert(
"test.pb.h",
"field_set_pointer:foo.Bar.repeatedString", context);
97 TryInsert(
"test.pb.h",
"field_mutable:foo.Bar.repeatedString", context);
98 TryInsert(
"test.pb.h",
"field_set_char:foo.Bar.repeatedString", context);
99 TryInsert(
"test.pb.h",
"field_set_pointer:foo.Bar.repeatedString", context);
102 TryInsert(
"test.pb.h",
"field_get:foo.Bar.oneOfInt", context);
103 TryInsert(
"test.pb.h",
"field_set:foo.Bar.oneOfInt", context);
106 TryInsert(
"test.pb.h",
"field_get:foo.Bar.oneOfString", context);
107 TryInsert(
"test.pb.h",
"field_set:foo.Bar.oneOfString", context);
108 TryInsert(
"test.pb.h",
"field_set_char:foo.Bar.oneOfString", context);
109 TryInsert(
"test.pb.h",
"field_set_pointer:foo.Bar.oneOfString", context);
110 TryInsert(
"test.pb.h",
"field_mutable:foo.Bar.oneOfString", context);
111 TryInsert(
"test.pb.h",
"field_set_allocated:foo.Bar.oneOfString", context);
112 TryInsert(
"test.pb.h",
"field_set_char:foo.Bar.oneOfString", context);
113 TryInsert(
"test.pb.h",
"field_set_pointer:foo.Bar.oneOfString", context);
116 TryInsert(
"test.pb.h",
"field_get:foo.Bar.optMessage", context);
117 TryInsert(
"test.pb.h",
"field_mutable:foo.Bar.optMessage", context);
118 TryInsert(
"test.pb.h",
"field_set_allocated:foo.Bar.optMessage", context);
121 TryInsert(
"test.pb.h",
"field_add:foo.Bar.repeatedMessage", context);
122 TryInsert(
"test.pb.h",
"field_get:foo.Bar.repeatedMessage", context);
123 TryInsert(
"test.pb.h",
"field_list:foo.Bar.repeatedMessage", context);
124 TryInsert(
"test.pb.h",
"field_mutable:foo.Bar.repeatedMessage", context);
125 TryInsert(
"test.pb.h",
"field_mutable_list:foo.Bar.repeatedMessage",
129 TryInsert(
"test.pb.h",
"field_get:foo.Bar.oneOfMessage", context);
130 TryInsert(
"test.pb.h",
"field_mutable:foo.Bar.oneOfMessage", context);
131 TryInsert(
"test.pb.cc",
"field_set_allocated:foo.Bar.oneOfMessage",
135 TryInsert(
"test.pb.h",
"field_get:foo.Bar.optEnum", context);
136 TryInsert(
"test.pb.h",
"field_set:foo.Bar.optEnum", context);
139 TryInsert(
"test.pb.h",
"field_get:foo.Bar.repeatedEnum", context);
140 TryInsert(
"test.pb.h",
"field_set:foo.Bar.repeatedEnum", context);
141 TryInsert(
"test.pb.h",
"field_add:foo.Bar.repeatedEnum", context);
142 TryInsert(
"test.pb.h",
"field_list:foo.Bar.repeatedEnum", context);
143 TryInsert(
"test.pb.h",
"field_mutable_list:foo.Bar.repeatedEnum", context);
146 TryInsert(
"test.pb.h",
"field_get:foo.Bar.oneOfEnum", context);
147 TryInsert(
"test.pb.h",
"field_set:foo.Bar.oneOfEnum", context);
150 TryInsert(
"test.pb.h",
"field_get:foo.Bar.requiredCord", context);
151 TryInsert(
"test.pb.h",
"field_set:foo.Bar.requiredCord", context);
152 TryInsert(
"test.pb.h",
"field_mutable:foo.Bar.requiredCord", context);
155 TryInsert(
"test.pb.h",
"field_get:foo.Bar.repeatedCord", context);
156 TryInsert(
"test.pb.h",
"field_set:foo.Bar.repeatedCord", context);
157 TryInsert(
"test.pb.h",
"field_add:foo.Bar.repeatedCord", context);
158 TryInsert(
"test.pb.h",
"field_list:foo.Bar.repeatedCord", context);
159 TryInsert(
"test.pb.h",
"field_mutable:foo.Bar.repeatedCord", context);
160 TryInsert(
"test.pb.h",
"field_mutable_list:foo.Bar.repeatedCord", context);
163 TryInsert(
"test.pb.h",
"field_get:foo.Bar.oneOfCord", context);
164 TryInsert(
"test.pb.h",
"field_set:foo.Bar.oneOfCord", context);
165 TryInsert(
"test.pb.h",
"field_mutable:foo.Bar.oneOfCord", context);
172 GeneratorContext* context)
const {
173 std::unique_ptr<io::ZeroCopyOutputStream>
output(
174 context->OpenForInsert(filename, insertion_point));
175 io::Printer printer(
output.get(),
'$');
176 printer.Print(
"// inserted $name$\n",
"name", insertion_point);
183 TEST(CppPluginTest, PluginTest) {
185 "syntax = \"proto2\";\n"
188 "enum Thud { VALUE = 0; }\n"
192 " optional int32 optInt = 1;\n"
193 " repeated int32 repeatedInt = 2;\n"
195 " required string requiredString = 3;\n"
196 " repeated string repeatedString = 4;\n"
198 " optional Baz optMessage = 6;\n"
199 " repeated Baz repeatedMessage = 7;\n"
201 " optional Thud optEnum = 8;\n"
202 " repeated Thud repeatedEnum = 9;\n"
204 " required string requiredCord = 10 [\n"
207 " repeated string repeatedCord = 11 [\n"
212 " int64 oneOfInt = 20;\n"
213 " string oneOfString = 21;\n"
214 " Baz oneOfMessage = 22;\n"
215 " Thud oneOfEnum = 23;"
216 " string oneOfCord = 24 [\n"
223 CommandLineInterface cli;
224 cli.SetInputsAreProtoPathRelative(
true);
226 CppGenerator cpp_generator;
227 TestGenerator test_generator;
228 cli.RegisterGenerator(
"--cpp_out", &cpp_generator,
"");
229 cli.RegisterGenerator(
"--test_out", &test_generator,
"");
235 const char* argv[] = {
"protoc", proto_path.c_str(), cpp_out.c_str(),
236 test_out.c_str(),
"test.proto"};