Fix last ChangeLog entry.
[gnulib.git] / tests / test-strncat.c
blob7b2e682a591fdc049e5eab290dd0e5efe5ceaf40
1 /* Test of strncat() function.
2 Copyright (C) 2010-2025 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
19 #include <config.h>
21 #include <string.h>
23 #include "signature.h"
24 SIGNATURE_CHECK (strncat, char *, (char *, const char *, size_t));
26 #include <stdlib.h>
28 #include "zerosize-ptr.h"
29 #include "macros.h"
31 /* Test the library, not the compiler+library. */
32 static char *
33 lib_strncat (char *s1, char const *s2, size_t n)
35 return strncat (s1, s2, n);
37 static char *(*volatile volatile_strncat) (char *, char const *, size_t)
38 = lib_strncat;
39 #undef strncat
40 #define strncat volatile_strncat
42 #define UNIT char
43 #define U_STRNCAT strncat
44 #define MAGIC ((char) 0xBA)
45 #include "unistr/test-strncat.h"
47 int
48 main ()
50 /* Simple string. */
51 { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글"
52 in UTF-8 encoding. */
53 static const char input[] =
54 { 'G', 'r', (char) 0xC3, (char) 0xBC, (char) 0xC3, (char) 0x9F, ' ',
55 'G', 'o', 't', 't', '.', ' ', (char) 0xD0, (char) 0x97, (char) 0xD0,
56 (char) 0xB4, (char) 0xD1, (char) 0x80, (char) 0xD0, (char) 0xB0,
57 (char) 0xD0, (char) 0xB2, (char) 0xD1, (char) 0x81, (char) 0xD1,
58 (char) 0x82, (char) 0xD0, (char) 0xB2, (char) 0xD1, (char) 0x83,
59 (char) 0xD0, (char) 0xB9, (char) 0xD1, (char) 0x82, (char) 0xD0,
60 (char) 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', (char) 0xC2,
61 (char) 0xB1, 's', 'q', 'r', 't', '(', 'b', (char) 0xC2, (char) 0xB2,
62 '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ',
63 (char) 0xE6, (char) 0x97, (char) 0xA5, (char) 0xE6, (char) 0x9C,
64 (char) 0xAC, (char) 0xE8, (char) 0xAA, (char) 0x9E, ',', (char) 0xE4,
65 (char) 0xB8, (char) 0xAD, (char) 0xE6, (char) 0x96, (char) 0x87, ',',
66 (char) 0xED, (char) 0x95, (char) 0x9C, (char) 0xEA, (char) 0xB8,
67 (char) 0x80, '\0'
69 check (input, SIZEOF (input));
72 /* Test zero-length operations on NULL pointers, allowed by
73 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>. */
75 #if 0 /* I think this is invalid, per ISO C 23 § 7.26.3.2. */
76 ASSERT (strncat (NULL, "x", 0) == NULL);
77 #endif
80 char y[2] = { 'x', '\0' };
81 ASSERT (strncat (y, NULL, 0) == y);
84 return test_exit_status;