summaryrefslogtreecommitdiffstats
path: root/base/file_path_unittest.cc
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-02 04:55:23 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-02 04:55:23 +0000
commit45440519a239ffad82425e08115d909fd82a1e9d (patch)
treef7b042dad754c87efdf5fac6944a2a30a9461353 /base/file_path_unittest.cc
parentd9037729a6f2e4cb56e59bc69b145d6ddec1d13b (diff)
downloadchromium_src-45440519a239ffad82425e08115d909fd82a1e9d.zip
chromium_src-45440519a239ffad82425e08115d909fd82a1e9d.tar.gz
chromium_src-45440519a239ffad82425e08115d909fd82a1e9d.tar.bz2
Add FilePath::FromUTF8Unsafe() and FilePath::AsUTF8Unsafe().
The logic is moved from value_conversions.cc. FilePath::FromUTF8Unsafe() should only be used when you are sure that the input string is UTF-8. See the function comments for why they have "Unsafe" in their names. BUG=none TEST=base_unittests Review URL: http://codereview.chromium.org/8402008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108246 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_path_unittest.cc')
-rw-r--r--base/file_path_unittest.cc32
1 files changed, 31 insertions, 1 deletions
diff --git a/base/file_path_unittest.cc b/base/file_path_unittest.cc
index 6eb106b..9890e80 100644
--- a/base/file_path_unittest.cc
+++ b/base/file_path_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -37,6 +37,11 @@ struct BinaryIntTestData {
int expected;
};
+struct UTF8TestData {
+ const FilePath::CharType* native;
+ const char* utf8;
+};
+
// file_util winds up using autoreleased objects on the Mac, so this needs
// to be a PlatformTest
class FilePathTest : public PlatformTest {
@@ -1044,6 +1049,30 @@ TEST_F(FilePathTest, ReferencesParent) {
}
}
+TEST_F(FilePathTest, FromUTF8Unsafe_And_AsUTF8Unsafe) {
+ const struct UTF8TestData cases[] = {
+ { FPL("foo.txt"), "foo.txt" },
+ // "aeo" with accents. Use http://0xcc.net/jsescape/ to decode them.
+ { FPL("\u00E0\u00E8\u00F2.txt"), "\xC3\xA0\xC3\xA8\xC3\xB2.txt" },
+ // Full-width "ABC".
+ { FPL("\uFF21\uFF22\uFF23.txt"),
+ "\xEF\xBC\xA1\xEF\xBC\xA2\xEF\xBC\xA3.txt" },
+ };
+
+ for (size_t i = 0; i < arraysize(cases); ++i) {
+ // Test FromUTF8Unsafe() works.
+ FilePath from_utf8 = FilePath::FromUTF8Unsafe(cases[i].utf8);
+ EXPECT_EQ(cases[i].native, from_utf8.value())
+ << "i: " << i << ", input: " << cases[i].native;
+ // Test AsUTF8Unsafe() works.
+ FilePath from_native = FilePath(cases[i].native);
+ EXPECT_EQ(cases[i].utf8, from_native.AsUTF8Unsafe())
+ << "i: " << i << ", input: " << cases[i].native;
+ // Test the two file paths are identical.
+ EXPECT_EQ(from_utf8.value(), from_native.value());
+ }
+}
+
#if defined(FILE_PATH_USES_WIN_SEPARATORS)
TEST_F(FilePathTest, NormalizeWindowsPathSeparators) {
const struct UnaryTestData cases[] = {
@@ -1086,4 +1115,5 @@ TEST_F(FilePathTest, NormalizeWindowsPathSeparators) {
"i: " << i << ", input: " << input.value();
}
}
+
#endif