Merging in platform fixes for libmemcached.
[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 void create_core(void);
46
47 #define test_truth(A) \
48 do \
49 { \
50 if (! (A)) { \
51 fprintf(stderr, "Assertion failed in %s:%d: %s\n", __FILE__, __LINE__, #A);\
52 create_core(); \
53 return TEST_FAILURE; \
54 } \
55 } while (0)
56
57 #define test_false(A) \
58 do \
59 { \
60 if ((A)) { \
61 fprintf(stderr, "Assertion failed in %s:%d: %s\n", __FILE__, __LINE__, #A);\
62 create_core(); \
63 return TEST_FAILURE; \
64 } \
65 } while (0)
66
67 #define test_strcmp(A,B) \
68 do \
69 { \
70 if (strcmp((A), (B))) \
71 { \
72 fprintf(stderr, "%d", __LINE__); \
73 create_core(); \
74 return TEST_FAILURE; \
75 } \
76 } while (0)
77
78 #ifdef __cplusplus
79 }
80 #endif