1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <locale.h>
#include <stdio.h>
#include <wchar.h>
#include <sys/types.h>
static int
do_test (void)
{
if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
{
puts ("setlocale failed");
return 1;
}
FILE *fp = tmpfile ();
if (fp == NULL)
{
puts ("tmpfile failed");
return 1;
}
if (fputws (L"hello", fp) == EOF)
{
puts ("fputws failed");
return 1;
}
rewind (fp);
const wchar_t *cp;
unsigned int cnt;
for (cp = L"hello", cnt = 1; *cp != L'\0'; ++cp, ++cnt)
{
wint_t wc = fgetwc (fp);
if (wc != (wint_t) *cp)
{
printf ("fgetwc failed: got L'%lc', expected L'%lc'\n",
wc, (wint_t) *cp);
return 1;
}
off_t o = ftello (fp);
if (o != cnt)
{
printf ("ftello failed: got %lu, expected %u\n",
(unsigned long int) o, cnt);
return 1;
}
printf ("round %u OK\n", cnt);
}
fclose (fp);
return 0;
}
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
|