Chromium Code Reviews| Index: base/file_path_unittest.cc |
| diff --git a/base/file_path_unittest.cc b/base/file_path_unittest.cc |
| index ab2554365216348c0c605ecd5252fd382f262eea..9f8e0fb6003144b878bf046429c9185fe6423283 100644 |
| --- a/base/file_path_unittest.cc |
| +++ b/base/file_path_unittest.cc |
| @@ -12,6 +12,9 @@ |
| // This macro helps avoid wrapped lines in the test structs. |
| #define FPL(x) FILE_PATH_LITERAL(x) |
| +// This macro constructs strings which can contain NULs. |
| +#define FPS(x) FilePath::StringType(FPL(x), arraysize(FPL(x)) - 1) |
| + |
| struct UnaryTestData { |
| const FilePath::CharType* input; |
| const FilePath::CharType* expected; |
| @@ -1115,6 +1118,29 @@ TEST_F(FilePathTest, FromUTF8Unsafe_And_AsUTF8Unsafe) { |
| } |
| } |
| +// Test constructor strips '\0' |
| +TEST_F(FilePathTest, ConstructWithNUL) { |
| + FilePath path(FPS("a\0b")); |
| + EXPECT_EQ(path.value(), FPL("a")); |
|
Chris Evans
2013/01/08 09:41:01
I'm not 100% sure how std::string equality works.
|
| +} |
| + |
| +// Test Append() strips '\0' |
| +TEST_F(FilePathTest, AppendWithNUL) { |
| + FilePath path(FPL("a")); |
| + path = path.Append(FPS("b\0b")); |
| +#if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| + EXPECT_EQ(path.value(), "a\\b"); |
| +#else |
| + EXPECT_EQ(path.value(), "a/b"); |
|
Chris Evans
2013/01/08 09:41:01
Again, maybe check length() to be sure.
|
| +#endif |
| +} |
| + |
| +// Test ReferencesParent() doesn't break with "..\0" |
| +TEST_F(FilePathTest, ReferencesParentWithNUL) { |
| + FilePath path(FPS("..\0")); |
| + ASSERT_TRUE(path.ReferencesParent()); |
| +} |
| + |
| #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| TEST_F(FilePathTest, NormalizePathSeparators) { |
| const struct UnaryTestData cases[] = { |