X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-vasnprintf-posix.c;h=a8186558750a5dde3cb405abf55a79d736cf004f;hb=81f8f597ea553e8454b0bbd89b81b71bc2ce3568;hp=9b3785c8dc915de289de4f8c6b8052cd9aca154d;hpb=6136fd62a3342532f17ccfd5f24db97764978448;p=gnulib.git diff --git a/tests/test-vasnprintf-posix.c b/tests/test-vasnprintf-posix.c index 9b3785c8d..a81865587 100644 --- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -111,7 +111,6 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) free (result); } -#if HAVE_LONG_DOUBLE { size_t length; char *result = @@ -121,7 +120,6 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) ASSERT (length == strlen (result)); free (result); } -#endif /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal output of floating-point numbers. */ @@ -416,6 +414,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) char *result = my_asnprintf (NULL, &length, "%010a %d", 1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); + /* "0000000inf 33" is not a valid result; see + */ ASSERT (strcmp (result, " inf 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -426,13 +426,13 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) char *result = my_asnprintf (NULL, &length, "%010a %d", NaN (), 33, 44, 55); ASSERT (result != NULL); + /* "0000000nan 33" is not a valid result; see + */ ASSERT (strcmp (result, " nan 33") == 0); ASSERT (length == strlen (result)); free (result); } -#if HAVE_LONG_DOUBLE - { /* A positive number. */ size_t length; char *result = @@ -724,6 +724,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) char *result = my_asnprintf (NULL, &length, "%010La %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); + /* "0000000inf 33" is not a valid result; see + */ ASSERT (strcmp (result, " inf 33") == 0); ASSERT (length == strlen (result)); free (result); @@ -734,12 +736,470 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) char *result = my_asnprintf (NULL, &length, "%010La %d", 0.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); + /* "0000000nan 33" is not a valid result; see + */ ASSERT (strcmp (result, " nan 33") == 0); ASSERT (length == strlen (result)); free (result); } -#endif + /* 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. */