Merge of cppccheck fixes.
[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 std::string testing_service;
55
56 static test_return_t LIBTOOL_COMMAND_test(void *)
57 {
58 test_true(getenv("LIBTOOL_COMMAND"));
59 return TEST_SUCCESS;
60 }
61
62 static test_return_t VALGRIND_COMMAND_test(void *)
63 {
64 test_true(getenv("VALGRIND_COMMAND"));
65 return TEST_SUCCESS;
66 }
67
68 static test_return_t HELGRIND_COMMAND_test(void *)
69 {
70 test_true(getenv("HELGRIND_COMMAND"));
71 return TEST_SUCCESS;
72 }
73
74 static test_return_t GDB_COMMAND_test(void *)
75 {
76 test_true(getenv("GDB_COMMAND"));
77 return TEST_SUCCESS;
78 }
79
80 static test_return_t test_success_equals_one_test(void *)
81 {
82 test_skip(HAVE_LIBMEMCACHED, 1);
83 #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
84 test_zero(MEMCACHED_SUCCESS);
85 #endif
86 return TEST_SUCCESS;
87 }
88
89 static test_return_t test_success_test(void *)
90 {
91 return TEST_SUCCESS;
92 }
93
94 static test_return_t test_failure_test(void *)
95 {
96 return TEST_SKIPPED; // Only run this when debugging
97
98 test_compare(1, 2);
99 return TEST_SUCCESS;
100 }
101
102 static test_return_t local_test(void *)
103 {
104 if (getenv("LIBTEST_LOCAL"))
105 {
106 test_true(test_is_local());
107 }
108 else
109 {
110 test_false(test_is_local());
111 }
112
113 return TEST_SUCCESS;
114 }
115
116 static test_return_t local_not_test(void *)
117 {
118 return TEST_SKIPPED;
119
120 std::string temp;
121
122 const char *ptr;
123 if ((ptr= getenv("LIBTEST_LOCAL")) == NULL)
124 {
125 temp.append(ptr);
126 }
127
128 // unsetenv() will cause issues with valgrind
129 _compare(__FILE__, __LINE__, __func__, 0, unsetenv("LIBTEST_LOCAL"), true);
130 test_compare(0, unsetenv("LIBTEST_LOCAL"));
131 test_false(test_is_local());
132
133 test_compare(0, setenv("LIBTEST_LOCAL", "1", 1));
134 test_true(test_is_local());
135
136 if (temp.empty())
137 {
138 test_compare(0, unsetenv("LIBTEST_LOCAL"));
139 }
140 else
141 {
142 char *old_string= strdup(temp.c_str());
143 test_compare(0, setenv("LIBTEST_LOCAL", old_string, 1));
144 }
145
146 return TEST_SUCCESS;
147 }
148
149 static test_return_t var_exists_test(void *)
150 {
151 test_compare(0, access("var", R_OK | W_OK | X_OK));
152 return TEST_SUCCESS;
153 }
154
155 static test_return_t var_tmp_exists_test(void *)
156 {
157 test_compare(0, access("var/tmp", R_OK | W_OK | X_OK));
158 return TEST_SUCCESS;
159 }
160
161 static test_return_t var_run_exists_test(void *)
162 {
163 test_compare(0, access("var/run", R_OK | W_OK | X_OK));
164 return TEST_SUCCESS;
165 }
166
167 static test_return_t var_log_exists_test(void *)
168 {
169 test_compare(0, access("var/log", R_OK | W_OK | X_OK));
170 return TEST_SUCCESS;
171 }
172
173 static test_return_t var_drizzle_exists_test(void *)
174 {
175 test_compare(0, access("var/drizzle", R_OK | W_OK | X_OK));
176 return TEST_SUCCESS;
177 }
178
179 static test_return_t var_tmp_test(void *)
180 {
181 FILE *file= fopen("var/tmp/junk", "w+");
182 test_true(file);
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 server_startup_TEST(void *object)
330 {
331 server_startup_st *servers= (server_startup_st*)object;
332 test_true(servers);
333
334 test_true(servers->start_server(testing_service, get_free_port(), 0, NULL, true));
335
336 test_true(servers->last());
337 pid_t last_pid= servers->last()->pid();
338
339 test_compare(servers->last()->pid(), last_pid);
340 test_true(last_pid > 1);
341 test_compare(kill(last_pid, 0), 0);
342
343 test_true(servers->shutdown());
344 #if 0
345 test_compare(servers->last()->pid(), -1);
346 test_compare(kill(last_pid, 0), -1);
347 #endif
348
349 return TEST_SUCCESS;
350 }
351
352 static test_return_t socket_server_startup_TEST(void *object)
353 {
354 server_startup_st *servers= (server_startup_st*)object;
355 test_true(servers);
356
357 test_true(servers->start_socket_server(testing_service, get_free_port(), 0, NULL, true));
358
359 return TEST_SUCCESS;
360 }
361
362 static test_return_t memcached_sasl_test(void *object)
363 {
364 server_startup_st *servers= (server_startup_st*)object;
365 test_true(servers);
366
367 test_skip(false, bool(getenv("TESTS_ENVIRONMENT")));
368
369 if (MEMCACHED_SASL_BINARY)
370 {
371 if (HAVE_LIBMEMCACHED)
372 {
373 test_true(has_memcached_sasl());
374 test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 0, NULL));
375
376 return TEST_SUCCESS;
377 }
378 }
379
380 return TEST_SKIPPED;
381 }
382
383 static test_return_t application_true_BINARY(void *)
384 {
385 Application true_app("true");
386
387 test_compare(Application::SUCCESS, true_app.run());
388 test_compare(Application::SUCCESS, true_app.wait());
389
390 return TEST_SUCCESS;
391 }
392
393 static test_return_t application_gdb_true_BINARY2(void *)
394 {
395 test_skip(0, access("/usr/bin/gdb", X_OK ));
396 Application true_app("true");
397 true_app.use_gdb();
398
399 test_compare(Application::SUCCESS, true_app.run());
400 test_compare(Application::SUCCESS, true_app.wait());
401
402 return TEST_SUCCESS;
403 }
404
405 static test_return_t application_gdb_true_BINARY(void *)
406 {
407 test_skip(0, access("/usr/bin/gdb", X_OK ));
408 Application true_app("true");
409 true_app.use_gdb();
410
411 const char *args[]= { "--fubar", 0 };
412 test_compare(Application::SUCCESS, true_app.run(args));
413 test_compare(Application::SUCCESS, true_app.wait());
414
415 return TEST_SUCCESS;
416 }
417
418 static test_return_t application_true_fubar_BINARY(void *)
419 {
420 Application true_app("true");
421
422 const char *args[]= { "--fubar", 0 };
423 test_compare(Application::SUCCESS, true_app.run(args));
424 test_compare(Application::SUCCESS, true_app.wait());
425 test_compare(0, true_app.stdout_result().size());
426
427 return TEST_SUCCESS;
428 }
429
430 static test_return_t application_doesnotexist_BINARY(void *)
431 {
432
433 test_skip_valgrind();
434 Application true_app("doesnotexist");
435 true_app.will_fail();
436
437 const char *args[]= { "--fubar", 0 };
438 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
439 test_compare(Application::INVALID, true_app.run(args));
440 #else
441 test_compare(Application::SUCCESS, true_app.run(args));
442 test_compare(Application::INVALID, true_app.wait(false));
443 #endif
444
445 test_compare(0, true_app.stdout_result().size());
446
447 return TEST_SUCCESS;
448 }
449
450 static test_return_t application_true_fubar_eq_doh_BINARY(void *)
451 {
452 Application true_app("true");
453
454 const char *args[]= { "--fubar=doh", 0 };
455 test_compare(Application::SUCCESS, true_app.run(args));
456 test_compare(Application::SUCCESS, true_app.wait());
457 test_compare(0, true_app.stdout_result().size());
458
459 return TEST_SUCCESS;
460 }
461
462 static test_return_t application_true_fubar_eq_doh_option_BINARY(void *)
463 {
464 Application true_app("true");
465
466 true_app.add_option("--fubar=", "doh");
467
468 test_compare(Application::SUCCESS, true_app.run());
469 test_compare(Application::SUCCESS, true_app.wait());
470 test_compare(0, true_app.stdout_result().size());
471
472 return TEST_SUCCESS;
473 }
474
475
476 static test_return_t GET_TEST(void *)
477 {
478 libtest::http::GET get("http://foo.example.com/");
479
480 test_compare(false, get.execute());
481
482 return TEST_SUCCESS;
483 }
484
485 static test_return_t POST_TEST(void *)
486 {
487 libtest::vchar_t body;
488 libtest::http::POST post("http://foo.example.com/", body);
489
490 test_compare(false, post.execute());
491
492 return TEST_SUCCESS;
493 }
494
495 static test_return_t TRACE_TEST(void *)
496 {
497 libtest::vchar_t body;
498 libtest::http::TRACE trace("http://foo.example.com/", body);
499
500 test_compare(false, trace.execute());
501
502 return TEST_SUCCESS;
503 }
504
505
506 static test_return_t vchar_t_TEST(void *)
507 {
508 libtest::vchar_t response;
509 libtest::make_vector(response, test_literal_param("fubar\n"));
510 test_compare(response, response);
511
512 return TEST_SUCCESS;
513 }
514
515 static test_return_t vchar_t_compare_neg_TEST(void *)
516 {
517 libtest::vchar_t response;
518 libtest::vchar_t response2;
519 libtest::make_vector(response, test_literal_param("fubar\n"));
520 libtest::make_vector(response2, test_literal_param(__func__));
521 test_true(response != response2);
522
523 return TEST_SUCCESS;
524 }
525
526 static test_return_t application_echo_fubar_BINARY(void *)
527 {
528 Application true_app("echo");
529
530 const char *args[]= { "fubar", 0 };
531 test_compare(Application::SUCCESS, true_app.run(args));
532 test_compare(Application::SUCCESS, true_app.wait());
533
534 while (true_app.slurp() == false) {} ;
535
536 libtest::vchar_t response;
537 make_vector(response, test_literal_param("fubar\n"));
538 test_compare(response, true_app.stdout_result());
539
540 return TEST_SUCCESS;
541 }
542
543 static test_return_t application_echo_fubar_BINARY2(void *)
544 {
545 Application true_app("echo");
546
547 true_app.add_option("fubar");
548
549 test_compare(Application::SUCCESS, true_app.run());
550 test_compare(Application::SUCCESS, true_app.wait(false));
551
552 libtest::vchar_t response;
553 make_vector(response, test_literal_param("fubar\n"));
554 test_compare(response, true_app.stdout_result());
555
556 return TEST_SUCCESS;
557 }
558
559 static test_return_t true_BINARY(void *)
560 {
561 const char *args[]= { 0 };
562 test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
563
564 return TEST_SUCCESS;
565 }
566
567 static test_return_t true_fubar_BINARY(void *)
568 {
569 const char *args[]= { "--fubar", 0 };
570 test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
571
572 return TEST_SUCCESS;
573 }
574
575 static test_return_t echo_fubar_BINARY(void *)
576 {
577 const char *args[]= { "fubar", 0 };
578 test_compare(EXIT_SUCCESS, exec_cmdline("echo", args));
579
580 return TEST_SUCCESS;
581 }
582
583 static test_return_t wait_BINARY(void *)
584 {
585 const char *args[]= { "--quiet", 0 };
586
587 test_compare(EXIT_FAILURE, exec_cmdline("libtest/wait", args, true));
588
589 return TEST_SUCCESS;
590 }
591
592 static test_return_t wait_help_BINARY(void *)
593 {
594 const char *args[]= { "--quiet", "--help", 0 };
595
596 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
597
598 return TEST_SUCCESS;
599 }
600
601 static test_return_t wait_version_BINARY(void *)
602 {
603 const char *args[]= { "--quiet", "--version", 0 };
604
605 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
606
607 return TEST_SUCCESS;
608 }
609
610 static test_return_t wait_services_BINARY(void *)
611 {
612 test_skip(0, access("/etc/services", R_OK ));
613
614 const char *args[]= { "--quiet", "/etc/services", 0 };
615
616 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
617
618 return TEST_SUCCESS;
619 }
620
621 static test_return_t wait_services_BINARY2(void *)
622 {
623 test_skip(0, access("/etc/services", R_OK ));
624
625 const char *args[]= { "/etc/services", 0 };
626
627 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
628
629 return TEST_SUCCESS;
630 }
631
632 static test_return_t wait_services_appliction_TEST(void *)
633 {
634 test_skip(0, access("/usr/bin/gdb", X_OK ));
635 test_skip(0, access("/etc/services", R_OK ));
636
637 libtest::Application wait_app("libtest/wait", true);
638 wait_app.use_gdb();
639
640 const char *args[]= { "/etc/services", 0 };
641 test_compare(Application::SUCCESS, wait_app.run(args));
642 test_compare(Application::SUCCESS, wait_app.wait());
643
644 return TEST_SUCCESS;
645 }
646
647 static test_return_t gdb_wait_services_appliction_TEST(void *)
648 {
649 test_skip(true, false);
650 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
651 test_skip(0, TARGET_OS_OSX);
652 #endif
653
654 test_skip(0, access("/usr/bin/gdb", X_OK ));
655 test_skip(0, access("/etc/services", R_OK ));
656
657 libtest::Application wait_app("libtest/wait", true);
658 wait_app.use_gdb();
659
660 const char *args[]= { "/etc/services", 0 };
661 test_compare(Application::SUCCESS, wait_app.run(args));
662 test_compare(Application::SUCCESS, wait_app.wait());
663
664 return TEST_SUCCESS;
665 }
666
667 static test_return_t gdb_abort_services_appliction_TEST(void *)
668 {
669 test_skip(true, false);
670 test_skip(0, access("/usr/bin/gdb", X_OK ));
671
672 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
673 test_skip(0, TARGET_OS_OSX);
674 #endif
675
676 libtest::Application abort_app("libtest/abort", true);
677 abort_app.use_gdb();
678
679 test_compare(Application::SUCCESS, abort_app.run());
680 test_compare(Application::SUCCESS, abort_app.wait());
681
682 std::string gdb_filename= abort_app.gdb_filename();
683 test_skip(0, access(gdb_filename.c_str(), R_OK ));
684 const char *args[]= { "SIGABRT", gdb_filename.c_str(), 0 };
685 test_compare(EXIT_SUCCESS, exec_cmdline("grep", args));
686
687 // Sanity test
688 args[0]= "THIS_WILL_NOT_BE_FOUND";
689 test_compare(EXIT_FAILURE, exec_cmdline("grep", args));
690
691 return TEST_SUCCESS;
692 }
693
694 static test_return_t get_free_port_TEST(void *)
695 {
696 in_port_t ret_port;
697 test_true((ret_port= get_free_port()));
698 test_true(get_free_port() != default_port());
699 test_true(get_free_port() != get_free_port());
700
701 return TEST_SUCCESS;
702 }
703
704 static uint32_t fatal_calls= 0;
705
706 static test_return_t fatal_TEST(void *)
707 {
708 test_compare(fatal_calls++, fatal::disabled_counter());
709 throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Testing va_args based fatal(): %d", 10);
710
711 return TEST_SUCCESS;
712 }
713
714 static test_return_t number_of_cpus_TEST(void *)
715 {
716 test_true(number_of_cpus() >= 1);
717
718 return TEST_SUCCESS;
719 }
720
721 static test_return_t check_dns_TEST(void *)
722 {
723 test_warn(libtest::check_dns(), "Broken DNS server/no DNS server found");
724
725 return TEST_SUCCESS;
726 }
727
728 static test_return_t Timer_TEST(void *)
729 {
730 int64_t minutes= random() % 50;
731 minutes++;
732
733 Timer check;
734
735 check.reset();
736 check.offset(minutes, 2, 200);
737
738 test_compare(check.minutes(), minutes);
739
740 return TEST_SUCCESS;
741 }
742
743 static test_return_t lookup_true_TEST(void *)
744 {
745 test_warn(libtest::lookup("exist.gearman.info"), "dns is not currently working");
746 return TEST_SUCCESS;
747 }
748
749 static test_return_t lookup_false_TEST(void *)
750 {
751 if (libtest::lookup("does_not_exist.gearman.info"))
752 {
753 Error << "Broken DNS server detected";
754 return TEST_SKIPPED;
755 }
756
757 return TEST_SUCCESS;
758 }
759
760 static test_return_t create_tmpfile_TEST(void *)
761 {
762 std::string tmp= create_tmpfile(__func__);
763 test_compare(-1, access(tmp.c_str(), R_OK));
764 test_compare(-1, access(tmp.c_str(), F_OK));
765
766 Application touch_app("touch");
767 const char *args[]= { tmp.c_str(), 0 };
768 test_compare(Application::SUCCESS, touch_app.run(args));
769 test_compare(Application::SUCCESS, touch_app.wait(false));
770
771 test_compare(0, access(tmp.c_str(), R_OK));
772 test_compare(0, unlink(tmp.c_str()));
773
774 return TEST_SUCCESS;
775 }
776
777 static test_return_t fatal_message_TEST(void *)
778 {
779 test_compare(fatal_calls++, fatal::disabled_counter());
780 fatal_message("Fatal test");
781
782 return TEST_SUCCESS;
783 }
784
785 static test_return_t default_port_TEST(void *)
786 {
787 in_port_t ret_port= default_port();
788 test_compare(ret_port, libtest::default_port());
789 test_compare(ret_port, libtest::default_port());
790
791 return TEST_SUCCESS;
792 }
793
794 static test_return_t check_for_gearman(void *)
795 {
796 test_skip(true, HAVE_LIBGEARMAN);
797 test_skip(true, has_gearmand());
798 return TEST_SUCCESS;
799 }
800
801 static test_return_t check_for_drizzle(void *)
802 {
803 test_skip(true, HAVE_LIBDRIZZLE);
804 test_skip(true, has_drizzled());
805 return TEST_SUCCESS;
806 }
807
808
809 test_st drizzled_tests[] ={
810 {"drizzled startup-shutdown", 0, drizzled_cycle_test },
811 {0, 0, 0}
812 };
813
814 test_st gearmand_tests[] ={
815 #if 0
816 {"pause", 0, pause_test },
817 #endif
818 {"gearmand startup-shutdown", 0, gearmand_cycle_test },
819 {"_compare(gearman_return_t)", 0, _compare_gearman_return_t_test },
820 {0, 0, 0}
821 };
822
823 static test_return_t check_for_libmemcached(void* object)
824 {
825 test_skip(true, HAVE_LIBMEMCACHED);
826 test_skip(true, has_memcached());
827
828 server_startup_st *servers= (server_startup_st*)object;
829 test_true(servers);
830 servers->clear();
831
832 testing_service= "memcached";
833
834 return TEST_SUCCESS;
835 }
836
837 test_st memcached_TESTS[] ={
838 {"memcached startup-shutdown", 0, server_startup_TEST },
839 {"memcached(socket file) startup-shutdown", 0, socket_server_startup_TEST },
840 {"_compare(memcached_return_t)", 0, _compare_memcached_return_t_test },
841 {0, 0, 0}
842 };
843
844 test_st test_skip_TESTS[] ={
845 {"true, true", 0, test_skip_true_TEST },
846 {"true, false", 0, test_skip_false_TEST },
847 {0, 0, 0}
848 };
849
850 test_st environment_tests[] ={
851 {"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test },
852 {"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test },
853 {"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test },
854 {"GDB_COMMAND", 0, GDB_COMMAND_test },
855 {0, 0, 0}
856 };
857
858 test_st tests_log[] ={
859 {"TEST_SUCCESS", false, test_success_test },
860 {"TEST_FAILURE", false, test_failure_test },
861 {"TEST_SUCCESS == 0", false, test_success_equals_one_test },
862 {0, 0, 0}
863 };
864
865 test_st local_log[] ={
866 {"test_is_local()", 0, local_test },
867 {"test_is_local(NOT)", 0, local_not_test },
868 {0, 0, 0}
869 };
870
871 test_st directories_tests[] ={
872 {"var exists", 0, var_exists_test },
873 {"var/tmp exists", 0, var_tmp_exists_test },
874 {"var/run exists", 0, var_run_exists_test },
875 {"var/log exists", 0, var_log_exists_test },
876 {"var/drizzle exists", 0, var_drizzle_exists_test },
877 {"var/tmp", 0, var_tmp_test },
878 {"var/run", 0, var_run_test },
879 {"var/log", 0, var_log_test },
880 {"var/drizzle", 0, var_drizzle_test },
881 {"var/tmp rm", 0, var_tmp_rm_test },
882 {"var/run rm", 0, var_run_rm_test },
883 {"var/log rm", 0, var_log_rm_test },
884 {"var/drizzle rm", 0, var_drizzle_rm_test },
885 {0, 0, 0}
886 };
887
888 test_st comparison_tests[] ={
889 {"_compare(test_return_t)", 0, _compare_test_return_t_test },
890 {0, 0, 0}
891 };
892
893 test_st cmdline_tests[] ={
894 {"true", 0, true_BINARY },
895 {"true --fubar", 0, true_fubar_BINARY },
896 {"echo fubar", 0, echo_fubar_BINARY },
897 {"wait --quiet", 0, wait_BINARY },
898 {"wait --quiet --help", 0, wait_help_BINARY },
899 {"wait --quiet --version", 0, wait_version_BINARY },
900 {"wait --quiet /etc/services", 0, wait_services_BINARY },
901 {"wait /etc/services", 0, wait_services_BINARY2 },
902 {"wait /etc/services", 0, wait_services_appliction_TEST },
903 {"gdb wait /etc/services", 0, gdb_wait_services_appliction_TEST },
904 {"gdb abort", 0, gdb_abort_services_appliction_TEST },
905 {0, 0, 0}
906 };
907
908 test_st get_free_port_TESTS[] ={
909 {"get_free_port()", 0, get_free_port_TEST },
910 {"default_port()", 0, default_port_TEST },
911 {0, 0, 0}
912 };
913
914 test_st fatal_message_TESTS[] ={
915 {"libtest::fatal", 0, fatal_TEST },
916 {"fatal_message()", 0, fatal_message_TEST },
917 {0, 0, 0}
918 };
919
920 test_st number_of_cpus_TESTS[] ={
921 {"libtest::number_of_cpus()", 0, number_of_cpus_TEST },
922 {0, 0, 0}
923 };
924
925 test_st create_tmpfile_TESTS[] ={
926 {"libtest::create_tmpfile()", 0, create_tmpfile_TEST },
927 {0, 0, 0}
928 };
929
930 test_st timer_TESTS[] ={
931 {"libtest::Timer", 0, Timer_TEST },
932 {0, 0, 0}
933 };
934
935 test_st dns_TESTS[] ={
936 {"libtest::lookup(true)", 0, lookup_true_TEST },
937 {"libtest::lookup(false)", 0, lookup_false_TEST },
938 {"libtest::check_dns()", 0, check_dns_TEST },
939 {0, 0, 0}
940 };
941
942 test_st application_tests[] ={
943 {"vchar_t", 0, vchar_t_TEST },
944 {"vchar_t compare()", 0, vchar_t_compare_neg_TEST },
945 {"true", 0, application_true_BINARY },
946 {"gbd true --fubar", 0, application_gdb_true_BINARY },
947 {"gbd true", 0, application_gdb_true_BINARY2 },
948 {"true --fubar", 0, application_true_fubar_BINARY },
949 {"doesnotexist --fubar", 0, application_doesnotexist_BINARY },
950 {"true --fubar=doh", 0, application_true_fubar_eq_doh_BINARY },
951 {"true --fubar=doh add_option()", 0, application_true_fubar_eq_doh_option_BINARY },
952 {"echo fubar", 0, application_echo_fubar_BINARY },
953 {"echo fubar (as option)", 0, application_echo_fubar_BINARY2 },
954 {0, 0, 0}
955 };
956
957 static test_return_t check_for_curl(void *)
958 {
959 test_skip(true, HAVE_LIBCURL);
960 return TEST_SUCCESS;
961 }
962
963 static test_return_t disable_fatal_exception(void *)
964 {
965 fatal::disable();
966 return TEST_SUCCESS;
967 }
968
969 static test_return_t enable_fatal_exception(void *)
970 {
971 fatal::disable();
972 return TEST_SUCCESS;
973 }
974
975 test_st http_tests[] ={
976 {"GET", 0, GET_TEST },
977 {"POST", 0, POST_TEST },
978 {"TRACE", 0, TRACE_TEST },
979 {0, 0, 0}
980 };
981
982 collection_st collection[] ={
983 {"environment", 0, 0, environment_tests},
984 {"return values", 0, 0, tests_log},
985 {"test_skip()", 0, 0, test_skip_TESTS },
986 {"local", 0, 0, local_log},
987 {"directories", 0, 0, directories_tests},
988 {"comparison", 0, 0, comparison_tests},
989 {"gearmand", check_for_gearman, 0, gearmand_tests},
990 {"memcached", check_for_libmemcached, 0, memcached_TESTS },
991 {"drizzled", check_for_drizzle, 0, drizzled_tests},
992 {"cmdline", 0, 0, cmdline_tests},
993 {"application", 0, 0, application_tests},
994 {"http", check_for_curl, 0, http_tests},
995 {"http", check_for_curl, 0, http_tests},
996 {"get_free_port()", 0, 0, get_free_port_TESTS },
997 {"fatal", disable_fatal_exception, enable_fatal_exception, fatal_message_TESTS },
998 {"number_of_cpus()", 0, 0, number_of_cpus_TESTS },
999 {"create_tmpfile()", 0, 0, create_tmpfile_TESTS },
1000 {"dns", 0, 0, dns_TESTS },
1001 {"libtest::Timer", 0, 0, timer_TESTS },
1002 {0, 0, 0, 0}
1003 };
1004
1005 static void *world_create(server_startup_st& servers, test_return_t&)
1006 {
1007 return &servers;
1008 }
1009
1010 void get_world(Framework *world)
1011 {
1012 world->collections(collection);
1013 world->create(world_create);
1014 }