cb0b0837893531a72e90a9478cacd822ab3020ab
[m6w6/libmemcached] / tests / plus.cpp
1 /*
2 C++ interface test
3 */
4 #include <assert.h>
5 #include <memcached.hh>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <sys/time.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <unistd.h>
13 #include <time.h>
14 #include "server.h"
15
16 #include "test.h"
17
18 uint8_t basic_test(memcached_st *memc)
19 {
20 Memcached foo;
21 char *value_set= "This is some data";
22 char *value;
23 size_t value_length;
24
25 foo.set("mine", value_set, strlen(value_set));
26 value= foo.get("mine", &value_length);
27
28 assert((memcmp(value, value_set, value_length) == 0));
29
30 return 0;
31 }
32
33 test_st tests[] ={
34 {"basic", 0, basic_test },
35 {0, 0, 0}
36 };
37
38 collection_st collection[] ={
39 {"block", 0, 0, tests},
40 {0, 0, 0, 0}
41 };
42
43 #define SERVERS_TO_CREATE 1
44
45 void *world_create(void)
46 {
47 unsigned int x;
48 memcached_server_st *servers;
49 server_startup_st *construct;
50
51 construct= (server_startup_st *)malloc(sizeof(server_startup_st));
52 memset(construct, 0, sizeof(server_startup_st));
53
54 construct->count= SERVERS_TO_CREATE;
55 server_startup(construct);
56
57 return construct;
58 }
59
60 void world_destroy(void *p)
61 {
62 server_startup_st *construct= (server_startup_st *)p;
63 memcached_server_st *servers= (memcached_server_st *)construct->servers;
64 memcached_server_list_free(servers);
65
66 server_shutdown(construct);
67 free(construct);
68 }
69
70 void get_world(world_st *world)
71 {
72 world->collections= collection;
73 world->create= world_create;
74 world->destroy= world_destroy;
75 }