VirtualBox

Ignore:
Timestamp:
Aug 10, 2011 11:48:29 AM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
73430
Message:

GuestCtrl: Update.

File:
1 edited

Legend:

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

    r38269 r38395  
    5858} aTests[] =
    5959{
     60    /*
     61     * Single object parsing.
     62     * An object is represented by one or multiple key=value pairs which are
     63     * separated by a single "\0". If this termination is missing it will be assumed
     64     * that we need to collect more data to do a successful parsing.
     65     */
     66
    6067    /* Invalid stuff. */
    6168    { NULL,                             0,                                                 0,  0,                                         0, VERR_INVALID_POINTER },
     
    6673    { "foo=bar2",                       0,                                                 50, 50,                                        0, VERR_INVALID_PARAMETER },
    6774    /* Empty buffers. */
    68     { "",                               1,                                                 0,  1,                                         0, VERR_MORE_DATA },
    69     { "\0",                             1,                                                 0,  1,                                         0, VERR_MORE_DATA },
    70     /* Incomplete buffer (missing components). */
    71     { szUnterm1,                        5,                                                 0,  0,                                         0, VERR_MORE_DATA },
    72     { "foo1",                           sizeof("foo1"),                                    0,  0,                                         0, VERR_MORE_DATA },
    73     { "=bar\0",                         sizeof("=bar"),                                    0,  0,                                         0, VERR_MORE_DATA },
    74     /* Last sequence is incomplete -- new offset should point to it. */
    75     { "hug=sub\0incomplete",            sizeof("hug=sub\0incomplete"),                     0,  sizeof("hug=sub"),                         1, VERR_MORE_DATA },
    76     { "boo=hoo\0baz=boo\0qwer",         sizeof("boo=hoo\0baz=boo\0qwer"),                  0,  sizeof("boo=hoo\0baz=boo"),                2, VERR_MORE_DATA },
    77     /* Parsing good stuff. */
    78     { "novalue=",                       sizeof("novalue="),                                0,  sizeof("novalue="),                        1, VINF_SUCCESS },
    79     { szUnterm2,                        8,                                                 0,  sizeof(szUnterm2),                         1, VINF_SUCCESS },
    80     { "foo2=",                          sizeof("foo2="),                                   0,  sizeof("foo2="),                           1, VINF_SUCCESS },
    81     { "har=hor",                        sizeof("har=hor"),                                 0,  sizeof("har=hor"),                         1, VINF_SUCCESS },
    82     { "foo=bar\0baz=boo",               sizeof("foo=bar\0baz=boo"),                        0,  sizeof("foo=bar\0baz=boo"),                2, VINF_SUCCESS },
    83     /* Parsing until a different block (two terminations, returning offset to next block). */
    84     { "off=rab\0a=b\0\0\0\0",           sizeof("off=rab\0a=b\0\0\0"),                      0,  13,                                        2, VERR_MORE_DATA },
    85     { "off=rab\0\0zab=oob",             sizeof("off=rab\0\0zab=oob"),                      0,  9,                                         1, VERR_MORE_DATA },
    86     { "\0\0\0\0off=rab\0zab=oob\0\0",   sizeof("\0\0\0\0off=rab\0zab=oob\0\0"),            0,  1,                                         0, VERR_MORE_DATA },
    87     { "o2=r2\0z3=o3\0\0f3=g3",          sizeof("o2=r2\0z3=o3\0\0f3=g3"),                   0,  13,                                        2, VERR_MORE_DATA }
     75    { "",                               1,                                                 0,  1,                                         0, VINF_SUCCESS },
     76    { "\0",                             1,                                                 0,  1,                                         0, VINF_SUCCESS },
     77    /* Unterminated values (missing "\0"). */
     78    { "test1",                          sizeof("test1"),                                   0,  0,                                         0, VERR_MORE_DATA },
     79    { "test2=",                         sizeof("test2="),                                  0,  0,                                         0, VERR_MORE_DATA },
     80    { "test3=test3",                    sizeof("test3=test3"),                             0,  0,                                         0, VERR_MORE_DATA },
     81    { "test4=test4\0t41",               sizeof("test4=test4\0t41"),                        0,  sizeof("test4=test4\0") - 1,               1, VERR_MORE_DATA },
     82    { "test5=test5\0t51=t51",           sizeof("test5=test5\0t51=t51"),                    0,  sizeof("test5=test5\0") - 1,               1, VERR_MORE_DATA },
     83    /* Next block unterminated. */
     84    { "t51=t51\0t52=t52\0\0t53=t53",    sizeof("t51=t51\0t52=t52\0\0t53=t53"),             0,  sizeof("t51=t51\0t52=t52\0") - 1,          2, VINF_SUCCESS },
     85    { "test6=test6\0\0t61=t61",         sizeof("test6=test6\0\0t61=t61"),                  0,  sizeof("test6=test6\0") - 1,               1, VINF_SUCCESS },
     86    /* Good stuff. */
     87    { "test61=\0test611=test611\0",     sizeof("test61=\0test611=test611\0"),              0,  sizeof("test61=\0test611=test611\0") - 1,  2, VINF_SUCCESS },
     88    { "test7=test7\0\0",                sizeof("test7=test7\0\0"),                         0,  sizeof("test7=test7\0") - 1,               1, VINF_SUCCESS },
     89    { "test8=test8\0t81=t81\0\0",       sizeof("test8=test8\0t81=t81\0\0"),                0,  sizeof("test8=test8\0t81=t81\0") - 1,      2, VINF_SUCCESS },
     90    /* Good stuff, but with a second block -- should be *not* taken into account since
     91     * we're only interested in parsing/handling the first object. */
     92    { "t9=t9\0t91=t91\0\0t92=t92\0\0",  sizeof("t9=t9\0t91=t91\0\0t92=t92\0\0"),           0,  sizeof("t9=t9\0t91=t91\0") - 1,            2, VINF_SUCCESS }
    8893};
    8994
     
    98103} aTests2[] =
    99104{
    100     { "\0\0\0\0",                                      sizeof("\0\0\0\0"),                                0, VINF_SUCCESS },
    101     { "off=rab\0\0zab=oob",                            sizeof("off=rab\0\0zab=oob"),                      2, VINF_SUCCESS },
    102     { "\0\0\0soo=foo\0goo=loo\0\0zab=oob",             sizeof("\0\0\0soo=foo\0goo=loo\0\0zab=oob"),       2, VINF_SUCCESS },
    103     { "qoo=uoo\0\0\0\0asdf=\0\0",                      sizeof("qoo=uoo\0\0\0\0asdf=\0\0"),                2, VINF_SUCCESS },
    104     { "foo=bar\0\0\0\0\0\0",                           sizeof("foo=bar\0\0\0\0\0\0"),                     1, VINF_SUCCESS },
    105     { "qwer=cvbnr\0\0\0gui=uig\0\0\0",                 sizeof("qwer=cvbnr\0\0\0gui=uig\0\0\0"),           2, VINF_SUCCESS }
     105    /* No blocks. */
     106    { "\0\0\0\0",                                      sizeof("\0\0\0\0"),                                0, VERR_NO_DATA },
     107    /* Good stuff. */
     108    { "\0b1=b1\0\0",                                   sizeof("\0b1=b1\0\0"),                             1, VERR_NO_DATA },
     109    { "b1=b1\0\0",                                     sizeof("b1=b1\0\0"),                               1, VERR_NO_DATA },
     110    { "b1=b1\0b2=b2\0\0",                              sizeof("b1=b1\0b2=b2\0\0"),                        1, VERR_NO_DATA },
     111    { "b1=b1\0b2=b2\0\0\0",                            sizeof("b1=b1\0b2=b2\0\0\0"),                      1, VERR_NO_DATA }
    106112};
    107113
     
    136142    for (iTest; iTest < RT_ELEMENTS(aTests); iTest++)
    137143    {
    138         uint32_t uOffset = aTests[iTest].uOffsetStart;
    139 
    140144        RTTestIPrintf(RTTESTLVL_DEBUG, "=> Test #%u\n", iTest);
    141145
     
    144148        if (RT_SUCCESS(iResult))
    145149        {
    146             GuestProcessStreamBlock block;
    147             iResult = stream.ParseBlock(block);
     150            GuestProcessStreamBlock curBlock;
     151            iResult = stream.ParseBlock(curBlock);
    148152            if (iResult != aTests[iTest].iResult)
    149153            {
     
    151155                             iResult, aTests[iTest].iResult);
    152156            }
    153             else if (block.GetCount() != aTests[iTest].uMapElements)
    154             {
    155                 RTTestFailed(hTest, "\tMap has %u elements, expected %u",
    156                              block.GetCount(), aTests[iTest].uMapElements);
    157             }
    158157            else if (stream.GetOffset() != aTests[iTest].uOffsetAfter)
    159158            {
     
    163162            else if (iResult == VERR_MORE_DATA)
    164163            {
    165                 RTTestIPrintf(RTTESTLVL_DEBUG, "\tMore data (Offset: %u)\n", uOffset);
    166 
    167                 /* There is remaining data left in the buffer (which needs to be merged
    168                  * with a following buffer) -- print it. */
    169                 size_t uToWrite = aTests[iTest].cbData - uOffset;
    170                 if (uToWrite)
     164                RTTestIPrintf(RTTESTLVL_DEBUG, "\tMore data (Offset: %u)\n", stream.GetOffset());
     165            }
     166
     167            if (  (   RT_SUCCESS(iResult)
     168                   || iResult == VERR_MORE_DATA))
     169            {
     170                if (curBlock.GetCount() != aTests[iTest].uMapElements)
    171171                {
    172                     const char *pszRemaining = aTests[iTest].pbData;
    173                     RTTestIPrintf(RTTESTLVL_DEBUG, "\tRemaining (%u):\n", uToWrite);
    174                     RTStrmWriteEx(g_pStdOut, &aTests[iTest].pbData[uOffset], uToWrite - 1, NULL);
    175                     RTTestIPrintf(RTTESTLVL_DEBUG, "\n");
     172                    RTTestFailed(hTest, "\tMap has %u elements, expected %u",
     173                                 curBlock.GetCount(), aTests[iTest].uMapElements);
    176174                }
     175            }
     176
     177            /* There is remaining data left in the buffer (which needs to be merged
     178             * with a following buffer) -- print it. */
     179            uint32_t uOffset = stream.GetOffset();
     180            size_t uToWrite = aTests[iTest].cbData - uOffset;
     181            if (uToWrite)
     182            {
     183                const char *pszRemaining = aTests[iTest].pbData;
     184                RTTestIPrintf(RTTESTLVL_DEBUG, "\tRemaining (%u):\n", uToWrite);
     185                RTStrmWriteEx(g_pStdOut, &aTests[iTest].pbData[uOffset], uToWrite - 1, NULL);
    177186            }
    178187        }
     
    181190    RTTestIPrintf(RTTESTLVL_INFO, "Doing block tests ...\n");
    182191
    183     for (unsigned iTest = 0; iTest < RT_ELEMENTS(aTests2); iTest++)
     192    iTest = 0;
     193    for (iTest; iTest < RT_ELEMENTS(aTests2); iTest++)
    184194    {
    185195        RTTestIPrintf(RTTESTLVL_DEBUG, "=> Block test #%u\n", iTest);
     
    190200        {
    191201            uint32_t uNumBlocks = 0;
    192 
     202            uint8_t uSafeCouunter = 0;
    193203            do
    194204            {
    195                 GuestProcessStreamBlock block;
    196                 iResult = stream.ParseBlock(block);
     205                GuestProcessStreamBlock curBlock;
     206                iResult = stream.ParseBlock(curBlock);
    197207                RTTestIPrintf(RTTESTLVL_DEBUG, "\tReturned with %Rrc\n", iResult);
    198                 if (   iResult == VINF_SUCCESS
    199                         || iResult == VERR_MORE_DATA)
     208                if (RT_SUCCESS(iResult))
    200209                {
    201210                    /* Only count block which have at least one pair. */
    202                     if (block.GetCount())
     211                    if (curBlock.GetCount())
    203212                        uNumBlocks++;
    204213                }
    205                 if (uNumBlocks > 32)
    206                     break; /* Give up if unreasonable big. */
    207                 block.Clear();
    208             } while (iResult == VERR_MORE_DATA);
     214                if (uSafeCouunter++ > 32)
     215                    break;
     216            } while (RT_SUCCESS(iResult));
    209217
    210218            if (iResult != aTests2[iTest].iResult)
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