drizzle_test.cc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #if defined(NDEBUG)
  10. # undef NDEBUG
  11. #endif
  12. #include <assert.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <unistd.h>
  17. #include <libgearman/gearman.h>
  18. #include <libtest/test.h>
  19. #include <libtest/server.h>
  20. #include <libtest/worker.h>
  21. #include <tests/basic.h>
  22. #include <tests/context.h>
  23. #define WORKER_TEST_PORT 32123
  24. #define WORKER_FUNCTION "drizzle_queue_test"
  25. void *world_create(test_return_t *error);
  26. test_return_t world_destroy(void *object);
  27. test_return_t collection_init(void *object);
  28. test_return_t collection_cleanup(void *object);
  29. #ifndef __INTEL_COMPILER
  30. #pragma GCC diagnostic ignored "-Wold-style-cast"
  31. #endif
  32. test_return_t collection_init(void *object)
  33. {
  34. const char *argv[2]= { "test_gearmand", "--queue-type=libdrizzle" };
  35. Context *test= (Context *)object;
  36. assert(test);
  37. test_true_got(test->initialize(2, argv), getenv("GEARMAN_SERVER_STARTUP"));
  38. return TEST_SUCCESS;
  39. }
  40. test_return_t collection_cleanup(void *object)
  41. {
  42. Context *test= (Context *)object;
  43. test->reset();
  44. return TEST_SUCCESS;
  45. }
  46. void *world_create(test_return_t *error)
  47. {
  48. Context *test= new Context(WORKER_TEST_PORT);
  49. if (not test)
  50. {
  51. *error= TEST_MEMORY_ALLOCATION_FAILURE;
  52. return NULL;
  53. }
  54. *error= TEST_SUCCESS;
  55. return test;
  56. }
  57. test_return_t world_destroy(void *object)
  58. {
  59. Context *test= (Context *)object;
  60. delete test;
  61. return TEST_SUCCESS;
  62. }
  63. test_st tests[] ={
  64. {"gearman_client_echo()", 0, client_echo_test },
  65. {"gearman_client_echo() fail", 0, client_echo_fail_test },
  66. {"gearman_worker_echo()", 0, worker_echo_test },
  67. {"clean", 0, queue_clean },
  68. {"add", 0, queue_add },
  69. {"worker", 0, queue_worker },
  70. {0, 0, 0}
  71. };
  72. test_st regressions[] ={
  73. {"lp:734663", 0, lp_734663 },
  74. {0, 0, 0}
  75. };
  76. collection_st collection[] ={
  77. #ifdef HAVE_LIBDRIZZLE
  78. {"drizzle queue", collection_init, collection_cleanup, tests},
  79. {"regressions", collection_init, collection_cleanup, regressions},
  80. #endif
  81. {0, 0, 0, 0}
  82. };
  83. void get_world(world_st *world)
  84. {
  85. world->collections= collection;
  86. world->create= world_create;
  87. world->destroy= world_destroy;
  88. }