- Timestamp:
- Jul 15, 2011 9:46:23 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/testcase/tstGuestCtrlParseBuffer.cpp
r37903 r37974 40 40 typedef std::map< RTCString, VBOXGUESTCTRL_BUFFER_VALUE >::const_iterator GuestBufferMapIterConst; 41 41 42 char pszUnterm1[] = { 'a', 's', 'd', 'f' };43 char pszUnterm2[] = { 'f', 'o', 'o', '3', '=', 'b', 'a', 'r', '3' };42 char szUnterm1[] = { 'a', 's', 'd', 'f' }; 43 char szUnterm2[] = { 'f', 'o', 'o', '3', '=', 'b', 'a', 'r', '3' }; 44 44 45 45 static struct … … 63 63 { "", 1, 0, 0, 0, VERR_MORE_DATA }, 64 64 { "\0", 1, 0, 0, 0, VERR_MORE_DATA }, 65 { pszUnterm1,5, 0, 0, 0, VERR_MORE_DATA },65 { szUnterm1, 5, 0, 0, 0, VERR_MORE_DATA }, 66 66 { "foo1", sizeof("foo1"), 0, 0, 0, VERR_MORE_DATA }, 67 { pszUnterm2,8, 0, 0, 0, VERR_MORE_DATA },67 { szUnterm2, 8, 0, 0, 0, VERR_MORE_DATA }, 68 68 /* Incomplete buffer (missing components). */ 69 69 { "=bar\0", sizeof("=bar"), 0, 0, 0, VERR_MORE_DATA }, … … 79 79 }; 80 80 81 static struct 82 { 83 const char *pbData; 84 size_t cbData; 85 /** Number of data blocks retrieved. These are separated by "\0\0". */ 86 uint32_t uNumBlocks; 87 /** Overall result when done parsing. */ 88 int iResult; 89 } aTests2[] = 90 { 91 { "off=rab\0\0zab=oob", sizeof("off=rab\0\0zab=oob"), 2, VINF_SUCCESS }, 92 { "\0\0\0soo=foo\0goo=loo\0\0zab=oob", sizeof("\0\0\0soo=foo\0goo=loo\0\0zab=oob"), 2, VINF_SUCCESS }, 93 { "qoo=uoo\0\0\0\0asdf=\0\0", sizeof("qoo=uoo\0\0\0\0asdf=\0\0"), 2, VINF_SUCCESS }, 94 { "foo=bar\0\0\0\0\0\0", sizeof("foo=bar\0\0\0\0\0\0"), 1, VINF_SUCCESS } 95 }; 96 81 97 int outputBufferParse(const BYTE *pbData, size_t cbData, uint32_t *puOffset, GuestBufferMap& mapBuf) 82 98 { … … 165 181 } 166 182 183 void tstOutputAndDestroyMap(GuestBufferMap &bufMap) 184 { 185 for (GuestBufferMapIter it = bufMap.begin(); it != bufMap.end(); it++) 186 { 187 RTTestIPrintf(RTTESTLVL_DEBUG, "\t%s -> %s\n", 188 it->first.c_str(), it->second.pszValue ? it->second.pszValue : "<undefined>"); 189 190 if (it->second.pszValue) 191 RTMemFree(it->second.pszValue); 192 } 193 194 bufMap.clear(); 195 } 196 167 197 int main() 168 198 { … … 173 203 RTTestBanner(hTest); 174 204 205 RTTestIPrintf(RTTESTLVL_INFO, "Doing basic tests ...\n"); 206 175 207 if (sizeof("sizecheck") != 10) 176 208 RTTestFailed(hTest, "Basic size test failed (%u <-> 10)", sizeof("sizecheck")); 209 210 RTTestIPrintf(RTTESTLVL_INFO, "Doing line tests ...\n"); 177 211 178 212 for (unsigned iTest = 0; iTest < RT_ELEMENTS(aTests); iTest++) … … 215 249 } 216 250 217 for (GuestBufferMapIter it = bufMap.begin(); it != bufMap.end(); it++) 218 { 219 RTTestIPrintf(RTTESTLVL_DEBUG, "\t%s -> %s\n", 220 it->first.c_str(), it->second.pszValue ? it->second.pszValue : "<undefined>"); 221 222 if (it->second.pszValue) 223 RTMemFree(it->second.pszValue); 251 tstOutputAndDestroyMap(bufMap); 252 } 253 254 RTTestIPrintf(RTTESTLVL_INFO, "Doing block tests ...\n"); 255 256 for (unsigned iTest = 0; iTest < RT_ELEMENTS(aTests2); iTest++) 257 { 258 RTTestIPrintf(RTTESTLVL_DEBUG, "=> Block test #%u\n", iTest); 259 260 int iResult; 261 262 GuestBufferMap bufMap; 263 uint32_t uOffset = 0; 264 uint32_t uNumBlocks = 0; 265 266 while (uOffset < aTests2[iTest].cbData) 267 { 268 iResult = outputBufferParse((BYTE*)aTests2[iTest].pbData, aTests2[iTest].cbData, 269 &uOffset, bufMap); 270 RTTestIPrintf(RTTESTLVL_DEBUG, "\tReturned with %Rrc\n", iResult); 271 if ( iResult == VINF_SUCCESS 272 || iResult == VERR_MORE_DATA) 273 { 274 if (bufMap.size()) /* Only count block which have some valid data. */ 275 uNumBlocks++; 276 277 tstOutputAndDestroyMap(bufMap); 278 279 RTTestIPrintf(RTTESTLVL_DEBUG, "\tNext offset %u (total: %u)\n", 280 uOffset, aTests2[iTest].cbData); 281 uOffset++; 282 } 283 else 284 break; 285 286 if (uNumBlocks > 32) 287 break; /* Give up if unreasonable big. */ 288 } 289 290 if (uNumBlocks != aTests2[iTest].uNumBlocks) 291 { 292 RTTestFailed(hTest, "\tReturned %u blocks, expected %u\n", 293 uNumBlocks, aTests2[iTest].uNumBlocks); 224 294 } 225 295 }
Note:
See TracChangeset
for help on using the changeset viewer.