binary_serialize_view.cpp
Go to the documentation of this file.
1 
11 #include "common.h"
12 
16 #include <opc/ua/protocol/types.h>
17 #include <opc/ua/protocol/view.h>
18 
19 #include <algorithm>
20 #include <stdexcept>
21 
23 {
24 };
25 
27 {
28 };
29 
30 
31 //-------------------------------------------------------
32 // BrowseDirection
33 //-------------------------------------------------------
34 
36 {
37 
38  using namespace OpcUa;
39  using namespace OpcUa::Binary;
40 
41  GetStream() << BrowseDirection::Both << flush;
42 
43  const std::vector<char> expectedData =
44  {
45  2, 0, 0, 0
46  };
47 
48  ASSERT_EQ(expectedData, GetChannel().SerializedData);
49  ASSERT_EQ(expectedData.size(), RawSize(BrowseDirection::Both));
50 }
51 
53 {
54  using namespace OpcUa;
55  using namespace OpcUa::Binary;
56 
57  const std::vector<char> expectedData =
58  {
59  2, 0, 0, 0
60  };
61 
62  GetChannel().SetData(expectedData);
63 
64  BrowseDirection direction;
65  GetStream() >> direction;
66 
67  ASSERT_EQ(direction, BrowseDirection::Both);
68 }
69 
70 //-------------------------------------------------------
71 // ViewDescription
72 //-------------------------------------------------------
73 
75 {
76 
77  using namespace OpcUa;
78  using namespace OpcUa::Binary;
79 
80  ViewDescription desc;
81 
82  desc.Id.Encoding = EV_TWO_BYTE;
83  desc.Id.TwoByteData.Identifier = 1;
84  desc.Timestamp.Value = 2;
85  desc.Version = 3;
86 
87  GetStream() << desc << flush;
88 
89  const std::vector<char> expectedData =
90  {
91  0, 1,
92  2, 0, 0, 0, 0, 0, 0, 0,
93  3, 0, 0, 0
94  };
95 
96  ASSERT_EQ(expectedData, GetChannel().SerializedData);
97  ASSERT_EQ(expectedData.size(), RawSize(desc));
98 }
99 
101 {
102 
103  using namespace OpcUa;
104  using namespace OpcUa::Binary;
105 
106  const std::vector<char> expectedData =
107  {
108  0, 1,
109  2, 0, 0, 0, 0, 0, 0, 0,
110  3, 0, 0, 0
111  };
112 
113  GetChannel().SetData(expectedData);
114 
115  ViewDescription desc;
116  GetStream() >> desc;
117 
120  ASSERT_EQ(desc.Timestamp, 2);
121  ASSERT_EQ(desc.Version, 3);
122 }
123 
124 //-------------------------------------------------------
125 // BrowseDescription
126 //-------------------------------------------------------
127 
129 {
130 
131  using namespace OpcUa;
132  using namespace OpcUa::Binary;
133 
134  BrowseDescription desc;
135 
138  desc.Direction = BrowseDirection::Inverse;
141  desc.IncludeSubtypes = true;
142  desc.NodeClasses = NodeClass::Variable;
144 
145  GetStream() << desc << flush;
146 
147  const std::vector<char> expectedData =
148  {
149  0, 1,
150  1, 0, 0, 0,
151  0, 2,
152  1,
153  2, 0, 0, 0,
154  4, 0, 0, 0
155  };
156 
157  ASSERT_EQ(expectedData, GetChannel().SerializedData);
158  ASSERT_EQ(expectedData.size(), RawSize(desc));
159 }
160 
162 {
163 
164  using namespace OpcUa;
165  using namespace OpcUa::Binary;
166 
167  const std::vector<char> expectedData =
168  {
169  0, 1,
170  1, 0, 0, 0,
171  0, 2,
172  1,
173  2, 0, 0, 0,
174  4, 0, 0, 0
175  };
176 
177  GetChannel().SetData(expectedData);
178 
179  BrowseDescription desc;
180  GetStream() >> desc;
181 
184  ASSERT_EQ(desc.Direction, BrowseDirection::Inverse);
187  ASSERT_EQ(desc.IncludeSubtypes, true);
188  ASSERT_EQ(desc.NodeClasses, NodeClass::Variable);
190 }
191 
192 //-------------------------------------------------------
193 // BrowseRequest
194 //-------------------------------------------------------
195 
197 {
198  using namespace OpcUa;
199  using namespace OpcUa::Binary;
200  BrowseDescription desc;
203  desc.Direction = BrowseDirection::Inverse;
206  desc.IncludeSubtypes = true;
207  desc.NodeClasses = NodeClass::Variable;
209  return desc;
210 }
211 
213 {
214  return
217  rhs.Direction == lhs.Direction &&
220  rhs.IncludeSubtypes == lhs.IncludeSubtypes &&
221  rhs.NodeClasses == lhs.NodeClasses &&
222  rhs.ResultMask == lhs.ResultMask;
223 }
224 
226 {
227 
228  using namespace OpcUa;
229  using namespace OpcUa::Binary;
230 
231  BrowseRequest request;
232 
236 
238 
239  request.Query.View.Id.Encoding = EV_TWO_BYTE;
240  request.Query.View.Id.TwoByteData.Identifier = 1;
241  request.Query.View.Timestamp.Value = 2;
242  request.Query.View.Version = 3;
243 
244  request.Query.MaxReferenciesPerNode = 4;
245 
246  request.Query.NodesToBrowse.push_back(CreateBrowseDescription());
247  request.Query.NodesToBrowse.push_back(CreateBrowseDescription());
248 
249  GetStream() << request << flush;
250 
251  const std::vector<char> expectedData =
252  {
253  1, 0, (char)0x0f, 0x2, // TypeId
254  // RequestHeader
256 
257  0, 1, // View.Id
258  2, 0, 0, 0, 0, 0, 0, 0, // View.TimeStamp
259  3, 0, 0, 0, // View.Version
260 
261  4, 0, 0, 0, // MaxReferenciesPerNode
262 
263  2, 0, 0, 0, // Count of Nodes
264  0, 1, 1, 0, 0, 0, 0, 2, 1, 2, 0, 0, 0, 4, 0, 0, 0, // Node 1
265  0, 1, 1, 0, 0, 0, 0, 2, 1, 2, 0, 0, 0, 4, 0, 0, 0, // Node 2
266 
267 
268  };
269 
270  ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
271  ASSERT_EQ(expectedData.size(), RawSize(request));
272 }
273 
275 {
276 
277  using namespace OpcUa;
278  using namespace OpcUa::Binary;
279 
280  const std::vector<char> expectedData =
281  {
282  1, 0, (char)0x0f, 0x2, // TypeId
283  // RequestHeader
285 
286  0, 1,
287  2, 0, 0, 0, 0, 0, 0, 0,
288  3, 0, 0, 0,
289 
290  4, 0, 0, 0,
291 
292  2, 0, 0, 0,
293  0, 1, 1, 0, 0, 0, 0, 2, 1, 2, 0, 0, 0, 4, 0, 0, 0,
294  0, 1, 1, 0, 0, 0, 0, 2, 1, 2, 0, 0, 0, 4, 0, 0, 0,
295 
296  };
297 
298  GetChannel().SetData(expectedData);
299  BrowseRequest request;
300  GetStream() >> request;
301 
305 
307 
310  ASSERT_EQ(request.Query.View.Timestamp, 2);
311  ASSERT_EQ(request.Query.View.Version, 3);
312 
314 
315  ASSERT_FALSE(request.Query.NodesToBrowse.empty());
316 
318 
319  ASSERT_TRUE(request.Query.NodesToBrowse[0] == desc);
320  ASSERT_TRUE(request.Query.NodesToBrowse[1] == desc);
321 
322 }
323 
324 //-------------------------------------------------------
325 // ReferenceDescription
326 //-------------------------------------------------------
327 
329 {
330 
331  using namespace OpcUa;
332  using namespace OpcUa::Binary;
333 
335 
338 
339  desc.IsForward = true;
340 
343 
344  desc.BrowseName.NamespaceIndex = 3;
345  desc.BrowseName.Name = "name";
346 
348  desc.DisplayName.Locale = "loc";
349  desc.DisplayName.Text = "text";
350 
352 
355 
356 
357  GetStream() << desc << flush;
358 
359  const std::vector<char> expectedData =
360  {
361  0, 1,
362  1,
363  0, 2,
364  3, 0, 4, 0, 0, 0, 'n', 'a', 'm', 'e',
365  3,
366  3, 0, 0, 0, 'l', 'o', 'c',
367  4, 0, 0, 0, 't', 'e', 'x', 't',
368  4, 0, 0, 0,
369  0, 5
370  };
371 
372  ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
373  ASSERT_EQ(expectedData.size(), RawSize(desc));
374 }
375 
377 {
378 
379  using namespace OpcUa;
380  using namespace OpcUa::Binary;
381 
382  const std::vector<char> expectedData =
383  {
384  0, 1,
385  1,
386  0, 2,
387  3, 0, 4, 0, 0, 0, 'n', 'a', 'm', 'e',
388  3,
389  3, 0, 0, 0, 'l', 'o', 'c',
390  4, 0, 0, 0, 't', 'e', 'x', 't',
391  4, 0, 0, 0,
392  0, 5
393  };
394 
395  GetChannel().SetData(expectedData);
396 
398 
399  GetStream() >> desc;
400 
403 
404  ASSERT_EQ(desc.IsForward, true);
405 
408 
410  ASSERT_EQ(desc.BrowseName.Name, "name");
411 
413  ASSERT_EQ(desc.DisplayName.Locale, "loc");
414  ASSERT_EQ(desc.DisplayName.Text, "text");
415 
417 
420 }
421 
422 //-------------------------------------------------------
423 // BrowseResult
424 //-------------------------------------------------------
425 
427 {
428  using namespace OpcUa;
429  using namespace OpcUa::Binary;
431 
434 
435  desc.IsForward = true;
436 
439 
440  desc.BrowseName.NamespaceIndex = 3;
441  desc.BrowseName.Name = "name";
442 
444  desc.DisplayName.Locale = "loc";
445  desc.DisplayName.Text = "text";
446 
448 
451  return desc;
452 }
453 
455 {
456 
457  using namespace OpcUa;
458  using namespace OpcUa::Binary;
459 
460  BrowseResult result;
461  result.Status = static_cast<OpcUa::StatusCode>(1);
462  result.ContinuationPoint = {2, 3, 4, 5};
463  result.Referencies.push_back(CreateReferenceDescription());
464 
465  GetStream() << result << flush;
466 
467  const std::vector<char> expectedData =
468  {
469  1, 0, 0, 0,
470  4, 0, 0, 0, 2, 3, 4, 5,
471 
472  1, 0, 0, 0,
473  0, 1,
474  1,
475  0, 2,
476  3, 0, 4, 0, 0, 0, 'n', 'a', 'm', 'e',
477  3,
478  3, 0, 0, 0, 'l', 'o', 'c',
479  4, 0, 0, 0, 't', 'e', 'x', 't',
480  4, 0, 0, 0,
481  0, 5
482  };
483 
484  ASSERT_EQ(expectedData.size(), RawSize(result));
485  ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
486 }
487 
489 {
490  using namespace OpcUa;
491  using namespace OpcUa::Binary;
492 
493  const std::vector<char> expectedData =
494  {
495  1, 0, 0, 0,
496  4, 0, 0, 0, 2, 3, 4, 5,
497 
498  1, 0, 0, 0,
499  0, 1,
500  1,
501  0, 2,
502  3, 0, 4, 0, 0, 0, 'n', 'a', 'm', 'e',
503  3,
504  3, 0, 0, 0, 'l', 'o', 'c',
505  4, 0, 0, 0, 't', 'e', 'x', 't',
506  4, 0, 0, 0,
507  0, 5
508  };
509 
510  GetChannel().SetData(expectedData);
511 
512  BrowseResult result;
513  GetStream() >> result;
514 
515  ASSERT_EQ(result.Status, static_cast<OpcUa::StatusCode>(1));
516  std::vector<uint8_t> cont = {2, 3, 4, 5};
517  ASSERT_EQ(result.ContinuationPoint, cont);
518  ASSERT_FALSE(result.Referencies.empty());
519 
520  const ReferenceDescription & desc = result.Referencies[0];
521  ASSERT_EQ(desc.ReferenceTypeId.Encoding, EV_TWO_BYTE);
522  ASSERT_EQ(desc.ReferenceTypeId.TwoByteData.Identifier, 1);
523  ASSERT_EQ(desc.IsForward, true);
524  ASSERT_EQ(desc.TargetNodeId.Encoding, EV_TWO_BYTE);
525  ASSERT_EQ(desc.TargetNodeId.TwoByteData.Identifier, 2);
526  ASSERT_EQ(desc.BrowseName.NamespaceIndex, 3);
527  ASSERT_EQ(desc.BrowseName.Name, "name");
528  ASSERT_EQ(desc.DisplayName.Encoding, HAS_LOCALE | HAS_TEXT);
529  ASSERT_EQ(desc.DisplayName.Locale, "loc");
530  ASSERT_EQ(desc.DisplayName.Text, "text");
531  ASSERT_EQ(desc.TargetNodeClass, NodeClass::Method);
532  ASSERT_EQ(desc.TargetNodeTypeDefinition.Encoding, EV_TWO_BYTE);
533  ASSERT_EQ(desc.TargetNodeTypeDefinition.TwoByteData.Identifier, 5);
534 }
535 
536 //-------------------------------------------------------
537 // BrowseRessponce
538 //-------------------------------------------------------
539 
541 {
542  OpcUa::BrowseResult result;
543  result.Status = static_cast<OpcUa::StatusCode>(1);
544  result.ContinuationPoint = {2, 3, 4, 5};
545  result.Referencies.push_back(CreateReferenceDescription());
546  return result;
547 }
548 
550 {
551  using namespace OpcUa;
552  using namespace OpcUa::Binary;
553 
554  BrowseResponse response;
555 
559 
561 
562  response.Results.push_back(CreateBrowseResult());
563 
564  DiagnosticInfo diag1;
566  diag1.LocalizedText = 4;
567  DiagnosticInfo diag2;
569  diag2.AdditionalInfo = "add";
570  response.Diagnostics.push_back(diag1);
571  response.Diagnostics.push_back(diag2);
572 
573  GetStream() << response << flush;
574 
575  const std::vector<char> expectedData =
576  {
577  1, 0, (char)0x12, 0x2, // TypeId
578  // RequestHeader
580 
581  // BrowseResults
582  1, 0, 0, 0,
583 
584  1, 0, 0, 0,
585  4, 0, 0, 0, 2, 3, 4, 5,
586  1, 0, 0, 0,
587  0, 1,
588  1,
589  0, 2,
590  3, 0, 4, 0, 0, 0, 'n', 'a', 'm', 'e',
591  3,
592  3, 0, 0, 0, 'l', 'o', 'c',
593  4, 0, 0, 0, 't', 'e', 'x', 't',
594  4, 0, 0, 0,
595  0, 5,
596 
597  2, 0, 0, 0,
598  // Diagnostics
599  DIM_LOCALIZED_TEXT, 4, 0, 0, 0, \
600  DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
601  };
602 
603  ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
604  ASSERT_EQ(expectedData.size(), RawSize(response));
605 }
606 
608 {
609  using namespace OpcUa;
610  using namespace OpcUa::Binary;
611 
612  const std::vector<char> expectedData =
613  {
614  1, 0, (char)0x12, 0x2, // TypeId
615  // RequestHeader
617 
618  // BrowseResults
619  1, 0, 0, 0,
620 
621  1, 0, 0, 0,
622  4, 0, 0, 0, 2, 3, 4, 5,
623  1, 0, 0, 0,
624  0, 1,
625  1,
626  0, 2,
627  3, 0, 4, 0, 0, 0, 'n', 'a', 'm', 'e',
628  3,
629  3, 0, 0, 0, 'l', 'o', 'c',
630  4, 0, 0, 0, 't', 'e', 'x', 't',
631  4, 0, 0, 0,
632  0, 5,
633 
634  2, 0, 0, 0,
635  // Diagnostics
636  DIM_LOCALIZED_TEXT, 4, 0, 0, 0, \
637  DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
638  };
639 
640 
641  GetChannel().SetData(expectedData);
642 
643  BrowseResponse response;
644  GetStream() >> response;
645 
649 
651 
652  ASSERT_EQ(response.Results.size(), 1);
653  ASSERT_EQ(response.Diagnostics.size(), 2);
654 }
655 
656 //-------------------------------------------------------
657 // BrowseNextRequest
658 //-------------------------------------------------------
659 
660 
662 {
663  using namespace OpcUa;
664  using namespace OpcUa::Binary;
665 
666  BrowseNextRequest request;
667 
671 
673 
674  request.ReleaseContinuationPoints = true;
675  request.ContinuationPoints.push_back(std::vector<uint8_t> {1});
676 
677  GetStream() << request << flush;
678 
679  const std::vector<char> expectedData =
680  {
681  1, 0, (char)0x15, 0x2, // TypeId
682  // RequestHeader
684 
685  1,
686  1, 0, 0, 0, 1, 0, 0, 0, 1
687  };
688 
689  ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
690  ASSERT_EQ(expectedData.size(), RawSize(request));
691 }
692 
694 {
695 
696  using namespace OpcUa;
697  using namespace OpcUa::Binary;
698 
699  const std::vector<char> expectedData =
700  {
701  1, 0, (char)0x15, 0x2, // TypeId
702  // RequestHeader
704 
705  1,
706  1, 0, 0, 0, 1, 0, 0, 0, 1
707  };
708 
709  GetChannel().SetData(expectedData);
710  BrowseNextRequest request;
711  GetStream() >> request;
712 
716 
718 
719  ASSERT_EQ(request.ReleaseContinuationPoints, true);
720  ASSERT_TRUE(!request.ContinuationPoints.empty());
721  ASSERT_EQ(request.ContinuationPoints[0], std::vector<uint8_t>(1, 1));
722 }
723 
724 //-------------------------------------------------------
725 // BrowseNextResponse
726 //-------------------------------------------------------
727 
729 {
730  using namespace OpcUa;
731  using namespace OpcUa::Binary;
732 
733  BrowseNextResponse response;
734 
738 
740 
741  response.Results.push_back(CreateBrowseResult());
742  DiagnosticInfo diag;
744  diag.LocalizedText = 4;
745  diag.InnerDiagnostics.reset(new DiagnosticInfo());
746  diag.InnerDiagnostics->EncodingMask = DIM_ADDITIONAL_INFO;
747  diag.InnerDiagnostics->AdditionalInfo = "add";
748  response.Diagnostics.push_back(diag);
749 
750  GetStream() << response << flush;
751 
752  const std::vector<char> expectedData =
753  {
754  1, 0, (char)0x18, 0x2, // TypeId
755  // RequestHeader
757 
758  // BrowseResults
759  1, 0, 0, 0,
760 
761  1, 0, 0, 0,
762  4, 0, 0, 0, 2, 3, 4, 5,
763  1, 0, 0, 0,
764  0, 1,
765  1,
766  0, 2,
767  3, 0, 4, 0, 0, 0, 'n', 'a', 'm', 'e',
768  3,
769  3, 0, 0, 0, 'l', 'o', 'c',
770  4, 0, 0, 0, 't', 'e', 'x', 't',
771  4, 0, 0, 0,
772  0, 5,
773 
774  1, 0, 0, 0,
775  // Diagnostics
776  static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4, 0, 0, 0, \
777  DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
778  };
779 
780  ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
781  ASSERT_EQ(expectedData.size(), RawSize(response));
782 }
783 
785 {
786  using namespace OpcUa;
787  using namespace OpcUa::Binary;
788 
789  const std::vector<char> expectedData =
790  {
791  1, 0, (char)0x18, 0x2, // TypeId
792  // RequestHeader
794 
795  // BrowseResults
796  1, 0, 0, 0,
797 
798  1, 0, 0, 0,
799  4, 0, 0, 0, 2, 3, 4, 5,
800  1, 0, 0, 0,
801  0, 1,
802  1,
803  0, 2,
804  3, 0, 4, 0, 0, 0, 'n', 'a', 'm', 'e',
805  3,
806  3, 0, 0, 0, 'l', 'o', 'c',
807  4, 0, 0, 0, 't', 'e', 'x', 't',
808  4, 0, 0, 0,
809  0, 5,
810 
811  1, 0, 0, 0,
812  // Diagnostics
813  static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4, 0, 0, 0, \
814  DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
815  };
816 
817 
818  GetChannel().SetData(expectedData);
819 
820  BrowseNextResponse response;
821  GetStream() >> response;
822 
826 
828 
829  ASSERT_EQ(response.Results.size(), 1);
830  ASSERT_EQ(response.Diagnostics.size(), 1);
831 }
832 
833 //-------------------------------------------------------
834 // BrowsePathTarget
835 //-------------------------------------------------------
836 
838 {
839  using namespace OpcUa;
840  using namespace OpcUa::Binary;
841 
843 
844  target.Node.Encoding = EV_TWO_BYTE;
845  target.Node.TwoByteData.Identifier = 1;
846  target.RemainingPathIndex = 2;
847 
848  GetStream() << target << flush;
849 
850  const std::vector<char> expectedData =
851  {
852  0, 1,
853  2, 0, 0, 0,
854  };
855 
856  ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
857  ASSERT_EQ(expectedData.size(), RawSize(target));
858 }
859 
861 {
862 
863  using namespace OpcUa;
864  using namespace OpcUa::Binary;
865 
866  const std::vector<char> expectedData =
867  {
868  0, 1,
869  2, 0, 0, 0,
870  };
871 
872  GetChannel().SetData(expectedData);
873 
875 
876  GetStream() >> target;
877 
880  ASSERT_EQ(target.RemainingPathIndex, 2);
881 }
882 
883 //-------------------------------------------------------
884 // BrowsePathTarget
885 //-------------------------------------------------------
886 
888 {
889  using namespace OpcUa;
890  using namespace OpcUa::Binary;
891 
892 
894  target.Node.Encoding = EV_TWO_BYTE;
895  target.Node.TwoByteData.Identifier = 1;
896  target.RemainingPathIndex = 2;
897 
898  BrowsePathResult result;
899  result.Status = static_cast<StatusCode>(3);
900  result.Targets.push_back(target);
901 
902  GetStream() << result << flush;
903 
904  const std::vector<char> expectedData =
905  {
906  3, 0, 0, 0,
907  1, 0, 0, 0,
908  0, 1,
909  2, 0, 0, 0,
910  };
911 
912  ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
913  ASSERT_EQ(expectedData.size(), RawSize(result));
914 }
915 
917 {
918 
919  using namespace OpcUa;
920  using namespace OpcUa::Binary;
921 
922  const std::vector<char> expectedData =
923  {
924  3, 0, 0, 0,
925  1, 0, 0, 0,
926  0, 1,
927  2, 0, 0, 0,
928  };
929 
930  GetChannel().SetData(expectedData);
931 
932  BrowsePathResult result;
933 
934  GetStream() >> result;
935 
936  ASSERT_EQ(result.Status, static_cast<StatusCode>(3));
937  ASSERT_EQ(result.Targets.size(), 1);
938  ASSERT_EQ(result.Targets[0].Node.Encoding, EV_TWO_BYTE);
939  ASSERT_EQ(result.Targets[0].Node.TwoByteData.Identifier, 1);
940  ASSERT_EQ(result.Targets[0].RemainingPathIndex, 2);
941 }
942 
943 //-------------------------------------------------------
944 // TranslateBrowsePathsResult
945 //-------------------------------------------------------
946 
948 {
949  using namespace OpcUa;
950  using namespace OpcUa::Binary;
951 
952 
954  target.Node.Encoding = EV_TWO_BYTE;
955  target.Node.TwoByteData.Identifier = 1;
956  target.RemainingPathIndex = 2;
957 
958  BrowsePathResult result;
959  result.Status = static_cast<StatusCode>(3);
960  result.Targets.push_back(target);
961 
962  TranslateBrowsePathsResult translateResult;
963  translateResult.Paths.push_back(result);
964 
965  GetStream() << translateResult << flush;
966 
967  const std::vector<char> expectedData =
968  {
969  1, 0, 0, 0, // Count of results
970  3, 0, 0, 0, // StatusCode
971  1, 0, 0, 0, // TargetsCount
972  0, 1, // TargetNode
973  2, 0, 0, 0, // Index
974 
975  0, 0, 0, 0, // Count of Diagnostics
976  };
977 
978  ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
979  ASSERT_EQ(expectedData.size(), RawSize(translateResult));
980 }
981 
983 {
984  using namespace OpcUa;
985  using namespace OpcUa::Binary;
986 
987  const std::vector<char> expectedData =
988  {
989  1, 0, 0, 0, // Count of results
990  3, 0, 0, 0, // StatusCode
991  1, 0, 0, 0, // TargetsCount
992  0, 1, // TargetNode
993  2, 0, 0, 0, // Index
994 
995  0, 0, 0, 0, // Count of Diagnostics
996  };
997 
998  GetChannel().SetData(expectedData);
999 
1000  TranslateBrowsePathsResult translateResult;
1001 
1002  GetStream() >> translateResult;
1003 
1004  ASSERT_EQ(translateResult.Paths.size(), 1);
1005  ASSERT_EQ(translateResult.Diagnostics.size(), 0);
1006 }
1007 
1008 //-------------------------------------------------------
1009 // TranslateBrowsePathsToNodeIdsResponse
1010 //-------------------------------------------------------
1011 
1013 {
1014  using namespace OpcUa;
1015  using namespace OpcUa::Binary;
1016 
1018  target.Node.Encoding = EV_TWO_BYTE;
1019  target.Node.TwoByteData.Identifier = 1;
1020  target.RemainingPathIndex = 2;
1021 
1022  BrowsePathResult result;
1023  result.Status = static_cast<StatusCode>(3);
1024  result.Targets.push_back(target);
1025 
1027  response.Result.Paths.push_back(result);
1028 
1032 
1034 
1035  DiagnosticInfo diag;
1037  diag.LocalizedText = 4;
1038  diag.InnerDiagnostics.reset(new DiagnosticInfo());
1039  diag.InnerDiagnostics->EncodingMask = DIM_ADDITIONAL_INFO;
1040  diag.InnerDiagnostics->AdditionalInfo = "add";
1041  response.Result.Diagnostics.push_back(diag);
1042 
1043  GetStream() << response << flush;
1044 
1045  const std::vector<char> expectedData =
1046  {
1047  1, 0, (char)0x2D, 0x2, // TypeId
1048  // RequestHeader
1050 
1051  // BrowseResults
1052  1, 0, 0, 0, // Count of results
1053  3, 0, 0, 0, // StatusCode
1054  1, 0, 0, 0, // TargetsCount
1055  0, 1, // TargetNode
1056  2, 0, 0, 0, // Index
1057 
1058  // Diagnostics
1059  1, 0, 0, 0, // Count
1060  static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4, 0, 0, 0, \
1061  DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
1062  };
1063 
1064  ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
1065  ASSERT_EQ(expectedData.size(), RawSize(response));
1066 }
1067 
1069 {
1070  using namespace OpcUa;
1071  using namespace OpcUa::Binary;
1072 
1073  const std::vector<char> expectedData =
1074  {
1075  1, 0, (char)0x2D, 0x2, // TypeId
1076  // RequestHeader
1078 
1079  // BrowseResults
1080  1, 0, 0, 0, // Count of results
1081  3, 0, 0, 0, // StatusCode
1082  1, 0, 0, 0, // TargetsCount
1083  0, 1, // TargetNode
1084  2, 0, 0, 0, // Index
1085 
1086  // Diagnostics
1087  1, 0, 0, 0, // Count
1088  static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4, 0, 0, 0, \
1089  DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd',
1090  };
1091 
1092  GetChannel().SetData(expectedData);
1093 
1095  GetStream() >> response;
1096 
1100 
1102 
1103  ASSERT_EQ(response.Result.Paths.size(), 1);
1104  ASSERT_EQ(response.Result.Diagnostics.size(), 1);
1105 }
1106 
1107 //-------------------------------------------------------
1108 // TranslateBrowsePathsToNodeIdsRequest
1109 //-------------------------------------------------------
1110 
1112 {
1113  using namespace OpcUa;
1114  using namespace OpcUa::Binary;
1115 
1116  RelativePathElement element;
1118  element.IsInverse = true;
1119  element.IncludeSubtypes = true;
1120  element.TargetName.NamespaceIndex = 2;
1121  element.TargetName.Name = "name";
1122 
1123  BrowsePath browse;
1124  browse.StartingNode = OpcUa::TwoByteNodeId(2);
1125  browse.Path.Elements.push_back(element);
1126 
1128  request.Parameters.BrowsePaths.push_back(browse);
1129 
1133 
1135 
1136  GetStream() << request << flush;
1137 
1138  const std::vector<char> expectedData =
1139  {
1140  1, 0, (char)0x2A, 0x2, // TypeId
1141  // RequestHeader
1143 
1144  1, 0, 0, 0, // Number of BrowsePaths
1145  0, 2,
1146  1, 0, 0, 0, // Number of Elements
1147  0, 1, // Reference Type (Two Byte Node Id)
1148  1, // IsInverse
1149  1, // IncludeSubTypes
1150  2, 0, 4, 0, 0, 0, 'n', 'a', 'm', 'e', // TargetName
1151  };
1152 
1153  ASSERT_EQ(expectedData, GetChannel().SerializedData) <<
1154  "Serialized: " << std::endl << PrintData(GetChannel().SerializedData) << std::endl <<
1155  "Expected" << std::endl << PrintData(expectedData);
1156  ASSERT_EQ(expectedData.size(), RawSize(request));
1157 }
1158 
1160 {
1161  using namespace OpcUa;
1162  using namespace OpcUa::Binary;
1163 
1164  const std::vector<char> expectedData =
1165  {
1166  1, 0, (char)0x2A, 0x2, // TypeId
1167  // RequestHeader
1169 
1170  1, 0, 0, 0, // Number of BrowsePaths
1171  0, 2, // Starting node
1172  1, 0, 0, 0, // Number of Elements
1173  0, 1, // Reference Type (Two Byte Node Id)
1174  1, // IsInverse
1175  1, // IncludeSubTypes
1176  2, 0, 4, 0, 0, 0, 'n', 'a', 'm', 'e', // TargetName
1177  };
1178 
1179  GetChannel().SetData(expectedData);
1180 
1182  GetStream() >> request;
1183 
1187 
1189 
1190  ASSERT_EQ(request.Parameters.BrowsePaths.size(), 1);
1191  const BrowsePath & browsePath = request.Parameters.BrowsePaths[0];
1192  ASSERT_EQ(browsePath.StartingNode, OpcUa::TwoByteNodeId(2));
1193  ASSERT_EQ(browsePath.Path.Elements.size(), 1);
1194 
1195  const RelativePathElement & element = browsePath.Path.Elements[0];
1196  ASSERT_TRUE(element.IncludeSubtypes);
1197  ASSERT_TRUE(element.IsInverse);
1198  ASSERT_EQ(element.ReferenceTypeId, OpcUa::TwoByteNodeId(1));
1199  ASSERT_EQ(element.TargetName.NamespaceIndex, 2);
1200  ASSERT_EQ(element.TargetName.Name, "name");
1201 }
OpcUa::BrowseResult CreateBrowseResult()
NodeId TwoByteNodeId(uint8_t value)
Definition: nodeid.h:201
const uint8_t HAS_LOCALE
Definition: types.h:129
int32_t LocalizedText
Definition: types.h:217
#define TEST_RESPONSE_HEADER_BINARY_DATA
std::vector< uint8_t > ContinuationPoint
Definition: protocol/view.h:81
OpcUa::BrowseDescription CreateBrowseDescription()
DiagnosticInfoList Diagnostics
Definition: protocol/view.h:93
DiagnosticInfoList Diagnostics
DiagnosticInfoMask
Definition: types.h:200
std::string PrintData(const std::vector< char > &vec)
Test of opc ua binary handshake. GNU LGPL.
std::vector< BrowseDescription > NodesToBrowse
Definition: protocol/view.h:50
std::vector< BrowsePath > BrowsePaths
const uint8_t HAS_TEXT
Definition: types.h:130
std::vector< BrowseResult > Results
#define ASSERT_REQUEST_HEADER_EQ(header)
std::string AdditionalInfo
Definition: types.h:219
bool operator==(const OpcUa::BrowseDescription &lhs, const OpcUa::BrowseDescription &rhs)
uint16_t NamespaceIndex
Definition: types.h:73
TranslateBrowsePathsParameters Parameters
uint8_t Encoding
Definition: types.h:134
OStream< ChannelType > & flush(OStream< ChannelType > &os)
Definition: stream.h:147
struct OpcUa::NodeId::TwoByteDataType TwoByteData
std::vector< BrowseResult > Results
Definition: protocol/view.h:92
std::shared_ptr< DiagnosticInfo > InnerDiagnostics
Definition: types.h:221
#define FILL_TEST_RESPONSE_HEADER(header)
RequestHeader Header
Definition: protocol/view.h:58
#define TEST_REQUEST_HEADER_BINARY_DATA
BrowseDirection
Definition: enums.h:173
#define FILL_TEST_REQUEST_HEADER(header)
std::vector< RelativePathElement > Elements
Definition: types.h:125
std::vector< BrowsePathResult > Paths
RelativePath Path
DiagnosticInfoMask EncodingMask
Definition: types.h:214
struct OpcUa::NodeId::FourByteDataType FourByteData
OPC UA Address space part. GNU LGPL.
#define ASSERT_TRUE(condition)
#define ASSERT_RESPONSE_HEADER_EQ(header)
#define ASSERT_EQ(val1, val2)
BrowseResultMask ResultMask
Definition: protocol/view.h:41
NodeClass
Definition: enums.h:39
std::string Text
Definition: types.h:136
std::string Name
Definition: types.h:74
#define Method
OpcUa::ReferenceDescription CreateReferenceDescription()
NodeIdEncoding Encoding
Definition: nodeid.h:46
int64_t Value
Definition: datetime.h:49
uint32_t MaxReferenciesPerNode
Definition: protocol/view.h:49
BrowseDirection Direction
Definition: protocol/view.h:37
View service set. GNU LGPL.
std::vector< ReferenceDescription > Referencies
Definition: protocol/view.h:82
std::vector< BrowsePathTarget > Targets
ResponseHeader Header
Definition: protocol/view.h:90
std::string Locale
Definition: types.h:135
TEST_F(ViewSerialization, BrowseDirection)
std::vector< std::vector< uint8_t > > ContinuationPoints
#define ASSERT_FALSE(condition)
ViewDescription View
Definition: protocol/view.h:48
const char DiagnosticInfo[]
Definition: strings.h:50
QualifiedName TargetName
Definition: types.h:120
std::size_t RawSize(const T &obj)


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