debug-trace.cpp
Go to the documentation of this file.
1 /* Copyright 2019, LAAS-CNRS
2  *
3  * Olivier Stasse
4  *
5  */
6 #include <dynamic-graph/entity.h>
8 
9 #include <iostream>
10 #include <sstream>
11 
12 #include "dynamic-graph/factory.h"
13 #include "dynamic-graph/pool.h"
14 
15 #define VP_DEBUG 1
16 #define VP_DEBUG_MODE 50
17 #define VP_TEMPLATE_DEBUG_MODE 50
18 
19 #include <dynamic-graph/debug.h>
20 
21 #define BOOST_TEST_MODULE debug - trace
22 
23 #if BOOST_VERSION >= 105900
24 #include <boost/test/tools/output_test_stream.hpp>
25 #else
26 #include <boost/test/output_test_stream.hpp>
27 #endif
28 #include <boost/test/unit_test.hpp>
29 
30 using boost::test_tools::output_test_stream;
31 
32 namespace dynamicgraph {
33 class CustomEntity : public Entity {
34  public:
35  static const std::string CLASS_NAME;
36  virtual const std::string &getClassName() const { return CLASS_NAME; }
37  explicit CustomEntity(const std::string &n) : Entity(n) {
38  dynamicgraph::dgDEBUGFLOW.openFile("/tmp/dynamic-graph-traces.txt");
39  }
41  dynamicgraph::dgDEBUGFLOW.closeFile("/tmp/dynamic-graph-traces.txt");
42  }
43  void testDebugTrace() {
45  dgDEBUGIN(5);
46 
48  dgDEBUGINOUT(5);
49 
50  dgDEBUG(5) << "Here is a test" << std::endl;
51 
53  dgDEBUGOUT(5);
54  }
55 };
57 } // namespace dynamicgraph
58 
59 BOOST_AUTO_TEST_CASE(testDebugTrace) {
60  BOOST_CHECK_EQUAL(dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity");
61 
62  dynamicgraph::CustomEntity *ptr_entity =
63  (dynamic_cast<dynamicgraph::CustomEntity *>(
65 
66  "my-entity")));
67 
68  dynamicgraph::CustomEntity &entity = *ptr_entity;
69  entity.testDebugTrace();
70 
72  output_test_stream output;
73  std::fstream the_debug_file;
75  std::ios::in);
76 
77  // Extract the filename and this source file from the output
78  std::string astr;
79  std::ostringstream oss_debug_file;
80  while (std::getline(the_debug_file, astr)) {
81  std::size_t found = astr.find(":");
82  std::string asubstr = astr.substr(found + 1, astr.length());
83  found = asubstr.find(":");
84  std::string asubstr2 = asubstr.substr(found + 1, astr.length());
85  oss_debug_file << asubstr2;
86  }
87 
88  the_debug_file.close();
89 
90  // Compare with the strings put inside this source file
91  std::string str_to_test =
92  "# In {"
93  "# In/Out { }"
94  "Here is a test"
95  "# Out }";
96  bool two_sub_string_identical;
97 
98  // Make comparisons.
99  two_sub_string_identical = str_to_test == oss_debug_file.str();
100 
101  BOOST_CHECK(two_sub_string_identical);
102 
103  delete ptr_entity;
104 }
entity.h
dynamicgraph::CustomEntity::getClassName
virtual const std::string & getClassName() const
Definition: debug-trace.cpp:36
dynamicgraph
dynamicgraph::CustomEntity::~CustomEntity
~CustomEntity()
Definition: debug-trace.cpp:40
dynamicgraph::DebugTrace::closeFile
static void closeFile(const char *filename=DEBUG_FILENAME_DEFAULT)
Definition: debug.cpp:54
dynamicgraph::Entity
This class represents an entity, i.e. a generic computational unit that provides input and output sig...
Definition: include/dynamic-graph/entity.h:52
dgDEBUG
#define dgDEBUG(level)
Definition: debug.h:157
dynamicgraph::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity")
dynamicgraph::CustomEntity
Definition: command-test.cpp:36
dynamicgraph::CustomEntity::CustomEntity
CustomEntity(const std::string &n)
Definition: debug-trace.cpp:37
CustomEntity
Definition: custom-entity.cpp:22
dynamicgraph::CustomEntity::testDebugTrace
void testDebugTrace()
Definition: debug-trace.cpp:43
dynamicgraph::dgDEBUGFLOW
DYNAMIC_GRAPH_DLLAPI DebugTrace dgDEBUGFLOW
dgDEBUGOUT
#define dgDEBUGOUT(level)
Definition: debug.h:204
dgDEBUGIN
#define dgDEBUGIN(level)
VP_DEBUG.
Definition: debug.h:202
dynamicgraph::Entity::Entity
Entity(const std::string &name)
Definition: src/dgraph/entity.cpp:33
exception-factory.h
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(testDebugTrace)
Definition: debug-trace.cpp:59
factory.h
dynamicgraph::CustomEntity::CLASS_NAME
static const std::string CLASS_NAME
Definition: command-test.cpp:38
dynamicgraph::DebugTrace::DEBUG_FILENAME_DEFAULT
static const char * DEBUG_FILENAME_DEFAULT
Definition: debug.h:86
dynamicgraph::DebugTrace::openFile
static void openFile(const char *filename=DEBUG_FILENAME_DEFAULT)
Definition: debug.cpp:48
dgDEBUGINOUT
#define dgDEBUGINOUT(level)
Definition: debug.h:206
debug.h
dynamicgraph::FactoryStorage::newEntity
Entity * newEntity(const std::string &classname, const std::string &objname) const
Instantiate (and allocate) an entity.
Definition: src/dgraph/factory.cpp:79
pool.h
dynamicgraph::FactoryStorage::getInstance
static FactoryStorage * getInstance()
Get pointer to unique object of the class.
Definition: src/dgraph/factory.cpp:15


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Fri Aug 2 2024 08:36:38