tst-fgetwc.c 972 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <locale.h>
  2. #include <stdio.h>
  3. #include <wchar.h>
  4. static int
  5. do_test (void)
  6. {
  7. if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
  8. {
  9. puts ("setlocale failed");
  10. return 1;
  11. }
  12. if (setvbuf (stdin, NULL, _IONBF, 0) != 0)
  13. {
  14. puts ("setvbuf failed");
  15. return 1;
  16. }
  17. wchar_t buf[100];
  18. size_t nbuf = 0;
  19. wint_t c;
  20. while ((c = fgetwc (stdin)) != WEOF)
  21. buf[nbuf++] = c;
  22. if (ferror (stdin))
  23. {
  24. puts ("error on stdin");
  25. return 1;
  26. }
  27. const wchar_t expected[] =
  28. {
  29. 0x00000439, 0x00000446, 0x00000443, 0x0000043a,
  30. 0x00000435, 0x0000043d, 0x0000000a, 0x00000071,
  31. 0x00000077, 0x00000065, 0x00000072, 0x00000074,
  32. 0x00000079, 0x0000000a
  33. };
  34. if (nbuf != sizeof (expected) / sizeof (expected[0])
  35. || wmemcmp (expected, buf, nbuf) != 0)
  36. {
  37. puts ("incorrect result");
  38. return 1;
  39. }
  40. return 0;
  41. }
  42. #define TEST_FUNCTION do_test ()
  43. #include "../test-skeleton.c"