]> Savannah Git Hosting - gnulib.git/commitdiff
wcsncat tests: Verify N3322 functionality.
authorBruno Haible <bruno@clisp.org>
Tue, 5 Nov 2024 20:11:39 +0000 (21:11 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 5 Nov 2024 21:38:48 +0000 (22:38 +0100)
* tests/test-wcsncat.c: New file.
* modules/wcsncat-tests: New file.

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

index c019e77f02cf6084157c697b92614d48941d9a16..0bb5d71f7913c886d9a5a36623b7c998c8d60f99 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2024-11-05  Bruno Haible  <bruno@clisp.org>
 
+       wcsncat tests: Verify N3322 functionality.
+       * tests/test-wcsncat.c: New file.
+       * modules/wcsncat-tests: New file.
+
        wcsncat: Guarantee N3322 functionality.
        * lib/wchar.in.h (wcsncat): Consider REPLACE_WCSNCAT.
        * m4/wcsncat.m4 (gl_FUNC_WCSNCAT): Test whether the zero-length bug is
diff --git a/modules/wcsncat-tests b/modules/wcsncat-tests
new file mode 100644 (file)
index 0000000..d498dad
--- /dev/null
@@ -0,0 +1,11 @@
+Files:
+tests/test-wcsncat.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-wcsncat
+check_PROGRAMS += test-wcsncat
diff --git a/tests/test-wcsncat.c b/tests/test-wcsncat.c
new file mode 100644 (file)
index 0000000..b8479df
--- /dev/null
@@ -0,0 +1,48 @@
+/* Test of wcsncat() function.
+   Copyright (C) 2010-2024 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/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2024.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <wchar.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main ()
+{
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+#if 0 /* I think this is invalid, per ISO C 23 ยง 7.31.4.3.2.  */
+  value = (wcsncat (NULL, L"x", 0) == NULL);
+  ASSERT (value);
+#endif
+
+  {
+    wchar_t y[1];
+    value = (wcsncat (y, NULL, 0) == y);
+    ASSERT (value);
+  }
+
+  return test_exit_status;
+}