VirtualBox

Changeset 28437 in vbox


Ignore:
Timestamp:
Apr 17, 2010 9:58:07 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
60208
Message:

RTList: Fixed RTListNodeIsDummy and added RTListForEachReverse. Added testcases for RTListForEach and RTListForEachReverse.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/list.h

    r28435 r28437  
    155155 */
    156156#define RTListNodeIsDummy(pList, pNode, Type, Member) \
    157          ( (pNode) != RT_FROM_MEMBER((pList), Type, Member) )
     157         ( (pNode) == RT_FROM_MEMBER((pList), Type, Member) )
    158158
    159159/**
     
    232232
    233233/**
     234 * Enumerate the list in reverse order (tail to head).
     235 *
     236 * @param   pList               List to enumerate.
     237 * @param   pIterator           The iterator variable name.
     238 * @param   Type                Structure the list node is a member of.
     239 * @param   Member              The list node member name.
     240 */
     241#define RTListForEachReverse(pList, pIterator, Type, Member) \
     242    for (pIterator = RTListNodeGetLast(pList, Type, Member); \
     243         !RTListNodeIsDummy(pList, pIterator, Type, Member); \
     244         pIterator = RT_FROM_MEMBER((pIterator)->Member.pPrev, Type, Member) )
     245
     246
     247/**
    234248 * Move the given list to a new list header.
    235249 *
  • trunk/src/VBox/Runtime/testcase/tstRTList.cpp

    r26813 r28437  
    5454
    5555static void tstRTListOrder(RTTEST hTest, PRTLISTNODE pList, unsigned cElements,
    56                            unsigned idxStart, unsigned idxEnd, unsigned idxStep)
     56                           unsigned idxFirst, unsigned idxLast, unsigned idxStep)
    5757{
    5858    RTTEST_CHECK(hTest, RTListIsEmpty(pList) == false);
     
    6666    /* Check that the order is right. */
    6767    PLISTELEM pNode = RTListNodeGetFirst(pList, LISTELEM, Node);
    68     for (unsigned i = idxStart; i < idxEnd; i += idxStep)
     68    for (unsigned i = idxFirst; i < idxLast; i += idxStep)
    6969    {
    7070        RTTEST_CHECK(hTest, pNode->idx == i);
     
    7272    }
    7373
    74     RTTEST_CHECK(hTest, pNode->idx == idxEnd);
     74    RTTEST_CHECK(hTest, pNode->idx == idxLast);
    7575    RTTEST_CHECK(hTest, RTListNodeGetLast(pList, LISTELEM, Node) == pNode);
    7676    RTTEST_CHECK(hTest, RTListNodeIsLast(pList, &pNode->Node) == true);
     
    7878    /* Check reverse order */
    7979    pNode = RTListNodeGetLast(pList, LISTELEM, Node);
    80     for (unsigned i = idxEnd; i > idxStart; i -= idxStep)
     80    for (unsigned i = idxLast; i > idxFirst; i -= idxStep)
    8181    {
    8282        RTTEST_CHECK(hTest, pNode->idx == i);
     
    8484    }
    8585
    86     RTTEST_CHECK(hTest, pNode->idx == idxStart);
     86    RTTEST_CHECK(hTest, pNode->idx == idxFirst);
    8787    RTTEST_CHECK(hTest, RTListNodeGetFirst(pList, LISTELEM, Node) == pNode);
    8888    RTTEST_CHECK(hTest, RTListNodeIsFirst(pList, &pNode->Node) == true);
     89
     90    /* The list enumeration. */
     91    unsigned idx = idxFirst;
     92    RTListForEach(pList, pNode, LISTELEM, Node)
     93    {
     94        RTTEST_CHECK_RETV(hTest, idx == pNode->idx);
     95        idx += idxStep;
     96    }
     97    RTTEST_CHECK_MSG_RETV(hTest, idx == idxLast + idxStep || (idx == idxFirst && idxFirst == idxLast),
     98                          (hTest, "idx=%u idxFirst=%u idxLast=%u idxStep=%u\n", idx, idxFirst, idxLast, idxStep));
     99
     100    idx = idxLast;
     101    RTListForEachReverse(pList, pNode, LISTELEM, Node)
     102    {
     103        RTTEST_CHECK_RETV(hTest, idx == pNode->idx);
     104        idx -= idxStep;
     105    }
     106    RTTEST_CHECK_MSG_RETV(hTest, idx == idxFirst - idxStep || (idx == idxLast && idxFirst == idxLast),
     107                          (hTest, "idx=%u idxFirst=%u idxLast idxStep=%u\n", idx, idxFirst, idxLast, idxStep));
    89108}
    90109
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette