From: Michael Wallner Date: Fri, 23 Oct 2020 16:44:28 +0000 (+0200) Subject: testing: cleanup X-Git-Tag: 1.1.0-beta1~167 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=f013c48684ce1d405dc80815139b31282a2a48f5;p=m6w6%2Flibmemcached testing: cleanup --- diff --git a/test/lib/common.cpp b/test/lib/common.cpp deleted file mode 100644 index c516a3db..00000000 --- a/test/lib/common.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "common.hpp" - -#include - -const char *getenv_else(const char *var, const char *defval) { - auto val = getenv(var); - if (val && *val) { - return val; - } - return defval; -} - diff --git a/test/lib/common.hpp b/test/lib/common.hpp index a0fdf384..8942a729 100644 --- a/test/lib/common.hpp +++ b/test/lib/common.hpp @@ -28,6 +28,7 @@ #include "test/conf.h" #include "test/lib/catch.hpp" +#include "test/lib/env.hpp" #include "test/lib/random.hpp" #include "libmemcached/memcached.h" @@ -38,8 +39,7 @@ using socket_or_port_t = variant; /** * Useful macros for testing */ -#define S(s) (s), strlen(s) -#define DECLARE_STREQUAL static auto strequal = equal_to(); +#define S(s) (s), strlen(s) #define LOOPED_SECTION(tests) \ for (auto &[name, test] : tests) DYNAMIC_SECTION("test " << name) #define REQUIRE_SUCCESS(rc) \ @@ -53,8 +53,6 @@ using socket_or_port_t = variant; REQUIRE_THAT(call, test.returns(rc)); \ } while (0) -const char *getenv_else(const char *var, const char *defval); - inline memcached_return_t fetch_all_results(memcached_st *memc, unsigned int &keys_returned, memcached_return_t &rc) { keys_returned = 0; @@ -102,12 +100,20 @@ class MemcachedPtr { public: memcached_st *memc; - explicit MemcachedPtr(memcached_st *memc_) { memc = memc_; } + explicit MemcachedPtr(memcached_st *memc_) { + memc = memc_; + } MemcachedPtr() : MemcachedPtr(memcached_create(nullptr)) {} - ~MemcachedPtr() { memcached_free(memc); } - memcached_st *operator*() const { return memc; } - auto operator->() const { return memc; } + ~MemcachedPtr() { + memcached_free(memc); + } + memcached_st *operator*() const { + return memc; + } + auto operator->() const { + return memc; + } }; template @@ -127,6 +133,6 @@ public: if (ptr) free(ptr); } - auto operator*() { return ptr; } - auto operator->() { return ptr; } + auto operator*() const { return ptr; } + auto operator->() const { return ptr; } }; diff --git a/test/lib/env.hpp b/test/lib/env.hpp index 6bc4da66..b1b35885 100644 --- a/test/lib/env.hpp +++ b/test/lib/env.hpp @@ -33,3 +33,11 @@ #define SET_ENV(symbolic_name, literal_env_var, literal_env_val) \ SET_ENV_EX(symbolic_name, literal_env_var, literal_env_val, true) + +static inline const char *getenv_else(const char *var, const char *defval) { + auto val = getenv(var); + if (val && *val) { + return val; + } + return defval; +} diff --git a/test/tests/memcached/append.cpp b/test/tests/memcached/append.cpp index 2b2449fd..fec1ea4b 100644 --- a/test/tests/memcached/append.cpp +++ b/test/tests/memcached/append.cpp @@ -1,8 +1,6 @@ #include "test/lib/common.hpp" #include "test/lib/MemcachedCluster.hpp" -DECLARE_STREQUAL; - TEST_CASE("memcached_append") { pair tests[] = { {"bin_mixed", MemcachedCluster::mixed()}, @@ -33,7 +31,7 @@ TEST_CASE("memcached_append") { uint32_t flags; Malloced got(memcached_get(memc, S(key), &len, &flags, &rc)); - REQUIRE(strequal(cmp, *got)); + REQUIRE(cmp == *got); REQUIRE_SUCCESS(rc); } } @@ -56,7 +54,7 @@ TEST_CASE("memcached_append") { Malloced got(memcached_get(memc, S(__func__), &len, &flags, &rc)); REQUIRE(len == raw_len); - REQUIRE(strequal({raw_ptr, raw_len}, string{*got, len})); + REQUIRE(string{raw_ptr, raw_len} == string{*got, len}); REQUIRE_SUCCESS(rc); } } diff --git a/test/tests/memcached/ketama.cpp b/test/tests/memcached/ketama.cpp index 75d18c2c..61e11957 100644 --- a/test/tests/memcached/ketama.cpp +++ b/test/tests/memcached/ketama.cpp @@ -6,8 +6,6 @@ #include "libmemcached/continuum.hpp" #include "libmemcached/instance.hpp" -DECLARE_STREQUAL; - TEST_CASE("memcached_ketama_compat") { auto test = MemcachedCluster::network(); auto memc = &test.memc; @@ -27,13 +25,13 @@ TEST_CASE("memcached_ketama_compat") { /* verify that the server list was parsed okay. */ REQUIRE(8U == memcached_server_count(memc)); - REQUIRE(strequal(server_pool[0].hostname, "10.0.1.1")); + REQUIRE(server_pool[0].hostname == "10.0.1.1"s); REQUIRE(in_port_t(11211) == server_pool[0].port); REQUIRE(600U == server_pool[0].weight); - REQUIRE(strequal(server_pool[2].hostname, "10.0.1.3")); + REQUIRE(server_pool[2].hostname == "10.0.1.3"s); REQUIRE(in_port_t(11211) == server_pool[2].port); REQUIRE(200U == server_pool[2].weight); - REQUIRE(strequal(server_pool[7].hostname, "10.0.1.8")); + REQUIRE(server_pool[7].hostname == "10.0.1.8"s); REQUIRE(in_port_t(11211) == server_pool[7].port); REQUIRE(100U == server_pool[7].weight); @@ -49,7 +47,7 @@ TEST_CASE("memcached_ketama_compat") { memcached_server_instance_by_position(memc, server_idx); const char *hostname = memcached_server_name(instance); - REQUIRE(strequal(hostname, ketama_test_cases[x].server)); + REQUIRE(string{hostname} == ketama_test_cases[x].server); } memcached_server_list_free(server_pool); @@ -68,13 +66,13 @@ TEST_CASE("memcached_ketama_compat") { /* verify that the server list was parsed okay. */ REQUIRE(memcached_server_count(memc) == 8); - REQUIRE(strequal(server_pool[0].hostname, "10.0.1.1")); + REQUIRE(server_pool[0].hostname == "10.0.1.1"s); REQUIRE(server_pool[0].port == 11211); REQUIRE(server_pool[0].weight == 600); - REQUIRE(strequal(server_pool[2].hostname, "10.0.1.3")); + REQUIRE(server_pool[2].hostname == "10.0.1.3"s); REQUIRE(server_pool[2].port == 11211); REQUIRE(server_pool[2].weight == 200); - REQUIRE(strequal(server_pool[7].hostname, "10.0.1.8")); + REQUIRE(server_pool[7].hostname == "10.0.1.8"s); REQUIRE(server_pool[7].port == 11211); REQUIRE(server_pool[7].weight == 100); @@ -91,7 +89,7 @@ TEST_CASE("memcached_ketama_compat") { memcached_server_instance_by_position(memc, server_idx); const char *hostname = memcached_server_name(instance); - REQUIRE(strequal(hostname, ketama_test_cases[x].server)); + REQUIRE(string{hostname} == ketama_test_cases[x].server); } memcached_server_list_free(server_pool); @@ -116,13 +114,13 @@ TEST_CASE("memcached_ketama_compat") { /* verify that the server list was parsed okay. */ REQUIRE(memcached_server_count(memc) == 8); - REQUIRE(strequal(server_pool[0].hostname, "10.0.1.1")); + REQUIRE(server_pool[0].hostname == "10.0.1.1"s); REQUIRE(server_pool[0].port == 11211); REQUIRE(server_pool[0].weight == 600); - REQUIRE(strequal(server_pool[2].hostname, "10.0.1.3")); + REQUIRE(server_pool[2].hostname == "10.0.1.3"s); REQUIRE(server_pool[2].port == 11211); REQUIRE(server_pool[2].weight == 200); - REQUIRE(strequal(server_pool[7].hostname, "10.0.1.8")); + REQUIRE(server_pool[7].hostname == "10.0.1.8"s); REQUIRE(server_pool[7].port == 11211); REQUIRE(server_pool[7].weight == 100); @@ -149,7 +147,7 @@ TEST_CASE("memcached_ketama_compat") { // We re-use instance from above. instance = memcached_server_instance_by_position(memc, server_idx); const char *hostname = memcached_server_name(instance); - REQUIRE(strequal(hostname, ketama_test_cases[x].server)); + REQUIRE(string{hostname} == ketama_test_cases[x].server); } memcached_server_list_free(server_pool); @@ -168,13 +166,13 @@ TEST_CASE("memcached_ketama_compat") { /* verify that the server list was parsed okay. */ REQUIRE(8U == memcached_server_count(memc)); - REQUIRE(strequal(server_pool[0].hostname, "10.0.1.1")); + REQUIRE(server_pool[0].hostname == "10.0.1.1"s); REQUIRE(in_port_t(11211) == server_pool[0].port); REQUIRE(600U == server_pool[0].weight); - REQUIRE(strequal(server_pool[2].hostname, "10.0.1.3")); + REQUIRE(server_pool[2].hostname == "10.0.1.3"s); REQUIRE(in_port_t(11211) == server_pool[2].port); REQUIRE(200U == server_pool[2].weight); - REQUIRE(strequal(server_pool[7].hostname, "10.0.1.8")); + REQUIRE(server_pool[7].hostname == "10.0.1.8"s); REQUIRE(in_port_t(11211) == server_pool[7].port); REQUIRE(100U == server_pool[7].weight); @@ -192,7 +190,7 @@ TEST_CASE("memcached_ketama_compat") { memcached_server_instance_by_position(memc, server_idx); const char *hostname = memcached_server_name(instance); - REQUIRE(strequal(hostname, ketama_test_cases_spy[x].server)); + REQUIRE(string{hostname} == ketama_test_cases_spy[x].server); } memcached_server_list_free(server_pool);