X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Funittest.cc;h=1e3241ed82bc165a1cb0a05dfea4225a3b2cccc8;hb=c87f1a554cce74ac1ba3d4e7e9c2a1d2904e4766;hp=e0df62f7ffaf5c05944ffae1bee06caae7597a39;hpb=9cd57ce737375540f6c3b5e2e3684160e5c4bfce;p=m6w6%2Flibmemcached diff --git a/libtest/unittest.cc b/libtest/unittest.cc index e0df62f7..1e3241ed 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -36,36 +36,144 @@ */ #include + #include +#include + +using namespace libtest; + static test_return_t test_success_test(void *) { return TEST_SUCCESS; } -static test_return_t local_test(void *) +static test_return_t test_failure_test(void *) { - char buffer[sizeof("LIBTEST_LOCAL=1")]; + return TEST_SKIPPED; // Only run this when debugging - snprintf(buffer, sizeof(buffer), "%s", "LIBTEST_LOCAL=1"); - test_compare(0, putenv(buffer)); + test_compare(1, 2); + return TEST_SUCCESS; +} - test_true(test_is_local()); +static test_return_t local_test(void *) +{ + if (getenv("LIBTEST_LOCAL")) + { + test_true(test_is_local()); + } + else + { + test_false(test_is_local()); + } return TEST_SUCCESS; } static test_return_t local_not_test(void *) { - test_compare(0, unsetenv("LIBTEST_LOCAL")); + return TEST_SKIPPED; + std::string temp; + + const char *ptr; + if ((ptr= getenv("LIBTEST_LOCAL")) == NULL) + { + temp.append(ptr); + } + + // unsetenv() will cause issues with valgrind + _compare(__FILE__, __LINE__, __func__, 0, unsetenv("LIBTEST_LOCAL")); + test_compare(0, unsetenv("LIBTEST_LOCAL")); test_false(test_is_local()); + test_compare(0, setenv("LIBTEST_LOCAL", "1", 1)); + test_true(test_is_local()); + + if (temp.empty()) + { + test_compare(0, unsetenv("LIBTEST_LOCAL")); + } + else + { + char *old_string= strdup(temp.c_str()); + test_compare(0, setenv("LIBTEST_LOCAL", old_string, 1)); + } + + return TEST_SUCCESS; +} + +#if 0 +static test_return_t pause_test(void *) +{ + (void)getchar(); return TEST_SUCCESS; } +#endif + + +static test_return_t gearmand_cycle_test(void *object) +{ + server_startup_st *servers= (server_startup_st*)object; + test_true(servers); + +#ifndef HAVE_LIBGEARMAN + return TEST_SKIPPED; +#endif + + const char *argv[1]= { "cycle_gearmand" }; + test_true(server_startup(*servers, "gearmand", 9999, 1, argv)); + + return TEST_SUCCESS; +} + +static test_return_t memcached_cycle_test(void *object) +{ + server_startup_st *servers= (server_startup_st*)object; + test_true(servers); + +#if !defined(MEMCACHED_BINARY) && !defined(HAVE_LIBMEMCACHED) + return TEST_SKIPPED; +#endif + + const char *argv[1]= { "cycle_memcached" }; + test_true(server_startup(*servers, "memcached", 9998, 1, argv)); + + return TEST_SUCCESS; +} + +static test_return_t memcached_socket_cycle_test(void *object) +{ + server_startup_st *servers= (server_startup_st*)object; + test_true(servers); + +#if !defined(MEMCACHED_BINARY) && !defined(HAVE_LIBMEMCACHED) + return TEST_SKIPPED; +#endif + + const char *argv[1]= { "cycle_memcached" }; + test_true(servers->start_socket_server("memcached", 9997, 1, argv)); + + return TEST_SUCCESS; +} + +test_st gearmand_tests[] ={ +#if 0 + {"pause", 0, pause_test }, +#endif + {"gearmand startup-shutdown", 0, gearmand_cycle_test }, + {0, 0, 0} +}; + +test_st memcached_tests[] ={ + {"memcached startup-shutdown", 0, memcached_cycle_test }, + {"memcached(socket file) startup-shutdown", 0, memcached_socket_cycle_test }, + {0, 0, 0} +}; test_st tests_log[] ={ {"TEST_SUCCESS", 0, test_success_test }, + {"TEST_FAILURE", 0, test_failure_test }, {0, 0, 0} }; @@ -78,10 +186,18 @@ test_st local_log[] ={ collection_st collection[] ={ {"return values", 0, 0, tests_log}, {"local", 0, 0, local_log}, + {"gearmand", 0, 0, gearmand_tests}, + {"memcached", 0, 0, memcached_tests}, {0, 0, 0, 0} }; -void get_world(Framework *arg) +static void *world_create(server_startup_st& servers, test_return_t&) +{ + return &servers; +} + +void get_world(Framework *world) { - arg->collections= collection; + world->collections= collection; + world->_create= world_create; }