Added strtotimeval tests.
Change-Id: I3dfd3647a8494490a2d549bdb915968063a7fb99
This commit is contained in:
parent
ecbf00bda2
commit
4bfaf462f0
@ -387,3 +387,51 @@ TEST(time, timer_delete_from_timer_thread) {
|
||||
ASSERT_EQ(ESRCH, pthread_detach(tdd.thread_id));
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(time, strtotimeval) {
|
||||
#if defined(__BIONIC__)
|
||||
struct timeval tv1;
|
||||
char* rest1 = strtotimeval("10.123456", &tv1);
|
||||
ASSERT_EQ(10, tv1.tv_sec);
|
||||
ASSERT_EQ(123456, tv1.tv_usec);
|
||||
ASSERT_EQ('\0', *rest1);
|
||||
|
||||
// strtotimeval interprets the fractional part as microseconds and thus will
|
||||
// only consider its first 6 digits. Even so it should consume all valid
|
||||
// digits.
|
||||
struct timeval tv2;
|
||||
char* rest2 = strtotimeval(".1234567", &tv2);
|
||||
ASSERT_EQ(0, tv2.tv_sec);
|
||||
ASSERT_EQ(123456, tv2.tv_usec);
|
||||
ASSERT_EQ('\0', *rest2);
|
||||
|
||||
struct timeval tv3;
|
||||
char* rest3 = strtotimeval("1.1a", &tv3);
|
||||
ASSERT_EQ(1, tv3.tv_sec);
|
||||
ASSERT_EQ(100000, tv3.tv_usec);
|
||||
ASSERT_EQ('a', *rest3);
|
||||
|
||||
struct timeval tv4;
|
||||
char* rest4 = strtotimeval("a", &tv4);
|
||||
ASSERT_EQ(0, tv4.tv_sec);
|
||||
ASSERT_EQ(0, tv4.tv_usec);
|
||||
ASSERT_EQ('a', *rest4);
|
||||
|
||||
struct timeval tv5;
|
||||
char* rest5 = strtotimeval("0", &tv5);
|
||||
ASSERT_EQ(0, tv5.tv_sec);
|
||||
ASSERT_EQ(0, tv5.tv_usec);
|
||||
ASSERT_EQ('\0', *rest5);
|
||||
|
||||
// TODO: should we reject this case and just return '.'?
|
||||
struct timeval tv6;
|
||||
char* rest6 = strtotimeval(".", &tv6);
|
||||
ASSERT_EQ(0, tv6.tv_sec);
|
||||
ASSERT_EQ(0, tv6.tv_usec);
|
||||
ASSERT_EQ('\0', *rest6);
|
||||
|
||||
#else // __BIONIC__
|
||||
GTEST_LOG_(INFO) << "This test does nothing.\n";
|
||||
#endif // __BIONIC__
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user