tst-mbswcs1.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Test restarting behaviour of mbrtowc.
  2. Copyright (C) 2000, 2005 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Bruno Haible <haible@ilog.fr>.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <wchar.h>
  19. #include <locale.h>
  20. #define show(expr, nexp, wcexp) \
  21. n = expr; \
  22. printf (#expr " -> %Zd", n); \
  23. printf (", wc = %lu", (unsigned long int) wc); \
  24. if (n != (size_t) nexp || wc != wcexp) \
  25. { \
  26. printf (", expected %Zd and %lu", nexp, (unsigned long int) wcexp); \
  27. result = 1; \
  28. } \
  29. putc ('\n', stdout)
  30. int
  31. main (void)
  32. {
  33. const unsigned char buf[6] = { 0x25, 0xe2, 0x82, 0xac, 0xce, 0xbb };
  34. mbstate_t state;
  35. wchar_t wc = 42;
  36. size_t n;
  37. int result = 0;
  38. const char *used_locale;
  39. setlocale (LC_CTYPE, "de_DE.UTF-8");
  40. /* Double check. */
  41. used_locale = setlocale (LC_CTYPE, NULL);
  42. printf ("used locale: \"%s\"\n", used_locale);
  43. result = strcmp (used_locale, "de_DE.UTF-8");
  44. memset (&state, '\0', sizeof (state));
  45. show (mbrtowc (&wc, (const char *) buf + 0, 1, &state), 1, 37);
  46. show (mbrtowc (&wc, (const char *) buf + 1, 1, &state), -2, 37);
  47. show (mbrtowc (&wc, (const char *) buf + 2, 3, &state), 2, 8364);
  48. show (mbrtowc (&wc, (const char *) buf + 4, 1, &state), -2, 8364);
  49. show (mbrtowc (&wc, (const char *) buf + 5, 1, &state), 1, 955);
  50. show (mbrtowc (&wc, (const char *) buf + 5, 1, &state), -1, 955);
  51. return result;
  52. }