7bb2a293499c3b793276e41b073e05103b4bf965
5 #include <memcached.hh>
10 #include <sys/types.h>
19 test_return
basic_test(memcached_st
*memc
);
20 uint8_t increment_test(memcached_st
*memc
);
21 test_return
basic_master_key_test(memcached_st
*memc
);
22 void *world_create(void);
23 void world_destroy(void *p
);
26 test_return
basic_test(memcached_st
*memc
)
29 const char *value_set
= "This is some data";
33 foo
.set("mine", value_set
, strlen(value_set
));
34 value
= foo
.get("mine", &value_length
);
36 assert((memcmp(value
, value_set
, value_length
) == 0));
41 uint8_t increment_test(memcached_st
*memc
)
43 Memcached
mcach(memc
);
45 const char *key
= "inctest";
46 const char *inc_value
= "1";
48 uint64_t int_inc_value
;
49 uint64_t int_ret_value
;
52 mcach
.set(key
, inc_value
, strlen(inc_value
));
53 ret_value
= mcach
.get(key
, &value_length
);
54 printf("\nretvalue %s\n",ret_value
);
55 int_inc_value
= atoi(inc_value
);
56 int_ret_value
= atoi(ret_value
);
57 assert(int_ret_value
== int_inc_value
);
59 rc
= mcach
.increment(key
, 1, &int_ret_value
);
60 assert(rc
== MEMCACHED_SUCCESS
);
61 assert(int_ret_value
== 2);
63 rc
= mcach
.increment(key
, 1, &int_ret_value
);
64 assert(rc
== MEMCACHED_SUCCESS
);
65 assert(int_ret_value
== 3);
67 rc
= mcach
.increment(key
, 5, &int_ret_value
);
68 assert(rc
== MEMCACHED_SUCCESS
);
69 assert(int_ret_value
== 8);
74 test_return
basic_master_key_test(memcached_st
*memc
)
77 const char *value_set
= "Data for server A";
78 const char *master_key_a
= "server-a";
79 const char *master_key_b
= "server-b";
80 const char *key
= "xyz";
84 foo
.set_by_key(master_key_a
, key
, value_set
, strlen(value_set
));
85 value
= foo
.get_by_key(master_key_a
, key
, &value_length
);
87 assert((memcmp(value
, value_set
, value_length
) == 0));
89 value
= foo
.get_by_key(master_key_b
, key
, &value_length
);
90 assert((memcmp(value
, value_set
, value_length
) == 0));
97 {"basic", 0, basic_test
},
98 {"basic_master_key", 0, basic_master_key_test
},
102 collection_st collection
[] ={
103 {"block", 0, 0, tests
},
107 #define SERVERS_TO_CREATE 1
109 extern "C" void *world_create(void)
111 server_startup_st
*construct
;
113 construct
= (server_startup_st
*)malloc(sizeof(server_startup_st
));
114 memset(construct
, 0, sizeof(server_startup_st
));
116 construct
->count
= SERVERS_TO_CREATE
;
117 server_startup(construct
);
122 void world_destroy(void *p
)
124 server_startup_st
*construct
= static_cast<server_startup_st
*>(p
);
125 memcached_server_st
*servers
=
126 static_cast<memcached_server_st
*>(construct
->servers
);
127 memcached_server_list_free(servers
);
129 server_shutdown(construct
);
133 void get_world(world_st
*world
)
135 world
->collections
= collection
;
136 world
->create
= world_create
;
137 world
->destroy
= world_destroy
;