ivanallen commented on code in PR #3062: URL: https://github.com/apache/brpc/pull/3062#discussion_r2278051486
########## test/iobuf_unittest.cpp: ########## @@ -1890,4 +1891,46 @@ TEST_F(IOBufTest, reserve_aligned) { } } +TEST_F(IOBufTest, single_iobuf) { + butil::IOBuf buf1; + // It will be freed by IOBuf. + char *usr_str = (char *)malloc(16); + memset(usr_str, 0, 16); + char src_str[] = "abcdefgh12345678"; + size_t total_len = sizeof(src_str); + strncpy(usr_str, src_str + 8, total_len - 8); + buf1.append(src_str, 8); + buf1.append_user_data(usr_str, total_len - 8, NULL); + ASSERT_EQ(2, buf1.backing_block_num()); + butil::SingleIOBuf sbuf; + ASSERT_EQ(0, sbuf.backing_block_num()); + sbuf.assign(buf1, total_len); + ASSERT_EQ(1, sbuf.backing_block_num()); + size_t s_len = sbuf.get_length(); + ASSERT_EQ(s_len, total_len); + const char* str = (const char*) sbuf.get_begin(); + int ret = strcmp(str, src_str); + ASSERT_EQ(0, ret); + butil::IOBuf buf2; + sbuf.append_to(&buf2); + ASSERT_EQ(buf2.length(), total_len); + butil::SingleIOBuf sbuf2; + sbuf2.swap(sbuf); + ASSERT_EQ(sbuf.get_length(), 0); + ASSERT_EQ(sbuf2.get_length(), total_len); + sbuf2.reset(); + ASSERT_EQ(0, sbuf2.get_length()); + void* buf = sbuf.allocate(1024); + ASSERT_TRUE(NULL != buf); + buf = sbuf.reallocate_downward(16384, 0, 0); Review Comment: Do you want to add some corner cases for reallocate_downward? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org