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>
44 using namespace libtest
;
46 static test_return_t
test_success_test(void *)
51 static test_return_t
test_failure_test(void *)
53 return TEST_SKIPPED
; // Only run this when debugging
59 static test_return_t
local_test(void *)
61 if (getenv("LIBTEST_LOCAL"))
63 test_true(test_is_local());
67 test_false(test_is_local());
73 static test_return_t
local_not_test(void *)
80 if ((ptr
= getenv("LIBTEST_LOCAL")) == NULL
)
85 // unsetenv() will cause issues with valgrind
86 _compare(__FILE__
, __LINE__
, __func__
, 0, unsetenv("LIBTEST_LOCAL"));
87 test_compare(0, unsetenv("LIBTEST_LOCAL"));
88 test_false(test_is_local());
90 test_compare(0, setenv("LIBTEST_LOCAL", "1", 1));
91 test_true(test_is_local());
95 test_compare(0, unsetenv("LIBTEST_LOCAL"));
99 char *old_string
= strdup(temp
.c_str());
100 test_compare(0, setenv("LIBTEST_LOCAL", old_string
, 1));
107 static test_return_t
pause_test(void *)
115 static test_return_t
gearmand_cycle_test(void *object
)
117 server_startup_st
*servers
= (server_startup_st
*)object
;
120 #ifndef HAVE_LIBGEARMAN
124 const char *argv
[1]= { "cycle_gearmand" };
125 test_true(server_startup(*servers
, "gearmand", 9999, 1, argv
));
130 static test_return_t
memcached_cycle_test(void *object
)
132 server_startup_st
*servers
= (server_startup_st
*)object
;
135 #if !defined(MEMCACHED_BINARY) && !defined(HAVE_LIBMEMCACHED)
139 const char *argv
[1]= { "cycle_memcached" };
140 test_true(server_startup(*servers
, "memcached", 9998, 1, argv
));
145 static test_return_t
memcached_socket_cycle_test(void *object
)
147 server_startup_st
*servers
= (server_startup_st
*)object
;
150 #if !defined(MEMCACHED_BINARY) && !defined(HAVE_LIBMEMCACHED)
154 const char *argv
[1]= { "cycle_memcached" };
155 test_true(servers
->start_socket_server("memcached", 9997, 1, argv
));
160 test_st gearmand_tests
[] ={
162 {"pause", 0, pause_test
},
164 {"gearmand startup-shutdown", 0, gearmand_cycle_test
},
168 test_st memcached_tests
[] ={
169 {"memcached startup-shutdown", 0, memcached_cycle_test
},
170 {"memcached(socket file) startup-shutdown", 0, memcached_socket_cycle_test
},
174 test_st tests_log
[] ={
175 {"TEST_SUCCESS", 0, test_success_test
},
176 {"TEST_FAILURE", 0, test_failure_test
},
180 test_st local_log
[] ={
181 {"test_is_local()", 0, local_test
},
182 {"test_is_local(NOT)", 0, local_not_test
},
186 collection_st collection
[] ={
187 {"return values", 0, 0, tests_log
},
188 {"local", 0, 0, local_log
},
189 {"gearmand", 0, 0, gearmand_tests
},
190 {"memcached", 0, 0, memcached_tests
},
194 static void *world_create(server_startup_st
& servers
, test_return_t
&)
199 void get_world(Framework
*world
)
201 world
->collections
= collection
;
202 world
->_create
= world_create
;