binary_deserialize.cpp
Go to the documentation of this file.
1 
11 #include "common.h"
12 
13 using namespace testing;
14 
15 //---------------------------------------------------------------------
16 // Integer types
17 //---------------------------------------------------------------------
18 
20 {
21  std::vector<char> serializedData = { -1};
22  GetChannel().SetData(serializedData);
23  uint8_t byte = 0;
24  GetStream() >> byte;
25  ASSERT_EQ(byte, 0xff);
26 }
27 
29 {
30  std::vector<char> serializedData = { -1};
31  GetChannel().SetData(serializedData);
32  int8_t byte = 0;
33  GetStream() >> byte;
34  ASSERT_EQ(byte, -1);
35 }
36 
38 {
39  std::vector<char> serializedData = {0, -1};
40  GetChannel().SetData(serializedData);
41  uint16_t word = 0;
42  GetStream() >> word;
43  ASSERT_EQ(word, 0xff00);
44 }
45 
47 {
48  std::vector<char> serializedData = {0, -1};
49  GetChannel().SetData(serializedData);
50  int16_t word = 0;
51  GetStream() >> word;
52  ASSERT_EQ(word, -256);
53 }
54 
56 {
57  std::vector<char> serializedData = {0, -1, 0, -1};
58  GetChannel().SetData(serializedData);
59  uint32_t dword = 0;
60  GetStream() >> dword;
61  ASSERT_EQ(dword, 0xff00ff00);
62 }
63 
65 {
66  std::vector<char> serializedData = {0, -1, 0, -1};
67  GetChannel().SetData(serializedData);
68  int32_t sdword = 0;
69  GetStream() >> sdword;
70  ASSERT_EQ(sdword, (int32_t)0xff00ff00);
71 }
72 
74 {
75  std::vector<char> serializedData = {0, -1, 0, -1, 0, 0, -1, -1};
76  GetChannel().SetData(serializedData);
77  uint64_t qword = 0;
78  GetStream() >> qword;
79  ASSERT_EQ(qword, 0xffff0000ff00ff00);
80 }
81 
83 {
84  std::vector<char> serializedData = {0, -1, 0, -1, 0, 0, -1, -1};
85  GetChannel().SetData(serializedData);
86  int64_t sqword = 0;
87  GetStream() >> sqword;
88  ASSERT_EQ(sqword, -281470698455296);
89 }
90 
91 //-------------------------------------------------------------
92 // Floating point
93 //-------------------------------------------------------------
94 
96 {
97  const std::vector<char> serializedData = {0, 0, (char)0xD0, (char)0xC0};
98  GetChannel().SetData(serializedData);
99  float num = 0;
100  GetStream() >> num;
101  ASSERT_EQ(num, -6.5);
102 }
103 
105 {
106  std::vector<char> serializedData = {0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41};
107  GetChannel().SetData(serializedData);
108  double num = 0;
109  GetStream() >> num;
110  ASSERT_EQ(num, 1200000);
111 }
112 
113 //-------------------------------------------------------------
114 // String
115 //-------------------------------------------------------------
116 
118 {
119  const std::vector<char> serializedData = {3, 0, 0, 0, 'u', 'r', 'l'};
120  GetChannel().SetData(serializedData);
121 
122  std::string deserializedString;
123  GetStream() >> deserializedString;
124 
125  std::string expectedString = {'u', 'r', 'l'};
126  ASSERT_EQ(deserializedString, expectedString);
127 }
128 /*
129 // TODO 0xFF*4 seems to be an empty string.
130 TEST_F(OpcUaBinaryDeserialization, ZeroEndStdString)
131 {
132  const std::vector<char> serializedData = {-1, -1, -1, -1, 'u', 'r', 'l',0};
133  GetChannel().SetData(serializedData);
134 
135  std::string deserializedString;
136  GetStream() >> deserializedString;
137 
138  std::string expectedString = {'u', 'r', 'l'};
139  ASSERT_EQ(deserializedString, expectedString);
140 }
141 */
143 {
144  const std::vector<char> serializedData = { -1, -1, -1, -1};
145  GetChannel().SetData(serializedData);
146 
147  std::string deserializedString;
148  GetStream() >> deserializedString;
149 
150  std::string expectedString;
151  ASSERT_EQ(deserializedString, expectedString);
152 }
153 
154 
155 //-------------------------------------------------------------
156 // ByteString
157 //-------------------------------------------------------------
158 
160 {
161  const std::vector<char> serializedData = {3, 0, 0, 0, 'u', 'r', 'l'};
162  GetChannel().SetData(serializedData);
163 
164  std::vector<uint8_t> deserializedBytes;
165  GetStream() >> deserializedBytes;
166 
167  std::vector<uint8_t> expectedBytes = {'u', 'r', 'l'};
168  ASSERT_EQ(deserializedBytes, expectedBytes);
169 }
170 
172 {
173  const std::vector<char> serializedData = { -1, -1, -1, -1};
174  GetChannel().SetData(serializedData);
175 
176  std::vector<uint8_t> deserializedBytes;
177  GetStream() >> deserializedBytes;
178 
179  std::vector<uint8_t> expectedBytes;
180  ASSERT_EQ(deserializedBytes, expectedBytes);
181 }
182 
183 //-------------------------------------------------------------
184 // RawBuffer
185 //-------------------------------------------------------------
186 
188 {
189  const std::vector<char> serializedData = {3, 0, 0, 0, 'u', 'r', 'l'};
190  GetChannel().SetData(serializedData);
191 
192  std::vector<char> deserializedBytes(serializedData.size());
193  OpcUa::Binary::RawBuffer rawBuffer(&deserializedBytes[0], deserializedBytes.size());
194  GetStream() >> rawBuffer;
195 
196  ASSERT_EQ(rawBuffer.Size, serializedData.size());
197  ASSERT_EQ(deserializedBytes, serializedData);
198 }
199 
200 //-------------------------------------------------------------
201 // LocalizedText
202 //-------------------------------------------------------------
203 
204 TEST_F(OpcUaBinaryDeserialization, LocalizedText_Full)
205 {
206  const std::vector<char> serializedData = {3, 2, 0, 0, 0, 'e', 'n', 4, 0, 0, 0, 't', 'e', 'x', 't'};
207  GetChannel().SetData(serializedData);
208 
210  GetStream() >> lt;
211 
212  ASSERT_EQ(lt.Locale, "en");
213  ASSERT_EQ(lt.Text, "text");
214 }
215 
216 TEST_F(OpcUaBinaryDeserialization, LocalizedText_Locale)
217 {
218  const std::vector<char> serializedData = {1, 2, 0, 0, 0, 'e', 'n', 4, 0, 0, 0, 't', 'e', 'x', 't'};
219  GetChannel().SetData(serializedData);
220 
222  GetStream() >> lt;
223 
224  ASSERT_EQ(lt.Locale, "en");
225  ASSERT_EQ(lt.Text, "");
226 }
227 
228 TEST_F(OpcUaBinaryDeserialization, LocalizedText_Text)
229 {
230  const std::vector<char> serializedData = {2, 2, 0, 0, 0, 'e', 'n', 4, 0, 0, 0, 't', 'e', 'x', 't'};
231  GetChannel().SetData(serializedData);
232 
234  GetStream() >> lt;
235 
236  ASSERT_EQ(lt.Locale, "");
237  ASSERT_EQ(lt.Text, "en");
238 }
239 
240 
241 //-------------------------------------------------------------
242 // Message type
243 //-------------------------------------------------------------
244 
246 {
247  const std::vector<char> serializedData = {'H', 'E', 'L'};
248  GetChannel().SetData(serializedData);
249 
251  GetStream() >> msgType;
252 
254 }
255 
256 TEST_F(OpcUaBinaryDeserialization, MessageTypeAcknowledge)
257 {
258  const std::vector<char> serializedData = {'A', 'C', 'K'};
259  GetChannel().SetData(serializedData);
260 
262  GetStream() >> msgType;
263 
265 }
266 
268 {
269  const std::vector<char> serializedData = {'E', 'R', 'R'};
270  GetChannel().SetData(serializedData);
271 
273  GetStream() >> msgType;
274 
276 }
277 
278 TEST_F(OpcUaBinaryDeserialization, MessageTypeSecureOpen)
279 {
280  const std::vector<char> serializedData = {'O', 'P', 'N'};
281  GetChannel().SetData(serializedData);
282 
284  GetStream() >> msgType;
285 
287 }
288 
289 TEST_F(OpcUaBinaryDeserialization, MessageTypeSecureClose)
290 {
291  const std::vector<char> serializedData = {'C', 'L', 'O'};
292  GetChannel().SetData(serializedData);
293 
295  GetStream() >> msgType;
296 
298 }
299 
300 TEST_F(OpcUaBinaryDeserialization, MessageTypeInvalid)
301 {
302  const std::vector<char> serializedData = {'I', 'N', 'V'};
303  GetChannel().SetData(serializedData);
304 
306  ASSERT_THROW(GetStream() >> msgType, std::logic_error);
307 }
308 
309 //------------------------------------------------------------
310 // Chunk types
311 //------------------------------------------------------------
312 
314 {
315  const std::vector<char> serializedData = {'F'};
316  GetChannel().SetData(serializedData);
317 
319  GetStream() >> chunkType;
320 
322 }
323 
324 TEST_F(OpcUaBinaryDeserialization, ChunkTypeIntermediate)
325 {
326  const std::vector<char> serializedData = {'C'};
327  GetChannel().SetData(serializedData);
328 
330  GetStream() >> chunkType;
331 
333 }
334 
336 {
337  const std::vector<char> serializedData = {'A'};
338  GetChannel().SetData(serializedData);
339 
341  GetStream() >> chunkType;
342 
344 }
345 
347 {
348  const std::vector<char> serializedData = {'I'};
349  GetChannel().SetData(serializedData);
350 
352  ASSERT_THROW(GetStream() >> chunkType, std::logic_error);
353 }
354 
355 
356 //---------------------------------------------------------
357 // Message Header
358 //---------------------------------------------------------
359 
361 {
362  const std::vector<char> serializedData = {'H', 'E', 'L', 'F', 4, 3, 2, 1};
363  GetChannel().SetData(serializedData);
364 
366  GetStream() >> hdr;
367 
370  ASSERT_EQ(hdr.Size, (uint32_t)0x01020304);
371 }
372 
373 
374 //---------------------------------------------------------
375 // Message
376 //---------------------------------------------------------
377 
379 {
380  const std::vector<char> serializedData =
381  {
382  1, 0, 0, 0, // ProtocolVersion
383  2, 0, 0, 0, // ReceiveBufferSize
384  3, 0, 0, 0, // SendBufferSize
385  4, 0, 0, 0, // MaxMessageSize
386  5, 0, 0, 0, // MaxChunkCount
387  3, 0, 0, 0, // string size
388  'u', 'r', 'l' // Endpoint
389  };
390 
391  GetChannel().SetData(serializedData);
392 
394  GetStream() >> message;
395 
396  ASSERT_EQ(message.ProtocolVersion, 1);
397  ASSERT_EQ(message.ReceiveBufferSize, 2);
398  ASSERT_EQ(message.SendBufferSize, 3);
399  ASSERT_EQ(message.MaxMessageSize, 4);
400  ASSERT_EQ(message.MaxChunkCount, 5);
401  ASSERT_EQ(message.EndpointUrl, "url");
402 }
403 
405 {
406  const std::vector<char> serializedData =
407  {
408 // 4, 3, 2, 1, // ProtocolVersion
409  4, 3, 2, 1, // ReceiveBufferSize
410  4, 3, 2, 1, // SendBufferSize
411  4, 3, 2, 1, // MaxMessageSize
412  4, 3, 2, 1, // MaxChunkCount
413  3, 0, 0, 0, // string size
414  'u', 'r', 'l' // Endpoint
415  };
416 
417  GetChannel().SetData(serializedData);
418 
420  ASSERT_THROW(GetStream() >> message, std::logic_error);
421 }
422 
423 
424 //----------------------------------------------------------
425 // Acknowlefge
426 //----------------------------------------------------------
427 
429 {
430  std::vector<char> serializedData =
431  {
432  1, 0, 0, 0, // ProtocolVersion
433  2, 0, 0, 0, // ReceiveBufferSize
434  3, 0, 0, 0, // SendBufferSize
435  4, 0, 0, 0, // MaxMessageSize
436  5, 0, 0, 0, // MaxChunkCount
437  };
438 
439  GetChannel().SetData(serializedData);
440 
442  GetStream() >> message;
443 
444  ASSERT_EQ(message.ProtocolVersion, 1);
445  ASSERT_EQ(message.ReceiveBufferSize, 2);
446  ASSERT_EQ(message.SendBufferSize, 3);
447  ASSERT_EQ(message.MaxMessageSize, 4);
448  ASSERT_EQ(message.MaxChunkCount, 5);
449 }
450 
451 TEST_F(OpcUaBinaryDeserialization, InvalidAcknowledge)
452 {
453  std::vector<char> serializedData =
454  {
455 // 4, 3, 2, 1, // ProtocolVersion
456  4, 3, 2, 1, // ReceiveBufferSize
457  4, 3, 2, 1, // MaxMessageSize
458  4, 3, 2, 1, // MaxChunkCount
459  };
460 
461  GetChannel().SetData(serializedData);
462 
464  ASSERT_THROW(GetStream() >> message, std::logic_error);
465 }
466 
467 //----------------------------------------------------------
468 // Error
469 //----------------------------------------------------------
470 
472 {
473  std::vector<char> serializedData =
474  {
475  4, 3, 2, 1, // Error code
476  3, 0, 0, 0, // string size
477  'u', 'r', 'l' // Endpoint
478  };
479 
480  GetChannel().SetData(serializedData);
481 
483  ASSERT_NO_THROW(GetStream() >> message);
484 
485  uint32_t tmpInt = 0x01020304;
486  ASSERT_EQ(message.Code, tmpInt);
487  ASSERT_EQ(message.Reason, "url");
488 }
489 
491 {
492  std::vector<char> serializedData =
493  {
494 // 4, 3, 2, 1, // Error code
495  3, 0, 0, 0, // string size
496  'u', 'r', 'l' // Endpoint
497  };
498 
499  GetChannel().SetData(serializedData);
500 
502  ASSERT_THROW(GetStream() >> message, std::logic_error);
503 }
504 
505 //---------------------------------------------------------
506 // Secure Message Header
507 //---------------------------------------------------------
508 
509 TEST_F(OpcUaBinaryDeserialization, SecureMessageHeader)
510 {
511  const std::vector<char> serializedData =
512  {
513  'H', 'E', 'L',
514  'F',
515  4, 3, 2, 1,
516  1, 0, 0, 0
517  };
518 
519  GetChannel().SetData(serializedData);
520 
522  GetStream() >> hdr;
523 
526  ASSERT_EQ(hdr.Size, (uint32_t)0x01020304);
527  ASSERT_EQ(hdr.ChannelId, (uint32_t)0x1);
528 }
529 
530 //---------------------------------------------------------
531 // AsymmetricAlgorithmHeader
532 //---------------------------------------------------------
533 
535 {
536  const std::vector<char> serializedData =
537  {
538  3, 0, 0, 0,
539  'p', 'o', 'l',
540  3, 0, 0, 0,
541  1, 2, 3,
542  3, 0, 0, 0,
543  4, 5, 6
544  };
545 
546  GetChannel().SetData(serializedData);
547 
549  GetStream() >> header;
550 
551  ASSERT_EQ(header.SecurityPolicyUri, std::string("pol"));
552  const std::vector<uint8_t> cert = {1, 2, 3};
553  ASSERT_EQ(header.SenderCertificate, cert);
554  const std::vector<uint8_t> thumb = {4, 5, 6};
556 }
557 
558 //---------------------------------------------------------
559 // SymmetricAlgorithmHeader
560 //---------------------------------------------------------
561 
563 {
564  const std::vector<char> serializedData =
565  {
566  7, 6, 5, 4
567  };
568 
569  GetChannel().SetData(serializedData);
570 
572  GetStream() >> header;
573  ASSERT_EQ(header.TokenId, 0x04050607);
574 }
575 
576 //---------------------------------------------------------
577 // SequenceHeader
578 //---------------------------------------------------------
579 
581 {
582  const std::vector<char> serializedData =
583  {
584  3, 0, 0, 0,
585  1, 0, 0, 0,
586  };
587 
588  GetChannel().SetData(serializedData);
589 
591  GetStream() >> header;
592 
593  ASSERT_EQ(header.SequenceNumber, 0x3);
594  ASSERT_EQ(header.RequestId, 0x1);
595 }
596 
597 //-------------------------------------------------------------------
598 // AdditionalHeader
599 //-------------------------------------------------------------------
600 
602 {
603  using namespace OpcUa;
604 
605  const std::vector<char> expectedData =
606  {
608  1, 0,
609  2, 0, 0, 0,
610  'i', 'd',
611  3, 0, 0, 0,
612  'u', 'r', 'i',
613  1, 0, 0, 0,
614  1
615  };
616 
617  GetChannel().SetData(expectedData);
618 
619  AdditionalHeader header;
620  GetStream() >> header;
621 
622  ASSERT_EQ(header.TypeId.Encoding, uint8_t(EV_STRING | EV_NAMESPACE_URI_FLAG | EV_Server_INDEX_FLAG));
623  ASSERT_EQ(header.TypeId.StringData.NamespaceIndex, 0x1);
624  ASSERT_EQ(header.TypeId.StringData.Identifier, "id");
625  ASSERT_EQ(header.TypeId.NamespaceURI, "uri");
626  ASSERT_EQ(header.TypeId.ServerIndex, 1);
627  ASSERT_EQ(header.Encoding, 1);
628 
629  ASSERT_EQ(expectedData.size(), Binary::RawSize(header));
630 }
631 
632 //-------------------------------------------------------------------
633 // RequestHeader
634 //-------------------------------------------------------------------
635 
637 {
638  using namespace OpcUa;
639 
640  const std::vector<char> expectedData =
641  {
642  EV_TWO_BYTE, 1,
643  2, 0, 0, 0, 0, 0, 0, 0,
644  3, 0, 0, 0,
645  4, 0, 0, 0,
646  5, 0, 0, 0,
647  'a', 'u', 'd', 'i', 't',
648  5, 0, 0, 0,
649  0,
650  6,
651  8
652  };
653 
654  GetChannel().SetData(expectedData);
655 
657  GetStream() >> header;
658 
661  ASSERT_EQ(header.UtcTime, 2);
662  ASSERT_EQ(header.RequestHandle, 3);
663  ASSERT_EQ(header.ReturnDiagnostics, 4);
664  ASSERT_EQ(header.AuditEntryId, "audit");
665  ASSERT_EQ(header.Timeout, 5); // in miliseconds
668  ASSERT_EQ(header.Additional.Encoding, 8);
669 
670  ASSERT_EQ(expectedData.size(), Binary::RawSize(header));
671 }
672 
673 //-------------------------------------------------------------------
674 // DiagnosticInfo
675 //-------------------------------------------------------------------
676 
677 TEST_F(OpcUaBinaryDeserialization, DiagnosticInfo_Empty)
678 {
679  using namespace OpcUa;
680 
681  const std::vector<char> expectedData =
682  {
683  0
684  };
685 
686  GetChannel().SetData(expectedData);
687 
689  GetStream() >> info;
690  ASSERT_EQ(info.EncodingMask, 0);
691 }
692 
693 TEST_F(OpcUaBinaryDeserialization, DiagnosticInfo_SymbolicId)
694 {
695  using namespace OpcUa;
696 
697  const std::vector<char> expectedData =
698  {
700  2, 0, 0, 0,
701  };
702 
703  GetChannel().SetData(expectedData);
704 
706  GetStream() >> info;
707 
709  ASSERT_EQ(info.SymbolicId, 2);
710  ASSERT_EQ(expectedData.size(), Binary::RawSize(info));
711 }
712 
713 TEST_F(OpcUaBinaryDeserialization, DiagnosticInfo_SymbolicId_Namespace)
714 {
715  using namespace OpcUa;
716 
717  const std::vector<char> expectedData =
718  {
720  2, 0, 0, 0,
721  3, 0, 0, 0,
722  };
723 
724  GetChannel().SetData(expectedData);
725 
727  GetStream() >> info;
728 
730  ASSERT_EQ(info.SymbolicId, 2);
731  ASSERT_EQ(info.NamespaceURI, 3);
732 }
733 
734 TEST_F(OpcUaBinaryDeserialization, DiagnosticInfo_SymbolicId_LocalizedText)
735 {
736  using namespace OpcUa;
737 
738  const std::vector<char> expectedData =
739  {
741  2, 0, 0, 0,
742  4, 0, 0, 0,
743  };
744 
745  GetChannel().SetData(expectedData);
746 
748  GetStream() >> info;
749 
751  ASSERT_EQ(info.SymbolicId, 2);
752  ASSERT_EQ(info.LocalizedText, 4);
753 }
754 
755 TEST_F(OpcUaBinaryDeserialization, DiagnosticInfo_LocalizedText_Locale)
756 {
757  using namespace OpcUa;
758 
759  const std::vector<char> expectedData =
760  {
762  2, 0, 0, 0,
763  4, 0, 0, 0,
764  };
765 
766  GetChannel().SetData(expectedData);
767 
769  GetStream() >> info;
770 
772  ASSERT_EQ(info.LocalizedText, 2);
773  ASSERT_EQ(info.Locale, 4);
774 }
775 
776 TEST_F(OpcUaBinaryDeserialization, DiagnosticInfo_AdditionalInfo)
777 {
778  using namespace OpcUa;
779 
780  const std::vector<char> expectedData =
781  {
783  3, 0, 0, 0,
784  'a', 'd', 'd'
785  };
786 
787  GetChannel().SetData(expectedData);
788 
790  GetStream() >> info;
791 
793  ASSERT_EQ(info.AdditionalInfo, "add");
794 }
795 
796 TEST_F(OpcUaBinaryDeserialization, DiagnosticInfo_InnerStatusCode)
797 {
798  using namespace OpcUa;
799 
800  const std::vector<char> expectedData =
801  {
803  6, 0, 0, 0,
804  };
805 
806  GetChannel().SetData(expectedData);
807 
809  GetStream() >> info;
810 
812  ASSERT_EQ(info.InnerStatusCode, static_cast<StatusCode>(6));
813 }
814 
815 //-------------------------------------------------------------------
816 // ResponseHeader
817 //-------------------------------------------------------------------
818 
820 {
821  using namespace OpcUa;
822 
823  const std::vector<char> expectedData =
824  {
826  };
827 
828  GetChannel().SetData(expectedData);
829 
831  GetStream() >> header;
832 
834 }
835 
836 //-------------------------------------------------------------------
837 // OpenSecureChannelRequset
838 //-------------------------------------------------------------------
839 
840 TEST_F(OpcUaBinaryDeserialization, OpenSequreChannelRequest)
841 {
842  using namespace OpcUa;
843 
844  const std::vector<char> expectedData =
845  {
846  1, 0, (char)0xbe, 0x1, // TypeId
847 
848  // RequestHeader
850  1, 0, 0, 0,
851  (uint32_t)SecurityTokenRequestType::Renew, 0, 0, 0,
852  (uint32_t)MessageSecurityMode::Sign, 0, 0, 0,
853  1, 0, 0, 0,
854  1,
855  5, 0, 0, 0,
856  };
857 
858  GetChannel().SetData(expectedData);
859 
860  OpenSecureChannelRequest request;
861  GetStream() >> request;
862 
864  ASSERT_EQ(request.Parameters.RequestType, SecurityTokenRequestType::Renew);
865  ASSERT_EQ(request.Parameters.SecurityMode, MessageSecurityMode::Sign);
866  ASSERT_EQ(request.Parameters.ClientNonce, std::vector<uint8_t>(1, 1));
868 
870 }
871 
872 //-------------------------------------------------------------------
873 // SecurityToken
874 //-------------------------------------------------------------------
875 
877 {
878  using namespace OpcUa;
879 
880  const std::vector<char> expectedData =
881  {
882  1, 0, 0, 0,
883  2, 0, 0, 0,
884  3, 0, 0, 0, 0, 0, 0, 0,
885  4, 0, 0, 0,
886  };
887 
888  GetChannel().SetData(expectedData);
889 
890  SecurityToken token;
891  GetStream() >> token;
892 
893  ASSERT_EQ(token.SecureChannelId, 1);
894  ASSERT_EQ(token.TokenId, 2);
895  ASSERT_EQ(token.CreatedAt, 3);
896  ASSERT_EQ(token.RevisedLifetime, 4);
897 }
898 
899 //-------------------------------------------------------------------
900 // OpenSecureChannelResponse
901 //-------------------------------------------------------------------
902 
903 TEST_F(OpcUaBinaryDeserialization, OpenSecureChannelResponse)
904 {
905  using namespace OpcUa;
906 
907  const std::vector<char> expectedData =
908  {
909  1, 0, (char)0xC1, 0x1, // TypeId
910 
911  // ResponseHeader
913 
914  1, 0, 0, 0,
915  2, 0, 0, 0,
916  3, 0, 0, 0,
917  4, 0, 0, 0, 0, 0, 0, 0,
918  5, 0, 0, 0,
919  1, 0, 0, 0,
920  6
921  };
922 
923  GetChannel().SetData(expectedData);
924 
925  OpenSecureChannelResponse response;
926  GetStream() >> response;
927 
928  ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
929  ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
930  ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::OPEN_SECURE_CHANNEL_RESPONSE);
931 
932  ASSERT_RESPONSE_HEADER_EQ(response.Header);
933 
934  ASSERT_EQ(response.ServerProtocolVersion, 1);
935  ASSERT_EQ(response.ChannelSecurityToken.SecureChannelId, 2);
936  ASSERT_EQ(response.ChannelSecurityToken.TokenId, 3);
937  ASSERT_EQ(response.ChannelSecurityToken.CreatedAt, 4);
938  ASSERT_EQ(response.ChannelSecurityToken.RevisedLifetime, 5);
939  ASSERT_EQ(response.ServerNonce, std::vector<uint8_t>(1, 6));
940 
941 }
942 
943 //-------------------------------------------------------------------
944 // CloseSecureChannelRequset
945 //-------------------------------------------------------------------
946 
947 TEST_F(OpcUaBinaryDeserialization, CloseSequreChannelRequest)
948 {
949  using namespace OpcUa;
950 
951  const std::vector<char> expectedData =
952  {
953  1, 0, (char)0xc4, 0x1, // TypeId
954 
955  // RequestHeader
957  };
958 
959  GetChannel().SetData(expectedData);
960 
962  GetStream() >> request;
963 
965 }
966 
967 //----------------------------------------------------------------
968 // SignatureData
969 //----------------------------------------------------------------
970 
972 {
973 
974  using namespace OpcUa;
975 
976  const std::vector<char> expectedData =
977  {
978  3, 0, 0, 0, 'a', 'e', 's', // Algorithm
979  4, 0, 0, 0, 1, 2, 3, 4 // Signature
980  };
981 
982  GetChannel().SetData(expectedData);
983 
985  GetStream() >> s;
986 
987  ASSERT_EQ(s.Signature, ByteString(std::vector<uint8_t> {1, 2, 3, 4}));
988  ASSERT_EQ(s.Algorithm, "aes");
989 }
990 
991 //-------------------------------------------------------------------
992 // ExtensionObjectHeader
993 //-------------------------------------------------------------------
994 
995 TEST_F(OpcUaBinaryDeserialization, ExtensionObjectHeader)
996 {
997  using namespace OpcUa;
998 
999  const std::vector<char> expectedData =
1000  {
1001  1, 0, (char)0x41, 0x1, // TypeId
1003  };
1004 
1005  GetChannel().SetData(expectedData);
1007  GetStream() >> header;
1008 
1009  ASSERT_EQ(header.TypeId.Encoding, EV_FOUR_BYTE);
1010  ASSERT_EQ(header.TypeId.FourByteData.NamespaceIndex, 0);
1011  ASSERT_EQ(header.TypeId.FourByteData.Identifier, OpcUa::USER_IdENTIFY_TOKEN_ANONYMOUS);
1012  ASSERT_EQ(header.Encoding, HAS_BINARY_BODY);
1013 }
1014 
1015 //-------------------------------------------------------------------
1016 // QualifiedName
1017 //-------------------------------------------------------------------
1018 
1020 {
1021  using namespace OpcUa;
1022 
1023  const std::vector<char> expectedData =
1024  {
1025  1, 0,
1026  4, 0, 0, 0, 'n', 'a', 'm', 'e'
1027  };
1028 
1029  GetChannel().SetData(expectedData);
1030 
1032  GetStream() >> name;
1033 
1034  ASSERT_EQ(name.NamespaceIndex, 1);
1035  ASSERT_EQ(name.Name, "name");
1036 }
1037 
1038 //-------------------------------------------------------------------
1039 // IntegerId
1040 //-------------------------------------------------------------------
1041 
1043 {
1044  using namespace OpcUa;
1045  using namespace OpcUa::Binary;
1046 
1047  const std::vector<char> expectedData =
1048  {
1049  5, 0, 0, 0
1050  };
1051 
1052  GetChannel().SetData(expectedData);
1053 
1054  IntegerId id;
1055  GetStream() >> id;
1056 
1057  ASSERT_EQ(id, 5);
1058 }
1059 
uint32_t Timeout
Definition: types.h:193
int32_t LocalizedText
Definition: types.h:217
#define TEST_RESPONSE_HEADER_BINARY_DATA
DateTime UtcTime
Definition: types.h:189
TEST_F(TestInfoTest, Names)
std::string AuditEntryId
Definition: types.h:192
XmlRpcServer s
std_msgs::Header * header(M &m)
#define ASSERT_REQUEST_HEADER_EQ(header)
std::string AdditionalInfo
Definition: types.h:219
uint16_t NamespaceIndex
Definition: types.h:73
name
Definition: setup.py:38
struct OpcUa::NodeId::TwoByteDataType TwoByteData
#define ASSERT_THROW(statement, expected_exception)
message
Definition: server.py:50
#define TEST_REQUEST_HEADER_BINARY_DATA
DiagnosticInfoMask EncodingMask
Definition: types.h:214
#define ASSERT_NO_THROW(statement)
OPC UA Address space part. GNU LGPL.
AdditionalHeader Additional
Definition: types.h:194
int32_t SymbolicId
Definition: types.h:215
std::vector< uint8_t > ClientNonce
OpenSecureChannelParameters Parameters
#define ASSERT_RESPONSE_HEADER_EQ(header)
uint32_t RequestHandle
Definition: types.h:190
#define ASSERT_EQ(val1, val2)
std::string Text
Definition: types.h:136
ExpandedNodeId SessionAuthenticationToken
Definition: types.h:188
std::string Name
Definition: types.h:74
StatusCode InnerStatusCode
Definition: types.h:220
NodeIdEncoding Encoding
Definition: nodeid.h:46
int32_t NamespaceURI
Definition: types.h:216
uint32_t ReturnDiagnostics
Definition: types.h:191
SecurityTokenRequestType RequestType
ExpandedNodeId TypeId
Definition: types.h:177
std::string Locale
Definition: types.h:135
OpcUa::ByteString Signature
std::size_t RawSize(const T &obj)


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