icu_test_util.h 1.7 KB

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