From 0b846e8c66239090f69faf307ebeb0b4e0dee9e9 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 20 Dec 2017 08:56:18 -0800 Subject: [PATCH] bionic: test: time() Validate return values from time(), confirm progression. Test: bionic-unit-tests --gtest_filter=time.time Bug: 63737556 Change-Id: I08186780c42ded9648b3e788bb2caa2210d00dab --- tests/time_test.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/time_test.cpp b/tests/time_test.cpp index 7a96760c2..fccff6737 100644 --- a/tests/time_test.cpp +++ b/tests/time_test.cpp @@ -31,6 +31,31 @@ #include "private/bionic_constants.h" +TEST(time, time) { + // Acquire time + time_t p1, t1 = time(&p1); + // valid? + ASSERT_NE(static_cast(0), t1); + ASSERT_NE(static_cast(-1), t1); + ASSERT_EQ(p1, t1); + + // Acquire time one+ second later + usleep(1010000); + time_t p2, t2 = time(&p2); + // valid? + ASSERT_NE(static_cast(0), t2); + ASSERT_NE(static_cast(-1), t2); + ASSERT_EQ(p2, t2); + + // Expect time progression + ASSERT_LT(p1, p2); + ASSERT_LE(t2 - t1, static_cast(2)); + + // Expect nullptr call to produce same results + ASSERT_LE(t2, time(nullptr)); + ASSERT_LE(time(nullptr) - t2, static_cast(1)); +} + TEST(time, gmtime) { time_t t = 0; tm* broken_down = gmtime(&t);