summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-06 08:36:26 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-06 08:36:26 +0000
commit503d0387804c4ddf22a52857407e885ce737dbba (patch)
treeb207cd83412330671e898e7c9063da60338be86f /base
parentcc7b9ccdc9f6eb94a89c0ce6f8e8af341eea4370 (diff)
downloadchromium_src-503d0387804c4ddf22a52857407e885ce737dbba.zip
chromium_src-503d0387804c4ddf22a52857407e885ce737dbba.tar.gz
chromium_src-503d0387804c4ddf22a52857407e885ce737dbba.tar.bz2
FTP: split the directory listing parser test and re-enable it on TSan bots
The test was disabled on TSan bots becuase it was taking too much time. This change converts one huge test which parses ~30 directory listings to ~30 separate test cases. This change also moves ToLower/ToUpper from ui/base/l10n_util to base/i18n/case_conversion so that they can be used in net/ftp. BUG=79022 Review URL: http://codereview.chromium.org/6905027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84413 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.gyp3
-rw-r--r--base/i18n/case_conversion.cc34
-rw-r--r--base/i18n/case_conversion.h27
-rw-r--r--base/i18n/case_conversion_unittest.cc39
4 files changed, 103 insertions, 0 deletions
diff --git a/base/base.gyp b/base/base.gyp
index 868e20e..da5d018 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -37,6 +37,8 @@
'i18n/break_iterator.h',
'i18n/char_iterator.cc',
'i18n/char_iterator.h',
+ 'i18n/case_conversion.cc',
+ 'i18n/case_conversion.h',
'i18n/file_util_icu.cc',
'i18n/file_util_icu.h',
'i18n/icu_encoding_detection.cc',
@@ -126,6 +128,7 @@
'id_map_unittest.cc',
'i18n/break_iterator_unittest.cc',
'i18n/char_iterator_unittest.cc',
+ 'i18n/case_conversion_unittest.cc',
'i18n/file_util_icu_unittest.cc',
'i18n/icu_string_conversions_unittest.cc',
'i18n/rtl_unittest.cc',
diff --git a/base/i18n/case_conversion.cc b/base/i18n/case_conversion.cc
new file mode 100644
index 0000000..2dedade
--- /dev/null
+++ b/base/i18n/case_conversion.cc
@@ -0,0 +1,34 @@
+// 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.
+
+#include "base/i18n/case_conversion.h"
+
+#include "base/utf_string_conversions.h"
+#include "unicode/unistr.h"
+
+namespace base {
+namespace i18n {
+
+string16 ToLower(const string16& string) {
+ icu::UnicodeString unicode_string(string.c_str(), string.size());
+ unicode_string.toLower();
+ return string16(unicode_string.getBuffer(), unicode_string.length());
+}
+
+std::wstring WideToLower(const std::wstring& string) {
+ return UTF16ToWide(ToLower(WideToUTF16(string)));
+}
+
+string16 ToUpper(const string16& string) {
+ icu::UnicodeString unicode_string(string.c_str(), string.size());
+ unicode_string.toUpper();
+ return string16(unicode_string.getBuffer(), unicode_string.length());
+}
+
+std::wstring WideToUpper(const std::wstring& string) {
+ return UTF16ToWide(ToUpper(WideToUTF16(string)));
+}
+
+} // namespace i18n
+} // namespace base
diff --git a/base/i18n/case_conversion.h b/base/i18n/case_conversion.h
new file mode 100644
index 0000000..d834ede
--- /dev/null
+++ b/base/i18n/case_conversion.h
@@ -0,0 +1,27 @@
+// 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.
+
+#ifndef BASE_I18N_CASE_CONVERSION_
+#define BASE_I18N_CASE_CONVERSION_
+#pragma once
+
+#include <string>
+
+#include "base/string16.h"
+
+namespace base {
+namespace i18n {
+
+// Returns the lower case equivalent of string. Uses ICU's default locale.
+string16 ToLower(const string16& string);
+std::wstring WideToLower(const std::wstring& string);
+
+// Returns the upper case equivalent of string. Uses ICU's default locale.
+string16 ToUpper(const string16& string);
+std::wstring WideToUpper(const std::wstring& string);
+
+} // namespace i18n
+} // namespace base
+
+#endif // BASE_I18N_CASE_CONVERSION_
diff --git a/base/i18n/case_conversion_unittest.cc b/base/i18n/case_conversion_unittest.cc
new file mode 100644
index 0000000..87a349e
--- /dev/null
+++ b/base/i18n/case_conversion_unittest.cc
@@ -0,0 +1,39 @@
+// 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.
+
+#include "base/i18n/case_conversion.h"
+#include "base/utf_string_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+// Test upper and lower case string conversion.
+TEST(CaseConversionTest, UpperLower) {
+ string16 mixed(ASCIIToUTF16("Text with UPPer & lowER casE."));
+ const string16 expected_lower(ASCIIToUTF16("text with upper & lower case."));
+ const string16 expected_upper(ASCIIToUTF16("TEXT WITH UPPER & LOWER CASE."));
+
+ string16 result = base::i18n::ToLower(mixed);
+ EXPECT_EQ(expected_lower, result);
+
+ result = base::i18n::ToUpper(mixed);
+ EXPECT_EQ(expected_upper, result);
+}
+
+// Test upper and lower case string conversion.
+TEST(CaseConversionTest, WideUpperLower) {
+ std::wstring mixed(L"Text with UPPer & lowER casE.");
+ const std::wstring expected_lower(L"text with upper & lower case.");
+ const std::wstring expected_upper(L"TEXT WITH UPPER & LOWER CASE.");
+
+ std::wstring result = base::i18n::WideToLower(mixed);
+ EXPECT_EQ(expected_lower, result);
+
+ result = base::i18n::WideToUpper(mixed);
+ EXPECT_EQ(expected_upper, result);
+}
+
+// TODO(jshin): More tests are needed, especially with non-ASCII characters.
+
+} // namespace