/* Test of POSIX compatible vasnprintf() and asnprintf() functions.
- Copyright (C) 2007-2009 Free Software Foundation, Inc.
+ Copyright (C) 2007-2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "vasnprintf.h"
+#include <errno.h>
#include <float.h>
#include <stdarg.h>
#include <stddef.h>
-#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include "macros.h"
#include "nan.h"
-#define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
-#define ASSERT(expr) \
- do \
- { \
- if (!(expr)) \
- { \
- fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
- fflush (stderr); \
- abort (); \
- } \
- } \
- while (0)
-
/* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */
static int
have_minus_zero ()
}
}
#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 *