Skip to content

Commit f58eb11

Browse files
committed
Merge pull request #380 from whoshuu/expand-buffer-tests
Add tests for expanding an unpacker buffer
2 parents 134beee + 434dae8 commit f58eb11

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/limit.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,3 +553,21 @@ TEST(limit, unpacker_array_over)
553553
EXPECT_TRUE(false);
554554
}
555555
}
556+
557+
TEST(limit, unpacker_reserve)
558+
{
559+
msgpack::unpacker u(nullptr, nullptr, MSGPACK_UNPACKER_INIT_BUFFER_SIZE,
560+
msgpack::unpack_limit());
561+
std::size_t original_capacity = u.buffer_capacity();
562+
u.reserve_buffer(original_capacity + 1u);
563+
EXPECT_EQ((original_capacity + COUNTER_SIZE) * 2 - COUNTER_SIZE, u.buffer_capacity());
564+
}
565+
566+
TEST(limit, unpacker_reserve_more_than_twice)
567+
{
568+
msgpack::unpacker u(nullptr, nullptr, MSGPACK_UNPACKER_INIT_BUFFER_SIZE,
569+
msgpack::unpack_limit());
570+
std::size_t original_capacity = u.buffer_capacity();
571+
u.reserve_buffer(original_capacity * 3);
572+
EXPECT_EQ((original_capacity + COUNTER_SIZE) * 4 - COUNTER_SIZE, u.buffer_capacity());
573+
}

0 commit comments

Comments
 (0)