• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/test/icu_test_util.h"
6 
7 #include "base/base_switches.h"
8 #include "base/command_line.h"
9 #include "base/i18n/icu_util.h"
10 #include "base/i18n/rtl.h"
11 #include "third_party/icu/source/common/unicode/uloc.h"
12 
13 namespace base {
14 namespace test {
15 
ScopedRestoreICUDefaultLocale()16 ScopedRestoreICUDefaultLocale::ScopedRestoreICUDefaultLocale()
17     : ScopedRestoreICUDefaultLocale(std::string()) {}
18 
ScopedRestoreICUDefaultLocale(const std::string & locale)19 ScopedRestoreICUDefaultLocale::ScopedRestoreICUDefaultLocale(
20     const std::string& locale)
21     : default_locale_(uloc_getDefault()) {
22   if (!locale.empty())
23     i18n::SetICUDefaultLocale(locale.data());
24 }
25 
~ScopedRestoreICUDefaultLocale()26 ScopedRestoreICUDefaultLocale::~ScopedRestoreICUDefaultLocale() {
27   i18n::SetICUDefaultLocale(default_locale_.data());
28 }
29 
InitializeICUForTesting()30 void InitializeICUForTesting() {
31   if (!CommandLine::ForCurrentProcess()->HasSwitch(
32           switches::kTestDoNotInitializeIcu)) {
33     i18n::AllowMultipleInitializeCallsForTesting();
34     i18n::InitializeICU();
35   }
36 }
37 
38 }  // namespace test
39 }  // namespace base
40