Index: third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc |
diff --git a/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc |
index 5c4aa4fbc598ece07fa847f7c903338c570dbd5d..d1efbfe6d0f0d4b2d88f9b1c693c479926f0c4e4 100644 |
--- a/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc |
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc |
@@ -1,6 +1,6 @@ |
// Protocol Buffers - Google's data interchange format |
// Copyright 2008 Google Inc. All rights reserved. |
-// http://code.google.com/p/protobuf/ |
+// https://developers.google.com/protocol-buffers/ |
// |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
@@ -34,6 +34,11 @@ |
// It seemed like parameterizing it would add more complexity than it is |
// worth. |
+#include <memory> |
+#ifndef _SHARED_PTR_H |
+#include <google/protobuf/stubs/shared_ptr.h> |
+#endif |
+ |
#include <google/protobuf/compiler/cpp/cpp_generator.h> |
#include <google/protobuf/compiler/command_line_interface.h> |
#include <google/protobuf/io/zero_copy_stream.h> |
@@ -67,13 +72,107 @@ class TestGenerator : public CodeGenerator { |
TryInsert("test.pb.cc", "includes", context); |
TryInsert("test.pb.cc", "namespace_scope", context); |
TryInsert("test.pb.cc", "global_scope", context); |
+ |
+ // Check field accessors for an optional int32: |
+ TryInsert("test.pb.h", "field_get:foo.Bar.optInt", context); |
+ TryInsert("test.pb.h", "field_set:foo.Bar.optInt", context); |
+ |
+ // Check field accessors for a repeated int32: |
+ TryInsert("test.pb.h", "field_get:foo.Bar.repeatedInt", context); |
+ TryInsert("test.pb.h", "field_set:foo.Bar.repeatedInt", context); |
+ |
+ // Check field accessors for a required string: |
+ TryInsert("test.pb.h", "field_get:foo.Bar.requiredString", context); |
+ TryInsert("test.pb.h", "field_set:foo.Bar.requiredString", context); |
+ TryInsert("test.pb.h", "field_set_char:foo.Bar.requiredString", context); |
+ TryInsert("test.pb.h", "field_set_pointer:foo.Bar.requiredString", context); |
+ TryInsert("test.pb.h", "field_mutable:foo.Bar.requiredString", context); |
+ TryInsert("test.pb.h", "field_set_allocated:foo.Bar.requiredString", |
+ context); |
+ TryInsert("test.pb.h", "field_set_char:foo.Bar.requiredString", context); |
+ TryInsert("test.pb.h", "field_set_pointer:foo.Bar.requiredString", context); |
+ |
+ // Check field accessors for a repeated string: |
+ TryInsert("test.pb.h", "field_get:foo.Bar.repeatedString", context); |
+ TryInsert("test.pb.h", "field_set:foo.Bar.repeatedString", context); |
+ TryInsert("test.pb.h", "field_set_char:foo.Bar.repeatedString", context); |
+ TryInsert("test.pb.h", "field_set_pointer:foo.Bar.repeatedString", context); |
+ TryInsert("test.pb.h", "field_mutable:foo.Bar.repeatedString", context); |
+ TryInsert("test.pb.h", "field_set_char:foo.Bar.repeatedString", context); |
+ TryInsert("test.pb.h", "field_set_pointer:foo.Bar.repeatedString", context); |
+ |
+ // Check field accessors for an int inside oneof{}: |
+ TryInsert("test.pb.h", "field_get:foo.Bar.oneOfInt", context); |
+ TryInsert("test.pb.h", "field_set:foo.Bar.oneOfInt", context); |
+ |
+ // Check field accessors for a string inside oneof{}: |
+ TryInsert("test.pb.h", "field_get:foo.Bar.oneOfString", context); |
+ TryInsert("test.pb.h", "field_set:foo.Bar.oneOfString", context); |
+ TryInsert("test.pb.h", "field_set_char:foo.Bar.oneOfString", context); |
+ TryInsert("test.pb.h", "field_set_pointer:foo.Bar.oneOfString", context); |
+ TryInsert("test.pb.h", "field_mutable:foo.Bar.oneOfString", context); |
+ TryInsert("test.pb.h", "field_set_allocated:foo.Bar.oneOfString", context); |
+ TryInsert("test.pb.h", "field_set_char:foo.Bar.oneOfString", context); |
+ TryInsert("test.pb.h", "field_set_pointer:foo.Bar.oneOfString", context); |
+ |
+ // Check field accessors for an optional message: |
+ TryInsert("test.pb.h", "field_get:foo.Bar.optMessage", context); |
+ TryInsert("test.pb.h", "field_mutable:foo.Bar.optMessage", context); |
+ TryInsert("test.pb.h", "field_set_allocated:foo.Bar.optMessage", context); |
+ |
+ // Check field accessors for a repeated message: |
+ TryInsert("test.pb.h", "field_add:foo.Bar.repeatedMessage", context); |
+ TryInsert("test.pb.h", "field_get:foo.Bar.repeatedMessage", context); |
+ TryInsert("test.pb.h", "field_list:foo.Bar.repeatedMessage", context); |
+ TryInsert("test.pb.h", "field_mutable:foo.Bar.repeatedMessage", context); |
+ TryInsert("test.pb.h", "field_mutable_list:foo.Bar.repeatedMessage", |
+ context); |
+ |
+ // Check field accessors for a message inside oneof{}: |
+ TryInsert("test.pb.h", "field_get:foo.Bar.oneOfMessage", context); |
+ TryInsert("test.pb.h", "field_mutable:foo.Bar.oneOfMessage", context); |
+ TryInsert("test.pb.h", "field_set_allocated:foo.Bar.oneOfMessage", context); |
+ |
+ // Check field accessors for an optional enum: |
+ TryInsert("test.pb.h", "field_get:foo.Bar.optEnum", context); |
+ TryInsert("test.pb.h", "field_set:foo.Bar.optEnum", context); |
+ |
+ // Check field accessors for a repeated enum: |
+ TryInsert("test.pb.h", "field_get:foo.Bar.repeatedEnum", context); |
+ TryInsert("test.pb.h", "field_set:foo.Bar.repeatedEnum", context); |
+ TryInsert("test.pb.h", "field_add:foo.Bar.repeatedEnum", context); |
+ TryInsert("test.pb.h", "field_list:foo.Bar.repeatedEnum", context); |
+ TryInsert("test.pb.h", "field_mutable_list:foo.Bar.repeatedEnum", context); |
+ |
+ // Check field accessors for an enum inside oneof{}: |
+ TryInsert("test.pb.h", "field_get:foo.Bar.oneOfEnum", context); |
+ TryInsert("test.pb.h", "field_set:foo.Bar.oneOfEnum", context); |
+ |
+ // Check field accessors for a required cord: |
+ TryInsert("test.pb.h", "field_get:foo.Bar.requiredCord", context); |
+ TryInsert("test.pb.h", "field_set:foo.Bar.requiredCord", context); |
+ TryInsert("test.pb.h", "field_mutable:foo.Bar.requiredCord", context); |
+ |
+ // Check field accessors for a repeated cord: |
+ TryInsert("test.pb.h", "field_get:foo.Bar.repeatedCord", context); |
+ TryInsert("test.pb.h", "field_set:foo.Bar.repeatedCord", context); |
+ TryInsert("test.pb.h", "field_add:foo.Bar.repeatedCord", context); |
+ TryInsert("test.pb.h", "field_list:foo.Bar.repeatedCord", context); |
+ TryInsert("test.pb.h", "field_mutable:foo.Bar.repeatedCord", context); |
+ TryInsert("test.pb.h", "field_mutable_list:foo.Bar.repeatedCord", context); |
+ |
+ // Check field accessors for a cord inside oneof{}: |
+ TryInsert("test.pb.h", "field_get:foo.Bar.oneOfCord", context); |
+ TryInsert("test.pb.h", "field_set:foo.Bar.oneOfCord", context); |
+ TryInsert("test.pb.h", "field_mutable:foo.Bar.oneOfCord", context); |
+ |
return true; |
} |
void TryInsert(const string& filename, const string& insertion_point, |
GeneratorContext* context) const { |
- scoped_ptr<io::ZeroCopyOutputStream> output( |
- context->OpenForInsert(filename, insertion_point)); |
+ google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output( |
+ context->OpenForInsert(filename, insertion_point)); |
io::Printer printer(output.get(), '$'); |
printer.Print("// inserted $name$\n", "name", insertion_point); |
} |
@@ -83,13 +182,44 @@ class TestGenerator : public CodeGenerator { |
// not verify that they are correctly-placed; that would require actually |
// compiling the output which is a bit more than I care to do for this test. |
TEST(CppPluginTest, PluginTest) { |
- File::WriteStringToFileOrDie( |
- "syntax = \"proto2\";\n" |
- "package foo;\n" |
- "message Bar {\n" |
- " message Baz {}\n" |
- "}\n", |
- TestTempDir() + "/test.proto"); |
+ GOOGLE_CHECK_OK(File::SetContents(TestTempDir() + "/test.proto", |
+ "syntax = \"proto2\";\n" |
+ "package foo;\n" |
+ "\n" |
+ "enum Thud { VALUE = 0; }\n" |
+ "\n" |
+ "message Bar {\n" |
+ " message Baz {}\n" |
+ " optional int32 optInt = 1;\n" |
+ " repeated int32 repeatedInt = 2;\n" |
+ "\n" |
+ " required string requiredString = 3;\n" |
+ " repeated string repeatedString = 4;\n" |
+ "\n" |
+ " optional Baz optMessage = 6;\n" |
+ " repeated Baz repeatedMessage = 7;\n" |
+ "\n" |
+ " optional Thud optEnum = 8;\n" |
+ " repeated Thud repeatedEnum = 9;\n" |
+ "\n" |
+ " required string requiredCord = 10 [\n" |
+ " ctype = CORD\n" |
+ " ];\n" |
+ " repeated string repeatedCord = 11 [\n" |
+ " ctype = CORD\n" |
+ " ];\n" |
+ "\n" |
+ " oneof Qux {\n" |
+ " int64 oneOfInt = 20;\n" |
+ " string oneOfString = 21;\n" |
+ " Baz oneOfMessage = 22;\n" |
+ " Thud oneOfEnum = 23;" |
+ " string oneOfCord = 24 [\n" |
+ " ctype = CORD\n" |
+ " ];\n" |
+ " }\n" |
+ "}\n", |
+ true)); |
google::protobuf::compiler::CommandLineInterface cli; |
cli.SetInputsAreProtoPathRelative(true); |