]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test: add ceph-dencoder test for ceph::real_time
authorCasey Bodley <cbodley@redhat.com>
Fri, 22 Jan 2016 20:25:15 +0000 (15:25 -0500)
committerCasey Bodley <cbodley@redhat.com>
Tue, 26 Jan 2016 19:22:06 +0000 (14:22 -0500)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/test/Makefile-client.am
src/test/encoding/test_ceph_time.h [new file with mode: 0644]
src/test/encoding/types.h

index 967dde46baac337ffee4fb4c84e66ee45037083c..928e2a1f160b4cde87351335c3e3e5a7be293563 100644 (file)
@@ -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 (file)
index 0000000..7adcb8f
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef TEST_CEPH_TIME_H
+#define TEST_CEPH_TIME_H
+
+#include <list>
+#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<real_time_wrapper*>& ls) {
+    constexpr time_t t{455500800}; // Ghostbusters release date
+    ls.push_back(new real_time_wrapper(ceph::real_clock::from_time_t(t)));
+  }
+};
+
+#endif
index e63dc8de8cf5137e154037aae5fea1a43788ef51..1622a53a9b7a2a964d1dafb594c08fa181c05174 100644 (file)
@@ -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)