blob: 0ad4763a1d6fcabe1d99d733fa58f049a5dbc7a4 [file] [log] [blame]
Elliott Hughese0175ca2013-03-14 14:38:08 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <sys/cdefs.h>
18#include <features.h>
19#include <gtest/gtest.h>
20
21#include <time.h>
22
23#ifdef __BIONIC__ // mktime_tz is a bionic extension.
24#include <libc/private/bionic_time.h>
25TEST(time, mktime_tz) {
26 struct tm epoch;
27 memset(&epoch, 0, sizeof(tm));
28 epoch.tm_year = 1970 - 1900;
29 epoch.tm_mon = 1;
30 epoch.tm_mday = 1;
31
32 // Alphabetically first. Coincidentally equivalent to UTC.
33 ASSERT_EQ(2678400, mktime_tz(&epoch, "Africa/Abidjan"));
34
35 // Alphabetically last. Coincidentally equivalent to UTC.
36 ASSERT_EQ(2678400, mktime_tz(&epoch, "Zulu"));
37
38 // Somewhere in the middle, not UTC.
39 ASSERT_EQ(2707200, mktime_tz(&epoch, "America/Los_Angeles"));
40
41 // Missing. Falls back to UTC.
42 ASSERT_EQ(2678400, mktime_tz(&epoch, "PST"));
43}
44#endif
Elliott Hughesee178bf2013-07-12 11:25:20 -070045
46TEST(time, gmtime) {
47 time_t t = 0;
48 tm* broken_down = gmtime(&t);
49 ASSERT_TRUE(broken_down != NULL);
50 ASSERT_EQ(0, broken_down->tm_sec);
51 ASSERT_EQ(0, broken_down->tm_min);
52 ASSERT_EQ(0, broken_down->tm_hour);
53 ASSERT_EQ(1, broken_down->tm_mday);
54 ASSERT_EQ(0, broken_down->tm_mon);
55 ASSERT_EQ(1970, broken_down->tm_year + 1900);
56}