1 /*
2 * Copyright 2022 Bjarki Arge Andreasen
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/ztest.h>
8 #include <zephyr/drivers/rtc.h>
9 #include <time.h>
10
ZTEST(rtc_api_helpers,test_validate_rtc_time_compat_with_tm)11 ZTEST(rtc_api_helpers, test_validate_rtc_time_compat_with_tm)
12 {
13 zassert_equal(offsetof(struct rtc_time, tm_sec), offsetof(struct tm, tm_sec),
14 "Offset of tm_sec in struct rtc_time does not match struct tm");
15
16 zassert_equal(offsetof(struct rtc_time, tm_min), offsetof(struct tm, tm_min),
17 "Offset of tm_min in struct rtc_time does not match struct tm");
18
19 zassert_equal(offsetof(struct rtc_time, tm_hour), offsetof(struct tm, tm_hour),
20 "Offset of tm_hour in struct rtc_time does not match struct tm");
21
22 zassert_equal(offsetof(struct rtc_time, tm_mday), offsetof(struct tm, tm_mday),
23 "Offset of tm_mday in struct rtc_time does not match struct tm");
24
25 zassert_equal(offsetof(struct rtc_time, tm_mon), offsetof(struct tm, tm_mon),
26 "Offset of tm_mon in struct rtc_time does not match struct tm");
27
28 zassert_equal(offsetof(struct rtc_time, tm_year), offsetof(struct tm, tm_year),
29 "Offset of tm_year in struct rtc_time does not match struct tm");
30
31 zassert_equal(offsetof(struct rtc_time, tm_wday), offsetof(struct tm, tm_wday),
32 "Offset of tm_wday in struct rtc_time does not match struct tm");
33
34 zassert_equal(offsetof(struct rtc_time, tm_yday), offsetof(struct tm, tm_yday),
35 "Offset of tm_yday in struct rtc_time does not match struct tm");
36
37 zassert_equal(offsetof(struct rtc_time, tm_isdst), offsetof(struct tm, tm_isdst),
38 "Offset of tm_isdts in struct rtc_time does not match struct tm");
39 }
40
ZTEST(rtc_api_helpers,test_validate_rtc_time_to_tm)41 ZTEST(rtc_api_helpers, test_validate_rtc_time_to_tm)
42 {
43 struct rtc_time rtc_datetime;
44 struct tm *datetime = NULL;
45
46 datetime = rtc_time_to_tm(&rtc_datetime);
47
48 zassert(((struct tm *)&rtc_datetime) == datetime, "Incorrect typecast");
49 }
50