1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <libtest/test.hpp>
30 using namespace libtest
;
32 static test_return_t
LIBTOOL_COMMAND_test(void *)
34 test_true(getenv("LIBTOOL_COMMAND"));
38 static test_return_t
VALGRIND_COMMAND_test(void *)
40 test_true(getenv("VALGRIND_COMMAND"));
44 static test_return_t
HELGRIND_COMMAND_test(void *)
46 test_true(getenv("HELGRIND_COMMAND"));
50 static test_return_t
GDB_COMMAND_test(void *)
52 test_true(getenv("GDB_COMMAND"));
56 static test_return_t
test_success_test(void *)
61 static test_return_t
test_failure_test(void *)
63 return TEST_SKIPPED
; // Only run this when debugging
69 static test_return_t
local_test(void *)
71 if (getenv("LIBTEST_LOCAL"))
73 test_true(test_is_local());
77 test_false(test_is_local());
83 static test_return_t
local_not_test(void *)
90 if ((ptr
= getenv("LIBTEST_LOCAL")) == NULL
)
95 // unsetenv() will cause issues with valgrind
96 _compare(__FILE__
, __LINE__
, __func__
, 0, unsetenv("LIBTEST_LOCAL"));
97 test_compare(0, unsetenv("LIBTEST_LOCAL"));
98 test_false(test_is_local());
100 test_compare(0, setenv("LIBTEST_LOCAL", "1", 1));
101 test_true(test_is_local());
105 test_compare(0, unsetenv("LIBTEST_LOCAL"));
109 char *old_string
= strdup(temp
.c_str());
110 test_compare(0, setenv("LIBTEST_LOCAL", old_string
, 1));
117 static test_return_t
pause_test(void *)
125 static test_return_t
gearmand_cycle_test(void *object
)
127 server_startup_st
*servers
= (server_startup_st
*)object
;
130 #ifndef HAVE_LIBGEARMAN
134 const char *argv
[1]= { "cycle_gearmand" };
135 test_true(server_startup(*servers
, "gearmand", 9999, 1, argv
));
140 static test_return_t
memcached_cycle_test(void *object
)
142 server_startup_st
*servers
= (server_startup_st
*)object
;
145 #if !defined(MEMCACHED_BINARY) || !defined(HAVE_LIBMEMCACHED)
149 const char *argv
[1]= { "cycle_memcached" };
150 test_true(server_startup(*servers
, "memcached", 9998, 1, argv
));
155 static test_return_t
memcached_socket_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(servers
->start_socket_server("memcached", 9997, 1, argv
));
170 test_st gearmand_tests
[] ={
172 {"pause", 0, pause_test
},
174 {"gearmand startup-shutdown", 0, gearmand_cycle_test
},
178 test_st memcached_tests
[] ={
179 {"memcached startup-shutdown", 0, memcached_cycle_test
},
180 {"memcached(socket file) startup-shutdown", 0, memcached_socket_cycle_test
},
184 test_st environment_tests
[] ={
185 {"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test
},
186 {"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test
},
187 {"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test
},
188 {"GDB_COMMAND", 0, GDB_COMMAND_test
},
192 test_st tests_log
[] ={
193 {"TEST_SUCCESS", 0, test_success_test
},
194 {"TEST_FAILURE", 0, test_failure_test
},
198 test_st local_log
[] ={
199 {"test_is_local()", 0, local_test
},
200 {"test_is_local(NOT)", 0, local_not_test
},
204 collection_st collection
[] ={
205 {"environment", 0, 0, environment_tests
},
206 {"return values", 0, 0, tests_log
},
207 {"local", 0, 0, local_log
},
208 {"gearmand", 0, 0, gearmand_tests
},
209 {"memcached", 0, 0, memcached_tests
},
213 static void *world_create(server_startup_st
& servers
, test_return_t
&)
218 void get_world(Framework
*world
)
220 world
->collections
= collection
;
221 world
->_create
= world_create
;