Home | History | Annotate | Download | only in tests
      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.
     17     const uint16_t kMinimumSaneYear = 1964;
     18     const uint16_t kMaximumSaneYear = 2064;
     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     }
     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
     44 
     45     // The westernmost timezone is -12:00.
     46     // The easternmost timezone is +14:00.
     47     REPORTER_ASSERT(r, SkTAbs(SkToInt(dateTime.fTimeZoneMinutes)) <= 14 * 60);
     48 
     49     SkString timeStamp;
     50     dateTime.toISO8601(&timeStamp);
     51     REPORTER_ASSERT(r, timeStamp.size() > 0);
     52     INFOF(r, "\nCurrent Time (ISO-8601 format): \"%s\"\n",
     53           timeStamp.c_str());
     54 }
     55