X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Funittest.cc;h=b81ef5e760360f494965ee869c993f77cc31a9e8;hb=16d48d83b08ec8c16269ab68ead2ef7ede86aafb;hp=0af3e30f8ab21977c9c7ce6c3ffbef0ae22f15b5;hpb=3893029e70c654f4fcf3bf8f8ba5b404afc6d446;p=m6w6%2Flibmemcached diff --git a/libtest/unittest.cc b/libtest/unittest.cc index 0af3e30f..b81ef5e7 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -34,16 +34,16 @@ * */ -#include +#include "libtest/yatlcon.h" #include -#if defined(LIBTEST_WITH_LIBMEMCACHED_SUPPORT) && LIBTEST_WITH_LIBMEMCACHED_SUPPORT -#include +#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H +# include #endif -#if defined(LIBTEST_WITH_LIBGEARMAN_SUPPORT) && LIBTEST_WITH_LIBGEARMAN_SUPPORT -#include +#if defined(HAVE_LIBGEARMAN_1_0_RETURN_H) && HAVE_LIBGEARMAN_1_0_RETURN_H +# include #endif #include @@ -56,6 +56,18 @@ static std::string testing_service; // Used to track setups where we see if failure is happening static uint32_t fatal_calls= 0; +static test_return_t getenv_TEST(void *) +{ +#if 0 + for (char **ptr= environ; *ptr; ptr++) + { + Error << *ptr; + } +#endif + + return TEST_SUCCESS; +} + static test_return_t LIBTOOL_COMMAND_test(void *) { test_true(getenv("LIBTOOL_COMMAND")); @@ -83,7 +95,7 @@ static test_return_t GDB_COMMAND_test(void *) static test_return_t test_success_equals_one_test(void *) { test_skip(HAVE_LIBMEMCACHED, 1); -#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED +#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H test_zero(MEMCACHED_SUCCESS); #endif return TEST_SUCCESS; @@ -94,6 +106,60 @@ static test_return_t test_success_test(void *) return TEST_SUCCESS; } +static test_return_t test_throw_success_TEST(void *) +{ + try { + _SUCCESS; + } + catch (libtest::__success) + { + return TEST_SUCCESS; + } + catch (...) + { + return TEST_FAILURE; + } + + return TEST_FAILURE; +} + +static test_return_t test_throw_skip_TEST(void *) +{ + try { + SKIP; + } + catch (libtest::__skipped) + { + return TEST_SUCCESS; + } + catch (...) + { + return TEST_FAILURE; + } + + return TEST_FAILURE; +} + +static test_return_t test_throw_fail_TEST(void *) +{ + std::string error_messsage("test message!"); + try { + FAIL(error_messsage); + } + catch (libtest::__failure e) + { + std::string compare_message("test message!"); + test_zero(compare_message.compare(e.what())); + return TEST_SUCCESS; + } + catch (...) + { + return TEST_FAILURE; + } + + return TEST_FAILURE; +} + static test_return_t test_failure_test(void *) { return TEST_SKIPPED; // Only run this when debugging @@ -245,7 +311,7 @@ static test_return_t _compare_test_return_t_test(void *) static test_return_t _compare_memcached_return_t_test(void *) { test_skip(HAVE_LIBMEMCACHED, true); -#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED +#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H test_compare(MEMCACHED_SUCCESS, MEMCACHED_SUCCESS); #endif @@ -255,7 +321,7 @@ static test_return_t _compare_memcached_return_t_test(void *) static test_return_t _compare_gearman_return_t_test(void *) { test_skip(HAVE_LIBGEARMAN, true); -#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN +#if defined(HAVE_LIBGEARMAN_1_0_RETURN_H) && HAVE_LIBGEARMAN_1_0_RETURN_H test_compare(GEARMAN_SUCCESS, GEARMAN_SUCCESS); #endif @@ -290,20 +356,6 @@ static test_return_t gearmand_cycle_test(void *object) return TEST_SUCCESS; } -#if 0 -static test_return_t memcached_light_cycle_TEST(void *object) -{ - server_startup_st *servers= (server_startup_st*)object; - test_true(servers); - - test_skip(true, bool(HAVE_MEMCACHED_LIGHT_BINARY)); - - test_true(server_startup(*servers, "memcached-light", get_free_port(), 0, NULL, false)); - - return TEST_SUCCESS; -} -#endif - static test_return_t skip_shim(bool a, bool b) { test_skip(a, b); @@ -409,6 +461,8 @@ static test_return_t application_true_BINARY(void *) static test_return_t application_gdb_true_BINARY2(void *) { test_skip(0, access("/usr/bin/gdb", X_OK )); + test_skip(0, access("/usr/bin/true", X_OK )); + Application true_app("/usr/bin/true"); true_app.use_gdb(); @@ -421,6 +475,8 @@ static test_return_t application_gdb_true_BINARY2(void *) static test_return_t application_gdb_true_BINARY(void *) { test_skip(0, access("/usr/bin/gdb", X_OK )); + test_skip(0, access("/usr/bin/true", X_OK )); + Application true_app("/usr/bin/true"); true_app.use_gdb(); @@ -454,6 +510,8 @@ static test_return_t application_doesnotexist_BINARY(void *) const char *args[]= { "--fubar", 0 }; #if defined(TARGET_OS_OSX) && TARGET_OS_OSX test_compare(Application::INVALID_POSIX_SPAWN, true_app.run(args)); +#elif defined(TARGET_OS_FREEBSD) && TARGET_OS_FREEBSD + test_compare(Application::INVALID_POSIX_SPAWN, true_app.run(args)); #else test_compare(Application::SUCCESS, true_app.run(args)); test_compare(Application::INVALID_POSIX_SPAWN, true_app.join()); @@ -622,8 +680,9 @@ static test_return_t wait_services_BINARY2(void *) static test_return_t wait_services_appliction_TEST(void *) { - test_skip(0, access("/usr/bin/gdb", X_OK )); test_skip(0, access("/etc/services", R_OK )); + test_skip(0, access("/usr/bin/gdb", X_OK )); + test_skip(0, access("libtest/wait", X_OK )); libtest::Application wait_app("libtest/wait", true); wait_app.use_gdb(); @@ -642,8 +701,9 @@ static test_return_t gdb_wait_services_appliction_TEST(void *) test_skip(0, TARGET_OS_OSX); #endif - test_skip(0, access("/usr/bin/gdb", X_OK )); test_skip(0, access("/etc/services", R_OK )); + test_skip(0, access("/usr/bin/gdb", X_OK )); + test_skip(0, access("libtest/wait", X_OK )); libtest::Application wait_app("libtest/wait", true); wait_app.use_gdb(); @@ -657,8 +717,9 @@ static test_return_t gdb_wait_services_appliction_TEST(void *) static test_return_t gdb_abort_services_appliction_TEST(void *) { - test_skip(true, false); test_skip(0, access("/usr/bin/gdb", X_OK )); + test_skip(0, access("libtest/abort", X_OK )); + test_skip(true, false); #if defined(TARGET_OS_OSX) && TARGET_OS_OSX test_skip(0, TARGET_OS_OSX); @@ -748,6 +809,7 @@ static test_return_t lookup_false_TEST(void *) static test_return_t create_tmpfile_TEST(void *) { + test_skip(0, access("/usr/bin/touch", X_OK )); std::string tmp= create_tmpfile(__func__); test_compare(-1, access(tmp.c_str(), R_OK)); test_compare(-1, access(tmp.c_str(), F_OK)); @@ -784,6 +846,16 @@ static test_return_t check_for_gearman(void *) { test_skip(true, HAVE_LIBGEARMAN); test_skip(true, has_gearmand()); +#if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY + if (GEARMAND_BINARY) + { + test_zero(access(GEARMAND_BINARY, X_OK )); + } + else + { + return TEST_SKIPPED; + } +#endif testing_service= "gearmand"; @@ -856,6 +928,7 @@ test_st test_skip_TESTS[] ={ }; test_st environment_tests[] ={ + {"getenv()", 0, getenv_TEST }, {"LIBTOOL_COMMAND", 0, LIBTOOL_COMMAND_test }, {"VALGRIND_COMMAND", 0, VALGRIND_COMMAND_test }, {"HELGRIND_COMMAND", 0, HELGRIND_COMMAND_test }, @@ -867,6 +940,9 @@ test_st tests_log[] ={ {"TEST_SUCCESS", false, test_success_test }, {"TEST_FAILURE", false, test_failure_test }, {"TEST_SUCCESS == 0", false, test_success_equals_one_test }, + {"SUCCESS", false, test_throw_success_TEST }, + {"SKIP", false, test_throw_skip_TEST }, + {"FAIL", false, test_throw_fail_TEST }, {0, 0, 0} };