From: Brian Aker Date: Sat, 23 Feb 2013 21:43:42 +0000 (-0500) Subject: See if we can clean up error reporting on one test for Ubuntu 12.04 X-Git-Tag: 1.0.17~4^2~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=4e7c4a986b51441df4241e94ee39cabe17cd3709;p=awesomized%2Flibmemcached See if we can clean up error reporting on one test for Ubuntu 12.04 --- diff --git a/libtest/lite.h b/libtest/lite.h index 100b8e20..70aee2b0 100644 --- a/libtest/lite.h +++ b/libtest/lite.h @@ -348,7 +348,7 @@ do \ } \ } while (0) -#define ASSERT_NEQ(__expected, __actual, ...) \ +#define ASSERT_NEQ(__expected, __actual) \ do \ { \ if ((__expected) == (__actual)) { \ diff --git a/libtest/memcached.hpp b/libtest/memcached.hpp index e0e14851..142f167c 100644 --- a/libtest/memcached.hpp +++ b/libtest/memcached.hpp @@ -39,7 +39,7 @@ #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED inline bool operator== (const memcached_st& memc, const memcached_return_t rc) { - if (memcached_last_error(const_cast(&memc)) == rc) + if (memcached_last_error(&memc) == rc) { return true; } @@ -47,7 +47,7 @@ inline bool operator== (const memcached_st& memc, const memcached_return_t rc) return false; } -inline bool operator!= (const memcached_st& memc, const memcached_return_t rc) +inline bool operator!= (const memcached_st& memc, memcached_return_t rc) { if (memcached_last_error(const_cast(&memc)) != rc) { @@ -57,7 +57,27 @@ inline bool operator!= (const memcached_st& memc, const memcached_return_t rc) return false; } -inline bool operator!= (const memcached_return_t rc, const memcached_st& memc) +inline bool operator== (memcached_st* const memc, memcached_return_t rc) +{ + if (memcached_last_error(memc) == rc) + { + return true; + } + + return false; +} + +inline bool operator!= (memcached_st* const memc, memcached_return_t rc) +{ + if (memcached_last_error(memc) != rc) + { + return true; + } + + return false; +} + +inline bool operator!= (memcached_return_t rc, const memcached_st& memc) { if (memcached_last_error(const_cast(&memc)) != rc) { @@ -66,5 +86,15 @@ inline bool operator!= (const memcached_return_t rc, const memcached_st& memc) return false; } + +inline bool operator!= (memcached_return_t rc, memcached_st* const memc) +{ + if (memcached_last_error(memc) != rc) + { + return true; + } + + return false; +} #endif diff --git a/libtest/unittest.cc b/libtest/unittest.cc index b96fea06..834614fc 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -199,6 +199,31 @@ static test_return_t ASSERT_FALSE__TEST(void *) return TEST_FAILURE; } +static test_return_t ASSERT_NEQ_FAIL_TEST(void *) +{ + try { + ASSERT_NEQ(1,1); + } + catch (const libtest::__failure& e) + { + ASSERT_STREQ(e.what(), "Assertion '1' == '1'"); + return TEST_SUCCESS; + } + catch (...) + { + return TEST_FAILURE; + } + + return TEST_FAILURE; +} + +static test_return_t ASSERT_NEQ_TEST(void *) +{ + ASSERT_NEQ(1,0); + + return TEST_SUCCESS; +} + static test_return_t ASSERT_FALSE_TEST(void *) { try { @@ -1012,6 +1037,8 @@ test_st tests_log[] ={ {"FAIL", false, test_throw_fail_TEST }, {"ASSERT_FALSE_", false, ASSERT_FALSE__TEST }, {"ASSERT_FALSE", false, ASSERT_FALSE_TEST }, + {"ASSERT_NEQ", false, ASSERT_NEQ_TEST }, + {"ASSERT_NEQ FAIL", false, ASSERT_NEQ_FAIL_TEST }, {0, 0, 0} }; diff --git a/tests/libmemcached-1.0/all_tests.h b/tests/libmemcached-1.0/all_tests.h index 643812d3..2012d477 100644 --- a/tests/libmemcached-1.0/all_tests.h +++ b/tests/libmemcached-1.0/all_tests.h @@ -164,6 +164,7 @@ test_st basic_tests[] ={ {"reset stack clone", true, (test_callback_fn*)basic_reset_stack_clone_test}, {"reset heap clone", true, (test_callback_fn*)basic_reset_heap_clone_test}, {"memcached_return_t", false, (test_callback_fn*)memcached_return_t_TEST }, + {"c++ memcached_st == memcached_return_t", false, (test_callback_fn*)comparison_operator_memcached_st_and__memcached_return_t_TEST }, {0, 0, 0} }; diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index 4241220a..ccfbe83e 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -2813,6 +2813,20 @@ test_return_t user_supplied_bug21(memcached_st *memc) return TEST_SUCCESS; } +test_return_t comparison_operator_memcached_st_and__memcached_return_t_TEST(memcached_st *) +{ + test::Memc memc_; + + memcached_st *memc= &memc_; + + ASSERT_EQ(memc, MEMCACHED_SUCCESS); + test_compare(memc, MEMCACHED_SUCCESS); + + ASSERT_NEQ(memc, MEMCACHED_FAILURE); + + return TEST_SUCCESS; +} + test_return_t ketama_TEST(memcached_st *) { test::Memc memc("--server=10.0.1.1:11211 --server=10.0.1.2:11211"); @@ -4666,7 +4680,7 @@ test_return_t regression_bug_583031(memcached_st *) test_false(value); test_zero(length); - test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_error(memc)); + test_compare(MEMCACHED_TIMEOUT, memc); memcached_free(memc); diff --git a/tests/libmemcached-1.0/mem_functions.h b/tests/libmemcached-1.0/mem_functions.h index 0ecea0d2..9edc820e 100644 --- a/tests/libmemcached-1.0/mem_functions.h +++ b/tests/libmemcached-1.0/mem_functions.h @@ -184,3 +184,4 @@ test_return_t regression_994772_TEST(memcached_st*); test_return_t regression_1009493_TEST(memcached_st*); test_return_t regression_1048945_TEST(memcached_st*); test_return_t regression_1067242_TEST(memcached_st*); +test_return_t comparison_operator_memcached_st_and__memcached_return_t_TEST(memcached_st*);