VirtualBox

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


Ignore:
Timestamp:
Jan 1, 2019 8:56:07 AM (6 years ago)
Author:
vboxsync
Message:

IPRT: Attempted to address some the more obvious shortcomings of RTPathCalcRelative. Had to add a parameter that clearifies whether the from path is a file (VHD usage) or directory (rest).

File:
1 edited

Legend:

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

    r76553 r76589  
    742742    {
    743743        const char *pszFrom;
     744        bool fFromFile;
    744745        const char *pszTo;
    745746        int rc;
     
    747748    } s_aRelPath[] =
    748749    {
    749         { "/home/test.ext", "/home/test2.ext", VINF_SUCCESS, "test2.ext"},
    750         { "/dir/test.ext", "/dir/dir2/test2.ext", VINF_SUCCESS, "dir2/test2.ext"},
    751         { "/dir/dir2/test.ext", "/dir/test2.ext", VINF_SUCCESS, ".." RTPATH_SLASH_STR "test2.ext"},
    752         { "/dir/dir2/test.ext", "/dir/dir3/test2.ext", VINF_SUCCESS, ".." RTPATH_SLASH_STR "dir3/test2.ext"},
     750        { "/home/test.ext",     true,           "/home/test2.ext",        VINF_SUCCESS, "test2.ext" },
     751        { "/dir/test.ext",      true,           "/dir/dir2/test2.ext",    VINF_SUCCESS, "dir2/test2.ext" },
     752        { "/dir/dir2/test.ext", true,           "/dir/test2.ext",         VINF_SUCCESS, ".." RTPATH_SLASH_STR "test2.ext" },
     753        { "/dir/dir2/test.ext", true,           "/dir/dir3/test2.ext",    VINF_SUCCESS, ".." RTPATH_SLASH_STR "dir3/test2.ext" },
     754        { "/dir/dir2",          false,          "/dir/dir3/test2.ext",    VINF_SUCCESS, ".." RTPATH_SLASH_STR "dir3/test2.ext" },
     755        { "/dir/dir2",          false,          "/dir/dir3//test2.ext",   VINF_SUCCESS, ".." RTPATH_SLASH_STR "dir3//test2.ext" },
     756        { "/dir/dir2/",         false,          "/dir/dir3/test2.ext",    VINF_SUCCESS, ".." RTPATH_SLASH_STR "dir3/test2.ext" },
     757        { "/dir/dir2////",      false,          "/dir//dir3/test2.ext",   VINF_SUCCESS, ".." RTPATH_SLASH_STR "dir3/test2.ext" },
     758        { "/include/iprt",      false,          "/include/iprt/cdefs.h",  VINF_SUCCESS, "cdefs.h" },
     759        { "/include/iprt/",     false,          "/include/iprt/cdefs.h",  VINF_SUCCESS, "cdefs.h" },
     760        { "/include/iprt/tt.h", true,           "/include/iprt/cdefs.h",  VINF_SUCCESS, "cdefs.h" },
    753761#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
    754         { "\\\\server\\share\\test.ext", "\\\\server\\share2\\test2.ext", VERR_NOT_SUPPORTED, ""},
    755         { "c:\\dir\\test.ext", "f:\\dir\\test.ext", VERR_NOT_SUPPORTED, ""}
     762        { "\\\\server\\share\\test.ext", true,  "\\\\server\\share2\\test2.ext", VERR_NOT_SUPPORTED, "" },
     763        { "c:\\dir\\test.ext",  true,           "f:\\dir\\test.ext",      VERR_NOT_SUPPORTED, "" },
     764        { "F:\\dir\\test.ext",  false,          "f:/dir//test.ext",      VINF_SUCCESS, "." } ,
     765        { "F:\\dir\\test.ext",  true,           "f:/dir//test.ext",      VINF_SUCCESS, "test.ext" } ,
    756766#endif
    757767    };
    758768    for (unsigned i = 0; i < RT_ELEMENTS(s_aRelPath); i++)
    759769    {
    760         const char *pszFrom = s_aRelPath[i].pszFrom;
    761         const char *pszTo   = s_aRelPath[i].pszTo;
    762 
    763         rc = RTPathCalcRelative(szPath, sizeof(szPath), pszFrom, pszTo);
     770        const char *pszFrom   = s_aRelPath[i].pszFrom;
     771        bool        fFromFile = s_aRelPath[i].fFromFile;
     772        const char *pszTo     = s_aRelPath[i].pszTo;
     773
     774        rc = RTPathCalcRelative(szPath, sizeof(szPath), pszFrom, fFromFile, pszTo);
    764775        if (rc != s_aRelPath[i].rc)
    765             RTTestIFailed("Unexpected return code\n"
     776            RTTestIFailed("Unexpected return code for %s .. %s\n"
    766777                          "     got: %Rrc\n"
    767778                          "expected: %Rrc",
    768                           rc, s_aRelPath[i].rc);
     779                          pszFrom, pszTo, rc, s_aRelPath[i].rc);
    769780        else if (   RT_SUCCESS(rc)
    770781                 && strcmp(szPath, s_aRelPath[i].pszExpected))
    771782            RTTestIFailed("Unexpected result\n"
    772                           "    from: '%s'\n"
     783                          "    from: '%s' (%s)\n"
    773784                          "      to: '%s'\n"
    774785                          "  output: '%s'\n"
    775786                          "expected: '%s'",
    776                           pszFrom, pszTo, szPath, s_aRelPath[i].pszExpected);
     787                          pszFrom, fFromFile ? "file" : "dir", pszTo, szPath, s_aRelPath[i].pszExpected);
    777788    }
    778789
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