VirtualBox

Changeset 19925 in vbox


Ignore:
Timestamp:
May 22, 2009 11:15:42 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
47627
Message:

tstPath.cpp: Converted to RTTest.

File:
1 edited

Legend:

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

    r19924 r19925  
    3333*******************************************************************************/
    3434#include <iprt/path.h>
     35
     36#include <iprt/err.h>
     37#include <iprt/initterm.h>
     38#include <iprt/param.h>
    3539#include <iprt/process.h>
    36 #include <iprt/initterm.h>
    3740#include <iprt/stream.h>
    3841#include <iprt/string.h>
    39 #include <iprt/err.h>
    40 #include <iprt/param.h>
    41 
    42 
    43 #define CHECK_RC(method) \
    44     do { \
    45         rc = method; \
    46         if (RT_FAILURE(rc)) \
    47         { \
    48             cErrors++; \
    49             RTPrintf("\ntstPath: FAILED calling " #method " at line %d: rc=%Rrc\n", __LINE__, rc); \
    50         } \
    51     } while (0)
     42#include <iprt/test.h>
     43
    5244
    5345int main()
    5446{
    5547    /*
    56      * Init RT.
    57      */
    58     int rc;
    59     int cErrors = 0;
    60     CHECK_RC(RTR3Init());
     48     * Init RT+Test.
     49     */
     50    int rc = RTR3Init();
    6151    if (RT_FAILURE(rc))
    6252        return 1;
    6353
     54    RTTEST hTest;
     55    rc = RTTestCreate("tstPath", &hTest);
     56    if (RT_FAILURE(rc))
     57        return 1;
     58    RTTestBanner(hTest);
     59
    6460    /*
    6561     * RTPathExecDir, RTPathUserHome and RTProcGetExecutableName.
    6662     */
     63    RTTestSub(hTest, "RTPathExecDir");
    6764    char szPath[RTPATH_MAX];
    68     CHECK_RC(RTPathExecDir(szPath, sizeof(szPath)));
     65    RTTESTI_CHECK_RC(RTPathExecDir(szPath, sizeof(szPath)), VINF_SUCCESS);
    6966    if (RT_SUCCESS(rc))
    70         RTPrintf("ExecDir={%s}\n", szPath);
    71     CHECK_RC(RTPathUserHome(szPath, sizeof(szPath)));
     67        RTTestIPrintf(RTTESTLVL_INFO, "ExecDir={%s}\n", szPath);
     68
     69    RTTestSub(hTest, "RTProcGetExecutableName");
     70    if (RTProcGetExecutableName(szPath, sizeof(szPath)) == szPath)
     71        RTTestIPrintf(RTTESTLVL_INFO, "ExecutableName={%s}\n", szPath);
     72    else
     73        RTTestIFailed("RTProcGetExecutableName -> NULL");
     74
     75    RTTestSub(hTest, "RTPathUserHome");
     76    RTTESTI_CHECK_RC(RTPathUserHome(szPath, sizeof(szPath)), VINF_SUCCESS);
    7277    if (RT_SUCCESS(rc))
    73         RTPrintf("UserHome={%s}\n", szPath);
    74     if (RTProcGetExecutableName(szPath, sizeof(szPath)) == szPath)
    75         RTPrintf("ExecutableName={%s}\n", szPath);
    76     else
    77     {
    78         RTPrintf("tstPath: FAILED - RTProcGetExecutableName\n");
    79         cErrors++;
    80     }
    81 
     78        RTTestIPrintf(RTTESTLVL_INFO, "UserHome={%s}\n", szPath);
    8279
    8380    /*
    8481     * RTPathAbsEx
    8582     */
    86     RTPrintf("tstPath: TESTING RTPathAbsEx()\n");
     83    RTTestSub(hTest, "RTPathAbsEx");
    8784    static const struct
    8885    {
     
    153150        if (rc != s_aRTPathAbsExTests[i].rc)
    154151        {
    155             RTPrintf("tstPath: RTPathAbsEx unexpected result code!\n"
    156                      "   input base: '%s'\n"
    157                      "   input path: '%s'\n"
    158                      "       output: '%s'\n"
    159                      "           rc: %Rrc\n"
    160                      "  expected rc: %Rrc\n",
    161                      s_aRTPathAbsExTests[i].pcszInputBase,
    162                      s_aRTPathAbsExTests[i].pcszInputPath,
    163                      szPath, rc,
    164                      s_aRTPathAbsExTests[i].rc);
    165             cErrors++;
     152            RTTestIFailed("unexpected result code!\n"
     153                          "   input base: '%s'\n"
     154                          "   input path: '%s'\n"
     155                          "       output: '%s'\n"
     156                          "           rc: %Rrc\n"
     157                          "  expected rc: %Rrc",
     158                          s_aRTPathAbsExTests[i].pcszInputBase,
     159                          s_aRTPathAbsExTests[i].pcszInputPath,
     160                          szPath, rc,
     161                          s_aRTPathAbsExTests[i].rc);
    166162            continue;
    167163        }
     
    173169            if (s_aRTPathAbsExTests[i].pcszOutput[0] == '%')
    174170            {
    175                 rc = RTPathGetCurrent(szTmp, sizeof(szTmp));
     171                RTTESTI_CHECK_RC(rc = RTPathGetCurrent(szTmp, sizeof(szTmp)), VINF_SUCCESS);
    176172                if (RT_FAILURE(rc))
    177                 {
    178                     RTPrintf("tstPath: RTPathGetCurrent failed with rc=%Rrc!\n", rc);
    179                     cErrors++;
    180173                    break;
    181                 }
    182174
    183175                pszExpected = szTmp;
     
    205197            if (strcmp(szPath, pszExpected))
    206198            {
    207                 RTPrintf("tstPath: RTPathAbsEx failed!\n"
    208                          "   input base: '%s'\n"
    209                          "   input path: '%s'\n"
    210                          "       output: '%s'\n"
    211                          "     expected: '%s'\n",
    212                          s_aRTPathAbsExTests[i].pcszInputBase,
    213                          s_aRTPathAbsExTests[i].pcszInputPath,
    214                          szPath,
    215                          s_aRTPathAbsExTests[i].pcszOutput);
    216                 cErrors++;
     199                RTTestIFailed("Unexpected result\n"
     200                              "   input base: '%s'\n"
     201                              "   input path: '%s'\n"
     202                              "       output: '%s'\n"
     203                              "     expected: '%s'",
     204                              s_aRTPathAbsExTests[i].pcszInputBase,
     205                              s_aRTPathAbsExTests[i].pcszInputPath,
     206                              szPath,
     207                              s_aRTPathAbsExTests[i].pcszOutput);
    217208            }
    218209        }
     
    222213     * RTPathStripFilename
    223214     */
    224     RTPrintf("tstPath: RTPathStripFilename...\n");
     215    RTTestSub(hTest, "RTPathStripFilename");
    225216    static const char *s_apszStripFilenameTests[] =
    226217    {
     
    246237        if (strcmp(szPath, pszExpect))
    247238        {
    248             RTPrintf("tstPath: RTPathStripFilename failed!\n"
    249                      "   input: '%s'\n"
    250                      "  output: '%s'\n"
    251                      "expected: '%s'\n",
    252                      pszInput, szPath, pszExpect);
    253             cErrors++;
     239            RTTestIFailed("Unexpected result\n"
     240                          "   input: '%s'\n"
     241                          "  output: '%s'\n"
     242                          "expected: '%s'",
     243                          pszInput, szPath, pszExpect);
    254244        }
    255245    }
    256246
    257247    /*
     248     * RTPathAppend.
     249     */
     250
     251
     252
     253    /*
    258254     * Summary.
    259255     */
    260     if (!cErrors)
    261         RTPrintf("tstPath: SUCCESS\n");
    262     else
    263         RTPrintf("tstPath: FAILURE %d errors\n", cErrors);
    264     return !!cErrors;
     256    return RTTestSummaryAndDestroy(hTest);
    265257}
    266258
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