mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-11-17 20:06:49 +00:00
f7a139b4b5
Also include some tests for strftime %z and %Z conversions (although just producing no output will satisfy them).
94 lines
3.1 KiB
C
94 lines
3.1 KiB
C
/*
|
|
* Test strftime function, including C99 additions.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
|
|
int main(void) {
|
|
char buf[300];
|
|
struct tm tm = {0};
|
|
size_t len;
|
|
|
|
tm.tm_year = 2021 - 1900;
|
|
tm.tm_mon = 11;
|
|
tm.tm_mday = 31;
|
|
tm.tm_hour = 14;
|
|
tm.tm_min = 5;
|
|
tm.tm_sec = 2;
|
|
tm.tm_wday = 5;
|
|
tm.tm_yday = 364;
|
|
tm.tm_isdst = 0;
|
|
|
|
len = strftime(buf, sizeof(buf),
|
|
"%a,%A,%b,%B,%c,%C,%d,%D,%e,%F,%g,%G,%h,%H,%I,%j,%m,%M,%p,%r,"
|
|
"%R,%S,%T,%u,%U,%V,%w,%W,%x,%X,%y,%Y,%%,%Ec,%EC,%Ex,%EX,"
|
|
"%Ey,%EY,%Od,%Oe,%OH,%OI,%Om,%OM,%OS,%Ou,%OU,%OV,%Ow,%OW,%Oy,"
|
|
"%t,%n",
|
|
&tm);
|
|
if (len != 274)
|
|
goto Fail;
|
|
if (strcmp(buf,
|
|
"Fri,Friday,Dec,December,Fri Dec 31 14:05:02 2021,20,31,"
|
|
"12/31/21,31,2021-12-31,21,2021,Dec,14,02,365,12,05,PM,"
|
|
"02:05:02 PM,14:05,02,14:05:02,5,52,52,5,52,12/31/21,14:05:02,"
|
|
"21,2021,%,Fri Dec 31 14:05:02 2021,20,12/31/21,14:05:02,21,"
|
|
"2021,31,31,14,02,12,05,02,5,52,52,5,52,21,\t,\n") != 0)
|
|
goto Fail;
|
|
|
|
tm.tm_year = 2022 - 1900;
|
|
tm.tm_mon = 0;
|
|
tm.tm_mday = 1;
|
|
tm.tm_hour = 0;
|
|
tm.tm_min = 59;
|
|
tm.tm_sec = 59;
|
|
tm.tm_wday = 6;
|
|
tm.tm_yday = 0;
|
|
tm.tm_isdst = 0;
|
|
|
|
len = strftime(buf, sizeof(buf),
|
|
"%a,%A,%b,%B,%c,%C,%d,%D,%e,%F,%g,%G,%h,%H,%I,%j,%m,%M,%p,%r,"
|
|
"%R,%S,%T,%u,%U,%V,%w,%W,%x,%X,%y,%Y,%%,%Ec,%EC,%Ex,%EX,"
|
|
"%Ey,%EY,%Od,%Oe,%OH,%OI,%Om,%OM,%OS,%Ou,%OU,%OV,%Ow,%OW,%Oy,"
|
|
"%t,%n",
|
|
&tm);
|
|
if (len != 275)
|
|
goto Fail;
|
|
if (strcmp(buf,
|
|
"Sat,Saturday,Jan,January,Sat Jan 1 00:59:59 2022,20,01,"
|
|
"01/01/22, 1,2022-01-01,21,2021,Jan,00,12,001,01,59,AM,"
|
|
"12:59:59 AM,00:59,59,00:59:59,6,00,52,6,00,01/01/22,00:59:59,"
|
|
"22,2022,%,Sat Jan 1 00:59:59 2022,20,01/01/22,00:59:59,22,"
|
|
"2022,01, 1,00,12,01,59,59,6,00,52,6,00,22,\t,\n"
|
|
) != 0)
|
|
goto Fail;
|
|
|
|
if (strftime(buf, 1, "%A", &tm) != 0)
|
|
goto Fail;
|
|
|
|
len = strftime(buf, sizeof(buf), "%z", &tm);
|
|
if (len != 0) {
|
|
if (len != 5)
|
|
goto Fail;
|
|
if (buf[0] != '-' && buf[0] != '+')
|
|
goto Fail;
|
|
if (buf[1] < '0' || buf[1] > '2')
|
|
goto Fail;
|
|
if (buf[2] < '0' || buf[2] > '9')
|
|
goto Fail;
|
|
if (buf[3] < '0' || buf[3] > '5')
|
|
goto Fail;
|
|
if (buf[4] < '0' || buf[4] > '9')
|
|
goto Fail;
|
|
}
|
|
|
|
strftime(buf, sizeof(buf), "%Z", &tm); /* format can vary */
|
|
|
|
printf ("Passed Conformance Test c99strftim\n");
|
|
return 0;
|
|
|
|
Fail:
|
|
printf ("Failed Conformance Test c99strftim\n");
|
|
}
|