Skip to content

Commit 1123c2b

Browse files
author
Cruz Monrreal
authored
Merge pull request #8377 from mprse/fix_for_issue_8368
Fix for issue #8368
2 parents 353e8bd + 4a3bcee commit 1123c2b

File tree

1 file changed

+33
-53
lines changed

1 file changed

+33
-53
lines changed

TESTS/mbed_hal/rtc_time/main.cpp

Lines changed: 33 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
using namespace utest::v1;
2727

28-
static rtc_leap_year_support_t rtc_leap_year_support;
29-
3028
/* Regular is_leap_year, see platform/mbed_mktime.c for the optimised version. */
3129
bool is_leap_year(int year)
3230
{
@@ -53,6 +51,7 @@ bool is_leap_year(int year)
5351
* When _rtc_is_leap_year() function is called.
5452
* Then _rtc_is_leap_year() returns true if given year is a leap year; false otherwise.
5553
*/
54+
template <rtc_leap_year_support_t rtc_leap_year_support>
5655
void test_is_leap_year()
5756
{
5857
for (int i = 70; i <= LAST_VALID_YEAR; ++i) {
@@ -79,31 +78,6 @@ typedef struct {
7978
bool result;
8079
} test_mk_time_struct;
8180

82-
/* Array which contains data to test boundary values for the RTC devices which handles correctly leap years in
83-
* whole range (1970 - 2106).
84-
* Expected range: the 1st of January 1970 at 00:00:00 (seconds: 0) to the 7th of February 2106 at 06:28:15 (seconds: UINT_MAX).
85-
*/
86-
test_mk_time_struct test_mk_time_arr_full[] = {
87-
{{ 0, 0, 0, 1, 0, 70, 0, 0, 0 }, (time_t) 0, true}, // valid lower bound - the 1st of January 1970 at 00:00:00
88-
{{ 59, 59, 23, 31, 11, 59, 0, 0, 0 }, (time_t) 0, false }, // invalid lower bound - the 31st of December 1969 at 23:59:59
89-
90-
{{ 15, 28, 6, 7, 1, 206, 0, 0, 0 }, (time_t)(UINT_MAX), true }, // valid upper bound - the 7th of February 2106 at 06:28:15
91-
{{ 16, 28, 6, 7, 1, 206, 0, 0, 0 }, (time_t) 0, false }, // invalid upper bound - the 7th of February 2106 at 06:28:16
92-
};
93-
94-
/* Array which contains data to test boundary values for the RTC devices which does not handle correctly leap years in
95-
* whole range (1970 - 2106). On this platforms we will be one day off after 28.02.2100 since 2100 year will be
96-
* incorrectly treated as a leap year.
97-
* Expected range: the 1st of January 1970 at 00:00:00 (seconds: 0) to the 6th of February 2106 at 06:28:15 (seconds: UINT_MAX).
98-
*/
99-
test_mk_time_struct test_mk_time_arr_partial[] = {
100-
{{ 0, 0, 0, 1, 0, 70, 0, 0, 0 }, (time_t) 0, true}, // valid lower bound - the 1st of January 1970 at 00:00:00
101-
{{ 59, 59, 23, 31, 11, 59, 0, 0, 0 }, (time_t) 0, false }, // invalid lower bound - the 31st of December 1969 at 23:59:59
102-
103-
{{ 15, 28, 6, 6, 1, 206, 0, 0, 0 }, (time_t)(UINT_MAX), true }, // valid upper bound - the 6th of February 2106 at 06:28:15
104-
{{ 16, 28, 6, 6, 1, 206, 0, 0, 0 }, (time_t) 0, false }, // invalid upper bound - the 6th of February 2106 at 06:28:16
105-
};
106-
10781
/* Test boundary values for _rtc_maketime().
10882
*
10983
* Note: This test case is designed for both types of RTC devices:
@@ -116,10 +90,36 @@ test_mk_time_struct test_mk_time_arr_partial[] = {
11690
* When _rtc_maketime() function is called to convert the calendar time into timestamp.
11791
* Then if given calendar time is valid function returns true and conversion result, otherwise returns false.
11892
*/
93+
template <rtc_leap_year_support_t rtc_leap_year_support>
11994
void test_mk_time_boundary()
12095
{
12196
test_mk_time_struct *pTestCases;
12297

98+
/* Array which contains data to test boundary values for the RTC devices which handles correctly leap years in
99+
* whole range (1970 - 2106).
100+
* Expected range: the 1st of January 1970 at 00:00:00 (seconds: 0) to the 7th of February 2106 at 06:28:15 (seconds: UINT_MAX).
101+
*/
102+
test_mk_time_struct test_mk_time_arr_full[] = {
103+
{{ 0, 0, 0, 1, 0, 70, 0, 0, 0 }, (time_t) 0, true}, // valid lower bound - the 1st of January 1970 at 00:00:00
104+
{{ 59, 59, 23, 31, 11, 59, 0, 0, 0 }, (time_t) 0, false }, // invalid lower bound - the 31st of December 1969 at 23:59:59
105+
106+
{{ 15, 28, 6, 7, 1, 206, 0, 0, 0 }, (time_t)(UINT_MAX), true }, // valid upper bound - the 7th of February 2106 at 06:28:15
107+
{{ 16, 28, 6, 7, 1, 206, 0, 0, 0 }, (time_t) 0, false }, // invalid upper bound - the 7th of February 2106 at 06:28:16
108+
};
109+
110+
/* Array which contains data to test boundary values for the RTC devices which does not handle correctly leap years in
111+
* whole range (1970 - 2106). On this platforms we will be one day off after 28.02.2100 since 2100 year will be
112+
* incorrectly treated as a leap year.
113+
* Expected range: the 1st of January 1970 at 00:00:00 (seconds: 0) to the 6th of February 2106 at 06:28:15 (seconds: UINT_MAX).
114+
*/
115+
test_mk_time_struct test_mk_time_arr_partial[] = {
116+
{{ 0, 0, 0, 1, 0, 70, 0, 0, 0 }, (time_t) 0, true}, // valid lower bound - the 1st of January 1970 at 00:00:00
117+
{{ 59, 59, 23, 31, 11, 59, 0, 0, 0 }, (time_t) 0, false }, // invalid lower bound - the 31st of December 1969 at 23:59:59
118+
119+
{{ 15, 28, 6, 6, 1, 206, 0, 0, 0 }, (time_t)(UINT_MAX), true }, // valid upper bound - the 6th of February 2106 at 06:28:15
120+
{{ 16, 28, 6, 6, 1, 206, 0, 0, 0 }, (time_t) 0, false }, // invalid upper bound - the 6th of February 2106 at 06:28:16
121+
};
122+
123123
/* Select array with test cases. */
124124
if (rtc_leap_year_support == RTC_FULL_LEAP_YEAR_SUPPORT) {
125125
pTestCases = test_mk_time_arr_full;
@@ -169,33 +169,13 @@ void test_local_time_invalid_param()
169169
TEST_ASSERT_EQUAL(false, _rtc_localtime(1, NULL, RTC_4_YEAR_LEAP_YEAR_SUPPORT));
170170
}
171171

172-
utest::v1::status_t teardown_handler_t(const Case *const source, const size_t passed, const size_t failed,
173-
const failure_t reason)
174-
{
175-
return greentea_case_teardown_handler(source, passed, failed, reason);
176-
}
177-
178-
utest::v1::status_t full_leap_year_case_setup_handler_t(const Case *const source, const size_t index_of_case)
179-
{
180-
rtc_leap_year_support = RTC_FULL_LEAP_YEAR_SUPPORT;
181-
182-
return greentea_case_setup_handler(source, index_of_case);
183-
}
184-
185-
utest::v1::status_t partial_leap_year_case_setup_handler_t(const Case *const source, const size_t index_of_case)
186-
{
187-
rtc_leap_year_support = RTC_4_YEAR_LEAP_YEAR_SUPPORT;
188-
189-
return greentea_case_setup_handler(source, index_of_case);
190-
}
191-
192172
Case cases[] = {
193-
Case("test is leap year - RTC leap years full support", full_leap_year_case_setup_handler_t, test_is_leap_year, teardown_handler_t),
194-
Case("test is leap year - RTC leap years partial support", partial_leap_year_case_setup_handler_t, test_is_leap_year, teardown_handler_t),
195-
Case("test make time boundary values - RTC leap years full support", full_leap_year_case_setup_handler_t, test_mk_time_boundary, teardown_handler_t),
196-
Case("test make time boundary values - RTC leap years partial support", partial_leap_year_case_setup_handler_t, test_mk_time_boundary, teardown_handler_t),
197-
Case("test make time - invalid param", test_mk_time_invalid_param, teardown_handler_t),
198-
Case("test local time - invalid param", test_local_time_invalid_param, teardown_handler_t),
173+
Case("test is leap year - RTC leap years full support", test_is_leap_year<RTC_FULL_LEAP_YEAR_SUPPORT>),
174+
Case("test is leap year - RTC leap years partial support", test_is_leap_year<RTC_4_YEAR_LEAP_YEAR_SUPPORT>),
175+
Case("test make time boundary values - RTC leap years full support", test_mk_time_boundary<RTC_FULL_LEAP_YEAR_SUPPORT>),
176+
Case("test make time boundary values - RTC leap years partial support", test_mk_time_boundary<RTC_4_YEAR_LEAP_YEAR_SUPPORT>),
177+
Case("test make time - invalid param", test_mk_time_invalid_param),
178+
Case("test local time - invalid param", test_local_time_invalid_param),
199179
};
200180

201181
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)

0 commit comments

Comments
 (0)