]> pd.if.org Git - pdclib/commitdiff
Added test drivers.
authorsolar <unknown>
Mon, 21 Nov 2005 18:08:43 +0000 (18:08 +0000)
committersolar <unknown>
Mon, 21 Nov 2005 18:08:43 +0000 (18:08 +0000)
18 files changed:
functions/string/memcpy.c
functions/string/memmove.c
functions/string/memset.c
functions/string/strcat.c
functions/string/strchr.c
functions/string/strcmp.c
functions/string/strcoll.c
functions/string/strcpy.c
functions/string/strcspn.c
functions/string/strlen.c
functions/string/strncat.c
functions/string/strncmp.c
functions/string/strpbrk.c
functions/string/strrchr.c
functions/string/strspn.c
functions/string/strstr.c
functions/string/strtok.c
functions/string/strxfrm.c

index ca460ef9b52de4f7fc399597b726a607caa5b98b..b2606b7222af7e87476d5a3e7718fa4631f99f10 100644 (file)
@@ -27,7 +27,7 @@ void * memcpy( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, siz
 
 int main()
 {
-    char s[11] = "xxxxxxxxxxx";
+    char s[] = "xxxxxxxxxxx";
     BEGIN_TESTS;
     TESTCASE( memcpy( s, abcde, 6 ) == s );
     TESTCASE( s[4] == 'e' );
index e9a52b20ed8864a6078121eabb75b3c3a4fd9e9c..7c50deeb6ead1e8d0c1cac5a3e2e3e793d7b6931 100644 (file)
@@ -38,7 +38,7 @@ void * memmove( void * s1, const void * s2, size_t n )
 
 int main()
 {
-    char s[10] = "xxxxabcde";
+    char s[] = "xxxxabcde";
     BEGIN_TESTS;
     TESTCASE( memmove( s, s + 4, 5 ) == s );
     TESTCASE( s[0] == 'a' );
index 735a8e60623dc1f9ebeb2cbf8e7f0a218e2efc7e..753a33320fc4db576d23c9fd12a4724989b4c2d6 100644 (file)
@@ -25,7 +25,7 @@ void * memset( void * s, int c, size_t n )
 
 int main()
 {
-    char s[10] = "xxxxxxxxx";
+    char s[] = "xxxxxxxxx";
     BEGIN_TESTS;
     TESTCASE( memset( s, 'o', 10 ) == s );
     TESTCASE( s[9] == 'o' );
index a4eab143b3352907df5f21e6877d9b1dcc083dee..d1135756069099dad2a478e9a55a19f65951750b 100644 (file)
@@ -21,11 +21,25 @@ char * strcat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 )
     return rc;
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    char s[] = "xx\0xxxxxx";
+    BEGIN_TESTS;
+    TESTCASE( strcat( s, abcde ) == s );
+    TESTCASE( s[2] == 'a' );
+    TESTCASE( s[6] == 'e' );
+    TESTCASE( s[7] == '\0' );
+    TESTCASE( s[8] == 'x' );
+    s[0] = '\0';
+    TESTCASE( strcat( s, abcdx ) == s );
+    TESTCASE( s[4] == 'x' );
+    TESTCASE( s[5] == '\0' );
+    TESTCASE( strcat( s, "\0" ) == s );
+    TESTCASE( s[5] == '\0' );
+    TESTCASE( s[6] == 'e' );
+    return TEST_RESULTS;
 }
 #endif
index ec296cbce33cab48ae8b9aeaa6fed4500710c83b..96ab0519aafbbdc8f4be004cf77929fabfc1914c 100644 (file)
@@ -22,11 +22,18 @@ char * strchr( const char * s, int c )
     return NULL;
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    char abccd[] = "abccd";
+    BEGIN_TESTS;
+    TESTCASE( strchr( abccd, 'x' ) == NULL );
+    TESTCASE( strchr( abccd, 'a' ) == &abccd[0] );
+    TESTCASE( strchr( abccd, 'd' ) == &abccd[4] );
+    TESTCASE( strchr( abccd, '\0' ) == &abccd[5] );
+    TESTCASE( strchr( abccd, 'c' ) == &abccd[2] );
+    return TEST_RESULTS;
 }
 #endif
index f6a555b56de7d0076c425a472466e393bec43685..fea5d2dfc7ac19352e3ce4014e72e74a239b2c70 100644 (file)
@@ -18,11 +18,19 @@ int strcmp( const char * s1, const char * s2 )
     return ( *s1 - *s2 );
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    char cmpabcde[] = "abcde";
+    char empty[] = "";
+    BEGIN_TESTS;
+    TESTCASE( strcmp( abcde, cmpabcde ) == 0 );
+    TESTCASE( strcmp( abcde, abcdx ) < 0 );
+    TESTCASE( strcmp( abcdx, abcde ) > 0 );
+    TESTCASE( strcmp( empty, abcde ) < 0 );
+    TESTCASE( strcmp( abcde, empty ) > 0 );
+    return TEST_RESULTS;
 }
 #endif
