aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/command_line_interface_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/command_line_interface_unittest.cc')
-rw-r--r--src/google/protobuf/compiler/command_line_interface_unittest.cc45
1 files changed, 36 insertions, 9 deletions
diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc
index adeb4cd5..0ebf9b6a 100644
--- a/src/google/protobuf/compiler/command_line_interface_unittest.cc
+++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc
@@ -60,17 +60,19 @@
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
+#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
-// Disable the whole test when we use tcmalloc for "draconian" heap checks, in
-// which case tcmalloc will print warnings that fail the plugin tests.
-#if !GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN
namespace google {
namespace protobuf {
namespace compiler {
+// Disable the whole test when we use tcmalloc for "draconian" heap checks, in
+// which case tcmalloc will print warnings that fail the plugin tests.
+#if !GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN
+
#if defined(_WIN32)
#ifndef STDIN_FILENO
#define STDIN_FILENO 0
@@ -294,6 +296,10 @@ void CommandLineInterfaceTest::Run(const string& command) {
if (!disallow_plugins_) {
cli_.AllowPlugins("prefix-");
#ifndef GOOGLE_THIRD_PARTY_PROTOBUF
+ string plugin_path;
+#ifdef GOOGLE_PROTOBUF_TEST_PLUGIN_PATH
+ plugin_path = GOOGLE_PROTOBUF_TEST_PLUGIN_PATH;
+#else
const char* possible_paths[] = {
// When building with shared libraries, libtool hides the real executable
// in .libs and puts a fake wrapper in the current directory.
@@ -311,15 +317,13 @@ void CommandLineInterfaceTest::Run(const string& command) {
"test_plugin.exe", // Other Win32 (MSVC)
"test_plugin", // Unix
};
-
- string plugin_path;
-
for (int i = 0; i < GOOGLE_ARRAYSIZE(possible_paths); i++) {
if (access(possible_paths[i], F_OK) == 0) {
plugin_path = possible_paths[i];
break;
}
}
+#endif
if (plugin_path.empty()) {
#else
@@ -374,7 +378,9 @@ void CommandLineInterfaceTest::CreateTempFile(
// Write file.
string full_name = temp_directory_ + "/" + name;
- GOOGLE_CHECK_OK(File::SetContents(full_name, contents, true));
+ GOOGLE_CHECK_OK(File::SetContents(
+ full_name, StringReplace(contents, "$tmpdir", temp_directory_, true),
+ true));
}
void CommandLineInterfaceTest::CreateTempDir(const string& name) {
@@ -899,6 +905,10 @@ TEST_F(CommandLineInterfaceTest, WriteDescriptorSet) {
EXPECT_EQ("bar.proto", descriptor_set.file(0).name());
// Descriptor set should not have source code info.
EXPECT_FALSE(descriptor_set.file(0).has_source_code_info());
+ // Descriptor set should have json_name.
+ EXPECT_EQ("Bar", descriptor_set.file(0).message_type(0).name());
+ EXPECT_EQ("foo", descriptor_set.file(0).message_type(0).field(0).name());
+ EXPECT_TRUE(descriptor_set.file(0).message_type(0).field(0).has_json_name());
}
TEST_F(CommandLineInterfaceTest, WriteDescriptorSetWithDuplicates) {
@@ -932,6 +942,10 @@ TEST_F(CommandLineInterfaceTest, WriteDescriptorSetWithDuplicates) {
EXPECT_EQ("baz.proto", descriptor_set.file(2).name());
// Descriptor set should not have source code info.
EXPECT_FALSE(descriptor_set.file(0).has_source_code_info());
+ // Descriptor set should have json_name.
+ EXPECT_EQ("Bar", descriptor_set.file(0).message_type(0).name());
+ EXPECT_EQ("foo", descriptor_set.file(0).message_type(0).field(0).name());
+ EXPECT_TRUE(descriptor_set.file(0).message_type(0).field(0).has_json_name());
}
TEST_F(CommandLineInterfaceTest, WriteDescriptorSetWithSourceInfo) {
@@ -1095,6 +1109,7 @@ TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFileForAbsolutePath) {
}
#endif // !_WIN32
+
// -------------------------------------------------------------------
TEST_F(CommandLineInterfaceTest, ParseErrors) {
@@ -1426,6 +1441,18 @@ TEST_F(CommandLineInterfaceTest, PluginReceivesSourceCodeInfo) {
"Saw message type MockCodeGenerator_HasSourceCodeInfo: 1.");
}
+TEST_F(CommandLineInterfaceTest, PluginReceivesJsonName) {
+ CreateTempFile("foo.proto",
+ "syntax = \"proto2\";\n"
+ "message MockCodeGenerator_HasJsonName {\n"
+ " optional int32 value = 1;\n"
+ "}\n");
+
+ Run("protocol_compiler --plug_out=$tmpdir --proto_path=$tmpdir foo.proto");
+
+ ExpectErrorSubstring("Saw json_name: 1");
+}
+
TEST_F(CommandLineInterfaceTest, GeneratorPluginNotFound) {
// Test what happens if the plugin isn't found.
@@ -1815,8 +1842,8 @@ TEST_F(EncodeDecodeTest, ProtoParseError) {
} // anonymous namespace
+#endif // !GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN
+
} // namespace compiler
} // namespace protobuf
-
-#endif // !GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN
} // namespace google