-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests util classes to capture std cout and cerr
- Loading branch information
1 parent
878b894
commit 2b4709b
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef _RBT_TEST_UTILS_H_ | ||
#define _RBT_TEST_UTILS_H_ | ||
|
||
#include <iostream> | ||
#include <streambuf> | ||
#include <sstream> | ||
|
||
class CoutRedirect { | ||
public: | ||
inline CoutRedirect(std::streambuf* new_buffer): old(std::cout.rdbuf(new_buffer)) {} | ||
inline ~CoutRedirect() {std::cout.rdbuf(old);} | ||
|
||
private: | ||
std::streambuf* old; | ||
}; | ||
|
||
|
||
class CerrRedirect { | ||
public: | ||
inline CerrRedirect(std::streambuf* new_buffer): old(std::cerr.rdbuf(new_buffer)) {} | ||
inline ~CerrRedirect() {std::cerr.rdbuf(old);} | ||
|
||
private: | ||
std::streambuf* old; | ||
}; | ||
|
||
class NullBuffer : public std::streambuf { | ||
public: | ||
inline int overflow(int c) override { return c; } | ||
}; | ||
|
||
#endif // _RBT_TEST_UTILS_H_ |