Fix the time unit tests for systems with 64-bit time_t.
Change-Id: I29df50b25d022c1c00906e71b612defa58e46e81
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index 02163a5..fb5a4a7 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -55,7 +55,7 @@
ASSERT_EQ(1970, broken_down->tm_year + 1900);
}
-#ifdef __BIONIC__
+#if __BIONIC__
TEST(time, mktime_10310929) {
struct tm t;
memset(&t, 0, sizeof(tm));
@@ -63,7 +63,23 @@
t.tm_mon = 2;
t.tm_mday = 10;
+#if !defined(__LP64__)
+ // 32-bit bionic stupidly had a signed 32-bit time_t.
ASSERT_EQ(-1, mktime(&t));
ASSERT_EQ(-1, mktime_tz(&t, "UTC"));
+#else
+ // Everyone else should be using a signed 64-bit time_t.
+ ASSERT_GE(sizeof(time_t) * 8, 64U);
+
+ setenv("TZ", "America/Los_Angeles", 1);
+ tzset();
+ ASSERT_EQ(static_cast<time_t>(4108348800U), mktime(&t));
+ ASSERT_EQ(static_cast<time_t>(4108320000U), mktime_tz(&t, "UTC"));
+
+ setenv("TZ", "UTC", 1);
+ tzset();
+ ASSERT_EQ(static_cast<time_t>(4108320000U), mktime(&t));
+ ASSERT_EQ(static_cast<time_t>(4108348800U), mktime_tz(&t, "America/Los_Angeles"));
+#endif
}
#endif