From 8af26000842694c330bdafaf3ae61c533b51d4ff Mon Sep 17 00:00:00 2001 From: Olivier Stasse <ostasse@laas.fr> Date: Wed, 6 Mar 2019 11:40:20 +0100 Subject: [PATCH] [test] Add missing tests/debug-logger-winit.cpp --- tests/debug-logger-winit.cpp | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/debug-logger-winit.cpp diff --git a/tests/debug-logger-winit.cpp b/tests/debug-logger-winit.cpp new file mode 100644 index 0000000..e13f8f3 --- /dev/null +++ b/tests/debug-logger-winit.cpp @@ -0,0 +1,89 @@ +/* Copyright 2019, LAAS-CNRS + * + * Olivier Stasse + * + * See LICENSE file + * + */ +#include <sstream> +#include <iostream> +#include <dynamic-graph/entity.h> +#include <dynamic-graph/exception-factory.h> +#include "dynamic-graph/factory.h" +#include "dynamic-graph/pool.h" + +#define ENABLE_RT_LOG +#include <dynamic-graph/real-time-logger.h> +#include <dynamic-graph/logger.h> + +#define BOOST_TEST_MODULE debug-logger + +#include <boost/test/unit_test.hpp> +#include <boost/test/output_test_stream.hpp> + +using boost::test_tools::output_test_stream; + + +namespace dynamicgraph +{ + class CustomEntity : public Entity + { + public: + static const std::string CLASS_NAME; + virtual const std::string& getClassName () const + { + return CLASS_NAME; + } + CustomEntity (const std::string n) + : Entity (n) + { + logger_.setTimeSample(0.001); + logger_.setStreamPrintPeriod(0.005); + logger_.setVerbosity(VERBOSITY_ALL); + LoggerVerbosity alv = logger_.getVerbosity(); + BOOST_CHECK(alv==VERBOSITY_ALL); + } + + ~CustomEntity() + { + } + void testDebugTrace() + { + sendMsg("This is a message of level MSG_TYPE_DEBUG",MSG_TYPE_DEBUG); + sendMsg("This is a message of level MSG_TYPE_INFO",MSG_TYPE_INFO); + sendMsg("This is a message of level MSG_TYPE_WARNING",MSG_TYPE_WARNING); + sendMsg("This is a message of level MSG_TYPE_ERROR",MSG_TYPE_ERROR); + sendMsg("This is a message of level MSG_TYPE_DEBUG_STREAM",MSG_TYPE_DEBUG_STREAM); + sendMsg("This is a message of level MSG_TYPE_INFO_STREAM",MSG_TYPE_INFO_STREAM); + sendMsg("This is a message of level MSG_TYPE_WARNING_STREAM",MSG_TYPE_WARNING_STREAM); + sendMsg("This is a message of level MSG_TYPE_ERROR_STREAM",MSG_TYPE_ERROR_STREAM); + + logger_.countdown(); + + } + }; + DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (CustomEntity,"CustomEntity"); +} + +BOOST_AUTO_TEST_CASE(debug_logger_wrong_initialization) +{ + std::ofstream of; + dynamicgraph::RealTimeLogger::instance(); + //of.open("/tmp/dg-LOGS.txt",std::ofstream::out|std::ofstream::app); + // dgADD_OSTREAM_TO_RTLOG (of); + + BOOST_CHECK_EQUAL (dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity"); + + dynamicgraph::CustomEntity& entity = *(dynamic_cast<dynamicgraph::CustomEntity *>( + dynamicgraph::FactoryStorage::getInstance()->newEntity("CustomEntity", + "my-entity-2"))); + + for(unsigned int i=0;i<10000;i++) + { + entity.testDebugTrace(); + } + + dynamicgraph::RealTimeLogger::destroy(); +} + + -- GitLab