index 6f8a0dc87ffbc0f83853fc5e0066097dfd35dd09..74a8aadb9a84cbb312c0d19f564730d3a509140e 100644 (file)
@@ -17,11 +17,19 @@ int strcoll( const char * s1, const char * s2 )
     return strcmp( s1, s2 );
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    char cmpabcde[] = "abcde";
+    char empty[] = "";
+    BEGIN_TESTS;
+    TESTCASE( strcmp( abcde, cmpabcde ) == 0 );
+    TESTCASE( strcmp( abcde, abcdx ) < 0 );
+    TESTCASE( strcmp( abcdx, abcde ) > 0 );
+    TESTCASE( strcmp( empty, abcde ) < 0 );
+    TESTCASE( strcmp( abcde, empty ) > 0 );
+    return TEST_RESULTS;
 }
 #endif
index 4f028759bf8cd0dddb560788f51c3433672da704..49204da54ba27d679de4fe6679daf1cb806131db 100644 (file)
@@ -17,11 +17,20 @@ char * strcpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 )
     return rc;
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    char s[] = "xxxxx";
+    BEGIN_TESTS;
+    TESTCASE( strcpy( s, "" ) == s );
+    TESTCASE( s[0] == '\0' );
+    TESTCASE( s[1] == 'x' );
+    TESTCASE( strcpy( s, abcde ) == s );
+    TESTCASE( s[0] == 'a' );
+    TESTCASE( s[4] == 'e' );
+    TESTCASE( s[5] == '\0' );
+    return TEST_RESULTS;
 }
 #endif
index 308fe362fcfdf47f59233348a64140a12010e00d..01f10e59bf0ab2da253c5004fb087f7b0b134cfd 100644 (file)
@@ -29,11 +29,21 @@ size_t strcspn( const char * s1, const char * s2 )
     return len;
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    BEGIN_TESTS;
+    TESTCASE( strcspn( abcde, "x" ) == 5 );
+    TESTCASE( strcspn( abcde, "xyz" ) == 5 );
+    TESTCASE( strcspn( abcde, "zyx" ) == 5 );
+    TESTCASE( strcspn( abcdx, "x" ) == 4 );
+    TESTCASE( strcspn( abcdx, "xyz" ) == 4 );
+    TESTCASE( strcspn( abcdx, "zyx" ) == 4 );
+    TESTCASE( strcspn( abcde, "a" ) == 0 );
+    TESTCASE( strcspn( abcde, "abc" ) == 0 );
+    TESTCASE( strcspn( abcde, "cba" ) == 0 );
+    return TEST_RESULTS;
 }
 #endif
index da5bc4093af805dddfdcf274f12cc19f6704f6e5..02d105cf0b8e1b697dfddb97af47c5b33ade8770 100644 (file)
@@ -20,11 +20,14 @@ size_t strlen( const char * s )
     return rc;
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    BEGIN_TESTS;
+    TESTCASE( strlen( abcde ) == 5 );
+    TESTCASE( strlen( "" ) == 0 );
+    return TEST_RESULTS;
 }
 #endif
