From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2134) id 1EF7E38293E0; Fri, 27 May 2022 15:43:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1EF7E38293E0 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jeff Johnston To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Add test cases for parser errors after reworked parsing behavior. X-Act-Checkin: newlib-cygwin X-Git-Author: jdoubleu X-Git-Refname: refs/heads/master X-Git-Oldrev: 2dbdf66b9112b8c004e51bb3a05250ea52ae66d7 X-Git-Newrev: e93bb6f9852a9dbfe21bd0ffbea1751a5d9cfd60 Message-Id: <20220527154323.1EF7E38293E0@sourceware.org> Date: Fri, 27 May 2022 15:43:23 +0000 (GMT) X-BeenThere: newlib-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib GIT logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 May 2022 15:43:23 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3De93bb6f9852= a9dbfe21bd0ffbea1751a5d9cfd60 commit e93bb6f9852a9dbfe21bd0ffbea1751a5d9cfd60 Author: jdoubleu Date: Fri May 27 11:35:27 2022 -0400 Add test cases for parser errors after reworked parsing behavior. Diff: --- newlib/testsuite/newlib.time/tzset.c | 64 +++++++++++++++++++++++++++-----= ---- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/newlib/testsuite/newlib.time/tzset.c b/newlib/testsuite/newlib= .time/tzset.c index 0e5b196c6..db25077ce 100644 --- a/newlib/testsuite/newlib.time/tzset.c +++ b/newlib/testsuite/newlib.time/tzset.c @@ -93,7 +93,6 @@ struct tz_test test_timezones[] =3D { {"3:152:30:15", IN_SECONDS(3, 15, 0), = IN_SECONDS(2, 30, 15)}, {"3:152:30:15", IN_SECONDS(3, 15, 0), = IN_SECONDS(2, 30, 15)}, // requires TZNAME_MAX >=3D 8 + 1 {"<+H6M20S12>6:20:12<-H4M40S14>-4:40:14", IN_SECONDS(6, 20, 12), -= IN_SECONDS(4, 40, 14)}, // requires TZNAME_MAX >=3D 9 + 1 - {"<+0123456789ABCDEF>3:33:33", IN_SECONDS(3, 33, 33), = NO_TIME}, // truncates the name (17 + 1) =20 /*=20 * real-world test vectors. @@ -111,13 +110,43 @@ struct tz_test test_timezones[] =3D { { /* Asia/Colombo */ "<+0530>-5:30", -IN= _SECONDS(5, 30, 0), NO_TIME}, { /* Europe/Berlin */ "CET-1CEST,M3.5.0,M10.5.0/3", -IN= _SECONDS(1, 0, 0), -IN_SECONDS(2, 0, 0)}, =20 - // END of list - {NULL, NO_TIME, NO_TIME} + /// test parsing errors + // 1. names are too long + {"JUSTEXCEEDI1:11:11", 0, NO_TI= ME}, + {"AVERYLONGNAMEWHICHEXCEEDSTZNAMEMAX2:22:22", 0, NO_TI= ME}, + {"FIRSTVERYLONGNAME3:33:33SECONDVERYLONGNAME4:44:44", 0, 0}, + {"5:55:55", 0, NO_TI= ME}, + {"3:33:334:44:44", 0, 0}, + {"<+JUSTEXCEED>5:55:55", 0, NO_TI= ME}, + + // 2. names are too short + {"JU6:34:47", 0, NO_TIME}, + {"HE6:34:47LO3:34:47", 0, 0}, + {"2:34:47", 0, NO_TIME}, + {"2:34:473:34:47", 0, 0}, + =20 + // 3. names contain invalid chars + {"N?ME2:10:56", 0, NO_TIME}, + {"N!ME2:10:56", 0, NO_TIME}, + {"N/ME2:10:56", 0, NO_TIME}, + {"N$ME2:10:56", 0, NO_TIME}, + {"NAME?2:10:56", 0, NO_TIME}, + {"?NAME2:10:56", 0, NO_TIME}, + {"NAME?UNK4:21:15", 0, NO_TIME}, + {"NAME!UNK4:22:15NEXT/NAME4:23:15", 0, NO_TIME}, + + // 4. bogus strings + {"NOINFO", 0, NO_TIME}, + {"HOUR:16:18", 0, NO_TIME}, + {"WRONG<2:15:00", 0, NO_TIME}, + {"STtzstr !=3D NULL; ++iter_name) - // END test vectors =20 static int failed =3D 0; @@ -136,22 +165,24 @@ void test_TimezoneStrings(void) { char buffer[128]; =20 - FOR_TIMEZONES(ptr) + for (int i =3D 0; i < (sizeof(test_timezones) / sizeof(struct tz_test)= ); ++i) { - setenv("TZ", ptr->tzstr, 1); - tzset(); - - snprintf(buffer, 128, "winter time, timezone =3D \"%s\"", ptr->tzs= tr); + struct tz_test ptr =3D test_timezones[i]; =20 + setenv("TZ", ptr.tzstr, 1); + tzset(); +=20 + snprintf(buffer, 128, "winter time, timezone =3D \"%s\"", ptr.tzst= r); +=20 struct tm winter_tm_copy =3D winter_tm; // copy - TEST_ASSERT_EQUAL_INT_MESSAGE(winter_time + ptr->offset_seconds, m= ktime(&winter_tm_copy), buffer); + TEST_ASSERT_EQUAL_INT_MESSAGE(winter_time + ptr.offset_seconds, mk= time(&winter_tm_copy), buffer); =20 - if (ptr->dst_offset_seconds !=3D NO_TIME) + if (ptr.dst_offset_seconds !=3D NO_TIME) { - snprintf(buffer, 128, "summer time, timezone =3D \"%s\"", ptr-= >tzstr); + snprintf(buffer, 128, "summer time, timezone =3D \"%s\"", ptr.= tzstr); =20 struct tm summer_tm_copy =3D summer_tm; // copy - TEST_ASSERT_EQUAL_INT_MESSAGE(summer_time + ptr->dst_offset_se= conds, mktime(&summer_tm_copy), buffer); + TEST_ASSERT_EQUAL_INT_MESSAGE(summer_time + ptr.dst_offset_sec= onds, mktime(&summer_tm_copy), buffer); } } } @@ -160,4 +191,5 @@ int main() { test_TimezoneStrings(); exit (failed); -} \ No newline at end of file +} +