Add more tests from stringlib

This commit is contained in:
2016-03-27 13:16:41 -07:00
parent 9fefff9edf
commit f059c083c8
8 changed files with 66 additions and 0 deletions

16
tests/string_memcpy.c Normal file
View File

@@ -0,0 +1,16 @@
#include "string.h"
int main(void)
{
char testblock[8] = {1, 2, 3, 4, 5, 6, 7, 8};
char testblock2[6] = {50, 60, 70, 80, 90, 100};
int i = 0;
memcpy((void *)&testblock, (void *)&testblock2, (sizeof(char)*6));
for ( i = 0; i < 6; i++) {
if ( testblock[i] != testblock2[i] ) return (i + 1);
}
if ( testblock[6] != 7 ) return 7;
if ( testblock[7] != 8 ) return 8;
return 0;
}

1
tests/string_memcpy.deps Normal file
View File

@@ -0,0 +1 @@
string

17
tests/string_memset.c Normal file
View File

@@ -0,0 +1,17 @@
#include "string.h"
int main(void)
{
char testblock[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
int i = 0;
memset((void *)&testblock, 0x00, (sizeof(char) * 8));
for ( i = 0; i < 8; i++) {
if ( testblock[i] != 0x00 ) return (i + 1);
}
if ( testblock[8] != 9 ) return 8;
if ( testblock[9] != 10 ) return 9;
if ( testblock[10] != 11 ) return 10;
if ( testblock[11] != 12 ) return 11;
return 0;
}

1
tests/string_memset.deps Normal file
View File

@@ -0,0 +1 @@
string

9
tests/string_strlen.c Normal file
View File

@@ -0,0 +1,9 @@
#include "string.h"
int main(void)
{
if ( strlen("Test") != 4 ) return 1;
if ( strlen("Th\0ing") != 2 ) return 2;
if ( strlen(NULL) != 0 ) return 3;
return 0;
}

1
tests/string_strlen.deps Normal file
View File

@@ -0,0 +1 @@
string

20
tests/string_strncat.c Normal file
View File

@@ -0,0 +1,20 @@
#include "string.h"
int main(void)
{
char buffer[32];
char *src = "Test String";
int i = 0 ;
if ( strncat((char *)&buffer, NULL, 0) != 0 ) return 1;
if ( strncat(NULL, NULL, 0) != 0 ) return 2;
if ( strncat(NULL, src, 0) != 0 ) return 3;
if ( strncat((char *)&buffer, src, 11) == 0 ) return 4;
for ( i = 0; i < 11 ; i++ ) {
if ( buffer[i] != *(src + (sizeof(char) * i)) ) return i + 5;
}
if ( buffer[11] != '\0' ) return 12 + 5;
return 0;
}

View File

@@ -0,0 +1 @@
string