Chromium Code Reviews| 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 { | |
|
oshima
2015/04/23 18:30:45
move this inside chromeos::system
jungshik at Google
2015/04/23 19:48:12
Done.
| |
| 13 | |
| 14 const static char* kTimeZones[] = { | |
|
oshima
2015/04/23 18:30:45
static isn't necessary in anonymous namespace
jungshik at Google
2015/04/23 19:48:12
Acknowledged.
| |
| 15 "America/Los_Angeles", | |
| 16 "America/Vancouver", | |
| 17 "America/Chicago", | |
| 18 "America/Winnipeg", | |
| 19 "America/Mexico_City", | |
| 20 "America/Buenos_Aires", | |
| 21 "Asia/Ho_Chi_Minh", | |
| 22 "Asia/Seoul", | |
| 23 "Europe/Athens", | |
| 24 "Asia/Ulaanbaatar", | |
| 25 }; | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 namespace chromeos { | |
| 30 namespace system { | |
| 31 | |
| 32 using icu::TimeZone; | |
| 33 using icu::UnicodeString; | |
| 34 | |
| 35 class KnownTimeZoneTest : public testing::Test { | |
| 36 public: | |
| 37 KnownTimeZoneTest() {} | |
| 38 ~KnownTimeZoneTest() override {} | |
| 39 | |
| 40 void SetUp() override { | |
| 41 for (auto id : kTimeZones) { | |
|
oshima
2015/04/23 18:30:45
const auto*
jungshik at Google
2015/04/23 19:48:12
Done. Do you prefer 'const char*' or 'const auto*'
oshima
2015/04/23 22:01:24
I'd use auto only if the type is long. More explic
| |
| 42 timezones_.push_back(TimeZone::createTimeZone(UnicodeString(id))); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 void TearDown() override { STLDeleteElements(&timezones_); } | |
| 47 | |
| 48 protected: | |
| 49 std::vector<TimeZone*> timezones_; | |
| 50 }; | |
| 51 | |
| 52 TEST_F(KnownTimeZoneTest, IdMatch) { | |
| 53 static struct { | |
| 54 const char* id; | |
| 55 const char* matched; | |
| 56 } timezone_match_list[] = { | |
| 57 // Self matches | |
| 58 {"America/Los_Angeles", "America/Los_Angeles"}, | |
| 59 {"America/Vancouver", "America/Vancouver"}, // Should not be Los_Angeles | |
| 60 {"America/Winnipeg", "America/Winnipeg"}, | |
| 61 {"Asia/Seoul", "Asia/Seoul"}, | |
| 62 // Canonical ID matches | |
| 63 {"Canada/Pacific", "America/Vancouver"}, | |
| 64 {"US/Pacific", "America/Los_Angeles"}, | |
| 65 {"US/Central", "America/Chicago"}, | |
| 66 {"Mexico/General", "America/Mexico_City"}, | |
| 67 {"Asia/Ulan_Bator", "Asia/Ulaanbaatar"}, | |
| 68 // Asia/Saigon is canonical, but the list has Asia/Ho_Chi_Minh | |
| 69 {"Asia/Saigon", "Asia/Ho_Chi_Minh"}, | |
| 70 }; | |
| 71 | |
| 72 for (const auto& pair : timezone_match_list) { | |
| 73 { | |
|
oshima
2015/04/23 18:30:45
any reason for this extra block?
jungshik at Google
2015/04/23 19:48:12
oops. what was I thinking? It's not necessary.
| |
| 74 scoped_ptr<TimeZone> input( | |
| 75 TimeZone::createTimeZone(UnicodeString(pair.id))); | |
| 76 scoped_ptr<TimeZone> expected( | |
| 77 TimeZone::createTimeZone(UnicodeString(pair.matched))); | |
| 78 const TimeZone* actual = GetKnownTimezoneOrNull(*input, timezones_); | |
| 79 EXPECT_NE(nullptr, actual) << "input=" << pair.id; | |
| 80 if (actual == nullptr) | |
| 81 continue; | |
| 82 UnicodeString actual_id; | |
| 83 actual->getID(actual_id); | |
| 84 std::string actual_id_str; | |
| 85 actual_id.toUTF8String(actual_id_str); | |
| 86 EXPECT_EQ(*expected, *actual) << "input=" << pair.id << ", " | |
| 87 << "expected=" << pair.matched << ", " | |
| 88 << "actual=" << actual_id_str; | |
| 89 } | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 TEST_F(KnownTimeZoneTest, NoMatch) { | |
| 94 static const char* no_match_list[] = { | |
| 95 "Africa/Juba", // Not in the list | |
| 96 "Africa/Tripoli", // UTC+2 with no DST != Europe/Athens | |
| 97 "America/Tijuana", // Historically != America/Los_Angeles | |
| 98 "Europe/Sofia", // Historically != Europe/Athens | |
| 99 "America/Argentina/Cordoba", // Historically != America/Buenos_Aires | |
| 100 "Asia/Tokyo", // Historically != Asia/Seoul | |
| 101 }; | |
| 102 for (const char* id : no_match_list) { | |
| 103 { | |
| 104 scoped_ptr<TimeZone> input(TimeZone::createTimeZone(UnicodeString(id))); | |
| 105 EXPECT_EQ(NULL, GetKnownTimezoneOrNull(*input, timezones_)) | |
| 106 << "input=" << id; | |
| 107 } | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 } // namespace system | |
| 112 } // namespace chromeos | |
| OLD | NEW |