1 // Copyright 2015 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_TEST_ICU_TEST_UTIL_H_ 6 #define BASE_TEST_ICU_TEST_UTIL_H_ 7 8 #include <memory> 9 #include <string> 10 11 #include "third_party/icu/source/common/unicode/uversion.h" 12 13 U_NAMESPACE_BEGIN 14 class TimeZone; 15 U_NAMESPACE_END 16 17 namespace base { 18 namespace test { 19 20 // In unit tests, prefer ScopedRestoreICUDefaultLocale over 21 // calling base::i18n::SetICUDefaultLocale() directly. This scoper makes it 22 // harder to accidentally forget to reset the locale. 23 class ScopedRestoreICUDefaultLocale { 24 public: 25 ScopedRestoreICUDefaultLocale(); 26 explicit ScopedRestoreICUDefaultLocale(const std::string& locale); 27 ScopedRestoreICUDefaultLocale(const ScopedRestoreICUDefaultLocale&) = delete; 28 ScopedRestoreICUDefaultLocale& operator=( 29 const ScopedRestoreICUDefaultLocale&) = delete; 30 ~ScopedRestoreICUDefaultLocale(); 31 32 private: 33 const std::string default_locale_; 34 }; 35 36 // In unit tests, prefer ScopedRestoreDefaultTimezone over 37 // calling icu::TimeZone::adoptDefault() directly. This scoper makes it 38 // harder to accidentally forget to reset the locale. 39 class ScopedRestoreDefaultTimezone { 40 public: 41 ScopedRestoreDefaultTimezone(const char* zoneid); 42 ~ScopedRestoreDefaultTimezone(); 43 44 ScopedRestoreDefaultTimezone(const ScopedRestoreDefaultTimezone&) = delete; 45 ScopedRestoreDefaultTimezone& operator=(const ScopedRestoreDefaultTimezone&) = 46 delete; 47 48 private: 49 std::unique_ptr<icu::TimeZone> original_zone_; 50 }; 51 52 void InitializeICUForTesting(); 53 54 } // namespace test 55 } // namespace base 56 57 #endif // BASE_TEST_ICU_TEST_UTIL_H_ 58