33 #include <google/protobuf/testing/file.h>
34 #include <google/protobuf/testing/file.h>
35 #include <google/protobuf/compiler/cpp/cpp_helpers.h>
36 #include <google/protobuf/compiler/cpp/cpp_generator.h>
37 #include <google/protobuf/compiler/annotation_test_util.h>
38 #include <google/protobuf/compiler/command_line_interface.h>
39 #include <google/protobuf/descriptor.pb.h>
40 #include <google/protobuf/testing/googletest.h>
41 #include <gtest/gtest.h>
48 namespace atu = annotation_test_util;
62 CommandLineInterface cli;
63 CppGenerator cpp_generator;
64 cli.RegisterGenerator(
"--cpp_out", &cpp_generator,
"");
66 "--cpp_out=annotate_headers=true,"
67 "annotation_pragma_name=pragma_name,"
68 "annotation_guard_name=guard_name:" +
84 if (pb_h != NULL && pb_h_info != NULL) {
92 if (proto_h != NULL && proto_h_info != NULL) {
104 const char kSmallTestFile[] =
105 "syntax = \"proto2\";\n"
107 "enum Enum { VALUE = 0; }\n"
108 "message Message { }\n";
110 TEST_F(CppMetadataTest, CapturesEnumNames) {
116 CaptureMetadata(
"test.proto", &
file, &pb_h, &info, NULL, NULL, NULL));
118 std::vector<int> enum_path;
120 enum_path.push_back(0);
127 TEST_F(CppMetadataTest, AddsPragma) {
133 CaptureMetadata(
"test.proto", &
file, &pb_h, &info, NULL, NULL, NULL));
134 EXPECT_TRUE(pb_h.find(
"#ifdef guard_name") != std::string::npos);
135 EXPECT_TRUE(pb_h.find(
"#pragma pragma_name \"test.pb.h.meta\"") !=
139 TEST_F(CppMetadataTest, CapturesMessageNames) {
145 CaptureMetadata(
"test.proto", &
file, &pb_h, &info, NULL, NULL, NULL));
147 std::vector<int> message_path;
149 message_path.push_back(0);