From: Casey Bodley Date: Fri, 22 Jan 2016 20:25:15 +0000 (-0500) Subject: test: add ceph-dencoder test for ceph::real_time X-Git-Tag: v10.0.4~53^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0f6bfbeca37c82402cb8652159655fd978366949;p=ceph.git test: add ceph-dencoder test for ceph::real_time Signed-off-by: Casey Bodley --- diff --git a/src/test/Makefile-client.am b/src/test/Makefile-client.am index 967dde46baac..928e2a1f160b 100644 --- a/src/test/Makefile-client.am +++ b/src/test/Makefile-client.am @@ -29,6 +29,8 @@ endif bin_PROGRAMS += ceph-dencoder +noinst_HEADERS += \ + test/encoding/test_ceph_time.h if WITH_RADOS diff --git a/src/test/encoding/test_ceph_time.h b/src/test/encoding/test_ceph_time.h new file mode 100644 index 000000000000..7adcb8f22ba5 --- /dev/null +++ b/src/test/encoding/test_ceph_time.h @@ -0,0 +1,30 @@ +#ifndef TEST_CEPH_TIME_H +#define TEST_CEPH_TIME_H + +#include +#include "common/ceph_time.h" + +// wrapper for ceph::real_time that implements the dencoder interface +class real_time_wrapper { + ceph::real_time t; + public: + real_time_wrapper() = default; + real_time_wrapper(const ceph::real_time& t) : t(t) {} + + void encode(bufferlist& bl) const { + ::encode(t, bl); + } + void decode(bufferlist::iterator &p) { + ::decode(t, p); + } + void dump(Formatter* f) { + auto epoch_time = ceph::real_clock::to_time_t(t); + f->dump_string("time", std::ctime(&epoch_time)); + } + static void generate_test_instances(std::list& ls) { + constexpr time_t t{455500800}; // Ghostbusters release date + ls.push_back(new real_time_wrapper(ceph::real_clock::from_time_t(t))); + } +}; + +#endif diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index e63dc8de8cf5..1622a53a9b7a 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -14,6 +14,9 @@ TYPE(BitVector<2>) TYPE(bloom_filter) TYPE(compressible_bloom_filter) +#include "test_ceph_time.h" +TYPE(real_time_wrapper) + #include "common/snap_types.h" TYPE(SnapContext) TYPE(SnapRealmInfo)