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/test | |
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/test')
-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 |
3 files changed, 53 insertions, 41 deletions
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_ |