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