mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
unittests: add test for timex_to_str()
This commit is contained in:
parent
ea48b48dd3
commit
2a4fd4dd75
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Philipp Rosenkranz, Daniel Jentsch
|
||||
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
@ -44,6 +45,28 @@ static void test_timex_from_uint64(void)
|
||||
TEST_ASSERT(time.microseconds == 1000);
|
||||
}
|
||||
|
||||
static void test_timex_to_str(void)
|
||||
{
|
||||
timex_t t = { 0, 0 };
|
||||
char t_str[TIMEX_MAX_STR_LEN];
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING("0.000000 s", timex_to_str(t, t_str));
|
||||
t.seconds = 1;
|
||||
TEST_ASSERT_EQUAL_STRING("1.000000 s", timex_to_str(t, t_str));
|
||||
t.seconds = 9;
|
||||
t.microseconds = 2640288149;
|
||||
TEST_ASSERT_EQUAL_STRING("2649.288149 s", timex_to_str(t, t_str));
|
||||
t.seconds = 1689940699;
|
||||
t.microseconds = 4361;
|
||||
TEST_ASSERT_EQUAL_STRING("1689940699.004361 s", timex_to_str(t, t_str));
|
||||
t.seconds = 100;
|
||||
t.microseconds = 101010;
|
||||
TEST_ASSERT_EQUAL_STRING("100.101010 s", timex_to_str(t, t_str));
|
||||
t.seconds = UINT32_MAX;
|
||||
t.microseconds = 999999; /* should be .999999 */
|
||||
TEST_ASSERT_EQUAL_STRING("4294967295.999999 s", timex_to_str(t, t_str));
|
||||
}
|
||||
|
||||
Test *tests_timex_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
@ -51,6 +74,7 @@ Test *tests_timex_tests(void)
|
||||
new_TestFixture(test_timex_add),
|
||||
new_TestFixture(test_timex_sub),
|
||||
new_TestFixture(test_timex_from_uint64),
|
||||
new_TestFixture(test_timex_to_str),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(timex_tests, NULL, NULL, fixtures);
|
||||
|
Loading…
Reference in New Issue
Block a user