Changeset 31926 in vbox for trunk/src/VBox/Debugger/testcase/tstDBGCParser.cpp
- Timestamp:
- Aug 24, 2010 1:50:41 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Debugger/testcase/tstDBGCParser.cpp
r31530 r31926 22 22 #include "../DBGCInternal.h" 23 23 24 #include <iprt/stream.h>25 24 #include <iprt/string.h> 26 #include <iprt/ initterm.h>25 #include <iprt/test.h> 27 26 28 27 … … 39 38 * Global Variables * 40 39 *******************************************************************************/ 41 /** Global error counter. */ 42 static unsigned g_cErrors = 0; 40 /** The test handle. */ 41 static RTTEST g_hTest = NIL_RTTEST; 42 43 43 /** The DBGC backend structure for use in this testcase. */ 44 44 static DBGCBACK g_tstBack = … … 50 50 }; 51 51 /** For keeping track of output prefixing. */ 52 static bool g_fPendingPrefix = true;52 static bool g_fPendingPrefix = true; 53 53 /** Pointer to the current input position. */ 54 const char *g_pszInput = NULL; 54 const char *g_pszInput = NULL; 55 /** The output of the last command. */ 56 static char g_szOutput[1024]; 57 /** The current offset into g_szOutput. */ 58 static size_t g_offOutput = 0; 59 55 60 56 61 /** … … 120 125 while (cbBuf-- > 0) 121 126 { 127 /* screen/log output */ 122 128 if (g_fPendingPrefix) 123 129 { 124 RT Printf("tstDBGCParser:OUTPUT: ");130 RTTestPrintfNl(g_hTest, RTTESTLVL_ALWAYS, "OUTPUT: "); 125 131 g_fPendingPrefix = false; 126 132 } 127 133 if (*pch == '\n') 128 134 g_fPendingPrefix = true; 129 RTPrintf("%c", *pch); 135 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "%c", *pch); 136 137 /* buffer output */ 138 if (g_offOutput < sizeof(g_szOutput) - 1) 139 { 140 g_szOutput[g_offOutput++] = *pch; 141 g_szOutput[g_offOutput] = '\0'; 142 } 143 144 /* advance */ 130 145 pch++; 131 146 } … … 154 169 { 155 170 if (!g_fPendingPrefix) 156 RT Printf("\n");171 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "\n"); 157 172 g_fPendingPrefix = true; 158 173 } … … 164 179 * @param pszCmds The command to test. 165 180 * @param rcCmd The expected result. 166 */ 167 static void tstTry(PDBGC pDbgc, const char *pszCmds, int rcCmd) 168 { 181 * @param fNoExecute When set, the command is not executed. 182 * @param pszExpected Expected output. This does not need to include all 183 * of the output, just the start of it. Thus the 184 * prompt can be omitted. 185 */ 186 static void tstTryEx(PDBGC pDbgc, const char *pszCmds, int rcCmd, bool fNoExecute, const char *pszExpected) 187 { 188 RT_ZERO(g_szOutput); 189 g_offOutput = 0; 169 190 g_pszInput = pszCmds; 170 191 if (strchr(pszCmds, '\0')[-1] == '\n') 171 RT Printf("tstDBGCParser:RUNNING: %s", pszCmds);192 RTTestPrintfNl(g_hTest, RTTESTLVL_ALWAYS, "RUNNING: %s", pszCmds); 172 193 else 173 RT Printf("tstDBGCParser:RUNNING: %s\n", pszCmds);194 RTTestPrintfNl(g_hTest, RTTESTLVL_ALWAYS, "RUNNING: %s\n", pszCmds); 174 195 175 196 pDbgc->rcCmd = VERR_INTERNAL_ERROR; 176 dbgcProcessInput(pDbgc, true /* fNoExecute */);197 dbgcProcessInput(pDbgc, fNoExecute); 177 198 tstCompleteOutput(); 178 199 179 200 if (pDbgc->rcCmd != rcCmd) 180 { 181 RTPrintf("tstDBGCParser: rcCmd=%Rrc expected =%Rrc\n", pDbgc->rcCmd, rcCmd); 182 g_cErrors++; 183 } 184 } 201 RTTestFailed(g_hTest, "rcCmd=%Rrc expected =%Rrc\n", pDbgc->rcCmd, rcCmd); 202 else if ( !fNoExecute 203 && pszExpected 204 && strncmp(pszExpected, g_szOutput, strlen(pszExpected))) 205 RTTestFailed(g_hTest, "Wrong output - expected \"%s\"", pszExpected); 206 } 207 208 209 /** 210 * Tries one command string without executing it. 211 * 212 * @param pDbgc Pointer to the debugger instance. 213 * @param pszCmds The command to test. 214 * @param rcCmd The expected result. 215 */ 216 static void tstTry(PDBGC pDbgc, const char *pszCmds, int rcCmd) 217 { 218 return tstTryEx(pDbgc, pszCmds, rcCmd, true /*fNoExecute*/, NULL); 219 } 220 221 222 /** 223 * Tries to execute one command string. 224 * @param pDbgc Pointer to the debugger instance. 225 * @param pszCmds The command to test. 226 * @param rcCmd The expected result. 227 * @param pszExpected Expected output. This does not need to include all 228 * of the output, just the start of it. Thus the 229 * prompt can be omitted. 230 */ 231 static void tstTryExec(PDBGC pDbgc, const char *pszCmds, int rcCmd, const char *pszExpected) 232 { 233 return tstTryEx(pDbgc, pszCmds, rcCmd, false /*fNoExecute*/, pszExpected); 234 } 235 236 237 /** 238 * Test an operator on an expression resulting a plain number. 239 * 240 * @param pDbgc Pointer to the debugger instance. 241 * @param pszExpr The express to test. 242 * @param u64Expect The expected result. 243 */ 244 static void tstNumOp(PDBGC pDbgc, const char *pszExpr, uint64_t u64Expect) 245 { 246 char szCmd[80]; 247 RTStrPrintf(szCmd, sizeof(szCmd), "format %s\n", pszExpr); 248 249 char szExpected[80]; 250 RTStrPrintf(szExpected, sizeof(szExpected), 251 "Number: hex %llx dec 0i%lld oct 0t%llo", u64Expect, u64Expect, u64Expect); 252 253 return tstTryEx(pDbgc, szCmd, VINF_SUCCESS, false /*fNoExecute*/, szExpected); 254 } 255 185 256 186 257 … … 190 261 * Init. 191 262 */ 192 RTR3Init(); 193 RTPrintf("tstDBGCParser: TESTING...\n"); 263 int rc = RTTestInitAndCreate("tstDBGCParser", &g_hTest); 264 if (rc) 265 return rc; 266 RTTestBanner(g_hTest); 194 267 195 268 /* … … 197 270 */ 198 271 PDBGC pDbgc; 199 intrc = dbgcCreate(&pDbgc, &g_tstBack, 0);272 rc = dbgcCreate(&pDbgc, &g_tstBack, 0); 200 273 if (RT_SUCCESS(rc)) 201 274 { … … 205 278 { 206 279 tstTry(pDbgc, "stop\n", VINF_SUCCESS); 280 tstTry(pDbgc, "format 1\n", VINF_SUCCESS); 207 281 tstTry(pDbgc, "format \n", VERR_PARSE_TOO_FEW_ARGUMENTS); 208 282 tstTry(pDbgc, "format 0 1 23 4\n", VERR_PARSE_TOO_MANY_ARGUMENTS); 209 283 tstTry(pDbgc, "sa 3 23 4 'q' \"21123123\" 'b' \n", VINF_SUCCESS); 284 285 tstNumOp(pDbgc, "1", 1); 286 tstNumOp(pDbgc, "1", 1); 287 tstNumOp(pDbgc, "1", 1); 288 289 tstNumOp(pDbgc, "+1", 1); 290 tstNumOp(pDbgc, "++++++1", 1); 291 292 tstNumOp(pDbgc, "-1", UINT64_MAX); 293 tstNumOp(pDbgc, "--1", 1); 294 tstNumOp(pDbgc, "---1", UINT64_MAX); 295 tstNumOp(pDbgc, "----1", 1); 296 297 tstNumOp(pDbgc, "~0", UINT64_MAX); 298 tstNumOp(pDbgc, "~1", UINT64_MAX-1); 299 tstNumOp(pDbgc, "~~0", 0); 300 tstNumOp(pDbgc, "~~1", 1); 301 302 tstNumOp(pDbgc, "!1", 0); 303 tstNumOp(pDbgc, "!0", 1); 304 tstNumOp(pDbgc, "!42", 0); 305 tstNumOp(pDbgc, "!!42", 1); 306 tstNumOp(pDbgc, "!!!42", 0); 307 tstNumOp(pDbgc, "!!!!42", 1); 308 309 tstNumOp(pDbgc, "1 +1", 2); 310 tstNumOp(pDbgc, "1 + 1", 2); 311 tstNumOp(pDbgc, "1+1", 2); 312 tstNumOp(pDbgc, "1+ 1", 2); 313 314 tstNumOp(pDbgc, "1 - 1", 0); 315 tstNumOp(pDbgc, "99 - 90", 9); 316 317 tstNumOp(pDbgc, "2 * 2", 4); 318 319 tstNumOp(pDbgc, "2 / 2", 1); 320 tstNumOp(pDbgc, "2 / 0", UINT64_MAX); 321 tstNumOp(pDbgc, "0i1024 / 0i4", 256); 322 323 tstNumOp(pDbgc, "1<<1", 2); 324 tstNumOp(pDbgc, "1<<0i32", 0x0000000100000000); 325 tstNumOp(pDbgc, "1<<0i48", 0x0001000000000000); 326 tstNumOp(pDbgc, "1<<0i63", 0x8000000000000000); 327 328 tstNumOp(pDbgc, "fedcba0987654321>>0i04", 0x0fedcba098765432); 329 tstNumOp(pDbgc, "fedcba0987654321>>0i32", 0xfedcba09); 330 tstNumOp(pDbgc, "fedcba0987654321>>0i48", 0x0000fedc); 331 332 tstNumOp(pDbgc, "0ef & 4", 4); 333 tstNumOp(pDbgc, "01234567891 & fff", 0x00000000891); 334 tstNumOp(pDbgc, "01234567891 & ~fff", 0x01234567000); 335 336 tstNumOp(pDbgc, "1 | 1", 1); 337 tstNumOp(pDbgc, "0 | 4", 4); 338 tstNumOp(pDbgc, "4 | 0", 4); 339 tstNumOp(pDbgc, "4 | 4", 4); 340 tstNumOp(pDbgc, "1 | 4 | 2", 7); 341 342 tstNumOp(pDbgc, "1 ^ 1", 0); 343 tstNumOp(pDbgc, "1 ^ 0", 1); 344 tstNumOp(pDbgc, "0 ^ 1", 1); 345 tstNumOp(pDbgc, "3 ^ 1", 2); 346 tstNumOp(pDbgc, "7 ^ 3", 4); 347 348 tstNumOp(pDbgc, "7 || 3", 1); 349 tstNumOp(pDbgc, "1 || 0", 1); 350 tstNumOp(pDbgc, "0 || 1", 1); 351 tstNumOp(pDbgc, "0 || 0", 0); 352 353 tstNumOp(pDbgc, "0 && 0", 0); 354 tstNumOp(pDbgc, "1 && 0", 0); 355 tstNumOp(pDbgc, "0 && 1", 0); 356 tstNumOp(pDbgc, "1 && 1", 1); 357 tstNumOp(pDbgc, "4 && 1", 1); 358 210 359 } 211 360 … … 216 365 * Summary 217 366 */ 218 if (!g_cErrors) 219 RTPrintf("tstDBGCParser: SUCCESS\n"); 220 else 221 RTPrintf("tstDBGCParser: FAILURE - %d errors\n", g_cErrors); 222 return g_cErrors != 0; 223 } 367 return RTTestSummaryAndDestroy(g_hTest); 368 }
Note:
See TracChangeset
for help on using the changeset viewer.