changeset 13200:69f672943274

vasnprintf: Add more tests.
author Bruno Haible <bruno@clisp.org>
date Sat, 10 Apr 2010 22:26:56 +0200
parents af2bd6fe2a98
children 44c840887cad
files ChangeLog tests/test-vasnprintf-posix.c
diffstat 2 files changed, 45 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Apr 10 22:25:31 2010 +0200
+++ b/ChangeLog	Sat Apr 10 22:26:56 2010 +0200
@@ -1,5 +1,9 @@
 2010-04-10  Bruno Haible  <bruno@clisp.org>
 
+	vasnprintf: Add more tests.
+	* tests/test-vasnprintf-posix.c: Include <errno.h>.
+	(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.
--- a/tests/test-vasnprintf-posix.c	Sat Apr 10 22:25:31 2010 +0200
+++ b/tests/test-vasnprintf-posix.c	Sat Apr 10 22:26:56 2010 +0200
@@ -20,6 +20,7 @@
 
 #include "vasnprintf.h"
 
+#include <errno.h>
 #include <float.h>
 #include <stdarg.h>
 #include <stddef.h>
@@ -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 *