MsgPackDeserializer: check extension allocation result

This commit is contained in:
Benoit Blanchon
2024-09-04 14:34:02 +02:00
parent 1f7a3f3174
commit 3b64197869
2 changed files with 51 additions and 6 deletions

View File

@ -199,3 +199,44 @@ TEST_CASE(
REQUIRE(err == DeserializationError::NoMemory);
}
}
TEST_CASE(
"deserializeMsgPack() returns NoMemory if extension allocation fails") {
JsonDocument doc(FailingAllocator::instance());
SECTION("uint32_t should pass") {
auto err = deserializeMsgPack(doc, "\xceXXXX");
REQUIRE(err == DeserializationError::Ok);
}
SECTION("uint64_t should fail") {
auto err = deserializeMsgPack(doc, "\xcfXXXXXXXX");
REQUIRE(err == DeserializationError::NoMemory);
}
SECTION("int32_t should pass") {
auto err = deserializeMsgPack(doc, "\xd2XXXX");
REQUIRE(err == DeserializationError::Ok);
}
SECTION("int64_t should fail") {
auto err = deserializeMsgPack(doc, "\xd3XXXXXXXX");
REQUIRE(err == DeserializationError::NoMemory);
}
SECTION("float should pass") {
auto err = deserializeMsgPack(doc, "\xcaXXXX");
REQUIRE(err == DeserializationError::Ok);
}
SECTION("double should fail") {
auto err = deserializeMsgPack(doc, "\xcbXXXXXXXX");
REQUIRE(err == DeserializationError::NoMemory);
}
}