projects
/
awesomized
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
C++: double underscores are reserved
[awesomized/libmemcached]
/
test
/
lib
/
common.hpp
diff --git
a/test/lib/common.hpp
b/test/lib/common.hpp
index a76a1ca8f8c94d80116cc75dabe9d470013f6d58..083efe0d66f060eaa2f4dd2baa2e7de7efc6659a 100644
(file)
--- a/
test/lib/common.hpp
+++ b/
test/lib/common.hpp
@@
-16,6
+16,7
@@
#pragma once
#include <chrono>
#pragma once
#include <chrono>
+#include <cstring>
#include <iostream>
#include <map>
#include <optional>
#include <iostream>
#include <map>
#include <optional>
@@
-28,6
+29,7
@@
#include "test/conf.h"
#include "test/lib/catch.hpp"
#include "test/conf.h"
#include "test/lib/catch.hpp"
+#include "test/lib/env.hpp"
#include "test/lib/random.hpp"
#include "libmemcached/memcached.h"
#include "test/lib/random.hpp"
#include "libmemcached/memcached.h"
@@
-38,8
+40,7
@@
using socket_or_port_t = variant<string, int>;
/**
* Useful macros for testing
*/
/**
* 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) \
#define LOOPED_SECTION(tests) \
for (auto &[name, test] : tests) DYNAMIC_SECTION("test " << name)
#define REQUIRE_SUCCESS(rc) \
@@
-53,8
+54,6
@@
using socket_or_port_t = variant<string, int>;
REQUIRE_THAT(call, test.returns(rc)); \
} while (0)
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;
inline memcached_return_t fetch_all_results(memcached_st *memc, unsigned int &keys_returned,
memcached_return_t &rc) {
keys_returned = 0;
@@
-87,11
+86,22
@@
public:
close(fd);
unlink(fn);
}
close(fd);
unlink(fn);
}
- int getFd() const { return fd; }
- const char *getFn() const { return fn; }
+
[[nodiscard]]
int getFd() const { return fd; }
+
[[nodiscard]]
const char *getFn() const { return fn; }
bool put(const char *buf, size_t len) const {
return static_cast<ssize_t>(len) == write(fd, buf, len);
}
bool put(const char *buf, size_t len) const {
return static_cast<ssize_t>(len) == write(fd, buf, len);
}
+ string get() const {
+ string all;
+ char buf[200];
+ ssize_t len;
+
+ lseek(fd, 0, SEEK_SET);
+ while (0 < (len = read(fd, buf, sizeof(buf)))) {
+ all.append(buf, len);
+ }
+ return all;
+ }
private:
char fn[80];
private:
char fn[80];
@@
-102,12
+112,20
@@
class MemcachedPtr {
public:
memcached_st *memc;
public:
memcached_st *memc;
- explicit MemcachedPtr(memcached_st *memc_) { memc = memc_; }
+ explicit MemcachedPtr(memcached_st *memc_) {
+ memc = memc_;
+ }
MemcachedPtr()
: MemcachedPtr(memcached_create(nullptr)) {}
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>
};
template<class T>
@@
-127,6
+145,6
@@
public:
if (ptr)
free(ptr);
}
if (ptr)
free(ptr);
}
- auto operator*() { return ptr; }
- auto operator->() { return ptr; }
+ auto operator*()
const
{ return ptr; }
+ auto operator->()
const
{ return ptr; }
};
};