tst-trans.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include <locale.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <wchar.h>
  22. #include <wctype.h>
  23. int
  24. main (void)
  25. {
  26. char buf[30];
  27. wchar_t wbuf[30];
  28. wctrans_t t;
  29. wint_t wch;
  30. int errors = 0;
  31. int len;
  32. setlocale (LC_ALL, "");
  33. t = wctrans ("test");
  34. if (t == (wctrans_t) 0)
  35. {
  36. puts ("locale data files probably not loaded");
  37. exit (1);
  38. }
  39. wch = towctrans (L'A', t);
  40. printf ("towctrans (L'A', t) = %c\n", wch);
  41. if (wch != L'B')
  42. errors = 1;
  43. wch = towctrans (L'B', t);
  44. printf ("towctrans (L'B', t) = %c\n", wch);
  45. if (wch != L'C')
  46. errors = 1;
  47. /* Test the output digit handling. */
  48. swprintf (wbuf, sizeof (wbuf) / sizeof (wbuf[0]), L"%Id", 0x499602D2);
  49. errors |= wcscmp (wbuf, L"bcdefghija") != 0;
  50. len = wcslen (wbuf);
  51. errors |= len != 10;
  52. printf ("len = %d, wbuf = L\"%ls\"\n", len, wbuf);
  53. snprintf (buf, sizeof buf, "%Id", 0x499602D2);
  54. errors |= strcmp (buf, "bcdefghija") != 0;
  55. len = strlen (buf);
  56. errors |= len != 10;
  57. printf ("len = %d, buf = \"%s\"\n", len, buf);
  58. return errors;
  59. }