EXPECT_EQ(0, ::memcmp("AB", bl.c_str(), 2));
}
+TEST(BufferList, c_str_carriage) {
+ // verify the c_str() optimization for carriage handling
+ buffer::ptr bp("A", 1);
+ bufferlist bl;
+ bl.append(bp);
+ bl.append('B');
+ EXPECT_EQ(2U, bl.get_num_buffers());
+ EXPECT_EQ(2U, bl.length());
+
+ // this should leave an empty bptr for carriage at the end of the bl
+ bl.splice(1, 1);
+ EXPECT_EQ(2U, bl.get_num_buffers());
+ EXPECT_EQ(1U, bl.length());
+
+ std::ignore = bl.c_str();
+ // if we have an empty bptr at the end, we don't need to rebuild
+ EXPECT_EQ(2U, bl.get_num_buffers());
+}
+
TEST(BufferList, substr_of) {
bufferlist bl;
EXPECT_THROW(bl.substr_of(bl, 1, 1), buffer::end_of_buffer);