Adding memslap tool.
[m6w6/libmemcached] / tests / test.h
1 /*
2 Structures for generic tests.
3 */
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include <libmemcached/memcached.h>
9 #include <stdio.h>
10
11 typedef struct world_st world_st;
12 typedef struct collection_st collection_st;
13 typedef struct test_st test_st;
14
15 typedef enum {
16 TEST_SUCCESS= 0, /* Backwards compatibility */
17 TEST_FAILURE,
18 TEST_MEMORY_ALLOCATION_FAILURE,
19 TEST_SKIPPED,
20 TEST_MAXIMUM_RETURN /* Always add new error code before */
21 } test_return_t;
22
23 struct test_st {
24 const char *name;
25 unsigned int requires_flush;
26 test_return_t (*function)(memcached_st *memc);
27 };
28
29 struct collection_st {
30 const char *name;
31 memcached_return (*pre)(memcached_st *memc);
32 memcached_return (*post)(memcached_st *memc);
33 test_st *tests;
34 };
35
36 struct world_st {
37 collection_st *collections;
38 void *(*create)(void);
39 void (*destroy)(void *collection_object);
40 };
41
42 /* How we make all of this work :) */
43 void get_world(world_st *world);
44
45 #define test_truth(A) if (! (A)) {fprintf(stderr, "%d", __LINE__); return TEST_FAILURE;}
46 #define test_false(A) if ((A)) {fprintf(stderr, "%d", __LINE__); return TEST_FAILURE;}
47 #define test_strcmp(A,B) if (strcmp((A), (B))) {fprintf(stderr, "%d", __LINE__); return TEST_FAILURE;}
48
49 #ifdef __cplusplus
50 }
51 #endif