logger_test.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jan 10 15:59:51 CET 2005 logger_test.cpp
3 
4  logger_test.cpp - description
5  -------------------
6  begin : Mon January 10 2005
7  copyright : (C) 2005 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 
20 
21 #include "unit.hpp"
22 #include "logger_test.hpp"
23 
24 #include <iostream>
25 #include <boost/scoped_ptr.hpp>
26 #include <Activity.hpp>
28 
29 using namespace boost;
30 using namespace std;
31 using namespace base;
32 using namespace RTT;
33 
34 class Dummy {};
35 
36 #define QS 10
37 
38 void
40 {
41  logger = Logger::Instance();
42 }
43 
44 
45 void
47 {
48 }
49 
50 struct TestLog
51  : public RunnableInterface
52 {
53  bool fini;
54  bool initialize() { fini = false; return true; }
55 
56  void step() {
57  Logger::In in("TLOG");
58  log(Info) << "Hello this is the world speaking elaborately and lengthy...!" <<endlog();
59  }
60 
61  void finalize() {
62  fini = true;
63  }
64 };
65 
66 
67 BOOST_FIXTURE_TEST_SUITE( LoggerTestSuite, LoggerTest )
68 
69 BOOST_AUTO_TEST_CASE( testStartStop )
70 {
71  BOOST_CHECK( logger != 0 );
72  BOOST_CHECK( &Logger::log() != 0 );
73 }
74 
75 BOOST_AUTO_TEST_CASE( testLogEnv )
76 {
77  Logger::log() << Logger::Debug << "Debug Level set + text"<< Logger::nl;
78  Logger::log() << "Test Log Environment variable : Single line" << Logger::endl;
79  Logger::log() << "Test Log Environment variable : Two ";
80  Logger::log() << "lines on one line." << Logger::endl;
81  Logger::log() << "Test Log Environment variable : Two" << Logger::nl;
82  Logger::log() << "lines on two lines." << Logger::endl;
83 
84  Logger::log() << "Test Log Environment variable : nl" << Logger::nl;
85  Logger::log() << "Test Log Environment variable : flush" << flush;
86  Logger::log() << " and std::endl." << std::endl;
87 }
88 
89 BOOST_AUTO_TEST_CASE( testNewLog )
90 {
91  log( Debug ) << "Debug Level set + text"<< endlog();
92  log() << "Test Log Environment variable : Single line" << endlog(Debug);
93  log() << "Test Log Environment variable : Two ";
94  log() << "lines on one line." << endlog();
95  log() << "Test Log Environment variable : Two" << nlog();
96  log() << "lines on two lines." << endlog();
97 
98  log() << "Test Log Environment variable : nl" << nlog();
99  log() << "Test Log Environment variable : flush" << flushlog();
100  log() << " and std::endl." << std::endl;
101 }
102 
103 BOOST_AUTO_TEST_CASE( testThreadLog )
104 {
105  boost::scoped_ptr<TestLog> run( new TestLog() );
106  boost::scoped_ptr<ActivityInterface> t( new Activity(25, 0.001, 0, "ORActivity1") );
107  boost::scoped_ptr<TestLog> run2( new TestLog() );
108  boost::scoped_ptr<ActivityInterface> t2( new Activity(25, 0.001, 0, "ORActivity2") );
109 
110  t->run( run.get() );
111  t2->run( run2.get() );
112 
113  t->start();
114  t2->start();
115  sleep(1);
116  t->stop();
117  t2->stop();
118 
119 }
120 
static Logger::LogFunction flushlog()
Definition: Logger.hpp:381
static Logger::LogFunction nlog()
Definition: Logger.hpp:375
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
void setUp()
Definition: logger_test.cpp:39
BOOST_AUTO_TEST_CASE(testStartStop)
Definition: logger_test.cpp:69
#define BOOST_AUTO_TEST_SUITE_END()
Definition: mystd.hpp:163
void step()
Definition: logger_test.cpp:56
bool initialize()
Definition: logger_test.cpp:54
bool fini
Definition: logger_test.cpp:53
basic_ostreams & endl(basic_ostreams &s)
Definition: rtstreams.cpp:110
An Activity executes a RunnableInterface object in a (periodic) thread.
Definition: Activity.hpp:70
unsigned int sleep(unsigned int s)
Definition: fosi.cpp:51
void tearDown()
Definition: logger_test.cpp:46
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
static Logger & log()
Definition: Logger.hpp:350
static Logger::LogFunction endlog()
Definition: Logger.hpp:362
void finalize()
Definition: logger_test.cpp:61


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:25