Fix for test cases to make sure memcached is around.
[m6w6/libmemcached] / libtest / unittest.cc
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Data Differential YATL (i.e. libtest) library
4 *
5 * Copyright (C) 2012 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 #include <config.h>
38
39 #include <libtest/test.hpp>
40
41 #if defined(LIBTEST_WITH_LIBMEMCACHED_SUPPORT) && LIBTEST_WITH_LIBMEMCACHED_SUPPORT
42 #include <libmemcached-1.0/memcached.h>
43 #endif
44
45 #if defined(LIBTEST_WITH_LIBGEARMAN_SUPPORT) && LIBTEST_WITH_LIBGEARMAN_SUPPORT
46 #include <libgearman/gearman.h>
47 #endif
48
49 #include <cstdlib>
50 #include <unistd.h>
51
52 using namespace libtest;
53
54 static test_return_t LIBTOOL_COMMAND_test(void *)
55 {
56 test_true(getenv("LIBTOOL_COMMAND"));
57 return TEST_SUCCESS;
58 }
59
60 static test_return_t VALGRIND_COMMAND_test(void *)
61 {
62 test_true(getenv("VALGRIND_COMMAND"));
63 return TEST_SUCCESS;
64 }
65
66 static test_return_t HELGRIND_COMMAND_test(void *)
67 {
68 test_true(getenv("HELGRIND_COMMAND"));
69 return TEST_SUCCESS;
70 }
71
72 static test_return_t GDB_COMMAND_test(void *)
73 {
74 test_true(getenv("GDB_COMMAND"));
75 return TEST_SUCCESS;
76 }
77
78 static test_return_t test_success_equals_one_test(void *)
79 {
80 test_skip(HAVE_LIBMEMCACHED, 1);
81 #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
82 test_zero(MEMCACHED_SUCCESS);
83 #endif
84 return TEST_SUCCESS;
85 }
86
87 static test_return_t test_success_test(void *)
88 {
89 return TEST_SUCCESS;
90 }
91
92 static test_return_t test_failure_test(void *)
93 {
94 return TEST_SKIPPED; // Only run this when debugging
95
96 test_compare(1, 2);
97 return TEST_SUCCESS;
98 }
99
100 static test_return_t local_test(void *)
101 {
102 if (getenv("LIBTEST_LOCAL"))
103 {
104 test_true(test_is_local());
105 }
106 else
107 {
108 test_false(test_is_local());
109 }
110
111 return TEST_SUCCESS;
112 }
113
114 static test_return_t local_not_test(void *)
115 {
116 return TEST_SKIPPED;
117
118 std::string temp;
119
120 const char *ptr;
121 if ((ptr= getenv("LIBTEST_LOCAL")) == NULL)
122 {
123 temp.append(ptr);
124 }
125
126 // unsetenv() will cause issues with valgrind
127 _compare(__FILE__, __LINE__, __func__, 0, unsetenv("LIBTEST_LOCAL"), true);
128 test_compare(0, unsetenv("LIBTEST_LOCAL"));
129 test_false(test_is_local());
130
131 test_compare(0, setenv("LIBTEST_LOCAL", "1", 1));
132 test_true(test_is_local());
133
134 if (temp.empty())
135 {
136 test_compare(0, unsetenv("LIBTEST_LOCAL"));
137 }
138 else
139 {
140 char *old_string= strdup(temp.c_str());
141 test_compare(0, setenv("LIBTEST_LOCAL", old_string, 1));
142 }
143
144 return TEST_SUCCESS;
145 }
146
147 static test_return_t var_exists_test(void *)
148 {
149 test_compare(0, access("var", R_OK | W_OK | X_OK));
150 return TEST_SUCCESS;
151 }
152
153 static test_return_t var_tmp_exists_test(void *)
154 {
155 test_compare(0, access("var/tmp", R_OK | W_OK | X_OK));
156 return TEST_SUCCESS;
157 }
158
159 static test_return_t var_run_exists_test(void *)
160 {
161 test_compare(0, access("var/run", R_OK | W_OK | X_OK));
162 return TEST_SUCCESS;
163 }
164
165 static test_return_t var_log_exists_test(void *)
166 {
167 test_compare(0, access("var/log", R_OK | W_OK | X_OK));
168 return TEST_SUCCESS;
169 }
170
171 static test_return_t var_drizzle_exists_test(void *)
172 {
173 test_compare(0, access("var/drizzle", R_OK | W_OK | X_OK));
174 return TEST_SUCCESS;
175 }
176
177 static test_return_t var_tmp_test(void *)
178 {
179 FILE *file= fopen("var/tmp/junk", "w+");
180 char buffer[1024];
181 const char *dir= getcwd(buffer, sizeof(buffer));
182 test_true_got(file, dir);
183 fclose(file);
184 return TEST_SUCCESS;
185 }
186
187 static test_return_t var_run_test(void *)
188 {
189 FILE *file= fopen("var/run/junk", "w+");
190 test_true(file);
191 fclose(file);
192 return TEST_SUCCESS;
193 }
194
195 static test_return_t var_log_test(void *)
196 {
197 FILE *file= fopen("var/log/junk", "w+");
198 test_true(file);
199 fclose(file);
200 return TEST_SUCCESS;
201 }
202
203 static test_return_t var_drizzle_test(void *)
204 {
205 FILE *file= fopen("var/drizzle/junk", "w+");
206 test_true(file);
207 fclose(file);
208 return TEST_SUCCESS;
209 }
210
211 static test_return_t var_tmp_rm_test(void *)
212 {
213 test_true(unlink("var/tmp/junk") == 0);
214 return TEST_SUCCESS;
215 }
216
217 static test_return_t var_run_rm_test(void *)
218 {
219 test_true(unlink("var/run/junk") == 0);
220 return TEST_SUCCESS;
221 }
222
223 static test_return_t var_log_rm_test(void *)
224 {
225 test_true(unlink("var/log/junk") == 0);
226 return TEST_SUCCESS;
227 }
228
229 static test_return_t var_drizzle_rm_test(void *)
230 {
231 test_true(unlink("var/drizzle/junk") == 0);
232 return TEST_SUCCESS;
233 }
234
235 static test_return_t _compare_test_return_t_test(void *)
236 {
237 test_compare(TEST_SUCCESS, TEST_SUCCESS);
238
239 return TEST_SUCCESS;
240 }
241
242 static test_return_t _compare_memcached_return_t_test(void *)
243 {
244 test_skip(HAVE_LIBMEMCACHED, true);
245 #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
246 test_compare(MEMCACHED_SUCCESS, MEMCACHED_SUCCESS);
247 #endif
248
249 return TEST_SUCCESS;
250 }
251
252 static test_return_t _compare_gearman_return_t_test(void *)
253 {
254 test_skip(HAVE_LIBGEARMAN, true);
255 #if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
256 test_compare(GEARMAN_SUCCESS, GEARMAN_SUCCESS);
257 #endif
258
259 return TEST_SUCCESS;
260 }
261
262 static test_return_t drizzled_cycle_test(void *object)
263 {
264 server_startup_st *servers= (server_startup_st*)object;
265 test_true(servers and servers->validate());
266
267 #if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
268 test_true(has_drizzled());
269 #endif
270
271 test_skip(true, has_drizzled());
272
273 test_true(server_startup(*servers, "drizzled", get_free_port(), 0, NULL));
274
275 return TEST_SUCCESS;
276 }
277
278 static test_return_t gearmand_cycle_test(void *object)
279 {
280 server_startup_st *servers= (server_startup_st*)object;
281 test_true(servers and servers->validate());
282
283 #if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
284 test_true(has_gearmand());
285 #endif
286
287 test_skip(true, has_gearmand());
288
289 test_true(server_startup(*servers, "gearmand", get_free_port(), 0, NULL));
290
291 return TEST_SUCCESS;
292 }
293
294 static test_return_t memcached_light_cycle_TEST(void *object)
295 {
296 server_startup_st *servers= (server_startup_st*)object;
297 test_true(servers);
298
299 test_skip(true, bool(HAVE_MEMCACHED_LIGHT_BINARY));
300
301 test_true(server_startup(*servers, "memcached-light", get_free_port(), 0, NULL));
302
303 return TEST_SUCCESS;
304 }
305
306 static test_return_t skip_shim(bool a, bool b)
307 {
308 test_skip(a, b);
309 return TEST_SUCCESS;
310 }
311
312 static test_return_t test_skip_true_TEST(void *object)
313 {
314 test_compare(true, true);
315 test_compare(false, false);
316 test_compare(TEST_SUCCESS, skip_shim(true, true));
317 test_compare(TEST_SUCCESS, skip_shim(false, false));
318
319 return TEST_SUCCESS;
320 }
321
322 static test_return_t test_skip_false_TEST(void *object)
323 {
324 test_compare(TEST_SKIPPED, skip_shim(true, false));
325 test_compare(TEST_SKIPPED, skip_shim(false, true));
326 return TEST_SUCCESS;
327 }
328
329 static test_return_t memcached_cycle_test(void *object)
330 {
331 server_startup_st *servers= (server_startup_st*)object;
332 test_true(servers);
333
334 if (MEMCACHED_BINARY and HAVE_LIBMEMCACHED)
335 {
336 test_true(has_memcached());
337 test_true(server_startup(*servers, "memcached", get_free_port(), 0, NULL));
338
339 return TEST_SUCCESS;
340 }
341
342 return TEST_SKIPPED;
343 }
344
345 static test_return_t memcached_socket_cycle_test(void *object)
346 {
347 server_startup_st *servers= (server_startup_st*)object;
348 test_true(servers);
349
350 if (MEMCACHED_BINARY)
351 {
352 if (HAVE_LIBMEMCACHED)
353 {
354 test_true(has_memcached());
355 test_true(servers->start_socket_server("memcached", get_free_port(), 0, NULL));
356
357 return TEST_SUCCESS;
358 }
359 }
360
361 return TEST_SKIPPED;
362 }
363
364 static test_return_t memcached_sasl_test(void *object)
365 {
366 server_startup_st *servers= (server_startup_st*)object;
367 test_true(servers);
368
369 test_skip(false, bool(getenv("TESTS_ENVIRONMENT")));
370
371 if (MEMCACHED_SASL_BINARY)
372 {
373 if (HAVE_LIBMEMCACHED)
374 {
375 test_true(has_memcached_sasl());
376 test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 0, NULL));
377
378 return TEST_SUCCESS;
379 }
380 }
381
382 return TEST_SKIPPED;
383 }
384
385 static test_return_t application_true_BINARY(void *)
386 {
387 Application true_app("true");
388
389 test_compare(Application::SUCCESS, true_app.run());
390 test_compare(Application::SUCCESS, true_app.wait());
391
392 return TEST_SUCCESS;
393 }
394
395 static test_return_t application_gdb_true_BINARY2(void *)
396 {
397 test_skip(0, access("/usr/bin/gdb", X_OK ));
398 Application true_app("true");
399 true_app.use_gdb();
400
401 test_compare(Application::SUCCESS, true_app.run());
402 test_compare(Application::SUCCESS, true_app.wait());
403
404 return TEST_SUCCESS;
405 }
406
407 static test_return_t application_gdb_true_BINARY(void *)
408 {
409 test_skip(0, access("/usr/bin/gdb", X_OK ));
410 Application true_app("true");
411 true_app.use_gdb();
412
413 const char *args[]= { "--fubar", 0 };
414 test_compare(Application::SUCCESS, true_app.run(args));
415 test_compare(Application::SUCCESS, true_app.wait());
416
417 return TEST_SUCCESS;
418 }
419
420 static test_return_t application_true_fubar_BINARY(void *)
421 {
422 Application true_app("true");
423
424 const char *args[]= { "--fubar", 0 };
425 test_compare(Application::SUCCESS, true_app.run(args));
426 test_compare(Application::SUCCESS, true_app.wait());
427 test_compare(0, true_app.stdout_result().size());
428
429 return TEST_SUCCESS;
430 }
431
432 static test_return_t application_doesnotexist_BINARY(void *)
433 {
434
435 test_skip_valgrind();
436 Application true_app("doesnotexist");
437 true_app.will_fail();
438
439 const char *args[]= { "--fubar", 0 };
440 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
441 test_compare(Application::INVALID, true_app.run(args));
442 #else
443 test_compare(Application::SUCCESS, true_app.run(args));
444 test_compare(Application::INVALID, true_app.wait(false));
445 #endif
446
447 test_compare(0, true_app.stdout_result().size());
448
449 return TEST_SUCCESS;
450 }
451
452 static test_return_t application_true_fubar_eq_doh_BINARY(void *)
453 {
454 Application true_app("true");
455
456 const char *args[]= { "--fubar=doh", 0 };
457 test_compare(Application::SUCCESS, true_app.run(args));
458 test_compare(Application::SUCCESS, true_app.wait());
459 test_compare(0, true_app.stdout_result().size());
460
461 return TEST_SUCCESS;
462 }
463
464 static test_return_t application_true_fubar_eq_doh_option_BINARY(void *)
465 {
466 Application true_app("true");
467
468 true_app.add_option("--fubar=", "doh");
469
470 test_compare(Application::SUCCESS, true_app.run());
471 test_compare(Application::SUCCESS, true_app.wait());
472 test_compare(0, true_app.stdout_result().size());
473
474 return TEST_SUCCESS;
475 }
476
477
478 static test_return_t GET_TEST(void *)
479 {
480 libtest::http::GET get("http://foo.example.com/");
481
482 test_compare(false, get.execute());
483
484 return TEST_SUCCESS;
485 }
486
487 static test_return_t POST_TEST(void *)
488 {
489 libtest::vchar_t body;
490 libtest::http::POST post("http://foo.example.com/", body);
491
492 test_compare(false, post.execute());
493
494 return TEST_SUCCESS;
495 }
496
497 static test_return_t TRACE_TEST(void *)
498 {
499 libtest::vchar_t body;
500 libtest::http::TRACE trace("http://foo.example.com/", body);
501
502 test_compare(false, trace.execute());
503
504 return TEST_SUCCESS;
505 }
506
507
508 static test_return_t vchar_t_TEST(void *)
509 {
510 libtest::vchar_t response;
511 libtest::make_vector(response, test_literal_param("fubar\n"));
512 test_compare(response, response);
513
514 return TEST_SUCCESS;
515 }
516
517 static test_return_t vchar_t_compare_neg_TEST(void *)
518 {
519 libtest::vchar_t response;
520 libtest::vchar_t response2;
521 libtest::make_vector(response, test_literal_param("fubar\n"));
522 libtest::make_vector(response2, test_literal_param(__func__));
523 test_true(response != response2);
524
525 return TEST_SUCCESS;
526 }
527
528 static test_return_t application_echo_fubar_BINARY(void *)
529 {
530 Application true_app("echo");
531
532 const char *args[]= { "fubar", 0 };
533 test_compare(Application::SUCCESS, true_app.run(args));
534 test_compare(Application::SUCCESS, true_app.wait());
535
536 while (true_app.slurp() == false) {} ;
537
538 libtest::vchar_t response;
539 make_vector(response, test_literal_param("fubar\n"));
540 test_compare(response, true_app.stdout_result());
541
542 return TEST_SUCCESS;
543 }
544
545 static test_return_t application_echo_fubar_BINARY2(void *)
546 {
547 Application true_app("echo");
548
549 true_app.add_option("fubar");
550
551 test_compare(Application::SUCCESS, true_app.run());
552 test_compare(Application::SUCCESS, true_app.wait(false));
553
554 libtest::vchar_t response;
555 make_vector(response, test_literal_param("fubar\n"));
556 test_compare(response, true_app.stdout_result());
557
558 return TEST_SUCCESS;
559 }
560
561 static test_return_t true_BINARY(void *)
562 {
563 const char *args[]= { 0 };
564 test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
565
566 return TEST_SUCCESS;
567 }
568
569 static test_return_t true_fubar_BINARY(void *)
570 {
571 const char *args[]= { "--fubar", 0 };
572 test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
573
574 return TEST_SUCCESS;
575 }
576
577 static test_return_t echo_fubar_BINARY(void *)
578 {
579 const char *args[]= { "fubar", 0 };
580 test_compare(EXIT_SUCCESS, exec_cmdline("echo", args));
581
582 return TEST_SUCCESS;
583 }
584
585 static test_return_t wait_BINARY(void *)
586 {
587 const char *args[]= { "--quiet", 0 };
588
589 test_compare(EXIT_FAILURE, exec_cmdline("libtest/wait", args, true));
590
591 return TEST_SUCCESS;
592 }
593
594 static test_return_t wait_help_BINARY(void *)
595 {
596 const char *args[]= { "--quiet", "--help", 0 };
597
598 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
599
600 return TEST_SUCCESS;
601 }
602
603 static test_return_t wait_version_BINARY(void *)
604 {
605 const char *args[]= { "--quiet", "--version", 0 };
606
607 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
608
609 return TEST_SUCCESS;
610 }
611
612 static test_return_t wait_services_BINARY(void *)
613 {
614 test_skip(0, access("/etc/services", R_OK ));
615
616 const char *args[]= { "--quiet", "/etc/services", 0 };
617
618 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
619
620 return TEST_SUCCESS;
621 }
622
623 static test_return_t wait_services_BINARY2(void *)
624 {
625 test_skip(0, access("/etc/services", R_OK ));
626
627 const char *args[]= { "/etc/services", 0 };
628
629 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
630
631 return TEST_SUCCESS;
632 }
633
634 static test_return_t wait_services_appliction_TEST(void *)
635 {
636 test_skip(0, access("/usr/bin/gdb", X_OK ));
637 test_skip(0, access("/etc/services", R_OK ));
638
639 libtest::Application wait_app("libtest/wait", true);
640 wait_app.use_gdb();
641
642 const char *args[]= { "/etc/services", 0 };
643 test_compare(Application::SUCCESS, wait_app.run(args));
644 test_compare(Application::SUCCESS, wait_app.wait());
645
646 return TEST_SUCCESS;
647 }
648
649 static test_return_t gdb_wait_services_appliction_TEST(void *)
650 {
651 test_skip(true, false);
652 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
653 test_skip(0, TARGET_OS_OSX);
654 #endif
655
656 test_skip(0, access("/usr/bin/gdb", X_OK ));
657 test_skip(0, access("/etc/services", R_OK ));
658
659 libtest::Application wait_app("libtest/wait", true);
660 wait_app.use_gdb();
661
662 const char *args[]= { "/etc/services", 0 };
663 test_compare(Application::SUCCESS, wait_app.run(args));
664 test_compare(Application::SUCCESS, wait_app.wait());
665
666 return TEST_SUCCESS;
667 }
668
669 static test_return_t gdb_abort_services_appliction_TEST(void *)
670 {
671 test_skip(true, false);
672 test_skip(0, access("/usr/bin/gdb", X_OK ));
673
674 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
675 test_skip(0, TARGET_OS_OSX);
676 #endif
677
678 libtest::Application abort_app("libtest/abort", true);
679 abort_app.use_gdb();
680
681 test_compare(Application::SUCCESS, abort_app.run());
682 test_compare(Application::SUCCESS, abort_app.wait());
683
684 std::string gdb_filename= abort_app.gdb_filename();
685 test_skip(0, access(gdb_filename.c_str(), R_OK ));
686 const char *args[]= { "SIGABRT", gdb_filename.c_str(), 0 };
687 test_compare(EXIT_SUCCESS, exec_cmdline("grep", args));
688
689 // Sanity test
690 args[0]= "THIS_WILL_NOT_BE_FOUND";
691 test_compare(EXIT_FAILURE, exec_cmdline("grep", args));
692
693 return TEST_SUCCESS;
694 }
695
696 static test_return_t get_free_port_TEST(void *)
697 {
698 in_port_t ret_port;
699 test_true_hint((ret_port= get_free_port()), ret_port);
700 test_true(get_free_port() != default_port());
701 test_true(get_free_port() != get_free_port());
702
703 return TEST_SUCCESS;
704 }
705
706 static uint32_t fatal_calls= 0;
707
708 static test_return_t fatal_TEST(void *)
709 {
710 test_compare(fatal_calls++, fatal::disabled_counter());
711 throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Testing va_args based fatal(): %d", 10);
712
713 return TEST_SUCCESS;
714 }
715
716 static test_return_t number_of_cpus_TEST(void *)
717 {
718 test_true(number_of_cpus() >= 1);
719
720 return TEST_SUCCESS;
721 }
722
723 static test_return_t create_tmpfile_TEST(void *)
724 {
725 std::string tmp= create_tmpfile(__func__);
726 test_compare(-1, access(tmp.c_str(), R_OK));
727 test_compare(-1, access(tmp.c_str(), F_OK));
728
729 Application touch_app("touch");
730 const char *args[]= { tmp.c_str(), 0 };
731 test_compare(Application::SUCCESS, touch_app.run(args));
732 test_compare(Application::SUCCESS, touch_app.wait(false));
733
734 test_compare_hint(0, access(tmp.c_str(), R_OK), strerror(errno));
735 test_compare_hint(0, unlink(tmp.c_str()), strerror(errno));
736
737 return TEST_SUCCESS;
738 }
739
740 static test_return_t fatal_message_TEST(void *)
741 {
742 test_compare(fatal_calls++, fatal::disabled_counter());
743 fatal_message("Fatal test");
744
745 return TEST_SUCCESS;
746 }
747
748 static test_return_t default_port_TEST(void *)
749 {
750 in_port_t ret_port= default_port();
751 test_compare(ret_port, libtest::default_port());
752 test_compare(ret_port, libtest::default_port());
753
754 return TEST_SUCCESS;
755 }
756
757 static test_return_t check_for_gearman(void *)
758 {
759 test_skip(true, HAVE_LIBGEARMAN);
760 test_skip(true, has_gearmand());
761 return TEST_SUCCESS;
762 }
763
764 static test_return_t check_for_drizzle(void *)
765 {
766 test_skip(true, HAVE_LIBDRIZZLE);
767 test_skip(true, has_drizzled());
768 return TEST_SUCCESS;
769 }
770
771
772 test_st drizzled_tests[] ={
773 {"drizzled startup-shutdown", 0, drizzled_cycle_test },
774 {0, 0, 0}
775 };
776
777 test_st gearmand_tests[] ={
778 #if 0
779 {"pause", 0, pause_test },
780 #endif
781 {"gearmand startup-shutdown", 0, gearmand_cycle_test },
782 {"_compare(gearman_return_t)", 0, _compare_gearman_return_t_test },
783 {0, 0, 0}
784 };
785
786 static test_return_t check_for_libmemcached(void *)
787 {
788 test_skip(true, HAVE_LIBMEMCACHED);
789 test_skip(true, has_memcached());
790 return TEST_SUCCESS;
791 }
792
793 test_st memcached_tests[] ={
794 {"memcached startup-shutdown", 0, memcached_cycle_test },
795 {"memcached-light startup-shutdown", 0, memcached_light_cycle_TEST },
796 {"memcached(socket file) startup-shutdown", 0, memcached_socket_cycle_test },
797 {"memcached_sasl() startup-shutdown", 0, memcached_sasl_test },
798 {"_compare(memcached_return_t)", 0, _compare_memcached_return_t_test },
799 {0, 0, 0}
800 };
801
802 test_st test_skip_TESTS[] ={
803 {"true, true", 0, test_skip_true_TEST },
804 {"true, false", 0, test_skip_false_TEST },
805 {0, 0, 0}
806 };
807
808 test_st environment_tests[] ={
809 {"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test },
810 {"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test },
811 {"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test },
812 {"GDB_COMMAND", 0, GDB_COMMAND_test },
813 {0, 0, 0}
814 };
815
816 test_st tests_log[] ={
817 {"TEST_SUCCESS", false, test_success_test },
818 {"TEST_FAILURE", false, test_failure_test },
819 {"TEST_SUCCESS == 0", false, test_success_equals_one_test },
820 {0, 0, 0}
821 };
822
823 test_st local_log[] ={
824 {"test_is_local()", 0, local_test },
825 {"test_is_local(NOT)", 0, local_not_test },
826 {0, 0, 0}
827 };
828
829 test_st directories_tests[] ={
830 {"var exists", 0, var_exists_test },
831 {"var/tmp exists", 0, var_tmp_exists_test },
832 {"var/run exists", 0, var_run_exists_test },
833 {"var/log exists", 0, var_log_exists_test },
834 {"var/drizzle exists", 0, var_drizzle_exists_test },
835 {"var/tmp", 0, var_tmp_test },
836 {"var/run", 0, var_run_test },
837 {"var/log", 0, var_log_test },
838 {"var/drizzle", 0, var_drizzle_test },
839 {"var/tmp rm", 0, var_tmp_rm_test },
840 {"var/run rm", 0, var_run_rm_test },
841 {"var/log rm", 0, var_log_rm_test },
842 {"var/drizzle rm", 0, var_drizzle_rm_test },
843 {0, 0, 0}
844 };
845
846 test_st comparison_tests[] ={
847 {"_compare(test_return_t)", 0, _compare_test_return_t_test },
848 {0, 0, 0}
849 };
850
851 test_st cmdline_tests[] ={
852 {"true", 0, true_BINARY },
853 {"true --fubar", 0, true_fubar_BINARY },
854 {"echo fubar", 0, echo_fubar_BINARY },
855 {"wait --quiet", 0, wait_BINARY },
856 {"wait --quiet --help", 0, wait_help_BINARY },
857 {"wait --quiet --version", 0, wait_version_BINARY },
858 {"wait --quiet /etc/services", 0, wait_services_BINARY },
859 {"wait /etc/services", 0, wait_services_BINARY2 },
860 {"wait /etc/services", 0, wait_services_appliction_TEST },
861 {"gdb wait /etc/services", 0, gdb_wait_services_appliction_TEST },
862 {"gdb abort", 0, gdb_abort_services_appliction_TEST },
863 {0, 0, 0}
864 };
865
866 test_st get_free_port_TESTS[] ={
867 {"get_free_port()", 0, get_free_port_TEST },
868 {"default_port()", 0, default_port_TEST },
869 {0, 0, 0}
870 };
871
872 test_st fatal_message_TESTS[] ={
873 {"libtest::fatal", 0, fatal_TEST },
874 {"fatal_message()", 0, fatal_message_TEST },
875 {0, 0, 0}
876 };
877
878 test_st number_of_cpus_TESTS[] ={
879 {"libtest::number_of_cpus()", 0, number_of_cpus_TEST },
880 {0, 0, 0}
881 };
882
883 test_st create_tmpfile_TESTS[] ={
884 {"libtest::create_tmpfile()", 0, create_tmpfile_TEST },
885 {0, 0, 0}
886 };
887
888 test_st application_tests[] ={
889 {"vchar_t", 0, vchar_t_TEST },
890 {"vchar_t compare()", 0, vchar_t_compare_neg_TEST },
891 {"true", 0, application_true_BINARY },
892 {"gbd true --fubar", 0, application_gdb_true_BINARY },
893 {"gbd true", 0, application_gdb_true_BINARY2 },
894 {"true --fubar", 0, application_true_fubar_BINARY },
895 {"doesnotexist --fubar", 0, application_doesnotexist_BINARY },
896 {"true --fubar=doh", 0, application_true_fubar_eq_doh_BINARY },
897 {"true --fubar=doh add_option()", 0, application_true_fubar_eq_doh_option_BINARY },
898 {"echo fubar", 0, application_echo_fubar_BINARY },
899 {"echo fubar (as option)", 0, application_echo_fubar_BINARY2 },
900 {0, 0, 0}
901 };
902
903 static test_return_t check_for_curl(void *)
904 {
905 test_skip(true, HAVE_LIBCURL);
906 return TEST_SUCCESS;
907 }
908
909 static test_return_t disable_fatal_exception(void *)
910 {
911 fatal::disable();
912 return TEST_SUCCESS;
913 }
914
915 static test_return_t enable_fatal_exception(void *)
916 {
917 fatal::disable();
918 return TEST_SUCCESS;
919 }
920
921 test_st http_tests[] ={
922 {"GET", 0, GET_TEST },
923 {"POST", 0, POST_TEST },
924 {"TRACE", 0, TRACE_TEST },
925 {0, 0, 0}
926 };
927
928 collection_st collection[] ={
929 {"environment", 0, 0, environment_tests},
930 {"return values", 0, 0, tests_log},
931 {"test_skip()", 0, 0, test_skip_TESTS },
932 {"local", 0, 0, local_log},
933 {"directories", 0, 0, directories_tests},
934 {"comparison", 0, 0, comparison_tests},
935 {"gearmand", check_for_gearman, 0, gearmand_tests},
936 {"memcached", check_for_libmemcached, 0, memcached_tests},
937 {"drizzled", check_for_drizzle, 0, drizzled_tests},
938 {"cmdline", 0, 0, cmdline_tests},
939 {"application", 0, 0, application_tests},
940 {"http", check_for_curl, 0, http_tests},
941 {"http", check_for_curl, 0, http_tests},
942 {"get_free_port()", 0, 0, get_free_port_TESTS },
943 {"fatal", disable_fatal_exception, enable_fatal_exception, fatal_message_TESTS },
944 {"number_of_cpus()", 0, 0, number_of_cpus_TESTS },
945 {"create_tmpfile()", 0, 0, create_tmpfile_TESTS },
946 {0, 0, 0, 0}
947 };
948
949 static void *world_create(server_startup_st& servers, test_return_t&)
950 {
951 return &servers;
952 }
953
954 void get_world(Framework *world)
955 {
956 world->collections(collection);
957 world->create(world_create);
958 }