Perform string self-tests.
49 {
50
51
54 ok (
strlen (
"Hello world!" ) == 12 );
55 ok (
strlen (
"Hello\0world!" ) == 5 );
56
57
64 ok (
strnlen (
"Hello world!", 5 ) == 5 );
65 ok (
strnlen (
"Hello world!", 11 ) == 11 );
66 ok (
strnlen (
"Hello world!", 16 ) == 12 );
67
68
70 ok ( *(
strchr (
"Testing",
'e' )) ==
'e' );
71 ok ( *(
strchr (
"Testing",
'g' )) ==
'g' );
73 ok ( *(
strchr (
"Testing",
'\0' )) ==
'\0' );
74
75
77 ok ( *(
strrchr (
"Haystack",
'a' )) ==
'a' );
78 ok ( *(
strrchr (
"Haystack",
'k' )) ==
'k' );
80
81
86 ok ( *(
strchrnul (
"Nonstandard",
'\0' )) ==
'\0' );
87
88
93
94
96 ok (
strcmp (
"Hello",
"Hello" ) == 0 );
97 ok (
strcmp (
"Hello",
"hello" ) != 0 );
98 ok (
strcmp (
"Hello",
"Hello world!" ) != 0 );
99 ok (
strcmp (
"Hello world!",
"Hello" ) != 0 );
101
102
105 ok (
strncmp (
"Goodbye",
"Goodbye", 16 ) == 0 );
106 ok (
strncmp (
"Goodbye",
"Hello", 16 ) != 0 );
107 ok (
strncmp (
"Goodbye",
"Goodbye world", 32 ) != 0 );
108 ok (
strncmp (
"Goodbye",
"Goodbye world", 7 ) == 0 );
109
110
116
117
124
125
127 ok (
memcmp (
"Foo",
"Foo", 3 ) == 0 );
128 ok (
memcmp (
"Foo",
"Bar", 3 ) != 0 );
129 ok (
memcmp (
"abc",
"def", 3 ) < 0 );
130
131
132 {
133 const char haystack[] = "find me!";
134 char *found;
135
136 found =
strstr ( haystack,
"find" );
137 ok ( found == &haystack[0] );
138 found =
strstr ( haystack,
"me" );
139 ok ( found == &haystack[5] );
140 found =
strstr ( haystack,
"me." );
142 }
143
144
145 {
146 const char haystack[] = "Find ME!";
147 char *found;
148
150 ok ( found == &haystack[0] );
152 ok ( found == &haystack[5] );
155 }
156
157
158 {
159 static uint8_t test[7] = {
'>', 1, 1, 1, 1, 1,
'<' };
160 static const uint8_t expected[7] = {
'>', 0, 0, 0, 0, 0,
'<' };
163 }
164 {
166 static const uint8_t expected[4] = {
'>', 0xeb, 0xeb,
'<' };
169 }
170
171
172 {
174 { '>', 1, 2, 3, 4, 5, 6, 7, 8, 9, '<' };
175 static const uint8_t expected[11] =
176 { '>', 3, 4, 5, 6, 7, 8, 7, 8, 9, '<' };
179 }
180 {
182 { '>', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, '<' };
183 static const uint8_t expected[12] =
184 { '>', 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, '<' };
187 }
188
189
190 {
192 { '>', 1, 2, 3, 7, 8, 9, '<' };
193 static const uint8_t expected[8] =
194 { '>', 7, 8, 9, 1, 2, 3, '<' };
197 }
198
199
200 {
201 const char *orig = "testing testing";
202 char *dup =
strdup ( orig );
207 }
208
209
210 {
211 const char *
normal =
"testing testing";
212 const char unterminated[6] = { 'h', 'e', 'l', 'l', 'o', '!' };
213 char *dup;
223 dup =
strndup ( unterminated, 5 );
225 ok (
strcmp ( dup,
"hello" ) == 0 );
227 }
228
229
230 {
231 const char longer[12] = "duplicateme";
232 const char shorter[6] = "hello";
234 char *dnul;
235
237 ok ( *dnul ==
'\0' );
241 ok ( *dnul ==
'\0' );
245 }
246
247
248 {
249 const char longer[7] = "copyme";
250 const char shorter[3] = "hi";
252 char *copy;
253
261 }
262
263
264 {
265 const char src[5] =
"copy";
266 const char orig[8] = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' };
267 const char zero[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
269 char *copy;
270
290 }
291
292
293 {
294 char buf[16] = "append";
296
299 ok (
strcmp ( buf,
"append this" ) == 0 );
300 }
301
302
303 {
304 unsigned int i;
305 char buf[2];
306 for ( i = 0 ; i < 16 ; i++ ) {
307 snprintf ( buf,
sizeof ( buf ),
"%x", i );
309 snprintf ( buf,
sizeof ( buf ),
"%X", i );
311 }
320 }
321
322
335 {
336 static const char string[] = "123aHa.world";
337 char *endp;
338 ok (
strtoul (
string, &endp, 0 ) == 123UL );
339 ok ( endp == &
string[3] );
340 ok (
strtoul (
string, &endp, 16 ) == 0x123aUL );
341 ok ( endp == &
string[4] );
343 ( ( ( ( ( 1 * 26 + 2 ) * 26 + 3 ) * 26 + 10 ) * 26
344 + 17 ) * 26 + 10 ) );
345 ok ( endp == &
string[6] );
346 }
347
348
351 ok (
wcslen ( L
"Helloo woorld!" ) == 14 );
352 ok (
wcslen ( L
"Helloo\0woorld!" ) == 6 );
353
354
361 ok (
wcsnlen ( L
"Helloo woorld!", 5 ) == 5 );
362 ok (
wcsnlen ( L
"Helloo woorld!", 11 ) == 11 );
363 ok (
wcsnlen ( L
"Helloo woorld!", 16 ) == 14 );
364}
#define NULL
NULL pointer (VOID *).
struct arbelprm_completion_queue_entry normal
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
void * memmove(void *dest, const void *src, size_t len) __nonnull
static void(* free)(struct refcnt *refcnt))
char * strcat(char *dest, const char *src)
Concatenate string.
void * memswap(void *first, void *second, size_t len)
Swap memory regions.
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
int strcmp(const char *first, const char *second)
Compare strings.
char * strchr(const char *src, int character)
Find character within a string.
int strncasecmp(const char *first, const char *second, size_t max)
Compare case-insensitive strings.
char * strdup(const char *src)
Duplicate string.
void * memchr(const void *src, int character, size_t len)
Find character within a memory region.
char * stpcpy(char *dest, const char *src)
Copy string.
int strncmp(const char *first, const char *second, size_t max)
Compare strings.
size_t strnlen(const char *src, size_t max)
Get length of string.
unsigned int digit_value(unsigned int character)
Calculate digit value.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
char * strndup(const char *src, size_t max)
Duplicate string.
char * strstr(const char *haystack, const char *needle)
Find substring.
char * strrchr(const char *src, int character)
Find rightmost character within a string.
char * strcpy(char *dest, const char *src)
Copy string.
char * strcasestr(const char *haystack, const char *needle)
Find case-insensitive substring.
size_t strlen(const char *src)
Get length of string.
char * strchrnul(const char *src, int character)
Find character within a string, or NUL terminator.
char * strncpy(char *dest, const char *src, size_t max)
Copy string.
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
size_t wcsnlen(const wchar_t *string, size_t max)
Calculate length of wide-character string.
size_t wcslen(const wchar_t *string)
Calculate length of wide-character string.