[heap-data] add Matches() to compare Heap::Data with a given buffer (#9740)

Also updates the unit test to validate the new method.
This commit is contained in:
Abtin Keshavarzian
2023-12-26 07:51:38 -08:00
committed by GitHub
parent 8167fb3626
commit 6751122f0a
3 changed files with 43 additions and 0 deletions
+12
View File
@@ -171,11 +171,15 @@ void VerifyData(const Heap::Data &aData, const uint8_t *aBytes, uint16_t aLength
PrintData(aData);
VerifyOrQuit(aData.Matches(aBytes, aLength));
VerifyOrQuit(!aData.Matches(aBytes, aLength + 1));
if (aLength == 0)
{
VerifyOrQuit(aData.IsNull());
VerifyOrQuit(aData.GetBytes() == nullptr);
VerifyOrQuit(aData.GetLength() == 0);
VerifyOrQuit(aData.Matches(nullptr, 0));
}
else
{
@@ -186,6 +190,10 @@ void VerifyData(const Heap::Data &aData, const uint8_t *aBytes, uint16_t aLength
aData.CopyBytesTo(buffer);
VerifyOrQuit(memcmp(buffer, aBytes, aLength) == 0, "CopyBytesTo() failed");
VerifyOrQuit(aData.Matches(buffer, aLength));
buffer[aLength - 1]++;
VerifyOrQuit(!aData.Matches(buffer, aLength));
}
}
@@ -223,6 +231,10 @@ void TestHeapData(void)
printf("After constructor\n");
VerifyData(data, nullptr, 0);
VerifyOrQuit(data.Matches(nullptr, 0));
VerifyOrQuit(data.Matches(kData1, 0));
VerifyOrQuit(!data.Matches(kData1, 1));
printf("------------------------------------------------------------------------------------\n");
printf("SetFrom(aBuffer, aLength)\n");