drizzle_test.cc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* Gearman server and library
  2. * Copyright (C) 2008 Brian Aker, Eric Day
  3. * All rights reserved.
  4. *
  5. * Use and distribution licensed under the BSD license. See
  6. * the COPYING file in the parent directory for full text.
  7. */
  8. #include <config.h>
  9. #include <libtest/test.hpp>
  10. using namespace libtest;
  11. #include <cassert>
  12. #include <cstdio>
  13. #include <cstdlib>
  14. #include <cstring>
  15. #include <unistd.h>
  16. #include <libgearman/gearman.h>
  17. #include <tests/basic.h>
  18. #include <tests/context.h>
  19. #include <tests/ports.h>
  20. #define WORKER_FUNCTION "drizzle_queue_test"
  21. #ifndef __INTEL_COMPILER
  22. #pragma GCC diagnostic ignored "-Wold-style-cast"
  23. #endif
  24. static test_return_t test_for_HAVE_LIBDRIZZLE(void *)
  25. {
  26. #if defined HAVE_LIBDRIZZLE && defined HAVE_DRIZZLED
  27. return TEST_SUCCESS;
  28. #else
  29. return TEST_SKIPPED;
  30. #endif
  31. }
  32. static test_return_t gearmand_basic_option_test(void *)
  33. {
  34. const char *args[]= { "--check-args",
  35. "--libdrizzle-host=localhost",
  36. "--libdrizzle-port=90",
  37. "--libdrizzle-uds=tmp/foo.socket",
  38. "--libdrizzle-user=root",
  39. "--libdrizzle-password=test",
  40. "--libdrizzle-db=gearman",
  41. "--libdrizzle-table=gearman",
  42. "--libdrizzle-mysql",
  43. 0 };
  44. test_success(exec_cmdline(GEARMAND_BINARY, args));
  45. return TEST_SUCCESS;
  46. }
  47. static test_return_t collection_init(void *object)
  48. {
  49. Context *test= (Context *)object;
  50. assert(test);
  51. const char *argv[2]= { "test_gearmand", "--queue-type=libdrizzle" };
  52. test->initialize(2, argv);
  53. return TEST_SUCCESS;
  54. }
  55. static test_return_t collection_cleanup(void *object)
  56. {
  57. Context *test= (Context *)object;
  58. test->reset();
  59. return TEST_SUCCESS;
  60. }
  61. static void *world_create(server_startup_st& servers, test_return_t& error)
  62. {
  63. if (test_for_HAVE_LIBDRIZZLE(NULL) == TEST_SKIPPED)
  64. {
  65. error= TEST_SKIPPED;
  66. return NULL;
  67. }
  68. Context *test= new Context(DRIZZLE_TEST_PORT, servers);
  69. if (not test)
  70. {
  71. error= TEST_MEMORY_ALLOCATION_FAILURE;
  72. return NULL;
  73. }
  74. error= TEST_SUCCESS;
  75. return test;
  76. }
  77. static bool world_destroy(void *object)
  78. {
  79. Context *test= (Context *)object;
  80. delete test;
  81. return TEST_SUCCESS;
  82. }
  83. test_st gearmand_basic_option_tests[] ={
  84. {"all options", 0, gearmand_basic_option_test },
  85. {0, 0, 0}
  86. };
  87. test_st tests[] ={
  88. {"gearman_client_echo()", 0, client_echo_test },
  89. {"gearman_client_echo() fail", 0, client_echo_fail_test },
  90. {"gearman_worker_echo()", 0, worker_echo_test },
  91. {"clean", 0, queue_clean },
  92. {"add", 0, queue_add },
  93. {"worker", 0, queue_worker },
  94. {0, 0, 0}
  95. };
  96. test_st regressions[] ={
  97. {"lp:734663", 0, lp_734663 },
  98. {0, 0, 0}
  99. };
  100. collection_st collection[] ={
  101. {"drizzle queue", collection_init, collection_cleanup, tests},
  102. {"regressions", collection_init, collection_cleanup, regressions},
  103. {0, 0, 0, 0}
  104. };
  105. void get_world(Framework *world)
  106. {
  107. world->collections= collection;
  108. world->_create= world_create;
  109. world->_destroy= world_destroy;
  110. }