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 
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 }
This class represents an entity, i.e. a generic computational unit that provides input and output sig...
#define dgDEBUGOUT(level)
Definition: debug.h:204
static const char * DEBUG_FILENAME_DEFAULT
Definition: debug.h:86
#define dgDEBUGINOUT(level)
Definition: debug.h:206
static void openFile(const char *filename=DEBUG_FILENAME_DEFAULT)
Definition: debug.cpp:48
static const std::string CLASS_NAME
static void closeFile(const char *filename=DEBUG_FILENAME_DEFAULT)
Definition: debug.cpp:54
BOOST_AUTO_TEST_CASE(testDebugTrace)
Definition: debug-trace.cpp:59
virtual const std::string & getClassName() const
Definition: debug-trace.cpp:36
#define dgDEBUG(level)
Definition: debug.h:157
CustomEntity(const std::string &n)
Definition: debug-trace.cpp:37
Entity(const std::string &name)
Entity * newEntity(const std::string &classname, const std::string &objname) const
Instantiate (and allocate) an entity.
static FactoryStorage * getInstance()
Get pointer to unique object of the class.
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity")
DYNAMIC_GRAPH_DLLAPI DebugTrace dgDEBUGFLOW
#define dgDEBUGIN(level)
VP_DEBUG.
Definition: debug.h:202


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Sun Jun 25 2023 02:06:03