cdcd4ba4c7cfff20c9bbd9a5bcd72168d2630b61
[m6w6/libmemcached] / tests / udp.c
1 /* LibMemcached
2 * Copyright (C) 2006-2009 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
8 * Summary:
9 *
10 */
11
12 /*
13 Sample test application.
14 */
15 #include <assert.h>
16 #include <libmemcached/memcached.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <sys/time.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <unistd.h>
24 #include <time.h>
25 #include "test.h"
26 #include "server.h"
27
28 /* Prototypes */
29 test_return_t set_test(memcached_st *memc);
30 void *world_create(void);
31 void world_destroy(void *p);
32
33 test_return_t set_test(memcached_st *memc)
34 {
35 memcached_return_t rc;
36 const char *key= "foo";
37 const char *value= "when we sanitize";
38
39 rc= memcached_set(memc, key, strlen(key),
40 value, strlen(value),
41 (time_t)0, (uint32_t)0);
42 test_truth(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
43
44 return TEST_SUCCESS;
45 }
46
47 test_st tests[] ={
48 {"set", 1, set_test },
49 {0, 0, 0}
50 };
51
52 collection_st collection[] ={
53 {"udp", 0, 0, tests},
54 {0, 0, 0, 0}
55 };
56
57 #define SERVERS_TO_CREATE 1
58
59 void *world_create(void)
60 {
61 server_startup_st *construct;
62
63 construct= (server_startup_st *)malloc(sizeof(server_startup_st));
64 memset(construct, 0, sizeof(server_startup_st));
65 construct->count= SERVERS_TO_CREATE;
66 construct->udp= 1;
67 server_startup(construct);
68
69 return construct;
70 }
71
72 void world_destroy(void *p)
73 {
74 server_startup_st *construct= (server_startup_st *)p;
75 memcached_server_st *servers= (memcached_server_st *)construct->servers;
76 memcached_server_list_free(servers);
77
78 server_shutdown(construct);
79 free(construct);
80 }
81
82 void get_world(world_st *world)
83 {
84 world->collections= collection;
85 world->create= world_create;
86 world->destroy= world_destroy;
87 }