diff options
author | maruel@google.com <maruel@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-29 20:01:03 +0000 |
---|---|---|
committer | maruel@google.com <maruel@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-29 20:01:03 +0000 |
commit | 5393a93be897b9aaf541577d70b89f433d829772 (patch) | |
tree | 1be16e6c5c2884fc19aedba2a8721154194b6b22 /chrome/common/win_util_unittest.cc | |
parent | 3b89a9d679792f6875be3f1a7051ff0275d88306 (diff) | |
download | chromium_src-5393a93be897b9aaf541577d70b89f433d829772.zip chromium_src-5393a93be897b9aaf541577d70b89f433d829772.tar.gz chromium_src-5393a93be897b9aaf541577d70b89f433d829772.tar.bz2 |
Fix the unit test when run from a MUI-Aware Vista installation and the current UI language is not the same as the installation language.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1549 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/win_util_unittest.cc')
-rw-r--r-- | chrome/common/win_util_unittest.cc | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/chrome/common/win_util_unittest.cc b/chrome/common/win_util_unittest.cc index af117ed..7da5fa1 100644 --- a/chrome/common/win_util_unittest.cc +++ b/chrome/common/win_util_unittest.cc @@ -8,18 +8,42 @@ #include "testing/gtest/include/gtest/gtest.h" class WinUtilTest: public testing::Test { + protected: + // Retrieve the OS primary language + static unsigned GetSystemLanguage() { + std::wstring language; + + typedef BOOL (WINAPI *fnGetThreadPreferredUILanguages)( + DWORD dwFlags, + PULONG pulNumLanguages, + PWSTR pwszLanguagesBuffer, + PULONG pcchLanguagesBuffer); + fnGetThreadPreferredUILanguages pGetThreadPreferredUILanguages = NULL; + pGetThreadPreferredUILanguages = + reinterpret_cast<fnGetThreadPreferredUILanguages>( + GetProcAddress(GetModuleHandle(L"kernel32.dll"), + "GetThreadPreferredUILanguages")); + if (pGetThreadPreferredUILanguages) { + // Vista, MUI-aware. + ULONG number = 0; + wchar_t buffer[256] = {0}; + ULONG buffer_size = sizeof(buffer); + EXPECT_TRUE(pGetThreadPreferredUILanguages(MUI_LANGUAGE_ID, &number, + buffer, &buffer_size)); + language = buffer; + } else { + // XP + RegKey language_key(HKEY_LOCAL_MACHINE, + L"SYSTEM\\CurrentControlSet\\Control\\Nls\\Language"); + language_key.ReadValue(L"InstallLanguage", &language); + } + wchar_t * unused_endptr; + return PRIMARYLANGID(wcstol(language.c_str(), &unused_endptr, 16)); + } }; -// Retrieve the OS primary language -unsigned GetSystemLanguage() { - RegKey language_key(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Nls\\Language"); - std::wstring language; - language_key.ReadValue(L"InstallLanguage", &language); - wchar_t * unused_endptr; - return PRIMARYLANGID(wcstol(language.c_str(), &unused_endptr, 16)); -} -TEST(WinUtilTest, FormatMessage) { +TEST_F(WinUtilTest, FormatMessage) { const int kAccessDeniedErrorCode = 5; SetLastError(kAccessDeniedErrorCode); ASSERT_EQ(GetLastError(), kAccessDeniedErrorCode); @@ -30,11 +54,11 @@ TEST(WinUtilTest, FormatMessage) { if (language == LANG_ENGLISH) { // This test would fail on non-English system. TrimWhitespace(win_util::FormatLastWin32Error(), TRIM_ALL, &value); - EXPECT_EQ(value, std::wstring(L"Access is denied.")); + EXPECT_EQ(std::wstring(L"Access is denied."), value); } else if (language == LANG_FRENCH) { // This test would fail on non-French system. TrimWhitespace(win_util::FormatLastWin32Error(), TRIM_ALL, &value); - EXPECT_EQ(value, std::wstring(L"Acc\00e8s refus\00e9.")); + EXPECT_EQ(std::wstring(L"Acc\u00e8s refus\u00e9."), value); } else { EXPECT_TRUE(0) << "Please implement the test for your OS language."; } @@ -61,7 +85,7 @@ TEST(WinUtilTest, FormatMessage) { LocalFree(string_buffer); } -TEST(WinUtilTest, EnsureRectIsVisibleInRect) { +TEST_F(WinUtilTest, EnsureRectIsVisibleInRect) { gfx::Rect parent_rect(0, 0, 500, 400); { |