* tests/test-strnul.c: New file.
* tests/test-strnul-c++.cc: New file.
* modules/strnul-tests: New file.
* modules/strnul-c++-tests: New file.
2026-02-21 Bruno Haible <bruno@clisp.org>
+ strnul: Add tests.
+ * tests/test-strnul.c: New file.
+ * tests/test-strnul-c++.cc: New file.
+ * modules/strnul-tests: New file.
+ * modules/strnul-c++-tests: New file.
+
strnul: New module.
Suggested by Alejandro Colomar <alx@kernel.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2026-02/msg00121.html>.
--- /dev/null
+Files:
+tests/test-strnul-c++.cc
+
+Status:
+c++-test
+
+Depends-on:
+ansi-c++-opt
+
+configure.ac:
+
+Makefile.am:
+if ANSICXX
+TESTS += test-strnul-c++
+check_PROGRAMS += test-strnul-c++
+test_strnul_c___SOURCES = test-strnul-c++.cc
+endif
--- /dev/null
+Files:
+tests/test-strnul.c
+tests/macros.h
+
+Depends-on:
+strnul-c++-tests
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-strnul
+check_PROGRAMS += test-strnul
--- /dev/null
+/* Test of strnul() function in C++ mode.
+ Copyright (C) 2026 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 <https://www.gnu.org/licenses/>. */
+
+#include "test-strnul.c"
--- /dev/null
+/* Test of strnul() function.
+ Copyright (C) 2026 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 <https://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <string.h>
+
+#include "macros.h"
+
+int
+main ()
+{
+ const char ro[] = "foo";
+ char rw[] = "foo";
+
+ const char *ro_nul = strnul (ro);
+ char *rw_nul = strnul (rw);
+
+ ASSERT (ro_nul - ro == 3);
+ ASSERT (rw_nul - rw == 3);
+
+ return test_exit_status;
+}