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
74
76 ok ( *(
strrchr (
"Haystack",
'a' )) ==
'a' );
77 ok ( *(
strrchr (
"Haystack",
'k' )) ==
'k' );
79
80
85
86
88 ok (
strcmp (
"Hello",
"Hello" ) == 0 );
89 ok (
strcmp (
"Hello",
"hello" ) != 0 );
90 ok (
strcmp (
"Hello",
"Hello world!" ) != 0 );
91 ok (
strcmp (
"Hello world!",
"Hello" ) != 0 );
93
94
97 ok (
strncmp (
"Goodbye",
"Goodbye", 16 ) == 0 );
98 ok (
strncmp (
"Goodbye",
"Hello", 16 ) != 0 );
99 ok (
strncmp (
"Goodbye",
"Goodbye world", 32 ) != 0 );
100 ok (
strncmp (
"Goodbye",
"Goodbye world", 7 ) == 0 );
101
102
108
109
116
117
119 ok (
memcmp (
"Foo",
"Foo", 3 ) == 0 );
120 ok (
memcmp (
"Foo",
"Bar", 3 ) != 0 );
121 ok (
memcmp (
"abc",
"def", 3 ) < 0 );
122
123
124 {
125 const char haystack[] = "find me!";
126 char *found;
127
128 found =
strstr ( haystack,
"find" );
129 ok ( found == &haystack[0] );
130 found =
strstr ( haystack,
"me" );
131 ok ( found == &haystack[5] );
132 found =
strstr ( haystack,
"me." );
134 }
135
136
137 {
138 static uint8_t test[7] = {
'>', 1, 1, 1, 1, 1,
'<' };
139 static const uint8_t expected[7] = {
'>', 0, 0, 0, 0, 0,
'<' };
142 }
143 {
145 static const uint8_t expected[4] = {
'>', 0xeb, 0xeb,
'<' };
148 }
149
150
151 {
153 { '>', 1, 2, 3, 4, 5, 6, 7, 8, 9, '<' };
154 static const uint8_t expected[11] =
155 { '>', 3, 4, 5, 6, 7, 8, 7, 8, 9, '<' };
158 }
159 {
161 { '>', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, '<' };
162 static const uint8_t expected[12] =
163 { '>', 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, '<' };
166 }
167
168
169 {
171 { '>', 1, 2, 3, 7, 8, 9, '<' };
172 static const uint8_t expected[8] =
173 { '>', 7, 8, 9, 1, 2, 3, '<' };
176 }
177
178
179 {
180 const char *orig = "testing testing";
181 char *dup =
strdup ( orig );
186 }
187
188
189 {
190 const char *
normal =
"testing testing";
191 const char unterminated[6] = { 'h', 'e', 'l', 'l', 'o', '!' };
192 char *dup;
202 dup =
strndup ( unterminated, 5 );
204 ok (
strcmp ( dup,
"hello" ) == 0 );
206 }
207
208
209 {
210 const char longer[12] = "duplicateme";
211 const char shorter[6] = "hello";
213 char *dnul;
214
216 ok ( *dnul ==
'\0' );
220 ok ( *dnul ==
'\0' );
224 }
225
226
227 {
228 const char longer[7] = "copyme";
229 const char shorter[3] = "hi";
231 char *copy;
232
240 }
241
242
243 {
244 const char src[5] =
"copy";
245 const char orig[8] = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' };
246 const char zero[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
248 char *copy;
249
269 }
270
271
272 {
273 char buf[16] = "append";
275
278 ok (
strcmp ( buf,
"append this" ) == 0 );
279 }
280
281
282 {
283 unsigned int i;
284 char buf[2];
285 for ( i = 0 ; i < 16 ; i++ ) {
286 snprintf ( buf,
sizeof ( buf ),
"%x", i );
288 snprintf ( buf,
sizeof ( buf ),
"%X", i );
290 }
299 }
300
301
314 {
315 static const char string[] = "123aHa.world";
316 char *endp;
317 ok (
strtoul (
string, &endp, 0 ) == 123UL );
318 ok ( endp == &
string[3] );
319 ok (
strtoul (
string, &endp, 16 ) == 0x123aUL );
320 ok ( endp == &
string[4] );
322 ( ( ( ( ( 1 * 26 + 2 ) * 26 + 3 ) * 26 + 10 ) * 26
323 + 17 ) * 26 + 10 ) );
324 ok ( endp == &
string[6] );
325 }
326
327
330 ok (
wcslen ( L
"Helloo woorld!" ) == 14 );
331 ok (
wcslen ( L
"Helloo\0woorld!" ) == 6 );
332
333
340 ok (
wcsnlen ( L
"Helloo woorld!", 5 ) == 5 );
341 ok (
wcsnlen ( L
"Helloo woorld!", 11 ) == 11 );
342 ok (
wcsnlen ( L
"Helloo woorld!", 16 ) == 14 );
343}
#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.
size_t strlen(const char *src)
Get length of string.
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.