Add tests for new functionality (other than math functions).

This commit is contained in:
Stephen Heumann 2022-01-01 20:50:12 -06:00
parent 1fb1762458
commit 45fad90d6d
5 changed files with 338 additions and 0 deletions

View File

@ -15,9 +15,14 @@
{1} c99hexflt.c
{1} c99arraytp.c
{1} c99complit.c
{1} c99strftim.c
{1} c99locale.c
{1} c99stdarg.c
{1} c11generic.c
{1} c11align.c
{1} c11noret.c
{1} c11quickex.c
{1} c11sassert.c
{1} c11unicode.c
{1} c11uchar.c

View File

@ -0,0 +1,77 @@
/*
* Test <uchar.h> conversion functions (C11).
*/
#include <limits.h>
#include <stdio.h>
#include <uchar.h>
#include <stddef.h>
#if !__STDC_UTF_16__ || !__STDC_UTF_32__
#error "Compiler does not use UTF-16/UTF-32 encodings"
#endif
int main(void) {
char16_t c16;
char32_t c32;
char s[MB_LEN_MAX];
if (mbrtoc16(&c16, "a", 2, NULL) != 1)
goto Fail;
if (c16 != u'a')
goto Fail;
if (mbrtoc32(&c32, "Z", 2, NULL) != 1)
goto Fail;
if (c32 != U'Z')
goto Fail;
if (c16rtomb(s, u'1', NULL) != 1)
goto Fail;
if (s[0] != '1')
goto Fail;
if (c32rtomb(s, U',', NULL) != 1)
goto Fail;
if (s[0] != ',')
goto Fail;
if (mbrtoc16(&c16, "", 1, NULL) != 0)
goto Fail;
if (c16 != 0)
goto Fail;
if (mbrtoc32(&c32, "", 1, NULL) != 0)
goto Fail;
if (c32 != 0)
goto Fail;
#ifdef __ORCAC__
/* Test conversion from/to Mac OS Roman */
if (mbrtoc16(&c16, "\x80", 2, NULL) != 1)
goto Fail;
if (c16 != u'\u00C4')
goto Fail;
if (mbrtoc32(&c32, "\xA0", 2, NULL) != 1)
goto Fail;
if (c32 != U'\u2020')
goto Fail;
if (c16rtomb(s, u'\u2264', NULL) != 1)
goto Fail;
if (s[0] != '\xB2')
goto Fail;
if (c32rtomb(s, U'\u0152', NULL) != 1)
goto Fail;
if (s[0] != '\xCE')
goto Fail;
#endif
printf ("Passed Conformance Test c99uchar\n");
return 0;
Fail:
printf ("Failed Conformance Test c99uchar\n");
}

View File

