#include "test/conf.h"
#include "test/lib/catch.hpp"
+#include "test/lib/env.hpp"
#include "test/lib/random.hpp"
#include "libmemcached/memcached.h"
/**
* Useful macros for testing
*/
-#define S(s) (s), strlen(s)
-#define DECLARE_STREQUAL static auto strequal = equal_to<string>();
+#define S(s) (s), strlen(s)
#define LOOPED_SECTION(tests) \
for (auto &[name, test] : tests) DYNAMIC_SECTION("test " << name)
#define REQUIRE_SUCCESS(rc) \
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;
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<class T>
if (ptr)
free(ptr);
}
- auto operator*() { return ptr; }
- auto operator->() { return ptr; }
+ auto operator*() const { return ptr; }
+ auto operator->() const { return ptr; }
};
#include "libmemcached/continuum.hpp"
#include "libmemcached/instance.hpp"
-DECLARE_STREQUAL;
-
TEST_CASE("memcached_ketama_compat") {
auto test = MemcachedCluster::network();
auto memc = &test.memc;
/* 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);
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);
/* 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);
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);
/* 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);
// 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);
/* 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);
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);