ephemeral_test.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Gearman server and library
  2. * Copyright (C) 2011 Data Differential, http://datadifferential.com/
  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. #ifndef __INTEL_COMPILER
  20. #pragma GCC diagnostic ignored "-Wold-style-cast"
  21. #endif
  22. static test_return_t collection_init(void *object)
  23. {
  24. Context *test= (Context *)object;
  25. test_true(test);
  26. test_truth(test->initialize(0, NULL));
  27. return TEST_SUCCESS;
  28. }
  29. static test_return_t collection_cleanup(void *object)
  30. {
  31. Context *test= (Context *)object;
  32. test->reset();
  33. return TEST_SUCCESS;
  34. }
  35. static void *world_create(server_startup_st& servers, test_return_t&)
  36. {
  37. return new Context(default_port(), servers);
  38. }
  39. static bool world_destroy(void *object)
  40. {
  41. Context *test= (Context *)object;
  42. delete test;
  43. return TEST_SUCCESS;
  44. }
  45. test_st tests[] ={
  46. {"gearman_client_echo()", 0, client_echo_test },
  47. {"gearman_client_echo() fail", 0, client_echo_fail_test },
  48. {"gearman_worker_echo()", 0, worker_echo_test },
  49. {"clean", 0, queue_clean },
  50. {"add", 0, queue_add },
  51. {"worker", 0, queue_worker },
  52. {0, 0, 0}
  53. };
  54. collection_st collection[] ={
  55. {"ephemeral queue", collection_init, collection_cleanup, tests},
  56. {0, 0, 0, 0}
  57. };
  58. void get_world(libtest::Framework *world)
  59. {
  60. world->collections(collection);
  61. world->create(world_create);
  62. world->destroy(world_destroy);
  63. }