@ -0,0 +1,110 @@
/*
* Test locale-related functions, including C99 additions.
*
* This does not test for the availability of any specific locales
* other than "C" and "".
*/
#include <limits.h>
#include <locale.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
/* query locale */
if (setlocale(LC_ALL, NULL) == NULL)
goto Fail;
/* set part or all of locale to "native environment" */
if (setlocale(LC_COLLATE, "") == NULL)
goto Fail;
if (setlocale(LC_CTYPE, "") == NULL)
goto Fail;
if (setlocale(LC_MONETARY, "") == NULL)
goto Fail;
if (setlocale(LC_NUMERIC, "") == NULL)
goto Fail;
if (setlocale(LC_TIME, "") == NULL)
goto Fail;
if (setlocale(LC_ALL, "") == NULL)
goto Fail;
/* setting a (presumably) invalid locale should fail */
if (setlocale(LC_ALL, "3454atfhjk-dfghfdkljglksjrh0;rdgfdsg") != NULL)
goto Fail;
/* set part or all of locale to C locale */
if (setlocale(LC_COLLATE, "C") == NULL)
goto Fail;
if (setlocale(LC_CTYPE, "C") == NULL)
goto Fail;
if (setlocale(LC_MONETARY, "C") == NULL)
goto Fail;
if (setlocale(LC_NUMERIC, "C") == NULL)
goto Fail;
if (setlocale(LC_TIME, "C") == NULL)
goto Fail;
if (setlocale(LC_ALL, "C") == NULL)
goto Fail;
/* test localeconv() output in "C" locale */
struct lconv *lc = localeconv();
if ( strcmp(lc->decimal_point, ".")
|| strcmp(lc->thousands_sep, "")
|| strcmp(lc->grouping, "")
|| strcmp(lc->mon_decimal_point, "")
|| strcmp(lc->mon_thousands_sep, "")
|| strcmp(lc->mon_grouping, "")
|| strcmp(lc->positive_sign, "")
|| strcmp(lc->negative_sign, "")
|| strcmp(lc->currency_symbol, "")
|| lc->frac_digits != CHAR_MAX
|| lc->p_cs_precedes != CHAR_MAX
|| lc->n_cs_precedes != CHAR_MAX
|| lc->p_sep_by_space != CHAR_MAX
|| lc->n_sep_by_space != CHAR_MAX
|| lc->p_sign_posn != CHAR_MAX
|| lc->n_sign_posn != CHAR_MAX
|| strcmp(lc->int_curr_symbol, "")
|| lc->int_frac_digits != CHAR_MAX
|| lc->int_p_cs_precedes != CHAR_MAX
|| lc->int_n_cs_precedes != CHAR_MAX
|| lc->int_p_sep_by_space != CHAR_MAX
|| lc->int_n_sep_by_space != CHAR_MAX
|| lc->int_p_sign_posn != CHAR_MAX
|| lc->int_n_sign_posn != CHAR_MAX)
goto Fail;
/* test strcoll in "C" locale */
if (strcoll("abd", "acd") >= 0)
goto Fail;
if (strcoll("abc", "abc") != 0)
goto Fail;
if (strcoll("124", "123") <= 0)
goto Fail;
/* test strxfrm */
char buf1[50] = {0}, buf2[50] = {0};
if (strxfrm(buf1, "abd", sizeof buf1) >= sizeof buf1)
goto Fail;
if (strxfrm(buf2, "acd", sizeof buf2) >= sizeof buf2)
goto Fail;
if (strcmp(buf1, buf2) >= 0)
goto Fail;
/* test mblen */
if (mblen("", 1) != 0)
goto Fail;
if (mblen("xyz", 3) != 1)
goto Fail;
mblen(NULL, 0);
printf ("Passed Conformance Test c99locale\n");
return 0;
Fail:
printf ("Failed Conformance Test c99locale\n");
}

View File

@ -0,0 +1,71 @@
/*
* Test <stdarg.h> functionality, including va_copy (from C99).
*/
#include <stdarg.h>
#include <stdio.h>
int va_list_fn(va_list ap) {
va_list ap2;
/* Test use of va_copy in a function that was passed a va_list */
va_copy(ap2, ap);
if (va_arg(ap2, double) != 67890.0)
return 0;
if (va_arg(ap2, long) != 1234567890)
return 0;
va_end(ap2);
return 1;
}
int va_fn(int x, ...) {
va_list ap, ap2;
int i, *ip = &i;
/* Test basic varargs functionality */
va_start(ap, x);
if (va_arg(ap, int) != 12345)
return 0;
/* Test va_copy */
va_copy(ap2, ap);
if (va_arg(ap2, double) != 67890.0)
return 0;
/* Test passing a va_list to another function */
if (!va_list_fn(ap))
return 0;
va_end(ap);
va_end(ap2);
/* Test that varargs processing can be restarted */
va_start(ap, x);
if (va_arg(ap, int) != 12345)
return 0;
va_end(ap);
/* Test that va_end does not change local variable addresses */
if (&i != ip)
return 0;
return 1;
}
int main(void) {
if (!va_fn(1, 12345, 67890.0, 1234567890L))
goto Fail;
printf ("Passed Conformance Test c99stdarg\n");
return 0;
Fail:
printf ("Failed Conformance Test c99stdarg\n");
}

View File

@ -0,0 +1,75 @@
/*
* 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;
printf ("Passed Conformance Test c99strftim\n");
return 0;
Fail:
printf ("Failed Conformance Test c99strftim\n");
}