logger_test.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jan 10 15:59:51 CET 2005  logger_test.cpp
00003 
00004                         logger_test.cpp -  description
00005                            -------------------
00006     begin                : Mon January 10 2005
00007     copyright            : (C) 2005 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.ac.be
00009 
00010  ***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 
00020 
00021 #include "unit.hpp"
00022 #include "logger_test.hpp"
00023 
00024 #include <iostream>
00025 #include <boost/scoped_ptr.hpp>
00026 #include <Activity.hpp>
00027 #include <base/RunnableInterface.hpp>
00028 
00029 using namespace boost;
00030 using namespace std;
00031 using namespace base;
00032 using namespace RTT;
00033 
00034 class Dummy {};
00035 
00036 #define QS 10
00037 
00038 void
00039 LoggerTest::setUp()
00040 {
00041     logger = Logger::Instance();
00042 }
00043 
00044 
00045 void
00046 LoggerTest::tearDown()
00047 {
00048 }
00049 
00050 struct TestLog
00051   : public RunnableInterface
00052 {
00053   bool fini;
00054   bool initialize() { fini = false; return true; }
00055 
00056   void step() {
00057       Logger::In in("TLOG");
00058       log(Info) << "Hello this is the world speaking elaborately and lengthy...!" <<endlog();
00059   }
00060 
00061   void finalize() {
00062     fini = true;
00063   }
00064 };
00065 
00066 
00067 BOOST_FIXTURE_TEST_SUITE( LoggerTestSuite, LoggerTest )
00068 
00069 BOOST_AUTO_TEST_CASE( testStartStop )
00070 {
00071     BOOST_CHECK( logger != 0 );
00072     BOOST_CHECK( &Logger::log() != 0 );
00073 }
00074 
00075 BOOST_AUTO_TEST_CASE( testLogEnv )
00076 {
00077     Logger::log() << Logger::Debug  << "Debug Level set + text"<< Logger::nl;
00078     Logger::log() << "Test Log Environment variable : Single line" << Logger::endl;
00079     Logger::log() << "Test Log Environment variable : Two ";
00080     Logger::log() << "lines on one line." << Logger::endl;
00081     Logger::log() << "Test Log Environment variable : Two" << Logger::nl;
00082     Logger::log() << "lines on two lines." << Logger::endl;
00083 
00084     Logger::log() << "Test Log Environment variable : nl" << Logger::nl;
00085     Logger::log() << "Test Log Environment variable : flush" << flush;
00086     Logger::log() << " and std::endl." << std::endl;
00087 }
00088 
00089 BOOST_AUTO_TEST_CASE( testNewLog )
00090 {
00091     log( Debug )  << "Debug Level set + text"<< endlog();
00092     log() << "Test Log Environment variable : Single line" << endlog(Debug);
00093     log() << "Test Log Environment variable : Two ";
00094     log() << "lines on one line." << endlog();
00095     log() << "Test Log Environment variable : Two" << nlog();
00096     log() << "lines on two lines." << endlog();
00097 
00098     log() << "Test Log Environment variable : nl" << nlog();
00099     log() << "Test Log Environment variable : flush" << flushlog();
00100     log() << " and std::endl." << std::endl;
00101 }
00102 
00103 BOOST_AUTO_TEST_CASE( testThreadLog )
00104 {
00105   boost::scoped_ptr<TestLog> run( new TestLog() );
00106   boost::scoped_ptr<ActivityInterface> t( new Activity(25, 0.001, 0, "ORActivity1") );
00107   boost::scoped_ptr<TestLog> run2( new TestLog() );
00108   boost::scoped_ptr<ActivityInterface> t2( new Activity(25, 0.001, 0, "ORActivity2") );
00109 
00110   t->run( run.get() );
00111   t2->run( run2.get() );
00112 
00113   t->start();
00114   t2->start();
00115   sleep(1);
00116   t->stop();
00117   t2->stop();
00118 
00119 }
00120 
00121 BOOST_AUTO_TEST_SUITE_END()


rtt
Author(s): RTT Developers
autogenerated on Fri Sep 9 2016 04:01:54