From ef0d50ebfaa5e60b8a5d06e7222618c0aa48b000 Mon Sep 17 00:00:00 2001 From: "joaodasilva@chromium.org" Date: Mon, 20 Jun 2011 15:03:36 +0000 Subject: Revert 89664 - Cleanup in base/test. This is related to http://codereview.chromium.org/7003028/. BUG=60476 TEST=None Review URL: http://codereview.chromium.org/7129056 TBR=joaodasilva@chromium.org Review URL: http://codereview.chromium.org/7212008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89669 0039d316-1c4b-4281-b951-d872f2087c98 --- base/base.gyp | 9 +------- base/sys_string_conversions_unittest.cc | 10 ++++---- base/test/scoped_locale.cc | 23 ------------------ base/test/scoped_locale.h | 30 ------------------------ base/test/test_util.h | 41 +++++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 66 deletions(-) delete mode 100644 base/test/scoped_locale.cc delete mode 100644 base/test/scoped_locale.h create mode 100644 base/test/test_util.h (limited to 'base') 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 - -#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 - -#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 + +#include + +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_ -- cgit v1.1