annotate tests/unistr/test-strncat.h @ 40057:b06060465f09

maint: Run 'make update-copyright'
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 01 Jan 2019 00:25:11 +0100
parents 10eb9086bea0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12708
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of uN_strncat() functions.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2010-2019 Free Software Foundation, Inc.
12708
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
12708
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 static void
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 check_single (const UNIT *input, size_t length, size_t n)
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 {
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 static const UNIT base[] = { 'C', 'h', 'a', 'n', 'g', 'i', 'n', 'g', 0 };
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 size_t m;
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 for (m = 0; m < SIZEOF (base); m++)
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 {
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 UNIT *dest;
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 UNIT *result;
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 size_t i;
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 dest = (UNIT *) malloc ((1 + m + n + 2) * sizeof (UNIT));
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 ASSERT (dest != NULL);
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 dest[0] = MAGIC;
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 for (i = 0; i < m; i++)
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 dest[1 + i] = base[i];
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 dest[1 + m] = 0;
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 for (i = 1; i < n + 2; i++)
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 dest[1 + m + i] = MAGIC;
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 result = U_STRNCAT (dest + 1, input, n);
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 ASSERT (result == dest + 1);
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 ASSERT (dest[0] == MAGIC);
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 for (i = 0; i < m; i++)
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 ASSERT (dest[1 + i] == base[i]);
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 for (i = 0; i < (n <= length ? n : length); i++)
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 ASSERT (dest[1 + m + i] == input[i]);
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 ASSERT (dest[1 + m + i] == 0);
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 ASSERT (dest[1 + m + i + 1] == MAGIC);
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 free (dest);
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 }
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 }
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 static void
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 check (const UNIT *input, size_t input_length)
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 {
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 size_t length;
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 size_t n;
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 ASSERT (input_length > 0);
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 ASSERT (input[input_length - 1] == 0);
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 length = input_length - 1; /* = U_STRLEN (input) */
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 for (n = 0; n <= 2 * length + 2; n++)
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 check_single (input, length, n);
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 /* Check that U_STRNCAT (D, S, N) does not look at more than
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 MIN (U_STRLEN (S) + 1, N) units. */
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 {
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 char *page_boundary = (char *) zerosize_ptr ();
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 if (page_boundary != NULL)
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 {
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 for (n = 0; n <= 2 * length + 2; n++)
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 {
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 size_t n_to_copy = (n <= length ? n : length + 1);
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 UNIT *copy;
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 size_t i;
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 copy = (UNIT *) page_boundary - n_to_copy;
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 for (i = 0; i < n_to_copy; i++)
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 copy[i] = input[i];
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 check_single (copy, length, n);
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 }
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 }
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 }
c3306b011528 Tests for module 'unistr/u8-strncat'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 }