tokyocabinet_test.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 <assert.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  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. #ifndef __INTEL_COMPILER
  21. #pragma GCC diagnostic ignored "-Wold-style-cast"
  22. #endif
  23. static test_return_t test_for_HAVE_LIBTOKYOCABINET(void *)
  24. {
  25. #ifdef HAVE_LIBSQLITE3
  26. return TEST_SUCCESS;
  27. #else
  28. return TEST_SKIPPED;
  29. #endif
  30. }
  31. static test_return_t gearmand_basic_option_test(void *)
  32. {
  33. const char *args[]= { "--queue=libtokyocabinet", "--libtokyocabinet-file=tmp/file", "--libtokyocabinet-optimize", "--check-args", 0 };
  34. test_success(exec_cmdline(GEARMAND_BINARY, args));
  35. return TEST_SUCCESS;
  36. }
  37. static test_return_t collection_init(void *object)
  38. {
  39. test_skip(TEST_SUCCESS, test_for_HAVE_LIBTOKYOCABINET(object));
  40. const char *argv[3]= { "test_gearmand", "--libtokyocabinet-file=tests/gearman.tcb", "--queue-type=libtokyocabinet" };
  41. unlink("tests/gearman.tcb");
  42. Context *test= (Context *)object;
  43. assert(test);
  44. test_truth(test->initialize(3, argv));
  45. return TEST_SUCCESS;
  46. }
  47. static test_return_t collection_cleanup(void *object)
  48. {
  49. Context *test= (Context *)object;
  50. test->reset();
  51. unlink("tests/gearman.tcb");
  52. return TEST_SUCCESS;
  53. }
  54. static void *world_create(server_startup_st& servers, test_return_t& error)
  55. {
  56. Context *test= new Context(TOKYOCABINET_TEST_PORT, servers);
  57. if (not test)
  58. {
  59. error= TEST_MEMORY_ALLOCATION_FAILURE;
  60. return NULL;
  61. }
  62. unlink("tests/gearman.tcb");
  63. return test;
  64. }
  65. static bool world_destroy(void *object)
  66. {
  67. Context *test= (Context *)object;
  68. unlink("tests/gearman.tcb");
  69. delete test;
  70. return TEST_SUCCESS;
  71. }
  72. test_st gearmand_basic_option_tests[] ={
  73. {"--libtokyocabinet-file=tmp/file --libtokyocabinet-optimize", 0, gearmand_basic_option_test },
  74. {0, 0, 0}
  75. };
  76. test_st tests[] ={
  77. {"gearman_client_echo()", 0, client_echo_test },
  78. {"gearman_client_echo() fail", 0, client_echo_fail_test },
  79. {"gearman_worker_echo()", 0, worker_echo_test },
  80. {"clean", 0, queue_clean },
  81. {"add", 0, queue_add },
  82. {"worker", 0, queue_worker },
  83. {0, 0, 0}
  84. };
  85. collection_st collection[] ={
  86. {"gearmand options", test_for_HAVE_LIBTOKYOCABINET, 0, gearmand_basic_option_tests},
  87. {"tokyocabinet queue", collection_init, collection_cleanup, tests},
  88. {0, 0, 0, 0}
  89. };
  90. void get_world(Framework *world)
  91. {
  92. world->collections= collection;
  93. world->_create= world_create;
  94. world->_destroy= world_destroy;
  95. }