annotate tests/unistr/test-strchr.h @ 40224:5d9b82ca550a

tests: Free allocated memory. Reported by <deltatau@protonmail.com> via Assaf Gordon. * tests/test-astrxfrm.c (main): Free allocated memory. * tests/test-bitset.c (compare, check_attributes): Free allocated bitsets. * tests/test-filenamecat.c (main): Free allocated memory. * tests/test-freadahead.c (main): Free allocated memory and close stdin. * tests/test-freadptr.c (main): Likewise. * tests/test-freadptr2.c (main): Free allocated memory. * tests/test-freadseek.c (main): Likewise. * tests/test-gc-arcfour.c (main): Close allocated context. * tests/test-gc-arctwo.c (main): Likewise. * tests/test-gc-des.c (main): Close all allocated contexts. * tests/test-pipe-filter-gi1.c (main): Free allocated memory. * tests/test-pipe-filter-ii1.c (main): Likewise. * tests/test-posix_spawn_file_actions_addchdir.c (main): Destroy the allocated file actions. * tests/test-posix_spawn_file_actions_addclose.c (main): Likewise. * tests/test-posix_spawn_file_actions_adddup2.c (main): Likewise. * tests/test-posix_spawn_file_actions_addopen.c (main): Likewise. * tests/test-sameacls.c (main): Free allocated memory and ACLs. * tests/test-strfmon_l.c (main): Free allocated locales. * tests/test-striconveh.c (main): Free allocated iconv_t objects. * tests/uniconv/test-u8-conv-to-enc.c (main): Free allocated memory. * tests/uniconv/test-u16-conv-to-enc.c (main): Likewise. * tests/uniconv/test-u32-conv-to-enc.c (main): Likewise. * tests/unistr/test-chr.h (main): Free input32. * tests/unistr/test-strchr.h (test_strchr): Likewise.
author Bruno Haible <bruno@clisp.org>
date Sun, 10 Mar 2019 14:05:09 +0100
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13520
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
1 /* Test of uN_strchr() functions.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2008-2019 Free Software Foundation, Inc.
13474
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
3
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
7 (at your option) any later version.
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
8
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
12 GNU General Public License for more details.
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
13
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
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/>. */
13474
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
16
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
17 /* Written by Paolo Bonzini <bonzini@gnu.org>, 2010.
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
18 Based on test-chr.h, by Eric Blake and Bruno Haible. */
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
19
13520
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
20 static void
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
21 test_strchr (void)
13474
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
22 {
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
23 size_t size = 0x100000;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
24 size_t length;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
25 size_t i;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
26 UNIT *input;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
27 uint32_t *input32 = (uint32_t *) malloc ((size + 1) * sizeof (uint32_t));
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
28 ASSERT (input32);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
29
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
30 input32[0] = 'a';
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
31 input32[1] = 'b';
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
32 u32_set (input32 + 2, 'c', 1024);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
33 for (i = 1026; i < size - 2; i += 63)
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
34 {
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
35 size_t last = i + 63 < size - 2 ? i + 63 : size - 2;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
36 ucs4_t uc = 'd' | (i - 1026);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
37 if (uc >= 0xd800 && uc <= 0xdfff)
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
38 uc |= 0x100000;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
39 u32_set (input32 + i, uc, last - i);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
40 }
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
41 input32[size - 2] = 'e';
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
42 input32[size - 1] = 'a';
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
43 input32[size] = 0;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
44
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
45 input = U32_TO_U (input32, size + 1, NULL, &length);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
46 ASSERT (input);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
47
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
48 /* Basic behavior tests. */
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
49 ASSERT (U_STRCHR (input, 'a') == input);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
50 ASSERT (U_STRCHR (input, 'b') == input + 1);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
51 ASSERT (U_STRCHR (input, 'c') == input + 2);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
52
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
53 {
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
54 UNIT *exp = input + 1026;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
55 UNIT *prev = input + 2;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
56
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
57 for (i = 1026; i < size - 2; i += 63)
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
58 {
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
59 UNIT c[6];
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
60 size_t n;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
61 ucs4_t uc = 'd' | (i - 1026);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
62 if (uc >= 0xd800 && uc <= 0xdfff)
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
63 uc |= 0x100000;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
64 n = U_UCTOMB (c, uc, 6);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
65 ASSERT (exp < input + length - 2);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
66 ASSERT (U_STRCHR (prev, uc) == exp);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
67 ASSERT (memcmp (exp, c, n * sizeof (UNIT)) == 0);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
68 prev = exp;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
69 exp += n * 63;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
70 }
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
71 }
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
72
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
73 ASSERT (U_STRCHR (input + 1, 'a') == input + length - 2);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
74 ASSERT (U_STRCHR (input + 1, 'e') == input + length - 3);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
75
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
76 ASSERT (U_STRCHR (input, 'f') == NULL);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
77 ASSERT (U_STRCHR (input, '\0') == input + length - 1);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
78
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
79 /* Check that a very long haystack is handled quickly if the byte is
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
80 found near the beginning. */
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
81 {
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
82 size_t repeat = 10000;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
83 for (; repeat > 0; repeat--)
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
84 {
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
85 ASSERT (U_STRCHR (input, 'c') == input + 2);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
86 }
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
87 }
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
88
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
89 /* Alignment tests. */
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
90 {
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
91 int i, j;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
92 for (i = 0; i < 32; i++)
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
93 {
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
94 for (j = 0; j < 127; j++)
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
95 input[i + j] = j + 1;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
96 input[i + 128] = 0;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
97 for (j = 0; j < 127; j++)
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
98 {
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
99 ASSERT (U_STRCHR (input + i, j + 1) == input + i + j);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
100 }
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
101 }
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
102 }
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
103
13520
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
104 /* Check that uN_strchr() does not read past the end of the string. */
13474
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
105 {
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
106 char *page_boundary = (char *) zerosize_ptr ();
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
107 size_t n;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
108
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
109 if (page_boundary != NULL)
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
110 {
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
111 for (n = 2; n <= 500 / sizeof (UNIT); n++)
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
112 {
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
113 UNIT *mem = (UNIT *) (page_boundary - n * sizeof (UNIT));
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
114 U_SET (mem, 'X', n - 2);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
115 mem[n - 2] = 0;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
116 ASSERT (U_STRCHR (mem, 'U') == NULL);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
117 mem[n - 2] = 'X';
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
118 mem[n - 1] = 0;
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
119 ASSERT (U_STRCHR (mem, 'U') == NULL);
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
120 }
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
121 }
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
122 }
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
123
13726
254f2b4bf21a unistr/u8-strchr: Fix a test failure on i586 glibc systems.
Bruno Haible <bruno@clisp.org>
parents: 13520
diff changeset
124 #if 0
254f2b4bf21a unistr/u8-strchr: Fix a test failure on i586 glibc systems.
Bruno Haible <bruno@clisp.org>
parents: 13520
diff changeset
125 /* This check is disabled, because uN_strchr() is allowed to read past the
254f2b4bf21a unistr/u8-strchr: Fix a test failure on i586 glibc systems.
Bruno Haible <bruno@clisp.org>
parents: 13520
diff changeset
126 first occurrence of the byte being searched. In fact, u8_strchr() does
254f2b4bf21a unistr/u8-strchr: Fix a test failure on i586 glibc systems.
Bruno Haible <bruno@clisp.org>
parents: 13520
diff changeset
127 so, on i586 glibc systems: u8_strchr calls strchr, which in
254f2b4bf21a unistr/u8-strchr: Fix a test failure on i586 glibc systems.
Bruno Haible <bruno@clisp.org>
parents: 13520
diff changeset
128 glibc/sysdeps/i386/i586/strchr.S loads the second word before the
254f2b4bf21a unistr/u8-strchr: Fix a test failure on i586 glibc systems.
Bruno Haible <bruno@clisp.org>
parents: 13520
diff changeset
129 handling of the first word has been completed. */
13520
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
130 /* Check that uN_strchr() does not read past the first occurrence of the
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
131 byte being searched. */
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
132 {
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
133 char *page_boundary = (char *) zerosize_ptr ();
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
134 size_t n;
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
135
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
136 if (page_boundary != NULL)
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
137 {
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
138 for (n = 2; n <= 500 / sizeof (UNIT); n++)
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
139 {
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
140 UNIT *mem = (UNIT *) (page_boundary - n * sizeof (UNIT));
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
141 U_SET (mem, 'X', n - 1);
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
142 mem[n - 1] = 0;
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
143 ASSERT (U_STRCHR (mem, 'U') == NULL);
13474
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
144
13520
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
145 {
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
146 size_t i;
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
147
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
148 for (i = 0; i < n; i++)
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
149 {
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
150 mem[i] = 'U';
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
151 ASSERT (U_STRCHR (mem, 'U') == mem + i);
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
152 mem[i] = 'X';
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
153 }
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
154 }
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
155 }
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
156 }
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
157 }
13726
254f2b4bf21a unistr/u8-strchr: Fix a test failure on i586 glibc systems.
Bruno Haible <bruno@clisp.org>
parents: 13520
diff changeset
158 #endif
13520
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
159
1d091087ce86 More tests for unistr/u8-strchr.
Bruno Haible <bruno@clisp.org>
parents: 13474
diff changeset
160 free (input);
40224
5d9b82ca550a tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
161 if (sizeof (UNIT) != sizeof (uint32_t))
5d9b82ca550a tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
162 free (input32);
13474
e88b0c7d0f85 unistr/u*-strchr: add tests
Paolo Bonzini <pbonzini@redhat.com>
parents:
diff changeset
163 }