opcua_protocol_addon_test.cpp
Go to the documentation of this file.
1 
12 
15 #include "builtin_server_addon.h"
16 #include "builtin_server.h"
17 
21 #include "services_registry_test.h"
23 #include "builtin_server_test.h"
24 
25 #include <gmock/gmock.h>
26 #include <gtest/gtest.h>
27 #include <iostream>
28 #include <thread>
29 
30 using namespace testing;
31 
33 {
34 public:
35  void SetUp()
36  {
38  Logger = spdlog::stderr_color_mt("test");
39  Logger->set_level(spdlog::level::info);
40  Addons = Common::CreateAddonsManager(Logger);
41 
46  //OpcUa::Test::RegisterOpcTcpAddon(*Addons);
49  Addons->Register(OpcUa::Server::CreateAsioAddon());
50  Addons->Start();
51  }
52 
53  void TearDown()
54  {
55  Addons->Stop();
56  Addons.reset();
57  }
58 
59 protected:
60  Common::Logger::SharedPtr Logger;
61  std::unique_ptr<Common::AddonsManager> Addons;
62 };
63 
65 {
66  ASSERT_TRUE(static_cast<bool>(Addons->GetAddon(OpcUa::Server::OpcUaProtocolAddonId)));
67 }
68 
69 TEST_F(OpcUaProtocolAddonTest, CanGetServerWhichOpensAndClosesSecureChannel)
70 {
71  std::shared_ptr<OpcUa::Server::BuiltinServer> computerAddon = Addons->GetAddon<OpcUa::Server::BuiltinServer>(OpcUa::Server::OpcUaProtocolAddonId);
72  ASSERT_TRUE(static_cast<bool>(computerAddon));
73  std::shared_ptr<OpcUa::Services> computer = computerAddon->GetServices();
74  ASSERT_TRUE(static_cast<bool>(computer));
75  computer.reset();
76 }
77 
78 TEST_F(OpcUaProtocolAddonTest, CanListEndpoints)
79 {
80  std::shared_ptr<OpcUa::Server::BuiltinServer> computerAddon = Addons->GetAddon<OpcUa::Server::BuiltinServer>(OpcUa::Server::OpcUaProtocolAddonId);
81  std::shared_ptr<OpcUa::Services> computer = computerAddon->GetServices();
82  std::shared_ptr<OpcUa::EndpointServices> endpoints = computer->Endpoints();
83  std::vector<OpcUa::EndpointDescription> desc;
84  ASSERT_NO_THROW(desc = endpoints->GetEndpoints(OpcUa::GetEndpointsParameters()));
85  ASSERT_EQ(desc.size(), 1);
86  endpoints.reset();
87  computer.reset();
88 }
89 
91 {
92  std::shared_ptr<OpcUa::Server::BuiltinServer> computerAddon = Addons->GetAddon<OpcUa::Server::BuiltinServer>(OpcUa::Server::OpcUaProtocolAddonId);
93  std::shared_ptr<OpcUa::Services> computer = computerAddon->GetServices();
94  std::shared_ptr<OpcUa::EndpointServices> endpoints = computer->Endpoints();
95  std::vector<OpcUa::ApplicationDescription> servers;
96  ASSERT_NO_THROW(servers = endpoints->FindServers(OpcUa::FindServersParameters()));
97  ASSERT_EQ(servers.size(), 1);
98  endpoints.reset();
99  computer.reset();
100 }
101 
102 TEST_F(OpcUaProtocolAddonTest, CanBrowseRootFolder)
103 {
104  std::shared_ptr<OpcUa::Server::BuiltinServer> computerAddon = Addons->GetAddon<OpcUa::Server::BuiltinServer>(OpcUa::Server::OpcUaProtocolAddonId);
105  std::shared_ptr<OpcUa::Services> computer = computerAddon->GetServices();
106  std::shared_ptr<OpcUa::ViewServices> views = computer->Views();
107 
112  description.IncludeSubtypes = true;
115  OpcUa::NodesQuery query;
116  query.NodesToBrowse.push_back(description);
117 
118  std::vector<OpcUa::BrowseResult> results = views->Browse(query);
119  ASSERT_EQ(results.size(), 1);
120  ASSERT_EQ(results[0].Referencies.size(), 3);
121 
122  views.reset();
123  computer.reset();
124 }
125 
126 TEST_F(OpcUaProtocolAddonTest, CanCreateSession)
127 {
128  std::shared_ptr<OpcUa::Server::BuiltinServer> computerAddon = Addons->GetAddon<OpcUa::Server::BuiltinServer>(OpcUa::Server::OpcUaProtocolAddonId);
129  std::shared_ptr<OpcUa::Services> computer = computerAddon->GetServices();
130 
132  session.ClientDescription.ApplicationName.Text = "opcua client";
133  session.SessionName = "opua command line";
134  session.EndpointUrl = "opc.tcp://localhost:4841";
135  session.Timeout = 1000;
136 
137  OpcUa::ActivateSessionParameters session_parameters;
138 
139  ASSERT_NO_THROW(computer->CreateSession(session));
140  ASSERT_NO_THROW(computer->ActivateSession(session_parameters));
141  ASSERT_NO_THROW(computer->CloseSession());
142 
143  computer.reset();
144 }
145 
146 TEST_F(OpcUaProtocolAddonTest, ManipulateSubscriptions)
147 {
148  std::shared_ptr<OpcUa::Server::BuiltinServer> computerAddon = Addons->GetAddon<OpcUa::Server::BuiltinServer>(OpcUa::Server::OpcUaProtocolAddonId);
149  std::shared_ptr<OpcUa::Services> computer = computerAddon->GetServices();
150  std::shared_ptr<OpcUa::SubscriptionServices> subscriptions = computer->Subscriptions();
151 
153  params.MaxNotificationsPerPublish = 3;
154  params.Priority = 0;
155  params.PublishingEnabled = true;
156  params.RequestedLifetimeCount = 3;
157  params.RequestedMaxKeepAliveCount = 3;
158  params.RequestedPublishingInterval = 1000;
159 
160 
162  req.Parameters = params;
164  ASSERT_NO_THROW(data = subscriptions->CreateSubscription(req, [](OpcUa::PublishResult)
165  {
166 
167  }));
168 
169  subscriptions.reset();
170  computer.reset();
171 }
172 
173 TEST_F(OpcUaProtocolAddonTest, CanReadAttributes)
174 {
175  std::shared_ptr<OpcUa::Server::BuiltinServer> computerAddon = Addons->GetAddon<OpcUa::Server::BuiltinServer>(OpcUa::Server::OpcUaProtocolAddonId);
176  std::shared_ptr<OpcUa::Services> computer = computerAddon->GetServices();
177  std::shared_ptr<OpcUa::AttributeServices> attributes = computer->Attributes();
178 
179  OpcUa::ReadParameters params;
181 
182  std::vector<OpcUa::DataValue> values = attributes->Read(params);
183  ASSERT_EQ(values.size(), 1);
184 
185  attributes.reset();
186  computer.reset();
187 }
std::vector< OpcUa::ReadValueId > AttributesToRead
OpcUa::CreateSubscriptionParameters Parameters
ReadValueId ToReadValueId(NodeId id, AttributeId attr)
Definition: protocol.h:7
ApplicationDescription ClientDescription
Definition: services.h:49
TEST_F(TestInfoTest, Names)
std::vector< BrowseDescription > NodesToBrowse
Definition: protocol/view.h:50
Common::AddonInformation CreateAsioAddon()
void RegisterBuiltinServerAddon(Common::AddonsManager &addons)
void RegisterStandardNamespace(Common::AddonsManager &addons)
description
Definition: setup.py:43
AddonsManager::UniquePtr CreateAddonsManager(const Common::Logger::SharedPtr &logger)
Get instance of addons core.
void RegisterServicesRegistry(Common::AddonsManager &addons)
void RegisterAddressSpace(Common::AddonsManager &addons)
#define ASSERT_NO_THROW(statement)
std::unique_ptr< Common::AddonsManager > Addons
#define ASSERT_TRUE(condition)
#define ASSERT_EQ(val1, val2)
OpcUa::LocalizedText ApplicationName
BrowseResultMask ResultMask
Definition: protocol/view.h:41
std::string Text
Definition: types.h:136
void RegisterEndpointsServicesAddon(Common::AddonsManager &addons)
Common::AddonInformation CreateSubscriptionServiceAddon()
BrowseDirection Direction
Definition: protocol/view.h:37
Common::Logger::SharedPtr Logger
std::shared_ptr< logger > stderr_color_mt(const std::string &logger_name)
Definition: spdlog_impl.h:150
computer
Definition: test.py:6
void drop_all()
Definition: spdlog_impl.h:260


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