Skip to content

Fix for issue #8368 #8377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 33 additions & 53 deletions TESTS/mbed_hal/rtc_time/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

using namespace utest::v1;

static rtc_leap_year_support_t rtc_leap_year_support;

/* Regular is_leap_year, see platform/mbed_mktime.c for the optimised version. */
bool is_leap_year(int year)
{
Expand All @@ -53,6 +51,7 @@ bool is_leap_year(int year)
* When _rtc_is_leap_year() function is called.
* Then _rtc_is_leap_year() returns true if given year is a leap year; false otherwise.
*/
template <rtc_leap_year_support_t rtc_leap_year_support>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this defined twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but what is defined twice?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 54 and 93

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because these are two different template functions. Is it possible to define one template for many functions? I have never seen such case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just seemed odd to me, but our local C++ expert (@geky) mentioend that it's par for the course. I'm use to seeing templates be used in classes, not functions.

void test_is_leap_year()
{
for (int i = 70; i <= LAST_VALID_YEAR; ++i) {
Expand All @@ -79,31 +78,6 @@ typedef struct {
bool result;
} test_mk_time_struct;

/* Array which contains data to test boundary values for the RTC devices which handles correctly leap years in
* whole range (1970 - 2106).
* 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).
*/
test_mk_time_struct test_mk_time_arr_full[] = {
{{ 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
{{ 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

{{ 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
{{ 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
};

/* Array which contains data to test boundary values for the RTC devices which does not handle correctly leap years in
* whole range (1970 - 2106). On this platforms we will be one day off after 28.02.2100 since 2100 year will be
* incorrectly treated as a leap year.
* 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).
*/
test_mk_time_struct test_mk_time_arr_partial[] = {
{{ 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
{{ 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

{{ 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
{{ 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
};

/* Test boundary values for _rtc_maketime().
*
* Note: This test case is designed for both types of RTC devices:
Expand All @@ -116,10 +90,36 @@ test_mk_time_struct test_mk_time_arr_partial[] = {
* When _rtc_maketime() function is called to convert the calendar time into timestamp.
* Then if given calendar time is valid function returns true and conversion result, otherwise returns false.
*/
template <rtc_leap_year_support_t rtc_leap_year_support>
void test_mk_time_boundary()
{
test_mk_time_struct *pTestCases;

/* Array which contains data to test boundary values for the RTC devices which handles correctly leap years in
* whole range (1970 - 2106).
* 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).
*/
test_mk_time_struct test_mk_time_arr_full[] = {
{{ 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
{{ 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

{{ 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
{{ 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
};

/* Array which contains data to test boundary values for the RTC devices which does not handle correctly leap years in
* whole range (1970 - 2106). On this platforms we will be one day off after 28.02.2100 since 2100 year will be
* incorrectly treated as a leap year.
* 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).
*/
test_mk_time_struct test_mk_time_arr_partial[] = {
{{ 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
{{ 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

{{ 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
{{ 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
};

/* Select array with test cases. */
if (rtc_leap_year_support == RTC_FULL_LEAP_YEAR_SUPPORT) {
pTestCases = test_mk_time_arr_full;
Expand Down Expand Up @@ -169,33 +169,13 @@ void test_local_time_invalid_param()
TEST_ASSERT_EQUAL(false, _rtc_localtime(1, NULL, RTC_4_YEAR_LEAP_YEAR_SUPPORT));
}

utest::v1::status_t teardown_handler_t(const Case *const source, const size_t passed, const size_t failed,
const failure_t reason)
{
return greentea_case_teardown_handler(source, passed, failed, reason);
}

utest::v1::status_t full_leap_year_case_setup_handler_t(const Case *const source, const size_t index_of_case)
{
rtc_leap_year_support = RTC_FULL_LEAP_YEAR_SUPPORT;

return greentea_case_setup_handler(source, index_of_case);
}

utest::v1::status_t partial_leap_year_case_setup_handler_t(const Case *const source, const size_t index_of_case)
{
rtc_leap_year_support = RTC_4_YEAR_LEAP_YEAR_SUPPORT;

return greentea_case_setup_handler(source, index_of_case);
}

Case cases[] = {
Case("test is leap year - RTC leap years full support", full_leap_year_case_setup_handler_t, test_is_leap_year, teardown_handler_t),
Case("test is leap year - RTC leap years partial support", partial_leap_year_case_setup_handler_t, test_is_leap_year, teardown_handler_t),
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),
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),
Case("test make time - invalid param", test_mk_time_invalid_param, teardown_handler_t),
Case("test local time - invalid param", test_local_time_invalid_param, teardown_handler_t),
Case("test is leap year - RTC leap years full support", test_is_leap_year<RTC_FULL_LEAP_YEAR_SUPPORT>),
Case("test is leap year - RTC leap years partial support", test_is_leap_year<RTC_4_YEAR_LEAP_YEAR_SUPPORT>),
Case("test make time boundary values - RTC leap years full support", test_mk_time_boundary<RTC_FULL_LEAP_YEAR_SUPPORT>),
Case("test make time boundary values - RTC leap years partial support", test_mk_time_boundary<RTC_4_YEAR_LEAP_YEAR_SUPPORT>),
Case("test make time - invalid param", test_mk_time_invalid_param),
Case("test local time - invalid param", test_local_time_invalid_param),
};

utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
Expand Down