Changeset 39790 in vbox
- Timestamp:
- Jan 18, 2012 10:48:43 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/testcase/tstGuestCtrlParseBuffer.cpp
r38611 r39790 30 30 #include <VBox/log.h> 31 31 32 #include <iprt/env.h> 32 33 #include <iprt/test.h> 33 34 #include <iprt/stream.h> … … 56 57 uint32_t uMapElements; 57 58 int iResult; 58 } aTest s[] =59 } aTestBlock[] = 59 60 { 60 61 /* … … 64 65 * that we need to collect more data to do a successful parsing. 65 66 */ 66 67 67 /* Invalid stuff. */ 68 68 { NULL, 0, 0, 0, 0, VERR_INVALID_POINTER }, … … 109 109 /** Overall result when done parsing. */ 110 110 int iResult; 111 } aTest s2[] =111 } aTestStream[] = 112 112 { 113 113 /* No blocks. */ … … 120 120 }; 121 121 122 int 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 122 162 int main() 123 163 { … … 129 169 130 170 RTTestIPrintf(RTTESTLVL_DEBUG, "Initializing COM...\n"); 131 rc = com::Initialize();132 if (FAILED( rc))133 { 134 RT Printf("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; 136 176 } 177 178 #ifdef DEBUG_andy 179 rc = manualTest(); 180 #endif 137 181 138 182 RTTestIPrintf(RTTESTLVL_INFO, "Doing basic tests ...\n"); … … 147 191 RTTestIPrintf(RTTESTLVL_INFO, "Doing line tests ...\n"); 148 192 193 /* Don't let the assertions trigger here 194 * -- we rely on the return values in the test(s) below. */ 195 RTAssertSetQuiet(true); 196 149 197 unsigned iTest = 0; 150 for (iTest; iTest < RT_ELEMENTS(aTest s); iTest++)198 for (iTest; iTest < RT_ELEMENTS(aTestBlock); iTest++) 151 199 { 152 200 RTTestIPrintf(RTTESTLVL_DEBUG, "=> Test #%u\n", iTest); 153 201 154 202 GuestProcessStream stream; 155 int iResult = stream.AddData((BYTE*)aTest s[iTest].pbData, aTests[iTest].cbData);203 int iResult = stream.AddData((BYTE*)aTestBlock[iTest].pbData, aTestBlock[iTest].cbData); 156 204 if (RT_SUCCESS(iResult)) 157 205 { 158 206 GuestProcessStreamBlock curBlock; 159 207 iResult = stream.ParseBlock(curBlock); 160 if (iResult != aTest s[iTest].iResult)208 if (iResult != aTestBlock[iTest].iResult) 161 209 { 162 210 RTTestFailed(hTest, "\tReturned %Rrc, expected %Rrc", 163 iResult, aTest s[iTest].iResult);164 } 165 else if (stream.GetOffset() != aTest s[iTest].uOffsetAfter)211 iResult, aTestBlock[iTest].iResult); 212 } 213 else if (stream.GetOffset() != aTestBlock[iTest].uOffsetAfter) 166 214 { 167 215 RTTestFailed(hTest, "\tOffset %u wrong, expected %u", 168 stream.GetOffset(), aTest s[iTest].uOffsetAfter);216 stream.GetOffset(), aTestBlock[iTest].uOffsetAfter); 169 217 } 170 218 else if (iResult == VERR_MORE_DATA) … … 176 224 || iResult == VERR_MORE_DATA)) 177 225 { 178 if (curBlock.GetCount() != aTest s[iTest].uMapElements)226 if (curBlock.GetCount() != aTestBlock[iTest].uMapElements) 179 227 { 180 228 RTTestFailed(hTest, "\tMap has %u elements, expected %u", 181 curBlock.GetCount(), aTest s[iTest].uMapElements);229 curBlock.GetCount(), aTestBlock[iTest].uMapElements); 182 230 } 183 231 } … … 186 234 * with a following buffer) -- print it. */ 187 235 uint32_t uOffset = stream.GetOffset(); 188 size_t uToWrite = aTest s[iTest].cbData - uOffset;236 size_t uToWrite = aTestBlock[iTest].cbData - uOffset; 189 237 if (uToWrite) 190 238 { 191 const char *pszRemaining = aTest s[iTest].pbData;239 const char *pszRemaining = aTestBlock[iTest].pbData; 192 240 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); 194 246 } 195 247 } … … 199 251 200 252 iTest = 0; 201 for (iTest; iTest < RT_ELEMENTS(aTest s2); iTest++)253 for (iTest; iTest < RT_ELEMENTS(aTestStream); iTest++) 202 254 { 203 255 RTTestIPrintf(RTTESTLVL_DEBUG, "=> Block test #%u\n", iTest); 204 256 205 257 GuestProcessStream stream; 206 int iResult = stream.AddData((BYTE*)aTest s2[iTest].pbData, aTests2[iTest].cbData);258 int iResult = stream.AddData((BYTE*)aTestStream[iTest].pbData, aTestStream[iTest].cbData); 207 259 if (RT_SUCCESS(iResult)) 208 260 { … … 224 276 } while (RT_SUCCESS(iResult)); 225 277 226 if (iResult != aTest s2[iTest].iResult)278 if (iResult != aTestStream[iTest].iResult) 227 279 { 228 280 RTTestFailed(hTest, "\tReturned %Rrc, expected %Rrc", 229 iResult, aTest s2[iTest].iResult);230 } 231 else if (uNumBlocks != aTest s2[iTest].uNumBlocks)281 iResult, aTestStream[iTest].iResult); 282 } 283 else if (uNumBlocks != aTestStream[iTest].uNumBlocks) 232 284 { 233 285 RTTestFailed(hTest, "\tReturned %u blocks, expected %u\n", 234 uNumBlocks, aTest s2[iTest].uNumBlocks);286 uNumBlocks, aTestStream[iTest].uNumBlocks); 235 287 } 236 288 }
Note:
See TracChangeset
for help on using the changeset viewer.

