VirtualBox

Changeset 86371 in vbox for trunk


Ignore:
Timestamp:
Oct 1, 2020 5:23:53 AM (4 years ago)
Author:
vboxsync
Message:

tstGuestCtrlParseBuffer: Must disable assertions when doing test expected to trigger some. bugref:9841

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/testcase/tstGuestCtrlParseBuffer.cpp

    r82968 r86371  
    6565    const char *pbData;
    6666    size_t      cbData;
    67     uint32_t    uOffsetStart;
    68     uint32_t    uOffsetAfter;
    69     uint32_t    uMapElements;
     67    uint32_t    offStart;
     68    uint32_t    offAfter;
     69    uint32_t    cMapElements;
    7070    int         iResult;
    71 } g_aTestBlock[] =
     71} g_aTestBlocks[] =
    7272{
    7373    /*
     
    119119    size_t      cbData;
    120120    /** Number of data blocks retrieved. These are separated by "\0\0". */
    121     uint32_t    uNumBlocks;
     121    uint32_t    cBlocks;
    122122    /** Overall result when done parsing. */
    123123    int         iResult;
    124 } g_aTestStream[] =
     124} const g_aTestStream[] =
    125125{
    126126    /* No blocks. */
     
    140140        const char *pbData;
    141141        size_t      cbData;
    142         uint32_t    uOffsetStart;
    143         uint32_t    uOffsetAfter;
    144         uint32_t    uMapElements;
     142        uint32_t    offStart;
     143        uint32_t    offAfter;
     144        uint32_t    cMapElements;
    145145        int         iResult;
    146     } s_aTest[] =
     146    } const s_aTest[] =
    147147    {
    148148        { "test5=test5\0t51=t51",           sizeof("test5=test5\0t51=t51"),                            0,  sizeof("test5=test5\0") - 1,                   1, VERR_MORE_DATA },
     
    175175{
    176176    RTTEST hTest;
    177     int rc = RTTestInitAndCreate("tstParseBuffer", &hTest);
    178     if (rc)
    179         return rc;
     177    RTEXITCODE rcExit = RTTestInitAndCreate("tstParseBuffer", &hTest);
     178    if (rcExit != RTEXITCODE_SUCCESS)
     179        return rcExit;
    180180    RTTestBanner(hTest);
    181181
     
    195195
    196196    if (sizeof("sizecheck") != 10)
    197         RTTestFailed(hTest, "Basic size test #1 failed (%u <-> 10)", sizeof("sizecheck"));
     197        RTTestFailed(hTest, "Basic size test #1 failed (%zu <-> 10)", sizeof("sizecheck"));
    198198    if (sizeof("off=rab") != 8)
    199         RTTestFailed(hTest, "Basic size test #2 failed (%u <-> 7)", sizeof("off=rab"));
     199        RTTestFailed(hTest, "Basic size test #2 failed (%zu <-> 7)", sizeof("off=rab"));
    200200    if (sizeof("off=rab\0\0") != 10)
    201         RTTestFailed(hTest, "Basic size test #3 failed (%u <-> 10)", sizeof("off=rab\0\0"));
     201        RTTestFailed(hTest, "Basic size test #3 failed (%zu <-> 10)", sizeof("off=rab\0\0"));
    202202
    203203    RTTestIPrintf(RTTESTLVL_INFO, "Doing line tests ...\n");
     
    208208
    209209    unsigned iTest;
    210     for (iTest = 0; iTest < RT_ELEMENTS(g_aTestBlock); iTest++)
     210    for (iTest = 0; iTest < RT_ELEMENTS(g_aTestBlocks); iTest++)
    211211    {
    212212        RTTestIPrintf(RTTESTLVL_DEBUG, "=> Test #%u\n", iTest);
    213213
    214214        GuestProcessStream stream;
    215         int iResult = stream.AddData((BYTE*)g_aTestBlock[iTest].pbData, g_aTestBlock[iTest].cbData);
     215        if (RT_FAILURE(g_aTestBlocks[iTest].iResult))
     216            RTTestDisableAssertions(hTest);
     217        int iResult = stream.AddData((BYTE *)g_aTestBlocks[iTest].pbData, g_aTestBlocks[iTest].cbData);
     218        if (RT_FAILURE(g_aTestBlocks[iTest].iResult))
     219            RTTestRestoreAssertions(hTest);
    216220        if (RT_SUCCESS(iResult))
    217221        {
    218222            GuestProcessStreamBlock curBlock;
    219223            iResult = stream.ParseBlock(curBlock);
    220             if (iResult != g_aTestBlock[iTest].iResult)
    221             {
    222                 RTTestFailed(hTest, "\tReturned %Rrc, expected %Rrc\n",
    223                              iResult, g_aTestBlock[iTest].iResult);
    224             }
    225             else if (stream.GetOffset() != g_aTestBlock[iTest].uOffsetAfter)
    226             {
    227                 RTTestFailed(hTest, "\tOffset %zu wrong, expected %u\n",
    228                              stream.GetOffset(), g_aTestBlock[iTest].uOffsetAfter);
    229             }
     224            if (iResult != g_aTestBlocks[iTest].iResult)
     225                RTTestFailed(hTest, "\tReturned %Rrc, expected %Rrc\n", iResult, g_aTestBlocks[iTest].iResult);
     226            else if (stream.GetOffset() != g_aTestBlocks[iTest].offAfter)
     227                RTTestFailed(hTest, "\tOffset %zu wrong, expected %u\n", stream.GetOffset(), g_aTestBlocks[iTest].offAfter);
    230228            else if (iResult == VERR_MORE_DATA)
    231             {
    232229                RTTestIPrintf(RTTESTLVL_DEBUG, "\tMore data (Offset: %zu)\n", stream.GetOffset());
    233             }
    234 
    235             if (  (   RT_SUCCESS(iResult)
    236                    || iResult == VERR_MORE_DATA))
    237             {
    238                 if (curBlock.GetCount() != g_aTestBlock[iTest].uMapElements)
    239                 {
     230
     231            if (RT_SUCCESS(iResult) || iResult == VERR_MORE_DATA)
     232                if (curBlock.GetCount() != g_aTestBlocks[iTest].cMapElements)
    240233                    RTTestFailed(hTest, "\tMap has %u elements, expected %u\n",
    241                                  curBlock.GetCount(), g_aTestBlock[iTest].uMapElements);
    242                 }
    243             }
     234                                 curBlock.GetCount(), g_aTestBlocks[iTest].cMapElements);
    244235
    245236            /* There is remaining data left in the buffer (which needs to be merged
    246237             * with a following buffer) -- print it. */
    247238            size_t off = stream.GetOffset();
    248             size_t cbToWrite = g_aTestBlock[iTest].cbData - off;
     239            size_t cbToWrite = g_aTestBlocks[iTest].cbData - off;
    249240            if (cbToWrite)
    250241            {
     
    254245                 * Hack alert: Using RTEnvGet for now. */
    255246                if (!RTStrICmp(RTEnvGet("IPRT_TEST_MAX_LEVEL"), "debug"))
    256                     RTStrmWriteEx(g_pStdOut, &g_aTestBlock[iTest].pbData[off], cbToWrite - 1, NULL);
     247                    RTStrmWriteEx(g_pStdOut, &g_aTestBlocks[iTest].pbData[off], cbToWrite - 1, NULL);
    257248            }
    258249        }
     
    269260        if (RT_SUCCESS(iResult))
    270261        {
    271             uint32_t uNumBlocks = 0;
     262            uint32_t cBlocks = 0;
    272263            uint8_t uSafeCouunter = 0;
    273264            do
     
    280271                    /* Only count block which have at least one pair. */
    281272                    if (curBlock.GetCount())
    282                         uNumBlocks++;
     273                        cBlocks++;
    283274                }
    284275                if (uSafeCouunter++ > 32)
     
    287278
    288279            if (iResult != g_aTestStream[iTest].iResult)
    289             {
    290                 RTTestFailed(hTest, "\tReturned %Rrc, expected %Rrc\n",
    291                              iResult, g_aTestStream[iTest].iResult);
    292             }
    293             else if (uNumBlocks != g_aTestStream[iTest].uNumBlocks)
    294             {
    295                 RTTestFailed(hTest, "\tReturned %u blocks, expected %u\n",
    296                              uNumBlocks, g_aTestStream[iTest].uNumBlocks);
    297             }
     280                RTTestFailed(hTest, "\tReturned %Rrc, expected %Rrc\n", iResult, g_aTestStream[iTest].iResult);
     281            else if (cBlocks != g_aTestStream[iTest].cBlocks)
     282                RTTestFailed(hTest, "\tReturned %u blocks, expected %u\n", cBlocks, g_aTestStream[iTest].cBlocks);
    298283        }
    299284        else
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