tokyocabinet_test.cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 <tests/basic.h>
  21. #include <tests/context.h>
  22. #define WORKER_TEST_PORT 32123
  23. void *world_create(test_return_t *error);
  24. test_return_t world_destroy(void *object);
  25. #ifndef __INTEL_COMPILER
  26. #pragma GCC diagnostic ignored "-Wold-style-cast"
  27. #endif
  28. static test_return_t collection_init(void *object)
  29. {
  30. const char *argv[3]= { "test_gearmand", "--libtokyocabinet-file=tests/gearman.tcb", "--queue-type=libtokyocabinet" };
  31. unlink("tests/gearman.tcb");
  32. Context *test= (Context *)object;
  33. assert(test);
  34. test_truth(test->initialize(3, argv));
  35. return TEST_SUCCESS;
  36. }
  37. static test_return_t collection_cleanup(void *object)
  38. {
  39. Context *test= (Context *)object;
  40. test->reset();
  41. return TEST_SUCCESS;
  42. }
  43. void *world_create(test_return_t *error)
  44. {
  45. Context *test= new Context(WORKER_TEST_PORT);
  46. if (not test)
  47. {
  48. *error= TEST_MEMORY_ALLOCATION_FAILURE;
  49. return NULL;
  50. }
  51. *error= TEST_SUCCESS;
  52. return test;
  53. }
  54. test_return_t world_destroy(void *object)
  55. {
  56. Context *test= (Context *)object;
  57. delete test;
  58. return TEST_SUCCESS;
  59. }
  60. test_st tests[] ={
  61. {"gearman_client_echo()", 0, client_echo_test },
  62. {"gearman_client_echo() fail", 0, client_echo_fail_test },
  63. {"gearman_worker_echo()", 0, worker_echo_test },
  64. {"clean", 0, queue_clean },
  65. {"add", 0, queue_add },
  66. {"worker", 0, queue_worker },
  67. {0, 0, 0}
  68. };
  69. collection_st collection[] ={
  70. #ifdef HAVE_LIBTOKYOCABINET
  71. {"tokyocabinet queue", collection_init, collection_cleanup, tests},
  72. #endif
  73. {0, 0, 0, 0}
  74. };
  75. void get_world(world_st *world)
  76. {
  77. world->collections= collection;
  78. world->create= world_create;
  79. world->destroy= world_destroy;
  80. }