34 lines
682 B
C
34 lines
682 B
C
#include <assert.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int main(void) {
|
|
/* memcpy */
|
|
char src[] = "hello world";
|
|
char dst[64];
|
|
memcpy(dst, src, 12);
|
|
dst[12] = 0;
|
|
assert(strcmp(dst, "hello world") == 0);
|
|
|
|
/* strlen */
|
|
assert(strlen("") == 0);
|
|
assert(strlen("abc") == 3);
|
|
|
|
/* memset */
|
|
char buf[10];
|
|
memset(buf, 0xAB, 10);
|
|
for (int i = 0; i < 10; i++) assert((unsigned char)buf[i] == 0xAB);
|
|
|
|
/* memcmp */
|
|
assert(memcmp("abc", "abc", 3) == 0);
|
|
assert(memcmp("abc", "abd", 3) < 0);
|
|
|
|
/* strcmp */
|
|
assert(strcmp("hello", "hello") == 0);
|
|
assert(strcmp("abc", "def") < 0);
|
|
|
|
printf("ALL STRING TESTS PASSED\n");
|
|
return 0;
|
|
}
|