sqlite_test.cc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 <cstdio>
  14. #include <cstdlib>
  15. #include <cstring>
  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. // Prototypes
  24. void *world_create(test_return_t *error);
  25. test_return_t world_destroy(void *object);
  26. #ifndef __INTEL_COMPILER
  27. #pragma GCC diagnostic ignored "-Wold-style-cast"
  28. #endif
  29. static test_return_t collection_init(void *object)
  30. {
  31. const char *argv[3]= { "test_gearmand", "--libsqlite3-db=tests/gearman.sql", "--queue-type=libsqlite3"};
  32. // Delete whatever might have been sitting around for the sql files
  33. unlink("tests/gearman.sql");
  34. unlink("tests/gearman.sql-journal");
  35. Context *test= (Context *)object;
  36. assert(test);
  37. test_truth(test->initialize(3, argv));
  38. return TEST_SUCCESS;
  39. }
  40. static 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. {"sqlite queue", collection_init, collection_cleanup, tests},
  78. {"queue regression", collection_init, collection_cleanup, regressions},
  79. #if 0
  80. {"sqlite queue change table", collection_init, collection_cleanup, tests},
  81. #endif
  82. {0, 0, 0, 0}
  83. };
  84. void get_world(world_st *world)
  85. {
  86. world->collections= collection;
  87. world->create= world_create;
  88. world->destroy= world_destroy;
  89. }