Files
@ f2a6ba12fc29
Branch filter:
Location: libtransport.git/3rdparty/cpprestsdk/tests/common/UnitTestpp/src/TestReporterStdout.cpp
f2a6ba12fc29
4.4 KiB
text/x-c++hdr
Slack frontend stub
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | /***
* This file is based on or incorporates material from the UnitTest++ r30 open source project.
* Microsoft is not the original author of this code but has modified it and is licensing the code under
* the MIT License. Microsoft reserves all other rights not expressly granted under the MIT License,
* whether by implication, estoppel or otherwise.
*
* UnitTest++ r30
*
* Copyright (c) 2006 Noel Llopis and Charles Nicholson
* Portions Copyright (c) Microsoft Corporation
*
* All Rights Reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
***/
#include "stdafx.h"
#include <vector>
#include <stdarg.h>
// cstdio doesn't pull in namespace std on VC6, so we do it here.
#if defined(UNITTEST_WIN32) && (_MSC_VER == 1200)
namespace std {}
#endif
namespace UnitTest {
// Function to work around outputing to the console when under WinRT.
static void PrintfWrapper(const char* format, ...)
{
va_list args;
va_start(args, format);
#ifdef __cplusplus_winrt
const auto bufSize = _vscprintf(format, args) + 1; // add 1 for null termination
std::vector<char> byteArray;
byteArray.resize(bufSize);
vsnprintf_s(&byteArray[0], bufSize, bufSize, format, args);
DWORD bytesWritten;
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
WriteFile(h, &byteArray[0], (DWORD)bufSize, &bytesWritten, NULL);
#else
#ifdef _WIN32
vfprintf_s(stdout, format, args);
#else
vfprintf(stdout, format, args);
#endif
#endif
va_end(args);
}
static void ChangeConsoleTextColorToRed()
{
#ifdef _WIN32
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0004 | 0x0008);
#else
std::cout << "\033[1;31m";
#endif
}
static void ChangeConsoleTextColorToGreen()
{
#ifdef _WIN32
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0002 | 0x0008);
#else
std::cout << "\033[1;32m";
#endif
}
static void ChangeConsoleTextColorToGrey()
{
#ifdef _WIN32
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
#else
std::cout << "\033[0m";
#endif
}
void TestReporterStdout::ReportFailure(TestDetails const& details, char const* failure)
{
#if defined(__APPLE__) || defined(__GNUG__)
char const* const errorFormat = "%s:%d: error: Failure in %s: %s FAILED\n";
#else
char const* const errorFormat = "%s(%d): error: Failure in %s: %s FAILED\n";
#endif
ChangeConsoleTextColorToRed();
PrintfWrapper(errorFormat, details.filename, details.lineNumber, details.testName, failure);
ChangeConsoleTextColorToGrey();
std::fflush(stdout);
}
void TestReporterStdout::ReportTestStart(TestDetails const& test)
{
const char * format = "Starting test case %s:%s...\n";
PrintfWrapper(format, test.suiteName, test.testName);
std::fflush(stdout);
}
void TestReporterStdout::ReportTestFinish(TestDetails const& test, bool passed, float)
{
if(passed)
{
const char * format = "Test case %s:%s ";
PrintfWrapper(format, test.suiteName, test.testName);
ChangeConsoleTextColorToGreen();
PrintfWrapper("PASSED\n");
ChangeConsoleTextColorToGrey();
}
else
{
ChangeConsoleTextColorToRed();
const char * format = "Test case %s:%s FAILED\n";
PrintfWrapper(format, test.suiteName, test.testName);
ChangeConsoleTextColorToGrey();
}
std::fflush(stdout);
}
void TestReporterStdout::ReportSummary(int const, int const,
int const, float)
{
}
}
|