]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/test/encoding.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / test / encoding.cc
index af3346e1a0916dbd27fc62430fe7238d35bcf50c..4f91ecc4debd8b2d11f5306733889e80d43c144d 100644 (file)
@@ -11,7 +11,7 @@ static void test_encode_and_decode(const T& src)
   bufferlist bl(1000000);
   encode(src, bl);
   T dst;
-  bufferlist::iterator i(bl.begin());
+  auto i = bl.cbegin();
   decode(dst, i);
   ASSERT_EQ(src, dst) << "Encoding roundtrip changed the string: orig=" << src << ", but new=" << dst;
 }
@@ -38,7 +38,7 @@ static void test_encode_and_nohead_nohead(Size len, const T& src)
   encode(len, bl);
   encode_nohead(src, bl);
   T dst;
-  bufferlist::iterator i(bl.begin());
+  auto i = bl.cbegin();
   decode(len, i);
   decode_nohead(len, dst, i);
   ASSERT_EQ(src, dst) << "Encoding roundtrip changed the string: orig=" << src << ", but new=" << dst;
@@ -163,14 +163,14 @@ public:
     return data == rhs.data;
   }
 
-  friend void decode(ConstructorCounter &s, bufferlist::iterator& p)
+  friend void decode(ConstructorCounter &s, bufferlist::const_iterator& p)
   {
-    ::decode(s.data, p);
+    decode(s.data, p);
   }
 
   friend void encode(const ConstructorCounter &s, bufferlist& p)
   {
-    ::encode(s.data, p);
+    encode(s.data, p);
   }
 
   friend ostream& operator<<(ostream &oss, const ConstructorCounter &cc)
@@ -234,6 +234,7 @@ TEST(EncodingRoundTrip, MultimapConstructorCounter) {
   EXPECT_EQ(my_val_t::get_assigns(), 0);
 }
 
+namespace ceph {
 // make sure that the legacy encode/decode methods are selected
 // over the ones defined using templates. the later is likely to
 // be slower, see also the definition of "WRITE_INT_DENC" in
@@ -263,6 +264,24 @@ void encode<ceph_le64, denc_traits<ceph_le64>>(const ceph_le64&,
   // make sure the test fails if i get called
   ASSERT_TRUE(false);
 }
+}
+
+namespace {
+  // search `underlying_type` in denc.h for supported underlying types
+  enum class Colour : int8_t { R,G,B };
+  ostream& operator<<(ostream& os, Colour c) {
+    switch (c) {
+    case Colour::R:
+      return os << "Colour::R";
+    case Colour::G:
+      return os << "Colour::G";
+    case Colour::B:
+      return os << "Colour::B";
+    default:
+      return os << "Colour::???";
+    }
+  }
+}
 
 TEST(EncodingRoundTrip, Integers) {
   // int types
@@ -288,6 +307,16 @@ TEST(EncodingRoundTrip, Integers) {
     i = 42;
     test_encode_and_decode(i);
   }
+  // enum
+  {
+    test_encode_and_decode(Colour::R);
+    // this should not build, as the size of unsigned is not the same on
+    // different archs, that's why denc_traits<> intentionally leaves
+    // `int` and `unsigned int` out of supported types.
+    //
+    // enum E { R, G, B };
+    // test_encode_and_decode(R);
+  }
 }
 
 const char* expected_what[] = {
@@ -355,7 +384,7 @@ TEST(small_encoding, varint) {
       cout << std::endl;
       ASSERT_EQ(bl.length(), v[i][1]);
       uint32_t u;
-      auto p = bl.begin().get_current_ptr().begin();
+      auto p = bl.begin().get_current_ptr().cbegin();
       denc_varint(u, p);
       ASSERT_EQ(v[i][0], u);
     }
@@ -370,7 +399,7 @@ TEST(small_encoding, varint) {
       cout << std::endl;
       ASSERT_EQ(bl.length(), v[i][2]);
       int32_t u;
-      auto p = bl.begin().get_current_ptr().begin();
+      auto p = bl.begin().get_current_ptr().cbegin();
       denc_signed_varint(u, p);
       ASSERT_EQ((int32_t)v[i][0], u);
     }
@@ -386,7 +415,7 @@ TEST(small_encoding, varint) {
       cout << std::endl;
       ASSERT_EQ(bl.length(), v[i][3]);
       int64_t u;
-      auto p = bl.begin().get_current_ptr().begin();
+      auto p = bl.begin().get_current_ptr().cbegin();
       denc_signed_varint(u, p);
       ASSERT_EQ(x, u);
     }
@@ -433,7 +462,7 @@ TEST(small_encoding, varint_lowz) {
       cout << std::endl;
       ASSERT_EQ(bl.length(), v[i][1]);
       uint32_t u;
-      auto p = bl.begin().get_current_ptr().begin();
+      auto p = bl.begin().get_current_ptr().cbegin();
       denc_varint_lowz(u, p);
       ASSERT_EQ(v[i][0], u);
     }
@@ -449,7 +478,7 @@ TEST(small_encoding, varint_lowz) {
       cout << std::endl;
       ASSERT_EQ(bl.length(), v[i][2]);
       int64_t u;
-      auto p = bl.begin().get_current_ptr().begin();
+      auto p = bl.begin().get_current_ptr().cbegin();
       denc_signed_varint_lowz(u, p);
       ASSERT_EQ(x, u);
     }
@@ -465,7 +494,7 @@ TEST(small_encoding, varint_lowz) {
       cout << std::endl;
       ASSERT_EQ(bl.length(), v[i][3]);
       int64_t u;
-      auto p = bl.begin().get_current_ptr().begin();
+      auto p = bl.begin().get_current_ptr().cbegin();
       denc_signed_varint_lowz(u, p);
       ASSERT_EQ(x, u);
     }    
@@ -504,7 +533,7 @@ TEST(small_encoding, lba) {
     cout << std::endl;
     ASSERT_EQ(bl.length(), v[i][1]);
     uint64_t u;
-    auto p = bl.begin().get_current_ptr().begin();
+    auto p = bl.begin().get_current_ptr().cbegin();
     denc_lba(u, p);
     ASSERT_EQ(v[i][0], u);
   }