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

Side by Side Diff: app/l10n_util_unittest.cc

Issue 5990008: Remove wstring from l10n_util. Part 1.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 12 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) 7 #if defined(OS_POSIX) && !defined(OS_MACOSX)
8 #include <cstdlib> 8 #include <cstdlib>
9 #endif 9 #endif
10 10
(...skipping 14 matching lines...) Expand all
25 #include "base/win/windows_version.h" 25 #include "base/win/windows_version.h"
26 #endif 26 #endif
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "testing/platform_test.h" 28 #include "testing/platform_test.h"
29 #include "unicode/locid.h" 29 #include "unicode/locid.h"
30 30
31 namespace { 31 namespace {
32 32
33 class StringWrapper { 33 class StringWrapper {
34 public: 34 public:
35 explicit StringWrapper(const std::wstring& string) : string_(string) {} 35 explicit StringWrapper(const string16& string) : string_(string) {}
36 const std::wstring& string() const { return string_; } 36 const string16& string() const { return string_; }
37 37
38 private: 38 private:
39 std::wstring string_; 39 string16 string_;
40 40
41 DISALLOW_COPY_AND_ASSIGN(StringWrapper); 41 DISALLOW_COPY_AND_ASSIGN(StringWrapper);
42 }; 42 };
43 43
44 } // namespace 44 } // namespace
45 45
46 class L10nUtilTest : public PlatformTest { 46 class L10nUtilTest : public PlatformTest {
47 }; 47 };
48 48
49 #if defined(OS_WIN) 49 #if defined(OS_WIN)
50 // TODO(beng): disabled until app strings move to app. 50 // TODO(beng): disabled until app strings move to app.
51 TEST_F(L10nUtilTest, DISABLED_GetString) { 51 TEST_F(L10nUtilTest, DISABLED_GetString) {
52 std::wstring s = l10n_util::GetString(IDS_SIMPLE); 52 std::string s = l10n_util::GetStringUTF8(IDS_SIMPLE);
53 EXPECT_EQ(std::wstring(L"Hello World!"), s); 53 EXPECT_EQ(std::string("Hello World!"), s);
54 54
55 s = l10n_util::GetStringF(IDS_PLACEHOLDERS, L"chrome", L"10"); 55 s = l10n_util::GetStringFUTF8(IDS_PLACEHOLDERS,
56 EXPECT_EQ(std::wstring(L"Hello, chrome. Your number is 10."), s); 56 UTF8ToUTF16("chrome"),
57 UTF8ToUTF16("10"));
58 EXPECT_EQ(std::string("Hello, chrome. Your number is 10."), s);
57 59
58 s = l10n_util::GetStringF(IDS_PLACEHOLDERS_2, 20); 60 string16 s16 = l10n_util::GetStringFUTF16(IDS_PLACEHOLDERS_2, 20);
Evan Martin 2010/12/24 01:00:42 Can't this use a std::string as well?
Avi (use Gerrit) 2010/12/28 15:02:55 No, this is a test for the int helper.
59 EXPECT_EQ(std::wstring(L"You owe me $20."), s); 61 EXPECT_EQ(UTF8ToUTF16("You owe me $20."), s16);
60 } 62 }
61 #endif // defined(OS_WIN) 63 #endif // defined(OS_WIN)
62 64
63 TEST_F(L10nUtilTest, TruncateString) { 65 TEST_F(L10nUtilTest, TruncateString) {
64 string16 string = ASCIIToUTF16("foooooey bxxxar baz"); 66 string16 string = ASCIIToUTF16("foooooey bxxxar baz");
65 67
66 // Make sure it doesn't modify the string if length > string length. 68 // Make sure it doesn't modify the string if length > string length.
67 EXPECT_EQ(string, l10n_util::TruncateString(string, 100)); 69 EXPECT_EQ(string, l10n_util::TruncateString(string, 100));
68 70
69 // Test no characters. 71 // Test no characters.
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // Clean up. 280 // Clean up.
279 PathService::Override(app::DIR_LOCALES, orig_locale_dir); 281 PathService::Override(app::DIR_LOCALES, orig_locale_dir);
280 file_util::Delete(new_locale_dir, true); 282 file_util::Delete(new_locale_dir, true);
281 UErrorCode error_code = U_ZERO_ERROR; 283 UErrorCode error_code = U_ZERO_ERROR;
282 icu::Locale::setDefault(locale, error_code); 284 icu::Locale::setDefault(locale, error_code);
283 } 285 }
284 #endif // !defined(OS_MACOSX) 286 #endif // !defined(OS_MACOSX)
285 287
286 TEST_F(L10nUtilTest, SortStringsUsingFunction) { 288 TEST_F(L10nUtilTest, SortStringsUsingFunction) {
287 std::vector<StringWrapper*> strings; 289 std::vector<StringWrapper*> strings;
288 strings.push_back(new StringWrapper(L"C")); 290 strings.push_back(new StringWrapper(UTF8ToUTF16("C")));
289 strings.push_back(new StringWrapper(L"d")); 291 strings.push_back(new StringWrapper(UTF8ToUTF16("d")));
290 strings.push_back(new StringWrapper(L"b")); 292 strings.push_back(new StringWrapper(UTF8ToUTF16("b")));
291 strings.push_back(new StringWrapper(L"a")); 293 strings.push_back(new StringWrapper(UTF8ToUTF16("a")));
292 l10n_util::SortStringsUsingMethod(L"en-US", &strings, &StringWrapper::string); 294 l10n_util::SortStringsUsingMethod("en-US",
293 ASSERT_TRUE(L"a" == strings[0]->string()); 295 &strings,
294 ASSERT_TRUE(L"b" == strings[1]->string()); 296 &StringWrapper::string);
295 ASSERT_TRUE(L"C" == strings[2]->string()); 297 ASSERT_TRUE(UTF8ToUTF16("a") == strings[0]->string());
296 ASSERT_TRUE(L"d" == strings[3]->string()); 298 ASSERT_TRUE(UTF8ToUTF16("b") == strings[1]->string());
299 ASSERT_TRUE(UTF8ToUTF16("C") == strings[2]->string());
300 ASSERT_TRUE(UTF8ToUTF16("d") == strings[3]->string());
297 STLDeleteElements(&strings); 301 STLDeleteElements(&strings);
298 } 302 }
299 303
300 // Test upper and lower case string conversion. 304 // Test upper and lower case string conversion.
301 TEST_F(L10nUtilTest, UpperLower) { 305 TEST_F(L10nUtilTest, UpperLower) {
302 string16 mixed(ASCIIToUTF16("Text with UPPer & lowER casE.")); 306 string16 mixed(ASCIIToUTF16("Text with UPPer & lowER casE."));
303 const string16 expected_lower(ASCIIToUTF16("text with upper & lower case.")); 307 const string16 expected_lower(ASCIIToUTF16("text with upper & lower case."));
304 const string16 expected_upper(ASCIIToUTF16("TEXT WITH UPPER & LOWER CASE.")); 308 const string16 expected_upper(ASCIIToUTF16("TEXT WITH UPPER & LOWER CASE."));
305 309
306 string16 result = l10n_util::ToLower(mixed); 310 string16 result = l10n_util::ToLower(mixed);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("Latin")); 388 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("Latin"));
385 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("German")); 389 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("German"));
386 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("pt--BR")); 390 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("pt--BR"));
387 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("sl-macedonia")); 391 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("sl-macedonia"));
388 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("@")); 392 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("@"));
389 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@")); 393 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@"));
390 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x")); 394 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x"));
391 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x=")); 395 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x="));
392 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@=y")); 396 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@=y"));
393 } 397 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698