Add tests for stdlib

This commit is contained in:
2016-03-27 12:42:42 -07:00
parent 3000e7e9fb
commit 9fefff9edf
10 changed files with 91 additions and 2 deletions

19
tests/stdlib_isalnum.c Normal file
View File

@@ -0,0 +1,19 @@
#include "stdlib.h"
#define NULL 0x00
int main(void)
{
const char *postest = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const char *negtest = "~!@#$%^&*()_+{}|[]\\:\";'<>?,./`/*-.";
char *ptr = NULL;
for ( ptr = (char *)postest; *ptr != '\0' ; ptr++ ) {
if ( isalnum((int)*ptr) != 1 ) return (int)(ptr - postest);
}
for ( ptr = (char *)negtest; *ptr != '\0' ; ptr++ ) {
if ( islower((int)*ptr) != 0 ) return (int)(100 + (ptr - negtest));
}
return 0;
}

View File

@@ -0,0 +1 @@
stdlib

19
tests/stdlib_isdigit.c Normal file
View File

@@ -0,0 +1,19 @@
#include "stdlib.h"
#define NULL 0x00
int main(void)
{
if ( isdigit((int)'0') != 1 ) return 1;
if ( isdigit((int)'1') != 1 ) return 2;
if ( isdigit((int)'2') != 1 ) return 3;
if ( isdigit((int)'3') != 1 ) return 4;
if ( isdigit((int)'4') != 1 ) return 5;
if ( isdigit((int)'5') != 1 ) return 6;
if ( isdigit((int)'6') != 1 ) return 7;
if ( isdigit((int)'7') != 1 ) return 8;
if ( isdigit((int)'8') != 1 ) return 9;
if ( isdigit((int)'9') != 1 ) return 10;
if ( isdigit((int)'a') != 0 ) return 11;
return 0;
}

View File

@@ -0,0 +1 @@
stdlib

View File

@@ -0,0 +1 @@
stdlib

View File

@@ -0,0 +1,27 @@
#include "stdlib.h"
#define NULL 0x00
int main(void)
{
const char *uptest = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const char *lowtest = "abcdefghijklmnopqrstuvwcyz";
char *ptr = NULL;
for ( ptr = (char *)uptest; *ptr != '\0' ; ptr++ ) {
if ( isupper((int)*ptr) != 1 ) return (int)(ptr - uptest);
}
for ( ptr = (char *)lowtest; *ptr != '\0' ; ptr++ ) {
if ( isupper((int)*ptr) != 0 ) return (int)(26 + (ptr - lowtest));
}
for ( ptr = (char *)lowtest; *ptr != '\0' ; ptr++ ) {
if ( islower((int)*ptr) != 1 ) return (int)(52 + (ptr - uptest));
}
for ( ptr = (char *)uptest; *ptr != '\0' ; ptr++ ) {
if ( islower((int)*ptr) != 0 ) return (int)(78 + (ptr - lowtest));
}
return 0;
}

View File

@@ -0,0 +1 @@
stdlib

19
tests/stdlib_isxdigit.c Normal file
View File

@@ -0,0 +1,19 @@
#include "stdlib.h"
#define NULL 0x00
int main(void)
{
const char *postest = "ABCDEFabcdef0123456789";
const char *negtest = "GHIJKLMNOPQRSTUVWXYZghijklmnopqrstuvwxyz~!@#$%^&*()_+{}|[]\\:\";'<>?,./`/*-.";
char *ptr = NULL;
for ( ptr = (char *)postest; *ptr != '\0' ; ptr++ ) {
if ( isxdigit((int)*ptr) != 1 ) return (int)(ptr - postest);
}
for ( ptr = (char *)negtest; *ptr != '\0' ; ptr++ ) {
if ( isxdigit((int)*ptr) != 0 ) return (int)(100 + (ptr - negtest));
}
return 0;
}

View File

@@ -0,0 +1 @@
stdlib

View File

@@ -1,8 +1,8 @@
#!/bin/bash
for file in *.c
for testfile in *.c
do
filebase=$(basename $file | sed 's/\.c$//')
filebase=$(basename $testfile | sed 's/\.c$//')
compile_def=$(cat <<EOF
function shunittest_compile_${filebase} {
set -e ; make ${filebase}.elf >&2 ; test -e ${filebase}.elf ; set +e