1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 * uTest self unit test.
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following disclaimer
17 * in the documentation and/or other materials provided with the
20 * * The names of its contributors may not be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <libtest/test.hpp>
45 using namespace libtest
;
47 static test_return_t
LIBTOOL_COMMAND_test(void *)
49 test_true(getenv("LIBTOOL_COMMAND"));
53 static test_return_t
VALGRIND_COMMAND_test(void *)
55 test_true(getenv("VALGRIND_COMMAND"));
59 static test_return_t
HELGRIND_COMMAND_test(void *)
61 test_true(getenv("HELGRIND_COMMAND"));
65 static test_return_t
GDB_COMMAND_test(void *)
67 test_true(getenv("GDB_COMMAND"));
71 static test_return_t
test_success_test(void *)
76 static test_return_t
test_failure_test(void *)
78 return TEST_SKIPPED
; // Only run this when debugging
84 static test_return_t
local_test(void *)
86 if (getenv("LIBTEST_LOCAL"))
88 test_true(test_is_local());
92 test_false(test_is_local());
98 static test_return_t
local_not_test(void *)
105 if ((ptr
= getenv("LIBTEST_LOCAL")) == NULL
)
110 // unsetenv() will cause issues with valgrind
111 _compare(__FILE__
, __LINE__
, __func__
, 0, unsetenv("LIBTEST_LOCAL"));
112 test_compare(0, unsetenv("LIBTEST_LOCAL"));
113 test_false(test_is_local());
115 test_compare(0, setenv("LIBTEST_LOCAL", "1", 1));
116 test_true(test_is_local());
120 test_compare(0, unsetenv("LIBTEST_LOCAL"));
124 char *old_string
= strdup(temp
.c_str());
125 test_compare(0, setenv("LIBTEST_LOCAL", old_string
, 1));
132 static test_return_t
pause_test(void *)
140 static test_return_t
gearmand_cycle_test(void *object
)
142 server_startup_st
*servers
= (server_startup_st
*)object
;
145 #ifndef HAVE_LIBGEARMAN
149 const char *argv
[1]= { "cycle_gearmand" };
150 test_true(server_startup(*servers
, "gearmand", 9999, 1, argv
));
155 static test_return_t
memcached_cycle_test(void *object
)
157 server_startup_st
*servers
= (server_startup_st
*)object
;
160 #if !defined(MEMCACHED_BINARY) || !defined(HAVE_LIBMEMCACHED)
164 const char *argv
[1]= { "cycle_memcached" };
165 test_true(server_startup(*servers
, "memcached", 9998, 1, argv
));
170 static test_return_t
memcached_socket_cycle_test(void *object
)
172 server_startup_st
*servers
= (server_startup_st
*)object
;
175 #if !defined(MEMCACHED_BINARY) || !defined(HAVE_LIBMEMCACHED)
179 const char *argv
[1]= { "cycle_memcached" };
180 test_true(servers
->start_socket_server("memcached", 9997, 1, argv
));
185 test_st gearmand_tests
[] ={
187 {"pause", 0, pause_test
},
189 {"gearmand startup-shutdown", 0, gearmand_cycle_test
},
193 test_st memcached_tests
[] ={
194 {"memcached startup-shutdown", 0, memcached_cycle_test
},
195 {"memcached(socket file) startup-shutdown", 0, memcached_socket_cycle_test
},
199 test_st environment_tests
[] ={
200 {"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test
},
201 {"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test
},
202 {"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test
},
203 {"GDB_COMMAND", 0, GDB_COMMAND_test
},
207 test_st tests_log
[] ={
208 {"TEST_SUCCESS", 0, test_success_test
},
209 {"TEST_FAILURE", 0, test_failure_test
},
213 test_st local_log
[] ={
214 {"test_is_local()", 0, local_test
},
215 {"test_is_local(NOT)", 0, local_not_test
},
219 collection_st collection
[] ={
220 {"environment", 0, 0, environment_tests
},
221 {"return values", 0, 0, tests_log
},
222 {"local", 0, 0, local_log
},
223 {"gearmand", 0, 0, gearmand_tests
},
224 {"memcached", 0, 0, memcached_tests
},
228 static void *world_create(server_startup_st
& servers
, test_return_t
&)
233 void get_world(Framework
*world
)
235 world
->collections
= collection
;
236 world
->_create
= world_create
;