index d9f9fe350031d0d8f768b80024e30cf188c8cb45..7fdaa2670eff250cba6bc045723320d844667f71 100644 (file)
@@ -29,11 +29,32 @@ char * strncat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, si
     return rc;
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    char s[] = "xx\0xxxxxx";
+    BEGIN_TESTS;
+    TESTCASE( strncat( s, abcde, 10 ) == s );
+    TESTCASE( s[2] == 'a' );
+    TESTCASE( s[6] == 'e' );
+    TESTCASE( s[7] == '\0' );
+    TESTCASE( s[8] == 'x' );
+    s[0] = '\0';
+    TESTCASE( strncat( s, abcdx, 10 ) == s );
+    TESTCASE( s[4] == 'x' );
+    TESTCASE( s[5] == '\0' );
+    TESTCASE( strncat( s, "\0", 10 ) == s );
+    TESTCASE( s[5] == '\0' );
+    TESTCASE( s[6] == 'e' );
+    TESTCASE( strncat( s, abcde, 0 ) == s );
+    TESTCASE( s[5] == '\0' );
+    TESTCASE( s[6] == 'e' );
+    TESTCASE( strncat( s, abcde, 3 ) == s );
+    TESTCASE( s[5] == 'a' );
+    TESTCASE( s[7] == 'c' );
+    TESTCASE( s[8] == '\0' );
+    return TEST_RESULTS;
 }
 #endif
index 7f398fa9b2b9be4bce4763afabf4bf737e4bf2d2..35a9511da11174497d831d91857d56a8511d3dcb 100644 (file)
@@ -28,11 +28,23 @@ int strncmp( const char * s1, const char * s2, size_t n )
     }
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    char cmpabcde[] = "abcde";
+    char empty[] = "";
+    char x[] = "x";
+    BEGIN_TESTS;
+    TESTCASE( strncmp( abcde, cmpabcde, 5 ) == 0 );
+    TESTCASE( strncmp( abcde, abcdx, 5 ) < 0 );
+    TESTCASE( strncmp( abcdx, abcde, 5 ) > 0 );
+    TESTCASE( strncmp( empty, abcde, 5 ) < 0 );
+    TESTCASE( strncmp( abcde, empty, 5 ) > 0 );
+    TESTCASE( strncmp( abcde, abcdx, 4 ) == 0 );
+    TESTCASE( strncmp( abcde, x, 0 ) == 0 );
+    TESTCASE( strncmp( abcde, x, 1 ) < 0 );
+    return TEST_RESULTS;
 }
 #endif
index bc402636516ea47b90fe5aaad622787a5db30a16..b317aed52fa00f4731f4340dc4ae075f3d997ace 100644 (file)
@@ -29,11 +29,20 @@ char * strpbrk( const char * s1, const char * s2 )
     return NULL;
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    BEGIN_TESTS;
+    TESTCASE( strpbrk( abcde, "x" ) == NULL );
+    TESTCASE( strpbrk( abcde, "xyz" ) == NULL );
+    TESTCASE( strpbrk( abcdx, "x" ) == &abcdx[4] );
+    TESTCASE( strpbrk( abcdx, "xyz" ) == &abcdx[4] );
+    TESTCASE( strpbrk( abcdx, "zyx" ) == &abcdx[4] );
+    TESTCASE( strpbrk( abcde, "a" ) == &abcde[0] );
+    TESTCASE( strpbrk( abcde, "abc" ) == &abcde[0] );
+    TESTCASE( strpbrk( abcde, "cba" ) == &abcde[0] );
+    return TEST_RESULTS;
 }
 #endif
index 4fe9a6b49acd8c00597b5da7bbd567985880883e..aa4c9301640a60c2ddcd918a94af4489ad77942f 100644 (file)
@@ -24,11 +24,17 @@ char * strrchr( const char * s, int c )
     return NULL;
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    char abccd[] = "abccd";
+    BEGIN_TESTS;
+    TESTCASE( strrchr( abcde, '\0' ) == &abcde[5] );
+    TESTCASE( strrchr( abcde, 'e' ) == &abcde[4] );
+    TESTCASE( strrchr( abcde, 'a' ) == &abcde[0] );
+    TESTCASE( strrchr( abccd, 'c' ) == &abccd[3] );
+    return TEST_RESULTS;
 }
 #endif
