diff options
Diffstat (limited to 'src/google/protobuf/compiler/importer_unittest.cc')
-rw-r--r-- | src/google/protobuf/compiler/importer_unittest.cc | 57 |
1 files changed, 20 insertions, 37 deletions
diff --git a/src/google/protobuf/compiler/importer_unittest.cc b/src/google/protobuf/compiler/importer_unittest.cc index 387f135..56fad56 100644 --- a/src/google/protobuf/compiler/importer_unittest.cc +++ b/src/google/protobuf/compiler/importer_unittest.cc @@ -1,6 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ +// http://code.google.com/p/protobuf/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are @@ -33,13 +33,12 @@ // Sanjay Ghemawat, Jeff Dean, and others. #include <google/protobuf/stubs/hash.h> -#include <memory> #include <google/protobuf/compiler/importer.h> #include <google/protobuf/descriptor.h> #include <google/protobuf/io/zero_copy_stream_impl.h> -#include <google/protobuf/stubs/map_util.h> +#include <google/protobuf/stubs/map-util.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/testing/file.h> #include <google/protobuf/stubs/strutil.h> @@ -93,10 +92,6 @@ class MockSourceTree : public SourceTree { } } - string GetLastErrorMessage() { - return "File not found."; - } - private: hash_map<string, const char*> files_; }; @@ -329,7 +324,6 @@ TEST_F(ImporterTest, MapFieldKeyNotScalar) { EXPECT_SUBSTRING("must name a scalar or string", error()); } - // =================================================================== class DiskSourceTreeTest : public testing::Test { @@ -342,7 +336,7 @@ class DiskSourceTreeTest : public testing::Test { if (File::Exists(dirnames_[i])) { File::DeleteRecursively(dirnames_[i], NULL, NULL); } - GOOGLE_CHECK_OK(File::CreateDir(dirnames_[i], 0777)); + GOOGLE_CHECK(File::CreateDir(dirnames_[i].c_str(), DEFAULT_FILE_MODE)); } } @@ -353,11 +347,11 @@ class DiskSourceTreeTest : public testing::Test { } void AddFile(const string& filename, const char* contents) { - GOOGLE_CHECK_OK(File::SetContents(filename, contents, true)); + File::WriteStringToFileOrDie(contents, filename); } void AddSubdir(const string& dirname) { - GOOGLE_CHECK_OK(File::CreateDir(dirname, 0777)); + GOOGLE_CHECK(File::CreateDir(dirname.c_str(), DEFAULT_FILE_MODE)); } void ExpectFileContents(const string& filename, @@ -377,11 +371,9 @@ class DiskSourceTreeTest : public testing::Test { EXPECT_EQ(expected_contents, file_contents); } - void ExpectCannotOpenFile(const string& filename, - const string& error_message) { + void ExpectFileNotFound(const string& filename) { scoped_ptr<io::ZeroCopyInputStream> input(source_tree_.Open(filename)); EXPECT_TRUE(input == NULL); - EXPECT_EQ(error_message, source_tree_.GetLastErrorMessage()); } DiskSourceTree source_tree_; @@ -397,7 +389,7 @@ TEST_F(DiskSourceTreeTest, MapRoot) { source_tree_.MapPath("", dirnames_[0]); ExpectFileContents("foo", "Hello World!"); - ExpectCannotOpenFile("bar", "File not found."); + ExpectFileNotFound("bar"); } TEST_F(DiskSourceTreeTest, MapDirectory) { @@ -408,21 +400,15 @@ TEST_F(DiskSourceTreeTest, MapDirectory) { source_tree_.MapPath("baz", dirnames_[0]); ExpectFileContents("baz/foo", "Hello World!"); - ExpectCannotOpenFile("baz/bar", "File not found."); - ExpectCannotOpenFile("foo", "File not found."); - ExpectCannotOpenFile("bar", "File not found."); + ExpectFileNotFound("baz/bar"); + ExpectFileNotFound("foo"); + ExpectFileNotFound("bar"); // Non-canonical file names should not work. - ExpectCannotOpenFile("baz//foo", - "Backslashes, consecutive slashes, \".\", or \"..\" are " - "not allowed in the virtual path"); - ExpectCannotOpenFile("baz/../baz/foo", - "Backslashes, consecutive slashes, \".\", or \"..\" are " - "not allowed in the virtual path"); - ExpectCannotOpenFile("baz/./foo", - "Backslashes, consecutive slashes, \".\", or \"..\" are " - "not allowed in the virtual path"); - ExpectCannotOpenFile("baz/foo/", "File not found."); + ExpectFileNotFound("baz//foo"); + ExpectFileNotFound("baz/../baz/foo"); + ExpectFileNotFound("baz/./foo"); + ExpectFileNotFound("baz/foo/"); } TEST_F(DiskSourceTreeTest, NoParent) { @@ -434,12 +420,8 @@ TEST_F(DiskSourceTreeTest, NoParent) { source_tree_.MapPath("", dirnames_[0] + "/bar"); ExpectFileContents("baz", "Blah."); - ExpectCannotOpenFile("../foo", - "Backslashes, consecutive slashes, \".\", or \"..\" are " - "not allowed in the virtual path"); - ExpectCannotOpenFile("../bar/baz", - "Backslashes, consecutive slashes, \".\", or \"..\" are " - "not allowed in the virtual path"); + ExpectFileNotFound("../foo"); + ExpectFileNotFound("../bar/baz"); } TEST_F(DiskSourceTreeTest, MapFile) { @@ -449,7 +431,7 @@ TEST_F(DiskSourceTreeTest, MapFile) { source_tree_.MapPath("foo", dirnames_[0] + "/foo"); ExpectFileContents("foo", "Hello World!"); - ExpectCannotOpenFile("bar", "File not found."); + ExpectFileNotFound("bar"); } TEST_F(DiskSourceTreeTest, SearchMultipleDirectories) { @@ -463,7 +445,7 @@ TEST_F(DiskSourceTreeTest, SearchMultipleDirectories) { ExpectFileContents("foo", "Hello World!"); ExpectFileContents("bar", "Goodbye World!"); - ExpectCannotOpenFile("baz", "File not found."); + ExpectFileNotFound("baz"); } TEST_F(DiskSourceTreeTest, OrderingTrumpsSpecificity) { @@ -471,7 +453,8 @@ TEST_F(DiskSourceTreeTest, OrderingTrumpsSpecificity) { // directory is more-specific than a former one. // Create the "bar" directory so we can put a file in it. - GOOGLE_CHECK_OK(File::CreateDir(dirnames_[0] + "/bar", 0777)); + ASSERT_TRUE(File::CreateDir((dirnames_[0] + "/bar").c_str(), + DEFAULT_FILE_MODE)); // Add files and map paths. AddFile(dirnames_[0] + "/bar/foo", "Hello World!"); |