Adding in more tests for command line tools.
[awesomized/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 test_return 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 TEST_SUCCESS;
31 }
32
33 test_return basic_master_key_test(memcached_st *memc)
34 {
35 Memcached foo;
36 char *value_set= "Data for server A";
37 char *master_key_a= "server-a";
38 char *master_key_b= "server-b";
39 char *key= "xyz";
40 char *value;
41 size_t value_length;
42
43 foo.set_by_key(master_key_a, key, value_set, strlen(value_set));
44 value= foo.get_by_key(master_key_a, key, &value_length);
45
46 assert((memcmp(value, value_set, value_length) == 0));
47
48 value= foo.get_by_key(master_key_b, key, &value_length);
49 assert((memcmp(value, value_set, value_length) == 0));
50
51 return TEST_SUCCESS;
52 }
53
54
55 test_st tests[] ={
56 {"basic", 0, basic_test },
57 {"basic_master_key", 0, basic_master_key_test },
58 {0, 0, 0}
59 };
60
61 collection_st collection[] ={
62 {"block", 0, 0, tests},
63 {0, 0, 0, 0}
64 };
65
66 #define SERVERS_TO_CREATE 1
67
68 void *world_create(void)
69 {
70 unsigned int x;
71 memcached_server_st *servers;
72 server_startup_st *construct;
73
74 construct= (server_startup_st *)malloc(sizeof(server_startup_st));
75 memset(construct, 0, sizeof(server_startup_st));
76
77 construct->count= SERVERS_TO_CREATE;
78 server_startup(construct);
79
80 return construct;
81 }
82
83 void world_destroy(void *p)
84 {
85 server_startup_st *construct= (server_startup_st *)p;
86 memcached_server_st *servers= (memcached_server_st *)construct->servers;
87 memcached_server_list_free(servers);
88
89 server_shutdown(construct);
90 free(construct);
91 }
92
93 void get_world(world_st *world)
94 {
95 world->collections= collection;
96 world->create= world_create;
97 world->destroy= world_destroy;
98 }