Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Unified Diff: base/file_path_unittest.cc

Issue 8402008: Add FilePath::FromUTF8Unsafe() and FilePath::AsUTF8Unsafe(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/file_path.cc ('k') | base/value_conversions.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_path_unittest.cc
diff --git a/base/file_path_unittest.cc b/base/file_path_unittest.cc
index 6eb106be68cde0bb81324c5dd6fee7aac16676c7..1c8b99fee23ce2cbdc13976872ed2b85f30de585 100644
--- a/base/file_path_unittest.cc
+++ b/base/file_path_unittest.cc
@@ -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
« no previous file with comments | « base/file_path.cc ('k') | base/value_conversions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698