halcanary | 8e74b15 | 2014-11-10 09:20:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkTime.h" |
| 9 | #include "Test.h" |
| 10 | |
| 11 | // Sanity checks for the GetDateTime function. |
| 12 | DEF_TEST(Time_GetDateTime, r) { |
| 13 | SkTime::DateTime dateTime; |
| 14 | SkTime::GetDateTime(&dateTime); |
| 15 | |
| 16 | // TODO(future generation): update these values. |
halcanary | ac6c4fc | 2014-11-10 14:39:24 -0800 | [diff] [blame] | 17 | const uint16_t kMinimumSaneYear = 1964; |
halcanary | 8e74b15 | 2014-11-10 09:20:22 -0800 | [diff] [blame] | 18 | const uint16_t kMaximumSaneYear = 2064; |
halcanary | ac6c4fc | 2014-11-10 14:39:24 -0800 | [diff] [blame] | 19 | |
| 20 | if (dateTime.fYear < kMinimumSaneYear) { |
| 21 | ERRORF(r, |
| 22 | "SkTime::GetDateTime: %u (CurrentYear) < %u (MinimumSaneYear)", |
| 23 | static_cast<unsigned>(dateTime.fYear), |
| 24 | static_cast<unsigned>(kMinimumSaneYear)); |
| 25 | } |
| 26 | if (dateTime.fYear > kMaximumSaneYear) { |
| 27 | ERRORF(r, |
| 28 | "SkTime::GetDateTime: %u (CurrentYear) > %u (MaximumSaneYear)", |
| 29 | static_cast<unsigned>(dateTime.fYear), |
| 30 | static_cast<unsigned>(kMaximumSaneYear)); |
| 31 | } |
halcanary | 8e74b15 | 2014-11-10 09:20:22 -0800 | [diff] [blame] | 32 | |
| 33 | REPORTER_ASSERT(r, dateTime.fMonth >= 1); |
| 34 | REPORTER_ASSERT(r, dateTime.fMonth <= 12); |
| 35 | |
| 36 | REPORTER_ASSERT(r, dateTime.fDay >= 1); |
| 37 | REPORTER_ASSERT(r, dateTime.fDay <= 31); |
| 38 | |
| 39 | REPORTER_ASSERT(r, dateTime.fHour <= 23); |
| 40 | |
| 41 | REPORTER_ASSERT(r, dateTime.fMinute <= 59); |
| 42 | |
| 43 | REPORTER_ASSERT(r, dateTime.fSecond <= 60); // leap seconds are 23:59:60 |
halcanary | 0b9d411 | 2015-05-01 07:06:23 -0700 | [diff] [blame] | 44 | |
| 45 | // The westernmost timezone is -12:00. |
| 46 | // The easternmost timezone is +14:00. |
| 47 | REPORTER_ASSERT(r, abs(SkToInt(dateTime.fTimeZoneMinutes)) <= 14 * 60); |
| 48 | |
| 49 | SkString timeStamp; |
| 50 | dateTime.toISO8601(&timeStamp); |
| 51 | REPORTER_ASSERT(r, timeStamp.size() > 0); |
| 52 | if (r->verbose()) { // `dm --veryVerbose` |
| 53 | SkDebugf("\nCurrent Time (ISO-8601 format): \"%s\"\n", |
| 54 | timeStamp.c_str()); |
| 55 | } |
halcanary | 8e74b15 | 2014-11-10 09:20:22 -0800 | [diff] [blame] | 56 | } |