/** * utest.c * Fun with unit testing! */ // +---------+-------------------------------------------------------- // | Headers | // +---------+ #include #include #include "utest.h" // +---------+-------------------------------------------------------- // | Globals | // +---------+ int errors = 0; // +-----------+------------------------------------------------------ // | Functions | // +-----------+ void check_int (char *command, int result, int expected) { if (result != expected) { ++errors; fprintf (stderr, "ERROR\n"); fprintf (stderr, " Command: %s\n", command); fprintf (stderr, " Result: %d\n", result); fprintf (stderr, " Expected: %d\n", expected); } } // check_int void check_ptr (char *command, void *result, void *expected) { if (result != expected) { ++errors; fprintf (stderr, "ERROR\n"); fprintf (stderr," Command: %s\n", command); } } // check_ptr void check_str (char *command, char *result, char *expected) { if (! string_equal (result, expected)) { ++errors; fprintf (stderr, "ERROR\n"); fprintf (stderr, " Command: %s\n", command); if (result != NULL) fprintf (stderr, " Result: \"%s\"\n", result); else fprintf (stderr, " Result: NULL\n"); if (expected != NULL) fprintf (stderr, " Expected: \"%s\"\n", expected); else fprintf (stderr, " Expected: NULL\n"); } } // check_str