2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
30 #include "test/conf.h"
31 #include "test/lib/catch.hpp"
32 #include "test/lib/env.hpp"
33 #include "test/lib/random.hpp"
35 #include "libmemcached/memcached.h"
38 using socket_or_port_t = variant<string, int>;
41 * Useful macros for testing
43 #define S(s) (s), strlen(s)
44 #define LOOPED_SECTION(tests) \
45 for (auto &[name, test] : tests) DYNAMIC_SECTION("test " << name)
46 #define REQUIRE_SUCCESS(rc) \
48 INFO("expected: SUCCESS"); \
49 REQUIRE_THAT(rc, test.returns.success()); \
51 #define REQUIRE_RC(rc, call) \
53 INFO("expected: " << memcached_strerror(nullptr, rc)); \
54 REQUIRE_THAT(call, test.returns(rc)); \
57 inline memcached_return_t fetch_all_results(memcached_st *memc, unsigned int &keys_returned,
58 memcached_return_t &rc) {
61 memcached_result_st *result = nullptr;
62 while ((result = memcached_fetch_result(memc, result, &rc))) {
63 REQUIRE(MEMCACHED_SUCCESS == rc);
66 memcached_result_free(result);
67 return MEMCACHED_SUCCESS;
70 inline memcached_return_t fetch_all_results(memcached_st *memc, unsigned int &keys_returned) {
71 memcached_return_t rc;
72 fetch_all_results(memc, keys_returned, rc);
81 explicit Tempfile(const char templ_[] = "memc.test.XXXXXX") {
82 *copy(S(templ_) + templ_, fn) = '\0';
89 [[nodiscard]] int getFd() const { return fd; }
90 [[nodiscard]] const char *getFn() const { return fn; }
91 bool put(const char *buf, size_t len) const {
92 return static_cast<ssize_t>(len) == write(fd, buf, len);
99 lseek(fd, 0, SEEK_SET);
100 while (0 < (len = read(fd, buf, sizeof(buf)))) {
101 all.append(buf, len);
115 explicit MemcachedPtr(memcached_st *memc_) {
119 : MemcachedPtr(memcached_create(nullptr)) {}
121 memcached_free(memc);
123 memcached_st *operator*() const {
126 auto operator->() const {
136 explicit Malloced(T *ptr_)
138 Malloced &operator=(T *ptr_) {
148 auto operator*() const { return ptr; }
149 auto operator->() const { return ptr; }