Index: /trunk/src/VBox/Main/testcase/tstGuestCtrlParseBuffer.cpp
===================================================================
--- /trunk/src/VBox/Main/testcase/tstGuestCtrlParseBuffer.cpp	(revision 39789)
+++ /trunk/src/VBox/Main/testcase/tstGuestCtrlParseBuffer.cpp	(revision 39790)
@@ -30,4 +30,5 @@
 #include <VBox/log.h>
 
+#include <iprt/env.h>
 #include <iprt/test.h>
 #include <iprt/stream.h>
@@ -56,5 +57,5 @@
     uint32_t    uMapElements;
     int         iResult;
-} aTests[] =
+} aTestBlock[] =
 {
     /*
@@ -64,5 +65,4 @@
      * that we need to collect more data to do a successful parsing.
      */
-
     /* Invalid stuff. */
     { NULL,                             0,                                                 0,  0,                                         0, VERR_INVALID_POINTER },
@@ -109,5 +109,5 @@
     /** Overall result when done parsing. */
     int         iResult;
-} aTests2[] =
+} aTestStream[] =
 {
     /* No blocks. */
@@ -120,4 +120,44 @@
 };
 
+int manualTest()
+{
+    int rc;
+    static struct
+    {
+        const char *pbData;
+        size_t      cbData;
+        uint32_t    uOffsetStart;
+        uint32_t    uOffsetAfter;
+        uint32_t    uMapElements;
+        int         iResult;
+    } aTest[] =
+    {
+        { "test5=test5\0t51=t51",           sizeof("test5=test5\0t51=t51"),                            0,  sizeof("test5=test5\0") - 1,                   1, VERR_MORE_DATA },
+        { "\0\0test5=test5\0t51=t51",       sizeof("\0\0test5=test5\0t51=t51"),                        0,  sizeof("\0\0test5=test5\0") - 1,               1, VERR_MORE_DATA },
+    };
+
+    int iTest = 0;
+    for (iTest; iTest < RT_ELEMENTS(aTest); iTest++)
+    {
+        RTTestIPrintf(RTTESTLVL_DEBUG, "Manual test #%d\n", iTest);
+
+        GuestProcessStream stream;
+        rc = stream.AddData((BYTE*)aTest[iTest].pbData, aTest[iTest].cbData);
+
+        for (;;)
+        {
+            GuestProcessStreamBlock block;
+            rc = stream.ParseBlock(block);
+            RTTestIPrintf(RTTESTLVL_DEBUG, "\tReturned with rc=%Rrc, numItems=%ld\n",
+                          rc, block.GetCount());
+
+            if (block.GetCount())
+                break;
+        }
+    }
+
+    return rc;
+}
+
 int main()
 {
@@ -129,10 +169,14 @@
 
     RTTestIPrintf(RTTESTLVL_DEBUG, "Initializing COM...\n");
-    rc = com::Initialize();
-    if (FAILED(rc))
-    {
-        RTPrintf("ERROR: failed to initialize COM!\n");
-        return rc;
+    HRESULT hrc = com::Initialize();
+    if (FAILED(hrc))
+    {
+        RTTestFailed(hTest, "Failed to initialize COM (%Rhrc)!\n", hrc);
+        return RTEXITCODE_FAILURE;
     }
+
+#ifdef DEBUG_andy
+    rc = manualTest();
+#endif
 
     RTTestIPrintf(RTTESTLVL_INFO, "Doing basic tests ...\n");
@@ -147,24 +191,28 @@
     RTTestIPrintf(RTTESTLVL_INFO, "Doing line tests ...\n");
 
+    /* Don't let the assertions trigger here
+     * -- we rely on the return values in the test(s) below. */
+    RTAssertSetQuiet(true);
+
     unsigned iTest = 0;
-    for (iTest; iTest < RT_ELEMENTS(aTests); iTest++)
+    for (iTest; iTest < RT_ELEMENTS(aTestBlock); iTest++)
     {
         RTTestIPrintf(RTTESTLVL_DEBUG, "=> Test #%u\n", iTest);
 
         GuestProcessStream stream;
-        int iResult = stream.AddData((BYTE*)aTests[iTest].pbData, aTests[iTest].cbData);
+        int iResult = stream.AddData((BYTE*)aTestBlock[iTest].pbData, aTestBlock[iTest].cbData);
         if (RT_SUCCESS(iResult))
         {
             GuestProcessStreamBlock curBlock;
             iResult = stream.ParseBlock(curBlock);
-            if (iResult != aTests[iTest].iResult)
+            if (iResult != aTestBlock[iTest].iResult)
             {
                 RTTestFailed(hTest, "\tReturned %Rrc, expected %Rrc",
-                             iResult, aTests[iTest].iResult);
-            }
-            else if (stream.GetOffset() != aTests[iTest].uOffsetAfter)
+                             iResult, aTestBlock[iTest].iResult);
+            }
+            else if (stream.GetOffset() != aTestBlock[iTest].uOffsetAfter)
             {
                 RTTestFailed(hTest, "\tOffset %u wrong, expected %u",
-                             stream.GetOffset(), aTests[iTest].uOffsetAfter);
+                             stream.GetOffset(), aTestBlock[iTest].uOffsetAfter);
             }
             else if (iResult == VERR_MORE_DATA)
@@ -176,8 +224,8 @@
                    || iResult == VERR_MORE_DATA))
             {
-                if (curBlock.GetCount() != aTests[iTest].uMapElements)
+                if (curBlock.GetCount() != aTestBlock[iTest].uMapElements)
                 {
                     RTTestFailed(hTest, "\tMap has %u elements, expected %u",
-                                 curBlock.GetCount(), aTests[iTest].uMapElements);
+                                 curBlock.GetCount(), aTestBlock[iTest].uMapElements);
                 }
             }
