From de9f4b14d7c2acc5088ecde5e5ccfdf7532aab29 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 10 Apr 2010 22:26:56 +0200 Subject: [PATCH] vasnprintf: Add more tests. --- ChangeLog | 4 ++++ tests/test-vasnprintf-posix.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/ChangeLog b/ChangeLog index d07f715aa..5ac07f2b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2010-04-10 Bruno Haible + vasnprintf: Add more tests. + * tests/test-vasnprintf-posix.c: Include . + (test_function): Test converting an invalid wide string. + vasnprintf: Correct handling of unconvertible wide string arguments. * lib/vasnprintf.c (MAX_ROOM_NEEDED): New function, extracted from VASNPRINTF. diff --git a/tests/test-vasnprintf-posix.c b/tests/test-vasnprintf-posix.c index 74ba16535..3a9879f77 100644 --- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -20,6 +20,7 @@ #include "vasnprintf.h" +#include #include #include #include @@ -3636,6 +3637,46 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) } } #endif + +#if HAVE_WCHAR_T + /* Test that converting an invalid wchar_t[] to char[] fails with EILSEQ. */ + { + static const wchar_t input[] = { (wchar_t) 1702057263, 114, 0 }; + size_t length; + char *result = my_asnprintf (NULL, &length, "%ls %d", input, 99); + if (result == NULL) + ASSERT (errno == EILSEQ); + else + free (result); + } + { + static const wchar_t input[] = { (wchar_t) 1702057263, 114, 0 }; + size_t length; + char *result = my_asnprintf (NULL, &length, "%3ls %d", input, 99); + if (result == NULL) + ASSERT (errno == EILSEQ); + else + free (result); + } + { + static const wchar_t input[] = { (wchar_t) 1702057263, 114, 0 }; + size_t length; + char *result = my_asnprintf (NULL, &length, "%.1ls %d", input, 99); + if (result == NULL) + ASSERT (errno == EILSEQ); + else + free (result); + } + { + static const wchar_t input[] = { (wchar_t) 1702057263, 114, 0 }; + size_t length; + char *result = my_asnprintf (NULL, &length, "%3.1ls %d", input, 99); + if (result == NULL) + ASSERT (errno == EILSEQ); + else + free (result); + } +#endif } static char * -- 2.11.0