mirror of
https://github.com/espressif/openthread.git
synced 2026-08-11 13:17:48 +00:00
[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:
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user