File indexing completed on 2026-04-09 07:49:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include "SDirect.hh"
0022 #include <iomanip>
0023 #include <iostream>
0024 #include <fstream>
0025 #include <sstream>
0026 #include <vector>
0027 #include <string>
0028
0029 #include "SSys.hh"
0030 #include "OPTICKS_LOG.hh"
0031
0032
0033 void test_cout_cerr_redirect(const char* msg)
0034 {
0035 std::stringstream coutbuf;
0036 std::stringstream cerrbuf;
0037 {
0038 cout_redirect out_(coutbuf.rdbuf());
0039 cerr_redirect err_(cerrbuf.rdbuf());
0040
0041 SSys::Dump(msg);
0042
0043
0044 }
0045
0046 std::string out = coutbuf.str();
0047 std::string err = cerrbuf.str();
0048
0049 LOG(info) << " captured cout " << out.size() ;
0050 std::cout << "[" << std::endl << out << "]" << std::endl ;
0051
0052 LOG(info) << " captured cerr " << err.size() ;
0053 std::cout << "[" << std::endl << err << "]" << std::endl ;
0054
0055 SSys::Dump(msg);
0056 }
0057
0058
0059 void method_expecting_to_write_to_file( std::ofstream& fp, std::vector<std::string>& msgv )
0060 {
0061 for(unsigned i=0 ; i < msgv.size() ; i++ )
0062 {
0063 const char* pt = msgv[i].c_str() ;
0064 fp.write( const_cast<char*>(pt) , sizeof(pt));
0065 }
0066 }
0067
0068 void test_stream_redirect()
0069 {
0070 std::ofstream fp("/dev/null", std::ios::out);
0071 std::stringstream ss ;
0072
0073 stream_redirect rdir(ss,fp);
0074
0075 std::vector<std::string> msgv ;
0076 msgv.push_back("hello");
0077 msgv.push_back("world");
0078
0079 method_expecting_to_write_to_file(fp, msgv);
0080
0081 std::cout << ss.str() << std::endl ;
0082 }
0083
0084
0085 int main(int argc, char** argv)
0086 {
0087 OPTICKS_LOG(argc, argv);
0088
0089
0090 LOG(info) << argv[0] ;
0091
0092 SSys::Dump(argv[0]);
0093
0094
0095 test_stream_redirect();
0096
0097
0098 return 0 ;
0099 }
0100