Mercurial > hg > octave-lyh > gnulib-hg
changeset 8684:9ea5590b49d1
Add tests for %f and %F directives.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 13 Apr 2007 16:56:08 +0000 |
parents | eb9089f3f491 |
children | c3cb2f3c7f8c |
files | ChangeLog tests/test-fprintf-posix.h tests/test-fprintf-posix.out tests/test-printf-posix.h tests/test-snprintf-posix.h tests/test-sprintf-posix.h tests/test-vasnprintf-posix.c tests/test-vasprintf-posix.c |
diffstat | 8 files changed, 1907 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-04-13 Bruno Haible <bruno@clisp.org> + + * tests/test-vasnprintf-posix.c (test_function): Add tests for %f and + %F directives. + * tests/test-vasprintf-posix.c (test_function): Likewise. + * tests/test-snprintf-posix.h (test_function): Likewise. + * tests/test-sprintf-posix.h (test_function): Likewise. + * tests/test-fprintf-posix.h (test_function): Likewise. + * tests/test-printf-posix.h (test_function): Likewise. + * tests/test-fprintf-posix.out: Likewise. + 2007-04-13 Bruno Haible <bruno@clisp.org> * modules/lock-tests (configure.ac): For LIBSCHED, try also -lposix4.
--- a/tests/test-fprintf-posix.h +++ b/tests/test-fprintf-posix.h @@ -67,6 +67,110 @@ /* FLAG_ZERO with NaN. */ my_fprintf (stdout, "%010a %d\n", NaN (), 33, 44, 55); + /* Test the support of the %f format directive. */ + + /* A positive number. */ + my_fprintf (stdout, "%f %d\n", 12.75, 33, 44, 55); + + /* A larger positive number. */ + my_fprintf (stdout, "%f %d\n", 1234567.0, 33, 44, 55); + + /* A negative number. */ + my_fprintf (stdout, "%f %d\n", -0.03125, 33, 44, 55); + + /* Positive zero. */ + my_fprintf (stdout, "%f %d\n", 0.0, 33, 44, 55); + + /* Negative zero. */ + my_fprintf (stdout, "%f %d\n", -0.0, 33, 44, 55); + + /* NaN. */ + my_fprintf (stdout, "%f %d\n", NaN (), 33, 44, 55); + + /* FLAG_ZERO. */ + my_fprintf (stdout, "%015f %d\n", 1234.0, 33, 44, 55); + + /* Precision. */ + my_fprintf (stdout, "%.f %d\n", 1234.0, 33, 44, 55); + + /* A positive number. */ + my_fprintf (stdout, "%Lf %d\n", 12.75L, 33, 44, 55); + + /* A larger positive number. */ + my_fprintf (stdout, "%Lf %d\n", 1234567.0L, 33, 44, 55); + + /* A negative number. */ + my_fprintf (stdout, "%Lf %d\n", -0.03125L, 33, 44, 55); + + /* Positive zero. */ + my_fprintf (stdout, "%Lf %d\n", 0.0L, 33, 44, 55); + + /* Negative zero. */ + my_fprintf (stdout, "%Lf %d\n", -0.0L, 33, 44, 55); + + { /* NaN. */ + static long double zero = 0.0L; + my_fprintf (stdout, "%Lf %d\n", zero / zero, 33, 44, 55); + } + + /* FLAG_ZERO. */ + my_fprintf (stdout, "%015Lf %d\n", 1234.0L, 33, 44, 55); + + /* Precision. */ + my_fprintf (stdout, "%.Lf %d\n", 1234.0L, 33, 44, 55); + + /* Test the support of the %F format directive. */ + + /* A positive number. */ + my_fprintf (stdout, "%F %d\n", 12.75, 33, 44, 55); + + /* A larger positive number. */ + my_fprintf (stdout, "%F %d\n", 1234567.0, 33, 44, 55); + + /* A negative number. */ + my_fprintf (stdout, "%F %d\n", -0.03125, 33, 44, 55); + + /* Positive zero. */ + my_fprintf (stdout, "%F %d\n", 0.0, 33, 44, 55); + + /* Negative zero. */ + my_fprintf (stdout, "%F %d\n", -0.0, 33, 44, 55); + + /* NaN. */ + my_fprintf (stdout, "%F %d\n", NaN (), 33, 44, 55); + + /* FLAG_ZERO. */ + my_fprintf (stdout, "%015F %d\n", 1234.0, 33, 44, 55); + + /* Precision. */ + my_fprintf (stdout, "%.F %d\n", 1234.0, 33, 44, 55); + + /* A positive number. */ + my_fprintf (stdout, "%LF %d\n", 12.75L, 33, 44, 55); + + /* A larger positive number. */ + my_fprintf (stdout, "%LF %d\n", 1234567.0L, 33, 44, 55); + + /* A negative number. */ + my_fprintf (stdout, "%LF %d\n", -0.03125L, 33, 44, 55); + + /* Positive zero. */ + my_fprintf (stdout, "%LF %d\n", 0.0L, 33, 44, 55); + + /* Negative zero. */ + my_fprintf (stdout, "%LF %d\n", -0.0L, 33, 44, 55); + + { /* NaN. */ + static long double zero = 0.0L; + my_fprintf (stdout, "%LF %d\n", zero / zero, 33, 44, 55); + } + + /* FLAG_ZERO. */ + my_fprintf (stdout, "%015LF %d\n", 1234.0L, 33, 44, 55); + + /* Precision. */ + my_fprintf (stdout, "%.LF %d\n", 1234.0L, 33, 44, 55); + /* Test the support of the POSIX/XSI format strings with positions. */ my_fprintf (stdout, "%2$d %1$d\n", 33, 55);
--- a/tests/test-fprintf-posix.out +++ b/tests/test-fprintf-posix.out @@ -8,4 +8,36 @@ nan 33 inf 33 nan 33 +12.750000 33 +1234567.000000 33 +-0.031250 33 +0.000000 33 +-0.000000 33 +nan 33 +00001234.000000 33 +1234 33 +12.750000 33 +1234567.000000 33 +-0.031250 33 +0.000000 33 +-0.000000 33 +nan 33 +00001234.000000 33 +1234 33 +12.750000 33 +1234567.000000 33 +-0.031250 33 +0.000000 33 +-0.000000 33 +NAN 33 +00001234.000000 33 +1234 33 +12.750000 33 +1234567.000000 33 +-0.031250 33 +0.000000 33 +-0.000000 33 +NAN 33 +00001234.000000 33 +1234 33 55 33
--- a/tests/test-printf-posix.h +++ b/tests/test-printf-posix.h @@ -71,6 +71,110 @@ <http://lists.gnu.org/archive/html/bug-gnulib/2007-04/msg00107.html> */ my_printf ("%010a %d\n", NaN (), 33, 44, 55); + /* Test the support of the %f format directive. */ + + /* A positive number. */ + my_printf ("%f %d\n", 12.75, 33, 44, 55); + + /* A larger positive number. */ + my_printf ("%f %d\n", 1234567.0, 33, 44, 55); + + /* A negative number. */ + my_printf ("%f %d\n", -0.03125, 33, 44, 55); + + /* Positive zero. */ + my_printf ("%f %d\n", 0.0, 33, 44, 55); + + /* Negative zero. */ + my_printf ("%f %d\n", -0.0, 33, 44, 55); + + /* NaN. */ + my_printf ("%f %d\n", NaN (), 33, 44, 55); + + /* FLAG_ZERO. */ + my_printf ("%015f %d\n", 1234.0, 33, 44, 55); + + /* Precision. */ + my_printf ("%.f %d\n", 1234.0, 33, 44, 55); + + /* A positive number. */ + my_printf ("%Lf %d\n", 12.75L, 33, 44, 55); + + /* A larger positive number. */ + my_printf ("%Lf %d\n", 1234567.0L, 33, 44, 55); + + /* A negative number. */ + my_printf ("%Lf %d\n", -0.03125L, 33, 44, 55); + + /* Positive zero. */ + my_printf ("%Lf %d\n", 0.0L, 33, 44, 55); + + /* Negative zero. */ + my_printf ("%Lf %d\n", -0.0L, 33, 44, 55); + + { /* NaN. */ + static long double zero = 0.0L; + my_printf ("%Lf %d\n", zero / zero, 33, 44, 55); + } + + /* FLAG_ZERO. */ + my_printf ("%015Lf %d\n", 1234.0L, 33, 44, 55); + + /* Precision. */ + my_printf ("%.Lf %d\n", 1234.0L, 33, 44, 55); + + /* Test the support of the %F format directive. */ + + /* A positive number. */ + my_printf ("%F %d\n", 12.75, 33, 44, 55); + + /* A larger positive number. */ + my_printf ("%F %d\n", 1234567.0, 33, 44, 55); + + /* A negative number. */ + my_printf ("%F %d\n", -0.03125, 33, 44, 55); + + /* Positive zero. */ + my_printf ("%F %d\n", 0.0, 33, 44, 55); + + /* Negative zero. */ + my_printf ("%F %d\n", -0.0, 33, 44, 55); + + /* NaN. */ + my_printf ("%F %d\n", NaN (), 33, 44, 55); + + /* FLAG_ZERO. */ + my_printf ("%015F %d\n", 1234.0, 33, 44, 55); + + /* Precision. */ + my_printf ("%.F %d\n", 1234.0, 33, 44, 55); + + /* A positive number. */ + my_printf ("%LF %d\n", 12.75L, 33, 44, 55); + + /* A larger positive number. */ + my_printf ("%LF %d\n", 1234567.0L, 33, 44, 55); + + /* A negative number. */ + my_printf ("%LF %d\n", -0.03125L, 33, 44, 55); + + /* Positive zero. */ + my_printf ("%LF %d\n", 0.0L, 33, 44, 55); + + /* Negative zero. */ + my_printf ("%LF %d\n", -0.0L, 33, 44, 55); + + { /* NaN. */ + static long double zero = 0.0L; + my_printf ("%LF %d\n", zero / zero, 33, 44, 55); + } + + /* FLAG_ZERO. */ + my_printf ("%015LF %d\n", 1234.0L, 33, 44, 55); + + /* Precision. */ + my_printf ("%.LF %d\n", 1234.0L, 33, 44, 55); + /* Test the support of the POSIX/XSI format strings with positions. */ my_printf ("%2$d %1$d\n", 33, 55);
--- a/tests/test-snprintf-posix.h +++ b/tests/test-snprintf-posix.h @@ -615,6 +615,376 @@ ASSERT (retval == strlen (result)); } + /* Test the support of the %f format directive. */ + + { /* A positive number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%f %d", 12.75, 33, 44, 55); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A larger positive number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%f %d", 1234567.0, 33, 44, 55); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A negative number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%f %d", -0.03125, 33, 44, 55); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive zero. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%f %d", 0.0, 33, 44, 55); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative zero. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%f %d", -0.0, 33, 44, 55); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive infinity. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%f %d", 1.0 / 0.0, 33, 44, 55); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative infinity. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%f %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (strcmp (result, "-inf 33") == 0 + || strcmp (result, "-infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* NaN. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%f %d", NaN (), 33, 44, 55); + ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%015f %d", 1234.0, 33, 44, 55); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO with infinite number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%015f %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (strcmp (result, " -inf 33") == 0 + || strcmp (result, " -infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.f %d", 1234.0, 33, 44, 55); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A positive number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%Lf %d", 12.75L, 33, 44, 55); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A larger positive number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%Lf %d", 1234567.0L, 33, 44, 55); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A negative number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%Lf %d", -0.03125L, 33, 44, 55); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive zero. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%Lf %d", 0.0L, 33, 44, 55); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative zero. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%Lf %d", -0.0L, 33, 44, 55); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive infinity. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%Lf %d", 1.0L / 0.0L, 33, 44, 55); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative infinity. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%Lf %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (strcmp (result, "-inf 33") == 0 + || strcmp (result, "-infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* NaN. */ + static long double zero = 0.0L; + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%Lf %d", zero / zero, 33, 44, 55); + ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%015Lf %d", 1234.0L, 33, 44, 55); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO with infinite number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%015Lf %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (strcmp (result, " -inf 33") == 0 + || strcmp (result, " -infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.Lf %d", 1234.0L, 33, 44, 55); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (retval == strlen (result)); + } + + /* Test the support of the %F format directive. */ + + { /* A positive number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%F %d", 12.75, 33, 44, 55); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A larger positive number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%F %d", 1234567.0, 33, 44, 55); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A negative number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%F %d", -0.03125, 33, 44, 55); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive zero. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%F %d", 0.0, 33, 44, 55); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative zero. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%F %d", -0.0, 33, 44, 55); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive infinity. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%F %d", 1.0 / 0.0, 33, 44, 55); + ASSERT (strcmp (result, "INF 33") == 0 + || strcmp (result, "INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative infinity. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%F %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (strcmp (result, "-INF 33") == 0 + || strcmp (result, "-INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* NaN. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%F %d", NaN (), 33, 44, 55); + ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%015F %d", 1234.0, 33, 44, 55); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO with infinite number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%015F %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (strcmp (result, " -INF 33") == 0 + || strcmp (result, " -INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.F %d", 1234.0, 33, 44, 55); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A positive number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%LF %d", 12.75L, 33, 44, 55); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A larger positive number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%LF %d", 1234567.0L, 33, 44, 55); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A negative number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%LF %d", -0.03125L, 33, 44, 55); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive zero. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%LF %d", 0.0L, 33, 44, 55); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative zero. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%LF %d", -0.0L, 33, 44, 55); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive infinity. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%LF %d", 1.0L / 0.0L, 33, 44, 55); + ASSERT (strcmp (result, "INF 33") == 0 + || strcmp (result, "INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative infinity. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%LF %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (strcmp (result, "-INF 33") == 0 + || strcmp (result, "-INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* NaN. */ + static long double zero = 0.0L; + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%LF %d", zero / zero, 33, 44, 55); + ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%015LF %d", 1234.0L, 33, 44, 55); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO with infinite number. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%015LF %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (strcmp (result, " -INF 33") == 0 + || strcmp (result, " -INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision. */ + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%.LF %d", 1234.0L, 33, 44, 55); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (retval == strlen (result)); + } + /* Test the support of the %n format directive. */ {
--- a/tests/test-sprintf-posix.h +++ b/tests/test-sprintf-posix.h @@ -601,6 +601,376 @@ ASSERT (retval == strlen (result)); } + /* Test the support of the %f format directive. */ + + { /* A positive number. */ + char result[1000]; + int retval = + my_sprintf (result, "%f %d", 12.75, 33, 44, 55); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A larger positive number. */ + char result[1000]; + int retval = + my_sprintf (result, "%f %d", 1234567.0, 33, 44, 55); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A negative number. */ + char result[1000]; + int retval = + my_sprintf (result, "%f %d", -0.03125, 33, 44, 55); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive zero. */ + char result[1000]; + int retval = + my_sprintf (result, "%f %d", 0.0, 33, 44, 55); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative zero. */ + char result[1000]; + int retval = + my_sprintf (result, "%f %d", -0.0, 33, 44, 55); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive infinity. */ + char result[1000]; + int retval = + my_sprintf (result, "%f %d", 1.0 / 0.0, 33, 44, 55); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative infinity. */ + char result[1000]; + int retval = + my_sprintf (result, "%f %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (strcmp (result, "-inf 33") == 0 + || strcmp (result, "-infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* NaN. */ + char result[1000]; + int retval = + my_sprintf (result, "%f %d", NaN (), 33, 44, 55); + ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO. */ + char result[1000]; + int retval = + my_sprintf (result, "%015f %d", 1234.0, 33, 44, 55); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO with infinite number. */ + char result[1000]; + int retval = + my_sprintf (result, "%015f %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (strcmp (result, " -inf 33") == 0 + || strcmp (result, " -infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision. */ + char result[1000]; + int retval = + my_sprintf (result, "%.f %d", 1234.0, 33, 44, 55); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A positive number. */ + char result[1000]; + int retval = + my_sprintf (result, "%Lf %d", 12.75L, 33, 44, 55); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A larger positive number. */ + char result[1000]; + int retval = + my_sprintf (result, "%Lf %d", 1234567.0L, 33, 44, 55); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A negative number. */ + char result[1000]; + int retval = + my_sprintf (result, "%Lf %d", -0.03125L, 33, 44, 55); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive zero. */ + char result[1000]; + int retval = + my_sprintf (result, "%Lf %d", 0.0L, 33, 44, 55); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative zero. */ + char result[1000]; + int retval = + my_sprintf (result, "%Lf %d", -0.0L, 33, 44, 55); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive infinity. */ + char result[1000]; + int retval = + my_sprintf (result, "%Lf %d", 1.0L / 0.0L, 33, 44, 55); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative infinity. */ + char result[1000]; + int retval = + my_sprintf (result, "%Lf %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (strcmp (result, "-inf 33") == 0 + || strcmp (result, "-infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* NaN. */ + static long double zero = 0.0L; + char result[1000]; + int retval = + my_sprintf (result, "%Lf %d", zero / zero, 33, 44, 55); + ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO. */ + char result[1000]; + int retval = + my_sprintf (result, "%015Lf %d", 1234.0L, 33, 44, 55); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO with infinite number. */ + char result[1000]; + int retval = + my_sprintf (result, "%015Lf %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (strcmp (result, " -inf 33") == 0 + || strcmp (result, " -infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision. */ + char result[1000]; + int retval = + my_sprintf (result, "%.Lf %d", 1234.0L, 33, 44, 55); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (retval == strlen (result)); + } + + /* Test the support of the %F format directive. */ + + { /* A positive number. */ + char result[1000]; + int retval = + my_sprintf (result, "%F %d", 12.75, 33, 44, 55); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A larger positive number. */ + char result[1000]; + int retval = + my_sprintf (result, "%F %d", 1234567.0, 33, 44, 55); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A negative number. */ + char result[1000]; + int retval = + my_sprintf (result, "%F %d", -0.03125, 33, 44, 55); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive zero. */ + char result[1000]; + int retval = + my_sprintf (result, "%F %d", 0.0, 33, 44, 55); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative zero. */ + char result[1000]; + int retval = + my_sprintf (result, "%F %d", -0.0, 33, 44, 55); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive infinity. */ + char result[1000]; + int retval = + my_sprintf (result, "%F %d", 1.0 / 0.0, 33, 44, 55); + ASSERT (strcmp (result, "INF 33") == 0 + || strcmp (result, "INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative infinity. */ + char result[1000]; + int retval = + my_sprintf (result, "%F %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (strcmp (result, "-INF 33") == 0 + || strcmp (result, "-INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* NaN. */ + char result[1000]; + int retval = + my_sprintf (result, "%F %d", NaN (), 33, 44, 55); + ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO. */ + char result[1000]; + int retval = + my_sprintf (result, "%015F %d", 1234.0, 33, 44, 55); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO with infinite number. */ + char result[1000]; + int retval = + my_sprintf (result, "%015F %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (strcmp (result, " -INF 33") == 0 + || strcmp (result, " -INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision. */ + char result[1000]; + int retval = + my_sprintf (result, "%.F %d", 1234.0, 33, 44, 55); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A positive number. */ + char result[1000]; + int retval = + my_sprintf (result, "%LF %d", 12.75L, 33, 44, 55); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A larger positive number. */ + char result[1000]; + int retval = + my_sprintf (result, "%LF %d", 1234567.0L, 33, 44, 55); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* A negative number. */ + char result[1000]; + int retval = + my_sprintf (result, "%LF %d", -0.03125L, 33, 44, 55); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive zero. */ + char result[1000]; + int retval = + my_sprintf (result, "%LF %d", 0.0L, 33, 44, 55); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative zero. */ + char result[1000]; + int retval = + my_sprintf (result, "%LF %d", -0.0L, 33, 44, 55); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Positive infinity. */ + char result[1000]; + int retval = + my_sprintf (result, "%LF %d", 1.0L / 0.0L, 33, 44, 55); + ASSERT (strcmp (result, "INF 33") == 0 + || strcmp (result, "INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Negative infinity. */ + char result[1000]; + int retval = + my_sprintf (result, "%LF %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (strcmp (result, "-INF 33") == 0 + || strcmp (result, "-INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* NaN. */ + static long double zero = 0.0L; + char result[1000]; + int retval = + my_sprintf (result, "%LF %d", zero / zero, 33, 44, 55); + ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO. */ + char result[1000]; + int retval = + my_sprintf (result, "%015LF %d", 1234.0L, 33, 44, 55); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* FLAG_ZERO with infinite number. */ + char result[1000]; + int retval = + my_sprintf (result, "%015LF %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (strcmp (result, " -INF 33") == 0 + || strcmp (result, " -INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* Precision. */ + char result[1000]; + int retval = + my_sprintf (result, "%.LF %d", 1234.0L, 33, 44, 55); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (retval == strlen (result)); + } + /* Test the support of the %n format directive. */ {
--- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -743,6 +743,464 @@ free (result); } + /* Test the support of the %f format directive. */ + + { /* A positive number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%f %d", 12.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* A larger positive number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%f %d", 1234567.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* A negative number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%f %d", -0.03125, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Positive zero. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%f %d", 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Negative zero. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%f %d", -0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Positive infinity. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%f %d", 1.0 / 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Negative infinity. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%f %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-inf 33") == 0 + || strcmp (result, "-infinity 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* NaN. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%f %d", NaN (), 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* FLAG_ZERO. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%015f %d", 1234.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* FLAG_ZERO with infinite number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%015f %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " -inf 33") == 0 + || strcmp (result, " -infinity 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Precision. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%.f %d", 1234.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* A positive number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%Lf %d", 12.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* A larger positive number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%Lf %d", 1234567.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* A negative number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%Lf %d", -0.03125L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Positive zero. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%Lf %d", 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Negative zero. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%Lf %d", -0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Positive infinity. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%Lf %d", 1.0L / 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Negative infinity. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%Lf %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-inf 33") == 0 + || strcmp (result, "-infinity 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* NaN. */ + static long double zero = 0.0L; + size_t length; + char *result = + my_asnprintf (NULL, &length, "%Lf %d", zero / zero, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* FLAG_ZERO. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%015Lf %d", 1234.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* FLAG_ZERO with infinite number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%015Lf %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " -inf 33") == 0 + || strcmp (result, " -infinity 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Precision. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%.Lf %d", 1234.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + /* Test the support of the %F format directive. */ + + { /* A positive number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%F %d", 12.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* A larger positive number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%F %d", 1234567.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* A negative number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%F %d", -0.03125, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Positive zero. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%F %d", 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Negative zero. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%F %d", -0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Positive infinity. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%F %d", 1.0 / 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "INF 33") == 0 + || strcmp (result, "INFINITY 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Negative infinity. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%F %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-INF 33") == 0 + || strcmp (result, "-INFINITY 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* NaN. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%F %d", NaN (), 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* FLAG_ZERO. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%015F %d", 1234.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* FLAG_ZERO with infinite number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%015F %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " -INF 33") == 0 + || strcmp (result, " -INFINITY 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Precision. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%.F %d", 1234.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* A positive number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%LF %d", 12.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* A larger positive number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%LF %d", 1234567.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* A negative number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%LF %d", -0.03125L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Positive zero. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%LF %d", 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Negative zero. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%LF %d", -0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Positive infinity. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%LF %d", 1.0L / 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "INF 33") == 0 + || strcmp (result, "INFINITY 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Negative infinity. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%LF %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-INF 33") == 0 + || strcmp (result, "-INFINITY 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* NaN. */ + static long double zero = 0.0L; + size_t length; + char *result = + my_asnprintf (NULL, &length, "%LF %d", zero / zero, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* FLAG_ZERO. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%015LF %d", 1234.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* FLAG_ZERO with infinite number. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%015LF %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " -INF 33") == 0 + || strcmp (result, " -INFINITY 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { /* Precision. */ + size_t length; + char *result = + my_asnprintf (NULL, &length, "%.LF %d", 1234.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (length == strlen (result)); + free (result); + } + /* Test the support of the %n format directive. */ {
--- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -724,6 +724,464 @@ free (result); } + /* Test the support of the %f format directive. */ + + { /* A positive number. */ + char *result; + int retval = + my_asprintf (&result, "%f %d", 12.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* A larger positive number. */ + char *result; + int retval = + my_asprintf (&result, "%f %d", 1234567.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* A negative number. */ + char *result; + int retval = + my_asprintf (&result, "%f %d", -0.03125, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Positive zero. */ + char *result; + int retval = + my_asprintf (&result, "%f %d", 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Negative zero. */ + char *result; + int retval = + my_asprintf (&result, "%f %d", -0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Positive infinity. */ + char *result; + int retval = + my_asprintf (&result, "%f %d", 1.0 / 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Negative infinity. */ + char *result; + int retval = + my_asprintf (&result, "%f %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-inf 33") == 0 + || strcmp (result, "-infinity 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* NaN. */ + char *result; + int retval = + my_asprintf (&result, "%f %d", NaN (), 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* FLAG_ZERO. */ + char *result; + int retval = + my_asprintf (&result, "%015f %d", 1234.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* FLAG_ZERO with infinite number. */ + char *result; + int retval = + my_asprintf (&result, "%015f %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " -inf 33") == 0 + || strcmp (result, " -infinity 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Precision. */ + char *result; + int retval = + my_asprintf (&result, "%.f %d", 1234.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* A positive number. */ + char *result; + int retval = + my_asprintf (&result, "%Lf %d", 12.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* A larger positive number. */ + char *result; + int retval = + my_asprintf (&result, "%Lf %d", 1234567.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* A negative number. */ + char *result; + int retval = + my_asprintf (&result, "%Lf %d", -0.03125L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Positive zero. */ + char *result; + int retval = + my_asprintf (&result, "%Lf %d", 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Negative zero. */ + char *result; + int retval = + my_asprintf (&result, "%Lf %d", -0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Positive infinity. */ + char *result; + int retval = + my_asprintf (&result, "%Lf %d", 1.0L / 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Negative infinity. */ + char *result; + int retval = + my_asprintf (&result, "%Lf %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-inf 33") == 0 + || strcmp (result, "-infinity 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* NaN. */ + static long double zero = 0.0L; + char *result; + int retval = + my_asprintf (&result, "%Lf %d", zero / zero, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "nan 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* FLAG_ZERO. */ + char *result; + int retval = + my_asprintf (&result, "%015Lf %d", 1234.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* FLAG_ZERO with infinite number. */ + char *result; + int retval = + my_asprintf (&result, "%015Lf %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " -inf 33") == 0 + || strcmp (result, " -infinity 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Precision. */ + char *result; + int retval = + my_asprintf (&result, "%.Lf %d", 1234.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + /* Test the support of the %F format directive. */ + + { /* A positive number. */ + char *result; + int retval = + my_asprintf (&result, "%F %d", 12.75, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* A larger positive number. */ + char *result; + int retval = + my_asprintf (&result, "%F %d", 1234567.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* A negative number. */ + char *result; + int retval = + my_asprintf (&result, "%F %d", -0.03125, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Positive zero. */ + char *result; + int retval = + my_asprintf (&result, "%F %d", 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Negative zero. */ + char *result; + int retval = + my_asprintf (&result, "%F %d", -0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Positive infinity. */ + char *result; + int retval = + my_asprintf (&result, "%F %d", 1.0 / 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "INF 33") == 0 + || strcmp (result, "INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Negative infinity. */ + char *result; + int retval = + my_asprintf (&result, "%F %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-INF 33") == 0 + || strcmp (result, "-INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* NaN. */ + char *result; + int retval = + my_asprintf (&result, "%F %d", NaN (), 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* FLAG_ZERO. */ + char *result; + int retval = + my_asprintf (&result, "%015F %d", 1234.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* FLAG_ZERO with infinite number. */ + char *result; + int retval = + my_asprintf (&result, "%015F %d", -1.0 / 0.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " -INF 33") == 0 + || strcmp (result, " -INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Precision. */ + char *result; + int retval = + my_asprintf (&result, "%.F %d", 1234.0, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* A positive number. */ + char *result; + int retval = + my_asprintf (&result, "%LF %d", 12.75L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "12.750000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* A larger positive number. */ + char *result; + int retval = + my_asprintf (&result, "%LF %d", 1234567.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234567.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* A negative number. */ + char *result; + int retval = + my_asprintf (&result, "%LF %d", -0.03125L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.031250 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Positive zero. */ + char *result; + int retval = + my_asprintf (&result, "%LF %d", 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Negative zero. */ + char *result; + int retval = + my_asprintf (&result, "%LF %d", -0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Positive infinity. */ + char *result; + int retval = + my_asprintf (&result, "%LF %d", 1.0L / 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "INF 33") == 0 + || strcmp (result, "INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Negative infinity. */ + char *result; + int retval = + my_asprintf (&result, "%LF %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-INF 33") == 0 + || strcmp (result, "-INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* NaN. */ + static long double zero = 0.0L; + char *result; + int retval = + my_asprintf (&result, "%LF %d", zero / zero, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "NAN 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* FLAG_ZERO. */ + char *result; + int retval = + my_asprintf (&result, "%015LF %d", 1234.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "00001234.000000 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* FLAG_ZERO with infinite number. */ + char *result; + int retval = + my_asprintf (&result, "%015LF %d", -1.0L / 0.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " -INF 33") == 0 + || strcmp (result, " -INFINITY 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* Precision. */ + char *result; + int retval = + my_asprintf (&result, "%.LF %d", 1234.0L, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "1234 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + /* Test the support of the %n format directive. */ {