]> pd.if.org Git - pdclib/blobdiff - functions/stdlib/atexit.c
Added test driver.
[pdclib] / functions / stdlib / atexit.c
index 573e4ba68bf706590b71e377ba0e21cbf45eae46..14363566a8147dba4f6c6c7962a9c62ea26eb61f 100644 (file)
 
 #ifndef REGTEST
 
-/* TODO: Required by both atexit() and exit(). */
-struct _PDCLIB_exitfunc_t
-{
-    struct _PDCLIB_exitfunc_t * next;
-    void (*func)( void );
-};
-
 extern struct _PDCLIB_exitfunc_t * regstack;
 
 int atexit( void (*func)( void ) )
@@ -41,12 +34,33 @@ int atexit( void (*func)( void ) )
 
 #ifdef TEST
 #include <_PDCLIB_test.h>
+#include <assert.h>
+
+static int flags[ 32 ];
+
+static void counthandler()
+{
+    static int rc = 0;
+    flags[ rc ] = rc;
+    ++rc;
+}
+
+static void checkhandler()
+{
+    for ( int i = 0; i < 31; ++i )
+    {
+        assert( flags[ i ] == i );
+    }
+}
 
 int main()
 {
-    int NO_TESTDRIVER = 0;
     BEGIN_TESTS;
-    TESTCASE( NO_TESTDRIVER );
+    TESTCASE( atexit( &checkhandler ) == 0 );
+    for ( int i = 0; i < 31; ++i )
+    {
+        TESTCASE( atexit( &counthandler ) == 0 );
+    }
     return TEST_RESULTS;
 }