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.
Location:
src/Helpers/unittests
Files:
4 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}
  • src/Helpers/unittests/LogUnitTest.hpp

    rca940b ref9dff6  
    2020    CPPUNIT_TEST_SUITE( LogTest) ;
    2121    CPPUNIT_TEST ( logTest );
     22    CPPUNIT_TEST ( newOutputTest );
    2223    CPPUNIT_TEST_SUITE_END();
    2324
     
    2526    void setUp();
    2627    void tearDown();
     28    void newOutputTest();
    2729
    2830    void logTest();
  • src/Helpers/unittests/Makefile.am

    rca940b ref9dff6  
    7777LogUnitTest_SOURCES = UnitTestMain.cpp \
    7878        ../Helpers/unittests/LogUnitTest.cpp \
    79         ../Helpers/unittests/LogUnitTest.hpp \
    80         ../Helpers/unittests/stubs/errorloggerStub.cpp \
    81         ../Helpers/unittests/stubs/loggerStub.cpp
     79        ../Helpers/unittests/LogUnitTest.hpp
    8280nodist_LogUnitTest_SOURCES = \
    8381        $(top_srcdir)/src/CodePatterns/Assert.hpp \
  • src/Helpers/unittests/stubs/loggerStub.cpp

    rca940b ref9dff6  
    2626int logger::verbosity = 2;
    2727ostream* logger::nix = NULL;
     28ostream* logger::defaultout = NULL;
     29ostream* logger::out = NULL;
    2830
    2931/**
     
    3537{
    3638  nix = new stringstream;
     39  defaultout = new stringstream;
     40  out = defaultout;
    3741};
    3842
     
    4347{
    4448  delete nix;
     49  delete defaultout;
     50  out = NULL;
    4551}
    4652
     
    6571}
    6672
     73/** Sets a new output stream.
     74 *
     75 * \param _newout new output stream, if NULL we set to defaultout
     76 */
     77void logger::setOutputStream(ostream *_newout)
     78{
     79  if(_newout != NULL)
     80    out = _newout;
     81  else
     82    out = defaultout;
     83}
     84
    6785/**
    6886 * Operator for the Binary(arg) call.
Note: See TracChangeset for help on using the changeset viewer.