1 // Copyright 2013 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 #include "base/i18n/timezone.h" 6 7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "third_party/icu/source/common/unicode/strenum.h" 9 #include "third_party/icu/source/common/unicode/unistr.h" 10 #include "third_party/icu/source/i18n/unicode/timezone.h" 11 12 namespace base { 13 namespace { 14 TEST(TimezoneTest,CountryCodeForTimezones)15TEST(TimezoneTest, CountryCodeForTimezones) { 16 std::unique_ptr<icu::StringEnumeration> timezones( 17 icu::TimeZone::createEnumeration()); 18 19 UErrorCode status = U_ZERO_ERROR; 20 while (const icu::UnicodeString* timezone = timezones->snext(status)) { 21 icu::TimeZone::adoptDefault(icu::TimeZone::createTimeZone(*timezone)); 22 23 std::string country_code = CountryCodeForCurrentTimezone(); 24 // On some systems (such as Android or some flavors of Linux), ICU may come 25 // up empty. With https://chromium-review.googlesource.com/c/512282/ , ICU 26 // will not fail any more. See also 27 // http://bugs.icu-project.org/trac/ticket/13208 . Even with that, ICU 28 // returns '001' (world) for region-agnostic timezones such as Etc/UTC and 29 // |CountryCodeForCurrentTimezone| returns an empty string so that the next 30 // fallback can be tried by a customer. 31 if (!country_code.empty()) 32 EXPECT_EQ(2U, country_code.size()) << "country_code = " << country_code; 33 } 34 35 icu::TimeZone::adoptDefault(nullptr); 36 } 37 38 } // namespace 39 } // namespace base 40