Skip to content

Commit

Permalink
Merge pull request #380 from whoshuu/expand-buffer-tests
Browse files Browse the repository at this point in the history
Add tests for expanding an unpacker buffer
  • Loading branch information
redboltz committed Nov 1, 2015
2 parents 134beee + 434dae8 commit f58eb11
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/limit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,21 @@ TEST(limit, unpacker_array_over)
EXPECT_TRUE(false);
}
}

TEST(limit, unpacker_reserve)
{
msgpack::unpacker u(nullptr, nullptr, MSGPACK_UNPACKER_INIT_BUFFER_SIZE,
msgpack::unpack_limit());
std::size_t original_capacity = u.buffer_capacity();
u.reserve_buffer(original_capacity + 1u);
EXPECT_EQ((original_capacity + COUNTER_SIZE) * 2 - COUNTER_SIZE, u.buffer_capacity());
}

TEST(limit, unpacker_reserve_more_than_twice)
{
msgpack::unpacker u(nullptr, nullptr, MSGPACK_UNPACKER_INIT_BUFFER_SIZE,
msgpack::unpack_limit());
std::size_t original_capacity = u.buffer_capacity();
u.reserve_buffer(original_capacity * 3);
EXPECT_EQ((original_capacity + COUNTER_SIZE) * 4 - COUNTER_SIZE, u.buffer_capacity());
}

0 comments on commit f58eb11

Please sign in to comment.