binary_serialize_endpoints.cpp
Go to the documentation of this file.
1 
14 #include <opc/ua/protocol/types.h>
15 
16 #include <algorithm>
17 #include <stdexcept>
18 #include <gtest/gtest.h>
19 
20 #include "common.h"
21 
22 
24 {
25 };
26 
28 {
29 };
30 
31 //-------------------------------------------------------
32 // GetEndpointsRequest
33 //-------------------------------------------------------
34 
35 TEST_F(EndpointsSerialization, GetEndpointsRequest)
36 {
37 
38  using namespace OpcUa;
39  using namespace OpcUa::Binary;
40 
41  GetEndpointsRequest request;
42 
46 
48  request.Parameters.EndpointUrl = "test";
49  request.Parameters.LocaleIds.push_back("RU");
50  request.Parameters.ProfileUris.push_back("pro");
51 
52 
53  GetStream() << request << flush;
54 
55  const std::vector<char> expectedData =
56  {
57  1, 0, (char)0xac, 0x1, // TypeId
58  // RequestHeader
60  4, 0, 0, 0, 't', 'e', 's', 't',
61  1, 0, 0, 0, 2, 0, 0, 0, 'R', 'U',
62  1, 0, 0, 0, 3, 0, 0, 0, 'p', 'r', 'o'
63  };
64 
65  ASSERT_EQ(expectedData, GetChannel().SerializedData);
66  ASSERT_EQ(expectedData.size(), RawSize(request));
67 }
68 
70 {
71  using namespace OpcUa;
72  using namespace OpcUa::Binary;
73 
74  const std::vector<char> expectedData =
75  {
76  1, 0, (char)0xac, 0x1, // TypeId
77  // RequestHeader
79  4, 0, 0, 0, 't', 'e', 's', 't',
80  1, 0, 0, 0, 2, 0, 0, 0, 'R', 'U',
81  1, 0, 0, 0, 3, 0, 0, 0, 'p', 'r', 'o'
82  };
83 
84  GetChannel().SetData(expectedData);
85 
86  GetEndpointsRequest request;
87  GetStream() >> request;
88 
92 
94 
95  ASSERT_EQ(request.Parameters.EndpointUrl, "test");
96  ASSERT_EQ(request.Parameters.LocaleIds, std::vector<std::string>(1, "RU"));
97  ASSERT_EQ(request.Parameters.ProfileUris, std::vector<std::string>(1, "pro"));
98 }
99 
100 //----------------------------------------------------
101 // GetEndpointsResponse
102 //----------------------------------------------------
103 
105 {
106 
107  using namespace OpcUa;
108  using namespace OpcUa::Binary;
109 
110  GetEndpointsResponse response;
111 
115 
117 
118  EndpointDescription endpoint;
119  FILL_TEST_ENDPOINT(endpoint);
120  response.Endpoints.push_back(endpoint);
121 
122  GetStream() << response << flush;
123 
124  const std::vector<char> expectedData =
125  {
126  1, 0, (char)0xaf, 0x1, // TypeId
127  // RequestHeader
129 
130  1, 0, 0, 0,
132  };
133 
134  ASSERT_EQ(expectedData, GetChannel().SerializedData);
135  ASSERT_EQ(expectedData.size(), RawSize(response));
136 }
137 
139 {
140  using namespace OpcUa;
141  using namespace OpcUa::Binary;
142 
143  const std::vector<char> expectedData =
144  {
145  1, 0, (char)0xaf, 0x1, // TypeId
146  // RequestHeader
148 
149  1, 0, 0, 0,
151  };
152 
153  GetChannel().SetData(expectedData);
154 
155  GetEndpointsResponse response;
156  GetStream() >> response;
157 
161 
163 
164  ASSERT_EQ(response.Endpoints.size(), 1);
165  ASSERT_ENDPOINT_EQ(response.Endpoints[0]);
166 
167  ASSERT_TRUE(Channel->IsEmpty());
168 }
169 
170 const std::vector<unsigned char> GetEndpointsResponseRealData =
171 {
172  0x4d, 0x53, 0x47, 0x46, 0xd2, 0x06, 0x00, 0x00, 0xfc, 0x4b, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, // MSGF.....K......
173  0x34, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0xaf, 0x01, 0xd8, 0xcd, 0x4e, 0x53, // 4.............NS
174  0x36, 0xda, 0xcd, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 6...............
175  0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x6f, 0x70, 0x63, 0x2e, // ............opc.
176  0x74, 0x63, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x31, 0x2e, // tcp://192.168.1.
177  0x33, 0x36, 0x3a, 0x34, 0x39, 0x33, 0x32, 0x30, 0x34, 0x00, 0x00, 0x00, 0x75, 0x72, 0x6e, 0x3a, // 36:493204...urn:
178  0x74, 0x72, 0x65, 0x77, 0x77, 0x2d, 0x61, 0x35, 0x38, 0x35, 0x35, 0x35, 0x37, 0x31, 0x62, 0x3a, // treww-a5855571b:
179  0x4b, 0x65, 0x70, 0x77, 0x61, 0x72, 0x65, 0x2e, 0x4b, 0x45, 0x50, 0x53, 0x65, 0x72, 0x76, 0x65, // Kepware.KEPServe
180  0x72, 0x45, 0x58, 0x2e, 0x56, 0x35, 0x3a, 0x55, 0x41, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, // rEX.V5:UA Server
181  0x34, 0x00, 0x00, 0x00, 0x75, 0x72, 0x6e, 0x3a, 0x74, 0x72, 0x65, 0x77, 0x77, 0x2d, 0x61, 0x35, // 4...urn:treww-a5
182  0x38, 0x35, 0x35, 0x35, 0x37, 0x31, 0x62, 0x3a, 0x4b, 0x65, 0x70, 0x77, 0x61, 0x72, 0x65, 0x2e, // 855571b:Kepware.
183  0x4b, 0x45, 0x50, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x45, 0x58, 0x2e, 0x56, 0x35, 0x3a, 0x55, // KEPServerEX.V5:U
184  0x41, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x03, 0x02, 0x00, 0x00, 0x00, 0x65, 0x6e, 0x1e, // A Server.....en.
185  0x00, 0x00, 0x00, 0x4b, 0x45, 0x50, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x45, 0x58, 0x2f, 0x55, // ...KEPServerEX/U
186  0x41, 0x40, 0x74, 0x72, 0x65, 0x77, 0x77, 0x2d, 0x61, 0x35, 0x38, 0x35, 0x35, 0x35, 0x37, 0x31, // A@treww-a5855571
187  0x62, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, // b...............
188  0x00, 0x1c, 0x00, 0x00, 0x00, 0x6f, 0x70, 0x63, 0x2e, 0x74, 0x63, 0x70, 0x3a, 0x2f, 0x2f, 0x31, // .....opc.tcp://1
189  0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x31, 0x2e, 0x33, 0x36, 0x3a, 0x34, 0x39, 0x33, 0x32, // 92.168.1.36:4932
190  0x30, 0xf3, 0x03, 0x00, 0x00, 0x30, 0x82, 0x03, 0xef, 0x30, 0x82, 0x03, 0x58, 0xa0, 0x03, 0x02, // 0....0...0..X...
191  0x01, 0x02, 0x02, 0x04, 0x84, 0x79, 0x20, 0xf2, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, // .....y .0...*.H.
192  0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x60, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x0a, 0x09, // .......0`1.0....
193  0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x0f, 0x74, 0x72, 0x65, 0x77, 0x77, // .&...,d....treww
194  0x2d, 0x61, 0x35, 0x38, 0x35, 0x35, 0x35, 0x37, 0x31, 0x62, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, // -a5855571b1.0...
195  0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, // U....US1.0...U..
196  0x13, 0x07, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, // ..Unknown1.0...U
197  0x04, 0x03, 0x13, 0x15, 0x4b, 0x45, 0x50, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x45, 0x58, 0x2f, // ....KEPServerEX/
198  0x55, 0x41, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x32, 0x31, // UA Server0...121
199  0x31, 0x30, 0x34, 0x30, 0x36, 0x33, 0x38, 0x34, 0x35, 0x5a, 0x17, 0x0d, 0x32, 0x32, 0x31, 0x31, // 104063845Z..2211
200  0x30, 0x32, 0x30, 0x36, 0x33, 0x38, 0x34, 0x35, 0x5a, 0x30, 0x60, 0x31, 0x1f, 0x30, 0x1d, 0x06, // 02063845Z0`1.0..
201  0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x0f, 0x74, 0x72, 0x65, // ...&...,d....tre
202  0x77, 0x77, 0x2d, 0x61, 0x35, 0x38, 0x35, 0x35, 0x35, 0x37, 0x31, 0x62, 0x31, 0x0b, 0x30, 0x09, // ww-a5855571b1.0.
203  0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, // ..U....US1.0...U
204  0x04, 0x0a, 0x13, 0x07, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x31, 0x1e, 0x30, 0x1c, 0x06, // ....Unknown1.0..
205  0x03, 0x55, 0x04, 0x03, 0x13, 0x15, 0x4b, 0x45, 0x50, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x45, // .U....KEPServerE
206  0x58, 0x2f, 0x55, 0x41, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x30, 0x81, 0x9f, 0x30, 0x0d, // X/UA Server0..0.
207  0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, // ..*.H...........
208  0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xb0, 0x1f, 0x2b, 0xd7, 0x13, 0x46, 0x0d, 0xd6, // .0........+..F..
209  0x52, 0xa9, 0x94, 0x38, 0xef, 0x30, 0xc2, 0xe8, 0xcf, 0x2e, 0x72, 0x8c, 0x4d, 0x95, 0x66, 0xbf, // R..8.0....r.M.f.
210  0x0d, 0x55, 0xa3, 0x03, 0x24, 0xf1, 0xc2, 0x94, 0x1c, 0xf0, 0x72, 0x4c, 0x7b, 0x3f, 0xf0, 0x13, // .U..$.....rL{?..
211  0x26, 0x97, 0x25, 0xb0, 0x26, 0x30, 0x3f, 0xe7, 0xa9, 0x4b, 0xb7, 0xbf, 0x29, 0x5a, 0x14, 0x42, // &.%.&0?..K..)Z.B
212  0x20, 0xe6, 0xc0, 0x2e, 0x71, 0xb6, 0xb2, 0xb9, 0xb4, 0x56, 0x2c, 0x28, 0xb9, 0x5c, 0x87, 0xd5, // ...q....V,(.\..
213  0xab, 0x26, 0x6d, 0x7c, 0x19, 0x3a, 0x51, 0x33, 0x04, 0x13, 0xf8, 0x79, 0x2c, 0x36, 0xae, 0xff, // .&m|.:Q3...y,6..
214  0xce, 0x76, 0x2b, 0x21, 0xfb, 0xdb, 0xef, 0xe4, 0x0a, 0xe1, 0x8a, 0x48, 0x3f, 0x58, 0xfe, 0xd7, // .v+!.......H?X..
215  0xa0, 0xea, 0x6d, 0x75, 0x57, 0xf4, 0x71, 0x0e, 0x91, 0xc5, 0x29, 0xb3, 0x91, 0x93, 0x9e, 0x27, // ..muW.q...)....'
216  0xfc, 0xe8, 0x36, 0x79, 0xd7, 0x96, 0xa1, 0xef, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x01, // ..6y............
217  0xb4, 0x30, 0x82, 0x01, 0xb0, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, // .0...0...U......
218  0xcf, 0xfd, 0xaf, 0x08, 0x54, 0x3d, 0x74, 0x5a, 0xc8, 0x81, 0x4f, 0x80, 0xa0, 0x5e, 0xb8, 0xbe, // ....T=tZ..O..^..
219  0x16, 0x2d, 0x0f, 0xb1, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, // .-..0...U.......
220  0x03, 0x02, 0x02, 0xf4, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, // ....0...U.......
221  0x30, 0x00, 0x30, 0x81, 0x8d, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x81, 0x85, 0x30, 0x81, 0x82, // 0.0....U.#...0..
222  0x80, 0x14, 0xcf, 0xfd, 0xaf, 0x08, 0x54, 0x3d, 0x74, 0x5a, 0xc8, 0x81, 0x4f, 0x80, 0xa0, 0x5e, // ......T=tZ..O..^
223  0xb8, 0xbe, 0x16, 0x2d, 0x0f, 0xb1, 0xa1, 0x64, 0xa4, 0x62, 0x30, 0x60, 0x31, 0x1f, 0x30, 0x1d, // ...-...d.b0`1.0.
224  0x06, 0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x0f, 0x74, 0x72, // ....&...,d....tr
225  0x65, 0x77, 0x77, 0x2d, 0x61, 0x35, 0x38, 0x35, 0x35, 0x35, 0x37, 0x31, 0x62, 0x31, 0x0b, 0x30, // eww-a5855571b1.0
226  0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, // ...U....US1.0...
227  0x55, 0x04, 0x0a, 0x13, 0x07, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x31, 0x1e, 0x30, 0x1c, // U....Unknown1.0.
228  0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x15, 0x4b, 0x45, 0x50, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, // ..U....KEPServer
229  0x45, 0x58, 0x2f, 0x55, 0x41, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x82, 0x04, 0x84, 0x79, // EX/UA Server...y
230  0x20, 0xf2, 0x30, 0x20, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01, 0xff, 0x04, 0x16, 0x30, 0x14, // .0 ..U.%.....0.
231  0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, // ..+.........+...
232  0x05, 0x07, 0x03, 0x02, 0x30, 0x6d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x86, 0xf8, 0x42, 0x01, // ....0m..`.H...B.
233  0x0d, 0x04, 0x60, 0x16, 0x5e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, // ..`.^Generated b
234  0x79, 0x20, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4d, 0x40, 0x74, 0x72, 0x65, 0x77, 0x77, 0x2d, 0x61, // y SYSTEM@treww-a
235  0x35, 0x38, 0x35, 0x35, 0x35, 0x37, 0x31, 0x62, 0x20, 0x6f, 0x6e, 0x20, 0x32, 0x30, 0x31, 0x32, // 5855571b on 2012
236  0x2d, 0x31, 0x31, 0x2d, 0x30, 0x34, 0x54, 0x30, 0x36, 0x3a, 0x33, 0x38, 0x3a, 0x34, 0x35, 0x2e, // -11-04T06:38:45.
237  0x32, 0x32, 0x39, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x4f, 0x70, 0x65, 0x6e, 0x53, 0x53, // 229 using OpenSS
238  0x4c, 0x20, 0x31, 0x2e, 0x30, 0x2e, 0x30, 0x64, 0x20, 0x38, 0x20, 0x46, 0x65, 0x62, 0x20, 0x32, // L 1.0.0d 8 Feb 2
239  0x30, 0x31, 0x31, 0x30, 0x50, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x49, 0x30, 0x47, 0x86, 0x34, // 0110P..U...I0G.4
240  0x75, 0x72, 0x6e, 0x3a, 0x74, 0x72, 0x65, 0x77, 0x77, 0x2d, 0x61, 0x35, 0x38, 0x35, 0x35, 0x35, // urn:treww-a58555
241  0x37, 0x31, 0x62, 0x3a, 0x4b, 0x65, 0x70, 0x77, 0x61, 0x72, 0x65, 0x2e, 0x4b, 0x45, 0x50, 0x53, // 71b:Kepware.KEPS
242  0x65, 0x72, 0x76, 0x65, 0x72, 0x45, 0x58, 0x2e, 0x56, 0x35, 0x3a, 0x55, 0x41, 0x20, 0x53, 0x65, // erverEX.V5:UA Se
243  0x72, 0x76, 0x65, 0x72, 0x82, 0x0f, 0x74, 0x72, 0x65, 0x77, 0x77, 0x2d, 0x61, 0x35, 0x38, 0x35, // rver..treww-a585
244  0x35, 0x35, 0x37, 0x31, 0x62, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, // 5571b0...*.H....
245  0x01, 0x05, 0x05, 0x00, 0x03, 0x81, 0x81, 0x00, 0x36, 0x3d, 0x98, 0xdc, 0xc8, 0xa2, 0x48, 0xfe, // ........6=....H.
246  0xbd, 0xc1, 0xdb, 0xf9, 0xfb, 0x32, 0x3b, 0x3d, 0x43, 0x6c, 0xff, 0xd3, 0x9d, 0xa0, 0x96, 0x80, // .....2;=Cl......
247  0x8a, 0x99, 0x0b, 0x19, 0x2b, 0x77, 0xd0, 0xd7, 0x66, 0x26, 0x45, 0xe4, 0x72, 0x5b, 0x7b, 0x62, // ....+w..f&E.r[{b
248  0xb6, 0x16, 0x25, 0x8c, 0xdf, 0x06, 0x53, 0x89, 0xb4, 0x19, 0x5d, 0xb3, 0x85, 0x50, 0x83, 0x86, // ..%...S...]..P..
249  0x1f, 0xc5, 0xa3, 0xc7, 0x8d, 0xd7, 0x0b, 0x0b, 0xfe, 0xd3, 0xb2, 0x54, 0x88, 0x9c, 0x41, 0xfd, // ...........T..A.
250  0x31, 0x83, 0x16, 0x49, 0x1e, 0x21, 0x16, 0xc5, 0x30, 0xaf, 0x72, 0xf2, 0x9b, 0x63, 0xe2, 0x96, // 1..I.!..0.r..c..
251  0x70, 0x97, 0x3c, 0x79, 0x4a, 0x58, 0x56, 0x9f, 0x2b, 0xa7, 0x66, 0x83, 0xd8, 0x43, 0xcf, 0x2b, // p.<yJXV.+.f..C.+
252  0xfe, 0x9b, 0x04, 0xa6, 0x8f, 0xa3, 0x23, 0x83, 0xff, 0x4f, 0xc7, 0x91, 0xa0, 0x9e, 0xfb, 0x5b, // ......#..O.....[
253  0x6c, 0xfe, 0xb7, 0x56, 0xee, 0x87, 0x1e, 0x89, 0x01, 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, // l..V......../...
254  0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6f, 0x70, 0x63, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x61, // http://opcfounda
255  0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x55, 0x41, 0x2f, 0x53, 0x65, 0x63, 0x75, // tion.org/UA/Secu
256  0x72, 0x69, 0x74, 0x79, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x23, 0x4e, 0x6f, 0x6e, 0x65, 0x02, // rityPolicy#None.
257  0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x41, 0x6e, 0x6f, 0x6e, 0x79, 0x6d, 0x6f, 0x75, 0x73, // .......Anonymous
258  0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // ................
259  0x08, 0x00, 0x00, 0x00, 0x55, 0x73, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x01, 0x00, 0x00, 0x00, // ....UserName....
260  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x38, 0x00, 0x00, 0x00, 0x68, 0x74, 0x74, 0x70, // ........8...http
261  0x3a, 0x2f, 0x2f, 0x6f, 0x70, 0x63, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, // ://opcfoundation
262  0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x55, 0x41, 0x2f, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, // .org/UA/Security
263  0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x23, 0x42, 0x61, 0x73, 0x69, 0x63, 0x31, 0x32, 0x38, 0x52, // Policy#Basic128R
264  0x73, 0x61, 0x31, 0x35, 0x41, 0x00, 0x00, 0x00, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6f, // sa15A...http://o
265  0x70, 0x63, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x6f, 0x72, 0x67, // pcfoundation.org
266  0x2f, 0x55, 0x41, 0x2d, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x2f, 0x54, 0x72, 0x61, 0x6e, // /UA-Profile/Tran
267  0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x75, 0x61, 0x74, 0x63, 0x70, 0x2d, 0x75, 0x61, 0x73, 0x63, // sport/uatcp-uasc
268  0x2d, 0x75, 0x61, 0x62, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // -uabinary.......
269  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, // ................
270  0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, // ................
271  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, // ................
272  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, // ................
273  0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, // ................
274  0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, // ................
275  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, // ................
276  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, // ................
277  0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, // ................
278  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, // ................
279  0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, // ................
280  0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // ................
281  0xff, 0x00
282 }; // ..
283 
284 TEST_F(EndpointsDeserialization, GetEndpointsResponseReal)
285 {
286  using namespace OpcUa;
287  using namespace OpcUa::Binary;
288 
289  GetChannel().SetData(std::vector<char>(GetEndpointsResponseRealData.begin(), GetEndpointsResponseRealData.end()));
290 
291  SecureHeader responseHeader;
292  GetStream() >> responseHeader;
293 
294  SymmetricAlgorithmHeader responseAlgo;
295  GetStream() >> responseAlgo;
296 
297  SequenceHeader responseSequence;
298  GetStream() >> responseSequence; // TODO Check for request Number
299 
300  GetEndpointsResponse response;
301  GetStream() >> response;
302 
306 
307  ASSERT_EQ(response.Endpoints.size(), 5);
308 
309  ASSERT_TRUE(Channel->IsEmpty());
310 }
311 
312 
313 //-------------------------------------------------------
314 // FindServersParameters
315 //-------------------------------------------------------
316 
318 {
319 
320  using namespace OpcUa;
321  using namespace OpcUa::Binary;
322 
323  FindServersParameters params;
324 
325  params.EndpointUrl = "url";
326  params.Locales.push_back("en");
327  params.ServersToReturn.push_back("server");
328 
329  GetStream() << params << flush;
330 
331  const std::vector<char> expectedData =
332  {
333  3, 0, 0, 0, 'u', 'r', 'l',
334  1, 0, 0, 0, 2, 0, 0, 0, 'e', 'n',
335  1, 0, 0, 0, 6, 0, 0, 0, 's', 'e', 'r', 'v', 'e', 'r'
336  };
337 
338  ASSERT_EQ(expectedData, GetChannel().SerializedData);
339  ASSERT_EQ(expectedData.size(), RawSize(params));
340 }
341 
343 {
344 
345  using namespace OpcUa;
346  using namespace OpcUa::Binary;
347 
348  const std::vector<char> expectedData =
349  {
350  3, 0, 0, 0, 'u', 'r', 'l',
351  1, 0, 0, 0, 2, 0, 0, 0, 'e', 'n',
352  1, 0, 0, 0, 6, 0, 0, 0, 's', 'e', 'r', 'v', 'e', 'r'
353  };
354 
355  GetChannel().SetData(expectedData);
356 
357  FindServersParameters params;
358  GetStream() >> params;
359 
360  ASSERT_EQ(params.EndpointUrl, "url");
361  ASSERT_EQ(params.Locales.size(), 1);
362  ASSERT_EQ(params.Locales[0], "en");
363  ASSERT_EQ(params.ServersToReturn.size(), 1);
364  ASSERT_EQ(params.ServersToReturn[0], "server");
365 }
366 
367 //-------------------------------------------------------
368 // FindServersRequest
369 //-------------------------------------------------------
370 
372 {
373 
374  using namespace OpcUa;
375  using namespace OpcUa::Binary;
376 
377  FindServersRequest request;
378 
382 
384  request.Parameters.EndpointUrl = "url";
385  request.Parameters.Locales.push_back("en");
386  request.Parameters.ServersToReturn.push_back("server");
387 
388 
389  GetStream() << request << flush;
390 
391  const std::vector<char> expectedData =
392  {
393  1, 0, (char)0xa6, 0x1, // TypeId
394  // RequestHeader
396  3, 0, 0, 0, 'u', 'r', 'l',
397  1, 0, 0, 0, 2, 0, 0, 0, 'e', 'n',
398  1, 0, 0, 0, 6, 0, 0, 0, 's', 'e', 'r', 'v', 'e', 'r'
399  };
400 
401  ASSERT_EQ(expectedData, GetChannel().SerializedData);
402  ASSERT_EQ(expectedData.size(), RawSize(request));
403 }
404 
406 {
407  using namespace OpcUa;
408  using namespace OpcUa::Binary;
409 
410  const std::vector<char> expectedData =
411  {
412  1, 0, (char)0xa6, 0x1, // TypeId
413  // RequestHeader
415  3, 0, 0, 0, 'u', 'r', 'l',
416  1, 0, 0, 0, 2, 0, 0, 0, 'e', 'n',
417  1, 0, 0, 0, 6, 0, 0, 0, 's', 'e', 'r', 'v', 'e', 'r'
418  };
419 
420  GetChannel().SetData(expectedData);
421 
422  FindServersRequest request;
423  GetStream() >> request;
424 
428 
430 
431  ASSERT_EQ(request.Parameters.EndpointUrl, "url");
432  ASSERT_EQ(request.Parameters.Locales, std::vector<std::string>(1, "en"));
433  ASSERT_EQ(request.Parameters.ServersToReturn, std::vector<std::string>(1, "server"));
434 }
435 
436 //----------------------------------------------------
437 // FindServersResponse
438 //----------------------------------------------------
439 
441 {
442 
443  using namespace OpcUa;
444  using namespace OpcUa::Binary;
445 
446  FindServersResponse response;
447 
451 
453 
456  response.Data.Descriptions.push_back(desc);
457 
458  GetStream() << response << flush;
459 
460  const std::vector<char> expectedData =
461  {
462  1, 0, (char)0xa9, 0x1, // TypeId
463  // RequestHeader
465 
466  1, 0, 0, 0,
468  };
469 
470  ASSERT_EQ(expectedData, GetChannel().SerializedData);
471  ASSERT_EQ(expectedData.size(), RawSize(response));
472 }
473 
475 {
476  using namespace OpcUa;
477  using namespace OpcUa::Binary;
478 
479  const std::vector<char> expectedData =
480  {
481  1, 0, (char)0xa9, 0x1, // TypeId
482  // RequestHeader
484 
485  1, 0, 0, 0,
487  };
488 
489  GetChannel().SetData(expectedData);
490 
491  FindServersResponse response;
492  GetStream() >> response;
493 
497 
499 
500  ASSERT_EQ(response.Data.Descriptions.size(), 1);
502 
503  ASSERT_TRUE(Channel->IsEmpty());
504 }
std::vector< ApplicationDescription > Descriptions
TEST_F(EndpointsSerialization, GetEndpointsRequest)
#define TEST_RESPONSE_HEADER_BINARY_DATA
std::vector< LocaleId > Locales
#define ASSERT_ENDPOINT_EQ(e)
#define TEST_ENDPOINT_BINARY_DATA
#define ASSERT_REQUEST_HEADER_EQ(header)
OStream< ChannelType > & flush(OStream< ChannelType > &os)
Definition: stream.h:147
#define FILL_APPLICATION_DESCRIPTION(desc)
#define FILL_TEST_RESPONSE_HEADER(header)
const std::vector< unsigned char > GetEndpointsResponseRealData
#define TEST_REQUEST_HEADER_BINARY_DATA
#define FILL_TEST_REQUEST_HEADER(header)
OpcUa::RequestHeader Header
std::shared_ptr< OutputChannel > Channel
struct OpcUa::NodeId::FourByteDataType FourByteData
OPC UA Address space part. GNU LGPL.
#define ASSERT_TRUE(condition)
#define ASSERT_RESPONSE_HEADER_EQ(header)
std::vector< std::string > LocaleIds
#define ASSERT_EQ(val1, val2)
OpcUa::ResponseHeader Header
OpcUa::GetEndpointsParameters Parameters
NodeIdEncoding Encoding
Definition: nodeid.h:46
#define TEST_APPLICATION_DESCRIPTION_BINARY_DATA
std::vector< std::string > ServersToReturn
#define FILL_TEST_ENDPOINT(endpoint)
#define ASSERT_APPLICATION_DESCRIPTION_EQ(desc)
FindServersParameters Parameters
Test of opc ua binary handshake. GNU LGPL.
std::vector< std::string > ProfileUris
std::vector< OpcUa::EndpointDescription > Endpoints
std::size_t RawSize(const T &obj)


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