From a366348be2d8859a86d40eff43a588a4ee0cbd88 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 5 Nov 2024 21:11:39 +0100 Subject: [PATCH 19/23] wcsncat tests: Verify N3322 functionality. * tests/test-wcsncat.c: New file. * modules/wcsncat-tests: New file. --- ChangeLog | 4 ++++ modules/wcsncat-tests | 11 ++++++++++ tests/test-wcsncat.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 modules/wcsncat-tests create mode 100644 tests/test-wcsncat.c diff --git a/ChangeLog b/ChangeLog index c019e77f02..0bb5d71f79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2024-11-05 Bruno Haible + 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 index 0000000000..d498dade80 --- /dev/null +++ b/modules/wcsncat-tests @@ -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 index 0000000000..b8479dfb5e --- /dev/null +++ b/tests/test-wcsncat.c @@ -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 . */ + +/* Written by Bruno Haible , 2024. */ + +#include + +/* Specification. */ +#include + +#include + +#include "macros.h" + +int +main () +{ + int volatile value; + + /* Test zero-length operations on NULL pointers, allowed by + . */ + +#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; +} -- 2.34.1