sqlite_test.cc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 <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. #include <tests/ports.h>
  20. // Prototypes
  21. #ifndef __INTEL_COMPILER
  22. #pragma GCC diagnostic ignored "-Wold-style-cast"
  23. #endif
  24. static bool test_for_HAVE_LIBSQLITE3(test_return_t &error)
  25. {
  26. #ifdef HAVE_LIBSQLITE3
  27. error= TEST_SUCCESS;
  28. return true;
  29. #else
  30. error= TEST_SKIPPED;
  31. return false;
  32. #endif
  33. }
  34. static test_return_t gearmand_basic_option_test(void *)
  35. {
  36. const char *args[]= { "--queue-type=libsqlite3", "--libsqlite3-db=tests/var/tmp/gearman.sql", "--libsqlite3-table=tmp/table", "--check-args", 0 };
  37. test_success(exec_cmdline(GEARMAND_BINARY, args));
  38. return TEST_SUCCESS;
  39. }
  40. static test_return_t gearmand_basic_option_without_table_test(void *)
  41. {
  42. const char *args[]= { "--queue-type=libsqlite3", "--libsqlite3-db=tests/var/tmp/gearman.sql", "--check-args", 0 };
  43. test_success(exec_cmdline(GEARMAND_BINARY, args));
  44. return TEST_SUCCESS;
  45. }
  46. static test_return_t collection_init(void *object)
  47. {
  48. const char *argv[3]= { "test_gearmand", "--libsqlite3-db=tests/var/tmp/gearman.sql", "--queue-type=libsqlite3"};
  49. // Delete whatever might have been sitting around for the sql files
  50. unlink("tests/var/tmp/gearman.sql");
  51. unlink("tests/var/tmp/gearman.sql-journal");
  52. Context *test= (Context *)object;
  53. assert(test);
  54. test_truth(test->initialize(3, argv));
  55. return TEST_SUCCESS;
  56. }
  57. static test_return_t collection_cleanup(void *object)
  58. {
  59. Context *test= (Context *)object;
  60. test->reset();
  61. return TEST_SUCCESS;
  62. }
  63. static void *world_create(server_startup_st& servers, test_return_t& error)
  64. {
  65. if (not test_for_HAVE_LIBSQLITE3(error))
  66. {
  67. return NULL;
  68. }
  69. Context *test= new Context(SQLITE_TEST_PORT, servers);
  70. if (not test)
  71. {
  72. error= TEST_MEMORY_ALLOCATION_FAILURE;
  73. return NULL;
  74. }
  75. return test;
  76. }
  77. static bool world_destroy(void *object)
  78. {
  79. Context *test= (Context *)object;
  80. delete test;
  81. return TEST_SUCCESS;
  82. }
  83. test_st gearmand_basic_option_tests[] ={
  84. {"--libsqlite3-db=tmp/schema --libsqlite3-table=tmp/table", 0, gearmand_basic_option_test },
  85. {"--libsqlite3-db=tmp/schema", 0, gearmand_basic_option_without_table_test },
  86. {0, 0, 0}
  87. };
  88. test_st tests[] ={
  89. {"gearman_client_echo()", 0, client_echo_test },
  90. {"gearman_client_echo() fail", 0, client_echo_fail_test },
  91. {"gearman_worker_echo()", 0, worker_echo_test },
  92. {"clean", 0, queue_clean },
  93. {"add", 0, queue_add },
  94. {"worker", 0, queue_worker },
  95. {0, 0, 0}
  96. };
  97. test_st regressions[] ={
  98. {"lp:734663", 0, lp_734663 },
  99. {0, 0, 0}
  100. };
  101. collection_st collection[] ={
  102. {"gearmand options", 0, 0, gearmand_basic_option_tests},
  103. {"sqlite queue", collection_init, collection_cleanup, tests},
  104. {"queue regression", collection_init, collection_cleanup, regressions},
  105. #if 0
  106. {"sqlite queue change table", collection_init, collection_cleanup, tests},
  107. #endif
  108. {0, 0, 0, 0}
  109. };
  110. void get_world(Framework *world)
  111. {
  112. world->collections= collection;
  113. world->_create= world_create;
  114. world->_destroy= world_destroy;
  115. }