index b8e703d1f09411a7e4d82678009cdfd3f5417e28..a5859cc2ca89b7b2d544457370fde2a74b6c550a 100644 (file)
@@ -34,11 +34,15 @@ size_t strspn( const char * s1, const char * s2 )
     return len;
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    BEGIN_TESTS;
+    TESTCASE( strspn( abcde, "abc" ) == 3 );
+    TESTCASE( strspn( abcde, "b" ) == 0 );
+    TESTCASE( strspn( abcde, abcde ) == 5 );
+    return TEST_RESULTS;
 }
 #endif
index 0566d5d71c2d8b15c9cd29dea665bcd8f74c0a50..2ad75058e75e21211a235b696c0c51151fa98804 100644 (file)
@@ -32,11 +32,19 @@ char * strstr( const char * s1, const char * s2 )
     return NULL;
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    char s[] = "abcabcabcdabcde";
+    BEGIN_TESTS;
+    TESTCASE( strstr( s, "x" ) == NULL );
+    TESTCASE( strstr( s, "xyz" ) == NULL );
+    TESTCASE( strstr( s, "a" ) == &s[0] );
+    TESTCASE( strstr( s, "abc" ) == &s[0] );
+    TESTCASE( strstr( s, "abcd" ) == &s[6] );
+    TESTCASE( strstr( s, "abcde" ) == &s[10] );
+    return TEST_RESULTS;
 }
 #endif
index 9daf329351115309ddcc83822dac52d83176c0a0..071f4f8607e4063f093674c3d81263f16d332793 100644 (file)
@@ -15,7 +15,6 @@ char * strtok( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 )
 {
     static char * tmp = NULL;
     const char * p = s2;
-    size_t len;
 
     if ( s1 != NULL )
     {
@@ -73,11 +72,25 @@ char * strtok( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 )
     return ( tmp = NULL );
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    char s[] = "_a_bc__d_";
+    BEGIN_TESTS;
+    TESTCASE( strtok( s, "_" ) == &s[1] );
+    TESTCASE( s[1] == 'a' );
+    TESTCASE( s[2] == '\0' );
+    TESTCASE( strtok( NULL, "_" ) == &s[3] );
+    TESTCASE( s[3] == 'b' );
+    TESTCASE( s[4] == 'c' );
+    TESTCASE( s[5] == '\0' );
+    TESTCASE( strtok( NULL, "_" ) == &s[7] );
+    TESTCASE( s[6] == '_' );
+    TESTCASE( s[7] == 'd' );
+    TESTCASE( s[8] == '\0' );
+    TESTCASE( strtok( NULL, "_" ) == NULL );
+    return TEST_RESULTS;
 }
 #endif
index af98c184071c2c8eadbef99151f94f6eacbafc8f..650cfbf2ed3c48fccbbc84945e64e5a7d72a56a7 100644 (file)
@@ -26,11 +26,24 @@ size_t strxfrm( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, si
     return len;
 }
 
-#warning Test driver missing.
-
 #ifdef TEST
+#include <_PDCLIB_test.h>
+
 int main()
 {
-    return 0;
+    char s[] = "xxxxxxxxxxx";
+    BEGIN_TESTS;
+    TESTCASE( strxfrm( NULL, "123456789012", 0 ) == 12 );
+    TESTCASE( strxfrm( s, "123456789012", 12 ) == 12 );
+    /*
+    The following test case is true in *this* implementation, but doesn't have to.
+    TESTCASE( s[0] == 'x' );
+    */
+    TESTCASE( strxfrm( s, "1234567890", 11 ) == 10 );
+    TESTCASE( s[0] == '1' );
+    TESTCASE( s[9] == '0' );
+    TESTCASE( s[10] == '\0' );
+    return TEST_RESULTS;
 }
 #endif
+