From: Bruno Haible Date: Sat, 21 Feb 2026 09:28:11 +0000 (+0100) Subject: strnul: Add tests. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e87eaccbb996d00d6482dc259b2937a4ab24d9b;p=thirdparty%2Fgnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 749d269dc1..7681ab4c5d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2026-02-21 Bruno Haible + 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 in . diff --git a/modules/strnul-c++-tests b/modules/strnul-c++-tests new file mode 100644 index 0000000000..2931df1cf1 --- /dev/null +++ b/modules/strnul-c++-tests @@ -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 index 0000000000..3d46b34a83 --- /dev/null +++ b/modules/strnul-tests @@ -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 index 0000000000..3e6f19c33d --- /dev/null +++ b/tests/test-strnul-c++.cc @@ -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 . */ + +#include "test-strnul.c" diff --git a/tests/test-strnul.c b/tests/test-strnul.c new file mode 100644 index 0000000000..b9b4970ad6 --- /dev/null +++ b/tests/test-strnul.c @@ -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 . */ + +#include + +/* Specification. */ +#include + +#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; +}