1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
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
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
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.
39 Test that we are cycling the servers we are creating during testing.
44 #include <libtest/test.hpp>
45 #include <libmemcached/memcached.h>
47 #include "tests/libmemcached-1.0/memcached_get.h"
49 using namespace libtest
;
51 #ifndef __INTEL_COMPILER
52 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
55 static std::string
executable("example/memcached_light");
57 static test_return_t
help_TEST(void *)
59 const char *args
[]= { "--help", 0 };
61 test_compare(EXIT_SUCCESS
, exec_cmdline(executable
, args
, true));
66 static test_return_t
verbose_TEST(void *)
68 const char *args
[]= { "--help", "--verbose", 0 };
70 test_compare(EXIT_SUCCESS
, exec_cmdline(executable
, args
, true));
75 static test_return_t
daemon_TEST(void *)
77 const char *args
[]= { "--help", "--daemon", 0 };
79 test_compare(EXIT_SUCCESS
, exec_cmdline(executable
, args
, true));
84 static test_return_t
protocol_TEST(void *)
86 const char *args
[]= { "--help", "--protocol", 0 };
88 test_compare(EXIT_SUCCESS
, exec_cmdline(executable
, args
, true));
93 static test_return_t
version_TEST(void *)
95 const char *args
[]= { "--help", "--version", 0 };
97 test_compare(EXIT_SUCCESS
, exec_cmdline(executable
, args
, true));
102 static test_return_t
port_TEST(void *)
104 const char *args
[]= { "--help", "--port=9090", 0 };
106 test_compare(EXIT_SUCCESS
, exec_cmdline(executable
, args
, true));
111 static test_return_t
pid_file_TEST(void *)
113 const char *args
[]= { "--help", "--pid-file=/tmp/foo.pid", 0 };
115 test_compare(EXIT_SUCCESS
, exec_cmdline(executable
, args
, true));
120 static test_return_t
log_file_TEST(void *)
122 const char *args
[]= { "--help", "--log-file=/tmp/foo.log", 0 };
124 test_compare(EXIT_SUCCESS
, exec_cmdline(executable
, args
, true));
129 static test_return_t
max_connections_file_TEST(void *)
131 const char *args
[]= { "--help", "--max-connections=/tmp/foo.max_connections", 0 };
133 test_compare(EXIT_SUCCESS
, exec_cmdline(executable
, args
, true));
138 typedef test_return_t (*libmemcached_test_callback_fn
)(memcached_st
*);
140 static test_return_t
_runner_default(libmemcached_test_callback_fn func
, void *object
)
147 ret
= func((memcached_st
*)object
);
149 catch (std::exception
& e
)
151 libtest::Error
<< e
.what();
161 class MemcachedLightRunner
: public libtest::Runner
{
163 test_return_t
run(test_callback_fn
* func
, void *object
)
165 return _runner_default(libmemcached_test_callback_fn(func
), object
);
169 test_st cmdline_option_TESTS
[] ={
170 {"--help", true, help_TEST
},
171 {"--verbose", true, verbose_TEST
},
172 {"--daemon", true, daemon_TEST
},
173 {"--protocol", true, protocol_TEST
},
174 {"--version", true, version_TEST
},
175 {"--port", true, port_TEST
},
176 {"--pid-file", true, pid_file_TEST
},
177 {"--log-file", true, log_file_TEST
},
178 {"--max-connections", true, max_connections_file_TEST
},
182 /* Clean the server before beginning testing */
183 test_st basic_TESTS
[] ={
185 {"memcached_get()", true, (test_callback_fn
*)get_test
},
186 {"memcached_get() test 2", false, (test_callback_fn
*)get_test2
},
187 {"memcached_get() test 3", false, (test_callback_fn
*)get_test3
},
188 {"memcached_get() test 4", false, (test_callback_fn
*)get_test4
},
189 {"memcached_get() test 5", false, (test_callback_fn
*)get_test5
},
194 collection_st collection
[] ={
195 {"command line options", 0, 0, cmdline_option_TESTS
},
196 {"basic", 0, 0, basic_TESTS
},
200 static void *world_create(server_startup_st
& servers
, test_return_t
& error
)
202 if (access(executable
.c_str(), X_OK
) != 0)
208 if (HAVE_MEMCACHED_LIGHT_BINARY
== 0)
214 if (server_startup(servers
, "memcached-light", libtest::default_port(), 0, NULL
) == 0)
222 int length
= snprintf(buffer
, sizeof(buffer
), "--server=localhost:%d", int(libtest::default_port()));
223 fatal_assert(length
> 0);
225 memcached_st
*memc
= memcached(buffer
, length
);
232 static bool world_destroy(void *object
)
234 memcached_st
*memc
= (memcached_st
*)object
;
235 memcached_free(memc
);
241 void get_world(libtest::Framework
* world
)
243 world
->create(world_create
);
244 world
->destroy(world_destroy
);
245 world
->collections(collection
);
246 world
->set_runner(new MemcachedLightRunner
);