Merging bzr://gaz.tangent.org/libmemcached/build/ to Build branch
[awesomized/libmemcached] / tests / cycle.cc
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Cycle the Gearmand server
4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36
37
38 /*
39 Test that we are cycling the servers we are creating during testing.
40 */
41
42 #include <config.h>
43 #include <libtest/test.hpp>
44
45 using namespace libtest;
46 #include <libmemcached/memcached.h>
47
48 static test_return_t server_startup_single_TEST(void *obj)
49 {
50 server_startup_st *servers= (server_startup_st*)obj;
51 test_compare(true, server_startup(*servers, "memcached", libtest::get_free_port(), 0, NULL, false));
52 test_compare(true, servers->shutdown());
53
54
55 return TEST_SUCCESS;
56 }
57
58 static test_return_t server_startup_multiple_TEST(void *obj)
59 {
60 server_startup_st *servers= (server_startup_st*)obj;
61 for (size_t x= 0; x < 10; x++)
62 {
63 test_compare(true, server_startup(*servers, "memcached", libtest::get_free_port(), 0, NULL, false));
64 }
65 test_compare(true, servers->shutdown());
66
67 return TEST_SUCCESS;
68 }
69
70 static test_return_t shutdown_and_remove_TEST(void *obj)
71 {
72 server_startup_st *servers= (server_startup_st*)obj;
73 servers->shutdown_and_remove();
74
75 return TEST_SUCCESS;
76 }
77
78 test_st server_startup_TESTS[] ={
79 {"server_startup(1)", false, (test_callback_fn*)server_startup_single_TEST },
80 {"server_startup(10)", false, (test_callback_fn*)server_startup_multiple_TEST },
81 {"shutdown_and_remove()", false, (test_callback_fn*)shutdown_and_remove_TEST },
82 {"server_startup(10)", false, (test_callback_fn*)server_startup_multiple_TEST },
83 {0, 0, 0}
84 };
85
86 #if 0
87 static test_return_t collection_INIT(void *object)
88 {
89 server_startup_st *servers= (server_startup_st*)object;
90 test_zero(servers->count());
91 test_compare(true, server_startup(*servers, "memcached", libtest::default_port(), 0, NULL));
92
93 return TEST_SUCCESS;
94 }
95 #endif
96
97 static test_return_t validate_sanity_INIT(void *object)
98 {
99 server_startup_st *servers= (server_startup_st*)object;
100
101 test_zero(servers->count());
102
103 return TEST_SUCCESS;
104 }
105
106 static test_return_t collection_FINAL(void *object)
107 {
108 server_startup_st *servers= (server_startup_st*)object;
109 servers->shutdown_and_remove();
110
111 return TEST_SUCCESS;
112 }
113
114 collection_st collection[] ={
115 {"server_startup()", validate_sanity_INIT, collection_FINAL, server_startup_TESTS },
116 {0, 0, 0, 0}
117 };
118
119 static void *world_create(server_startup_st& servers, test_return_t& )
120 {
121 return &servers;
122 }
123
124 void get_world(Framework *world)
125 {
126 world->collections= collection;
127 world->_create= world_create;
128 }
129