|
21 | 21 | #include "mbed.h"
|
22 | 22 | #include "mbed_mktime.h"
|
23 | 23 |
|
| 24 | +// Limit the test range to 1935 for IAR only. From the IAR C/C++ Development Guide: |
| 25 | +// "The 32-bit interface supports years from 1900 up to 2035 and uses a 32-bit integer |
| 26 | +// for time_t." |
| 27 | +#ifdef __ICCARM__ |
| 28 | +#define LOCALTIME_MAX 2082758400 // 1st of january 2036 at 00:00:00 |
| 29 | +#define MKTIME_YR_MAX 136 |
| 30 | +#else |
| 31 | +#define LOCALTIME_MAX INT_MAX |
| 32 | +#define MKTIME_YR_MAX 137 |
| 33 | +#endif |
| 34 | + |
24 | 35 | using namespace utest::v1;
|
25 | 36 |
|
26 | 37 | /*
|
@@ -54,13 +65,17 @@ void test_is_leap_year() {
|
54 | 65 | }
|
55 | 66 |
|
56 | 67 | struct tm make_time_info(int year, int month, int day, int hours, int minutes, int seconds) {
|
57 |
| - struct tm timeinfo; |
58 |
| - timeinfo.tm_year = year; |
59 |
| - timeinfo.tm_mon = month; |
60 |
| - timeinfo.tm_mday = day; |
61 |
| - timeinfo.tm_hour = hours; |
62 |
| - timeinfo.tm_min = minutes; |
63 |
| - timeinfo.tm_sec = seconds; |
| 68 | + struct tm timeinfo = { |
| 69 | + seconds, // tm_sec |
| 70 | + minutes, // tm_min |
| 71 | + hours, // tm_hour |
| 72 | + day, // tm_mday |
| 73 | + month, // tm_mon |
| 74 | + year, // tm_year |
| 75 | + 0, // tm_wday |
| 76 | + 0, // tm_yday |
| 77 | + 0, // tm_isdst |
| 78 | + }; |
64 | 79 | return timeinfo;
|
65 | 80 | }
|
66 | 81 |
|
@@ -116,7 +131,7 @@ void test_mk_time_out_of_range() {
|
116 | 131 | * test mktime over a large set of values
|
117 | 132 | */
|
118 | 133 | void test_mk_time() {
|
119 |
| - for (size_t year = 70; year < 137; ++year) { |
| 134 | + for (size_t year = 70; year < MKTIME_YR_MAX; ++year) { |
120 | 135 | for (size_t month = 0; month < 12; ++month) {
|
121 | 136 | for (size_t day = 1; day < 32; ++day) {
|
122 | 137 | if (month == 1 && is_leap_year(year) && day == 29) {
|
@@ -172,7 +187,7 @@ void test_local_time_limit() {
|
172 | 187 | * test _rtc_localtime over a large set of values.
|
173 | 188 | */
|
174 | 189 | void test_local_time() {
|
175 |
| - for (uint32_t i = 0; i < INT_MAX; i += 3451) { |
| 190 | + for (uint32_t i = 0; i < LOCALTIME_MAX; i += 3451) { |
176 | 191 | time_t copy = (time_t) i;
|
177 | 192 | struct tm* expected = localtime(©);
|
178 | 193 | struct tm actual_value;
|
|
0 commit comments