13 const wchar_t *expected;
17 { "UCS-4LE", "a\0\0\0b\0\0\0", 8, L"ab", 2 },
18 { "UCS-4BE", "\0\0\0a\0\0\0b", 8, L"ab", 2 },
20 #define ntests (sizeof (tests) / sizeof (tests[0]))
23 static int do_test (void);
24 #define TEST_FUNCTION do_test ()
26 static void prepare (void);
27 #define PREPARE(argc, argv) prepare ();
29 #include "../test-skeleton.c"
39 fd = create_temp_file ("tst-fopenloc2", &tmpname);
42 puts ("cannot open temp file");
51 for (int i = 0; i < ntests; ++i)
53 if (ftruncate (fd, 0) != 0)
55 printf ("ftruncate in round %d failed\n", i + 1);
59 if (TEMP_FAILURE_RETRY (write (fd, tests[i].data, tests[i].datalen))
62 printf ("write in round %d failed\n", i + 1);
66 if (lseek (fd, 0, SEEK_SET) != 0)
68 printf ("lseek in round %d failed\n", i + 1);
73 if (asprintf (&ccs, "r,ccs=%s", tests[i].enc) == -1)
75 printf ("asprintf in round %d failed\n", i + 1);
79 FILE *fp = fopen (tmpname, ccs);
82 printf ("fopen in round %d failed\n", i + 1);
87 wchar_t line[LINELEN];
88 if (fgetws (line, LINELEN, fp) != line)
90 printf ("fgetws in round %d failed\n", i + 1);
94 if (wcslen (line) != tests[i].expectedlen)
96 printf ("round %d: expected length %zu, got length %zu\n",
97 i + 1, tests[i].expectedlen, wcslen (line));
101 if (wcscmp (tests[i].expected, line) != 0)
103 printf ("round %d: expected L\"%ls\", got L\"%ls\"\n",
104 i + 1, tests[i].expected, line);