computer_view.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 View : public ::testing::Test
22 {
23 protected:
24  View()
25  {
26  Query.Description.NodeToBrowse.Encoding = EV_TWO_BYTE;
27  Query.Description.NodeToBrowse.TwoByteData.Identifier = static_cast<uint8_t>(ObjectId::RootFolder); // TODO automatic cast
28  Query.Description.Direction = BrowseDirection::Forward;
29  Query.Description.ReferenceTypeId.Encoding = EV_TWO_BYTE;
30 // Params.Description.ReferenceTypeId.TwoByteData.Identifier = 33;
31  Query.Description.IncludeSubtypes = true;
32  Query.Description.NodeClasses = NodeClass::Unspecified;
33  Query.Description.ResultMask = BrowseResultMask::All;
34  Query.MaxReferenciesCount = 1;
35  }
36 
37  virtual void SetUp()
38  {
40 
42  session.ClientDescription.Name.Text = "opcua view service test";
43  session.SessionName = "opua test";
44  session.EndpointUrl = GetEndpoint();
45  session.Timeout = 1000;
46 
47  Server->CreateSession(session);
48  Server->ActivateSession();
49 
50  Service = Server->Views();
51  }
52 
53  virtual void TearDown()
54  {
55  Service = std::unique_ptr<ViewServices>();
56 
57  if (Server)
58  {
59  Server->CloseSession();
60  }
61 
62  Server.reset();
63  }
64 
65 protected:
67  std::unique_ptr<Services> Server;
68  std::shared_ptr<ViewServices> Service;
69 };
70 
71 
72 
74 {
75  using namespace OpcUa;
76  ASSERT_TRUE(static_cast<bool>(Service));
77 
78  const std::vector<ReferenceDescription> refs = Service->Browse(Query);
79  ASSERT_EQ(refs.size(), 1);
80 }
81 
82 TEST_F(View, BrowseNext)
83 {
84  using namespace OpcUa;
85  ASSERT_TRUE(static_cast<bool>(Service));
86 
87  Service->Browse(Query);
88  const std::vector<ReferenceDescription> refs = Service->BrowseNext();
89  ASSERT_EQ(refs.size(), 1);
90 }
91 
92 TEST_F(View, BrowseFinishes)
93 {
94  using namespace OpcUa;
95  ASSERT_TRUE(static_cast<bool>(Service));
96 
97  Service->Browse(Query);
98  std::vector<ReferenceDescription> browsedRefs;
99  unsigned count = 0;
100 
101  while (true)
102  {
103  const std::vector<ReferenceDescription> refs = Service->BrowseNext();
104 
105  if (refs.empty())
106  {
107  break;
108  }
109 
110  browsedRefs.insert(browsedRefs.end(), refs.begin(), refs.end());
111  ++count;
112  }
113 
114  EXPECT_TRUE(count > 0);
115  EXPECT_EQ(browsedRefs.size(), count);
116 }
117 
int * count
ApplicationDescription ClientDescription
Definition: services.h:49
OpcUa::NodesQuery Query
virtual void TearDown()
std::unique_ptr< Services > Server
std::vector< T > Browse(const NodeId &node, NodeClass nodeClassMask, Services::SharedPtr services)
Definition: model_impl.h:31
#define EXPECT_TRUE(condition)
std::shared_ptr< ViewServices > Service
virtual void SetUp()
OPC UA Address space part. GNU LGPL.
TEST_F(View, Browse)
#define ASSERT_TRUE(condition)
#define ASSERT_EQ(val1, val2)
#define EXPECT_EQ(expected, actual)
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