diff options
-rw-r--r-- | base/base.gyp | 9 | ||||
-rw-r--r-- | base/sys_string_conversions_unittest.cc | 10 | ||||
-rw-r--r-- | base/test/scoped_locale.cc | 23 | ||||
-rw-r--r-- | base/test/scoped_locale.h | 30 | ||||
-rw-r--r-- | base/test/test_util.h | 41 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 5 | ||||
-rw-r--r-- | chrome/common/time_format_browsertest.cc | 15 |
7 files changed, 56 insertions, 77 deletions
diff --git a/base/base.gyp b/base/base.gyp index 668171d..f8356d7 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -312,12 +312,6 @@ '../build/linux/system.gyp:gtk', ], }], - ['os_posix==0', { - 'sources!': [ - 'test/scoped_locale.cc', - 'test/scoped_locale.h', - ], - }], ], 'sources': [ 'perftimer.cc', @@ -327,8 +321,6 @@ 'test/multiprocess_test.h', 'test/perf_test_suite.cc', 'test/perf_test_suite.h', - 'test/scoped_locale.cc', - 'test/scoped_locale.h', 'test/test_file_util.h', 'test/test_file_util_linux.cc', 'test/test_file_util_mac.cc', @@ -340,6 +332,7 @@ 'test/test_switches.h', 'test/test_timeouts.cc', 'test/test_timeouts.h', + 'test/test_util.h', ], }, { diff --git a/base/sys_string_conversions_unittest.cc b/base/sys_string_conversions_unittest.cc index a3393ba..fa711f3 100644 --- a/base/sys_string_conversions_unittest.cc +++ b/base/sys_string_conversions_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2008 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. @@ -7,7 +7,7 @@ #include "base/basictypes.h" #include "base/string_piece.h" -#include "base/test/scoped_locale.h" +#include "base/test/test_util.h" #include "base/utf_string_conversions.h" #include "base/sys_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" @@ -77,7 +77,7 @@ TEST(SysStrings, SysUTF8ToWide) { TEST(SysStrings, SysWideToNativeMB) { using base::SysWideToNativeMB; - base::ScopedLocale locale("en_US.utf-8"); + base::ScopedSetLocale locale("en_US.utf-8"); EXPECT_EQ("Hello, world", SysWideToNativeMB(L"Hello, world")); EXPECT_EQ("\xe4\xbd\xa0\xe5\xa5\xbd", SysWideToNativeMB(L"\x4f60\x597d")); @@ -108,7 +108,7 @@ TEST(SysStrings, SysWideToNativeMB) { // We assume the test is running in a UTF8 locale. TEST(SysStrings, SysNativeMBToWide) { using base::SysNativeMBToWide; - base::ScopedLocale locale("en_US.utf-8"); + base::ScopedSetLocale locale("en_US.utf-8"); EXPECT_EQ(L"Hello, world", SysNativeMBToWide("Hello, world")); EXPECT_EQ(L"\x4f60\x597d", SysNativeMBToWide("\xe4\xbd\xa0\xe5\xa5\xbd")); // >16 bits @@ -162,7 +162,7 @@ static const wchar_t* const kConvertRoundtripCases[] = { TEST(SysStrings, SysNativeMBAndWide) { - base::ScopedLocale locale("en_US.utf-8"); + base::ScopedSetLocale locale("en_US.utf-8"); for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) { std::wstring wide = kConvertRoundtripCases[i]; std::wstring trip = base::SysNativeMBToWide(base::SysWideToNativeMB(wide)); diff --git a/base/test/scoped_locale.cc b/base/test/scoped_locale.cc deleted file mode 100644 index 35b3fbe..0000000 --- a/base/test/scoped_locale.cc +++ /dev/null @@ -1,23 +0,0 @@ -// 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/test/scoped_locale.h" - -#include <locale.h> - -#include "testing/gtest/include/gtest/gtest.h" - -namespace base { - -ScopedLocale::ScopedLocale(const std::string& locale) { - prev_locale_ = setlocale(LC_ALL, NULL); - EXPECT_TRUE(setlocale(LC_ALL, locale.c_str()) != NULL) << - "Failed to set locale: " << locale; -} - -ScopedLocale::~ScopedLocale() { - EXPECT_STREQ(prev_locale_.c_str(), setlocale(LC_ALL, prev_locale_.c_str())); -} - -} // namespace base diff --git a/base/test/scoped_locale.h b/base/test/scoped_locale.h deleted file mode 100644 index 1fd1e18..0000000 --- a/base/test/scoped_locale.h +++ /dev/null @@ -1,30 +0,0 @@ -// 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_TEST_SCOPED_LOCALE_H_ -#define BASE_TEST_SCOPED_LOCALE_H_ -#pragma once - -#include <string> - -#include "base/basictypes.h" - -namespace base { - -// Sets the given |locale| on construction, and restores the previous locale -// on destruction. -class ScopedLocale { - public: - explicit ScopedLocale(const std::string& locale); - ~ScopedLocale(); - - private: - std::string prev_locale_; - - DISALLOW_COPY_AND_ASSIGN(ScopedLocale); -}; - -} // namespace base - -#endif // BASE_TEST_SCOPED_LOCALE_H_ diff --git a/base/test/test_util.h b/base/test/test_util.h new file mode 100644 index 0000000..63f0b16 --- /dev/null +++ b/base/test/test_util.h @@ -0,0 +1,41 @@ +// 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_TEST_TEST_UTIL_H_ +#define BASE_TEST_TEST_UTIL_H_ +#pragma once + +// Generic utilities used only by tests. + +#include <locale.h> + +#include <string> + +namespace base { + +#if defined(OS_POSIX) + +// Sets the given |locale| on construction, and restores the previous locale +// on destruction. +class ScopedSetLocale { + public: + explicit ScopedSetLocale(const char* locale) { + old_locale_ = setlocale(LC_ALL, NULL); + setlocale(LC_ALL, locale); + } + ~ScopedSetLocale() { + setlocale(LC_ALL, old_locale_.c_str()); + } + + private: + std::string old_locale_; + + DISALLOW_COPY_AND_ASSIGN(ScopedSetLocale); +}; + +#endif + +} // namespace base + +#endif // BASE_TEST_TEST_UTIL_H_ diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 2d614fb..c7e8094 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2682,11 +2682,6 @@ 'browser/extensions/browser_action_test_util_mac.mm', ], }], - ['os_posix == 0', { - 'sources!': [ - 'common/time_format_browsertest.cc', - ], - }], ['os_posix == 1 and OS != "mac"', { 'conditions': [ ['linux_use_tcmalloc==1', { diff --git a/chrome/common/time_format_browsertest.cc b/chrome/common/time_format_browsertest.cc index 812a0e2..3aa8582 100644 --- a/chrome/common/time_format_browsertest.cc +++ b/chrome/common/time_format_browsertest.cc @@ -11,20 +11,20 @@ // this test is executed on its own process. #include "base/string16.h" -#include "base/test/scoped_locale.h" +#include "base/test/test_util.h" #include "base/utf_string_conversions.h" #include "chrome/common/time_format.h" #include "chrome/test/in_process_browser_test.h" +#if defined(OS_POSIX) using base::TimeDelta; -class TimeFormatBrowserTest : public InProcessBrowserTest { +class TimeFormatBrowserTest: public InProcessBrowserTest { public: - TimeFormatBrowserTest() : scoped_locale_("fr_FR.utf-8") { - } + TimeFormatBrowserTest(): scoped_locale_("fr_FR.utf-8") {} private: - base::ScopedLocale scoped_locale_; + base::ScopedSetLocale scoped_locale_; }; IN_PROC_BROWSER_TEST_F(TimeFormatBrowserTest, DecimalPointNotDot) { @@ -35,5 +35,8 @@ IN_PROC_BROWSER_TEST_F(TimeFormatBrowserTest, DecimalPointNotDot) { // http://crbug.com/60476 string16 one_min = TimeFormat::TimeRemainingShort(TimeDelta::FromMinutes(1)); - EXPECT_EQ(ASCIIToUTF16("1 min"), one_min); + EXPECT_EQ(ASCIIToUTF16("1 min"), one_min) << "fr_FR.utf-8 locale generates " + << one_min; } + +#endif // defined(OS_POSIX) |