addons_manager_test.cpp
Go to the documentation of this file.
1 
11 #include <opc/common/exception.h>
12 #include <opc/common/logger.h>
15 #include <opc/managers/device_manager/id.h>
16 #include <opc/managers/property_tree/id.h>
17 
18 #include <cppunit/extensions/HelperMacros.h>
19 #include <cppunit/config/SourcePrefix.h>
20 
21 class AddonsManagerTestCase : public CPPUNIT_NS::TestFixture
22 {
27 
28 public:
29  virtual void setUp()
30  {
33  Logger->set_level(spdlog::level::info);
35  }
36 
37  virtual void tearDown()
38  {
39  Addons.reset();
40  }
41 protected:
42  Common::Logger::SharedPtr Logger;
43  Common::AddonsManager::UniquePtr Addons;
44 
45 
46 protected:
47  void TestOneManager();
48  void TestTwoManagers();
49 };
50 
52 
54 
55 
57 {
58 private:
60  bool Stopped;
61 
62 public:
64  : Initialized(false)
65  , Stopped(false)
66  {
67  }
68 
70  {
71  CPPUNIT_ASSERT(InitializedAddonsCount == 0);
73  Initialized = true;
74  }
75 
76  virtual void Stop()
77  {
78  Stopped = true;
79  }
80 
81  bool IsInitialized() const
82  {
83  return Initialized;
84  }
85 
86  bool IsStopped() const
87  {
88  return Stopped;
89  }
90 };
91 
93 {
94 public:
95  virtual Common::Addon::UniquePtr CreateAddon()
96  {
97  return Common::Addon::UniquePtr(new PropertyTreeAddon());
98  }
99 };
100 
102 {
103 private:
105  bool Stopped;
106 
107 public:
109  : Initialized(false)
110  , Stopped(false)
111  {
112  }
113 
115  {
116  CPPUNIT_ASSERT(InitializedAddonsCount == 1);
118  Initialized = true;
119  }
120 
121  virtual void Stop()
122  {
123  Stopped = true;
124  }
125 
126  bool IsInitialized() const
127  {
128  return Initialized;
129  }
130 
131  bool IsStopped() const
132  {
133  return Stopped;
134  }
135 };
136 
138 {
139 public:
140  virtual Common::Addon::UniquePtr CreateAddon()
141  {
142  return Common::Addon::UniquePtr(new DeviceIOManagerAddon());
143  }
144 };
146 {
148 
149  Common::AddonInformation dmConfig;
150  dmConfig.Id = DeviceManager::ManagerId;
151  dmConfig.Factory = Common::AddonFactory::UniquePtr(new DeviceIOManagerFactory);
152  dmConfig.Dependencies = std::vector<Common::AddonId>(1, PropertyTree::ManagerId);
153  CPPUNIT_ASSERT_NO_THROW(Addons->Register(dmConfig));
154 
155  Common::AddonInformation ptConfig;
156  ptConfig.Id = PropertyTree::ManagerId;
157  ptConfig.Factory = Common::AddonFactory::UniquePtr(new PropertyTreeAddonFactory);
158  CPPUNIT_ASSERT_NO_THROW(Addons->Register(ptConfig));
159 
160  CPPUNIT_ASSERT_NO_THROW(Addons->Start(/*Common::AddonsConfiguration()*/));
161  CPPUNIT_ASSERT_THROW(Addons->Start(/*Common::AddonsConfiguration()*/), Common::Error);
162 
163  std::shared_ptr<PropertyTreeAddon> propertyTree;
164  CPPUNIT_ASSERT_NO_THROW(propertyTree = Common::GetAddon<PropertyTreeAddon>(*Addons, PropertyTree::ManagerId));
165  CPPUNIT_ASSERT(propertyTree);
166  CPPUNIT_ASSERT(propertyTree->IsInitialized());
167 
168  CPPUNIT_ASSERT_NO_THROW(Addons->Stop());
169  CPPUNIT_ASSERT(propertyTree->IsStopped());
170 
171  CPPUNIT_ASSERT_THROW(Addons->Stop(), Common::Error);
172 }
173 
175 {
177 
178  Common::AddonInformation dmConfig;
179  dmConfig.Id = DeviceManager::ManagerId;
180  dmConfig.Factory = Common::AddonFactory::UniquePtr(new DeviceIOManagerFactory);
181  dmConfig.Dependencies = std::vector<Common::AddonId>(1, PropertyTree::ManagerId);
182  CPPUNIT_ASSERT_NO_THROW(Addons->Register(dmConfig));
183  CPPUNIT_ASSERT_THROW(Addons->Register(dmConfig), Common::Error);
184  CPPUNIT_ASSERT_THROW(Addons->GetAddon(DeviceManager::ManagerId), Common::Error);
185 
186  Common::AddonInformation ptConfig;
187  ptConfig.Id = PropertyTree::ManagerId;
188  ptConfig.Factory = Common::AddonFactory::UniquePtr(new PropertyTreeAddonFactory);
189  CPPUNIT_ASSERT_NO_THROW(Addons->Register(ptConfig));
190  CPPUNIT_ASSERT_THROW(Addons->GetAddon(PropertyTree::ManagerId), Common::Error);
191 
192  CPPUNIT_ASSERT_NO_THROW(Addons->Start(/*Common::AddonsConfiguration()*/));
193  CPPUNIT_ASSERT_THROW(Addons->Start(/*Common::AddonsConfiguration()*/), Common::Error);
194 
195  std::shared_ptr<PropertyTreeAddon> propertyTree;
196  CPPUNIT_ASSERT_NO_THROW(propertyTree = Common::GetAddon<PropertyTreeAddon>(*Addons, PropertyTree::ManagerId));
197  CPPUNIT_ASSERT(propertyTree);
198  CPPUNIT_ASSERT(propertyTree->IsInitialized());
199 
200  std::shared_ptr<DeviceIOManagerAddon> deviceManager;
201  CPPUNIT_ASSERT_NO_THROW(deviceManager = Common::GetAddon<DeviceIOManagerAddon>(*Addons, DeviceManager::ManagerId));
202  CPPUNIT_ASSERT(deviceManager);
203  CPPUNIT_ASSERT(deviceManager->IsInitialized());
204 
205  CPPUNIT_ASSERT_NO_THROW(Addons->Stop());
206  CPPUNIT_ASSERT(propertyTree->IsStopped());
207  CPPUNIT_ASSERT(deviceManager->IsStopped());
208 
209  CPPUNIT_ASSERT_THROW(Addons->Stop(), Common::Error);
210 }
211 
Test of addons manager GNU LGPL.
Common::AddonsManager::UniquePtr Addons
virtual void Initialize(Common::AddonsManager &, const Common::AddonParameters &)
initialize addon.
virtual Common::Addon::UniquePtr CreateAddon()
Create instance of addon.
virtual void Initialize(Common::AddonsManager &, const Common::AddonParameters &)
initialize addon.
std::shared_ptr< AddonFactory > Factory
Definition: addon_manager.h:32
Common::Logger::SharedPtr Logger
std::vector< AddonId > Dependencies
Definition: addon_manager.h:33
AddonsManager::UniquePtr CreateAddonsManager(const Common::Logger::SharedPtr &logger)
Get instance of addons core.
bool IsInitialized() const
virtual void Stop()
Stopping addon work. After calling this method addon should throw exception on any calls...
virtual void Stop()
Stopping addon work. After calling this method addon should throw exception on any calls...
virtual Common::Addon::UniquePtr CreateAddon()
Create instance of addon.
unsigned InitializedAddonsCount
CPPUNIT_TEST(TestTwoManagers)
CPPUNIT_TEST_SUITE_REGISTRATION(AddonsManagerTestCase)
std::shared_ptr< logger > stderr_color_mt(const std::string &logger_name)
Definition: spdlog_impl.h:150
CPPUNIT_TEST_SUITE(AddonsManagerTestCase)
void drop_all()
Definition: spdlog_impl.h:260


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:06:03