mirror of
https://github.com/espressif/openthread.git
synced 2026-08-10 04:37:47 +00:00
[linked-list] add Find() and GetTail() methods (#4388)
The `LinkedList::Find()` method searches for a given entry in the linked list and if found returns a pointer to the previous entry behind it. The `LinkedList::GetTail()` returns the tail of the list (last entry in the list). This commit also updates the unit test `test_linked_list` to verify the behavior of newly added methods.
This commit is contained in:
committed by
Jonathan Hui
parent
db1f7d2eac
commit
802c9dfcbc
@@ -52,19 +52,29 @@ void VerifyLinkedListContent(const ot::LinkedList<Entry> &aList, ...)
|
||||
{
|
||||
va_list args;
|
||||
Entry * argEntry;
|
||||
Entry * argPrev = NULL;
|
||||
|
||||
va_start(args, aList);
|
||||
|
||||
for (const Entry *entry = aList.GetHead(); entry; entry = entry->GetNext())
|
||||
{
|
||||
Entry *prev;
|
||||
|
||||
argEntry = va_arg(args, Entry *);
|
||||
VerifyOrQuit(argEntry != NULL, "List contains more entries than expected");
|
||||
VerifyOrQuit(argEntry == entry, "List does not contain the same entry");
|
||||
VerifyOrQuit(aList.Contains(*argEntry), "List::Contains() failed");
|
||||
|
||||
SuccessOrQuit(aList.Find(*argEntry, prev), "List::Find() failed");
|
||||
VerifyOrQuit(prev == argPrev, "List::Find() returned prev entry is incorrect");
|
||||
|
||||
argPrev = argEntry;
|
||||
}
|
||||
|
||||
argEntry = va_arg(args, Entry *);
|
||||
VerifyOrQuit(argEntry == NULL, "List contains less entries than expected");
|
||||
|
||||
VerifyOrQuit(aList.GetTail() == argPrev, "List::GetTail() failed");
|
||||
}
|
||||
|
||||
void TestLinkedList(void)
|
||||
|
||||
Reference in New Issue
Block a user