Wire Sysio
Wire Sysion 1.0.0
Loading...
Searching...
No Matches
231-Cfg-OutputStreams.cpp
Go to the documentation of this file.
1
// 231-Cfg-OutputStreams.cpp
2
// Show how to replace the streams with a simple custom made streambuf.
3
4
// Note that this reimplementation _does not_ follow `std::cerr`
5
// semantic, because it buffers the output. For most uses however,
6
// there is no important difference between having `std::cerr` buffered
7
// or unbuffered.
8
9
#define CATCH_CONFIG_NOSTDOUT
10
#define CATCH_CONFIG_MAIN
11
#include <
catch2/catch.hpp
>
12
13
class
out_buff
:
public
std::stringbuf {
14
std::FILE* m_stream;
15
public
:
16
out_buff
(std::FILE* stream) :m_stream(stream) {}
17
~out_buff
() { pubsync(); }
18
int
sync
() {
19
int
ret
= 0;
20
for
(
unsigned
char
c : str()) {
21
if
(putc(c, m_stream) == EOF) {
22
ret
= -1;
23
break
;
24
}
25
}
26
// Reset the buffer to avoid printing it multiple times
27
str(
""
);
28
return
ret
;
29
}
30
};
31
32
namespace
Catch
{
33
std::ostream&
cout
() {
34
static
std::ostream
ret
(
new
out_buff
(stdout));
35
return
ret
;
36
}
37
std::ostream&
clog
() {
38
static
std::ostream
ret
(
new
out_buff
(stderr));
39
return
ret
;
40
}
41
std::ostream&
cerr
() {
42
return
clog
();
43
}
44
}
45
46
47
TEST_CASE
(
"This binary uses putc to write out output"
,
"[compilation-only]"
) {
48
SUCCEED
(
"Nothing to test."
);
49
}
out_buff
Definition
231-Cfg-OutputStreams.cpp:13
out_buff::~out_buff
~out_buff()
Definition
231-Cfg-OutputStreams.cpp:17
out_buff::sync
int sync()
Definition
231-Cfg-OutputStreams.cpp:18
out_buff::out_buff
out_buff(std::FILE *stream)
Definition
231-Cfg-OutputStreams.cpp:16
SUCCEED
#define SUCCEED()
Definition
gtest.h:1867
TEST_CASE
#define TEST_CASE(...)
Definition
catch.hpp:222
Catch
Definition
231-Cfg-OutputStreams.cpp:32
Catch::cout
std::ostream & cout()
Definition
231-Cfg-OutputStreams.cpp:33
Catch::clog
std::ostream & clog()
Definition
231-Cfg-OutputStreams.cpp:37
Catch::cerr
std::ostream & cerr()
Definition
231-Cfg-OutputStreams.cpp:41
catch.hpp
ret
CK_RV ret
Definition
yubihsm_pkcs11.c:973
libraries
sys-vm
external
Catch2
examples
231-Cfg-OutputStreams.cpp
Generated by
1.12.0