From 2a4fd4dd75f27b832fb4bef3eea15dbedad13af0 Mon Sep 17 00:00:00 2001 From: Martine Lenders <mlenders@inf.fu-berlin.de> Date: Wed, 5 Aug 2015 18:36:22 +0200 Subject: [PATCH] unittests: add test for timex_to_str() --- tests/unittests/tests-timex/tests-timex.c | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/unittests/tests-timex/tests-timex.c b/tests/unittests/tests-timex/tests-timex.c index f48810cc94..1e92647468 100644 --- a/tests/unittests/tests-timex/tests-timex.c +++ b/tests/unittests/tests-timex/tests-timex.c @@ -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); -- GitLab