summaryrefslogtreecommitdiffstats
path: root/chrome/common/l10n_util_unittest.cc
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-24 05:14:04 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-24 05:14:04 +0000
commit07ae2c333da12779c87eefcd65f4272e389766f3 (patch)
treed13dc876544bd5b65e00f1e4db8573c4551dcf8d /chrome/common/l10n_util_unittest.cc
parenta53ef0492a5c34542d5b1d607f848fb7b45002ba (diff)
downloadchromium_src-07ae2c333da12779c87eefcd65f4272e389766f3.zip
chromium_src-07ae2c333da12779c87eefcd65f4272e389766f3.tar.gz
chromium_src-07ae2c333da12779c87eefcd65f4272e389766f3.tar.bz2
Adds a method to sort the elements of a vector by invoking a method on
each that returns a string. The strings are then compared using a collator, or operator < if no collator is found. I'm going to use this for sorting bookmarks. BUG=1750 TEST=none yet Review URL: http://codereview.chromium.org/20484 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10252 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/l10n_util_unittest.cc')
-rw-r--r--chrome/common/l10n_util_unittest.cc32
1 files changed, 29 insertions, 3 deletions
diff --git a/chrome/common/l10n_util_unittest.cc b/chrome/common/l10n_util_unittest.cc
index 88c1cad..b308ffa4 100644
--- a/chrome/common/l10n_util_unittest.cc
+++ b/chrome/common/l10n_util_unittest.cc
@@ -10,6 +10,7 @@
#include "base/string_util.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/l10n_util.h"
+#include "chrome/common/stl_util-inl.h"
#if !defined(OS_MACOSX)
#include "chrome/test/data/resource.h"
#endif
@@ -19,7 +20,20 @@
namespace {
-class L10nUtilTest: public PlatformTest {
+class StringWrapper {
+ public:
+ explicit StringWrapper(const std::wstring& string) : string_(string) {}
+ const std::wstring& string() const { return string_; }
+
+ private:
+ std::wstring string_;
+
+ DISALLOW_COPY_AND_ASSIGN(StringWrapper);
+};
+
+} // namespace
+
+class L10nUtilTest : public PlatformTest {
};
#if defined(OS_WIN)
@@ -160,6 +174,20 @@ TEST_F(L10nUtilTest, GetAppLocale) {
Locale::setDefault(locale, error_code);
}
+TEST_F(L10nUtilTest, SortStringsUsingFunction) {
+ std::vector<StringWrapper*> strings;
+ strings.push_back(new StringWrapper(L"C"));
+ strings.push_back(new StringWrapper(L"d"));
+ strings.push_back(new StringWrapper(L"b"));
+ strings.push_back(new StringWrapper(L"a"));
+ l10n_util::SortStringsUsingMethod(L"en-US", &strings, &StringWrapper::string);
+ ASSERT_TRUE(L"a" == strings[0]->string());
+ ASSERT_TRUE(L"b" == strings[1]->string());
+ ASSERT_TRUE(L"C" == strings[2]->string());
+ ASSERT_TRUE(L"d" == strings[3]->string());
+ STLDeleteElements(&strings);
+}
+
TEST_F(L10nUtilTest, GetFirstStrongCharacterDirection) {
// Test pure LTR string.
std::wstring string(L"foo bar");
@@ -334,5 +362,3 @@ TEST_F(L10nUtilTest, WrapPathWithLTRFormatting) {
EXPECT_EQ(wrapped_path, test_data[i].wrapped_path);
}
}
-}
-