Ignore:
Timestamp:
Sep 6, 2009, 3:54:05 AM (12 years ago)
Author:
Peter
Message:

refs #521. added constructor taking ostream and string. It does not take char* (as ofstream does) because I don't see the point with that. Needed to split member variable ios_ into a ostream* and istream* because the two cases need separate treatment (ostream needs to be flushed in destructor).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/stream_redirect_test.cc

    r2048 r2050  
    3535void test3(test::Suite&);
    3636void test_cout(test::Suite&);
     37void test_ofstream(test::Suite&);
    3738
    3839int main(int argc, char* argv[])
     
    4344  test2(suite);
    4445  test3(suite);
     46  test_ofstream(suite);
    4547
    4648  // keep this last in case it screws up cout
     
    103105
    104106
     107void test_ofstream(test::Suite& suite)
     108{
     109  suite.out() << "testing redirect to ofstream\n";
     110  std::ostringstream my_out;
     111  std::string msg("some message");
     112  std::string tmp_file("tmp.txt");
     113  {
     114    StreamRedirect sr(my_out, tmp_file.c_str());
     115    my_out << msg;
     116  }
     117  if (my_out.str().size()) {
     118    suite.err() << "my_out contains: '" << my_out.str()
     119                << "'\n expected empty\n";
     120    suite.add(false);
     121  }
     122  std::ifstream is(tmp_file.c_str());
     123  std::string line;
     124  getline(is, line);
     125  if (line!=msg) {
     126    suite.add(false);
     127    suite.err() << "expected to find '" << msg << "' in file `"
     128                << tmp_file << "'\nfound: '" << line << "'\n";
     129  }
     130  // cleaning up
     131  unlink(tmp_file.c_str());
     132}
     133
     134
    105135void test_cout(test::Suite& suite)
    106136{
Note: See TracChangeset for help on using the changeset viewer.