Changeset 38395 in vbox for trunk/src/VBox/Main/testcase/tstGuestCtrlParseBuffer.cpp
- Timestamp:
- Aug 10, 2011 11:48:29 AM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 73430
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/testcase/tstGuestCtrlParseBuffer.cpp
r38269 r38395 58 58 } aTests[] = 59 59 { 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 60 67 /* Invalid stuff. */ 61 68 { NULL, 0, 0, 0, 0, VERR_INVALID_POINTER }, … … 66 73 { "foo=bar2", 0, 50, 50, 0, VERR_INVALID_PARAMETER }, 67 74 /* 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 } 88 93 }; 89 94 … … 98 103 } aTests2[] = 99 104 { 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 } 106 112 }; 107 113 … … 136 142 for (iTest; iTest < RT_ELEMENTS(aTests); iTest++) 137 143 { 138 uint32_t uOffset = aTests[iTest].uOffsetStart;139 140 144 RTTestIPrintf(RTTESTLVL_DEBUG, "=> Test #%u\n", iTest); 141 145 … … 144 148 if (RT_SUCCESS(iResult)) 145 149 { 146 GuestProcessStreamBlock block;147 iResult = stream.ParseBlock( block);150 GuestProcessStreamBlock curBlock; 151 iResult = stream.ParseBlock(curBlock); 148 152 if (iResult != aTests[iTest].iResult) 149 153 { … … 151 155 iResult, aTests[iTest].iResult); 152 156 } 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 }158 157 else if (stream.GetOffset() != aTests[iTest].uOffsetAfter) 159 158 { … … 163 162 else if (iResult == VERR_MORE_DATA) 164 163 { 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) 171 171 { 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); 176 174 } 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); 177 186 } 178 187 } … … 181 190 RTTestIPrintf(RTTESTLVL_INFO, "Doing block tests ...\n"); 182 191 183 for (unsigned iTest = 0; iTest < RT_ELEMENTS(aTests2); iTest++) 192 iTest = 0; 193 for (iTest; iTest < RT_ELEMENTS(aTests2); iTest++) 184 194 { 185 195 RTTestIPrintf(RTTESTLVL_DEBUG, "=> Block test #%u\n", iTest); … … 190 200 { 191 201 uint32_t uNumBlocks = 0; 192 202 uint8_t uSafeCouunter = 0; 193 203 do 194 204 { 195 GuestProcessStreamBlock block;196 iResult = stream.ParseBlock( block);205 GuestProcessStreamBlock curBlock; 206 iResult = stream.ParseBlock(curBlock); 197 207 RTTestIPrintf(RTTESTLVL_DEBUG, "\tReturned with %Rrc\n", iResult); 198 if ( iResult == VINF_SUCCESS 199 || iResult == VERR_MORE_DATA) 208 if (RT_SUCCESS(iResult)) 200 209 { 201 210 /* Only count block which have at least one pair. */ 202 if ( block.GetCount())211 if (curBlock.GetCount()) 203 212 uNumBlocks++; 204 213 } 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)); 209 217 210 218 if (iResult != aTests2[iTest].iResult)
Note:
See TracChangeset
for help on using the changeset viewer.