This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include "c-strstr.h"
22
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "macros.h"
27
28 int
29 main ()
30 {
31 {
32 const char input[] = "foo";
33 const char *result = c_strstr (input, "");
34 ASSERT (result == input);
35 }
36
37 {
38 const char input[] = "foo";
39 const char *result = c_strstr (input, "o");
40 ASSERT (result == input + 1);
41 }
42
43 {
44 const char input[] = "ABC ABCDAB ABCDABCDABDE";
45 const char *result = c_strstr (input, "ABCDABD");
46 ASSERT (result == input + 15);
47 }
48
49 {
50 const char input[] = "ABC ABCDAB ABCDABCDABDE";
51 const char *result = c_strstr (input, "ABCDABE");
52 ASSERT (result == NULL);
53 }
54
55
56
57 {
58 size_t repeat = 10000;
59 size_t m = 1000000;
60 const char *needle =
61 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
62 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
63 char *haystack = (char *) malloc (m + 1);
64 if (haystack != NULL)
65 {
66 memset (haystack, 'A', m);
67 haystack[0] = 'B';
68 haystack[m] = '\0';
69
70 for (; repeat > 0; repeat--)
71 {
72 ASSERT (c_strstr (haystack, needle) == haystack + 1);
73 }
74
75 free (haystack);
76 }
77 }
78
79
80
81 {
82 size_t repeat = 10000;
83 size_t m = 1000000;
84 const char *haystack =
85 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
86 "ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB";
87 char *needle = (char *) malloc (m + 1);
88 if (needle != NULL)
89 {
90 memset (needle, 'A', m);
91 needle[m] = '\0';
92
93 for (; repeat > 0; repeat--)
94 {
95 ASSERT (c_strstr (haystack, needle) == NULL);
96 }
97
98 free (needle);
99 }
100 }
101
102
103 {
104 size_t m = 1000000;
105 char *haystack = (char *) malloc (2 * m + 2);
106 char *needle = (char *) malloc (m + 2);
107 if (haystack != NULL && needle != NULL)
108 {
109 const char *result;
110
111 memset (haystack, 'A', 2 * m);
112 haystack[2 * m] = 'B';
113 haystack[2 * m + 1] = '\0';
114
115 memset (needle, 'A', m);
116 needle[m] = 'B';
117 needle[m + 1] = '\0';
118
119 result = c_strstr (haystack, needle);
120 ASSERT (result == haystack + m);
121 }
122 free (needle);
123 free (haystack);
124 }
125
126 {
127
128
129
130
131 const char *haystack =
132 "\n"
133 "with_build_libsubdir\n"
134 "with_local_prefix\n"
135 "with_gxx_include_dir\n"
136 "with_cpp_install_dir\n"
137 "enable_generated_files_in_srcdir\n"
138 "with_gnu_ld\n"
139 "with_ld\n"
140 "with_demangler_in_ld\n"
141 "with_gnu_as\n"
142 "with_as\n"
143 "enable_largefile\n"
144 "enable_werror_always\n"
145 "enable_checking\n"
146 "enable_coverage\n"
147 "enable_gather_detailed_mem_stats\n"
148 "enable_build_with_cxx\n"
149 "with_stabs\n"
150 "enable_multilib\n"
151 "enable___cxa_atexit\n"
152 "enable_decimal_float\n"
153 "enable_fixed_point\n"
154 "enable_threads\n"
155 "enable_tls\n"
156 "enable_objc_gc\n"
157 "with_dwarf2\n"
158 "enable_shared\n"
159 "with_build_sysroot\n"
160 "with_sysroot\n"
161 "with_specs\n"
162 "with_pkgversion\n"
163 "with_bugurl\n"
164 "enable_languages\n"
165 "with_multilib_list\n";
166 const char *needle = "\n"
167 "with_gnu_ld\n";
168 const char* p = c_strstr (haystack, needle);
169 ASSERT (p - haystack == 114);
170 }
171
172 {
173
174 const char *haystack = "..wi.d.";
175 const char *needle = ".d.";
176 const char* p = c_strstr (haystack, needle);
177 ASSERT (p - haystack == 4);
178 }
179
180 {
181
182
183
184
185
186
187 const char *needle = "\nwith_gnu_ld-extend-to-len-32-b\n";
188 const char *h =
189 "\n"
190 "with_build_libsubdir\n"
191 "with_local_prefix\n"
192 "with_gxx_include_dir\n"
193 "with_cpp_install_dir\n"
194 "with_e_\n"
195 "..............................\n"
196 "with_FGHIJKLMNOPQRSTUVWXYZ\n"
197 "with_567890123456789\n"
198 "with_multilib_list\n";
199 size_t h_len = strlen (h);
200 char *haystack = malloc (h_len + 1);
201 size_t i;
202 ASSERT (haystack);
203 for (i = 0; i < h_len - strlen (needle); i++)
204 {
205 const char *p;
206 memcpy (haystack, h, h_len + 1);
207 memcpy (haystack + i, needle, strlen (needle) + 1);
208 p = c_strstr (haystack, needle);
209 ASSERT (p);
210 ASSERT (p - haystack == i);
211 }
212 free (haystack);
213 }
214
215
216 {
217 size_t m = 1024;
218 char *haystack = (char *) malloc (2 * m + 1);
219 char *needle = (char *) malloc (m + 1);
220 if (haystack != NULL && needle != NULL)
221 {
222 const char *p;
223 haystack[0] = 'x';
224 memset (haystack + 1, ' ', m - 1);
225 memset (haystack + m, 'x', m);
226 haystack[2 * m] = '\0';
227 memset (needle, 'x', m);
228 needle[m] = '\0';
229 p = c_strstr (haystack, needle);
230 ASSERT (p);
231 ASSERT (p - haystack == m);
232 }
233 free (needle);
234 free (haystack);
235 }
236
237 return 0;
238 }