VirtualBox

Changeset 85382 in vbox for trunk/src/VBox/Runtime/testcase


Ignore:
Timestamp:
Jul 18, 2020 11:33:58 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139396
Message:

iprt/path.h: Adjustments and a bunch of todos for RTPathFindCommon[Ex].

File:
1 edited

Legend:

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

    r85312 r85382  
    4646    struct
    4747    {
    48         char const *papszPath1;
    49         char const *papszPath2;
    50         char const *papszPath3;
    51         char const *papszPatCommon;
     48        char const *apszPaths[3];
     49        char const *pszCommon;
     50        uint32_t    fFlags;
    5251    } aTests[] =
    5352    {
    5453        /* Simple stuff first. */
    55         { "", "", "", "" },
    56         { "none", "none", "", "" },
     54        { { "",                     "",                 "" },                       "",          RTPATH_STR_F_STYLE_UNIX },
     55        { { "none",                 "none",             "" },                       "",          RTPATH_STR_F_STYLE_UNIX },
    5756        /* Missing start slash. */
    58         { "/path/to/stuff1", "path/to/stuff2", "", "" },
     57        { { "/path/to/stuff1",      "path/to/stuff2",   "" },                       "",          RTPATH_STR_F_STYLE_UNIX },
    5958        /* Working stuff. */
    60         { "/path/to/stuff1", "/path/to/stuff2", "/path/to/stuff3", "/path/to/" },
    61         { "/path/to/stuff1", "/path/to/", "/path/", "/path/" },
    62         { "/path/to/stuff1", "/", "/path/", "" },
    63         { "/path/to/../stuff1", "./../", "/path/to/stuff2/..", "" }
     59        { { "/path/to/stuff1",      "/path/to/stuff2",  "/path/to/stuff3" },        "/path/to/", RTPATH_STR_F_STYLE_UNIX },
     60        { { "/path/to/stuff1",      "/path/to/",        "/path/" },                 "/path/",    RTPATH_STR_F_STYLE_UNIX },
     61        { { "/path/to/stuff1",      "/",                "/path/" },                 "",          RTPATH_STR_F_STYLE_UNIX },
     62        { { "/path/to/../stuff1",   "./../",            "/path/to/stuff2/.." },     "",          RTPATH_STR_F_STYLE_UNIX },
    6463    };
    6564
    66     const size_t cNumPaths = 3; /* Number of paths to compare. */
     65    for (size_t i = 0; i < RT_ELEMENTS(aTests); i++)
     66    {
     67        size_t cPaths = RT_ELEMENTS(aTests[i].apszPaths);
     68        while (cPaths > 0 && aTests[i].apszPaths[cPaths - 1] == NULL)
     69            cPaths--;
    6770
    68     size_t cchRes;
    69     for (size_t i = 0; i < RT_ELEMENTS(aTests); i++)
    70         RTTEST_CHECK_MSG(hTest, (cchRes = RTPathFindCommonEx((const char * const *)&aTests[i], cNumPaths, '/')) == strlen(aTests[i].papszPatCommon),
    71                          (hTest, "Test %zu failed: Got %zu, expected %zu\n", i, cchRes, strlen(aTests[i].papszPatCommon)));
     71        size_t const cchCommon = RTPathFindCommonEx(cPaths, aTests[i].apszPaths, aTests[i].fFlags);
     72        size_t const cchExpect = strlen(aTests[i].pszCommon);
     73        if (cchCommon != cchExpect)
     74            RTTestFailed(hTest,
     75                         "Test %zu failed: got %zu, expected %zu (cPaths=%zu: %s %s %s)", i, cchCommon, cchExpect, cPaths,
     76                         aTests[i].apszPaths[0], aTests[i].apszPaths[1], aTests[i].apszPaths[2]);
     77    }
    7278
    7379    /*
Note: See TracChangeset for help on using the changeset viewer.

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