14 #include "testing/conf.h"
15 #include "testing/lib/catch.hpp"
16 #include "testing/lib/random.hpp"
18 #include "libmemcached/memcached.h"
21 using socket_or_port_t = variant<string, int>;
24 * Useful macros for testing
26 #define S(s) (s),strlen(s)
27 #define DECLARE_STREQUAL static auto strequal = equal_to<string>();
28 #define LOOPED_SECTION(tests) \
29 for (auto &[name, test] : tests) DYNAMIC_SECTION("test " << name)
30 #define REQUIRE_SUCCESS(rc) do { \
31 INFO("expected: SUCCESS"); \
32 REQUIRE_THAT(rc, test.returns.success()); \
34 #define REQUIRE_RC(rc, call) do { \
35 INFO("expected: " << memcached_strerror(nullptr, rc)); \
36 REQUIRE_THAT(call, test.returns(rc)); \
39 const char *getenv_else(const char *var, const char *defval);
41 inline memcached_return_t fetch_all_results(memcached_st *memc, unsigned int &keys_returned, memcached_return_t &rc) {
44 memcached_result_st *result = nullptr;
45 while ((result = memcached_fetch_result(memc, result, &rc))) {
46 REQUIRE(MEMCACHED_SUCCESS == rc);
49 memcached_result_free(result);
50 return MEMCACHED_SUCCESS;
53 inline memcached_return_t fetch_all_results(memcached_st *memc, unsigned int &keys_returned) {
54 memcached_return_t rc;
55 fetch_all_results(memc, keys_returned, rc);
64 explicit Tempfile(const char templ_[] = "memc.test.XXXXXX") {
65 *copy(S(templ_)+templ_, fn) = '\0';
75 const char *getFn() const {
78 bool put(const char *buf, size_t len) const {
79 return static_cast<ssize_t >(len) == write(fd, buf, len);
91 MemcachedPtr(memcached_st *memc_) {
95 : MemcachedPtr(memcached_create(nullptr))
100 memcached_st *operator * () {