VirtualBox

Changeset 85348 in vbox for trunk/src


Ignore:
Timestamp:
Jul 15, 2020 12:12:37 PM (4 years ago)
Author:
vboxsync
Message:

IPRT/tstRTStrSplit: Added macro for cleaning up test runs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstRTStrSplit.cpp

    r85345 r85348  
    3232
    3333#include <iprt/test.h>
     34#include <iprt/mem.h>
    3435#include <iprt/stream.h>
    3536
     
    5152    size_t cStrings = 0;
    5253
     54#define DO_CLEANUP() \
     55    for (size_t i = 0; i < cStrings; ++i) \
     56        RTStrFree(papszStrings[i]); \
     57    RTMemFree(papszStrings);
     58    cStrings = 0;
     59
    5360    /* Empty stuff. */
    5461    const char szEmpty[] = "";
    5562    RTTEST_CHECK_RC(hTest, RTStrSplit(szEmpty, sizeof(szEmpty), "\r\n", &papszStrings, &cStrings), VINF_SUCCESS);
    5663    RTTEST_CHECK(hTest, cStrings == 0);
     64    DO_CLEANUP();
    5765
    5866    /* No separator given. */
     
    6169    RTTEST_CHECK(hTest, cStrings == 1);
    6270    RTTEST_CHECK(hTest, RTStrICmp(papszStrings[0], "foo") == 0);
     71    DO_CLEANUP();
    6372
    6473    /* Single string w/ separator. */
     
    6776    RTTEST_CHECK(hTest, cStrings == 1);
    6877    RTTEST_CHECK(hTest, papszStrings && RTStrICmp(papszStrings[0], "foo") == 0);
     78    DO_CLEANUP();
    6979
    7080    /* Multiple strings w/ separator. */
     
    7686                        && RTStrICmp(papszStrings[0], "foo") == 0
    7787                        && RTStrICmp(papszStrings[1], "bar") == 0);
     88    DO_CLEANUP();
    7889
    7990    /* Multiple strings w/ two consequtive separators. */
     
    8596                        && RTStrICmp(papszStrings[0], "foo") == 0
    8697                        && RTStrICmp(papszStrings[1], "bar") == 0);
     98    DO_CLEANUP();
    8799
    88100    /* Multiple strings w/ two consequtive separators. */
     
    95107                        && RTStrICmp(papszStrings[1], "bar") == 0
    96108                        && RTStrICmp(papszStrings[2], "baz") == 0);
     109    DO_CLEANUP();
    97110
    98111    /* Multiple strings w/ trailing separators. */
     
    105118                        && RTStrICmp(papszStrings[1], "bar") == 0
    106119                        && RTStrICmp(papszStrings[2], "baz") == 0);
     120    DO_CLEANUP();
     121
     122#undef DO_CLEANUP
     123
    107124    /*
    108125     * Summary.
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