OLD | NEW |
(Empty) | |
| 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 |
| 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/stl_util.h" |
| 7 #include "chromeos/settings/timezone_settings_helper.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/icu/source/common/unicode/unistr.h" |
| 10 #include "third_party/icu/source/i18n/unicode/timezone.h" |
| 11 |
| 12 namespace chromeos { |
| 13 namespace system { |
| 14 |
| 15 using icu::TimeZone; |
| 16 using icu::UnicodeString; |
| 17 |
| 18 const char* kTimeZones[] = { |
| 19 "America/Los_Angeles", |
| 20 "America/Vancouver", |
| 21 "America/Chicago", |
| 22 "America/Winnipeg", |
| 23 "America/Mexico_City", |
| 24 "America/Buenos_Aires", |
| 25 "Asia/Ho_Chi_Minh", |
| 26 "Asia/Seoul", |
| 27 "Europe/Athens", |
| 28 "Asia/Ulaanbaatar", |
| 29 }; |
| 30 |
| 31 class KnownTimeZoneTest : public testing::Test { |
| 32 public: |
| 33 KnownTimeZoneTest() {} |
| 34 ~KnownTimeZoneTest() override {} |
| 35 |
| 36 void SetUp() override { |
| 37 for (const char* id : kTimeZones) { |
| 38 timezones_.push_back(TimeZone::createTimeZone(UnicodeString(id))); |
| 39 } |
| 40 } |
| 41 |
| 42 void TearDown() override { STLDeleteElements(&timezones_); } |
| 43 |
| 44 protected: |
| 45 std::vector<TimeZone*> timezones_; |
| 46 }; |
| 47 |
| 48 TEST_F(KnownTimeZoneTest, IdMatch) { |
| 49 static struct { |
| 50 const char* id; |
| 51 const char* matched; |
| 52 } timezone_match_list[] = { |
| 53 // Self matches |
| 54 {"America/Los_Angeles", "America/Los_Angeles"}, |
| 55 {"America/Vancouver", "America/Vancouver"}, // Should not be Los_Angeles |
| 56 {"America/Winnipeg", "America/Winnipeg"}, |
| 57 {"Asia/Seoul", "Asia/Seoul"}, |
| 58 // Canonical ID matches |
| 59 {"Canada/Pacific", "America/Vancouver"}, |
| 60 {"US/Pacific", "America/Los_Angeles"}, |
| 61 {"US/Central", "America/Chicago"}, |
| 62 {"Mexico/General", "America/Mexico_City"}, |
| 63 {"Asia/Ulan_Bator", "Asia/Ulaanbaatar"}, |
| 64 // Asia/Saigon is canonical, but the list has Asia/Ho_Chi_Minh |
| 65 {"Asia/Saigon", "Asia/Ho_Chi_Minh"}, |
| 66 }; |
| 67 |
| 68 for (const auto& pair : timezone_match_list) { |
| 69 scoped_ptr<TimeZone> input( |
| 70 TimeZone::createTimeZone(UnicodeString(pair.id))); |
| 71 scoped_ptr<TimeZone> expected( |
| 72 TimeZone::createTimeZone(UnicodeString(pair.matched))); |
| 73 const TimeZone* actual = GetKnownTimezoneOrNull(*input, timezones_); |
| 74 EXPECT_NE(nullptr, actual) << "input=" << pair.id; |
| 75 if (actual == nullptr) |
| 76 continue; |
| 77 UnicodeString actual_id; |
| 78 actual->getID(actual_id); |
| 79 std::string actual_id_str; |
| 80 actual_id.toUTF8String(actual_id_str); |
| 81 EXPECT_EQ(*expected, *actual) << "input=" << pair.id << ", " |
| 82 << "expected=" << pair.matched << ", " |
| 83 << "actual=" << actual_id_str; |
| 84 } |
| 85 } |
| 86 |
| 87 TEST_F(KnownTimeZoneTest, NoMatch) { |
| 88 static const char* no_match_list[] = { |
| 89 "Africa/Juba", // Not in the list |
| 90 "Africa/Tripoli", // UTC+2 with no DST != Europe/Athens |
| 91 "America/Tijuana", // Historically != America/Los_Angeles |
| 92 "Europe/Sofia", // Historically != Europe/Athens |
| 93 "America/Argentina/Cordoba", // Historically != America/Buenos_Aires |
| 94 "Asia/Tokyo", // Historically != Asia/Seoul |
| 95 }; |
| 96 for (const char* id : no_match_list) { |
| 97 scoped_ptr<TimeZone> input(TimeZone::createTimeZone(UnicodeString(id))); |
| 98 EXPECT_EQ(NULL, GetKnownTimezoneOrNull(*input, timezones_)) |
| 99 << "input=" << id; |
| 100 } |
| 101 } |
| 102 |
| 103 } // namespace system |
| 104 } // namespace chromeos |
OLD | NEW |