|
| 1 | +/* Copyright 2019, LAAS-CNRS |
| 2 | + * |
| 3 | + * Olivier Stasse |
| 4 | + * |
| 5 | + * See LICENSE file |
| 6 | + * |
| 7 | + */ |
| 8 | +#include <sstream> |
| 9 | +#include <iostream> |
| 10 | +#include <dynamic-graph/entity.h> |
| 11 | +#include <dynamic-graph/exception-factory.h> |
| 12 | +#include "dynamic-graph/factory.h" |
| 13 | +#include "dynamic-graph/pool.h" |
| 14 | + |
| 15 | +#define ENABLE_RT_LOG |
| 16 | +#include <dynamic-graph/real-time-logger.h> |
| 17 | +#include <dynamic-graph/logger.h> |
| 18 | + |
| 19 | +#define BOOST_TEST_MODULE debug-logger |
| 20 | + |
| 21 | +#include <boost/test/unit_test.hpp> |
| 22 | +#include <boost/test/output_test_stream.hpp> |
| 23 | + |
| 24 | +using boost::test_tools::output_test_stream; |
| 25 | + |
| 26 | + |
| 27 | +namespace dynamicgraph |
| 28 | +{ |
| 29 | + class CustomEntity : public Entity |
| 30 | + { |
| 31 | + public: |
| 32 | + static const std::string CLASS_NAME; |
| 33 | + virtual const std::string& getClassName () const |
| 34 | + { |
| 35 | + return CLASS_NAME; |
| 36 | + } |
| 37 | + CustomEntity (const std::string n) |
| 38 | + : Entity (n) |
| 39 | + { |
| 40 | + logger_.setTimeSample(0.001); |
| 41 | + logger_.setStreamPrintPeriod(0.005); |
| 42 | + logger_.setVerbosity(VERBOSITY_ALL); |
| 43 | + LoggerVerbosity alv = logger_.getVerbosity(); |
| 44 | + BOOST_CHECK(alv==VERBOSITY_ALL); |
| 45 | + } |
| 46 | + |
| 47 | + ~CustomEntity() |
| 48 | + { |
| 49 | + } |
| 50 | + void testDebugTrace() |
| 51 | + { |
| 52 | + sendMsg("This is a message of level MSG_TYPE_DEBUG",MSG_TYPE_DEBUG); |
| 53 | + sendMsg("This is a message of level MSG_TYPE_INFO",MSG_TYPE_INFO); |
| 54 | + sendMsg("This is a message of level MSG_TYPE_WARNING",MSG_TYPE_WARNING); |
| 55 | + sendMsg("This is a message of level MSG_TYPE_ERROR",MSG_TYPE_ERROR); |
| 56 | + sendMsg("This is a message of level MSG_TYPE_DEBUG_STREAM",MSG_TYPE_DEBUG_STREAM); |
| 57 | + sendMsg("This is a message of level MSG_TYPE_INFO_STREAM",MSG_TYPE_INFO_STREAM); |
| 58 | + sendMsg("This is a message of level MSG_TYPE_WARNING_STREAM",MSG_TYPE_WARNING_STREAM); |
| 59 | + sendMsg("This is a message of level MSG_TYPE_ERROR_STREAM",MSG_TYPE_ERROR_STREAM); |
| 60 | + |
| 61 | + logger_.countdown(); |
| 62 | + |
| 63 | + } |
| 64 | + }; |
| 65 | + DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (CustomEntity,"CustomEntity"); |
| 66 | +} |
| 67 | + |
| 68 | +BOOST_AUTO_TEST_CASE(debug_logger_wrong_initialization) |
| 69 | +{ |
| 70 | + std::ofstream of; |
| 71 | + dynamicgraph::RealTimeLogger::instance(); |
| 72 | + //of.open("/tmp/dg-LOGS.txt",std::ofstream::out|std::ofstream::app); |
| 73 | + // dgADD_OSTREAM_TO_RTLOG (of); |
| 74 | + |
| 75 | + BOOST_CHECK_EQUAL (dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity"); |
| 76 | + |
| 77 | + dynamicgraph::CustomEntity& entity = *(dynamic_cast<dynamicgraph::CustomEntity *>( |
| 78 | + dynamicgraph::FactoryStorage::getInstance()->newEntity("CustomEntity", |
| 79 | + "my-entity-2"))); |
| 80 | + |
| 81 | + for(unsigned int i=0;i<10000;i++) |
| 82 | + { |
| 83 | + entity.testDebugTrace(); |
| 84 | + } |
| 85 | + |
| 86 | + dynamicgraph::RealTimeLogger::destroy(); |
| 87 | +} |
| 88 | + |
| 89 | + |
0 commit comments