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

Side by Side Diff: base/i18n/file_util_icu_unittest.cc

Issue 447403002: Move file_util_icu to base::i18n namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/i18n/file_util_icu.cc ('k') | chrome/browser/download/save_package_file_picker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/i18n/file_util_icu.h" 5 #include "base/i18n/file_util_icu.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/platform_test.h" 10 #include "testing/platform_test.h"
11 11
12 namespace base {
13 namespace i18n {
14
12 // file_util winds up using autoreleased objects on the Mac, so this needs 15 // file_util winds up using autoreleased objects on the Mac, so this needs
13 // to be a PlatformTest 16 // to be a PlatformTest
14 class FileUtilICUTest : public PlatformTest { 17 class FileUtilICUTest : public PlatformTest {
15 }; 18 };
16 19
17 #if defined(OS_POSIX) && !defined(OS_MACOSX) 20 #if defined(OS_POSIX) && !defined(OS_MACOSX)
18 21
19 // Linux disallows some evil ASCII characters, but passes all non-ASCII. 22 // Linux disallows some evil ASCII characters, but passes all non-ASCII.
20 static const struct goodbad_pair { 23 static const struct goodbad_pair {
21 const char* bad_name; 24 const char* bad_name;
22 const char* good_name; 25 const char* good_name;
23 } kIllegalCharacterCases[] = { 26 } kIllegalCharacterCases[] = {
24 {"bad*file:name?.jpg", "bad-file-name-.jpg"}, 27 {"bad*file:name?.jpg", "bad-file-name-.jpg"},
25 {"**********::::.txt", "--------------.txt"}, 28 {"**********::::.txt", "--------------.txt"},
26 {"\xe9\xf0zzzz.\xff", "\xe9\xf0zzzz.\xff"}, 29 {"\xe9\xf0zzzz.\xff", "\xe9\xf0zzzz.\xff"},
27 }; 30 };
28 31
29 TEST_F(FileUtilICUTest, ReplaceIllegalCharacersInPathLinuxTest) { 32 TEST_F(FileUtilICUTest, ReplaceIllegalCharacersInPathLinuxTest) {
30 for (size_t i = 0; i < arraysize(kIllegalCharacterCases); ++i) { 33 for (size_t i = 0; i < arraysize(kIllegalCharacterCases); ++i) {
31 std::string bad_name(kIllegalCharacterCases[i].bad_name); 34 std::string bad_name(kIllegalCharacterCases[i].bad_name);
32 file_util::ReplaceIllegalCharactersInPath(&bad_name, '-'); 35 ReplaceIllegalCharactersInPath(&bad_name, '-');
33 EXPECT_EQ(kIllegalCharacterCases[i].good_name, bad_name); 36 EXPECT_EQ(kIllegalCharacterCases[i].good_name, bad_name);
34 } 37 }
35 } 38 }
36 39
37 #else 40 #else
38 41
39 // For Mac & Windows, which both do Unicode validation on filenames. These 42 // For Mac & Windows, which both do Unicode validation on filenames. These
40 // characters are given as wide strings since its more convenient to specify 43 // characters are given as wide strings since its more convenient to specify
41 // unicode characters. For Mac they should be converted to UTF-8. 44 // unicode characters. For Mac they should be converted to UTF-8.
42 static const struct goodbad_pair { 45 static const struct goodbad_pair {
(...skipping 20 matching lines...) Expand all
63 {L"\u0378\U00040001.mp3", L"\u0378\U00040001.mp3"}, 66 {L"\u0378\U00040001.mp3", L"\u0378\U00040001.mp3"},
64 // Non-characters are not allowed. 67 // Non-characters are not allowed.
65 {L"bad\uFFFFfile\U0010FFFEname.jpg ", L"bad-file-name.jpg"}, 68 {L"bad\uFFFFfile\U0010FFFEname.jpg ", L"bad-file-name.jpg"},
66 {L"bad\uFDD0file\uFDEFname.jpg ", L"bad-file-name.jpg"}, 69 {L"bad\uFDD0file\uFDEFname.jpg ", L"bad-file-name.jpg"},
67 }; 70 };
68 71
69 TEST_F(FileUtilICUTest, ReplaceIllegalCharactersInPathTest) { 72 TEST_F(FileUtilICUTest, ReplaceIllegalCharactersInPathTest) {
70 for (size_t i = 0; i < arraysize(kIllegalCharacterCases); ++i) { 73 for (size_t i = 0; i < arraysize(kIllegalCharacterCases); ++i) {
71 #if defined(OS_WIN) 74 #if defined(OS_WIN)
72 std::wstring bad_name(kIllegalCharacterCases[i].bad_name); 75 std::wstring bad_name(kIllegalCharacterCases[i].bad_name);
73 file_util::ReplaceIllegalCharactersInPath(&bad_name, '-'); 76 ReplaceIllegalCharactersInPath(&bad_name, '-');
74 EXPECT_EQ(kIllegalCharacterCases[i].good_name, bad_name); 77 EXPECT_EQ(kIllegalCharacterCases[i].good_name, bad_name);
75 #elif defined(OS_MACOSX) 78 #elif defined(OS_MACOSX)
76 std::string bad_name(base::WideToUTF8(kIllegalCharacterCases[i].bad_name)); 79 std::string bad_name(WideToUTF8(kIllegalCharacterCases[i].bad_name));
77 file_util::ReplaceIllegalCharactersInPath(&bad_name, '-'); 80 ReplaceIllegalCharactersInPath(&bad_name, '-');
78 EXPECT_EQ(base::WideToUTF8(kIllegalCharacterCases[i].good_name), bad_name); 81 EXPECT_EQ(WideToUTF8(kIllegalCharacterCases[i].good_name), bad_name);
79 #endif 82 #endif
80 } 83 }
81 } 84 }
82 85
83 #endif 86 #endif
84 87
85 #if defined(OS_CHROMEOS) 88 #if defined(OS_CHROMEOS)
86 static const struct normalize_name_encoding_test_cases { 89 static const struct normalize_name_encoding_test_cases {
87 const char* original_path; 90 const char* original_path;
88 const char* normalized_path; 91 const char* normalized_path;
89 } kNormalizeFileNameEncodingTestCases[] = { 92 } kNormalizeFileNameEncodingTestCases[] = {
90 { "foo_na\xcc\x88me.foo", "foo_n\xc3\xa4me.foo"}, 93 { "foo_na\xcc\x88me.foo", "foo_n\xc3\xa4me.foo"},
91 { "foo_dir_na\xcc\x88me/foo_na\xcc\x88me.foo", 94 { "foo_dir_na\xcc\x88me/foo_na\xcc\x88me.foo",
92 "foo_dir_na\xcc\x88me/foo_n\xc3\xa4me.foo"}, 95 "foo_dir_na\xcc\x88me/foo_n\xc3\xa4me.foo"},
93 { "", ""}, 96 { "", ""},
94 { "foo_dir_na\xcc\x88me/", "foo_dir_n\xc3\xa4me"} 97 { "foo_dir_na\xcc\x88me/", "foo_dir_n\xc3\xa4me"}
95 }; 98 };
96 99
97 TEST_F(FileUtilICUTest, NormalizeFileNameEncoding) { 100 TEST_F(FileUtilICUTest, NormalizeFileNameEncoding) {
98 for (size_t i = 0; i < arraysize(kNormalizeFileNameEncodingTestCases); i++) { 101 for (size_t i = 0; i < arraysize(kNormalizeFileNameEncodingTestCases); i++) {
99 base::FilePath path(kNormalizeFileNameEncodingTestCases[i].original_path); 102 FilePath path(kNormalizeFileNameEncodingTestCases[i].original_path);
100 file_util::NormalizeFileNameEncoding(&path); 103 NormalizeFileNameEncoding(&path);
101 EXPECT_EQ( 104 EXPECT_EQ(FilePath(kNormalizeFileNameEncodingTestCases[i].normalized_path),
102 base::FilePath(kNormalizeFileNameEncodingTestCases[i].normalized_path), 105 path);
103 path);
104 } 106 }
105 } 107 }
106 108
107 #endif 109 #endif
110
111 } // namespace i18n
112 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/file_util_icu.cc ('k') | chrome/browser/download/save_package_file_picker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698