Merging bzr://gaz.tangent.org/libmemcached/build/ to Build branch
[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, 1);
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"), true);
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 and servers->validate());
232
233 #if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
234 test_true(has_gearmand_binary());
235 #endif
236
237 test_skip(true, has_gearmand_binary());
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 skip_shim(bool a, bool b)
257 {
258 test_skip(a, b);
259 return TEST_SUCCESS;
260 }
261
262 static test_return_t test_skip_true_TEST(void *object)
263 {
264 test_compare(true, true);
265 test_compare(false, false);
266 test_compare(TEST_SUCCESS, skip_shim(true, true));
267 test_compare(TEST_SUCCESS, skip_shim(false, false));
268
269 return TEST_SUCCESS;
270 }
271
272 static test_return_t test_skip_false_TEST(void *object)
273 {
274 test_compare(TEST_SKIPPED, skip_shim(true, false));
275 test_compare(TEST_SKIPPED, skip_shim(false, true));
276 return TEST_SUCCESS;
277 }
278
279 static test_return_t memcached_cycle_test(void *object)
280 {
281 server_startup_st *servers= (server_startup_st*)object;
282 test_true(servers);
283
284 if (MEMCACHED_BINARY and HAVE_LIBMEMCACHED)
285 {
286 test_true(has_memcached_binary());
287 test_true(server_startup(*servers, "memcached", get_free_port(), 0, NULL));
288
289 return TEST_SUCCESS;
290 }
291
292 return TEST_SKIPPED;
293 }
294
295 static test_return_t memcached_socket_cycle_test(void *object)
296 {
297 server_startup_st *servers= (server_startup_st*)object;
298 test_true(servers);
299
300 if (MEMCACHED_BINARY)
301 {
302 if (HAVE_LIBMEMCACHED)
303 {
304 test_true(has_memcached_binary());
305 test_true(servers->start_socket_server("memcached", get_free_port(), 0, NULL));
306
307 return TEST_SUCCESS;
308 }
309 }
310
311 return TEST_SKIPPED;
312 }
313
314 static test_return_t memcached_sasl_test(void *object)
315 {
316 server_startup_st *servers= (server_startup_st*)object;
317 test_true(servers);
318
319 test_skip(false, bool(getenv("TESTS_ENVIRONMENT")));
320
321 if (MEMCACHED_SASL_BINARY)
322 {
323 if (HAVE_LIBMEMCACHED)
324 {
325 test_true(has_memcached_sasl_binary());
326 test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 0, NULL));
327
328 return TEST_SUCCESS;
329 }
330 }
331
332 return TEST_SKIPPED;
333 }
334
335 static test_return_t application_true_BINARY(void *)
336 {
337 Application true_app("true");
338
339 test_compare(Application::SUCCESS, true_app.run());
340 test_compare(Application::SUCCESS, true_app.wait());
341
342 return TEST_SUCCESS;
343 }
344
345 static test_return_t application_gdb_true_BINARY2(void *)
346 {
347 test_skip(0, access("/usr/bin/gdb", X_OK ));
348 Application true_app("true");
349 true_app.use_gdb();
350
351 test_compare(Application::SUCCESS, true_app.run());
352 test_compare(Application::SUCCESS, true_app.wait());
353
354 return TEST_SUCCESS;
355 }
356
357 static test_return_t application_gdb_true_BINARY(void *)
358 {
359 test_skip(0, access("/usr/bin/gdb", X_OK ));
360 Application true_app("true");
361 true_app.use_gdb();
362
363 const char *args[]= { "--fubar", 0 };
364 test_compare(Application::SUCCESS, true_app.run(args));
365 test_compare(Application::SUCCESS, true_app.wait());
366
367 return TEST_SUCCESS;
368 }
369
370 static test_return_t application_true_fubar_BINARY(void *)
371 {
372 Application true_app("true");
373
374 const char *args[]= { "--fubar", 0 };
375 test_compare(Application::SUCCESS, true_app.run(args));
376 test_compare(Application::SUCCESS, true_app.wait());
377 test_compare(0, true_app.stdout_result().size());
378
379 return TEST_SUCCESS;
380 }
381
382 static test_return_t application_doesnotexist_BINARY(void *)
383 {
384 test_skip_valgrind();
385
386 Application true_app("doesnotexist");
387
388 const char *args[]= { "--fubar", 0 };
389 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
390 test_compare(Application::INVALID, true_app.run(args));
391 test_compare(Application::FAILURE, true_app.wait());
392 #else
393 test_compare(Application::SUCCESS, true_app.run(args));
394 test_compare(Application::INVALID, true_app.wait());
395 #endif
396
397 test_compare(0, true_app.stdout_result().size());
398
399 return TEST_SUCCESS;
400 }
401
402 static test_return_t application_true_fubar_eq_doh_BINARY(void *)
403 {
404 Application true_app("true");
405
406 const char *args[]= { "--fubar=doh", 0 };
407 test_compare(Application::SUCCESS, true_app.run(args));
408 test_compare(Application::SUCCESS, true_app.wait());
409 test_compare(0, true_app.stdout_result().size());
410
411 return TEST_SUCCESS;
412 }
413
414 static test_return_t application_true_fubar_eq_doh_option_BINARY(void *)
415 {
416 Application true_app("true");
417
418 true_app.add_option("--fubar=", "doh");
419
420 test_compare(Application::SUCCESS, true_app.run());
421 test_compare(Application::SUCCESS, true_app.wait());
422 test_compare(0, true_app.stdout_result().size());
423
424 return TEST_SUCCESS;
425 }
426
427
428 static test_return_t GET_TEST(void *)
429 {
430 libtest::http::GET get("http://foo.example.com/");
431
432 test_compare(false, get.execute());
433
434 return TEST_SUCCESS;
435 }
436
437 static test_return_t POST_TEST(void *)
438 {
439 libtest::vchar_t body;
440 libtest::http::POST post("http://foo.example.com/", body);
441
442 test_compare(false, post.execute());
443
444 return TEST_SUCCESS;
445 }
446
447 static test_return_t TRACE_TEST(void *)
448 {
449 libtest::vchar_t body;
450 libtest::http::TRACE trace("http://foo.example.com/", body);
451
452 test_compare(false, trace.execute());
453
454 return TEST_SUCCESS;
455 }
456
457
458 static test_return_t vchar_t_TEST(void *)
459 {
460 libtest::vchar_t response;
461 libtest::make_vector(response, test_literal_param("fubar\n"));
462 test_compare(response, response);
463
464 return TEST_SUCCESS;
465 }
466
467 static test_return_t application_echo_fubar_BINARY(void *)
468 {
469 Application true_app("echo");
470
471 const char *args[]= { "fubar", 0 };
472 test_compare(Application::SUCCESS, true_app.run(args));
473 test_compare(Application::SUCCESS, true_app.wait());
474
475 libtest::vchar_t response;
476 make_vector(response, test_literal_param("fubar\n"));
477 test_compare(response, true_app.stdout_result());
478
479 return TEST_SUCCESS;
480 }
481
482 static test_return_t application_echo_fubar_BINARY2(void *)
483 {
484 Application true_app("echo");
485
486 true_app.add_option("fubar");
487
488 test_compare(Application::SUCCESS, true_app.run());
489 test_compare(Application::SUCCESS, true_app.wait());
490 libtest::vchar_t response;
491 make_vector(response, test_literal_param("fubar\n"));
492 test_compare(response, true_app.stdout_result());
493
494 return TEST_SUCCESS;
495 }
496
497 static test_return_t true_BINARY(void *)
498 {
499 const char *args[]= { 0 };
500 test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
501
502 return TEST_SUCCESS;
503 }
504
505 static test_return_t true_fubar_BINARY(void *)
506 {
507 const char *args[]= { "--fubar", 0 };
508 test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
509
510 return TEST_SUCCESS;
511 }
512
513 static test_return_t echo_fubar_BINARY(void *)
514 {
515 const char *args[]= { "fubar", 0 };
516 test_compare(EXIT_SUCCESS, exec_cmdline("echo", args));
517
518 return TEST_SUCCESS;
519 }
520
521 static test_return_t wait_BINARY(void *)
522 {
523 const char *args[]= { "--quiet", 0 };
524
525 test_compare(EXIT_FAILURE, exec_cmdline("libtest/wait", args, true));
526
527 return TEST_SUCCESS;
528 }
529
530 static test_return_t wait_help_BINARY(void *)
531 {
532 const char *args[]= { "--quiet", "--help", 0 };
533
534 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
535
536 return TEST_SUCCESS;
537 }
538
539 static test_return_t wait_version_BINARY(void *)
540 {
541 const char *args[]= { "--quiet", "--version", 0 };
542
543 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
544
545 return TEST_SUCCESS;
546 }
547
548 static test_return_t wait_services_BINARY(void *)
549 {
550 test_skip(0, access("/etc/services", R_OK ));
551
552 const char *args[]= { "--quiet", "/etc/services", 0 };
553
554 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
555
556 return TEST_SUCCESS;
557 }
558
559 static test_return_t wait_services_BINARY2(void *)
560 {
561 test_skip(0, access("/etc/services", R_OK ));
562
563 const char *args[]= { "/etc/services", 0 };
564
565 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
566
567 return TEST_SUCCESS;
568 }
569
570 static test_return_t wait_services_appliction_TEST(void *)
571 {
572 test_skip(0, access("/usr/bin/gdb", X_OK ));
573 test_skip(0, access("/etc/services", R_OK ));
574
575 libtest::Application wait_app("libtest/wait", true);
576 wait_app.use_gdb();
577
578 const char *args[]= { "/etc/services", 0 };
579 test_compare(Application::SUCCESS, wait_app.run(args));
580 test_compare(Application::SUCCESS, wait_app.wait());
581
582 return TEST_SUCCESS;
583 }
584
585 static test_return_t gdb_wait_services_appliction_TEST(void *)
586 {
587 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
588 test_skip(0, TARGET_OS_OSX);
589 #endif
590
591 test_skip(0, access("/usr/bin/gdb", X_OK ));
592 test_skip(0, access("/etc/services", R_OK ));
593
594 libtest::Application wait_app("libtest/wait", true);
595 wait_app.use_gdb();
596
597 const char *args[]= { "/etc/services", 0 };
598 test_compare(Application::SUCCESS, wait_app.run(args));
599 test_compare(Application::SUCCESS, wait_app.wait());
600
601 return TEST_SUCCESS;
602 }
603
604 static test_return_t gdb_abort_services_appliction_TEST(void *)
605 {
606 test_skip(0, access("/usr/bin/gdb", X_OK ));
607
608 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
609 test_skip(0, TARGET_OS_OSX);
610 #endif
611
612 libtest::Application abort_app("libtest/abort", true);
613 abort_app.use_gdb();
614
615 test_compare(Application::SUCCESS, abort_app.run());
616 test_compare(Application::SUCCESS, abort_app.wait());
617
618 std::string gdb_filename= abort_app.gdb_filename();
619 const char *args[]= { "SIGABRT", gdb_filename.c_str(), 0 };
620 test_compare(EXIT_SUCCESS, exec_cmdline("grep", args));
621
622 // Sanity test
623 args[0]= "THIS_WILL_NOT_BE_FOUND";
624 test_compare(EXIT_FAILURE, exec_cmdline("grep", args));
625
626 return TEST_SUCCESS;
627 }
628
629 static test_return_t get_free_port_TEST(void *)
630 {
631 in_port_t ret_port;
632 test_true_hint((ret_port= get_free_port()), ret_port);
633 test_true(get_free_port() != default_port());
634 test_true(get_free_port() != get_free_port());
635
636 return TEST_SUCCESS;
637 }
638
639 static uint32_t fatal_calls= 0;
640
641 static test_return_t fatal_TEST(void *)
642 {
643 test_compare(fatal_calls++, fatal::disabled_counter());
644 throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Testing va_args based fatal(): %d", 10);
645
646 return TEST_SUCCESS;
647 }
648
649 static test_return_t number_of_cpus_TEST(void *)
650 {
651 test_true(number_of_cpus() >= 1);
652
653 return TEST_SUCCESS;
654 }
655
656 static test_return_t create_tmpfile_TEST(void *)
657 {
658 std::string tmp= create_tmpfile(__func__);
659
660 Application touch_app("touch");
661 const char *args[]= { tmp.c_str(), 0 };
662 test_compare(Application::SUCCESS, touch_app.run(args));
663 test_compare(Application::SUCCESS, touch_app.wait());
664
665 test_compare_hint(0, access(tmp.c_str(), R_OK), strerror(errno));
666 test_compare_hint(0, unlink(tmp.c_str()), strerror(errno));
667
668 return TEST_SUCCESS;
669 }
670
671 static test_return_t fatal_message_TEST(void *)
672 {
673 test_compare(fatal_calls++, fatal::disabled_counter());
674 throw fatal_message("Fatal test");
675
676 return TEST_SUCCESS;
677 }
678
679 static test_return_t default_port_TEST(void *)
680 {
681 in_port_t ret_port= default_port();
682 test_compare(ret_port, libtest::default_port());
683 test_compare(ret_port, libtest::default_port());
684
685 return TEST_SUCCESS;
686 }
687
688 static test_return_t check_for_gearman(void *)
689 {
690 test_skip(true, HAVE_LIBGEARMAN);
691 test_skip(true, has_gearmand_binary());
692 return TEST_SUCCESS;
693 }
694
695
696 test_st gearmand_tests[] ={
697 #if 0
698 {"pause", 0, pause_test },
699 #endif
700 {"gearmand startup-shutdown", 0, gearmand_cycle_test },
701 {"_compare(gearman_return_t)", 0, _compare_gearman_return_t_test },
702 {0, 0, 0}
703 };
704
705 static test_return_t check_for_libmemcached(void *)
706 {
707 test_skip(true, HAVE_LIBMEMCACHED);
708 test_skip(true, has_memcached_binary());
709 return TEST_SUCCESS;
710 }
711
712 test_st memcached_tests[] ={
713 {"memcached startup-shutdown", 0, memcached_cycle_test },
714 {"memcached-light startup-shutdown", 0, memcached_light_cycle_TEST },
715 {"memcached(socket file) startup-shutdown", 0, memcached_socket_cycle_test },
716 {"memcached_sasl() startup-shutdown", 0, memcached_sasl_test },
717 {"_compare(memcached_return_t)", 0, _compare_memcached_return_t_test },
718 {0, 0, 0}
719 };
720
721 test_st test_skip_TESTS[] ={
722 {"true, true", 0, test_skip_true_TEST },
723 {"true, false", 0, test_skip_false_TEST },
724 {0, 0, 0}
725 };
726
727 test_st environment_tests[] ={
728 {"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test },
729 {"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test },
730 {"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test },
731 {"GDB_COMMAND", 0, GDB_COMMAND_test },
732 {0, 0, 0}
733 };
734
735 test_st tests_log[] ={
736 {"TEST_SUCCESS", false, test_success_test },
737 {"TEST_FAILURE", false, test_failure_test },
738 {"TEST_SUCCESS == 0", false, test_success_equals_one_test },
739 {0, 0, 0}
740 };
741
742 test_st local_log[] ={
743 {"test_is_local()", 0, local_test },
744 {"test_is_local(NOT)", 0, local_not_test },
745 {0, 0, 0}
746 };
747
748 test_st directories_tests[] ={
749 {"var exists", 0, var_exists_test },
750 {"var/tmp exists", 0, var_tmp_exists_test },
751 {"var/run exists", 0, var_run_exists_test },
752 {"var/log exists", 0, var_log_exists_test },
753 {"var/tmp", 0, var_tmp_test },
754 {"var/run", 0, var_run_test },
755 {"var/log", 0, var_log_test },
756 {"var/tmp rm", 0, var_tmp_rm_test },
757 {"var/run rm", 0, var_run_rm_test },
758 {"var/log rm", 0, var_log_rm_test },
759 {0, 0, 0}
760 };
761
762 test_st comparison_tests[] ={
763 {"_compare(test_return_t)", 0, _compare_test_return_t_test },
764 {0, 0, 0}
765 };
766
767 test_st cmdline_tests[] ={
768 {"true", 0, true_BINARY },
769 {"true --fubar", 0, true_fubar_BINARY },
770 {"echo fubar", 0, echo_fubar_BINARY },
771 {"wait --quiet", 0, wait_BINARY },
772 {"wait --quiet --help", 0, wait_help_BINARY },
773 {"wait --quiet --version", 0, wait_version_BINARY },
774 {"wait --quiet /etc/services", 0, wait_services_BINARY },
775 {"wait /etc/services", 0, wait_services_BINARY2 },
776 {"wait /etc/services", 0, wait_services_appliction_TEST },
777 {"gdb wait /etc/services", 0, gdb_wait_services_appliction_TEST },
778 {"gdb abort", 0, gdb_abort_services_appliction_TEST },
779 {0, 0, 0}
780 };
781
782 test_st get_free_port_TESTS[] ={
783 {"get_free_port()", 0, get_free_port_TEST },
784 {"default_port()", 0, default_port_TEST },
785 {0, 0, 0}
786 };
787
788 test_st fatal_message_TESTS[] ={
789 {"libtest::fatal", 0, fatal_TEST },
790 {"fatal_message()", 0, fatal_message_TEST },
791 {0, 0, 0}
792 };
793
794 test_st number_of_cpus_TESTS[] ={
795 {"libtest::number_of_cpus()", 0, number_of_cpus_TEST },
796 {0, 0, 0}
797 };
798
799 test_st create_tmpfile_TESTS[] ={
800 {"libtest::create_tmpfile()", 0, create_tmpfile_TEST },
801 {0, 0, 0}
802 };
803
804 test_st application_tests[] ={
805 {"vchar_t", 0, vchar_t_TEST },
806 {"true", 0, application_true_BINARY },
807 {"gbd true --fubar", 0, application_gdb_true_BINARY },
808 {"gbd true", 0, application_gdb_true_BINARY2 },
809 {"true --fubar", 0, application_true_fubar_BINARY },
810 {"doesnotexist --fubar", 0, application_doesnotexist_BINARY },
811 {"true --fubar=doh", 0, application_true_fubar_eq_doh_BINARY },
812 {"true --fubar=doh add_option()", 0, application_true_fubar_eq_doh_option_BINARY },
813 {"echo fubar", 0, application_echo_fubar_BINARY },
814 {"echo fubar (as option)", 0, application_echo_fubar_BINARY2 },
815 {0, 0, 0}
816 };
817
818 static test_return_t check_for_curl(void *)
819 {
820 test_skip(true, HAVE_LIBCURL);
821 return TEST_SUCCESS;
822 }
823
824 static test_return_t disable_fatal_exception(void *)
825 {
826 fatal::disable();
827 return TEST_SUCCESS;
828 }
829
830 static test_return_t enable_fatal_exception(void *)
831 {
832 fatal::disable();
833 return TEST_SUCCESS;
834 }
835
836 test_st http_tests[] ={
837 {"GET", 0, GET_TEST },
838 {"POST", 0, POST_TEST },
839 {"TRACE", 0, TRACE_TEST },
840 {0, 0, 0}
841 };
842
843 collection_st collection[] ={
844 {"environment", 0, 0, environment_tests},
845 {"return values", 0, 0, tests_log},
846 {"test_skip()", 0, 0, test_skip_TESTS },
847 {"local", 0, 0, local_log},
848 {"directories", 0, 0, directories_tests},
849 {"comparison", 0, 0, comparison_tests},
850 {"gearmand", check_for_gearman, 0, gearmand_tests},
851 {"memcached", check_for_libmemcached, 0, memcached_tests},
852 {"cmdline", 0, 0, cmdline_tests},
853 {"application", 0, 0, application_tests},
854 {"http", check_for_curl, 0, http_tests},
855 {"get_free_port()", 0, 0, get_free_port_TESTS },
856 {"fatal", disable_fatal_exception, enable_fatal_exception, fatal_message_TESTS },
857 {"number_of_cpus()", 0, 0, number_of_cpus_TESTS },
858 {"create_tmpfile()", 0, 0, create_tmpfile_TESTS },
859 {0, 0, 0, 0}
860 };
861
862 static void *world_create(server_startup_st& servers, test_return_t&)
863 {
864 return &servers;
865 }
866
867 void get_world(Framework *world)
868 {
869 world->collections= collection;
870 world->_create= world_create;
871 }