1 /*
2 * # Copyright (c) 2024 Andrew Featherstone
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/ztest.h>
8
9 #include "../../../../drivers/rtc/rtc_utils.h"
10
ZTEST(rtc_utils,test_rtc_utils_validate_rtc_time)11 ZTEST(rtc_utils, test_rtc_utils_validate_rtc_time)
12 {
13 /* Arbitrary out-out-range values. */
14 const struct rtc_time alarm_time = {
15 .tm_sec = 70,
16 .tm_min = 70,
17 .tm_hour = 25,
18 .tm_mday = 35,
19 .tm_mon = 15,
20 .tm_year = 8000,
21 .tm_wday = 8,
22 .tm_yday = 370,
23 .tm_nsec = INT32_MAX,
24 };
25 uint16_t masks[] = {RTC_ALARM_TIME_MASK_SECOND, RTC_ALARM_TIME_MASK_MINUTE,
26 RTC_ALARM_TIME_MASK_HOUR, RTC_ALARM_TIME_MASK_MONTHDAY,
27 RTC_ALARM_TIME_MASK_MONTH, RTC_ALARM_TIME_MASK_YEAR,
28 RTC_ALARM_TIME_MASK_WEEKDAY, RTC_ALARM_TIME_MASK_YEARDAY,
29 RTC_ALARM_TIME_MASK_NSEC};
30 ARRAY_FOR_EACH(masks, j)
31 {
32 bool ret = rtc_utils_validate_rtc_time(&alarm_time, masks[j]);
33
34 zassert_false(ret, "RTC should reject invalid alarm time in field %zu.", j);
35 }
36 }
37