Merge from built to trunk
[awesomized/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 char buffer[1024];
183 test_true(file);
184 fclose(file);
185 return TEST_SUCCESS;
186 }
187
188 static test_return_t var_run_test(void *)
189 {
190 FILE *file= fopen("var/run/junk", "w+");
191 test_true(file);
192 fclose(file);
193 return TEST_SUCCESS;
194 }
195
196 static test_return_t var_log_test(void *)
197 {
198 FILE *file= fopen("var/log/junk", "w+");
199 test_true(file);
200 fclose(file);
201 return TEST_SUCCESS;
202 }
203
204 static test_return_t var_drizzle_test(void *)
205 {
206 FILE *file= fopen("var/drizzle/junk", "w+");
207 test_true(file);
208 fclose(file);
209 return TEST_SUCCESS;
210 }
211
212 static test_return_t var_tmp_rm_test(void *)
213 {
214 test_true(unlink("var/tmp/junk") == 0);
215 return TEST_SUCCESS;
216 }
217
218 static test_return_t var_run_rm_test(void *)
219 {
220 test_true(unlink("var/run/junk") == 0);
221 return TEST_SUCCESS;
222 }
223
224 static test_return_t var_log_rm_test(void *)
225 {
226 test_true(unlink("var/log/junk") == 0);
227 return TEST_SUCCESS;
228 }
229
230 static test_return_t var_drizzle_rm_test(void *)
231 {
232 test_true(unlink("var/drizzle/junk") == 0);
233 return TEST_SUCCESS;
234 }
235
236 static test_return_t _compare_test_return_t_test(void *)
237 {
238 test_compare(TEST_SUCCESS, TEST_SUCCESS);
239
240 return TEST_SUCCESS;
241 }
242
243 static test_return_t _compare_memcached_return_t_test(void *)
244 {
245 test_skip(HAVE_LIBMEMCACHED, true);
246 #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
247 test_compare(MEMCACHED_SUCCESS, MEMCACHED_SUCCESS);
248 #endif
249
250 return TEST_SUCCESS;
251 }
252
253 static test_return_t _compare_gearman_return_t_test(void *)
254 {
255 test_skip(HAVE_LIBGEARMAN, true);
256 #if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
257 test_compare(GEARMAN_SUCCESS, GEARMAN_SUCCESS);
258 #endif
259
260 return TEST_SUCCESS;
261 }
262
263 static test_return_t drizzled_cycle_test(void *object)
264 {
265 server_startup_st *servers= (server_startup_st*)object;
266 test_true(servers and servers->validate());
267
268 #if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
269 test_true(has_drizzled());
270 #endif
271
272 test_skip(true, has_drizzled());
273
274 test_true(server_startup(*servers, "drizzled", get_free_port(), 0, NULL));
275
276 return TEST_SUCCESS;
277 }
278
279 static test_return_t gearmand_cycle_test(void *object)
280 {
281 server_startup_st *servers= (server_startup_st*)object;
282 test_true(servers and servers->validate());
283
284 #if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
285 test_true(has_gearmand());
286 #endif
287
288 test_skip(true, has_gearmand());
289
290 test_true(server_startup(*servers, "gearmand", get_free_port(), 0, NULL));
291
292 return TEST_SUCCESS;
293 }
294
295 static test_return_t memcached_light_cycle_TEST(void *object)
296 {
297 server_startup_st *servers= (server_startup_st*)object;
298 test_true(servers);
299
300 test_skip(true, bool(HAVE_MEMCACHED_LIGHT_BINARY));
301
302 test_true(server_startup(*servers, "memcached-light", get_free_port(), 0, NULL));
303
304 return TEST_SUCCESS;
305 }
306
307 static test_return_t skip_shim(bool a, bool b)
308 {
309 test_skip(a, b);
310 return TEST_SUCCESS;
311 }
312
313 static test_return_t test_skip_true_TEST(void *object)
314 {
315 test_compare(true, true);
316 test_compare(false, false);
317 test_compare(TEST_SUCCESS, skip_shim(true, true));
318 test_compare(TEST_SUCCESS, skip_shim(false, false));
319
320 return TEST_SUCCESS;
321 }
322
323 static test_return_t test_skip_false_TEST(void *object)
324 {
325 test_compare(TEST_SKIPPED, skip_shim(true, false));
326 test_compare(TEST_SKIPPED, skip_shim(false, true));
327 return TEST_SUCCESS;
328 }
329
330 static test_return_t server_startup_TEST(void *object)
331 {
332 server_startup_st *servers= (server_startup_st*)object;
333 test_true(servers);
334
335 test_true(servers->start_server(testing_service, get_free_port(), 0, NULL, true));
336
337 test_true(servers->last());
338 pid_t last_pid= servers->last()->pid();
339
340 test_compare(servers->last()->pid(), last_pid);
341 test_true(last_pid > 1);
342 test_compare(kill(last_pid, 0), 0);
343
344 test_true(servers->shutdown());
345 #if 0
346 test_compare(servers->last()->pid(), -1);
347 test_compare(kill(last_pid, 0), -1);
348 #endif
349
350 return TEST_SUCCESS;
351 }
352
353 static test_return_t socket_server_startup_TEST(void *object)
354 {
355 server_startup_st *servers= (server_startup_st*)object;
356 test_true(servers);
357
358 test_true(servers->start_socket_server(testing_service, get_free_port(), 0, NULL, true));
359
360 return TEST_SUCCESS;
361 }
362
363 static test_return_t memcached_sasl_test(void *object)
364 {
365 server_startup_st *servers= (server_startup_st*)object;
366 test_true(servers);
367
368 test_skip(false, bool(getenv("TESTS_ENVIRONMENT")));
369
370 if (MEMCACHED_SASL_BINARY)
371 {
372 if (HAVE_LIBMEMCACHED)
373 {
374 test_true(has_memcached_sasl());
375 test_true(server_startup(*servers, "memcached-sasl", get_free_port(), 0, NULL));
376
377 return TEST_SUCCESS;
378 }
379 }
380
381 return TEST_SKIPPED;
382 }
383
384 static test_return_t application_true_BINARY(void *)
385 {
386 Application true_app("true");
387
388 test_compare(Application::SUCCESS, true_app.run());
389 test_compare(Application::SUCCESS, true_app.wait());
390
391 return TEST_SUCCESS;
392 }
393
394 static test_return_t application_gdb_true_BINARY2(void *)
395 {
396 test_skip(0, access("/usr/bin/gdb", X_OK ));
397 Application true_app("true");
398 true_app.use_gdb();
399
400 test_compare(Application::SUCCESS, true_app.run());
401 test_compare(Application::SUCCESS, true_app.wait());
402
403 return TEST_SUCCESS;
404 }
405
406 static test_return_t application_gdb_true_BINARY(void *)
407 {
408 test_skip(0, access("/usr/bin/gdb", X_OK ));
409 Application true_app("true");
410 true_app.use_gdb();
411
412 const char *args[]= { "--fubar", 0 };
413 test_compare(Application::SUCCESS, true_app.run(args));
414 test_compare(Application::SUCCESS, true_app.wait());
415
416 return TEST_SUCCESS;
417 }
418
419 static test_return_t application_true_fubar_BINARY(void *)
420 {
421 Application true_app("true");
422
423 const char *args[]= { "--fubar", 0 };
424 test_compare(Application::SUCCESS, true_app.run(args));
425 test_compare(Application::SUCCESS, true_app.wait());
426 test_compare(0, true_app.stdout_result().size());
427
428 return TEST_SUCCESS;
429 }
430
431 static test_return_t application_doesnotexist_BINARY(void *)
432 {
433
434 test_skip_valgrind();
435 Application true_app("doesnotexist");
436 true_app.will_fail();
437
438 const char *args[]= { "--fubar", 0 };
439 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
440 test_compare(Application::INVALID, true_app.run(args));
441 #else
442 test_compare(Application::SUCCESS, true_app.run(args));
443 test_compare(Application::INVALID, true_app.wait(false));
444 #endif
445
446 test_compare(0, true_app.stdout_result().size());
447
448 return TEST_SUCCESS;
449 }
450
451 static test_return_t application_true_fubar_eq_doh_BINARY(void *)
452 {
453 Application true_app("true");
454
455 const char *args[]= { "--fubar=doh", 0 };
456 test_compare(Application::SUCCESS, true_app.run(args));
457 test_compare(Application::SUCCESS, true_app.wait());
458 test_compare(0, true_app.stdout_result().size());
459
460 return TEST_SUCCESS;
461 }
462
463 static test_return_t application_true_fubar_eq_doh_option_BINARY(void *)
464 {
465 Application true_app("true");
466
467 true_app.add_option("--fubar=", "doh");
468
469 test_compare(Application::SUCCESS, true_app.run());
470 test_compare(Application::SUCCESS, true_app.wait());
471 test_compare(0, true_app.stdout_result().size());
472
473 return TEST_SUCCESS;
474 }
475
476
477 static test_return_t GET_TEST(void *)
478 {
479 libtest::http::GET get("http://foo.example.com/");
480
481 test_compare(false, get.execute());
482
483 return TEST_SUCCESS;
484 }
485
486 static test_return_t POST_TEST(void *)
487 {
488 libtest::vchar_t body;
489 libtest::http::POST post("http://foo.example.com/", body);
490
491 test_compare(false, post.execute());
492
493 return TEST_SUCCESS;
494 }
495
496 static test_return_t TRACE_TEST(void *)
497 {
498 libtest::vchar_t body;
499 libtest::http::TRACE trace("http://foo.example.com/", body);
500
501 test_compare(false, trace.execute());
502
503 return TEST_SUCCESS;
504 }
505
506
507 static test_return_t vchar_t_TEST(void *)
508 {
509 libtest::vchar_t response;
510 libtest::make_vector(response, test_literal_param("fubar\n"));
511 test_compare(response, response);
512
513 return TEST_SUCCESS;
514 }
515
516 static test_return_t vchar_t_compare_neg_TEST(void *)
517 {
518 libtest::vchar_t response;
519 libtest::vchar_t response2;
520 libtest::make_vector(response, test_literal_param("fubar\n"));
521 libtest::make_vector(response2, test_literal_param(__func__));
522 test_true(response != response2);
523
524 return TEST_SUCCESS;
525 }
526
527 static test_return_t application_echo_fubar_BINARY(void *)
528 {
529 Application true_app("echo");
530
531 const char *args[]= { "fubar", 0 };
532 test_compare(Application::SUCCESS, true_app.run(args));
533 test_compare(Application::SUCCESS, true_app.wait());
534
535 while (true_app.slurp() == false) {} ;
536
537 libtest::vchar_t response;
538 make_vector(response, test_literal_param("fubar\n"));
539 test_compare(response, true_app.stdout_result());
540
541 return TEST_SUCCESS;
542 }
543
544 static test_return_t application_echo_fubar_BINARY2(void *)
545 {
546 Application true_app("echo");
547
548 true_app.add_option("fubar");
549
550 test_compare(Application::SUCCESS, true_app.run());
551 test_compare(Application::SUCCESS, true_app.wait(false));
552
553 libtest::vchar_t response;
554 make_vector(response, test_literal_param("fubar\n"));
555 test_compare(response, true_app.stdout_result());
556
557 return TEST_SUCCESS;
558 }
559
560 static test_return_t true_BINARY(void *)
561 {
562 const char *args[]= { 0 };
563 test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
564
565 return TEST_SUCCESS;
566 }
567
568 static test_return_t true_fubar_BINARY(void *)
569 {
570 const char *args[]= { "--fubar", 0 };
571 test_compare(EXIT_SUCCESS, exec_cmdline("true", args));
572
573 return TEST_SUCCESS;
574 }
575
576 static test_return_t echo_fubar_BINARY(void *)
577 {
578 const char *args[]= { "fubar", 0 };
579 test_compare(EXIT_SUCCESS, exec_cmdline("echo", args));
580
581 return TEST_SUCCESS;
582 }
583
584 static test_return_t wait_BINARY(void *)
585 {
586 const char *args[]= { "--quiet", 0 };
587
588 test_compare(EXIT_FAILURE, exec_cmdline("libtest/wait", args, true));
589
590 return TEST_SUCCESS;
591 }
592
593 static test_return_t wait_help_BINARY(void *)
594 {
595 const char *args[]= { "--quiet", "--help", 0 };
596
597 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
598
599 return TEST_SUCCESS;
600 }
601
602 static test_return_t wait_version_BINARY(void *)
603 {
604 const char *args[]= { "--quiet", "--version", 0 };
605
606 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
607
608 return TEST_SUCCESS;
609 }
610
611 static test_return_t wait_services_BINARY(void *)
612 {
613 test_skip(0, access("/etc/services", R_OK ));
614
615 const char *args[]= { "--quiet", "/etc/services", 0 };
616
617 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
618
619 return TEST_SUCCESS;
620 }
621
622 static test_return_t wait_services_BINARY2(void *)
623 {
624 test_skip(0, access("/etc/services", R_OK ));
625
626 const char *args[]= { "/etc/services", 0 };
627
628 test_compare(EXIT_SUCCESS, exec_cmdline("libtest/wait", args, true));
629
630 return TEST_SUCCESS;
631 }
632
633 static test_return_t wait_services_appliction_TEST(void *)
634 {
635 test_skip(0, access("/usr/bin/gdb", X_OK ));
636 test_skip(0, access("/etc/services", R_OK ));
637
638 libtest::Application wait_app("libtest/wait", true);
639 wait_app.use_gdb();
640
641 const char *args[]= { "/etc/services", 0 };
642 test_compare(Application::SUCCESS, wait_app.run(args));
643 test_compare(Application::SUCCESS, wait_app.wait());
644
645 return TEST_SUCCESS;
646 }
647
648 static test_return_t gdb_wait_services_appliction_TEST(void *)
649 {
650 test_skip(true, false);
651 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
652 test_skip(0, TARGET_OS_OSX);
653 #endif
654
655 test_skip(0, access("/usr/bin/gdb", X_OK ));
656 test_skip(0, access("/etc/services", R_OK ));
657
658 libtest::Application wait_app("libtest/wait", true);
659 wait_app.use_gdb();
660
661 const char *args[]= { "/etc/services", 0 };
662 test_compare(Application::SUCCESS, wait_app.run(args));
663 test_compare(Application::SUCCESS, wait_app.wait());
664
665 return TEST_SUCCESS;
666 }
667
668 static test_return_t gdb_abort_services_appliction_TEST(void *)
669 {
670 test_skip(true, false);
671 test_skip(0, access("/usr/bin/gdb", X_OK ));
672
673 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
674 test_skip(0, TARGET_OS_OSX);
675 #endif
676
677 libtest::Application abort_app("libtest/abort", true);
678 abort_app.use_gdb();
679
680 test_compare(Application::SUCCESS, abort_app.run());
681 test_compare(Application::SUCCESS, abort_app.wait());
682
683 std::string gdb_filename= abort_app.gdb_filename();
684 test_skip(0, access(gdb_filename.c_str(), R_OK ));
685 const char *args[]= { "SIGABRT", gdb_filename.c_str(), 0 };
686 test_compare(EXIT_SUCCESS, exec_cmdline("grep", args));
687
688 // Sanity test
689 args[0]= "THIS_WILL_NOT_BE_FOUND";
690 test_compare(EXIT_FAILURE, exec_cmdline("grep", args));
691
692 return TEST_SUCCESS;
693 }
694
695 static test_return_t get_free_port_TEST(void *)
696 {
697 in_port_t ret_port;
698 test_true((ret_port= get_free_port()));
699 test_true(get_free_port() != default_port());
700 test_true(get_free_port() != get_free_port());
701
702 return TEST_SUCCESS;
703 }
704
705 static uint32_t fatal_calls= 0;
706
707 static test_return_t fatal_TEST(void *)
708 {
709 test_compare(fatal_calls++, fatal::disabled_counter());
710 throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Testing va_args based fatal(): %d", 10);
711
712 return TEST_SUCCESS;
713 }
714
715 static test_return_t number_of_cpus_TEST(void *)
716 {
717 test_true(number_of_cpus() >= 1);
718
719 return TEST_SUCCESS;
720 }
721
722 static test_return_t check_dns_TEST(void *)
723 {
724 test_warn(libtest::check_dns(), "Broken DNS server/no DNS server found");
725
726 return TEST_SUCCESS;
727 }
728
729 static test_return_t Timer_TEST(void *)
730 {
731 int64_t minutes= random() % 50;
732 minutes++;
733
734 Timer check;
735
736 check.reset();
737 check.offset(minutes, 2, 200);
738
739 test_compare(check.minutes(), minutes);
740
741 return TEST_SUCCESS;
742 }
743
744 static test_return_t lookup_true_TEST(void *)
745 {
746 test_warn(libtest::lookup("exist.gearman.info"), "dns is not currently working");
747 return TEST_SUCCESS;
748 }
749
750 static test_return_t lookup_false_TEST(void *)
751 {
752 if (libtest::lookup("does_not_exist.gearman.info"))
753 {
754 Error << "Broken DNS server detected";
755 return TEST_SKIPPED;
756 }
757
758 return TEST_SUCCESS;
759 }
760
761 static test_return_t create_tmpfile_TEST(void *)
762 {
763 std::string tmp= create_tmpfile(__func__);
764 test_compare(-1, access(tmp.c_str(), R_OK));
765 test_compare(-1, access(tmp.c_str(), F_OK));
766
767 Application touch_app("touch");
768 const char *args[]= { tmp.c_str(), 0 };
769 test_compare(Application::SUCCESS, touch_app.run(args));
770 test_compare(Application::SUCCESS, touch_app.wait(false));
771
772 test_compare(0, access(tmp.c_str(), R_OK));
773 test_compare(0, unlink(tmp.c_str()));
774
775 return TEST_SUCCESS;
776 }
777
778 static test_return_t fatal_message_TEST(void *)
779 {
780 test_compare(fatal_calls++, fatal::disabled_counter());
781 fatal_message("Fatal test");
782
783 return TEST_SUCCESS;
784 }
785
786 static test_return_t default_port_TEST(void *)
787 {
788 in_port_t ret_port= default_port();
789 test_compare(ret_port, libtest::default_port());
790 test_compare(ret_port, libtest::default_port());
791
792 return TEST_SUCCESS;
793 }
794
795 static test_return_t check_for_gearman(void *)
796 {
797 test_skip(true, HAVE_LIBGEARMAN);
798 test_skip(true, has_gearmand());
799 return TEST_SUCCESS;
800 }
801
802 static test_return_t check_for_drizzle(void *)
803 {
804 test_skip(true, HAVE_LIBDRIZZLE);
805 test_skip(true, has_drizzled());
806 return TEST_SUCCESS;
807 }
808
809
810 test_st drizzled_tests[] ={
811 {"drizzled startup-shutdown", 0, drizzled_cycle_test },
812 {0, 0, 0}
813 };
814
815 test_st gearmand_tests[] ={
816 #if 0
817 {"pause", 0, pause_test },
818 #endif
819 {"gearmand startup-shutdown", 0, gearmand_cycle_test },
820 {"_compare(gearman_return_t)", 0, _compare_gearman_return_t_test },
821 {0, 0, 0}
822 };
823
824 static test_return_t check_for_libmemcached(void* object)
825 {
826 test_skip(true, HAVE_LIBMEMCACHED);
827 test_skip(true, has_memcached());
828
829 server_startup_st *servers= (server_startup_st*)object;
830 test_true(servers);
831 servers->clear();
832
833 testing_service= "memcached";
834
835 return TEST_SUCCESS;
836 }
837
838 test_st memcached_TESTS[] ={
839 {"memcached startup-shutdown", 0, server_startup_TEST },
840 {"memcached(socket file) startup-shutdown", 0, socket_server_startup_TEST },
841 {"_compare(memcached_return_t)", 0, _compare_memcached_return_t_test },
842 {0, 0, 0}
843 };
844
845 test_st test_skip_TESTS[] ={
846 {"true, true", 0, test_skip_true_TEST },
847 {"true, false", 0, test_skip_false_TEST },
848 {0, 0, 0}
849 };
850
851 test_st environment_tests[] ={
852 {"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test },
853 {"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test },
854 {"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test },
855 {"GDB_COMMAND", 0, GDB_COMMAND_test },
856 {0, 0, 0}
857 };
858
859 test_st tests_log[] ={
860 {"TEST_SUCCESS", false, test_success_test },
861 {"TEST_FAILURE", false, test_failure_test },
862 {"TEST_SUCCESS == 0", false, test_success_equals_one_test },
863 {0, 0, 0}
864 };
865
866 test_st local_log[] ={
867 {"test_is_local()", 0, local_test },
868 {"test_is_local(NOT)", 0, local_not_test },
869 {0, 0, 0}
870 };
871
872 test_st directories_tests[] ={
873 {"var exists", 0, var_exists_test },
874 {"var/tmp exists", 0, var_tmp_exists_test },
875 {"var/run exists", 0, var_run_exists_test },
876 {"var/log exists", 0, var_log_exists_test },
877 {"var/drizzle exists", 0, var_drizzle_exists_test },
878 {"var/tmp", 0, var_tmp_test },
879 {"var/run", 0, var_run_test },
880 {"var/log", 0, var_log_test },
881 {"var/drizzle", 0, var_drizzle_test },
882 {"var/tmp rm", 0, var_tmp_rm_test },
883 {"var/run rm", 0, var_run_rm_test },
884 {"var/log rm", 0, var_log_rm_test },
885 {"var/drizzle rm", 0, var_drizzle_rm_test },
886 {0, 0, 0}
887 };
888
889 test_st comparison_tests[] ={
890 {"_compare(test_return_t)", 0, _compare_test_return_t_test },
891 {0, 0, 0}
892 };
893
894 test_st cmdline_tests[] ={
895 {"true", 0, true_BINARY },
896 {"true --fubar", 0, true_fubar_BINARY },
897 {"echo fubar", 0, echo_fubar_BINARY },
898 {"wait --quiet", 0, wait_BINARY },
899 {"wait --quiet --help", 0, wait_help_BINARY },
900 {"wait --quiet --version", 0, wait_version_BINARY },
901 {"wait --quiet /etc/services", 0, wait_services_BINARY },
902 {"wait /etc/services", 0, wait_services_BINARY2 },
903 {"wait /etc/services", 0, wait_services_appliction_TEST },
904 {"gdb wait /etc/services", 0, gdb_wait_services_appliction_TEST },
905 {"gdb abort", 0, gdb_abort_services_appliction_TEST },
906 {0, 0, 0}
907 };
908
909 test_st get_free_port_TESTS[] ={
910 {"get_free_port()", 0, get_free_port_TEST },
911 {"default_port()", 0, default_port_TEST },
912 {0, 0, 0}
913 };
914
915 test_st fatal_message_TESTS[] ={
916 {"libtest::fatal", 0, fatal_TEST },
917 {"fatal_message()", 0, fatal_message_TEST },
918 {0, 0, 0}
919 };
920
921 test_st number_of_cpus_TESTS[] ={
922 {"libtest::number_of_cpus()", 0, number_of_cpus_TEST },
923 {0, 0, 0}
924 };
925
926 test_st create_tmpfile_TESTS[] ={
927 {"libtest::create_tmpfile()", 0, create_tmpfile_TEST },
928 {0, 0, 0}
929 };
930
931 test_st timer_TESTS[] ={
932 {"libtest::Timer", 0, Timer_TEST },
933 {0, 0, 0}
934 };
935
936 test_st dns_TESTS[] ={
937 {"libtest::lookup(true)", 0, lookup_true_TEST },
938 {"libtest::lookup(false)", 0, lookup_false_TEST },
939 {"libtest::check_dns()", 0, check_dns_TEST },
940 {0, 0, 0}
941 };
942
943 test_st application_tests[] ={
944 {"vchar_t", 0, vchar_t_TEST },
945 {"vchar_t compare()", 0, vchar_t_compare_neg_TEST },
946 {"true", 0, application_true_BINARY },
947 {"gbd true --fubar", 0, application_gdb_true_BINARY },
948 {"gbd true", 0, application_gdb_true_BINARY2 },
949 {"true --fubar", 0, application_true_fubar_BINARY },
950 {"doesnotexist --fubar", 0, application_doesnotexist_BINARY },
951 {"true --fubar=doh", 0, application_true_fubar_eq_doh_BINARY },
952 {"true --fubar=doh add_option()", 0, application_true_fubar_eq_doh_option_BINARY },
953 {"echo fubar", 0, application_echo_fubar_BINARY },
954 {"echo fubar (as option)", 0, application_echo_fubar_BINARY2 },
955 {0, 0, 0}
956 };
957
958 static test_return_t check_for_curl(void *)
959 {
960 test_skip(true, HAVE_LIBCURL);
961 return TEST_SUCCESS;
962 }
963
964 static test_return_t disable_fatal_exception(void *)
965 {
966 fatal::disable();
967 return TEST_SUCCESS;
968 }
969
970 static test_return_t enable_fatal_exception(void *)
971 {
972 fatal::disable();
973 return TEST_SUCCESS;
974 }
975
976 test_st http_tests[] ={
977 {"GET", 0, GET_TEST },
978 {"POST", 0, POST_TEST },
979 {"TRACE", 0, TRACE_TEST },
980 {0, 0, 0}
981 };
982
983 collection_st collection[] ={
984 {"environment", 0, 0, environment_tests},
985 {"return values", 0, 0, tests_log},
986 {"test_skip()", 0, 0, test_skip_TESTS },
987 {"local", 0, 0, local_log},
988 {"directories", 0, 0, directories_tests},
989 {"comparison", 0, 0, comparison_tests},
990 {"gearmand", check_for_gearman, 0, gearmand_tests},
991 {"memcached", check_for_libmemcached, 0, memcached_TESTS },
992 {"drizzled", check_for_drizzle, 0, drizzled_tests},
993 {"cmdline", 0, 0, cmdline_tests},
994 {"application", 0, 0, application_tests},
995 {"http", check_for_curl, 0, http_tests},
996 {"http", check_for_curl, 0, http_tests},
997 {"get_free_port()", 0, 0, get_free_port_TESTS },
998 {"fatal", disable_fatal_exception, enable_fatal_exception, fatal_message_TESTS },
999 {"number_of_cpus()", 0, 0, number_of_cpus_TESTS },
1000 {"create_tmpfile()", 0, 0, create_tmpfile_TESTS },
1001 {"dns", 0, 0, dns_TESTS },
1002 {"libtest::Timer", 0, 0, timer_TESTS },
1003 {0, 0, 0, 0}
1004 };
1005
1006 static void *world_create(server_startup_st& servers, test_return_t&)
1007 {
1008 return &servers;
1009 }
1010
1011 void get_world(Framework *world)
1012 {
1013 world->collections(collection);
1014 world->create(world_create);
1015 }