Commit 678a41bb authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Add a comment for base::test::ScopedRestoreICUDefaultLocale.

Fix some nits too.

Change-Id: Ida343bd53083015d9a4027e2fd85f559e65cde90
Reviewed-on: https://chromium-review.googlesource.com/959692Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543086}
parent 391e9004
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
namespace base { namespace base {
namespace test { namespace test {
ScopedRestoreICUDefaultLocale::ScopedRestoreICUDefaultLocale()
: ScopedRestoreICUDefaultLocale(std::string()) {}
ScopedRestoreICUDefaultLocale::ScopedRestoreICUDefaultLocale( ScopedRestoreICUDefaultLocale::ScopedRestoreICUDefaultLocale(
const std::string& locale) const std::string& locale)
: default_locale_(uloc_getDefault()) { : default_locale_(uloc_getDefault()) {
...@@ -25,9 +28,9 @@ ScopedRestoreICUDefaultLocale::~ScopedRestoreICUDefaultLocale() { ...@@ -25,9 +28,9 @@ ScopedRestoreICUDefaultLocale::~ScopedRestoreICUDefaultLocale() {
} }
void InitializeICUForTesting() { void InitializeICUForTesting() {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch( if (!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kTestDoNotInitializeIcu)) { switches::kTestDoNotInitializeIcu)) {
base::i18n::AllowMultipleInitializeCallsForTesting(); i18n::AllowMultipleInitializeCallsForTesting();
i18n::InitializeICU(); i18n::InitializeICU();
} }
} }
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef BASE_ICU_TEST_UTIL_H_ #ifndef BASE_TEST_ICU_TEST_UTIL_H_
#define BASE_ICU_TEST_UTIL_H_ #define BASE_TEST_ICU_TEST_UTIL_H_
#include <string> #include <string>
...@@ -12,13 +12,17 @@ ...@@ -12,13 +12,17 @@
namespace base { namespace base {
namespace test { namespace test {
// In unit tests, prefer ScopedRestoreICUDefaultLocale over
// calling base::i18n::SetICUDefaultLocale() directly. This scoper makes it
// harder to accidentally forget to reset the locale.
class ScopedRestoreICUDefaultLocale { class ScopedRestoreICUDefaultLocale {
public: public:
ScopedRestoreICUDefaultLocale(const std::string& locale = std::string()); ScopedRestoreICUDefaultLocale();
explicit ScopedRestoreICUDefaultLocale(const std::string& locale);
~ScopedRestoreICUDefaultLocale(); ~ScopedRestoreICUDefaultLocale();
private: private:
std::string default_locale_; const std::string default_locale_;
DISALLOW_COPY_AND_ASSIGN(ScopedRestoreICUDefaultLocale); DISALLOW_COPY_AND_ASSIGN(ScopedRestoreICUDefaultLocale);
}; };
...@@ -28,4 +32,4 @@ void InitializeICUForTesting(); ...@@ -28,4 +32,4 @@ void InitializeICUForTesting();
} // namespace test } // namespace test
} // namespace base } // namespace base
#endif // BASE_ICU_TEST_UTIL_H_ #endif // BASE_TEST_ICU_TEST_UTIL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment