VirtualBox

Changeset 41555 in vbox


Ignore:
Timestamp:
Jun 3, 2012 10:43:15 PM (13 years ago)
Author:
vboxsync
Message:

tstErrUnique.cpp: Converted to RTTest and updated with changes from r78322.

File:
1 edited

Legend:

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

    r41296 r41555  
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3131#include <iprt/err.h>
    3232#include <iprt/string.h>
    33 #include <iprt/stream.h>
    34 #include <iprt/initterm.h>
    35 #include <VBox/err.h>
     33#include <iprt/test.h>
     34#ifdef VBOX
     35# include <VBox/err.h>
     36#endif
    3637
    3738
     
    4849
    4950
    50 static bool strIsPermissibleDuplicate(const RTSTATUSMSG *msg)
     51static bool strIsPermissibleDuplicate(const RTSTATUSMSG *pMsg)
    5152{
    52     const char *pszMsgShort = msg->pszMsgShort;
    53     const char *pszDefine = msg->pszDefine;
    54     size_t cbDefine = strlen(pszDefine);
     53    const char *pszDefine = pMsg->pszDefine;
     54    size_t      cchDefine = strlen(pszDefine);
    5555
    56     return    (strstr(pszMsgShort, "(mapped to") != 0)
    57            || (strstr(pszDefine, "FIRST") == pszDefine + (cbDefine - 5))
    58            || (strstr(pszDefine, "LAST") == pszDefine + (cbDefine - 4));
     56#define STR_ENDS_WITH(a_psz, a_cch, a_sz) \
     57    ( (a_cch) >= sizeof(a_sz) && !strncmp((a_psz) + (a_cch) - sizeof(a_sz) + 1, RT_STR_TUPLE(a_sz)) )
     58
     59    return  STR_ENDS_WITH(pszDefine, cchDefine, "_FIRST")
     60         || STR_ENDS_WITH(pszDefine, cchDefine, "_LASTX")
     61         || STR_ENDS_WITH(pszDefine, cchDefine, "_LOWEST")
     62         || STR_ENDS_WITH(pszDefine, cchDefine, "_HIGHEST")
     63         || strstr(pMsg->pszMsgShort, "(mapped to") != 0;
    5964}
    6065
     
    6267int main()
    6368{
    64     int         cErrors = 0;
    65     RTR3InitExeNoArguments(0);
    66     RTPrintf("tstErrUnique: TESTING\n");
     69    RTTEST hTest;
     70    RTEXITCODE rcExit = RTTestInitAndCreate("tstRTErrUnique", &hTest);
     71    if (rcExit != RTEXITCODE_SUCCESS)
     72        return rcExit;
     73    RTTestBanner(hTest);
    6774
     75    RTTestSub(hTest, "IPRT status code");
    6876    for (uint32_t i = 0; i < RT_ELEMENTS(g_aErrorMessages) - 1; i++)
    69     {
    70         if (strIsPermissibleDuplicate(&g_aErrorMessages[i]))
    71             continue;
     77        if (!strIsPermissibleDuplicate(&g_aErrorMessages[i]))
     78            for (uint32_t j = i + 1; j < RT_ELEMENTS(g_aErrorMessages); j++)
     79                if (   !strIsPermissibleDuplicate(&g_aErrorMessages[j])
     80                    && g_aErrorMessages[i].iCode == g_aErrorMessages[j].iCode)
     81                    RTTestFailed(hTest, "Status code %d can mean both '%s' and '%s'",
     82                                 g_aErrorMessages[i].iCode,
     83                                 g_aErrorMessages[i].pszDefine,
     84                                 g_aErrorMessages[j].pszDefine);
    7285
    73         for (uint32_t j = i + 1; j < RT_ELEMENTS(g_aErrorMessages); j++)
    74         {
    75             if (strIsPermissibleDuplicate(&g_aErrorMessages[j]))
    76                 continue;
    77 
    78             if (g_aErrorMessages[i].iCode == g_aErrorMessages[j].iCode)
    79             {
    80                 RTPrintf("tstErrUnique: status code %d\n  can mean '%s'\n  or '%s'\n", g_aErrorMessages[i].iCode, g_aErrorMessages[i].pszMsgShort, g_aErrorMessages[j].pszMsgShort);
    81                 cErrors++;
    82             }
    83         }
    84     }
    85 
    86     /*
    87      * Summary
    88      */
    89     if (cErrors == 0)
    90         RTPrintf("tstErrUnique: SUCCESS\n");
    91     else
    92         RTPrintf("tstErrUnique: FAILURE - %d errors\n", cErrors);
    93     return !!cErrors;
     86    return RTTestSummaryAndDestroy(hTest);
    9487}
    9588
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