icu_test_util.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #ifndef BASE_TEST_ICU_TEST_UTIL_H_
  5. #define BASE_TEST_ICU_TEST_UTIL_H_
  6. #include <memory>
  7. #include <string>
  8. #include "third_party/icu/source/common/unicode/uversion.h"
  9. U_NAMESPACE_BEGIN
  10. class TimeZone;
  11. U_NAMESPACE_END
  12. namespace base {
  13. namespace test {
  14. // In unit tests, prefer ScopedRestoreICUDefaultLocale over
  15. // calling base::i18n::SetICUDefaultLocale() directly. This scoper makes it
  16. // harder to accidentally forget to reset the locale.
  17. class ScopedRestoreICUDefaultLocale {
  18. public:
  19. ScopedRestoreICUDefaultLocale();
  20. explicit ScopedRestoreICUDefaultLocale(const std::string& locale);
  21. ScopedRestoreICUDefaultLocale(const ScopedRestoreICUDefaultLocale&) = delete;
  22. ScopedRestoreICUDefaultLocale& operator=(
  23. const ScopedRestoreICUDefaultLocale&) = delete;
  24. ~ScopedRestoreICUDefaultLocale();
  25. private:
  26. const std::string default_locale_;
  27. };
  28. // In unit tests, prefer ScopedRestoreDefaultTimezone over
  29. // calling icu::TimeZone::adoptDefault() directly. This scoper makes it
  30. // harder to accidentally forget to reset the locale.
  31. class ScopedRestoreDefaultTimezone {
  32. public:
  33. ScopedRestoreDefaultTimezone(const char* zoneid);
  34. ~ScopedRestoreDefaultTimezone();
  35. ScopedRestoreDefaultTimezone(const ScopedRestoreDefaultTimezone&) = delete;
  36. ScopedRestoreDefaultTimezone& operator=(const ScopedRestoreDefaultTimezone&) =
  37. delete;
  38. private:
  39. std::unique_ptr<icu::TimeZone> original_zone_;
  40. };
  41. void InitializeICUForTesting();
  42. } // namespace test
  43. } // namespace base
  44. #endif // BASE_TEST_ICU_TEST_UTIL_H_