summaryrefslogtreecommitdiffstats
path: root/chrome/common/win_util_unittest.cc
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-17 17:00:04 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-17 17:00:04 +0000
commit3b95b86342778c3a18b70158280332c0601516c9 (patch)
tree3baeb2e90f6a0160cfe9c6763f13d5d339bb7229 /chrome/common/win_util_unittest.cc
parentbc9147a10c7287f285ddc1c246cc9d38cd5987c4 (diff)
downloadchromium_src-3b95b86342778c3a18b70158280332c0601516c9.zip
chromium_src-3b95b86342778c3a18b70158280332c0601516c9.tar.gz
chromium_src-3b95b86342778c3a18b70158280332c0601516c9.tar.bz2
Adds logging to file_util::WriteFile to figure out why writing
bookmarks is failing for some people. As a result of this I moved some code from common/win_util to base/win_util so that file_util_win could call it. The only changes to this code are formatting. BUG=none TEST=none Review URL: http://codereview.chromium.org/2931 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2312 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/win_util_unittest.cc')
-rw-r--r--chrome/common/win_util_unittest.cc85
1 files changed, 1 insertions, 84 deletions
diff --git a/chrome/common/win_util_unittest.cc b/chrome/common/win_util_unittest.cc
index 8df32e1..016e391 100644
--- a/chrome/common/win_util_unittest.cc
+++ b/chrome/common/win_util_unittest.cc
@@ -2,91 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/registry.h"
-#include "base/string_util.h"
#include "chrome/common/win_util.h"
#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));
- }
-};
-
-
-TEST_F(WinUtilTest, FormatMessage) {
- unsigned language = GetSystemLanguage();
- ASSERT_TRUE(language);
-
- const int kAccessDeniedErrorCode = 5;
- SetLastError(kAccessDeniedErrorCode);
- ASSERT_EQ(GetLastError(), kAccessDeniedErrorCode);
- std::wstring value;
-
- if (language == LANG_ENGLISH) {
- // This test would fail on non-English system.
- TrimWhitespace(win_util::FormatLastWin32Error(), TRIM_ALL, &value);
- 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(std::wstring(L"Acc\u00e8s refus\u00e9."), value);
- } else {
- EXPECT_TRUE(0) << "Please implement the test for your OS language.";
- }
-
- // Manually call the OS function
- wchar_t * string_buffer = NULL;
- unsigned string_length = ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
- kAccessDeniedErrorCode, 0,
- reinterpret_cast<wchar_t *>(&string_buffer),
- 0, NULL);
-
- // Verify the call succeeded
- ASSERT_TRUE(string_length);
- ASSERT_TRUE(string_buffer);
-
- // Verify the string is the same by different calls
- EXPECT_EQ(win_util::FormatLastWin32Error(), std::wstring(string_buffer));
- EXPECT_EQ(win_util::FormatMessage(kAccessDeniedErrorCode),
- std::wstring(string_buffer));
-
- // Done with the buffer allocated by ::FormatMessage()
- LocalFree(string_buffer);
-}
-
-TEST_F(WinUtilTest, EnsureRectIsVisibleInRect) {
+TEST(WinUtilTest, EnsureRectIsVisibleInRect) {
gfx::Rect parent_rect(0, 0, 500, 400);
{
@@ -131,5 +50,3 @@ TEST_F(WinUtilTest, EnsureRectIsVisibleInRect) {
EXPECT_EQ(gfx::Rect(20, 20, 100, 380), child_rect);
}
}
-
-