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