X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=testing%2Flib%2Fcommon.hpp;h=ee177003bac8fbf3b2a5a0cff0b4be838158fb36;hb=cbaa9f46519f9b085e28db5f44247d23ca7ec5a4;hp=9f9578224d48581a798a6b717c9d600b35ea4641;hpb=c0b779f4045f4858701b3741af805414bc066717;p=awesomized%2Flibmemcached diff --git a/testing/lib/common.hpp b/testing/lib/common.hpp index 9f957822..ee177003 100644 --- a/testing/lib/common.hpp +++ b/testing/lib/common.hpp @@ -11,6 +11,7 @@ #include #include +#include "testing/conf.h" #include "testing/lib/catch.hpp" #include "testing/lib/random.hpp" @@ -55,6 +56,33 @@ inline memcached_return_t fetch_all_results(memcached_st *memc, unsigned int &ke return rc; } +#include +#include + +class Tempfile { +public: + explicit Tempfile(const char templ_[] = "memc.test.XXXXXX") { + *copy(S(templ_)+templ_, fn) = '\0'; + fd = mkstemp(fn); + } + ~Tempfile() { + close(fd); + unlink(fn); + } + int getFd() const { + return fd; + } + const char *getFn() const { + return fn; + } + bool put(const char *buf, size_t len) const { + return static_cast(len) == write(fd, buf, len); + } +private: + char fn[80]; + int fd; +}; + class MemcachedPtr { public: memcached_st *memc; @@ -78,6 +106,7 @@ template class Malloced { T *ptr; public: + explicit Malloced(T *ptr_) : ptr{ptr_} {} @@ -88,4 +117,7 @@ public: auto operator *() { return ptr; } + auto operator ->() { + return ptr; + } };