#include #include #include "lsup_rdf.h" #ifndef _LSUP_TEST_H #define _LSUP_TEST_H /** * Minimal unit testing framework. * Inspired from http://www.jera.com/techinfo/jtns/jtn002.html */ /** @brief assert true. */ #define ASSERT(test, msg) do { \ if (!(test)) {\ fprintf(\ stderr, "!!! Assertion failed at %s:%d. Message: %s\n", \ __FILE__, __LINE__, msg); \ return -1; \ }\ } while (0) /** @brief Expect that two int values are equal. */ #define EXPECT_INT_EQ(got, exp) do { \ if ((exp) != (got)) {\ fprintf(\ stderr, "!!! Test failed at %s:%d. Expected: %lu; got: %lu\n",\ __FILE__, __LINE__, (size_t)(exp), (size_t)(got)); \ return -1; \ }\ } while (0) /** @brief Expect that two string values are equal. */ #define EXPECT_STR_EQ(got, exp) do { \ if (strcmp((exp), (got)) != 0) {\ fprintf(\ stderr, "!!! Test failed at %s:%d. Expected: %s; got: %s\n", \ __FILE__, __LINE__, (exp), (got)); \ return -1; \ }\ } while (0) #define EXPECT_PASS(exp) do { \ int rc = (exp); \ if (rc != LSUP_OK) {\ fprintf(\ stderr, "!!! Test failed at %s:%d. Error code: %d\n",\ __FILE__, __LINE__, rc); \ return -1; \ }\ } while (0) /** @brief Run a test by function name. * * The function must not accept any parameters. */ #define RUN(test) do { int rc = test(); tests_run++; \ if (rc != 0) return -1; } while (0) int tests_run; #endif