]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/encoding/test_sstring.h
update sources to v12.1.0
[ceph.git] / ceph / src / test / encoding / test_sstring.h
1 #ifndef TEST_SSTRING_H
2 #define TEST_SSTRING_H
3
4 #include "common/sstring.hh"
5
6 // wrapper for sstring that implements the dencoder interface
7 class sstring_wrapper {
8 using sstring16 = basic_sstring<char, uint32_t, 16>;
9 sstring16 s1;
10 using sstring24 = basic_sstring<unsigned char, uint16_t, 24>;
11 sstring24 s2;
12 public:
13 sstring_wrapper() = default;
14 sstring_wrapper(sstring16&& s1, sstring24&& s2)
15 : s1(std::move(s1)), s2(std::move(s2))
16 {}
17
18 DENC(sstring_wrapper, w, p) {
19 DENC_START(1, 1, p);
20 denc(w.s1, p);
21 denc(w.s2, p);
22 DENC_FINISH(p);
23 }
24 void dump(Formatter* f) {
25 f->dump_string("s1", s1.c_str());
26 f->dump_string("s2", reinterpret_cast<const char*>(s2.c_str()));
27 }
28 static void generate_test_instances(std::list<sstring_wrapper*>& ls) {
29 ls.push_back(new sstring_wrapper());
30 // initialize sstrings that fit in internal storage
31 constexpr auto cstr6 = "abcdef";
32 ls.push_back(new sstring_wrapper(sstring16{cstr6}, sstring24{cstr6}));
33 // initialize sstrings that overflow into external storage
34 constexpr auto cstr26 = "abcdefghijklmnopqrstuvwxyz";
35 ls.push_back(new sstring_wrapper(sstring16{cstr26}, sstring24{cstr26}));
36 }
37 };
38 WRITE_CLASS_DENC(sstring_wrapper)
39
40 #endif