/** * utest.h * Sam's favorite unit testing macros. Make sure to link your file * with utest.o. * * Copyright (c) 2010-2011 Samuel A. Rebelsky, All Rights Reserved * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General * Public License along with this program. If not, see * . */ #ifndef __UTEST_H__ #define __UTEST_H__ // +--------+--------------------------------------------------------- // | Macros | // +--------+ #define CHECK_INT(COMMAND, EXPECTED) check_int (#COMMAND, COMMAND, EXPECTED) #define CHECK_PTR(COMMAND, EXPECTED) check_ptr (#COMMAND, COMMAND, EXPECTED) #define CHECK_STR(COMMAND, EXPECTED) check_str (#COMMAND, COMMAND, EXPECTED) // +---------+-------------------------------------------------------- // | Globals | // +---------+ /** * A count of tests conducted. */ extern int tests; /** * A count of errors encountered. */ extern int errors; // +-----------+------------------------------------------------------ // | Functions | // +-----------+ void check_int (char *command, int result, int expected); void check_ptr (char *command, void *result, void *expected); void check_str (char *command, char *result, char *expected); /** Get a count of errors. */ int utest_errors (void); /** Get a count of tests. */ int utest_tests (void); #endif // __UTEST_H__