- Timestamp:
- Oct 1, 2020 5:23:53 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/testcase/tstGuestCtrlParseBuffer.cpp
r82968 r86371 65 65 const char *pbData; 66 66 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; 70 70 int iResult; 71 } g_aTestBlock [] =71 } g_aTestBlocks[] = 72 72 { 73 73 /* … … 119 119 size_t cbData; 120 120 /** Number of data blocks retrieved. These are separated by "\0\0". */ 121 uint32_t uNumBlocks;121 uint32_t cBlocks; 122 122 /** Overall result when done parsing. */ 123 123 int iResult; 124 } g_aTestStream[] =124 } const g_aTestStream[] = 125 125 { 126 126 /* No blocks. */ … … 140 140 const char *pbData; 141 141 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; 145 145 int iResult; 146 } s_aTest[] =146 } const s_aTest[] = 147 147 { 148 148 { "test5=test5\0t51=t51", sizeof("test5=test5\0t51=t51"), 0, sizeof("test5=test5\0") - 1, 1, VERR_MORE_DATA }, … … 175 175 { 176 176 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; 180 180 RTTestBanner(hTest); 181 181 … … 195 195 196 196 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")); 198 198 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")); 200 200 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")); 202 202 203 203 RTTestIPrintf(RTTESTLVL_INFO, "Doing line tests ...\n"); … … 208 208 209 209 unsigned iTest; 210 for (iTest = 0; iTest < RT_ELEMENTS(g_aTestBlock ); iTest++)210 for (iTest = 0; iTest < RT_ELEMENTS(g_aTestBlocks); iTest++) 211 211 { 212 212 RTTestIPrintf(RTTESTLVL_DEBUG, "=> Test #%u\n", iTest); 213 213 214 214 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); 216 220 if (RT_SUCCESS(iResult)) 217 221 { 218 222 GuestProcessStreamBlock curBlock; 219 223 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); 230 228 else if (iResult == VERR_MORE_DATA) 231 {232 229 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) 240 233 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); 244 235 245 236 /* There is remaining data left in the buffer (which needs to be merged 246 237 * with a following buffer) -- print it. */ 247 238 size_t off = stream.GetOffset(); 248 size_t cbToWrite = g_aTestBlock [iTest].cbData - off;239 size_t cbToWrite = g_aTestBlocks[iTest].cbData - off; 249 240 if (cbToWrite) 250 241 { … … 254 245 * Hack alert: Using RTEnvGet for now. */ 255 246 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); 257 248 } 258 249 } … … 269 260 if (RT_SUCCESS(iResult)) 270 261 { 271 uint32_t uNumBlocks = 0;262 uint32_t cBlocks = 0; 272 263 uint8_t uSafeCouunter = 0; 273 264 do … … 280 271 /* Only count block which have at least one pair. */ 281 272 if (curBlock.GetCount()) 282 uNumBlocks++;273 cBlocks++; 283 274 } 284 275 if (uSafeCouunter++ > 32) … … 287 278 288 279 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); 298 283 } 299 284 else
Note:
See TracChangeset
for help on using the changeset viewer.