]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
stdcountof-h: Add tests.
authorBruno Haible <bruno@clisp.org>
Mon, 2 Jun 2025 21:44:55 +0000 (23:44 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 2 Jun 2025 21:44:55 +0000 (23:44 +0200)
* 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.

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

index 3c05726d954f89d7097259b6f4149c1ca1e8b64f..7f5017392493f343d98b8f3a5b3aeae4928144d0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2025-06-02  Bruno Haible  <bruno@clisp.org>
 
+       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 (file)
index 0000000..e0d2638
--- /dev/null
@@ -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 (file)
index 0000000..8024a99
--- /dev/null
@@ -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 (file)
index 0000000..55ef7e6
--- /dev/null
@@ -0,0 +1,17 @@
+/* Test <stdcountof.h> 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 <https://www.gnu.org/licenses/>.  */
+
+#include "test-stdcountof-h.c"
diff --git a/tests/test-stdcountof-h.c b/tests/test-stdcountof-h.c
new file mode 100644 (file)
index 0000000..619a666
--- /dev/null
@@ -0,0 +1,60 @@
+/* Test <stdcountof.h>.
+   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 <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <stdcountof.h>
+
+#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;
+}