custom-entity.cpp 1.65 KB
Newer Older
Thomas Moulard's avatar
Thomas Moulard committed
1
2
3
4
5
// Copyright 2010 Thomas Moulard.
//

#include <sstream>
#include <dynamic-graph/factory.h>
6
#include <dynamic-graph/pool.h>
Thomas Moulard's avatar
Thomas Moulard committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <dynamic-graph/entity.h>
#include <dynamic-graph/exception-factory.h>

#define BOOST_TEST_MODULE customEntity

#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>

using boost::test_tools::output_test_stream;

struct CustomEntity : public dynamicgraph::Entity
{
  static const std::string CLASS_NAME;

21
  virtual const std::string& getClassName () const
Thomas Moulard's avatar
Thomas Moulard committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  {
    return CLASS_NAME;
  }

  CustomEntity (const std::string n)
    : Entity (n)
  {
  }

  virtual ~CustomEntity()
  {
  }

  void display (std::ostream& os) const
  {
    os << "custom entity";
  }

};

DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (CustomEntity,"CustomEntity");


BOOST_AUTO_TEST_CASE (constructor)
{
  BOOST_CHECK_EQUAL (CustomEntity::CLASS_NAME, "CustomEntity");

49
50
51
52
  dynamicgraph::Entity* entity =
    dynamicgraph::FactoryStorage::getInstance()->
    newEntity("CustomEntity", "my-entity");
  BOOST_CHECK_EQUAL (entity->getName (), "my-entity");
53
  BOOST_CHECK_EQUAL (entity->Entity::getClassName (), "Entity");
54
  BOOST_CHECK_EQUAL (entity->getClassName (), CustomEntity::CLASS_NAME);
55

56
57
58
  //CustomEntity entity2 ("");
  // Deregister entities before destroying them
  dynamicgraph::PoolStorage::destroy();
Thomas Moulard's avatar
Thomas Moulard committed
59
60
61
62
}

BOOST_AUTO_TEST_CASE (display)
{
63
64
  dynamicgraph::Entity* entity = dynamicgraph::FactoryStorage::getInstance()->
    newEntity("CustomEntity", "my-entity");
Thomas Moulard's avatar
Thomas Moulard committed
65
66
67

  output_test_stream output;

68
  entity->display(output);
Thomas Moulard's avatar
Thomas Moulard committed
69
  BOOST_CHECK (output.is_equal ("custom entity"));
70
71
  // Deregister entities before destroying them
  dynamicgraph::PoolStorage::destroy();
Thomas Moulard's avatar
Thomas Moulard committed
72
}