public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: jdoubleu <hi@jdoubleu.de>
To: Dimitar Dimitrov <dimitar@dinux.eu>
Cc: newlib@sourceware.org
Subject: [PATCH v2] update tzset tests
Date: Sun, 22 May 2022 11:51:45 +0200	[thread overview]
Message-ID: <c61f6e20-521f-00bd-3fdb-7c7f5b2f55d0@jdoubleu.de> (raw)
In-Reply-To: <1060b8f4-b592-d883-acfe-b5d5193ee825@jdoubleu.de>

[-- Attachment #1: Type: text/plain, Size: 551 bytes --]

Dimitar Dimitrov <dimitar@dinux.eu> writes:
> Only the following test case fails in tzset.c:

jdoubleu <hi@jdoubleu.de> writes:
> I'm going fix my patch. Thanks for running the tests! 

I've fixed that one test case. I wasn't able to run it myself, yet.

> BTW, it took me a while to realize that your patch and the source code in
> newlib's GIT have different line endings 

The patch is now formated with CLRF line endings. I checked tzset_r.c 
and it also uses CLRF. But maybe I checked it out the wrong way?


Cheers
---
🙎🏻‍♂️ jdoubleu

[-- Attachment #2: 0001-update-tzset-tests.patch --]
[-- Type: text/plain, Size: 4779 bytes --]

From 90f857d6a4ec999074f892fb0641a2d785c09de5 Mon Sep 17 00:00:00 2001
From: jdoubleu <hi@jdoubleu.de>
Date: Sat, 14 May 2022 15:41:22 +0200
Subject: [PATCH] update tzset tests

Add test cases for parser errors after reworked parsing behavior.
---
 newlib/testsuite/newlib.time/tzset.c | 58 +++++++++++++++++++++-------
 1 file changed, 45 insertions(+), 13 deletions(-)

diff --git a/newlib/testsuite/newlib.time/tzset.c b/newlib/testsuite/newlib.time/tzset.c
index 0e5b196c6..19a33be73 100644
--- a/newlib/testsuite/newlib.time/tzset.c
+++ b/newlib/testsuite/newlib.time/tzset.c
@@ -93,7 +93,6 @@ struct tz_test test_timezones[] = {
     {"<WINT+03>3:15<SUM+02>2:30:15",             IN_SECONDS(3, 15, 0),    IN_SECONDS(2, 30, 15)},
     {"<H3M15>3:15<H2M30S15>2:30:15",             IN_SECONDS(3, 15, 0),    IN_SECONDS(2, 30, 15)},   // requires TZNAME_MAX >= 8 + 1
     {"<+H6M20S12>6:20:12<-H4M40S14>-4:40:14",    IN_SECONDS(6, 20, 12),  -IN_SECONDS(4, 40, 14)},   // requires TZNAME_MAX >= 9 + 1
-    {"<+0123456789ABCDEF>3:33:33",               IN_SECONDS(3, 33, 33),   NO_TIME},                 // truncates the name (17 + 1)
 
     /* 
      * real-world test vectors.
@@ -111,13 +110,44 @@ struct tz_test test_timezones[] = {
     { /* 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)},
 
-    // END of list
-    {NULL, NO_TIME, NO_TIME}
+    /// test parsing errors
+    // 1. names are too long
+    {"<+0123456789ABCDEF>3:33:33",                              0,   NO_TIME},
+    {"JUSTEXCEEDI1:11:11",                                      0,   NO_TIME},
+    {"AVERYLONGNAMEWHICHEXCEEDSTZNAMEMAX2:22:22",               0,   NO_TIME},
+    {"FIRSTVERYLONGNAME3:33:33SECONDVERYLONGNAME4:44:44",       0,   0},
+    {"<JUSTEXCEEDI>5:55:55",                                    0,   NO_TIME},
+    {"<FIRSTVERYLONGNAME>3:33:33<SECONDVERYLONGNAME>4:44:44",   0,   0},
+    {"<+JUSTEXCEED>5:55:55",                                    0,   NO_TIME},
+
+    // 2. names are too short
+    {"JU6:34:47",               0,   NO_TIME},
+    {"HE6:34:47LO3:34:47",      0,   0},
+    {"<AB>2:34:47",             0,   NO_TIME},
+    {"<AB>2:34:47<CD>3:34:47",  0,   0},
+    
+    // 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},
+    {"<BEGIN",          0,  NO_TIME},
+    {"<NEXT:55",        0,  NO_TIME},
+    {">WRONG<2:15:00",  0,  NO_TIME},
+    {"ST<ART4:30:00",   0,  NO_TIME},
+    //{"MANY8:00:00:00",  0,  NO_TIME},
+    {"\0",              0,  NO_TIME},
+    {"M\0STR7:30:36",   0,  NO_TIME}
 };
 
-// helper macros
-#define FOR_TIMEZONES(iter_name) for (struct tz_test* iter_name = test_timezones; iter_name->tzstr != NULL; ++iter_name)
-
 // END test vectors
 
 static int failed = 0;
@@ -136,22 +166,24 @@ void test_TimezoneStrings(void)
 {
     char buffer[128];
 
-    FOR_TIMEZONES(ptr)
+    for (int i = 0; i < (sizeof(test_timezones) / sizeof(struct tz_test)); ++i)
     {
-        setenv("TZ", ptr->tzstr, 1);
+        struct tz_test ptr = test_timezones[i];
+
+        setenv("TZ", ptr.tzstr, 1);
         tzset();
 
-        snprintf(buffer, 128, "winter time, timezone = \"%s\"", ptr->tzstr);
+        snprintf(buffer, 128, "winter time, timezone = \"%s\"", ptr.tzstr);
 
         struct tm winter_tm_copy = winter_tm; // copy
-        TEST_ASSERT_EQUAL_INT_MESSAGE(winter_time + ptr->offset_seconds, mktime(&winter_tm_copy), buffer);
+        TEST_ASSERT_EQUAL_INT_MESSAGE(winter_time + ptr.offset_seconds, mktime(&winter_tm_copy), buffer);
 
-        if (ptr->dst_offset_seconds != NO_TIME)
+        if (ptr.dst_offset_seconds != NO_TIME)
         {
-            snprintf(buffer, 128, "summer time, timezone = \"%s\"", ptr->tzstr);
+            snprintf(buffer, 128, "summer time, timezone = \"%s\"", ptr.tzstr);
 
             struct tm summer_tm_copy = summer_tm; // copy
-            TEST_ASSERT_EQUAL_INT_MESSAGE(summer_time + ptr->dst_offset_seconds, mktime(&summer_tm_copy), buffer);
+            TEST_ASSERT_EQUAL_INT_MESSAGE(summer_time + ptr.dst_offset_seconds, mktime(&summer_tm_copy), buffer);
         }
     }
 }
-- 
2.35.1


  reply	other threads:[~2022-05-22  9:51 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-07 15:58 [PATCH] add tests for tzset(3) jdoubleu
2022-04-08 21:21 ` Jeff Johnston
2022-04-10  8:43 ` Dimitar Dimitrov
2022-04-10 17:55   ` jdoubleu
2022-04-10 21:00     ` Dimitar Dimitrov
2022-04-11 11:17       ` jdoubleu
2022-04-11 17:27         ` Dimitar Dimitrov
2022-04-12 11:19           ` jdoubleu
2022-04-12 18:33             ` Brian Inglis
2022-04-07 23:34               ` [PATCH v2 0/2] add tzset/_r POSIX angle bracket <> support in TZ env var Brian Inglis
2022-04-07 23:34                 ` [PATCH v2 1/2] newlib/libc/time/tzset.c: doc update POSIX angle bracket <> support Brian Inglis
2022-04-07 23:34                 ` [PATCH v2 2/2] newlib/libc/time/tzset_r.c(_tzset_unlocked_r): " Brian Inglis
2022-04-08 19:11                 ` [PATCH v2 0/2] add tzset/_r POSIX angle bracket <> support in TZ env var Jeff Johnston
2022-04-13 17:53                 ` [PATCH] add tests for tzset(3) Brian Inglis
2022-04-13 20:33                   ` Jeff Johnston
2022-04-13 22:19                     ` Brian Inglis
2022-04-14  8:59                       ` jdoubleu
2022-04-14 16:31                         ` Brian Inglis
2022-04-14 19:23                           ` Jeff Johnston
2022-04-15 10:10                             ` jdoubleu
2022-04-27 19:30                               ` Jeff Johnston
2022-05-14 14:39                         ` jdoubleu
2022-05-16 16:05                           ` Dimitar Dimitrov
2022-05-16 17:38                             ` Jeff Johnston
2022-05-17  8:45                           ` [PATCH] update tzset tests jdoubleu
2022-05-18 18:48                             ` Dimitar Dimitrov
2022-05-18 20:56                               ` Keith Packard
2022-05-19  8:47                                 ` jdoubleu
2022-05-22  9:51                                   ` jdoubleu [this message]
2022-05-22 21:02                                     ` [PATCH v2] " Dimitar Dimitrov
2022-05-27 15:46                                       ` Jeff Johnston
2022-04-13 22:21               ` [PATCH] add tests for tzset(3) Brian Inglis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c61f6e20-521f-00bd-3fdb-7c7f5b2f55d0@jdoubleu.de \
    --to=hi@jdoubleu.de \
    --cc=dimitar@dinux.eu \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).