VirtualBox

Changeset 39790 in vbox


Ignore:
Timestamp:
Jan 18, 2012 10:48:43 AM (13 years ago)
Author:
vboxsync
Message:

tstGuestCtrlParseBuffer: Added routine for manual testing, some renaming and logging adjustments; fixed COM return value.

File:
1 edited

Legend:

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

    r38611 r39790  
    3030#include <VBox/log.h>
    3131
     32#include <iprt/env.h>
    3233#include <iprt/test.h>
    3334#include <iprt/stream.h>
     
    5657    uint32_t    uMapElements;
    5758    int         iResult;
    58 } aTests[] =
     59} aTestBlock[] =
    5960{
    6061    /*
     
    6465     * that we need to collect more data to do a successful parsing.
    6566     */
    66 
    6767    /* Invalid stuff. */
    6868    { NULL,                             0,                                                 0,  0,                                         0, VERR_INVALID_POINTER },
     
    109109    /** Overall result when done parsing. */
    110110    int         iResult;
    111 } aTests2[] =
     111} aTestStream[] =
    112112{
    113113    /* No blocks. */
     
    120120};
    121121
     122int manualTest()
     123{
     124    int rc;
     125    static struct
     126    {
     127        const char *pbData;
     128        size_t      cbData;
     129        uint32_t    uOffsetStart;
     130        uint32_t    uOffsetAfter;
     131        uint32_t    uMapElements;
     132        int         iResult;
     133    } aTest[] =
     134    {
     135        { "test5=test5\0t51=t51",           sizeof("test5=test5\0t51=t51"),                            0,  sizeof("test5=test5\0") - 1,                   1, VERR_MORE_DATA },
     136        { "\0\0test5=test5\0t51=t51",       sizeof("\0\0test5=test5\0t51=t51"),                        0,  sizeof("\0\0test5=test5\0") - 1,               1, VERR_MORE_DATA },
     137    };
     138
     139    int iTest = 0;
     140    for (iTest; iTest < RT_ELEMENTS(aTest); iTest++)
     141    {
     142        RTTestIPrintf(RTTESTLVL_DEBUG, "Manual test #%d\n", iTest);
     143
     144        GuestProcessStream stream;
     145        rc = stream.AddData((BYTE*)aTest[iTest].pbData, aTest[iTest].cbData);
     146
     147        for (;;)
     148        {
     149            GuestProcessStreamBlock block;
     150            rc = stream.ParseBlock(block);
     151            RTTestIPrintf(RTTESTLVL_DEBUG, "\tReturned with rc=%Rrc, numItems=%ld\n",
     152                          rc, block.GetCount());
     153
     154            if (block.GetCount())
     155                break;
     156        }
     157    }
     158
     159    return rc;
     160}
     161
    122162int main()
    123163{
     
    129169
    130170    RTTestIPrintf(RTTESTLVL_DEBUG, "Initializing COM...\n");
    131     rc = com::Initialize();
    132     if (FAILED(rc))
    133     {
    134         RTPrintf("ERROR: failed to initialize COM!\n");
    135         return rc;
     171    HRESULT hrc = com::Initialize();
     172    if (FAILED(hrc))
     173    {
     174        RTTestFailed(hTest, "Failed to initialize COM (%Rhrc)!\n", hrc);
     175        return RTEXITCODE_FAILURE;
    136176    }
     177
     178#ifdef DEBUG_andy
     179    rc = manualTest();
     180#endif
    137181
    138182    RTTestIPrintf(RTTESTLVL_INFO, "Doing basic tests ...\n");
     
    147191    RTTestIPrintf(RTTESTLVL_INFO, "Doing line tests ...\n");
    148192
     193    /* Don't let the assertions trigger here
     194     * -- we rely on the return values in the test(s) below. */
     195    RTAssertSetQuiet(true);
     196
    149197    unsigned iTest = 0;
    150     for (iTest; iTest < RT_ELEMENTS(aTests); iTest++)
     198    for (iTest; iTest < RT_ELEMENTS(aTestBlock); iTest++)
    151199    {
    152200        RTTestIPrintf(RTTESTLVL_DEBUG, "=> Test #%u\n", iTest);
    153201
    154202        GuestProcessStream stream;
    155         int iResult = stream.AddData((BYTE*)aTests[iTest].pbData, aTests[iTest].cbData);
     203        int iResult = stream.AddData((BYTE*)aTestBlock[iTest].pbData, aTestBlock[iTest].cbData);
    156204        if (RT_SUCCESS(iResult))
    157205        {
    158206            GuestProcessStreamBlock curBlock;
    159207            iResult = stream.ParseBlock(curBlock);
    160             if (iResult != aTests[iTest].iResult)
     208            if (iResult != aTestBlock[iTest].iResult)
    161209            {
    162210                RTTestFailed(hTest, "\tReturned %Rrc, expected %Rrc",
    163                              iResult, aTests[iTest].iResult);
    164             }
    165             else if (stream.GetOffset() != aTests[iTest].uOffsetAfter)
     211                             iResult, aTestBlock[iTest].iResult);
     212            }
     213            else if (stream.GetOffset() != aTestBlock[iTest].uOffsetAfter)
    166214            {
    167215                RTTestFailed(hTest, "\tOffset %u wrong, expected %u",
    168                              stream.GetOffset(), aTests[iTest].uOffsetAfter);
     216                             stream.GetOffset(), aTestBlock[iTest].uOffsetAfter);
    169217            }
    170218            else if (iResult == VERR_MORE_DATA)
     
    176224                   || iResult == VERR_MORE_DATA))
    177225            {
    178                 if (curBlock.GetCount() != aTests[iTest].uMapElements)
     226                if (curBlock.GetCount() != aTestBlock[iTest].uMapElements)
    179227                {
    180228                    RTTestFailed(hTest, "\tMap has %u elements, expected %u",
    181                                  curBlock.GetCount(), aTests[iTest].uMapElements);
     229                                 curBlock.GetCount(), aTestBlock[iTest].uMapElements);
    182230                }
    183231            }
     
    186234             * with a following buffer) -- print it. */
    187235            uint32_t uOffset = stream.GetOffset();
    188             size_t uToWrite = aTests[iTest].cbData - uOffset;
     236            size_t uToWrite = aTestBlock[iTest].cbData - uOffset;
    189237            if (uToWrite)
    190238            {
    191                 const char *pszRemaining = aTests[iTest].pbData;
     239                const char *pszRemaining = aTestBlock[iTest].pbData;
    192240                RTTestIPrintf(RTTESTLVL_DEBUG, "\tRemaining (%u):\n", uToWrite);
    193                 RTStrmWriteEx(g_pStdOut, &aTests[iTest].pbData[uOffset], uToWrite - 1, NULL);
     241
     242                /* How to properly get the current RTTESTLVL (aka IPRT_TEST_MAX_LEVEL) here?
     243                 * Hack alert: Using RTEnvGet for now. */
     244                if (!RTStrICmp(RTEnvGet("IPRT_TEST_MAX_LEVEL"), "debug"))
     245                    RTStrmWriteEx(g_pStdOut, &aTestBlock[iTest].pbData[uOffset], uToWrite - 1, NULL);
    194246            }
    195247        }
     
    199251
    200252    iTest = 0;
    201     for (iTest; iTest < RT_ELEMENTS(aTests2); iTest++)
     253    for (iTest; iTest < RT_ELEMENTS(aTestStream); iTest++)
    202254    {
    203255        RTTestIPrintf(RTTESTLVL_DEBUG, "=> Block test #%u\n", iTest);
    204256
    205257        GuestProcessStream stream;
    206         int iResult = stream.AddData((BYTE*)aTests2[iTest].pbData, aTests2[iTest].cbData);
     258        int iResult = stream.AddData((BYTE*)aTestStream[iTest].pbData, aTestStream[iTest].cbData);
    207259        if (RT_SUCCESS(iResult))
    208260        {
     
    224276            } while (RT_SUCCESS(iResult));
    225277
    226             if (iResult != aTests2[iTest].iResult)
     278            if (iResult != aTestStream[iTest].iResult)
    227279            {
    228280                RTTestFailed(hTest, "\tReturned %Rrc, expected %Rrc",
    229                              iResult, aTests2[iTest].iResult);
    230             }
    231             else if (uNumBlocks != aTests2[iTest].uNumBlocks)
     281                             iResult, aTestStream[iTest].iResult);
     282            }
     283            else if (uNumBlocks != aTestStream[iTest].uNumBlocks)
    232284            {
    233285                RTTestFailed(hTest, "\tReturned %u blocks, expected %u\n",
    234                              uNumBlocks, aTests2[iTest].uNumBlocks);
     286                             uNumBlocks, aTestStream[iTest].uNumBlocks);
    235287            }
    236288        }
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