From: Bruno Haible Date: Mon, 2 Jun 2025 21:44:55 +0000 (+0200) Subject: stdcountof-h: Add tests. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b239ab56fd3b79acf1f1326c4fe7383362fc99d;p=thirdparty%2Fgnulib.git stdcountof-h: Add tests. * tests/test-stdcountof-h.c: New file. * tests/test-stdcountof-h-c++.cc: New file. * modules/stdcountof-h-tests: New file. * modules/stdcountof-h-c++-tests: New file. --- diff --git a/ChangeLog b/ChangeLog index 3c05726d95..7f50173924 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2025-06-02 Bruno Haible + stdcountof-h: Add tests. + * tests/test-stdcountof-h.c: New file. + * tests/test-stdcountof-h-c++.cc: New file. + * modules/stdcountof-h-tests: New file. + * modules/stdcountof-h-c++-tests: New file. + stdcountof-h: New module. * lib/stdcountof.in.h: New file. * m4/stdcountof_h.m4: New file. diff --git a/modules/stdcountof-h-c++-tests b/modules/stdcountof-h-c++-tests new file mode 100644 index 0000000000..e0d2638cfe --- /dev/null +++ b/modules/stdcountof-h-c++-tests @@ -0,0 +1,17 @@ +Files: +tests/test-stdcountof-h-c++.cc + +Status: +c++-test + +Depends-on: +ansi-c++-opt + +configure.ac: + +Makefile.am: +if ANSICXX +TESTS += test-stdcountof-h-c++ +check_PROGRAMS += test-stdcountof-h-c++ +test_stdcountof_h_c___SOURCES = test-stdcountof-h-c++.cc +endif diff --git a/modules/stdcountof-h-tests b/modules/stdcountof-h-tests new file mode 100644 index 0000000000..8024a999a9 --- /dev/null +++ b/modules/stdcountof-h-tests @@ -0,0 +1,12 @@ +Files: +tests/test-stdcountof-h.c +tests/macros.h + +Depends-on: +stdcountof-h-c++-tests + +configure.ac: + +Makefile.am: +TESTS += test-stdcountof-h +check_PROGRAMS += test-stdcountof-h diff --git a/tests/test-stdcountof-h-c++.cc b/tests/test-stdcountof-h-c++.cc new file mode 100644 index 0000000000..55ef7e6818 --- /dev/null +++ b/tests/test-stdcountof-h-c++.cc @@ -0,0 +1,17 @@ +/* Test in C++ mode. + Copyright 2025 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-stdcountof-h.c" diff --git a/tests/test-stdcountof-h.c b/tests/test-stdcountof-h.c new file mode 100644 index 0000000000..619a666186 --- /dev/null +++ b/tests/test-stdcountof-h.c @@ -0,0 +1,60 @@ +/* Test . + Copyright 2025 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 + +#include + +#include "macros.h" + +extern int integer; +extern int unbounded[]; +extern int bounded[10]; +extern int multidimensional[10][20]; + +static void +test_func (int parameter[3]) +{ + int local_bounded[20]; + + (void) local_bounded; + + (void) _gl_verify_is_array (unbounded); + (void) _gl_verify_is_array (bounded); + (void) _gl_verify_is_array (multidimensional); + + ASSERT (countof (bounded) == 10); + ASSERT (countof (multidimensional) == 10); + ASSERT (countof (local_bounded) == 20); + +#if 0 /* These produce compilation errors. */ + (void) _gl_verify_is_array (integer); + (void) _gl_verify_is_array (parameter); + + ASSERT (countof (integer) >= 0); + ASSERT (countof (unbounded) >= 0); +#endif +} + +int +main () +{ + int x[3]; + + test_func (x); + + return test_exit_status; +}