forked from microsoft/GraphEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatch_wrapper.hpp
More file actions
51 lines (42 loc) · 1.14 KB
/
catch_wrapper.hpp
File metadata and controls
51 lines (42 loc) · 1.14 KB
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
#include "catch.hpp"
#include "Trinity/IO/Console.h"
#ifdef CATCH_CONFIG_NOSTDOUT
#include <ostream>
#include <streambuf>
#include "Trinity/String.h"
class ostream_adapter_t : public std::streambuf, public std::ostream
{
private:
const size_t szbuf = 256;
char* pbuf;
void _reset_buf()
{
setp(pbuf, pbuf + szbuf - 1);
}
public:
ostream_adapter_t() : std::ostream(this)
{
pbuf = new char[szbuf + 1];
pbuf[szbuf] = 0;
_reset_buf();
}
std::streambuf::int_type overflow(std::streambuf::int_type c) override
{
pbuf[szbuf - 1] = c;
Trinity::IO::Console::Write("{0}", Trinity::String(pbuf));
_reset_buf();
return 0;
}
int sync() override
{
*pptr() = 0;
Trinity::IO::Console::WriteLine("{0}", Trinity::String(pbuf));
_reset_buf();
return 0;
}
};
ostream_adapter_t ostream_trinity_console_adapter;
std::ostream& Catch::cout() { return ostream_trinity_console_adapter; }
std::ostream& Catch::cerr() { return ostream_trinity_console_adapter; }
std::ostream& Catch::clog() { return ostream_trinity_console_adapter; }
#endif