X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Ftest.h;h=b002cd1e05a4d896d7cd9b27e9ce3981214793da;hb=b4de8d3fd063b9017797dd9809ab3acb8a537606;hp=0cbb5f0d3d2079c7643a15016276b73137b3b12c;hpb=34a8c3858f30b02568c87f56a827f618aba6d6be;p=m6w6%2Flibmemcached diff --git a/tests/test.h b/tests/test.h index 0cbb5f0d..b002cd1e 100644 --- a/tests/test.h +++ b/tests/test.h @@ -3,25 +3,33 @@ */ #ifdef __cplusplus extern "C" { - #endif + #include -#include "../libmemcached/common.h" +#include typedef struct world_st world_st; typedef struct collection_st collection_st; typedef struct test_st test_st; +typedef enum { + TEST_SUCCESS= 0, /* Backwards compatibility */ + TEST_FAILURE, + TEST_MEMORY_ALLOCATION_FAILURE, + TEST_SKIPPED, + TEST_MAXIMUM_RETURN /* Always add new error code before */ +} test_return_t; + struct test_st { - char *name; + const char *name; unsigned int requires_flush; - uint8_t (*function)(memcached_st *memc); + test_return_t (*function)(memcached_st *memc); }; struct collection_st { - char *name; - memcached_return (*pre)(memcached_st *memc); - memcached_return (*post)(memcached_st *memc); + const char *name; + memcached_return_t (*pre)(memcached_st *memc); + memcached_return_t (*post)(memcached_st *memc); test_st *tests; }; @@ -34,6 +42,39 @@ struct world_st { /* How we make all of this work :) */ void get_world(world_st *world); +void create_core(void); + +#define test_truth(A) \ +do \ +{ \ + if (! (A)) { \ + fprintf(stderr, "Assertion failed in %s:%d: %s\n", __FILE__, __LINE__, #A);\ + create_core(); \ + return TEST_FAILURE; \ + } \ +} while (0) + +#define test_false(A) \ +do \ +{ \ + if ((A)) { \ + fprintf(stderr, "Assertion failed in %s:%d: %s\n", __FILE__, __LINE__, #A);\ + create_core(); \ + return TEST_FAILURE; \ + } \ +} while (0) + +#define test_strcmp(A,B) \ +do \ +{ \ + if (strcmp((A), (B))) \ + { \ + fprintf(stderr, "%d", __LINE__); \ + create_core(); \ + return TEST_FAILURE; \ + } \ +} while (0) + #ifdef __cplusplus } #endif