diff options
author | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-20 17:44:05 +0000 |
---|---|---|
committer | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-20 17:44:05 +0000 |
commit | 3ae445e87c76883a093adcd2ab64082210102820 (patch) | |
tree | 8ef1bfc5e268a91f2ae167ae50321bc53cc9e581 /base | |
parent | d539beae684ad05d65dad3338c442bf472e89279 (diff) | |
download | chromium_src-3ae445e87c76883a093adcd2ab64082210102820.zip chromium_src-3ae445e87c76883a093adcd2ab64082210102820.tar.gz chromium_src-3ae445e87c76883a093adcd2ab64082210102820.tar.bz2 |
Cleanup in base/test.
This is related to http://codereview.chromium.org/7003028/.
BUG=60476
TEST=None
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=89664
Review URL: http://codereview.chromium.org/7129056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89681 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-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 |
5 files changed, 66 insertions, 47 deletions
diff --git a/base/base.gyp b/base/base.gyp index f8356d7..668171d 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -312,6 +312,12 @@ '../build/linux/system.gyp:gtk', ], }], + ['os_posix==0', { + 'sources!': [ + 'test/scoped_locale.cc', + 'test/scoped_locale.h', + ], + }], ], 'sources': [ 'perftimer.cc', @@ -321,6 +327,8 @@ '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', @@ -332,7 +340,6 @@ '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 fa711f3..a3393ba 100644 --- a/base/sys_string_conversions_unittest.cc +++ b/base/sys_string_conversions_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -7,7 +7,7 @@ #include "base/basictypes.h" #include "base/string_piece.h" -#include "base/test/test_util.h" +#include "base/test/scoped_locale.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::ScopedSetLocale locale("en_US.utf-8"); + base::ScopedLocale 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::ScopedSetLocale locale("en_US.utf-8"); + base::ScopedLocale 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::ScopedSetLocale locale("en_US.utf-8"); + base::ScopedLocale 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 new file mode 100644 index 0000000..35b3fbe --- /dev/null +++ b/base/test/scoped_locale.cc @@ -0,0 +1,23 @@ +// 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 new file mode 100644 index 0000000..1fd1e18 --- /dev/null +++ b/base/test/scoped_locale.h @@ -0,0 +1,30 @@ +// 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 deleted file mode 100644 index 63f0b16..0000000 --- a/base/test/test_util.h +++ /dev/null @@ -1,41 +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_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_ |