From 70c869be3fcd5da3813a73520dc6bf5b91d68afd Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 5 Oct 2023 18:02:26 +0200 Subject: [PATCH] xstrerror: Add tests. * tests/test-xstrerror.c: New file. * modules/xstrerror-tests: New file. --- ChangeLog | 4 ++++ modules/xstrerror-tests | 12 +++++++++++ tests/test-xstrerror.c | 45 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 modules/xstrerror-tests create mode 100644 tests/test-xstrerror.c diff --git a/ChangeLog b/ChangeLog index b8aefaf222..6df9aaaef7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2023-10-05 Bruno Haible + xstrerror: Add tests. + * tests/test-xstrerror.c: New file. + * modules/xstrerror-tests: New file. + xstrerror: New module. * lib/xstrerror.h: New file. * lib/xstrerror.c: New file. diff --git a/modules/xstrerror-tests b/modules/xstrerror-tests new file mode 100644 index 0000000000..24a5fc9a10 --- /dev/null +++ b/modules/xstrerror-tests @@ -0,0 +1,12 @@ +Files: +tests/test-xstrerror.c +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-xstrerror +check_PROGRAMS += test-xstrerror +test_xstrerror_LDADD = $(LDADD) $(LIBINTL) diff --git a/tests/test-xstrerror.c b/tests/test-xstrerror.c new file mode 100644 index 0000000000..d725aa1c94 --- /dev/null +++ b/tests/test-xstrerror.c @@ -0,0 +1,45 @@ +/* Test of xstrerror function. + Copyright (C) 2023 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2023. */ + +#include + +#include "xstrerror.h" + +#include +#include +#include + +#include "macros.h" + +int +main () +{ + /* Test in the "C" locale. */ + { + char *s = xstrerror ("can't steal", EACCES); + ASSERT (strcmp (s, "can't steal: Permission denied") == 0); + free (s); + } + { + char *s = xstrerror (NULL, EACCES); + ASSERT (strcmp (s, "Permission denied") == 0); + free (s); + } + + return 0; +} -- 2.39.5