| 316 | |
| 317 | template <typename XCHAR> |
| 318 | DWORD PrintWithClreol(const XCHAR * szFormat, va_list argList, bool bPrintLastError, bool bPrintEndOfLine) |
| 319 | { |
| 320 | char * szBufferPtr; |
| 321 | char * szBufferEnd; |
| 322 | size_t nNewPrinted; |
| 323 | size_t nLength = 0; |
| 324 | DWORD dwErrCode = Test_GetLastError(); |
| 325 | XCHAR szMessage[0x200]; |
| 326 | char szBuffer[0x200]; |
| 327 | bool bPrintPrefix = TEST_PRINT_PREFIX; |
| 328 | |
| 329 | // Always start the buffer with '\r' |
| 330 | szBufferEnd = szBuffer + _countof(szBuffer); |
| 331 | szBufferPtr = szBuffer; |
| 332 | *szBufferPtr++ = '\r'; |
| 333 | |
| 334 | // Print the prefix, if needed |
| 335 | if(szMainTitle != NULL && bPrintPrefix) |
| 336 | { |
| 337 | while(szMainTitle[nLength] != 0) |
| 338 | *szBufferPtr++ = szMainTitle[nLength++]; |
| 339 | |
| 340 | *szBufferPtr++ = ':'; |
| 341 | *szBufferPtr++ = ' '; |
| 342 | } |
| 343 | |
| 344 | // Construct the message |
| 345 | nLength = TestStrPrintfV(szMessage, _countof(szMessage), szFormat, argList); |
| 346 | TestStrCopy(szBufferPtr, (szBufferEnd - szBufferPtr), szMessage); |
| 347 | szBufferPtr += nLength; |
| 348 | |
| 349 | // Append the last error |
| 350 | if(bPrintLastError) |
| 351 | { |
| 352 | nLength = TestStrPrintf(szBufferPtr, (szBufferEnd - szBufferPtr), " (error code: %u)", dwErrCode); |
| 353 | szBufferPtr += nLength; |
| 354 | } |
| 355 | |
| 356 | // Remember how much did we print |
| 357 | nNewPrinted = (szBufferPtr - szBuffer); |
| 358 | |
| 359 | // Shall we pad the string? |
| 360 | if((nLength = (szBufferPtr - szBuffer - 1)) < nPrevPrinted) |
| 361 | { |
| 362 | size_t nPadding = nPrevPrinted - nLength; |
| 363 | |
| 364 | if((size_t)(nLength + nPadding) > (size_t)(szBufferEnd - szBufferPtr)) |
| 365 | nPadding = (szBufferEnd - szBufferPtr); |
| 366 | |
| 367 | memset(szBufferPtr, ' ', nPadding); |
| 368 | szBufferPtr += nPadding; |
| 369 | } |
| 370 | |
| 371 | // Shall we add new line? |
| 372 | if((bPrintEndOfLine != false) && (szBufferPtr < szBufferEnd)) |
| 373 | *szBufferPtr++ = '\n'; |
| 374 | *szBufferPtr = 0; |
| 375 |
nothing calls this directly
no test coverage detected