14 #include "testing/lib/catch.hpp"
15 #include "testing/lib/random.hpp"
17 #include "libmemcached/memcached.h"
20 using socket_or_port_t = variant<string, int>;
23 * Useful macros for testing
25 #define S(s) (s),strlen(s)
26 #define DECLARE_STREQUAL static auto strequal = equal_to<string>();
27 #define LOOPED_SECTION(tests) \
28 for (auto &[name, test] : tests) DYNAMIC_SECTION("test " << name)
29 #define REQUIRE_SUCCESS(rc) do { \
30 INFO("expected: SUCCESS"); \
31 REQUIRE_THAT(rc, test.returns.success()); \
33 #define REQUIRE_RC(rc, call) do { \
34 INFO("expected: " << memcached_strerror(nullptr, rc)); \
35 REQUIRE_THAT(call, test.returns(rc)); \
38 const char *getenv_else(const char *var, const char *defval);
40 inline memcached_return_t fetch_all_results(memcached_st *memc, unsigned int &keys_returned, memcached_return_t &rc) {
43 memcached_result_st *result = nullptr;
44 while ((result = memcached_fetch_result(memc, result, &rc))) {
45 REQUIRE(MEMCACHED_SUCCESS == rc);
48 memcached_result_free(result);
49 return MEMCACHED_SUCCESS;
52 inline memcached_return_t fetch_all_results(memcached_st *memc, unsigned int &keys_returned) {
53 memcached_return_t rc;
54 fetch_all_results(memc, keys_returned, rc);
63 MemcachedPtr(memcached_st *memc_) {
67 : MemcachedPtr(memcached_create(nullptr))
72 memcached_st *operator * () {