aboutsummaryrefslogtreecommitdiffstats
path: root/tests/time_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-11-17 23:14:57 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-11-17 23:14:58 +0000
commit8eda0a6d69fda865b576bc18311a3d79c84b42a1 (patch)
tree937f40e8e2b645d491233f00c9d37f3bdc459d8e /tests/time_test.cpp
parentee4c8febb7bd1f5492486cc11980f925425b02ec (diff)
parent154e2026c83575eb17101df3a8d1192e305588d4 (diff)
downloadandroid_bionic-8eda0a6d69fda865b576bc18311a3d79c84b42a1.tar.gz
android_bionic-8eda0a6d69fda865b576bc18311a3d79c84b42a1.tar.bz2
android_bionic-8eda0a6d69fda865b576bc18311a3d79c84b42a1.zip
Merge "libc: Fix mktime returns an uncorrect time in empty TZ case"
Diffstat (limited to 'tests/time_test.cpp')
-rw-r--r--tests/time_test.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index 7a551b42a..e0231b1ca 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -71,6 +71,30 @@ TEST(time, gmtime_no_stack_overflow_14313703) {
ASSERT_EQ(0, pthread_join(t, &result));
}
+TEST(time, mktime_empty_TZ) {
+ // tzcode used to have a bug where it didn't reinitialize some internal state.
+
+ // Choose a time where DST is set.
+ struct tm t;
+ memset(&t, 0, sizeof(tm));
+ t.tm_year = 1980 - 1900;
+ t.tm_mon = 6;
+ t.tm_mday = 2;
+
+ setenv("TZ", "America/Los_Angeles", 1);
+ tzset();
+ ASSERT_EQ(static_cast<time_t>(331372800U), mktime(&t));
+
+ memset(&t, 0, sizeof(tm));
+ t.tm_year = 1980 - 1900;
+ t.tm_mon = 6;
+ t.tm_mday = 2;
+
+ setenv("TZ", "", 1); // Implies UTC.
+ tzset();
+ ASSERT_EQ(static_cast<time_t>(331344000U), mktime(&t));
+}
+
TEST(time, mktime_10310929) {
struct tm t;
memset(&t, 0, sizeof(tm));