用在单元测试很好用
inline std::ostream& red(std::ostream& s)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout,
FOREGROUND_RED | FOREGROUND_INTENSITY);
return s;
}
inline std::ostream& green(std::ostream& s)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout,
FOREGROUND_GREEN | FOREGROUND_INTENSITY);
return s;
}
inline std::ostream& white(std::ostream& s)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout,
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
return s;
}
struct color {
color(WORD attribute) :m_color(attribute) {};
WORD m_color;
};
template <class _Elem, class _Traits>
std::basic_ostream<_Elem, _Traits>&
operator<<(std::basic_ostream<_Elem, _Traits>& i, color& c)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout, c.m_color);
return i;
}
void show_result(bool b, const char* func) {
if (b) {
std::cout << green << "PASSED" << white;
}
else {
std::cout << red << "FAILED" << white;
}
std::cout << ":\t" << func << std::endl;
}
|