Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 "ash/system/night_light/time_of_day.h" | |
| 6 | |
| 7 #include "base/time/time.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace ash { | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 TEST(TimeOfDayTest, TestEquality) { | |
| 15 // Test created TimeOfDay objects with equal offsets are equal. | |
| 16 TimeOfDay time1(18 * 60 + 32); // 6:32 PM. | |
| 17 TimeOfDay time2(18 * 60 + 32); // 6:32 PM. | |
| 18 EXPECT_EQ(time1, time2); | |
| 19 TimeOfDay time3(time1); | |
| 20 EXPECT_EQ(time1, time3); | |
| 21 EXPECT_EQ(time2, time3); | |
| 22 TimeOfDay time4(9 * 60 + 59); // 9:59 AM. | |
| 23 EXPECT_FALSE(time1 == time4); | |
| 24 time1 = time4; | |
| 25 EXPECT_EQ(time1, time4); | |
| 26 } | |
| 27 | |
| 28 TEST(TimeOfDayTest, TestSeveralOffsets) { | |
| 29 // 6:32 PM ==> 18:32. | |
| 30 TimeOfDay time1(18 * 60 + 32); | |
| 31 EXPECT_EQ("6:32 PM", time1.ToString()); | |
|
jungshik at Google
2017/06/05 23:17:43
This will fail in some locales because the format
afakhry
2017/06/06 00:07:17
Done. Thanks!
| |
| 32 | |
| 33 // 9:59 AM. | |
| 34 TimeOfDay time2(9 * 60 + 59); | |
| 35 EXPECT_EQ("9:59 AM", time2.ToString()); | |
| 36 | |
| 37 // Border times: 00:00 and 24:00. | |
| 38 TimeOfDay time3(0); | |
| 39 TimeOfDay time4(24 * 60); | |
| 40 EXPECT_EQ("12:00 AM", time3.ToString()); | |
| 41 EXPECT_EQ("12:00 AM", time4.ToString()); | |
| 42 } | |
| 43 | |
| 44 TEST(TimeOfDayTest, TestFromTime) { | |
| 45 // "Now" today and "now" tomorrow should have the same minutes offset from | |
| 46 // 00:00. | |
| 47 // Assume that "now" is Tuesday May 23, 2017 at 10:30 AM. | |
| 48 base::Time::Exploded now; | |
| 49 now.year = 2017; | |
| 50 now.month = 5; // May. | |
| 51 now.day_of_week = 2; // Tuesday. | |
| 52 now.day_of_month = 23; | |
| 53 now.hour = 10; | |
| 54 now.minute = 30; | |
| 55 now.second = 0; | |
| 56 now.millisecond = 0; | |
| 57 | |
| 58 base::Time now_today = base::Time::Now(); | |
| 59 ASSERT_TRUE(base::Time::FromLocalExploded(now, &now_today)); | |
| 60 base::Time now_tomorrow = now_today + base::TimeDelta::FromDays(1); | |
| 61 EXPECT_EQ(TimeOfDay::FromTime(now_today), TimeOfDay::FromTime(now_tomorrow)); | |
| 62 } | |
| 63 | |
| 64 } // namespace | |
| 65 | |
| 66 } // namespace ash | |
| OLD | NEW |