GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tests/debug-logger-winit.cpp Lines: 28 31 90.3 %
Date: 2023-03-15 12:04:10 Branches: 78 154 50.6 %

Line Branch Exec Source
1
/* Copyright 2019, LAAS-CNRS
2
 *
3
 * Olivier Stasse
4
 *
5
 * See LICENSE file
6
 *
7
 */
8
#include <iostream>
9
#include <sstream>
10
11
#define ENABLE_RT_LOG
12
#include <dynamic-graph/entity.h>
13
#include <dynamic-graph/exception-factory.h>
14
#include <dynamic-graph/logger.h>
15
#include <dynamic-graph/real-time-logger.h>
16
17
#include "dynamic-graph/factory.h"
18
#include "dynamic-graph/pool.h"
19
20
#define BOOST_TEST_MODULE debug - logger
21
22
#if BOOST_VERSION >= 105900
23
#include <boost/test/tools/output_test_stream.hpp>
24
#else
25
#include <boost/test/output_test_stream.hpp>
26
#endif
27
#include <boost/date_time/posix_time/posix_time.hpp>
28
#include <boost/test/unit_test.hpp>
29
#include <boost/thread/thread.hpp>
30
31
using boost::test_tools::output_test_stream;
32
33
namespace dynamicgraph {
34
class CustomEntity : public Entity {
35
 public:
36
  static const std::string CLASS_NAME;
37
  virtual const std::string &getClassName() const { return CLASS_NAME; }
38
1
  explicit CustomEntity(const std::string &n) : Entity(n) {
39
1
    logger_.setTimeSample(0.001);
40
1
    logger_.setStreamPrintPeriod(0.005);
41
1
    logger_.setVerbosity(VERBOSITY_ALL);
42
1
    LoggerVerbosity alv = logger_.getVerbosity();
43



1
    BOOST_CHECK(alv == VERBOSITY_ALL);
44
1
  }
45
46
  ~CustomEntity() {}
47
1000
  void testDebugTrace() {
48

1000
    sendMsg("This is a message of level MSG_TYPE_DEBUG", MSG_TYPE_DEBUG);
49

1000
    sendMsg("This is a message of level MSG_TYPE_INFO", MSG_TYPE_INFO);
50

1000
    sendMsg("This is a message of level MSG_TYPE_WARNING", MSG_TYPE_WARNING);
51

1000
    sendMsg("This is a message of level MSG_TYPE_ERROR", MSG_TYPE_ERROR);
52

1000
    sendMsg("This is a message of level MSG_TYPE_DEBUG_STREAM",
53
            MSG_TYPE_DEBUG_STREAM);
54

1000
    sendMsg("This is a message of level MSG_TYPE_INFO_STREAM",
55
            MSG_TYPE_INFO_STREAM);
56

1000
    sendMsg("This is a message of level MSG_TYPE_WARNING_STREAM",
57
            MSG_TYPE_WARNING_STREAM);
58

1000
    sendMsg("This is a message of level MSG_TYPE_ERROR_STREAM",
59
            MSG_TYPE_ERROR_STREAM);
60
61
1000
    logger_.countdown();
62
1000
  }
63
};
64
1
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity");
65
}  // namespace dynamicgraph
66
67
















4
BOOST_AUTO_TEST_CASE(debug_logger_wrong_initialization) {
68
2
  dynamicgraph::RealTimeLogger::instance();
69
70


2
  BOOST_CHECK_EQUAL(dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity");
71
72
  dynamicgraph::CustomEntity &entity =
73
      *(dynamic_cast<dynamicgraph::CustomEntity *>(
74


4
          dynamicgraph::FactoryStorage::getInstance()->newEntity(
75
2
              "CustomEntity", "my-entity-2")));
76
77
2002
  for (unsigned int i = 0; i < 1000; i++) {
78
2000
    entity.testDebugTrace();
79
  }
80
81
2
  dynamicgraph::RealTimeLogger::destroy();
82
2
}