tst-trans.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Test program for user-defined character maps.
  2. Copyright (C) 1999, 2000 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>.
  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 <locale.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <wchar.h>
  21. #include <wctype.h>
  22. int
  23. main (void)
  24. {
  25. char buf[30];
  26. wchar_t wbuf[30];
  27. wctrans_t t;
  28. wint_t wch;
  29. int errors = 0;
  30. int len;
  31. setlocale (LC_ALL, "");
  32. t = wctrans ("test");
  33. if (t == (wctrans_t) 0)
  34. {
  35. puts ("locale data files probably not loaded");
  36. exit (1);
  37. }
  38. wch = towctrans (L'A', t);
  39. printf ("towctrans (L'A', t) = %c\n", wch);
  40. if (wch != L'B')
  41. errors = 1;
  42. wch = towctrans (L'B', t);
  43. printf ("towctrans (L'B', t) = %c\n", wch);
  44. if (wch != L'C')
  45. errors = 1;
  46. /* Test the output digit handling. */
  47. swprintf (wbuf, sizeof (wbuf) / sizeof (wbuf[0]), L"%Id", 0x499602D2);
  48. errors |= wcscmp (wbuf, L"bcdefghija") != 0;
  49. len = wcslen (wbuf);
  50. errors |= len != 10;
  51. printf ("len = %d, wbuf = L\"%ls\"\n", len, wbuf);
  52. snprintf (buf, sizeof buf, "%Id", 0x499602D2);
  53. errors |= strcmp (buf, "bcdefghija") != 0;
  54. len = strlen (buf);
  55. errors |= len != 10;
  56. printf ("len = %d, buf = \"%s\"\n", len, buf);
  57. return errors;
  58. }