ephemeral_test.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "gear_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. ASSERT_TRUE(test);
  26. ASSERT_TRUE(test->initialize(NULL));
  27. return TEST_SUCCESS;
  28. }
  29. static test_return_t collection_cleanup(void *object)
  30. {
  31. Context *test= (Context *)object;
  32. ASSERT_TRUE(test);
  33. test->reset();
  34. return TEST_SUCCESS;
  35. }
  36. static void *world_create(server_startup_st& servers, test_return_t&)
  37. {
  38. return new Context(servers);
  39. }
  40. static bool world_destroy(void *object)
  41. {
  42. Context *test= (Context *)object;
  43. delete test;
  44. return TEST_SUCCESS;
  45. }
  46. test_st tests[] ={
  47. {"gearman_client_echo()", 0, client_echo_test },
  48. {"gearman_client_echo() fail", 0, client_echo_fail_test },
  49. {"gearman_worker_echo()", 0, worker_echo_test },
  50. {"clean", 0, queue_clean },
  51. {"add", 0, queue_add },
  52. {"worker", 0, queue_worker },
  53. {0, 0, 0}
  54. };
  55. collection_st collection[] ={
  56. {"ephemeral queue", collection_init, collection_cleanup, tests},
  57. {0, 0, 0, 0}
  58. };
  59. void get_world(libtest::Framework *world)
  60. {
  61. world->collections(collection);
  62. world->create(world_create);
  63. world->destroy(world_destroy);
  64. }