| Index: third_party/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc
|
| index 165599231647d718144e4a6d3b4d2c4476a768e8..dda007d48f728f2eeb92d7d4a946a16279e93956 100644
|
| --- a/third_party/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc
|
| +++ b/third_party/protobuf/src/google/protobuf/compiler/command_line_interface_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
|
| @@ -40,6 +40,10 @@
|
| #else
|
| #include <unistd.h>
|
| #endif
|
| +#include <memory>
|
| +#ifndef _SHARED_PTR_H
|
| +#include <google/protobuf/stubs/shared_ptr.h>
|
| +#endif
|
| #include <vector>
|
|
|
| #include <google/protobuf/descriptor.pb.h>
|
| @@ -47,6 +51,7 @@
|
| #include <google/protobuf/io/zero_copy_stream.h>
|
| #include <google/protobuf/compiler/command_line_interface.h>
|
| #include <google/protobuf/compiler/code_generator.h>
|
| +#include <google/protobuf/testing/file.h>
|
| #include <google/protobuf/compiler/mock_code_generator.h>
|
| #include <google/protobuf/compiler/subprocess.h>
|
| #include <google/protobuf/io/printer.h>
|
| @@ -62,6 +67,10 @@ 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
|
| @@ -76,6 +85,10 @@ namespace compiler {
|
|
|
| namespace {
|
|
|
| +bool FileExists(const string& path) {
|
| + return File::Exists(path);
|
| +}
|
| +
|
| class CommandLineInterfaceTest : public testing::Test {
|
| protected:
|
| virtual void SetUp();
|
| @@ -102,6 +115,16 @@ class CommandLineInterfaceTest : public testing::Test {
|
| // Create a subdirectory within temp_directory_.
|
| void CreateTempDir(const string& name);
|
|
|
| +#ifdef PROTOBUF_OPENSOURCE
|
| + // Change working directory to temp directory.
|
| + void SwitchToTempDirectory() {
|
| + File::ChangeWorkingDirectory(temp_directory_);
|
| + }
|
| +#else // !PROTOBUF_OPENSOURCE
|
| + // TODO(teboring): Figure out how to change and get working directory in
|
| + // google3.
|
| +#endif // !PROTOBUF_OPENSOURCE
|
| +
|
| void SetInputsAreProtoPathRelative(bool enable) {
|
| cli_.SetInputsAreProtoPathRelative(enable);
|
| }
|
| @@ -126,6 +149,9 @@ class CommandLineInterfaceTest : public testing::Test {
|
| void ExpectErrorSubstringWithZeroReturnCode(
|
| const string& expected_substring);
|
|
|
| + // Checks that the captured stdout is the same as the expected_text.
|
| + void ExpectCapturedStdout(const string& expected_text);
|
| +
|
| // Returns true if ExpectErrorSubstring(expected_substring) would pass, but
|
| // does not fail otherwise.
|
| bool HasAlternateErrorSubstring(const string& expected_substring);
|
| @@ -163,6 +189,9 @@ class CommandLineInterfaceTest : public testing::Test {
|
| void ReadDescriptorSet(const string& filename,
|
| FileDescriptorSet* descriptor_set);
|
|
|
| + void ExpectFileContent(const string& filename,
|
| + const string& content);
|
| +
|
| private:
|
| // The object we are testing.
|
| CommandLineInterface cli_;
|
| @@ -182,6 +211,9 @@ class CommandLineInterfaceTest : public testing::Test {
|
| // The captured stderr output.
|
| string error_text_;
|
|
|
| + // The captured stdout.
|
| + string captured_stdout_;
|
| +
|
| // Pointers which need to be deleted later.
|
| vector<CodeGenerator*> mock_generators_to_delete_;
|
|
|
| @@ -219,12 +251,12 @@ void CommandLineInterfaceTest::SetUp() {
|
|
|
| // If the temp directory already exists, it must be left over from a
|
| // previous run. Delete it.
|
| - if (File::Exists(temp_directory_)) {
|
| + if (FileExists(temp_directory_)) {
|
| File::DeleteRecursively(temp_directory_, NULL, NULL);
|
| }
|
|
|
| // Create the temp directory.
|
| - GOOGLE_CHECK(File::CreateDir(temp_directory_.c_str(), DEFAULT_FILE_MODE));
|
| + GOOGLE_CHECK_OK(File::CreateDir(temp_directory_, 0777));
|
|
|
| // Register generators.
|
| CodeGenerator* generator = new MockCodeGenerator("test_generator");
|
| @@ -245,7 +277,9 @@ void CommandLineInterfaceTest::SetUp() {
|
|
|
| void CommandLineInterfaceTest::TearDown() {
|
| // Delete the temp directory.
|
| - File::DeleteRecursively(temp_directory_, NULL, NULL);
|
| + if (FileExists(temp_directory_)) {
|
| + File::DeleteRecursively(temp_directory_, NULL, NULL);
|
| + }
|
|
|
| // Delete all the MockCodeGenerators.
|
| for (int i = 0; i < mock_generators_to_delete_.size(); i++) {
|
| @@ -255,11 +289,15 @@ void CommandLineInterfaceTest::TearDown() {
|
| }
|
|
|
| void CommandLineInterfaceTest::Run(const string& command) {
|
| - vector<string> args;
|
| - SplitStringUsing(command, " ", &args);
|
| + vector<string> args = Split(command, " ", true);
|
|
|
| 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.
|
| @@ -277,17 +315,20 @@ 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
|
| + string plugin_path = "third_party/protobuf/test_plugin";
|
| +
|
| + if (access(plugin_path.c_str(), F_OK) != 0) {
|
| +#endif // GOOGLE_THIRD_PARTY_PROTOBUF
|
| GOOGLE_LOG(ERROR)
|
| << "Plugin executable not found. Plugin tests are likely to fail.";
|
| } else {
|
| @@ -295,18 +336,27 @@ void CommandLineInterfaceTest::Run(const string& command) {
|
| }
|
| }
|
|
|
| - scoped_array<const char*> argv(new const char*[args.size()]);
|
| + google::protobuf::scoped_array<const char * > argv(new const char* [args.size()]);
|
|
|
| for (int i = 0; i < args.size(); i++) {
|
| args[i] = StringReplace(args[i], "$tmpdir", temp_directory_, true);
|
| argv[i] = args[i].c_str();
|
| }
|
|
|
| + // TODO(jieluo): Cygwin doesn't work well if we try to capture stderr and
|
| + // stdout at the same time. Need to figure out why and add this capture back
|
| + // for Cygwin.
|
| +#if !defined(__CYGWIN__)
|
| + CaptureTestStdout();
|
| +#endif
|
| CaptureTestStderr();
|
|
|
| return_code_ = cli_.Run(args.size(), argv.get());
|
|
|
| error_text_ = GetCapturedTestStderr();
|
| +#if !defined(__CYGWIN__)
|
| + captured_stdout_ = GetCapturedTestStdout();
|
| +#endif
|
| }
|
|
|
| // -------------------------------------------------------------------
|
| @@ -318,16 +368,20 @@ void CommandLineInterfaceTest::CreateTempFile(
|
| string::size_type slash_pos = name.find_last_of('/');
|
| if (slash_pos != string::npos) {
|
| string dir = name.substr(0, slash_pos);
|
| - File::RecursivelyCreateDir(temp_directory_ + "/" + dir, 0777);
|
| + if (!FileExists(temp_directory_ + "/" + dir)) {
|
| + GOOGLE_CHECK_OK(File::RecursivelyCreateDir(temp_directory_ + "/" + dir,
|
| + 0777));
|
| + }
|
| }
|
|
|
| // Write file.
|
| string full_name = temp_directory_ + "/" + name;
|
| - File::WriteStringToFileOrDie(contents, full_name);
|
| + GOOGLE_CHECK_OK(File::SetContents(full_name, contents, true));
|
| }
|
|
|
| void CommandLineInterfaceTest::CreateTempDir(const string& name) {
|
| - File::RecursivelyCreateDir(temp_directory_ + "/" + name, 0777);
|
| + GOOGLE_CHECK_OK(File::RecursivelyCreateDir(temp_directory_ + "/" + name,
|
| + 0777));
|
| }
|
|
|
| // -------------------------------------------------------------------
|
| @@ -414,14 +468,29 @@ void CommandLineInterfaceTest::ReadDescriptorSet(
|
| const string& filename, FileDescriptorSet* descriptor_set) {
|
| string path = temp_directory_ + "/" + filename;
|
| string file_contents;
|
| - if (!File::ReadFileToString(path, &file_contents)) {
|
| - FAIL() << "File not found: " << path;
|
| - }
|
| + GOOGLE_CHECK_OK(File::GetContents(path, &file_contents, true));
|
| +
|
| if (!descriptor_set->ParseFromString(file_contents)) {
|
| FAIL() << "Could not parse file contents: " << path;
|
| }
|
| }
|
|
|
| +void CommandLineInterfaceTest::ExpectCapturedStdout(
|
| + const string& expected_text) {
|
| + EXPECT_EQ(expected_text, captured_stdout_);
|
| +}
|
| +
|
| +
|
| +void CommandLineInterfaceTest::ExpectFileContent(
|
| + const string& filename, const string& content) {
|
| + string path = temp_directory_ + "/" + filename;
|
| + string file_contents;
|
| + GOOGLE_CHECK_OK(File::GetContents(path, &file_contents, true));
|
| +
|
| + EXPECT_EQ(StringReplace(content, "$tmpdir", temp_directory_, true),
|
| + file_contents);
|
| +}
|
| +
|
| // ===================================================================
|
|
|
| TEST_F(CommandLineInterfaceTest, BasicOutput) {
|
| @@ -691,7 +760,7 @@ TEST_F(CommandLineInterfaceTest, ColonDelimitedPath) {
|
| #endif
|
|
|
| Run("protocol_compiler --test_out=$tmpdir "
|
| - "--proto_path=$tmpdir/a"PATH_SEPARATOR"$tmpdir/b foo.proto");
|
| + "--proto_path=$tmpdir/a" PATH_SEPARATOR "$tmpdir/b foo.proto");
|
|
|
| #undef PATH_SEPARATOR
|
|
|
| @@ -813,10 +882,51 @@ TEST_F(CommandLineInterfaceTest, WriteDescriptorSet) {
|
| FileDescriptorSet descriptor_set;
|
| ReadDescriptorSet("descriptor_set", &descriptor_set);
|
| if (HasFatalFailure()) return;
|
| - ASSERT_EQ(1, descriptor_set.file_size());
|
| + EXPECT_EQ(1, descriptor_set.file_size());
|
| 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) {
|
| + CreateTempFile("foo.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Foo {}\n");
|
| + CreateTempFile("bar.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "import \"foo.proto\";\n"
|
| + "message Bar {\n"
|
| + " optional Foo foo = 1;\n"
|
| + "}\n");
|
| + CreateTempFile("baz.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "import \"foo.proto\";\n"
|
| + "message Baz {\n"
|
| + " optional Foo foo = 1;\n"
|
| + "}\n");
|
| +
|
| + Run("protocol_compiler --descriptor_set_out=$tmpdir/descriptor_set "
|
| + "--proto_path=$tmpdir bar.proto foo.proto bar.proto baz.proto");
|
| +
|
| + ExpectNoErrors();
|
| +
|
| + FileDescriptorSet descriptor_set;
|
| + ReadDescriptorSet("descriptor_set", &descriptor_set);
|
| + if (HasFatalFailure()) return;
|
| + EXPECT_EQ(3, descriptor_set.file_size());
|
| + EXPECT_EQ("bar.proto", descriptor_set.file(0).name());
|
| + EXPECT_EQ("foo.proto", descriptor_set.file(1).name());
|
| + 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) {
|
| @@ -838,7 +948,7 @@ TEST_F(CommandLineInterfaceTest, WriteDescriptorSetWithSourceInfo) {
|
| FileDescriptorSet descriptor_set;
|
| ReadDescriptorSet("descriptor_set", &descriptor_set);
|
| if (HasFatalFailure()) return;
|
| - ASSERT_EQ(1, descriptor_set.file_size());
|
| + EXPECT_EQ(1, descriptor_set.file_size());
|
| EXPECT_EQ("bar.proto", descriptor_set.file(0).name());
|
| // Source code info included.
|
| EXPECT_TRUE(descriptor_set.file(0).has_source_code_info());
|
| @@ -863,7 +973,7 @@ TEST_F(CommandLineInterfaceTest, WriteTransitiveDescriptorSet) {
|
| FileDescriptorSet descriptor_set;
|
| ReadDescriptorSet("descriptor_set", &descriptor_set);
|
| if (HasFatalFailure()) return;
|
| - ASSERT_EQ(2, descriptor_set.file_size());
|
| + EXPECT_EQ(2, descriptor_set.file_size());
|
| if (descriptor_set.file(0).name() == "bar.proto") {
|
| std::swap(descriptor_set.mutable_file()->mutable_data()[0],
|
| descriptor_set.mutable_file()->mutable_data()[1]);
|
| @@ -894,7 +1004,7 @@ TEST_F(CommandLineInterfaceTest, WriteTransitiveDescriptorSetWithSourceInfo) {
|
| FileDescriptorSet descriptor_set;
|
| ReadDescriptorSet("descriptor_set", &descriptor_set);
|
| if (HasFatalFailure()) return;
|
| - ASSERT_EQ(2, descriptor_set.file_size());
|
| + EXPECT_EQ(2, descriptor_set.file_size());
|
| if (descriptor_set.file(0).name() == "bar.proto") {
|
| std::swap(descriptor_set.mutable_file()->mutable_data()[0],
|
| descriptor_set.mutable_file()->mutable_data()[1]);
|
| @@ -906,6 +1016,80 @@ TEST_F(CommandLineInterfaceTest, WriteTransitiveDescriptorSetWithSourceInfo) {
|
| EXPECT_TRUE(descriptor_set.file(1).has_source_code_info());
|
| }
|
|
|
| +#ifdef _WIN32
|
| +// TODO(teboring): Figure out how to write test on windows.
|
| +#else
|
| +TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFileGivenTwoInputs) {
|
| + CreateTempFile("foo.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Foo {}\n");
|
| + CreateTempFile("bar.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "import \"foo.proto\";\n"
|
| + "message Bar {\n"
|
| + " optional Foo foo = 1;\n"
|
| + "}\n");
|
| +
|
| + Run("protocol_compiler --dependency_out=$tmpdir/manifest "
|
| + "--test_out=$tmpdir --proto_path=$tmpdir bar.proto foo.proto");
|
| +
|
| + ExpectErrorText(
|
| + "Can only process one input file when using --dependency_out=FILE.\n");
|
| +}
|
| +
|
| +#ifdef PROTOBUF_OPENSOURCE
|
| +TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFile) {
|
| + CreateTempFile("foo.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Foo {}\n");
|
| + CreateTempFile("bar.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "import \"foo.proto\";\n"
|
| + "message Bar {\n"
|
| + " optional Foo foo = 1;\n"
|
| + "}\n");
|
| +
|
| + string current_working_directory = getcwd(NULL, 0);
|
| + SwitchToTempDirectory();
|
| +
|
| + Run("protocol_compiler --dependency_out=manifest --test_out=. "
|
| + "bar.proto");
|
| +
|
| + ExpectNoErrors();
|
| +
|
| + ExpectFileContent("manifest",
|
| + "bar.proto.MockCodeGenerator.test_generator: "
|
| + "foo.proto\\\n bar.proto");
|
| +
|
| + File::ChangeWorkingDirectory(current_working_directory);
|
| +}
|
| +#else // !PROTOBUF_OPENSOURCE
|
| +// TODO(teboring): Figure out how to change and get working directory in
|
| +// google3.
|
| +#endif // !PROTOBUF_OPENSOURCE
|
| +
|
| +TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFileForAbsolutePath) {
|
| + CreateTempFile("foo.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Foo {}\n");
|
| + CreateTempFile("bar.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "import \"foo.proto\";\n"
|
| + "message Bar {\n"
|
| + " optional Foo foo = 1;\n"
|
| + "}\n");
|
| +
|
| + Run("protocol_compiler --dependency_out=$tmpdir/manifest "
|
| + "--test_out=$tmpdir --proto_path=$tmpdir bar.proto");
|
| +
|
| + ExpectNoErrors();
|
| +
|
| + ExpectFileContent("manifest",
|
| + "$tmpdir/bar.proto.MockCodeGenerator.test_generator: "
|
| + "$tmpdir/foo.proto\\\n $tmpdir/bar.proto");
|
| +}
|
| +#endif // !_WIN32
|
| +
|
| // -------------------------------------------------------------------
|
|
|
| TEST_F(CommandLineInterfaceTest, ParseErrors) {
|
| @@ -1237,6 +1421,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.
|
|
|
| @@ -1393,6 +1589,76 @@ TEST_F(CommandLineInterfaceTest, MissingValueAtEndError) {
|
| ExpectErrorText("Missing value for flag: --test_out\n");
|
| }
|
|
|
| +TEST_F(CommandLineInterfaceTest, PrintFreeFieldNumbers) {
|
| + CreateTempFile(
|
| + "foo.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "package foo;\n"
|
| + "message Foo {\n"
|
| + " optional int32 a = 2;\n"
|
| + " optional string b = 4;\n"
|
| + " optional string c = 5;\n"
|
| + " optional int64 d = 8;\n"
|
| + " optional double e = 10;\n"
|
| + "}\n");
|
| + CreateTempFile(
|
| + "bar.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Bar {\n"
|
| + " optional int32 a = 2;\n"
|
| + " extensions 4 to 5;\n"
|
| + " optional int64 d = 8;\n"
|
| + " extensions 10;\n"
|
| + "}\n");
|
| + CreateTempFile(
|
| + "baz.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Baz {\n"
|
| + " optional int32 a = 2;\n"
|
| + " optional int64 d = 8;\n"
|
| + " extensions 15 to max;\n" // unordered.
|
| + " extensions 13;\n"
|
| + " extensions 10 to 12;\n"
|
| + " extensions 5;\n"
|
| + " extensions 4;\n"
|
| + "}\n");
|
| + CreateTempFile(
|
| + "quz.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Quz {\n"
|
| + " message Foo {}\n" // nested message
|
| + " optional int32 a = 2;\n"
|
| + " optional group C = 4 {\n"
|
| + " optional int32 d = 5;\n"
|
| + " }\n"
|
| + " extensions 8 to 10;\n"
|
| + " optional group E = 11 {\n"
|
| + " optional int32 f = 9;\n" // explicitly reuse extension range 8-10
|
| + " optional group G = 15 {\n" // nested group
|
| + " message Foo {}\n" // nested message inside nested group
|
| + " }\n"
|
| + " }\n"
|
| + "}\n");
|
| +
|
| + Run("protocol_compiler --print_free_field_numbers --proto_path=$tmpdir "
|
| + "foo.proto bar.proto baz.proto quz.proto");
|
| +
|
| + ExpectNoErrors();
|
| +
|
| + // TODO(jieluo): Cygwin doesn't work well if we try to capture stderr and
|
| + // stdout at the same time. Need to figure out why and add this test back
|
| + // for Cygwin.
|
| +#if !defined(__CYGWIN__)
|
| + ExpectCapturedStdout(
|
| + "foo.Foo free: 1 3 6-7 9 11-INF\n"
|
| + "Bar free: 1 3 6-7 9 11-INF\n"
|
| + "Baz free: 1 3 6-7 9 14\n"
|
| + "Quz.Foo free: 1-INF\n"
|
| + "Quz.E.G.Foo free: 1-INF\n"
|
| + "Quz free: 1 3 6-7 12-14 16-INF\n");
|
| +#endif
|
| +}
|
| +
|
| // ===================================================================
|
|
|
| // Test for --encode and --decode. Note that it would be easier to do this
|
| @@ -1412,7 +1678,7 @@ class EncodeDecodeTest : public testing::Test {
|
|
|
| void RedirectStdinFromText(const string& input) {
|
| string filename = TestTempDir() + "/test_stdin";
|
| - File::WriteStringToFileOrDie(input, filename);
|
| + GOOGLE_CHECK_OK(File::SetContents(filename, input, true));
|
| GOOGLE_CHECK(RedirectStdinFromFile(filename));
|
| }
|
|
|
| @@ -1446,7 +1712,7 @@ class EncodeDecodeTest : public testing::Test {
|
| SplitStringUsing(command, " ", &args);
|
| args.push_back("--proto_path=" + TestSourceDir());
|
|
|
| - scoped_array<const char*> argv(new const char*[args.size()]);
|
| + google::protobuf::scoped_array<const char * > argv(new const char* [args.size()]);
|
| for (int i = 0; i < args.size(); i++) {
|
| argv[i] = args[i].c_str();
|
| }
|
| @@ -1467,7 +1733,7 @@ class EncodeDecodeTest : public testing::Test {
|
|
|
| void ExpectStdoutMatchesBinaryFile(const string& filename) {
|
| string expected_output;
|
| - ASSERT_TRUE(File::ReadFileToString(filename, &expected_output));
|
| + GOOGLE_CHECK_OK(File::GetContents(filename, &expected_output, true));
|
|
|
| // Don't use EXPECT_EQ because we don't want to print raw binary data to
|
| // stdout on failure.
|
| @@ -1476,7 +1742,7 @@ class EncodeDecodeTest : public testing::Test {
|
|
|
| void ExpectStdoutMatchesTextFile(const string& filename) {
|
| string expected_output;
|
| - ASSERT_TRUE(File::ReadFileToString(filename, &expected_output));
|
| + GOOGLE_CHECK_OK(File::GetContents(filename, &expected_output, true));
|
|
|
| ExpectStdoutMatchesText(expected_output);
|
| }
|
| @@ -1496,22 +1762,23 @@ class EncodeDecodeTest : public testing::Test {
|
| };
|
|
|
| TEST_F(EncodeDecodeTest, Encode) {
|
| - RedirectStdinFromFile(TestSourceDir() +
|
| - "/google/protobuf/testdata/text_format_unittest_data.txt");
|
| + RedirectStdinFromFile(TestSourceDir() + "/google/protobuf/"
|
| + "testdata/text_format_unittest_data_oneof_implemented.txt");
|
| EXPECT_TRUE(Run("google/protobuf/unittest.proto "
|
| "--encode=protobuf_unittest.TestAllTypes"));
|
| ExpectStdoutMatchesBinaryFile(TestSourceDir() +
|
| - "/google/protobuf/testdata/golden_message");
|
| + "/google/protobuf/testdata/golden_message_oneof_implemented");
|
| ExpectStderrMatchesText("");
|
| }
|
|
|
| TEST_F(EncodeDecodeTest, Decode) {
|
| RedirectStdinFromFile(TestSourceDir() +
|
| - "/google/protobuf/testdata/golden_message");
|
| + "/google/protobuf/testdata/golden_message_oneof_implemented");
|
| EXPECT_TRUE(Run("google/protobuf/unittest.proto "
|
| "--decode=protobuf_unittest.TestAllTypes"));
|
| ExpectStdoutMatchesTextFile(TestSourceDir() +
|
| - "/google/protobuf/testdata/text_format_unittest_data.txt");
|
| + "/google/protobuf/"
|
| + "testdata/text_format_unittest_data_oneof_implemented.txt");
|
| ExpectStderrMatchesText("");
|
| }
|
|
|
| @@ -1555,6 +1822,8 @@ TEST_F(EncodeDecodeTest, ProtoParseError) {
|
|
|
| } // anonymous namespace
|
|
|
| +#endif // !GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN
|
| +
|
| } // namespace compiler
|
| } // namespace protobuf
|
| } // namespace google
|
|
|