4 #include "libmemcached/memcached.hh"
11 #include <sys/types.h>
20 test_return
basic_test(memcached_st
*memc
);
21 uint8_t increment_test(memcached_st
*memc
);
22 test_return
basic_master_key_test(memcached_st
*memc
);
23 void *world_create(void);
24 void world_destroy(void *p
);
27 test_return
basic_test(memcached_st
*memc
)
30 const char *value_set
= "This is some data";
34 foo
.set("mine", value_set
, strlen(value_set
));
35 value
= foo
.get("mine", &value_length
);
37 assert((memcmp(value
, value_set
, value_length
) == 0));
42 uint8_t increment_test(memcached_st
*memc
)
44 Memcached
mcach(memc
);
46 const char *key
= "inctest";
47 const char *inc_value
= "1";
49 uint64_t int_inc_value
;
50 uint64_t int_ret_value
;
53 mcach
.set(key
, inc_value
, strlen(inc_value
));
54 ret_value
= mcach
.get(key
, &value_length
);
55 printf("\nretvalue %s\n",ret_value
);
56 int_inc_value
= atoi(inc_value
);
57 int_ret_value
= atoi(ret_value
);
58 assert(int_ret_value
== int_inc_value
);
60 rc
= mcach
.increment(key
, 1, &int_ret_value
);
61 assert(rc
== MEMCACHED_SUCCESS
);
62 assert(int_ret_value
== 2);
64 rc
= mcach
.increment(key
, 1, &int_ret_value
);
65 assert(rc
== MEMCACHED_SUCCESS
);
66 assert(int_ret_value
== 3);
68 rc
= mcach
.increment(key
, 5, &int_ret_value
);
69 assert(rc
== MEMCACHED_SUCCESS
);
70 assert(int_ret_value
== 8);
75 test_return
basic_master_key_test(memcached_st
*memc
)
78 const char *value_set
= "Data for server A";
79 const char *master_key_a
= "server-a";
80 const char *master_key_b
= "server-b";
81 const char *key
= "xyz";
85 foo
.set_by_key(master_key_a
, key
, value_set
, strlen(value_set
));
86 value
= foo
.get_by_key(master_key_a
, key
, &value_length
);
88 assert((memcmp(value
, value_set
, value_length
) == 0));
90 value
= foo
.get_by_key(master_key_b
, key
, &value_length
);
91 assert((memcmp(value
, value_set
, value_length
) == 0));
98 {"basic", 0, basic_test
},
99 {"basic_master_key", 0, basic_master_key_test
},
103 collection_st collection
[] ={
104 {"block", 0, 0, tests
},
108 #define SERVERS_TO_CREATE 1
110 extern "C" void *world_create(void)
112 server_startup_st
*construct
;
114 construct
= (server_startup_st
*)malloc(sizeof(server_startup_st
));
115 memset(construct
, 0, sizeof(server_startup_st
));
117 construct
->count
= SERVERS_TO_CREATE
;
118 server_startup(construct
);
123 void world_destroy(void *p
)
125 server_startup_st
*construct
= static_cast<server_startup_st
*>(p
);
126 memcached_server_st
*servers
=
127 static_cast<memcached_server_st
*>(construct
->servers
);
128 memcached_server_list_free(servers
);
130 server_shutdown(construct
);
134 void get_world(world_st
*world
)
136 world
->collections
= collection
;
137 world
->create
= world_create
;
138 world
->destroy
= world_destroy
;