]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
strnul: Add tests.
authorBruno Haible <bruno@clisp.org>
Sat, 21 Feb 2026 09:28:11 +0000 (10:28 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 21 Feb 2026 09:28:11 +0000 (10:28 +0100)
* tests/test-strnul.c: New file.
* tests/test-strnul-c++.cc: New file.
* modules/strnul-tests: New file.
* modules/strnul-c++-tests: New file.

ChangeLog
modules/strnul-c++-tests [new file with mode: 0644]
modules/strnul-tests [new file with mode: 0644]
tests/test-strnul-c++.cc [new file with mode: 0644]
tests/test-strnul.c [new file with mode: 0644]

index 749d269dc1ac3d5af3d5d2925ba39f9837d0f107..7681ab4c5d88f09093c4b032fd27d6965da64fea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 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>.
diff --git a/modules/strnul-c++-tests b/modules/strnul-c++-tests
new file mode 100644 (file)
index 0000000..2931df1
--- /dev/null
@@ -0,0 +1,17 @@
+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
diff --git a/modules/strnul-tests b/modules/strnul-tests
new file mode 100644 (file)
index 0000000..3d46b34
--- /dev/null
@@ -0,0 +1,12 @@
+Files:
+tests/test-strnul.c
+tests/macros.h
+
+Depends-on:
+strnul-c++-tests
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-strnul
+check_PROGRAMS += test-strnul
diff --git a/tests/test-strnul-c++.cc b/tests/test-strnul-c++.cc
new file mode 100644 (file)
index 0000000..3e6f19c
--- /dev/null
@@ -0,0 +1,17 @@
+/* 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"
diff --git a/tests/test-strnul.c b/tests/test-strnul.c
new file mode 100644 (file)
index 0000000..b9b4970
--- /dev/null
@@ -0,0 +1,37 @@
+/* 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;
+}