Skip to content

Commit 4a3bcee

Browse files
committed
tests-mbed_hal-rtc_time: use templates instead of global variable
1 parent 8d57429 commit 4a3bcee

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

TESTS/mbed_hal/rtc_time/main.cpp

Lines changed: 8 additions & 28 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) {
@@ -91,6 +90,7 @@ typedef struct {
9190
* When _rtc_maketime() function is called to convert the calendar time into timestamp.
9291
* Then if given calendar time is valid function returns true and conversion result, otherwise returns false.
9392
*/
93+
template <rtc_leap_year_support_t rtc_leap_year_support>
9494
void test_mk_time_boundary()
9595
{
9696
test_mk_time_struct *pTestCases;
@@ -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)