]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test: add denc tests for sstring 15135/head
authorCasey Bodley <cbodley@redhat.com>
Tue, 16 May 2017 20:26:39 +0000 (16:26 -0400)
committerCasey Bodley <cbodley@redhat.com>
Thu, 25 May 2017 14:57:31 +0000 (10:57 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/test/encoding/test_sstring.h [new file with mode: 0644]
src/test/encoding/types.h

diff --git a/src/test/encoding/test_sstring.h b/src/test/encoding/test_sstring.h
new file mode 100644 (file)
index 0000000..c2493c1
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef TEST_SSTRING_H
+#define TEST_SSTRING_H
+
+#include "common/sstring.hh"
+
+// wrapper for sstring that implements the dencoder interface
+class sstring_wrapper {
+  using sstring16 = basic_sstring<char, uint32_t, 16>;
+  sstring16 s1;
+  using sstring24 = basic_sstring<unsigned char, uint16_t, 24>;
+  sstring24 s2;
+ public:
+  sstring_wrapper() = default;
+  sstring_wrapper(sstring16&& s1, sstring24&& s2)
+    : s1(std::move(s1)), s2(std::move(s2))
+  {}
+
+  DENC(sstring_wrapper, w, p) {
+    DENC_START(1, 1, p);
+    denc(w.s1, p);
+    denc(w.s2, p);
+    DENC_FINISH(p);
+  }
+  void dump(Formatter* f) {
+    f->dump_string("s1", s1.c_str());
+    f->dump_string("s2", reinterpret_cast<const char*>(s2.c_str()));
+  }
+  static void generate_test_instances(std::list<sstring_wrapper*>& ls) {
+    ls.push_back(new sstring_wrapper());
+    // initialize sstrings that fit in internal storage
+    constexpr auto cstr6 = "abcdef";
+    ls.push_back(new sstring_wrapper(sstring16{cstr6}, sstring24{cstr6}));
+    // initialize sstrings that overflow into external storage
+    constexpr auto cstr26 = "abcdefghijklmnopqrstuvwxyz";
+    ls.push_back(new sstring_wrapper(sstring16{cstr26}, sstring24{cstr26}));
+  }
+};
+WRITE_CLASS_DENC(sstring_wrapper)
+
+#endif
index d4f4413080aed058640b1e6ed87c1780355c4b11..77df9f0d7e64701f7b11cb390103d5e3c5ee33fd 100644 (file)
@@ -17,6 +17,9 @@ TYPE(compressible_bloom_filter)
 #include "test_ceph_time.h"
 TYPE(real_time_wrapper)
 
+#include "test_sstring.h"
+TYPE(sstring_wrapper)
+
 #include "common/snap_types.h"
 TYPE(SnapContext)
 TYPE(SnapRealmInfo)