@@ -186,10 +234,14 @@
              * with a following buffer) -- print it. */
             uint32_t uOffset = stream.GetOffset();
-            size_t uToWrite = aTests[iTest].cbData - uOffset;
+            size_t uToWrite = aTestBlock[iTest].cbData - uOffset;
             if (uToWrite)
             {
-                const char *pszRemaining = aTests[iTest].pbData;
+                const char *pszRemaining = aTestBlock[iTest].pbData;
                 RTTestIPrintf(RTTESTLVL_DEBUG, "\tRemaining (%u):\n", uToWrite);
-                RTStrmWriteEx(g_pStdOut, &aTests[iTest].pbData[uOffset], uToWrite - 1, NULL);
+
+                /* How to properly get the current RTTESTLVL (aka IPRT_TEST_MAX_LEVEL) here?
+                 * Hack alert: Using RTEnvGet for now. */
+                if (!RTStrICmp(RTEnvGet("IPRT_TEST_MAX_LEVEL"), "debug"))
+                    RTStrmWriteEx(g_pStdOut, &aTestBlock[iTest].pbData[uOffset], uToWrite - 1, NULL);
             }
         }
@@ -199,10 +251,10 @@
 
     iTest = 0;
-    for (iTest; iTest < RT_ELEMENTS(aTests2); iTest++)
+    for (iTest; iTest < RT_ELEMENTS(aTestStream); iTest++)
     {
         RTTestIPrintf(RTTESTLVL_DEBUG, "=> Block test #%u\n", iTest);
 
         GuestProcessStream stream;
-        int iResult = stream.AddData((BYTE*)aTests2[iTest].pbData, aTests2[iTest].cbData);
+        int iResult = stream.AddData((BYTE*)aTestStream[iTest].pbData, aTestStream[iTest].cbData);
         if (RT_SUCCESS(iResult))
         {
@@ -224,13 +276,13 @@
             } while (RT_SUCCESS(iResult));
 
-            if (iResult != aTests2[iTest].iResult)
+            if (iResult != aTestStream[iTest].iResult)
             {
                 RTTestFailed(hTest, "\tReturned %Rrc, expected %Rrc",
-                             iResult, aTests2[iTest].iResult);
-            }
-            else if (uNumBlocks != aTests2[iTest].uNumBlocks)
+                             iResult, aTestStream[iTest].iResult);
+            }
+            else if (uNumBlocks != aTestStream[iTest].uNumBlocks)
             {
                 RTTestFailed(hTest, "\tReturned %u blocks, expected %u\n",
-                             uNumBlocks, aTests2[iTest].uNumBlocks);
+                             uNumBlocks, aTestStream[iTest].uNumBlocks);
             }
         }
