| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <stdio.h> | 
|  | 2 | #include <stdlib.h> | 
|  | 3 | #include <string.h> | 
|  | 4 | #include <time.h> | 
|  | 5 |  | 
|  | 6 |  | 
|  | 7 | static int | 
|  | 8 | do_test (void) | 
|  | 9 | { | 
|  | 10 | int result = 0; | 
|  | 11 | struct tm tm; | 
|  | 12 |  | 
|  | 13 | memset (&tm, 0xaa, sizeof (tm)); | 
|  | 14 |  | 
|  | 15 | /* Test we don't crash on uninitialized struct tm. | 
|  | 16 | Some fields might contain bogus values until everything | 
|  | 17 | needed is initialized, but we shouldn't crash.  */ | 
|  | 18 | if (strptime ("2007", "%Y", &tm) == NULL | 
|  | 19 | || strptime ("12", "%d", &tm) == NULL | 
|  | 20 | || strptime ("Feb", "%b", &tm) == NULL | 
|  | 21 | || strptime ("13", "%M", &tm) == NULL | 
|  | 22 | || strptime ("21", "%S", &tm) == NULL | 
|  | 23 | || strptime ("16", "%H", &tm) == NULL) | 
|  | 24 | { | 
|  | 25 | puts ("strptimes failed"); | 
|  | 26 | result = 1; | 
|  | 27 | } | 
|  | 28 |  | 
|  | 29 | if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16 | 
|  | 30 | || tm.tm_mday != 12 || tm.tm_mon != 1 || tm.tm_year != 107 | 
|  | 31 | || tm.tm_wday != 1 || tm.tm_yday != 42) | 
|  | 32 | { | 
|  | 33 | puts ("unexpected tm content"); | 
|  | 34 | result = 1; | 
|  | 35 | } | 
|  | 36 |  | 
|  | 37 | if (strptime ("8", "%d", &tm) == NULL) | 
|  | 38 | { | 
|  | 39 | puts ("strptime failed"); | 
|  | 40 | result = 1; | 
|  | 41 | } | 
|  | 42 |  | 
|  | 43 | if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16 | 
|  | 44 | || tm.tm_mday != 8 || tm.tm_mon != 1 || tm.tm_year != 107 | 
|  | 45 | || tm.tm_wday != 4 || tm.tm_yday != 38) | 
|  | 46 | { | 
|  | 47 | puts ("unexpected tm content"); | 
|  | 48 | result = 1; | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | return result; | 
|  | 52 | } | 
|  | 53 |  | 
|  | 54 | #define TEST_FUNCTION do_test () | 
|  | 55 | #include "../test-skeleton.c" |