computer_attribute.cpp
Go to the documentation of this file.
1 
11 #include "common.h"
12 
13 #include <opc/ua/client/remote_server.h>
14 #include <opc/ua/object_ids.h>
15 
16 #include <stdexcept>
17 
18 using namespace OpcUa;
19 
20 
21 class Attribute : public ::testing::Test
22 {
23 protected:
25  {
26  }
27 
28  virtual void SetUp()
29  {
31 
32  if (!Server)
33  {
34  return;
35  }
36 
38  session.ClientDescription.Name.Text = "opcua view service test";
39  session.SessionName = "opua test";
40  session.EndpointUrl = GetEndpoint();
41  session.Timeout = 1000;
42 
43  Server->CreateSession(session);
44  Server->ActivateSession();
45 
46  Service = Server->Attributes();
47  }
48 
49  virtual void TearDown()
50  {
51  Service = std::unique_ptr<AttributeServices>();
52 
53  if (Server)
54  {
55  Server->CloseSession();
56  Server.reset();
57  }
58  }
59 
60 protected:
61  std::unique_ptr<Services> Server;
62  std::shared_ptr<AttributeServices> Service;
63 };
64 
65 
66 
68 {
69  using namespace OpcUa;
70  ASSERT_TRUE(static_cast<bool>(Service));
71 
72 
73  ReadValueId id;
74  id.Node.Encoding = EV_TWO_BYTE;
75  id.Node.TwoByteData.Identifier = static_cast<uint8_t>(ObjectId::ObjectsFolder);
76  id.Attribute = AttributeId::BrowseName;
77 
78  OpcUa::ReadParameters params;
79  params.AttributesToRead.push_back(id);
80 
81  const std::vector<DataValue> values = Service->Read(params);
82  ASSERT_EQ(values.size(), 1);
83  EXPECT_TRUE(values.at(0).Encoding & DATA_VALUE);
84 }
85 
87 {
88  using namespace OpcUa;
89  ASSERT_TRUE(static_cast<bool>(Service));
90 
91  WriteValue value;
92  value.Node.Encoding = EV_TWO_BYTE;
93  value.Node.TwoByteData.Identifier = static_cast<uint8_t>(ObjectId::ObjectsFolder);
94  value.Attribute = AttributeId::BrowseName;
95 
96  const std::vector<StatusCode> codes = Service->Write(std::vector<WriteValue>(1, value));
97  ASSERT_EQ(codes.size(), 1);
98  EXPECT_NE(codes[0], StatusCode::Good);
99 }
100 
101 
std::vector< OpcUa::ReadValueId > AttributesToRead
ApplicationDescription ClientDescription
Definition: services.h:49
#define EXPECT_TRUE(condition)
std::shared_ptr< AttributeServices > Service
TEST_F(Attribute, Read)
std::unique_ptr< Services > Server
#define EXPECT_NE(expected, actual)
OPC UA Address space part. GNU LGPL.
#define ASSERT_TRUE(condition)
virtual void TearDown()
#define ASSERT_EQ(val1, val2)
virtual void SetUp()
EndpointDescription GetEndpoint(OpcUa::Binary::IOStream &stream)
std::unique_ptr< RemoteConnection > Connect(const std::string &host, unsigned port, const Common::Logger::SharedPtr &logger)


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