+TEST(IOBuf, Printf) {
+ IOBuf head(IOBuf::CREATE, 24);
+ Appender app(&head, 32);
+
+ app.printf("%s", "test");
+ EXPECT_EQ(head.length(), 4);
+ EXPECT_EQ(0, memcmp(head.data(), "test\0", 5));
+
+ app.printf("%d%s %s%s %#x", 32, "this string is",
+ "longer than our original allocation size,",
+ "and will therefore require a new allocation", 0x12345678);
+ // The tailroom should start with a nul byte now.
+ EXPECT_GE(head.prev()->tailroom(), 1);
+ EXPECT_EQ(0, *head.prev()->tail());
+
+ EXPECT_EQ("test32this string is longer than our original "
+ "allocation size,and will therefore require a "
+ "new allocation 0x12345678",
+ head.moveToFbString().toStdString());
+}
+
+TEST(IOBuf, Format) {
+ IOBuf head(IOBuf::CREATE, 24);
+ Appender app(&head, 32);
+
+ format("{}", "test")(app);
+ EXPECT_EQ(head.length(), 4);
+ EXPECT_EQ(0, memcmp(head.data(), "test", 4));
+
+ auto fmt = format("{}{} {}{} {:#x}",
+ 32, "this string is",
+ "longer than our original allocation size,",
+ "and will therefore require a new allocation",
+ 0x12345678);
+ fmt(app);
+ EXPECT_EQ("test32this string is longer than our original "
+ "allocation size,and will therefore require a "
+ "new allocation 0x12345678",
+ head.moveToFbString().toStdString());
+}
+