Ignore:
Timestamp:
Jul 14, 2014, 8:37:03 PM (11 years ago)
Author:
Frederik Heber <heber@…>
Children:
0ab195
Parents:
ca940b
git-author:
Frederik Heber <heber@…> (06/19/14 16:26:39)
git-committer:
Frederik Heber <heber@…> (07/14/14 20:37:03)
Message:

logger and errorLogger have new setOutputStream().

  • this allows to redirect the logging streams in a program internally, e.g. in a GUI setting.
  • added unit test on this function.
  • TESTFIX: LogUnitTest used loggerStub which made the tests useless.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Helpers/unittests/LogUnitTest.cpp

    rca940b ref9dff6  
    3939void LogTest::setUp()
    4040{
    41 };
     41}
    4242
    4343void LogTest::tearDown()
     
    4545  logger::purgeInstance();
    4646  errorLogger::purgeInstance();
    47 };
     47}
    4848
    4949/**
     
    7070  CPPUNIT_ASSERT(!DoLog(4));
    7171  CPPUNIT_ASSERT(!DoeLog(4));
    72 };
     72}
     73
     74/**
     75 * UnitTest for log()
     76 */
     77void LogTest::newOutputTest()
     78{
     79  // check whether redirecting output works
     80  std::stringstream teststream;
     81  {
     82    Log().setOutputStream(&teststream);
     83    logger::getInstance().setVerbosity(2);
     84    Log() << Verbose(0) << std::string("test");
     85//    DoLog(0) && (Log() << Verbose(0) << "test" << endl);
     86    CPPUNIT_ASSERT_EQUAL( std::string("test"), teststream.str() );
     87    Log().setOutputStream(NULL);  // go to default, as stringstream is destroyed
     88  }
     89  // redirect to NULL changes to cout
     90  teststream.str("");
     91  {
     92    DoLog(0) && (Log() << Verbose(0) << "test" << endl);
     93    CPPUNIT_ASSERT_EQUAL( std::string(""), teststream.str() );
     94  }
     95}
Note: See TracChangeset for help on using the changeset viewer.