Changeset 38210 in vbox for trunk/src/VBox/Main/testcase
- Timestamp:
- Jul 28, 2011 8:42:59 AM (13 years ago)
- Location:
- trunk/src/VBox/Main/testcase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/testcase/Makefile.kmk
r37883 r38210 23 23 # 24 24 ifndef VBOX_ONLY_SDK 25 if defined(VBOX_WITH_TESTCASES) || "$(USERNAME)" == "umoeller"25 if defined(VBOX_WITH_TESTCASES) 26 26 PROGRAMS += \ 27 27 tstAPI \ … … 69 69 endif 70 70 71 71 72 # 72 73 # tstOVF … … 97 98 ovf-winxp-vbox-sharedfolders/winxp.ovf=>ovf-winxp-vbox-sharedfolders/winxp.ovf 98 99 endif 100 99 101 100 102 # … … 144 146 tstCollector_LDFLAGS.win += psapi.lib powrprof.lib 145 147 148 146 149 # 147 150 # tstGuestCtrlParseBuffer 148 151 # 149 tstGuestCtrlParseBuffer_TEMPLATE = VBOXR3TSTNPEXE 150 tstGuestCtrlParseBuffer_SOURCES = tstGuestCtrlParseBuffer.cpp 152 tstGuestCtrlParseBuffer_TEMPLATE = VBOXMAINCLIENTEXE 153 tstGuestCtrlParseBuffer_SOURCES = \ 154 tstGuestCtrlParseBuffer.cpp \ 155 ../src-client/GuestCtrlIO.cpp 156 tstGuestCtrlParseBuffer_INCS = ../include 157 ifeq ($(KBUILD_TARGET),win) ## @todo just add this to the template. 158 tstGuestCtrlParseBuffer_DEPS = $(VBOX_PATH_SDK)/bindings/mscom/include/VirtualBox.h 159 else 160 tstGuestCtrlParseBuffer_DEPS = $(VBOX_PATH_SDK)/bindings/xpcom/include/VirtualBox_XPCOM.h 161 endif 162 151 163 152 164 # -
trunk/src/VBox/Main/testcase/tstGuestCtrlParseBuffer.cpp
r38085 r38210 18 18 */ 19 19 20 #include <map> 21 22 #include <iprt/string.h> 23 #include <iprt/cpp/ministring.h> 20 #include <stdio.h> 21 #include <stdlib.h> 22 23 #include "../include/GuestCtrlImplPrivate.h" 24 25 using namespace com; 26 27 #define LOG_ENABLED 28 #define LOG_GROUP LOG_GROUP_MAIN 29 #define LOG_INSTANCE NULL 30 #include <VBox/log.h> 24 31 25 32 #include <iprt/test.h> … … 29 36 # define BYTE uint8_t 30 37 #endif 31 32 /** @todo Use original source of GuestCtrlImpl.cpp! */33 38 34 39 typedef struct VBOXGUESTCTRL_BUFFER_VALUE … … 101 106 }; 102 107 103 int outputBufferParse(const BYTE *pbData, size_t cbData, uint32_t *puOffset, GuestBufferMap& mapBuf)104 {105 AssertPtrReturn(pbData, VERR_INVALID_POINTER);106 AssertReturn(cbData, VERR_INVALID_PARAMETER);107 AssertPtrReturn(puOffset, VERR_INVALID_POINTER);108 AssertReturn(*puOffset < cbData, VERR_INVALID_PARAMETER);109 110 int rc = VINF_SUCCESS;111 112 size_t uCur = *puOffset;113 for (;uCur < cbData;)114 {115 const char *pszStart = (char*)&pbData[uCur];116 const char *pszEnd = pszStart;117 118 /* Search end of current pair (key=value\0). */119 while (uCur++ < cbData)120 {121 if (*pszEnd == '\0')122 break;123 pszEnd++;124 }125 126 size_t uPairLen = pszEnd - pszStart;127 if (uPairLen)128 {129 const char *pszSep = pszStart;130 while ( *pszSep != '='131 && pszSep != pszEnd)132 {133 pszSep++;134 }135 136 /* No separator found (or incomplete key=value pair)? */137 if ( pszSep == pszStart138 || pszSep == pszEnd)139 {140 *puOffset = uCur - uPairLen - 1;141 rc = VERR_MORE_DATA;142 }143 144 if (RT_FAILURE(rc))145 break;146 147 size_t uKeyLen = pszSep - pszStart;148 size_t uValLen = pszEnd - (pszSep + 1);149 150 /* Get key (if present). */151 if (uKeyLen)152 {153 Assert(pszSep > pszStart);154 char *pszKey = (char*)RTMemAllocZ(uKeyLen + 1);155 if (!pszKey)156 {157 rc = VERR_NO_MEMORY;158 break;159 }160 memcpy(pszKey, pszStart, uKeyLen);161 162 mapBuf[RTCString(pszKey)].pszValue = NULL;163 164 /* Get value (if present). */165 if (uValLen)166 {167 Assert(pszEnd > pszSep);168 char *pszVal = (char*)RTMemAllocZ(uValLen + 1);169 if (!pszVal)170 {171 rc = VERR_NO_MEMORY;172 break;173 }174 memcpy(pszVal, pszSep + 1, uValLen);175 176 mapBuf[RTCString(pszKey)].pszValue = pszVal;177 }178 179 RTMemFree(pszKey);180 181 *puOffset += uCur - *puOffset;182 }183 }184 else /* No pair detected, check for a new block. */185 {186 do187 {188 if (*pszEnd == '\0')189 {190 *puOffset = uCur;191 rc = VERR_MORE_DATA;192 break;193 }194 pszEnd++;195 } while (++uCur < cbData);196 }197 198 if (RT_FAILURE(rc))199 break;200 }201 202 RT_CLAMP(*puOffset, 0, cbData);203 204 return rc;205 }206 207 void tstOutputAndDestroyMap(GuestBufferMap &bufMap)208 {209 for (GuestBufferMapIter it = bufMap.begin(); it != bufMap.end(); it++)210 {211 RTTestIPrintf(RTTESTLVL_DEBUG, "\t%s -> %s\n",212 it->first.c_str(), it->second.pszValue ? it->second.pszValue : "<undefined>");213 214 if (it->second.pszValue)215 RTMemFree(it->second.pszValue);216 }217 218 bufMap.clear();219 }220 221 108 int main() 222 109 { … … 226 113 return rc; 227 114 RTTestBanner(hTest); 115 116 RTPrintf("Initializing COM...\n"); 117 rc = com::Initialize(); 118 if (FAILED(rc)) 119 { 120 RTPrintf("ERROR: failed to initialize COM!\n"); 121 return rc; 122 } 228 123 229 124 RTTestIPrintf(RTTESTLVL_INFO, "Doing basic tests ...\n"); … … 241 136 for (iTest; iTest < RT_ELEMENTS(aTests); iTest++) 242 137 { 243 GuestBufferMap bufMap;244 138 uint32_t uOffset = aTests[iTest].uOffsetStart; 245 139 246 int iResult = outputBufferParse((BYTE*)aTests[iTest].pbData, aTests[iTest].cbData,247 &uOffset, bufMap);248 249 140 RTTestIPrintf(RTTESTLVL_DEBUG, "=> Test #%u\n", iTest); 141 142 GuestProcessStream stream; 143 int iResult = stream.AddData((BYTE*)aTests[iTest].pbData, aTests[iTest].cbData); 144 if (RT_FAILURE(iResult)) 145 { 146 RTTestFailed(hTest, "\tAdding data returned %Rrc, expected VINF_SUCCESS", 147 iResult); 148 continue; 149 } 150 151 iResult = stream.Parse(); 250 152 251 153 if (iResult != aTests[iTest].iResult) … … 254 156 iResult, aTests[iTest].iResult); 255 157 } 256 else if ( bufMap.size() != aTests[iTest].uMapElements)158 else if (stream.GetNumPairs() != aTests[iTest].uMapElements) 257 159 { 258 160 RTTestFailed(hTest, "\tMap has %u elements, expected %u", 259 bufMap.size(), aTests[iTest].uMapElements);260 } 261 else if ( uOffset!= aTests[iTest].uOffsetAfter)161 stream.GetNumPairs(), aTests[iTest].uMapElements); 162 } 163 else if (stream.GetOffset() != aTests[iTest].uOffsetAfter) 262 164 { 263 165 RTTestFailed(hTest, "\tOffset %u wrong, expected %u", … … 279 181 } 280 182 } 281 282 tstOutputAndDestroyMap(bufMap);283 183 } 284 184 … … 289 189 RTTestIPrintf(RTTESTLVL_DEBUG, "=> Block test #%u\n", iTest); 290 190 291 int iResult; 292 293 GuestBufferMap bufMap; 294 uint32_t uOffset = 0; 295 uint32_t uNumBlocks = 0; 296 297 while (uOffset < aTests2[iTest].cbData - 1) 298 { 299 iResult = outputBufferParse((BYTE*)aTests2[iTest].pbData, aTests2[iTest].cbData, 300 &uOffset, bufMap); 301 RTTestIPrintf(RTTESTLVL_DEBUG, "\tReturned with %Rrc\n", iResult); 302 if ( iResult == VINF_SUCCESS 303 || iResult == VERR_MORE_DATA) 304 { 305 if (bufMap.size()) /* Only count block which have some valid data. */ 191 GuestProcessStream stream; 192 int iResult = stream.AddData((BYTE*)aTests2[iTest].pbData, aTests2[iTest].cbData); 193 if (RT_SUCCESS(iResult)) 194 { 195 uint32_t uNumBlocks = 0; 196 197 do 198 { 199 iResult = stream.Parse(); 200 if (iResult == VERR_MORE_DATA) 306 201 uNumBlocks++; 307 308 tstOutputAndDestroyMap(bufMap); 309 310 RTTestIPrintf(RTTESTLVL_DEBUG, "\tNext offset %u (total: %u)\n", 311 uOffset, aTests2[iTest].cbData); 202 if (uNumBlocks > 32) 203 break; /* Give up if unreasonable big. */ 204 } while (iResult == VERR_MORE_DATA); 205 206 if (iResult != aTests2[iTest].iResult) 207 { 208 RTTestFailed(hTest, "\tReturned %Rrc, expected %Rrc", 209 iResult, aTests2[iTest].iResult); 312 210 } 313 else 314 break; 315 316 if (uNumBlocks > 32) 317 break; /* Give up if unreasonable big. */ 318 } 319 320 if (iResult != aTests2[iTest].iResult) 321 { 322 RTTestFailed(hTest, "\tReturned %Rrc, expected %Rrc", 323 iResult, aTests2[iTest].iResult); 324 } 325 else if (uNumBlocks != aTests2[iTest].uNumBlocks) 326 { 327 RTTestFailed(hTest, "\tReturned %u blocks, expected %u\n", 328 uNumBlocks, aTests2[iTest].uNumBlocks); 329 } 211 else if (uNumBlocks != aTests2[iTest].uNumBlocks) 212 { 213 RTTestFailed(hTest, "\tReturned %u blocks, expected %u\n", 214 uNumBlocks, aTests2[iTest].uNumBlocks); 215 } 216 } 217 else 218 RTTestFailed(hTest, "\tAdding data failed with %Rrc", iResult); 330 219 } 220 221 RTPrintf("Shutting down COM...\n"); 222 com::Shutdown(); 331 223 332 224 /*
Note:
See TracChangeset
for help on using the changeset viewer.