tst-mbswcs1.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <wchar.h>
  20. #include <locale.h>
  21. #define show(expr, nexp, wcexp) \
  22. n = expr; \
  23. printf (#expr " -> %Zd", n); \
  24. printf (", wc = %lu", (unsigned long int) wc); \
  25. if (n != (size_t) nexp || wc != wcexp) \
  26. { \
  27. printf (", expected %Zd and %lu", nexp, (unsigned long int) wcexp); \
  28. result = 1; \
  29. } \
  30. putc ('\n', stdout)
  31. int
  32. main (void)
  33. {
  34. const unsigned char buf[6] = { 0x25, 0xe2, 0x82, 0xac, 0xce, 0xbb };
  35. mbstate_t state;
  36. wchar_t wc = 42;
  37. size_t n;
  38. int result = 0;
  39. const char *used_locale;
  40. setlocale (LC_CTYPE, "de_DE.UTF-8");
  41. /* Double check. */
  42. used_locale = setlocale (LC_CTYPE, NULL);
  43. printf ("used locale: \"%s\"\n", used_locale);
  44. result = strcmp (used_locale, "de_DE.UTF-8");
  45. memset (&state, '\0', sizeof (state));
  46. show (mbrtowc (&wc, (const char *) buf + 0, 1, &state), 1, 37);
  47. show (mbrtowc (&wc, (const char *) buf + 1, 1, &state), -2, 37);
  48. show (mbrtowc (&wc, (const char *) buf + 2, 3, &state), 2, 8364);
  49. show (mbrtowc (&wc, (const char *) buf + 4, 1, &state), -2, 8364);
  50. show (mbrtowc (&wc, (const char *) buf + 5, 1, &state), 1, 955);
  51. show (mbrtowc (&wc, (const char *) buf + 5, 1, &state), -1, 955);
  52. return result;
  53. }