# HG changeset patch # User Bruno Haible # Date 1270931216 -7200 # Node ID 69f672943274e56e7c9f3cbed3a6a2dbe6be1d86 # Parent af2bd6fe2a984e8063ee207eb39314ccffe4bc04 vasnprintf: Add more tests. diff --git a/ChangeLog b/ChangeLog --- 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 --- 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 @@ } } #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 *