Skip to content

Commit

Permalink
add tests util classes to capture std cout and cerr
Browse files Browse the repository at this point in the history
  • Loading branch information
ggutierrez-sunbright committed Jun 27, 2024
1 parent 878b894 commit 2b4709b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/include/test_utils.hpp
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_

0 comments on commit 2b4709b

Please sign in to comment.