Add test of strnlen().
This commit is contained in:
@@ -160,6 +160,7 @@ EXELIST_c64 = \
|
|||||||
scanf-test \
|
scanf-test \
|
||||||
ser-test \
|
ser-test \
|
||||||
strdup-test \
|
strdup-test \
|
||||||
|
strnlen \
|
||||||
stroserror-test \
|
stroserror-test \
|
||||||
strqtok-test \
|
strqtok-test \
|
||||||
tinyshell \
|
tinyshell \
|
||||||
@@ -190,6 +191,7 @@ EXELIST_vic20 = \
|
|||||||
rename-test \
|
rename-test \
|
||||||
scanf-test \
|
scanf-test \
|
||||||
strdup-test \
|
strdup-test \
|
||||||
|
strnlen \
|
||||||
stroserror-test \
|
stroserror-test \
|
||||||
strqtok-test \
|
strqtok-test \
|
||||||
tinyshell \
|
tinyshell \
|
||||||
@@ -222,6 +224,7 @@ EXELIST_apple2 = \
|
|||||||
seek \
|
seek \
|
||||||
ser-test \
|
ser-test \
|
||||||
strdup-test \
|
strdup-test \
|
||||||
|
strnlen \
|
||||||
stroserror-test \
|
stroserror-test \
|
||||||
strqtok-test \
|
strqtok-test \
|
||||||
tinyshell \
|
tinyshell \
|
||||||
@@ -257,6 +260,7 @@ EXELIST_atari = \
|
|||||||
seek \
|
seek \
|
||||||
ser-test \
|
ser-test \
|
||||||
strdup-test \
|
strdup-test \
|
||||||
|
strnlen \
|
||||||
stroserror-test \
|
stroserror-test \
|
||||||
strqtok-test \
|
strqtok-test \
|
||||||
tinyshell \
|
tinyshell \
|
||||||
|
|||||||
32
targettest/strnlen.c
Normal file
32
targettest/strnlen.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
const char * str = "0123456789";
|
||||||
|
|
||||||
|
void
|
||||||
|
check (size_t result, size_t expected)
|
||||||
|
{
|
||||||
|
if (result != expected) {
|
||||||
|
printf ("Expected strnlen() to return %d, got %d.\n",
|
||||||
|
expected, result);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (void)
|
||||||
|
{
|
||||||
|
size_t maxlen = strlen (str);
|
||||||
|
size_t result;
|
||||||
|
size_t expected;
|
||||||
|
|
||||||
|
for (expected = 0; expected < maxlen; expected++)
|
||||||
|
check (strnlen (str, expected), expected);
|
||||||
|
|
||||||
|
check (strnlen (str, maxlen << 1), maxlen);
|
||||||
|
|
||||||
|
printf ("strnlen() OK.\n");
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user