1 /*
2 * Copyright 2019-2020 Peter Bigot Consulting
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/ztest.h>
8 #include "timeutil_test.h"
9 #include "../../../lib/utils/timeutil.c"
10
timeutil_check(const struct timeutil_test_data * tp,size_t count)11 void timeutil_check(const struct timeutil_test_data *tp,
12 size_t count)
13 {
14 const struct timeutil_test_data *tpe = tp + count;
15
16 while (tp < tpe) {
17 struct tm tm = *gmtime(&tp->ux);
18 time_t uxtime = timeutil_timegm(&tm);
19
20 zassert_equal(&tm, gmtime_r(&tp->ux, &tm),
21 "gmtime_r failed");
22
23 zassert_equal(tm.tm_year, tp->tm.tm_year,
24 "datetime %s year %d != %d",
25 tp->civil, tm.tm_year, tp->tm.tm_year);
26 zassert_equal(tm.tm_mon, tp->tm.tm_mon,
27 "datetime %s mon %d != %d",
28 tp->civil, tm.tm_mon, tp->tm.tm_mon);
29 zassert_equal(tm.tm_mday, tp->tm.tm_mday,
30 "datetime %s mday %d != %d",
31 tp->civil, tm.tm_mday, tp->tm.tm_mday);
32 zassert_equal(tm.tm_hour, tp->tm.tm_hour,
33 "datetime %s hour %d != %d",
34 tp->civil, tm.tm_hour, tp->tm.tm_hour);
35 zassert_equal(tm.tm_min, tp->tm.tm_min,
36 "datetime %s min %d != %d",
37 tp->civil, tm.tm_min, tp->tm.tm_min);
38 zassert_equal(tm.tm_sec, tp->tm.tm_sec,
39 "datetime %s sec %d != %d",
40 tp->civil, tm.tm_sec, tp->tm.tm_sec);
41 zassert_equal(tm.tm_wday, tp->tm.tm_wday,
42 "datetime %s wday %d != %d",
43 tp->civil, tm.tm_wday, tp->tm.tm_wday);
44 zassert_equal(tm.tm_yday, tp->tm.tm_yday,
45 "datetime %s yday %d != %d",
46 tp->civil, tm.tm_yday, tp->tm.tm_yday);
47 zassert_equal(tp->ux, uxtime,
48 "datetime %s reverse != %ld",
49 tp->civil, uxtime);
50
51 ++tp;
52 }
53 }
54
55 ZTEST_SUITE(timeutil_api, NULL, NULL, NULL, NULL, NULL);
56