binary_serialize.cpp
Go to the documentation of this file.
1 
11 #include "common.h"
12 
13 using namespace testing;
14 using namespace OpcUa::Binary;
15 
16 TEST_F(OpcUaBinarySerialization, LeftShiftAddsData)
17 {
18  uint8_t dataForSerialize = 1;
19  const std::vector<char> expectedData = {1, 1};
20  GetStream() << dataForSerialize;
21  GetStream() << dataForSerialize;
22  GetStream() << flush;
23  ASSERT_EQ(expectedData, GetChannel().SerializedData);
24 }
25 
27 {
28  uint8_t dataForSerialize = 1;
29  const std::vector<char> expectedData = {1};
30  GetStream() << dataForSerialize << flush;
31  GetStream() << dataForSerialize << flush;
32  ASSERT_EQ(expectedData, GetChannel().SerializedData);
33 }
34 
35 //---------------------------------------------------------------------
36 // Integer types
37 //---------------------------------------------------------------------
38 
40 {
41  uint8_t dataForSerialize = 1;
42  const std::vector<char> expectedData = { 1 };
43  GetStream() << dataForSerialize << flush;
44  ASSERT_EQ(expectedData, GetChannel().SerializedData);
45 }
46 
48 {
49  int8_t dataForSerialize = 1;
50  const std::vector<char> expectedData = { 1 };
51  GetStream() << dataForSerialize << flush;
52  ASSERT_EQ(expectedData, GetChannel().SerializedData);
53 }
54 
56 {
57  uint16_t dataForSerialize = 0x0102;
58  const std::vector<char> expectedData = {2, 1};
59  GetStream() << dataForSerialize << flush;
60  ASSERT_EQ(expectedData, GetChannel().SerializedData);
61 }
62 
64 {
65  int16_t dataForSerialize = 0x0102;
66  const std::vector<char> expectedData = {2, 1};
67  GetStream() << dataForSerialize << flush;
68  ASSERT_EQ(expectedData, GetChannel().SerializedData);
69 }
70 
72 {
73  uint32_t dataForSerialize = 0x01020304;
74  const std::vector<char> expectedData = {4, 3, 2, 1};
75  GetStream() << dataForSerialize << flush;
76  ASSERT_EQ(expectedData, GetChannel().SerializedData);
77 }
78 
80 {
81  int32_t dataForSerialize = 0x01020304;
82  const std::vector<char> expectedData = {4, 3, 2, 1};
83  GetStream() << dataForSerialize << flush;
84  ASSERT_EQ(expectedData, GetChannel().SerializedData);
85 }
86 
88 {
89  uint64_t dataForSerialize = 0x0102030405060708;
90  const std::vector<char> expectedData = {8, 7, 6, 5, 4, 3, 2, 1};
91  GetStream() << dataForSerialize << flush;
92  ASSERT_EQ(expectedData, GetChannel().SerializedData);
93 }
94 
96 {
97  int64_t dataForSerialize = 0x0102030405060708;
98  const std::vector<char> expectedData = {8, 7, 6, 5, 4, 3, 2, 1};
99  GetStream() << dataForSerialize << flush;
100  ASSERT_EQ(expectedData, GetChannel().SerializedData);
101 }
102 
104 {
105  OpcUa::DateTime dataForSerialize(0x0102030405060708);
106  const std::vector<char> expectedData = {8, 7, 6, 5, 4, 3, 2, 1};
107  GetStream() << dataForSerialize << flush;
108  ASSERT_EQ(expectedData, GetChannel().SerializedData);
109 }
110 
112 {
113  OpcUa::Guid dataForSerialize;
114  dataForSerialize.Data1 = 0x01020304;
115  dataForSerialize.Data2 = 0x0506;
116  dataForSerialize.Data3 = 0x0708;
117 
118  for (unsigned i = 0; i < 8; ++i)
119  {
120  dataForSerialize.Data4[i] = i + 1;
121  }
122 
123  const std::vector<char> expectedData =
124  {
125  4, 3, 2, 1,
126  6, 5,
127  8, 7,
128  1, 2, 3, 4, 5, 6, 7, 8
129  };
130  GetStream() << dataForSerialize << flush;
131  ASSERT_EQ(expectedData, GetChannel().SerializedData);
132 }
133 //-------------------------------------------------------------
134 // Floating point
135 //-------------------------------------------------------------
136 
138 {
139  float dataForSerialize = -6.5;
140  const std::vector<char> expectedData = {0, 0, (char)0xD0, (char)0xC0};
141  GetStream() << dataForSerialize << flush;
142  ASSERT_EQ(expectedData, GetChannel().SerializedData);
143 }
144 
146 {
147  double dataForSerialize = 1200000;
148 // const std::vector<char> expectedData = {(char)0xC0, (char)0x1A, 0, 0, 0, 0, 0, 0};
149  const std::vector<char> expectedData = {0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41};
150  GetStream() << dataForSerialize << flush;
151  ASSERT_EQ(expectedData, GetChannel().SerializedData);
152 }
153 
154 //-------------------------------------------------------------
155 // String
156 //-------------------------------------------------------------
157 
159 {
160  std::string dataForSerialize = {'u', 'r', 'l'};
161  const std::vector<char> expectedData = {3, 0, 0, 0, 'u', 'r', 'l'};
162  GetStream() << dataForSerialize << flush;
163  ASSERT_EQ(expectedData, GetChannel().SerializedData);
164 }
165 
167 {
168  std::string dataForSerialize;
169  const std::vector<char> expectedData(4, ~char());
170  GetStream() << dataForSerialize << flush;
171  ASSERT_EQ(expectedData, GetChannel().SerializedData);
172 }
173 
174 
175 //-------------------------------------------------------------
176 // ByteString
177 //-------------------------------------------------------------
178 
180 {
181  std::vector<uint8_t> dataForSerialize = {'u', 'r', 'l'};
182  const std::vector<char> expectedData = {3, 0, 0, 0, 'u', 'r', 'l'};
183  GetStream() << dataForSerialize << flush;
184  ASSERT_EQ(expectedData, GetChannel().SerializedData);
185 }
186 
188 {
189  GetStream() << std::vector<uint8_t>() << flush;
190  ASSERT_EQ(std::vector<char>(4, -1), GetChannel().SerializedData);
191 }
192 
193 
194 //-------------------------------------------------------------
195 // RawMessage
196 //-------------------------------------------------------------
198 {
199  const std::vector<char> expectedData = {8, 7, 6, 5, 4, 3, 2, 1};
200  GetStream() << OpcUa::Binary::RawMessage(&expectedData[0], expectedData.size()) << flush;
201  ASSERT_EQ(expectedData, GetChannel().SerializedData);
202 }
203 
204 //-------------------------------------------------------------
205 // LocalizedText
206 //-------------------------------------------------------------
207 
208 TEST_F(OpcUaBinarySerialization, LocalizedText_Full)
209 {
210  using namespace OpcUa;
211  using namespace OpcUa::Binary;
212 
213  LocalizedText lt;
215  lt.Locale = "en";
216  lt.Text = "text";
217 
218  GetStream() << lt << flush;
219 
220  const std::vector<char> expectedData = {3, 2, 0, 0, 0, 'e', 'n', 4, 0, 0, 0, 't', 'e', 'x', 't'};
221  ASSERT_EQ(expectedData, GetChannel().SerializedData);
222  ASSERT_EQ(RawSize(lt), expectedData.size());
223 }
224 
225 TEST_F(OpcUaBinarySerialization, LocalizedText_Locale)
226 {
227  using namespace OpcUa;
228  using namespace OpcUa::Binary;
229 
230  LocalizedText lt;
231  lt.Encoding = HAS_LOCALE;
232  lt.Locale = "en";
233  lt.Text = "text";
234 
235  GetStream() << lt << flush;
236 
237  const std::vector<char> expectedData = {1, 2, 0, 0, 0, 'e', 'n'};
238  ASSERT_EQ(expectedData, GetChannel().SerializedData);
239  ASSERT_EQ(RawSize(lt), expectedData.size());
240 }
241 
242 TEST_F(OpcUaBinarySerialization, LocalizedText_Text)
243 {
244  using namespace OpcUa;
245  using namespace OpcUa::Binary;
246 
247  LocalizedText lt;
248  lt.Encoding = HAS_TEXT;
249  lt.Locale = "en";
250  lt.Text = "text";
251 
252  GetStream() << lt << flush;
253 
254  const std::vector<char> expectedData = {2, 4, 0, 0, 0, 't', 'e', 'x', 't'};
255  ASSERT_EQ(expectedData, GetChannel().SerializedData);
256  ASSERT_EQ(RawSize(lt), expectedData.size());
257 }
258 
259 
260 
261 //-------------------------------------------------------------
262 // Message type
263 //-------------------------------------------------------------
264 
266 {
267  const std::vector<char> expectedData = {'H', 'E', 'L'};
268  GetStream() << OpcUa::Binary::MT_HELLO << flush;
269  ASSERT_EQ(expectedData, GetChannel().SerializedData);
270 }
271 
272 TEST_F(OpcUaBinarySerialization, MessageAcknowledge)
273 {
274  const std::vector<char> expectedData = {'A', 'C', 'K'};
275  GetStream() << OpcUa::Binary::MT_ACKNOWLEDGE << flush;
276  ASSERT_EQ(expectedData, GetChannel().SerializedData);
277 }
278 
280 {
281  const std::vector<char> expectedData = {'E', 'R', 'R'};
282  GetStream() << OpcUa::Binary::MT_ERROR << flush;
283  ASSERT_EQ(expectedData, GetChannel().SerializedData);
284 }
285 
287 {
288  const std::vector<char> expectedData = {'O', 'P', 'N'};
289  GetStream() << OpcUa::Binary::MT_SECURE_OPEN << flush;
290  ASSERT_EQ(expectedData, GetChannel().SerializedData);
291 }
292 
294 {
295  const std::vector<char> expectedData = {'C', 'L', 'O'};
296  GetStream() << OpcUa::Binary::MT_SECURE_CLOSE << flush;
297  ASSERT_EQ(expectedData, GetChannel().SerializedData);
298 }
299 
301 {
302  ASSERT_THROW(GetStream() << static_cast<OpcUa::Binary::MessageType>(-1), std::logic_error);
303 }
304 
305 //------------------------------------------------------------
306 // Chunk types
307 //------------------------------------------------------------
308 
310 {
311  const std::vector<char> expectedData = {'F'};
312  GetStream() << OpcUa::Binary::CHT_SINGLE << flush;
313  ASSERT_EQ(expectedData, GetChannel().SerializedData);
314 }
315 
316 TEST_F(OpcUaBinarySerialization, ChunkIntermediate)
317 {
318  const std::vector<char> expectedData = {'C'};
319  GetStream() << OpcUa::Binary::CHT_INTERMEDIATE << flush;
320  ASSERT_EQ(expectedData, GetChannel().SerializedData);
321 }
322 
324 {
325  const std::vector<char> expectedData = {'A'};
326  GetStream() << OpcUa::Binary::CHT_FINAL << flush;
327  ASSERT_EQ(expectedData, GetChannel().SerializedData);
328 }
329 
331 {
332  ASSERT_THROW(GetStream() << static_cast<OpcUa::Binary::ChunkType>(-1), std::logic_error);
333 }
334 
335 //---------------------------------------------------------
336 // Message Header
337 //---------------------------------------------------------
338 
340 {
344  hdr.Size = 0x01020304;
345 
346  const std::vector<char> expectedData = {'H', 'E', 'L', 'F', 4, 3, 2, 1};
347  GetStream() << hdr << flush;
348  ASSERT_EQ(expectedData, GetChannel().SerializedData);
349 }
350 
351 //---------------------------------------------------------
352 // Message Header
353 //---------------------------------------------------------
354 
355 TEST_F(OpcUaBinarySerialization, SecureMessageHeader)
356 {
360  hdr.Size = 0x01020304;
361  hdr.ChannelId = 0x1;
362 
363  const std::vector<char> expectedData =
364  {
365  'H', 'E', 'L',
366  'F',
367  4, 3, 2, 1,
368  1, 0, 0, 0
369  };
370  GetStream() << hdr << flush;
371  ASSERT_EQ(expectedData, GetChannel().SerializedData);
372  ASSERT_EQ(expectedData.size(), RawSize(hdr));
373 }
374 
375 
376 //---------------------------------------------------------
377 // Hello
378 //---------------------------------------------------------
379 
381 {
383  message.ProtocolVersion = 1;
384  message.ReceiveBufferSize = 2;
385  message.SendBufferSize = 3;
386  message.MaxMessageSize = 4;
387  message.MaxChunkCount = 5;
388  message.EndpointUrl = "url";
389 
390  const std::vector<char> expectedData =
391  {
392  1, 0, 0, 0, // ProtocolVersion
393  2, 0, 0, 0, // ReceiveBufferSize
394  3, 0, 0, 0, // SendBufferSize
395  4, 0, 0, 0, // MaxMessageSize
396  5, 0, 0, 0, // MaxChunkCount
397  3, 0, 0, 0, // string size
398  'u', 'r', 'l' // Endpoint
399  };
400 
401  GetStream() << message << flush;
402  ASSERT_EQ(expectedData, GetChannel().SerializedData);
403  ASSERT_EQ(expectedData.size(), RawSize(message));
404 }
405 
406 //---------------------------------------------------------
407 // Message
408 //---------------------------------------------------------
409 
411 {
413  message.ProtocolVersion = 1;
414  message.ReceiveBufferSize = 2;
415  message.SendBufferSize = 3;
416  message.MaxMessageSize = 4;
417  message.MaxChunkCount = 5;
418 
419  const std::vector<char> expectedData =
420  {
421  1, 0, 0, 0, // ProtocolVersion
422  2, 0, 0, 0, // ReceiveBufferSize
423  3, 0, 0, 0, // SendBufferSize
424  4, 0, 0, 0, // MaxMessageSize
425  5, 0, 0, 0, // MaxChunkCount
426  };
427 
428  GetStream() << message << flush;
429  ASSERT_EQ(expectedData, GetChannel().SerializedData);
430  ASSERT_EQ(expectedData.size(), RawSize(message));
431 }
432 
433 //---------------------------------------------------------
434 // Error
435 //---------------------------------------------------------
436 
438 {
440  message.Code = 1;
441  message.Reason = "url";
442 
443  const std::vector<char> expectedData =
444  {
445  1, 0, 0, 0, // Error code
446  3, 0, 0, 0, // string size
447  'u', 'r', 'l' // Endpoint
448  };
449 
450  GetStream() << message << flush;
451  ASSERT_EQ(expectedData, GetChannel().SerializedData);
452  ASSERT_EQ(expectedData.size(), RawSize(message));
453 }
454 
455 //---------------------------------------------------------
456 // AsymmetricAlgorithmHeader
457 //---------------------------------------------------------
458 
460 {
462  header.SecurityPolicyUri = "pol";
463  header.SenderCertificate = {1, 2, 3};
464  header.ReceiverCertificateThumbPrint = {4, 5, 6};
465 
466  const std::vector<char> expectedData =
467  {
468  3, 0, 0, 0,
469  'p', 'o', 'l',
470  3, 0, 0, 0,
471  1, 2, 3,
472  3, 0, 0, 0,
473  4, 5, 6
474  };
475 
476  GetStream() << header << flush;
477  ASSERT_EQ(expectedData, GetChannel().SerializedData);
478  ASSERT_EQ(expectedData.size(), RawSize(header));
479 }
480 
481 //---------------------------------------------------------
482 // SymmetricAlgorithmHeader
483 //---------------------------------------------------------
484 
486 {
488  header.TokenId = 0x04050607;
489 
490  const std::vector<char> expectedData =
491  {
492  7, 6, 5, 4
493  };
494 
495  GetStream() << header << flush;
496  ASSERT_EQ(expectedData, GetChannel().SerializedData);
497  ASSERT_EQ(expectedData.size(), RawSize(header));
498 }
499 
500 //---------------------------------------------------------
501 // SequenceHeader
502 //---------------------------------------------------------
503 
505 {
507  header.SequenceNumber = 0x04050607;
508  header.RequestId = 0x1;
509 
510  const std::vector<char> expectedData =
511  {
512  7, 6, 5, 4,
513  1, 0, 0, 0
514  };
515 
516  GetStream() << header << flush;
517  ASSERT_EQ(expectedData, GetChannel().SerializedData);
518  ASSERT_EQ(expectedData.size(), RawSize(header));
519 }
520 
521 //-------------------------------------------------------------------
522 // AdditionalHeader
523 //-------------------------------------------------------------------
524 
526 {
527  using namespace OpcUa;
528  using namespace OpcUa::Binary;
531  header.TypeId.StringData.NamespaceIndex = 0x1;
532  header.TypeId.StringData.Identifier = "id";
533  header.TypeId.NamespaceURI = "uri";
534  header.TypeId.ServerIndex = 1;
535  header.Encoding = 1;
536 
537  const std::vector<char> expectedData =
538  {
540  1, 0,
541  2, 0, 0, 0,
542  'i', 'd',
543  3, 0, 0, 0,
544  'u', 'r', 'i',
545  1, 0, 0, 0,
546  1
547  };
548 
549  GetStream() << header << flush;
550 
551  ASSERT_EQ(expectedData, GetChannel().SerializedData);
552  ASSERT_EQ(expectedData.size(), RawSize(header));
553 }
554 
555 //-------------------------------------------------------------------
556 // RequestHeader
557 //-------------------------------------------------------------------
558 
559 
561 {
562  using namespace OpcUa;
563  using namespace OpcUa::Binary;
564 
566  FILL_TEST_REQUEST_HEADER(header);
567 
568  GetStream() << header << flush;
569 
570  const std::vector<char> expectedData =
571  {
573  };
574 
575  ASSERT_EQ(expectedData, GetChannel().SerializedData);
576  ASSERT_EQ(expectedData.size(), RawSize(header));
577 }
578 
579 //-------------------------------------------------------------------
580 // DiagnosticInfo
581 //-------------------------------------------------------------------
582 
583 TEST_F(OpcUaBinarySerialization, DiagnosticInfo_Empty)
584 {
585  using namespace OpcUa;
586  using namespace OpcUa::Binary;
587 
589  info.EncodingMask = DIM_NONE;
590 
591  GetStream() << info << flush;
592 
593  const std::vector<char> expectedData =
594  {
595  0,
596  };
597 
598  ASSERT_EQ(expectedData, GetChannel().SerializedData);
599  ASSERT_EQ(expectedData.size(), RawSize(info));
600 }
601 
602 TEST_F(OpcUaBinarySerialization, DiagnosticInfo_SymbolicId)
603 {
604  using namespace OpcUa;
605  using namespace OpcUa::Binary;
606 
609  info.SymbolicId = 2;
610 
611  GetStream() << info << flush;
612 
613  const std::vector<char> expectedData =
614  {
616  2, 0, 0, 0,
617  };
618 
619  ASSERT_EQ(expectedData, GetChannel().SerializedData);
620  ASSERT_EQ(expectedData.size(), RawSize(info));
621 }
622 
623 TEST_F(OpcUaBinarySerialization, DiagnosticInfo_SymbolicId_Namespace)
624 {
625  using namespace OpcUa;
626  using namespace OpcUa::Binary;
627 
630  info.SymbolicId = 2;
631  info.NamespaceURI = 3;
632 
633  GetStream() << info << flush;
634 
635  const std::vector<char> expectedData =
636  {
638  2, 0, 0, 0,
639  3, 0, 0, 0,
640  };
641 
642  ASSERT_EQ(expectedData, GetChannel().SerializedData);
643  ASSERT_EQ(expectedData.size(), RawSize(info));
644 }
645 
646 TEST_F(OpcUaBinarySerialization, DiagnosticInfo_SymbolicId_LocalizedText)
647 {
648  using namespace OpcUa;
649  using namespace OpcUa::Binary;
650 
653  info.SymbolicId = 2;
654  info.LocalizedText = 4;
655 
656  GetStream() << info << flush;
657 
658  const std::vector<char> expectedData =
659  {
661  2, 0, 0, 0,
662  4, 0, 0, 0,
663  };
664 
665  ASSERT_EQ(expectedData, GetChannel().SerializedData);
666  ASSERT_EQ(expectedData.size(), RawSize(info));
667 }
668 
669 TEST_F(OpcUaBinarySerialization, DiagnosticInfo_LocalizedText_Locale)
670 {
671  using namespace OpcUa;
672  using namespace OpcUa::Binary;
673 
676  info.LocalizedText = 2;
677  info.Locale = 4;
678 
679  GetStream() << info << flush;
680 
681  const std::vector<char> expectedData =
682  {
684  2, 0, 0, 0,
685  4, 0, 0, 0,
686  };
687 
688  ASSERT_EQ(expectedData, GetChannel().SerializedData);
689  ASSERT_EQ(expectedData.size(), RawSize(info));
690 }
691 
692 TEST_F(OpcUaBinarySerialization, DiagnosticInfo_AdditionalInfo)
693 {
694  using namespace OpcUa;
695  using namespace OpcUa::Binary;
696 
699  info.AdditionalInfo = "add";
700 
701  GetStream() << info << flush;
702 
703  const std::vector<char> expectedData =
704  {
706  3, 0, 0, 0,
707  'a', 'd', 'd'
708  };
709 
710  ASSERT_EQ(expectedData, GetChannel().SerializedData);
711  ASSERT_EQ(expectedData.size(), RawSize(info));
712 }
713 
714 TEST_F(OpcUaBinarySerialization, DiagnosticInfo_InnerStatusCode)
715 {
716  using namespace OpcUa;
717  using namespace OpcUa::Binary;
718 
721  info.InnerStatusCode = static_cast<StatusCode>(6);
722 
723  GetStream() << info << flush;
724 
725  const std::vector<char> expectedData =
726  {
728  6, 0, 0, 0,
729  };
730 
731  ASSERT_EQ(expectedData, GetChannel().SerializedData);
732  ASSERT_EQ(expectedData.size(), RawSize(info));
733 }
734 
735 //-------------------------------------------------------------------
736 // ResponseHeader
737 //-------------------------------------------------------------------
738 
739 
740 
742 {
743  using namespace OpcUa;
744  using namespace OpcUa::Binary;
745 
748 
749  GetStream() << header << flush;
750 
751  const std::vector<char> expectedData =
752  {
754  };
755 
756  ASSERT_EQ(expectedData, GetChannel().SerializedData);
757  ASSERT_EQ(expectedData.size(), RawSize(header));
758 }
759 
760 //-------------------------------------------------------------------
761 // OpenSecureChannelRequset
762 //-------------------------------------------------------------------
763 
764 TEST_F(OpcUaBinarySerialization, OpenSequreChannelRequest)
765 {
766  using namespace OpcUa;
767  using namespace OpcUa::Binary;
768 
769  OpenSecureChannelRequest request;
771 
772  request.Parameters.ClientProtocolVersion = 1;
773  request.Parameters.RequestType = SecurityTokenRequestType::Renew;
774  request.Parameters.SecurityMode = MessageSecurityMode::Sign;
775  request.Parameters.ClientNonce = std::vector<uint8_t>(1, 1);
776  request.Parameters.RequestLifeTime = 5;
777 
778  GetStream() << request << flush;
779 
780  const std::vector<char> expectedData =
781  {
782  1, 0, (char)0xbe, 0x1, // TypeId
783 
784  // RequestHeader
786 
787  1, 0, 0, 0,
788  (uint32_t)SecurityTokenRequestType::Renew, 0, 0, 0,
789  (uint32_t)MessageSecurityMode::Sign, 0, 0, 0,
790  1, 0, 0, 0,
791  1,
792  5, 0, 0, 0,
793  };
794 
795  ASSERT_EQ(expectedData, GetChannel().SerializedData);
796  ASSERT_EQ(expectedData.size(), RawSize(request));
797 }
798 
799 //-------------------------------------------------------------------
800 // SecurityToken
801 //-------------------------------------------------------------------
802 
804 {
805  using namespace OpcUa;
806  using namespace OpcUa::Binary;
807 
808  SecurityToken token;
809 
810  token.SecureChannelId = 1;
811  token.TokenId = 2;
812  token.CreatedAt.Value = 3;
813  token.RevisedLifetime = 4;
814 
815  GetStream() << token << flush;
816 
817  const std::vector<char> expectedData =
818  {
819  1, 0, 0, 0,
820  2, 0, 0, 0,
821  3, 0, 0, 0, 0, 0, 0, 0,
822  4, 0, 0, 0,
823  };
824 
825  ASSERT_EQ(expectedData, GetChannel().SerializedData);
826  ASSERT_EQ(expectedData.size(), RawSize(token));
827 }
828 
829 //-------------------------------------------------------------------
830 // OpenSecureChannelResponse
831 //-------------------------------------------------------------------
832 
834 {
835  using namespace OpcUa;
836  using namespace OpcUa::Binary;
837 
838  OpenSecureChannelResponse response;
839 
843 
845 
846  response.ServerProtocolVersion = 1;
848  response.ChannelSecurityToken.TokenId = 3;
849  response.ChannelSecurityToken.CreatedAt.Value = 4;
851  response.ServerNonce = std::vector<uint8_t>(1, 6);
852 
853  GetStream() << response << flush;
854 
855  const std::vector<char> expectedData =
856  {
857  1, 0, (char)0xC1, 0x1, // TypeId
858 
859  // ResponseHeader
861 
862  1, 0, 0, 0,
863  2, 0, 0, 0,
864  3, 0, 0, 0,
865  4, 0, 0, 0, 0, 0, 0, 0,
866  5, 0, 0, 0,
867  1, 0, 0, 0,
868  6
869  };
870 
871  ASSERT_EQ(expectedData, GetChannel().SerializedData);
872  ASSERT_EQ(expectedData.size(), RawSize(response));
873 }
874 
875 //-------------------------------------------------------------------
876 // CloseSecureChannelRequset
877 //-------------------------------------------------------------------
878 
879 TEST_F(OpcUaBinarySerialization, CloseSequreChannelRequest)
880 {
881  using namespace OpcUa;
882  using namespace OpcUa::Binary;
883 
885 
889 
891 
892  GetStream() << request << flush;
893 
894  const std::vector<char> expectedData =
895  {
896  1, 0, (char)0xc4, 0x1, // TypeId
897 
898  // RequestHeader
900  };
901 
902  ASSERT_EQ(expectedData, GetChannel().SerializedData);
903  ASSERT_EQ(expectedData.size(), RawSize(request));
904 }
905 
906 //----------------------------------------------------------------
907 // SignatureData
908 //----------------------------------------------------------------
909 
911 {
913  s.Signature = OpcUa::ByteString(std::vector<uint8_t> {1, 2, 3, 4});
914  s.Algorithm = "aes";
915 
916  const std::vector<char> expectedData =
917  {
918  3, 0, 0, 0, 'a', 'e', 's', // Algorithm
919  4, 0, 0, 0, 1, 2, 3, 4 // Signature
920  };
921 
922  GetStream() << s << flush;
923 
924  ASSERT_EQ(expectedData, GetChannel().SerializedData);
925  ASSERT_EQ(expectedData.size(), RawSize(s));
926 }
927 
928 //-------------------------------------------------------------------
929 // ExtensionObjectHeader
930 //-------------------------------------------------------------------
931 
933 {
934  using namespace OpcUa;
935  using namespace OpcUa::Binary;
936 
938 
939  GetStream() << header << flush;
940 
941  const std::vector<char> expectedData =
942  {
943  1, 0, (char)0x41, 0x1, // TypeId
945  };
946 
947  ASSERT_EQ(expectedData, GetChannel().SerializedData);
948  ASSERT_EQ(expectedData.size(), RawSize(header));
949 }
950 
951 //-------------------------------------------------------------------
952 // QualifiedName
953 //-------------------------------------------------------------------
954 
956 {
957  using namespace OpcUa;
958  using namespace OpcUa::Binary;
959 
960  QualifiedName name;
961 
962  name.NamespaceIndex = 1;
963  name.Name = "name";
964 
965  GetStream() << name << flush;
966 
967  const std::vector<char> expectedData =
968  {
969  1, 0,
970  4, 0, 0, 0, 'n', 'a', 'm', 'e'
971  };
972 
973  ASSERT_EQ(expectedData.size(), RawSize(name));
974  ASSERT_EQ(expectedData, GetChannel().SerializedData);
975 }
976 
977 //-------------------------------------------------------------------
978 // IntegerId
979 //-------------------------------------------------------------------
980 
982 {
983  using namespace OpcUa;
984  using namespace OpcUa::Binary;
985 
986  IntegerId id(5);
987 
988  GetStream() << id << flush;
989 
990  const std::vector<char> expectedData =
991  {
992  5, 0, 0, 0
993  };
994 
995  ASSERT_EQ(expectedData.size(), RawSize(id));
996  ASSERT_EQ(expectedData, GetChannel().SerializedData);
997 }
uint16_t Data2
Definition: guid.h:22
const uint8_t HAS_LOCALE
Definition: types.h:129
int32_t LocalizedText
Definition: types.h:217
#define TEST_RESPONSE_HEADER_BINARY_DATA
DiagnosticInfoMask
Definition: types.h:200
TEST_F(TestInfoTest, Names)
uint32_t Data1
Definition: guid.h:21
XmlRpcServer s
const uint8_t HAS_TEXT
Definition: types.h:130
std_msgs::Header * header(M &m)
std::string AdditionalInfo
Definition: types.h:219
name
Definition: setup.py:38
uint8_t Encoding
Definition: types.h:134
OStream< ChannelType > & flush(OStream< ChannelType > &os)
Definition: stream.h:147
#define ASSERT_THROW(statement, expected_exception)
#define FILL_TEST_RESPONSE_HEADER(header)
message
Definition: server.py:50
#define TEST_REQUEST_HEADER_BINARY_DATA
#define FILL_TEST_REQUEST_HEADER(header)
uint16_t Data3
Definition: guid.h:23
DiagnosticInfoMask EncodingMask
Definition: types.h:214
struct OpcUa::NodeId::FourByteDataType FourByteData
OPC UA Address space part. GNU LGPL.
int32_t SymbolicId
Definition: types.h:215
std::vector< uint8_t > ClientNonce
OpenSecureChannelParameters Parameters
uint8_t Data4[8]
Definition: guid.h:24
struct OpcUa::NodeId::StringDataType StringData
NodeIdEncoding
Definition: nodeid.h:27
#define ASSERT_EQ(val1, val2)
std::string Text
Definition: types.h:136
uint32_t ServerIndex
Definition: nodeid.h:48
StatusCode InnerStatusCode
Definition: types.h:220
NodeIdEncoding Encoding
Definition: nodeid.h:46
int64_t Value
Definition: datetime.h:49
int32_t NamespaceURI
Definition: types.h:216
SecurityTokenRequestType RequestType
ExpandedNodeId TypeId
Definition: types.h:177
std::string Locale
Definition: types.h:135
std::string NamespaceURI
Definition: nodeid.h:47
OpcUa::ByteString Signature
std::size_t RawSize(const T &obj)
std::vector< uint8_t > ServerNonce


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