tst-strerror.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Test for strerror, strerror_r, and strerror_l.
  2. Copyright (C) 2020-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <string.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <errno.h>
  19. #include <locale.h>
  20. #include <array_length.h>
  21. #include <support/support.h>
  22. #include <support/check.h>
  23. static int
  24. do_test (void)
  25. {
  26. unsetenv ("LANGUAGE");
  27. xsetlocale (LC_ALL, "C");
  28. TEST_COMPARE_STRING (strerror (EINVAL), "Invalid argument");
  29. TEST_COMPARE_STRING (strerror (-1), "Unknown error -1");
  30. {
  31. char buffer[32];
  32. TEST_COMPARE_STRING (strerror_r (EINVAL, buffer, 8),
  33. "Invalid argument");
  34. TEST_COMPARE_STRING (strerror_r (-1, buffer, 8),
  35. "Unknown");
  36. TEST_COMPARE_STRING (strerror_r (-1, buffer, 16),
  37. "Unknown error -");
  38. TEST_COMPARE_STRING (strerror_r (-1, buffer, 32),
  39. "Unknown error -1");
  40. }
  41. locale_t l = xnewlocale (LC_ALL_MASK, "pt_BR.UTF-8", NULL);
  42. TEST_COMPARE_STRING (strerror_l (EINVAL, l), "Argumento inv\303\241lido");
  43. TEST_COMPARE_STRING (strerror_l (-1, l), "Erro desconhecido -1");
  44. xuselocale (l);
  45. TEST_COMPARE_STRING (strerror (EINVAL), "Argumento inv\303\241lido");
  46. TEST_COMPARE_STRING (strerror (-1), "Erro desconhecido -1");
  47. {
  48. char buffer[32];
  49. TEST_COMPARE_STRING (strerror_r (EINVAL, buffer, 8),
  50. "Argumento inv\303\241lido");
  51. TEST_COMPARE_STRING (strerror_r (-1, buffer, 8),
  52. "Erro de");
  53. TEST_COMPARE_STRING (strerror_r (-1, buffer, 16),
  54. "Erro desconheci");
  55. TEST_COMPARE_STRING (strerror_r (-1, buffer, 32),
  56. "Erro desconhecido -1");
  57. }
  58. freelocale (l);
  59. return 0;
  60. }
  61. #include <support/test-driver.c>