VirtualBox

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


Ignore:
Timestamp:
Oct 6, 2015 5:26:45 PM (9 years ago)
Author:
vboxsync
Message:

tstRTUri: Merged the windows reference results into g_aCreateFileURIs so it's easier to read. Did so by making the TSTRTURI_WITH_WINDOWS_REFERENCE_RESULTS code regenerate the table.

File:
1 edited

Legend:

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

    r58057 r58059  
    3636#include <iprt/test.h>
    3737
    38 #ifdef _DEBUG
    39 # ifdef RT_OS_WINDOWS
    40 #  include <Shlwapi.h> /* For generating the PathCreateFromUrl/UrlCreateFromPath reference on Windows. */
    41 # endif
     38#if 0 && defined(RT_OS_WINDOWS) /* Enable for windows API reference results. */
     39# define TSTRTURI_WITH_WINDOWS_REFERENCE_RESULTS
     40# include <Shlwapi.h>
     41# include <iprt/stream.h>
    4242#endif
     43
    4344
    4445/*********************************************************************************************************************************
     
    300301
    301302
    302 struct URIFILETEST
     303static struct URIFILETEST
    303304{
    304     const char *pcszPath;
    305     const char *pcszUri;
    306     uint32_t uFormat;
    307 }
    308 g_apCreateFileURIs[] =
     305    const char     *pszPath;
     306    const char     *pszUri;
     307    uint32_t        uFormat;
     308    const char     *pszCreatedPath;
     309    const char     *pszCreatedUri;
     310} g_aCreateFileURIs[] =
    309311{
     312    {   /* #0: */
     313        /* .pszPath          =*/ "C:\\over\\ <>#%\"{}|^[]`\\there",
     314        /* .pszUri           =*/ "file:///C:%5Cover%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere",
     315        /* .uFormat          =*/ URI_FILE_FORMAT_WIN,
     316        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     317        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     318        /* PathCreateFromUrl =   "C:\\over\\ <>#%\"{}|^[]`\\there" - same */
     319        /* UrlCreateFromPath =   "file:///C:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there" - differs */
     320    },
     321    {   /* #1: */
     322        /* .pszPath          =*/ "/over/ <>#%\"{}|^[]`/there",
     323        /* .pszUri           =*/ "file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there",
     324        /* .uFormat          =*/ URI_FILE_FORMAT_UNIX,
     325        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     326        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     327        /* PathCreateFromUrl =   "\\over\\ <>#%\"{}|^[]`\\there" - differs */
     328        /* UrlCreateFromPath =   "file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there" - same */
     329    },
     330    {   /* #2: */
     331        /* .pszPath          =*/ NULL,
     332        /* .pszUri           =*/ "file://",
     333        /* .uFormat          =*/ URI_FILE_FORMAT_UNIX,
     334        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     335        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     336        /* PathCreateFromUrl =   "" - differs */
     337        /* UrlCreateFromPath => 0x80070057 (E_INVALIDARG) */
     338    },
     339    {   /* #3: */
     340        /* .pszPath          =*/ NULL,
     341        /* .pszUri           =*/ "file://",
     342        /* .uFormat          =*/ URI_FILE_FORMAT_WIN,
     343        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     344        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     345        /* PathCreateFromUrl =   "" - differs */
     346        /* UrlCreateFromPath => 0x80070057 (E_INVALIDARG) */
     347    },
     348    {   /* #4: */
     349        /* .pszPath          =*/ "/",
     350        /* .pszUri           =*/ "file:///",
     351        /* .uFormat          =*/ URI_FILE_FORMAT_UNIX,
     352        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     353        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     354        /* PathCreateFromUrl =   "" - differs */
     355        /* UrlCreateFromPath =   "file:///" - same */
     356    },
     357    {   /* #5: */
     358        /* .pszPath          =*/ "\\",
     359        /* .pszUri           =*/ "file:///",
     360        /* .uFormat          =*/ URI_FILE_FORMAT_WIN,
     361        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     362        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     363        /* PathCreateFromUrl =   "" - differs */
     364        /* UrlCreateFromPath =   "file:///" - same */
     365    },
     366    {   /* #6: */
     367        /* .pszPath          =*/ "/foo/bar",
     368        /* .pszUri           =*/ "file:///foo/bar",
     369        /* .uFormat          =*/ URI_FILE_FORMAT_UNIX,
     370        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     371        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     372        /* PathCreateFromUrl =   "\\foo\\bar" - differs */
     373        /* UrlCreateFromPath =   "file:///foo/bar" - same */
     374    },
     375    {   /* #7: */
     376        /* .pszPath          =*/ "\\foo\\bar",
     377        /* .pszUri           =*/ "file:///foo%5Cbar",
     378        /* .uFormat          =*/ URI_FILE_FORMAT_WIN,
     379        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     380        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     381        /* PathCreateFromUrl =   "\\foo\\bar" - same */
     382        /* UrlCreateFromPath =   "file:///foo/bar" - differs */
     383    },
     384    {   /* #8: */
     385        /* .pszPath          =*/ "C:/over/ <>#%\"{}|^[]`/there",
     386        /* .pszUri           =*/ "file:///C:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there",
     387        /* .uFormat          =*/ URI_FILE_FORMAT_UNIX,
     388        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     389        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     390        /* PathCreateFromUrl =   "C:\\over\\ <>#%\"{}|^[]`\\there" - differs */
     391        /* UrlCreateFromPath =   "file:///C:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there" - same */
     392    },
     393    {   /* #9: */
     394        /* .pszPath          =*/ "\\over\\ <>#%\"{}|^[]`\\there",
     395        /* .pszUri           =*/ "file:///over%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere",
     396        /* .uFormat          =*/ URI_FILE_FORMAT_WIN,
     397        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     398        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     399        /* PathCreateFromUrl =   "\\over\\ <>#%\"{}|^[]`\\there" - same */
     400        /* UrlCreateFromPath =   "file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there" - differs */
     401    },
     402    {   /* #10: */
     403        /* .pszPath          =*/ "/usr/bin/grep",
     404        /* .pszUri           =*/ "file:///usr/bin/grep",
     405        /* .uFormat          =*/ URI_FILE_FORMAT_UNIX,
     406        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     407        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     408        /* PathCreateFromUrl =   "\\usr\\bin\\grep" - differs */
     409        /* UrlCreateFromPath =   "file:///usr/bin/grep" - same */
     410    },
     411    {   /* #11: */
     412        /* .pszPath          =*/ "\\usr\\bin\\grep",
     413        /* .pszUri           =*/ "file:///usr%5Cbin%5Cgrep",
     414        /* .uFormat          =*/ URI_FILE_FORMAT_WIN,
     415        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     416        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     417        /* PathCreateFromUrl =   "\\usr\\bin\\grep" - same */
     418        /* UrlCreateFromPath =   "file:///usr/bin/grep" - differs */
     419    },
     420    {   /* #12: */
     421        /* .pszPath          =*/ "/unixserver/isos/files.lst",
     422        /* .pszUri           =*/ "file:///unixserver/isos/files.lst",
     423        /* .uFormat          =*/ URI_FILE_FORMAT_UNIX,
     424        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     425        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     426        /* PathCreateFromUrl =   "\\unixserver\\isos\\files.lst" - differs */
     427        /* UrlCreateFromPath =   "file:///unixserver/isos/files.lst" - same */
     428    },
     429    {   /* #13: */
     430        /* .pszPath          =*/ "\\winserver\\isos\\files.lst",
     431        /* .pszUri           =*/ "file:///winserver%5Cisos%5Cfiles.lst",
     432        /* .uFormat          =*/ URI_FILE_FORMAT_WIN,
     433        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     434        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     435        /* PathCreateFromUrl =   "\\winserver\\isos\\files.lst" - same */
     436        /* UrlCreateFromPath =   "file:///winserver/isos/files.lst" - differs */
     437    },
     438    {   /* #14: */
     439        /* .pszPath          =*/ "/myserver/isos/files.lst",
     440        /* .pszUri           =*/ "file:///myserver/isos/files.lst",
     441        /* .uFormat          =*/ URI_FILE_FORMAT_UNIX,
     442        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     443        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     444        /* PathCreateFromUrl =   "\\myserver\\isos\\files.lst" - differs */
     445        /* UrlCreateFromPath =   "file:///myserver/isos/files.lst" - same */
     446    },
     447    {   /* #15: */
     448        /* .pszPath          =*/ "\\myserver\\isos\\files.lst",
     449        /* .pszUri           =*/ "file:///myserver%5Cisos%5Cfiles.lst",
     450        /* .uFormat          =*/ URI_FILE_FORMAT_WIN,
     451        /* .pszCreatedPath   =*/ NULL,    /* Same as pszPath. */
     452        /* .pszCreatedUri    =*/ NULL,    /* Same as pszUri. */
     453        /* PathCreateFromUrl =   "\\myserver\\isos\\files.lst" - same */
     454        /* UrlCreateFromPath =   "file:///myserver/isos/files.lst" - differs */
     455    },
     456};
     457
     458#ifdef TSTRTURI_WITH_WINDOWS_REFERENCE_RESULTS
     459
     460static void tstPrintCString(const char *pszString)
     461{
     462    if (pszString)
    310463    {
    311         "C:\\over\\ <>#%\"{}|^[]`\\there",
    312         "file:///C:%5Cover%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere",
    313         URI_FILE_FORMAT_WIN
    314     },
    315     {
    316         "/over/ <>#%\"{}|^[]`/there",
    317         "file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there",
    318         URI_FILE_FORMAT_UNIX
    319     },
    320     {
    321         NULL,
    322         "file://",
    323         URI_FILE_FORMAT_UNIX
    324     },
    325     {
    326         NULL,
    327         "file://",
    328         URI_FILE_FORMAT_WIN
    329     },
    330     {
    331         "/",
    332         "file:///",
    333         URI_FILE_FORMAT_UNIX
    334     },
    335     {
    336         "\\",
    337         "file:///",
    338         URI_FILE_FORMAT_WIN
    339     },
    340     {
    341         "/foo/bar",
    342         "file:///foo/bar",
    343         URI_FILE_FORMAT_UNIX
    344     },
    345     {
    346         "\\foo\\bar",
    347         "file:///foo%5Cbar",
    348         URI_FILE_FORMAT_WIN
    349     },
    350     {
    351         "C:/over/ <>#%\"{}|^[]`/there",
    352         "file:///C:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there",
    353         URI_FILE_FORMAT_UNIX
    354     },
    355     {
    356         "\\over\\ <>#%\"{}|^[]`\\there",
    357         "file:///over%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere",
    358         URI_FILE_FORMAT_WIN
    359     },
    360     {
    361         "/usr/bin/grep",
    362         "file:///usr/bin/grep",
    363         URI_FILE_FORMAT_UNIX
    364     },
    365     {
    366         "\\usr\\bin\\grep",
    367         "file:///usr%5Cbin%5Cgrep",
    368         URI_FILE_FORMAT_WIN
    369     },
    370     {
    371         "/unixserver/isos/files.lst",
    372         "file:///unixserver/isos/files.lst",
    373         URI_FILE_FORMAT_UNIX
    374     },
    375     {
    376         "\\winserver\\isos\\files.lst",
    377         "file:///winserver%5Cisos%5Cfiles.lst",
    378         URI_FILE_FORMAT_WIN
    379     },
    380     {
    381         "/myserver/isos/files.lst",
    382         "file:///myserver/isos/files.lst",
    383         URI_FILE_FORMAT_UNIX
    384     },
    385     {
    386         "\\myserver\\isos\\files.lst",
    387         "file:///myserver%5Cisos%5Cfiles.lst",
    388         URI_FILE_FORMAT_WIN
    389     }
    390 };
    391 
    392 /*
    393  * For reference, taken from output of PathCreateFromUrl/UrlCreateFromPath on Windows:
    394  *
    395  * #0: Path=C:\over\ <>#%"{}|^[]`\there, URL=file:///C:%5Cover%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere
    396  *       PathCreateFromUrl: file:///C:%5Cover%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere -> C:\over\ <>#%"{}|^[]`\there
    397  *       UrlCreateFromPath: C:\over\ <>#%"{}|^[]`\there -> file:%2F%2F%2FC:%2Fover%2F%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%2Fthere
    398  * #1: Path=/over/ <>#%"{}|^[]`/there, URL=file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there
    399  *       PathCreateFromUrl: file:///over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there -> \over\ <>#%"{}|^[]`\there
    400  *       UrlCreateFromPath: /over/ <>#%"{}|^[]`/there -> file:%2F%2F%2Fover%2F%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%2Fthere
    401  * #2: Path=<NULL>, URL=file://
    402  *       PathCreateFromUrl: file:// ->
    403  *       UrlCreateFromPath: <NULL> ->
    404  * #3: Path=<NULL>, URL=file://
    405  *       PathCreateFromUrl: file:// ->
    406  *       UrlCreateFromPath: <NULL> ->
    407  * #4: Path=/, URL=file:///
    408  *       PathCreateFromUrl: file:/// ->
    409  *       UrlCreateFromPath: / -> file:%2F%2F%2F
    410  * #5: Path=/foo/bar, URL=file:///foo/bar
    411  *       PathCreateFromUrl: file:///foo/bar -> \foo\bar
    412  *       UrlCreateFromPath: /foo/bar -> file:%2F%2F%2Ffoo%2Fbar
    413  * #6: Path=\foo\bar, URL=file:///foo%5Cbar
    414  *       PathCreateFromUrl: file:///foo%5Cbar -> \foo\bar
    415  *       UrlCreateFromPath: \foo\bar -> file:%2F%2F%2Ffoo%2Fbar
    416  * #7: Path=C:/over/ <>#%"{}|^[]`/there, URL=file:///C:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there
    417  *       PathCreateFromUrl: file:///C:/over/%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60/there -> C:\over\ <>#%"{}|^[]`\there
    418  *       UrlCreateFromPath: C:/over/ <>#%"{}|^[]`/there -> file:%2F%2F%2FC:%2Fover%2F%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%2Fthere
    419  * #8: Path=\over\ <>#%"{}|^[]`\there, URL=file:///over%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere
    420  *       PathCreateFromUrl: file:///over%5C%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%5Cthere -> \over\ <>#%"{}|^[]`\there
    421  *       UrlCreateFromPath: \over\ <>#%"{}|^[]`\there -> file:%2F%2F%2Fover%2F%20%3C%3E%23%25%22%7B%7D%7C%5E%5B%5D%60%2Fthere
    422  * #9: Path=/usr/bin/grep, URL=file:///usr/bin/grep
    423  *       PathCreateFromUrl: file:///usr/bin/grep -> \usr\bin\grep
    424  *       UrlCreateFromPath: /usr/bin/grep -> file:%2F%2F%2Fusr%2Fbin%2Fgrep
    425  * #10: Path=\usr\bin\grep, URL=file:///usr%5Cbin%5Cgrep
    426  *       PathCreateFromUrl: file:///usr%5Cbin%5Cgrep -> \usr\bin\grep
    427  *       UrlCreateFromPath: \usr\bin\grep -> file:%2F%2F%2Fusr%2Fbin%2Fgrep
    428  * #11: Path=/unixserver/isos/files.lst, URL=file:///unixserver/isos/files.lst
    429  *       PathCreateFromUrl: file:///unixserver/isos/files.lst -> \unixserver\isos\files.lst
    430  *       UrlCreateFromPath: /unixserver/isos/files.lst -> file:%2F%2F%2Funixserver%2Fisos%2Ffiles.lst
    431  * #12: Path=\winserver\isos\files.lst, URL=file:///winserver%5Cisos%5Cfiles.lst
    432  *       PathCreateFromUrl: file:///winserver%5Cisos%5Cfiles.lst -> \winserver\isos\files.lst
    433  *       UrlCreateFromPath: \winserver\isos\files.lst -> file:%2F%2F%2Fwinserver%2Fisos%2Ffiles.lst
    434  * #13: Path=/myserver/isos/files.lst, URL=file:///myserver/isos/files.lst
    435  *       PathCreateFromUrl: file:///myserver/isos/files.lst -> \myserver\isos\files.lst
    436  *       UrlCreateFromPath: /myserver/isos/files.lst -> file:%2F%2F%2Fmyserver%2Fisos%2Ffiles.lst
    437  * #14: Path=\myserver\isos\files.lst, URL=file:///myserver%5Cisos%5Cfiles.lst
    438  *       PathCreateFromUrl: file:///myserver%5Cisos%5Cfiles.lst -> \myserver\isos\files.lst
    439  *       UrlCreateFromPath: \myserver\isos\files.lst -> file:%2F%2F%2Fmyserver%2Fisos%2Ffiles.lst
    440  */
    441 
    442 static void tstCreate(size_t idxTest, const char *pszScheme, const char *pszAuthority, const char *pszPath, const char *pszQuery, const char *pszFragment, const char *pszTest)
    443 {
    444     char *pszResult = RTUriCreate(pszScheme, pszAuthority, pszPath, pszQuery, pszFragment);
    445     if (pszTest)
    446     {
    447         RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
    448         RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
     464        char ch;
     465        RTPrintf("\"");
     466        while ((ch = *pszString++) != '\0')
     467        {
     468            if (ch >= 0x20 && ch < 0x7f)
     469                switch (ch)
     470                {
     471                    default:
     472                        RTPrintf("%c", ch);
     473                        break;
     474                    case '\\':
     475                    case '"':
     476                        RTPrintf("\\%c", ch);
     477                        break;
     478                }
     479            else
     480                RTPrintf("\\x%02X", ch); /* good enough */
     481        }
     482        RTPrintf("\"");
    449483    }
    450484    else
    451         RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'", idxTest, pszResult, pszTest));
    452 
    453     if (pszResult)
    454         RTStrFree(pszResult);
    455     return;
     485        RTPrintf("NULL");
    456486}
    457487
    458 static void tstFileCreate(size_t idxTest, const char *pszPath, const char *pszTest)
     488static void tstWindowsReferenceResults(void)
    459489{
    460     char *pszResult = RTUriFileCreate(pszPath);
    461     if (pszTest)
     490    /*
     491     * Feed the g_aCreateFileURIs values as input to the Windows
     492     * PathCreateFromUrl and URlCreateFromPath APIs and print the results.
     493     *
     494     * We reproduce the entire source file content of g_aCreateFileURIs here.
     495     */
     496    for (size_t i = 0; i < RT_ELEMENTS(g_aCreateFileURIs); ++i)
    462497    {
    463         RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'\n", idxTest, pszResult, pszTest));
    464         RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'\n", idxTest, pszResult, pszTest));
     498        RTPrintf("    {   /* #%u: */\n", i);
     499        RTPrintf("        /* .pszPath          =*/ ");
     500        tstPrintCString(g_aCreateFileURIs[i].pszPath);
     501        RTPrintf(",\n");
     502        RTPrintf("        /* .pszUri           =*/ ");
     503        tstPrintCString(g_aCreateFileURIs[i].pszUri);
     504        RTPrintf(",\n");
     505        RTPrintf("        /* .uFormat          =*/ %s,\n",
     506                   g_aCreateFileURIs[i].uFormat == URI_FILE_FORMAT_WIN  ? "URI_FILE_FORMAT_WIN"
     507                 : g_aCreateFileURIs[i].uFormat == URI_FILE_FORMAT_UNIX ? "URI_FILE_FORMAT_UNIX"
     508                 : g_aCreateFileURIs[i].uFormat == URI_FILE_FORMAT_AUTO ? "URI_FILE_FORMAT_AUTO" : "URI_FILE_FORMAT_INVALID");
     509        RTPrintf("        /* .pszCreatedPath   =*/ ");
     510        if (g_aCreateFileURIs[i].pszCreatedPath == NULL)
     511            RTPrintf("NULL,    /* Same as pszPath. */\n");
     512        else
     513        {
     514            tstPrintCString(g_aCreateFileURIs[i].pszCreatedPath);
     515            RTPrintf(",\n");
     516        }
     517        RTPrintf("        /* .pszCreatedUri    =*/ ");
     518        if (g_aCreateFileURIs[i].pszCreatedUri == NULL)
     519            RTPrintf("NULL,    /* Same as pszUri. */\n");
     520        else
     521        {
     522            tstPrintCString(g_aCreateFileURIs[i].pszCreatedUri);
     523            RTPrintf(",\n");
     524        }
     525
     526        /*
     527         * PathCreateFromUrl
     528         */
     529        PRTUTF16 pwszInput = NULL;
     530        if (g_aCreateFileURIs[i].pszUri)
     531            RTTESTI_CHECK_RC_OK_RETV(RTStrToUtf16(g_aCreateFileURIs[i].pszUri, &pwszInput));
     532        WCHAR wszResult[_1K];
     533        DWORD cwcResult = RT_ELEMENTS(wszResult);
     534        RT_ZERO(wszResult);
     535        HRESULT hrc = PathCreateFromUrlW(pwszInput, wszResult, &cwcResult, 0 /*dwFlags*/);
     536        RTUtf16Free(pwszInput);
     537
     538        if (SUCCEEDED(hrc))
     539        {
     540            char *pszResult;
     541            RTTESTI_CHECK_RC_OK_RETV(RTUtf16ToUtf8(wszResult, &pszResult));
     542            RTPrintf("        /* PathCreateFromUrl =   ");
     543            tstPrintCString(pszResult);
     544            if (   g_aCreateFileURIs[i].pszPath
     545                && strcmp(pszResult, g_aCreateFileURIs[i].pszCreatedPath
     546                                     ? g_aCreateFileURIs[i].pszCreatedPath : g_aCreateFileURIs[i].pszPath) == 0)
     547                RTPrintf(" - same */\n");
     548            else
     549                RTPrintf(" - differs */\n");
     550            RTStrFree(pszResult);
     551        }
     552        else
     553            RTPrintf("        /* PathCreateFromUrl => %#x (%Rhrc) */\n", hrc, hrc);
     554
     555        /*
     556         * UrlCreateFromPath + UrlEscape
     557         */
     558        pwszInput = NULL;
     559        if (g_aCreateFileURIs[i].pszPath)
     560            RTTESTI_CHECK_RC_OK_RETV(RTStrToUtf16(g_aCreateFileURIs[i].pszPath, &pwszInput));
     561        RT_ZERO(wszResult);
     562        cwcResult = RT_ELEMENTS(wszResult);
     563        hrc = UrlCreateFromPathW(pwszInput, wszResult, &cwcResult, 0 /*dwFlags*/);
     564        RTUtf16Free(pwszInput);
     565
     566        if (SUCCEEDED(hrc))
     567        {
     568            WCHAR wszResult2[_1K];
     569            DWORD cwcResult2 = RT_ELEMENTS(wszResult2);
     570            hrc = UrlEscapeW(wszResult, wszResult2, &cwcResult2, URL_DONT_ESCAPE_EXTRA_INFO );
     571            if (SUCCEEDED(hrc))
     572            {
     573                char *pszResult;
     574                RTTESTI_CHECK_RC_OK_RETV(RTUtf16ToUtf8(wszResult2, &pszResult));
     575                RTPrintf("        /* UrlCreateFromPath =   ");
     576                tstPrintCString(pszResult);
     577                if (   g_aCreateFileURIs[i].pszUri
     578                    && strcmp(pszResult, g_aCreateFileURIs[i].pszCreatedUri
     579                                         ? g_aCreateFileURIs[i].pszCreatedUri : g_aCreateFileURIs[i].pszUri) == 0)
     580                    RTPrintf(" - same */\n");
     581                else
     582                    RTPrintf(" - differs */\n");
     583                RTStrFree(pszResult);
     584            }
     585            else
     586                RTPrintf("        /* UrlEscapeW        => %#x (%Rhrc) */\n", hrc, hrc);
     587        }
     588        else
     589            RTPrintf("        /* UrlCreateFromPath => %#x (%Rhrc) */\n", hrc, hrc);
     590        RTPrintf("    },\n");
    465591    }
    466     else
    467         RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'\n", idxTest, pszResult, pszTest));
    468 
    469     if (pszResult)
    470         RTStrFree(pszResult);
    471     return;
    472592}
    473593
    474 static void tstFilePath(size_t idxTest, const char *pszUri, const char *pszTest, uint32_t uFormat)
    475 {
    476     char *pszResult = RTUriFilePath(pszUri, uFormat);
    477     if (pszTest)
    478     {
    479         RTTESTI_CHECK_MSG_RETV(pszResult, ("#%u: Result '%s' != '%s'\n", idxTest, pszResult, pszTest));
    480         RTTESTI_CHECK_MSG(RTStrCmp(pszResult, pszTest) == 0, ("#%u: Result '%s' != '%s'\n", idxTest, pszResult, pszTest));
    481     }
    482     else
    483         RTTESTI_CHECK_MSG(!pszResult, ("#%u: Result '%s' != '%s'\n", idxTest, pszResult, pszTest));
    484 
    485     if (pszResult)
    486         RTStrFree(pszResult);
    487     return;
    488 }
     594#endif /* TSTRTURI_WITH_WINDOWS_REFERENCE_RESULTS */
     595
    489596
    490597int main()
     
    539646                      g_aTests[i].pszCreated ? g_aTests[i].pszCreated : g_aTests[i].pszUri);
    540647
    541 #ifdef _DEBUG
    542 # ifdef RT_OS_WINDOWS
    543     /* To generate the PathCreateFromUrl/UrlCreateFromPath reference on Windows. */
    544     for (size_t i = 0; i < RT_ELEMENTS(g_apCreateFileURIs); ++i)
    545     {
    546         RTTestPrintf(hTest, RTTESTLVL_DEBUG, "#%u: Path=%s, URL=%s\n", i, g_apCreateFileURIs[i].pcszPath, g_apCreateFileURIs[i].pcszUri);
    547         char szPath[255] = { 0 };
    548         DWORD dw = 255;
    549         PathCreateFromUrl(g_apCreateFileURIs[i].pcszUri, szPath, &dw, NULL);
    550         RTTestPrintf(hTest, RTTESTLVL_DEBUG, "\tPathCreateFromUrl: %s -> %s\n", g_apCreateFileURIs[i].pcszUri, szPath);
    551         char szURL[255] = { 0 };
    552         dw = 255;
    553         UrlCreateFromPath(g_apCreateFileURIs[i].pcszPath, szURL, &dw, NULL);
    554         char szURLEsc[255] = { 0 };
    555         dw = 255;
    556         UrlEscape(szURL, szURLEsc, &dw, URL_ESCAPE_SEGMENT_ONLY);
    557         RTTestPrintf(hTest, RTTESTLVL_DEBUG, "\tUrlCreateFromPath: %s -> %s\n", g_apCreateFileURIs[i].pcszPath, szURLEsc);
    558     }
    559 # endif
     648#ifdef TSTRTURI_WITH_WINDOWS_REFERENCE_RESULTS
     649    tstWindowsReferenceResults();
    560650#endif
    561651
    562652    /* File Uri path */
    563653    RTTestISub("RTUriFilePath");
    564     for (size_t i = 0; i < RT_ELEMENTS(g_apCreateFileURIs); ++i)
    565         tstFilePath(i, g_apCreateFileURIs[i].pcszUri, g_apCreateFileURIs[i].pcszPath, g_apCreateFileURIs[i].uFormat);
     654    for (size_t i = 0; i < RT_ELEMENTS(g_aCreateFileURIs); ++i)
     655        CHECK_STR_API(RTUriFilePath(g_aCreateFileURIs[i].pszUri, g_aCreateFileURIs[i].uFormat),
     656                      g_aCreateFileURIs[i].pszCreatedPath ? g_aCreateFileURIs[i].pszCreatedPath : g_aCreateFileURIs[i].pszPath);
    566657
    567658    /* File Uri creation */
    568659    RTTestISub("RTUriFileCreate");
    569     for (size_t i = 0; i < RT_ELEMENTS(g_apCreateFileURIs); ++i)
    570         tstFileCreate(i, g_apCreateFileURIs[i].pcszPath, g_apCreateFileURIs[i].pcszUri);
     660    for (size_t i = 0; i < RT_ELEMENTS(g_aCreateFileURIs); ++i)
     661        CHECK_STR_API(RTUriFileCreate(g_aCreateFileURIs[i].pszPath),
     662                      g_aCreateFileURIs[i].pszCreatedUri ? g_aCreateFileURIs[i].pszCreatedUri : g_aCreateFileURIs[i].pszUri);
    571663
    572664    return RTTestSummaryAndDestroy(hTest);
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