VirtualBox

Ignore:
Timestamp:
Feb 10, 2013 6:10:50 PM (12 years ago)
Author:
vboxsync
Message:

Runtime/path: Add RTPathCreateRelative to create a relative path between two absolute ones

File:
1 edited

Legend:

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

    r36881 r44615  
    554554    }
    555555
     556    /*
     557     * RTPathCreateRelative
     558     */
     559    RTTestSub(hTest, "RTPathCreateRelative");
     560    struct
     561    {
     562        const char *pszFrom;
     563        const char *pszTo;
     564        int rc;
     565        const char *pszExpected;
     566    } s_aRelPath[] =
     567    {
     568        { "/home/test.ext", "/home/test2.ext", VINF_SUCCESS, "test2.ext"},
     569        { "/dir/test.ext", "/dir/dir2/test2.ext", VINF_SUCCESS, "dir2/test2.ext"},
     570        { "/dir/dir2/test.ext", "/dir/test2.ext", VINF_SUCCESS, "../test2.ext"},
     571        { "/dir/dir2/test.ext", "/dir/dir3/test2.ext", VINF_SUCCESS, "../dir3/test2.ext"},
     572#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
     573        { "\\\\server\\share\\test.ext", "\\\\server\\share2\\test2.ext", VERR_NOT_SUPPORTED, ""},
     574        { "c:\\dir\\test.ext", "f:\\dir\\test.ext", VERR_NOT_SUPPORTED, ""}
     575#endif
     576    };
     577    for (unsigned i = 0; i < RT_ELEMENTS(s_aRelPath); i++)
     578    {
     579        const char *pszFrom = s_aRelPath[i].pszFrom;
     580        const char *pszTo   = s_aRelPath[i].pszTo;
     581
     582        rc = RTPathCreateRelative(szPath, sizeof(szPath), pszFrom, pszTo);
     583        if (rc != s_aRelPath[i].rc)
     584            RTTestIFailed("Unexpected return code\n"
     585                          "     got: %Rrc\n"
     586                          "expected: %Rrc",
     587                          rc, s_aRelPath[i].rc);
     588        else if (   RT_SUCCESS(rc)
     589                 && strcmp(szPath, s_aRelPath[i].pszExpected))
     590            RTTestIFailed("Unexpected result\n"
     591                          "    from: '%s'\n"
     592                          "      to: '%s'\n"
     593                          "  output: '%s'\n"
     594                          "expected: '%s'",
     595                          pszFrom, pszTo, szPath, s_aRelPath[i].pszExpected);
     596    }
    556597
    557598    /*
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