fdc7e916948e07e5c20f7f2445e1cae1f1ae8c64
4 #include "libmemcached/memcached.hh"
11 #include <sys/types.h>
24 test_return
basic_test(memcached_st
*memc
);
25 test_return
increment_test(memcached_st
*memc
);
26 test_return
basic_master_key_test(memcached_st
*memc
);
27 void *world_create(void);
28 void world_destroy(void *p
);
31 test_return
basic_test(memcached_st
*memc
)
34 const string
value_set("This is some data");
38 foo
.set("mine", value_set
);
39 value
= foo
.get("mine", &value_length
);
41 assert((memcmp(value
.c_str(), value_set
.c_str(), value_length
) == 0));
46 test_return
increment_test(memcached_st
*memc
)
48 Memcached
mcach(memc
);
50 const string
key("inctest");
51 const string
inc_value("1");
53 uint64_t int_inc_value
;
54 uint64_t int_ret_value
;
57 mcach
.set(key
, inc_value
);
58 ret_value
= mcach
.get(key
, &value_length
);
59 printf("\nretvalue %s\n",ret_value
.c_str());
60 int_inc_value
= uint64_t(atol(inc_value
.c_str()));
61 int_ret_value
= uint64_t(atol(ret_value
.c_str()));
62 assert(int_ret_value
== int_inc_value
);
64 rc
= mcach
.increment(key
, 1, &int_ret_value
);
66 assert(int_ret_value
== 2);
68 rc
= mcach
.increment(key
, 1, &int_ret_value
);
70 assert(int_ret_value
== 3);
72 rc
= mcach
.increment(key
, 5, &int_ret_value
);
74 assert(int_ret_value
== 8);
79 test_return
basic_master_key_test(memcached_st
*memc
)
82 const string
value_set("Data for server A");
83 const string
master_key_a("server-a");
84 const string
master_key_b("server-b");
85 const string
key("xyz");
89 foo
.set_by_key(master_key_a
, key
, value_set
);
90 value
= foo
.get_by_key(master_key_a
, key
, &value_length
);
92 assert((memcmp(value
.c_str(), value_set
.c_str(), value_length
) == 0));
94 value
= foo
.get_by_key(master_key_b
, key
, &value_length
);
95 assert((memcmp(value
.c_str(), value_set
.c_str(), value_length
) == 0));
102 { "basic", 0, basic_test
},
103 { "basic_master_key", 0, basic_master_key_test
},
104 { "increment_test", 0, increment_test
},
108 collection_st collection
[] ={
109 {"block", 0, 0, tests
},
113 #define SERVERS_TO_CREATE 1
115 extern "C" void *world_create(void)
117 server_startup_st
*construct
;
119 construct
= (server_startup_st
*)malloc(sizeof(server_startup_st
));
120 memset(construct
, 0, sizeof(server_startup_st
));
122 construct
->count
= SERVERS_TO_CREATE
;
123 server_startup(construct
);
128 void world_destroy(void *p
)
130 server_startup_st
*construct
= static_cast<server_startup_st
*>(p
);
131 memcached_server_st
*servers
=
132 static_cast<memcached_server_st
*>(construct
->servers
);
133 memcached_server_list_free(servers
);
135 server_shutdown(construct
);
139 void get_world(world_st
*world
)
141 world
->collections
= collection
;
142 world
->create
= world_create
;
143 world
->destroy
= world_destroy
;