binary_subscriptions.cpp
Go to the documentation of this file.
1 
11 #include "common.h"
12 
16 #include <opc/ua/protocol/types.h>
17 
18 #include <algorithm>
19 #include <stdexcept>
20 
22 {
23 };
24 
26 {
27 };
28 
29 
30 //-------------------------------------------------------
31 // SubScriptionParameters
32 //-------------------------------------------------------
33 
34 TEST_F(SubscriptionSerialization, CreateSubscriptionParameters)
35 {
36 
37  using namespace OpcUa;
38  using namespace OpcUa::Binary;
39 
41  params.RequestedPublishingInterval = 1200000;
42  params.RequestedLifetimeCount = 2;
43  params.RequestedMaxKeepAliveCount = 3;
44  params.MaxNotificationsPerPublish = 4;
45  params.PublishingEnabled = true;
46  params.Priority = 5;
47 
48  GetStream() << params << flush;
49 
50  const std::vector<char> expectedData =
51  {
52  0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
53  2, 0, 0, 0,
54  3, 0, 0, 0,
55  4, 0, 0, 0,
56  1,
57  5
58  };
59 
60  ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
61  ASSERT_EQ(expectedData.size(), RawSize(params));
62 }
63 
65 {
66  using namespace OpcUa;
67  using namespace OpcUa::Binary;
68 
69  const std::vector<char> expectedData =
70  {
71  0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
72  2, 0, 0, 0,
73  3, 0, 0, 0,
74  4, 0, 0, 0,
75  1,
76  5
77  };
78 
79  GetChannel().SetData(expectedData);
80 
82  GetStream() >> params;
83 
84  ASSERT_EQ(params.RequestedPublishingInterval, 1200000);
88  ASSERT_EQ(params.PublishingEnabled, true);
89  ASSERT_EQ(params.Priority, 5);
90 }
91 
92 //-------------------------------------------------------
93 // CreateSubscriptionRequest
94 //-------------------------------------------------------
95 
97 {
98  using namespace OpcUa;
99  using namespace OpcUa::Binary;
100 
102 
106 
108 
109  request.Parameters.RequestedPublishingInterval = 1200000;
113  request.Parameters.PublishingEnabled = true;
114  request.Parameters.Priority = 5;
115 
116  GetStream() << request << flush;
117 
118  const std::vector<char> expectedData =
119  {
120  1, 0, (char)0x13, 0x3, // TypeId
121 
122  // RequestHeader
124 
125  0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
126  2, 0, 0, 0,
127  3, 0, 0, 0,
128  4, 0, 0, 0,
129  1,
130  5
131  };
132 
133  ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
134  ASSERT_EQ(expectedData.size(), RawSize(request));
135 }
136 
138 {
139  using namespace OpcUa;
140  using namespace OpcUa::Binary;
141 
142  const std::vector<char> expectedData =
143  {
144  1, 0, (char)0x13, 0x3, // TypeId
145 
146  // RequestHeader
148 
149  0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
150  2, 0, 0, 0,
151  3, 0, 0, 0,
152  4, 0, 0, 0,
153  1,
154  5
155  };
156 
157  GetChannel().SetData(expectedData);
158 
160  GetStream() >> request;
161 
165 
167 
172  ASSERT_EQ(request.Parameters.PublishingEnabled, true);
173  ASSERT_EQ(request.Parameters.Priority, 5);
174 }
175 
176 //-------------------------------------------------------
177 // SubscriptionData
178 //-------------------------------------------------------
179 
181 {
182 
183  using namespace OpcUa;
184  using namespace OpcUa::Binary;
185 
186  SubscriptionData data;
187  data.SubscriptionId = 2;
188  data.RevisedPublishingInterval = 1200000;
189  data.RevisedLifetimeCount = 3;
190  data.RevisedMaxKeepAliveCount = 4;
191 
192  GetStream() << data << flush;
193 
194  const std::vector<char> expectedData =
195  {
196  2, 0, 0, 0,
197  0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
198  3, 0, 0, 0,
199  4, 0, 0, 0,
200  };
201 
202  ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
203  ASSERT_EQ(expectedData.size(), RawSize(data));
204 }
205 
207 {
208  using namespace OpcUa;
209  using namespace OpcUa::Binary;
210 
211  const std::vector<char> expectedData =
212  {
213  2, 0, 0, 0,
214  0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
215  3, 0, 0, 0,
216  4, 0, 0, 0,
217  };
218 
219  GetChannel().SetData(expectedData);
220 
221  SubscriptionData data;
222  GetStream() >> data;
223 
224  ASSERT_EQ(data.SubscriptionId, 2);
225  ASSERT_EQ(data.RevisedPublishingInterval, 1200000);
228 }
229 //-------------------------------------------------------
230 // CreateSubscriptionResponse
231 //-------------------------------------------------------
232 
234 {
235  using namespace OpcUa;
236  using namespace OpcUa::Binary;
237 
239 
243 
245 
246  response.Data.SubscriptionId = 2;
247  response.Data.RevisedPublishingInterval = 1200000;
248  response.Data.RevisedLifetimeCount = 3;
249  response.Data.RevisedMaxKeepAliveCount = 4;
250 
251  GetStream() << response << flush;
252 
253  const std::vector<char> expectedData =
254  {
255  1, 0, (char)0x16, 0x3, // TypeId
256 
257  // RequestHeader
259 
260  2, 0, 0, 0,
261  0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
262  3, 0, 0, 0,
263  4, 0, 0, 0,
264  };
265 
266  ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
267  ASSERT_EQ(expectedData.size(), RawSize(response));
268 }
269 
271 {
272  using namespace OpcUa;
273  using namespace OpcUa::Binary;
274 
275  const std::vector<char> expectedData =
276  {
277  1, 0, (char)0x16, 0x3, // TypeId
278 
279  // RequestHeader
281 
282  2, 0, 0, 0,
283  0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
284  3, 0, 0, 0,
285  4, 0, 0, 0,
286  };
287 
288  GetChannel().SetData(expectedData);
289 
291  GetStream() >> response;
292 
296 
298 
299  ASSERT_EQ(response.Data.SubscriptionId, 2);
300  ASSERT_EQ(response.Data.RevisedPublishingInterval, 1200000);
301  ASSERT_EQ(response.Data.RevisedLifetimeCount, 3);
303 }
304 
305 //-------------------------------------------------------
306 // SubscriptionAcknowledgement
307 //-------------------------------------------------------
308 
310 {
311 
312  using namespace OpcUa;
313  using namespace OpcUa::Binary;
314 
316  ack.SubscriptionId = 1;
317  ack.SequenceNumber = 2;
318 
319  GetStream() << ack << flush;
320 
321  const std::vector<char> expectedData =
322  {
323  1, 0, 0, 0,
324  2, 0, 0, 0,
325  };
326 
327  ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
328  ASSERT_EQ(expectedData.size(), RawSize(ack));
329 }
330 
332 {
333  using namespace OpcUa;
334  using namespace OpcUa::Binary;
335 
336  const std::vector<char> expectedData =
337  {
338  1, 0, 0, 0,
339  2, 0, 0, 0,
340  };
341 
342  GetChannel().SetData(expectedData);
343 
345  GetStream() >> ack;
346 
347  ASSERT_EQ(ack.SubscriptionId, 1);
348  ASSERT_EQ(ack.SequenceNumber, 2);
349 }
350 
351 // //-------------------------------------------------------
352 // // PublishParameters
353 // //-------------------------------------------------------
354 //
355 // TEST_F(SubscriptionSerialization, PublishParameters)
356 // {
357 // using namespace OpcUa;
358 // using namespace OpcUa::Binary;
359 //
360 // SubscriptionAcknowledgement ack;
361 // ack.SubscriptionId = 1;
362 // ack.SequenceNumber = 2;
363 //
364 // PublishParameters params;
365 // params.Acknowledgements.push_back(ack);
366 //
367 // GetStream() << params << flush;
368 //
369 // const std::vector<char> expectedData = {
370 // 1,0,0,0, // Count of acks
371 // 1,0,0,0,
372 // 2,0,0,0,
373 // };
374 //
375 // ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
376 // ASSERT_EQ(expectedData.size(), RawSize(params));
377 // }
378 
379 // TEST_F(SubscriptionDeserialization, PublishParameters)
380 // {
381 // using namespace OpcUa;
382 // using namespace OpcUa::Binary;
383 //
384 // const std::vector<char> expectedData = {
385 // 1,0,0,0, // Count of acks
386 // 1,0,0,0,
387 // 2,0,0,0,
388 // };
389 //
390 // GetChannel().SetData(expectedData);
391 //
392 // PublishParameters params;
393 // GetStream() >> params;
394 //
395 // ASSERT_EQ(params.Acknowledgements.size(), 1);
396 // }
397 
398 //-------------------------------------------------------
399 // CreateSubscriptionRequest
400 //-------------------------------------------------------
401 
403 {
404  using namespace OpcUa;
405  using namespace OpcUa::Binary;
406 
407  PublishRequest request;
408 
412 
414 
416  ack.SubscriptionId = 1;
417  ack.SequenceNumber = 2;
418 
419  request.SubscriptionAcknowledgements.push_back(ack);
420 
421  GetStream() << request << flush;
422 
423  const std::vector<char> expectedData =
424  {
425  1, 0, (char)0x3A, 0x3, // TypeId
426 
427  // RequestHeader
429 
430  // Parameters
431  1, 0, 0, 0, // Count of acks
432  1, 0, 0, 0,
433  2, 0, 0, 0
434  };
435 
436  ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
437  ASSERT_EQ(expectedData.size(), RawSize(request));
438 }
439 
441 {
442  using namespace OpcUa;
443  using namespace OpcUa::Binary;
444 
445  const std::vector<char> expectedData =
446  {
447  1, 0, (char)0x3A, 0x3, // TypeId
448 
449  // RequestHeader
451 
452  // Parameters
453  1, 0, 0, 0, // Count of acks
454  1, 0, 0, 0,
455  2, 0, 0, 0
456  };
457 
458  GetChannel().SetData(expectedData);
459 
460  PublishRequest request;
461  GetStream() >> request;
462 
466 
468 
469  ASSERT_EQ(request.SubscriptionAcknowledgements.size(), 1);
470 }
471 
472 //-------------------------------------------------------
473 // NotificationMessage
474 //-------------------------------------------------------
475 
477 {
478  using namespace OpcUa;
479  using namespace OpcUa::Binary;
480 
481  NotificationMessage data;
482  data.SequenceNumber = 1;
483  data.PublishTime.Value = 2;
484  data.NotificationData.push_back(NotificationData());
485 
486  GetStream() << data << flush;
487 
488  const std::vector<char> expectedData =
489  {
490  1, 0, 0, 0, // SequenceId
491  2, 0, 0, 0, 0, 0, 0, 0, // PublishTime
492 
493  1, 0, 0, 0, // Count of data
494  //Message.Header
495  0, 0, // TypeId
496  0, // Encoding
497  };
498 
499  ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
500  ASSERT_EQ(expectedData.size(), RawSize(data));
501 }
502 
504 {
505  using namespace OpcUa;
506  using namespace OpcUa::Binary;
507 
508  const std::vector<char> expectedData =
509  {
510  1, 0, 0, 0, // SequenceId
511  2, 0, 0, 0, 0, 0, 0, 0, // PublishTime
512  // Data vector
513  1, 0, 0, 0, //Count of Data
514  0, 0, // Data.Header.TypeId
515  0, // Data.Header.Encoding
516  };
517 
518  GetChannel().SetData(expectedData);
519 
521  GetStream() >> message;
522 
523  ASSERT_EQ(message.SequenceNumber, IntegerId(1));
524  ASSERT_EQ(message.PublishTime, 2);
525 }
526 
527 //-------------------------------------------------------
528 // PublishResult
529 //-------------------------------------------------------
530 
532 {
533  using namespace OpcUa;
534  using namespace OpcUa::Binary;
535 
536  PublishResult result;
537  result.SubscriptionId = 1;
538  result.AvailableSequenceNumbers.push_back(2);
539  result.MoreNotifications = true;
540 
544 
545  result.Results.push_back(StatusCode::Good);
546 
547  DiagnosticInfo diag;
549  diag.LocalizedText = 4;
550  diag.InnerDiagnostics.reset(new DiagnosticInfo());
551  diag.InnerDiagnostics->EncodingMask = DIM_ADDITIONAL_INFO;
552  diag.InnerDiagnostics->AdditionalInfo = "add";
553  result.DiagnosticInfos.push_back(diag);
554 
555  GetStream() << result << flush;
556 
557  const std::vector<char> expectedData =
558  {
559  1, 0, 0, 0, // SubscriptionId
560  //AvailableSequenceNumbers
561  1, 0, 0, 0, // count
562  2, 0, 0, 0,
563  // MoreNotifications
564  1,
565 
566  // NotificationData
567  1, 0, 0, 0, // SequenceId
568  2, 0, 0, 0, 0, 0, 0, 0, // PublishTime
569  // Data vector
570  1, 0, 0, 0, //Count of Data
571  0, 0, // Data.Header.TypeId
572  0, // Data.Header.Encoding
573 
574  // Statuses
575  1, 0, 0, 0,
576  0, 0, 0, 0,
577  // Diagnostics
578  1, 0, 0, 0, // Count
580  DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
581  };
582 
583  ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
584  ASSERT_EQ(expectedData.size(), RawSize(result));
585 }
586 
588 {
589  using namespace OpcUa;
590  using namespace OpcUa::Binary;
591 
592  const std::vector<char> expectedData =
593  {
594  1, 0, 0, 0, // SubscriptionId
595  //AvailableSequenceNumbers
596  1, 0, 0, 0, // count
597  2, 0, 0, 0,
598  // MoreNotifications
599  1,
600 
601  // NotificationData
602  1, 0, 0, 0, // SequenceId
603  2, 0, 0, 0, 0, 0, 0, 0, // PublishTime
604  // Data vector
605  1, 0, 0, 0, //Count of Data
606  0, 0, // Data.Header.TypeId
607  0, // Data.Header.Encoding
608 
609  // Statuses
610  1, 0, 0, 0,
611  0, 0, 0, 0,
612  // Diagnostics
613  1, 0, 0, 0, // Count
615  DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
616  };
617 
618  GetChannel().SetData(expectedData);
619 
620  PublishResult result;
621  GetStream() >> result;
622 
623  ASSERT_EQ(result.SubscriptionId, 1);
624  ASSERT_EQ(result.AvailableSequenceNumbers.size(), 1);
625  ASSERT_EQ(result.MoreNotifications, true);
627  ASSERT_EQ(result.Results.size(), 1);
628  ASSERT_EQ(result.DiagnosticInfos.size(), 1);
629 }
630 
631 //-------------------------------------------------------
632 // PublishResponse
633 //-------------------------------------------------------
634 
636 {
637  using namespace OpcUa;
638  using namespace OpcUa::Binary;
639 
640  PublishResponse response;
641 
645 
647 
648  PublishResult result;
649  response.Parameters.SubscriptionId = 1;
650  response.Parameters.AvailableSequenceNumbers.push_back(2);
651  response.Parameters.MoreNotifications = true;
655  response.Parameters.Results.push_back(StatusCode::Good);
656 
657  DiagnosticInfo diag;
659  diag.LocalizedText = 4;
660  diag.InnerDiagnostics.reset(new DiagnosticInfo());
661  diag.InnerDiagnostics->EncodingMask = DIM_ADDITIONAL_INFO;
662  diag.InnerDiagnostics->AdditionalInfo = "add";
663  response.Parameters.DiagnosticInfos.push_back(diag);
664 
665  GetStream() << response << flush;
666 
667  const std::vector<char> expectedData =
668  {
669  1, 0, (char)0x3D, 0x3, // TypeId
670 
671  // RequestHeader
673 
674  1, 0, 0, 0, // SubscriptionId
675  //AvailableSequenceNumbers
676  1, 0, 0, 0, // count
677  2, 0, 0, 0,
678  // MoreNotifications
679  1,
680 
681  // NotificationData
682  1, 0, 0, 0, // SequenceId
683  2, 0, 0, 0, 0, 0, 0, 0, // PublishTime
684  // Data vector
685  1, 0, 0, 0, //Count of Data
686  0, 0, // Data.Header.TypeId
687  0, // Data.Header.Encoding
688 
689  // Statuses
690  1, 0, 0, 0,
691  0, 0, 0, 0,
692  // Diagnostics
693  1, 0, 0, 0, // Count
694  static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4, 0, 0, 0, \
695  DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
696  };
697 
698  ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
699  ASSERT_EQ(expectedData.size(), RawSize(response));
700 }
701 
702 // TEST_F(SubscriptionSerialization, PublishResponse_Empty)
703 // {
704 // using namespace OpcUa;
705 // using namespace OpcUa::Binary;
706 //
707 // PublishResponse response;
708 //
709 // ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
710 // ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
711 // ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::PUBLISH_RESPONSE);
712 //
713 // FILL_TEST_RESPONSE_HEADER(response.Header);
714 //
715 // PublishResult result;
716 // response.Parameters.NotificationMessage.PublishTime.Value = 2;
717 //
718 // GetStream() << response << flush;
719 //
720 // const std::vector<char> expectedData = {
721 // 1, 0, (char)0x3D, 0x3, // TypeId
722 //
723 // // RequestHeader
724 // TEST_RESPONSE_HEADER_BINARY_DATA,
725 //
726 // 1,0,0,0, // SubscriptionId
727 // //AvailableSequenceNumbers
728 // 0,0,0,0, // count
729 // // MoreNotifications
730 // 0,
731 //
732 // // NotificationData
733 // 0,0,0,0, // SequenceId
734 // 2,0,0,0,0,0,0,0, // PublishTime
735 // // Data vector
736 // 0,0,0,0, //Count
737 //
738 // // Statuses
739 // 0,0,0,0, // Count
740 // // Diagnostics
741 // 0,0,0,0, // Count
742 // };
743 //
744 // ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
745 // ASSERT_EQ(expectedData.size(), RawSize(response));
746 // }
747 
749 {
750  using namespace OpcUa;
751  using namespace OpcUa::Binary;
752 
753  const std::vector<char> expectedData =
754  {
755  1, 0, (char)0x3D, 0x3, // TypeId
756 
757  // RequestHeader
759 
760  1, 0, 0, 0, // SubscriptionId
761  //AvailableSequenceNumbers
762  1, 0, 0, 0, // count
763  2, 0, 0, 0,
764  // MoreNotifications
765  1,
766 
767  // NotificationData
768  1, 0, 0, 0, // SequenceId
769  2, 0, 0, 0, 0, 0, 0, 0, // PublishTime
770  // Data vector
771  1, 0, 0, 0, //Count of Data
772  0, 0, // Data.Header.TypeId
773  0, // Data.Header.Encoding
774 
775  // Statuses
776  1, 0, 0, 0,
777  0, 0, 0, 0,
778  // Diagnostics
779  1, 0, 0, 0, // Count
780  static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4, 0, 0, 0, \
781  DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
782  };
783 
784  GetChannel().SetData(expectedData);
785 
786  PublishResponse response;
787  GetStream() >> response;
788 
792 
794 
795  ASSERT_EQ(response.Parameters.DiagnosticInfos.size(), 1);
796 }
797 
798 //-------------------------------------------------------
799 // PublishingModeParameters
800 //-------------------------------------------------------
801 
803 {
804  using namespace OpcUa;
805  using namespace OpcUa::Binary;
806 
808  params.PublishingEnabled = true;
809  params.SubscriptionIds.push_back(1);
810 
811  GetStream() << params << flush;
812 
813  const std::vector<char> expectedData =
814  {
815  1,
816  1, 0, 0, 0, // SubscriptionId
817  1, 0, 0, 0
818  };
819 
820  ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
821  ASSERT_EQ(expectedData.size(), RawSize(params));
822 }
823 
824 // TEST_F(SubscriptionSerialization, PublishingModeParameters_Empty)
825 // {
826 // using namespace OpcUa;
827 // using namespace OpcUa::Binary;
828 //
829 // PublishingModeParameters params;
830 //
831 // GetStream() << params << flush;
832 //
833 // const std::vector<char> expectedData = {
834 // 0,
835 // 0,0,0,0, // Count of subscriptions
836 // };
837 //
838 // ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
839 // ASSERT_EQ(expectedData.size(), RawSize(params));
840 // }
841 
842 
844 {
845  using namespace OpcUa;
846  using namespace OpcUa::Binary;
847 
848  const std::vector<char> expectedData =
849  {
850  1,
851  1, 0, 0, 0, // SubscriptionId
852  1, 0, 0, 0
853  };
854 
855  GetChannel().SetData(expectedData);
856 
858  GetStream() >> params;
859 
860  ASSERT_EQ(params.PublishingEnabled, true);
861  ASSERT_EQ(params.SubscriptionIds.size(), 1);
862  ASSERT_EQ(params.SubscriptionIds[0], 1);
863 }
864 
865 //-------------------------------------------------------
866 // SetPublishingModeRequest
867 //-------------------------------------------------------
868 
870 {
871  using namespace OpcUa;
872  using namespace OpcUa::Binary;
873 
874  SetPublishingModeRequest request;
875 
879 
881 
882  request.Parameters.PublishingEnabled = true;
883  request.Parameters.SubscriptionIds.push_back(IntegerId());
884 
885  GetStream() << request << flush;
886 
887  const std::vector<char> expectedData =
888  {
889  1, 0, (char)0x1F, 0x3, // TypeId
890 
891  // RequestHeader
893 
894  // PublishingEnabled
895  1, // Enabled
896  1, 0, 0, 0,
897  1, 0, 0, 0
898  };
899 
900  ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
901  ASSERT_EQ(expectedData.size(), RawSize(request));
902 }
903 
905 {
906  using namespace OpcUa;
907  using namespace OpcUa::Binary;
908 
909  const std::vector<char> expectedData =
910  {
911  1, 0, (char)0x1F, 0x3, // TypeId
912 
913  // RequestHeader
915 
916  // Parameters
917  1, // Enabled
918  1, 0, 0, 0,
919  1, 0, 0, 0
920  };
921 
922  GetChannel().SetData(expectedData);
923 
924  SetPublishingModeRequest request;
925  GetStream() >> request;
926 
930 
932 
933  ASSERT_EQ(request.Parameters.PublishingEnabled, true);
934  ASSERT_EQ(request.Parameters.SubscriptionIds.size(), 1);
935  ASSERT_EQ(request.Parameters.SubscriptionIds[0], 1);
936 }
937 
938 //-------------------------------------------------------
939 // PublishingModeResult
940 //-------------------------------------------------------
941 
942 // TEST_F(SubscriptionSerialization, PublishingModeResult)
943 // {
944 // using namespace OpcUa;
945 // using namespace OpcUa::Binary;
946 //
947 // PublishingModeResult result;
948 // result.Results.push_back(StatusCode::Good);
949 //
950 // GetStream() << result << flush;
951 //
952 // const std::vector<char> expectedData = {
953 // 1,0,0,0,
954 // 0,0,0,0, // StatusCode
955 // 0,0,0,0 // Count of diagnostics
956 // };
957 //
958 // ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
959 // ASSERT_EQ(expectedData.size(), RawSize(result));
960 // }
961 
962 // TEST_F(SubscriptionSerialization, PublishingModeResult_Empty)
963 // {
964 // using namespace OpcUa;
965 // using namespace OpcUa::Binary;
966 //
967 // PublishingModeResult result;
968 //
969 // GetStream() << result << flush;
970 //
971 // const std::vector<char> expectedData = {
972 // 0,0,0,0,
973 // 0,0,0,0, // Count of subscriptions
974 // };
975 //
976 // ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
977 // ASSERT_EQ(expectedData.size(), RawSize(result));
978 // }
979 
980 
982 {
983  using namespace OpcUa;
984  using namespace OpcUa::Binary;
985 
986  const std::vector<char> expectedData =
987  {
988  1, 0, 0, 0,
989  0, 0, 0, 0, // StatusCode
990  0, 0, 0, 0 // Count of diagnostics
991  };
992 
993  GetChannel().SetData(expectedData);
994 
995  PublishingModeResult result;
996  GetStream() >> result;
997 
998  ASSERT_EQ(result.Results.size(), 1);
999  ASSERT_EQ(result.Results[0], StatusCode::Good);
1000  ASSERT_EQ(result.DiagnosticInfos.size(), 0);
1001 }
1002 
1003 //-------------------------------------------------------
1004 // SetPublishingModeResponse
1005 //-------------------------------------------------------
1006 
1007 // TEST_F(SubscriptionSerialization, SetPublishingModeResponse)
1008 // {
1009 // using namespace OpcUa;
1010 // using namespace OpcUa::Binary;
1011 //
1012 // SetPublishingModeResponse response;
1013 //
1014 // ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
1015 // ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
1016 // ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::SET_PUBLISHING_MODE_RESPONSE);
1017 //
1018 // FILL_TEST_RESPONSE_HEADER(response.Header);
1019 //
1020 // response.Result.Results.push_back(StatusCode::Good);
1021 //
1022 // GetStream() << response << flush;
1023 //
1024 // const std::vector<char> expectedData = {
1025 // 1, 0, (char)0x22, 0x3, // TypeId
1026 //
1027 // // RequestHeader
1028 // TEST_RESPONSE_HEADER_BINARY_DATA,
1029 //
1030 // 1,0,0,0,
1031 // 0,0,0,0, // StatusCode
1032 // 0,0,0,0 // Count of diagnostics
1033 // };
1034 //
1035 // ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
1036 // ASSERT_EQ(expectedData.size(), RawSize(response));
1037 // }
1038 
1039 // TEST_F(SubscriptionSerialization, SetPublishingModeResponse_Empty)
1040 // {
1041 // using namespace OpcUa;
1042 // using namespace OpcUa::Binary;
1043 //
1044 // SetPublishingModeResponse response;
1045 //
1046 // ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
1047 // ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
1048 // ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::SET_PUBLISHING_MODE_RESPONSE);
1049 //
1050 // FILL_TEST_RESPONSE_HEADER(response.Header);
1051 //
1052 // GetStream() << response << flush;
1053 //
1054 // const std::vector<char> expectedData = {
1055 // 1, 0, (char)0x22, 0x3, // TypeId
1056 //
1057 // // RequestHeader
1058 // TEST_RESPONSE_HEADER_BINARY_DATA,
1059 //
1060 // 0,0,0,0, // StatusCode
1061 // 0,0,0,0 // Count of diagnostics
1062 // };
1063 //
1064 // ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << 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)0x22, 0x3, // TypeId
1076 
1077  // RequestHeader
1079 
1080  1, 0, 0, 0,
1081  0, 0, 0, 0, // StatusCode
1082  0, 0, 0, 0 // Count of diagnostics
1083  };
1084 
1085  GetChannel().SetData(expectedData);
1086 
1087  SetPublishingModeResponse response;
1088  GetStream() >> response;
1089 
1093 
1095 
1096  ASSERT_EQ(response.Result.Results.size(), 1);
1097  ASSERT_EQ(response.Result.DiagnosticInfos.size(), 0);
1098 }
TEST_F(SubscriptionSerialization, CreateSubscriptionParameters)
std::vector< OpcUa::DiagnosticInfo > DiagnosticInfos
int32_t LocalizedText
Definition: types.h:217
#define TEST_RESPONSE_HEADER_BINARY_DATA
OpcUa::CreateSubscriptionParameters Parameters
DiagnosticInfoMask
Definition: types.h:200
std::string PrintData(const std::vector< char > &vec)
Test of opc ua binary handshake. GNU LGPL.
std::vector< OpcUa::NotificationData > NotificationData
OpcUa::PublishingModeParameters Parameters
std::vector< OpcUa::StatusCode > Results
#define ASSERT_REQUEST_HEADER_EQ(header)
OStream< ChannelType > & flush(OStream< ChannelType > &os)
Definition: stream.h:147
OpcUa::ResponseHeader Header
std::shared_ptr< DiagnosticInfo > InnerDiagnostics
Definition: types.h:221
std::vector< uint32_t > SubscriptionIds
Opc Ua Binary. Subscription service. GNU LGPL.
message
Definition: server.py:50
#define FILL_TEST_RESPONSE_HEADER(header)
#define TEST_REQUEST_HEADER_BINARY_DATA
#define FILL_TEST_REQUEST_HEADER(header)
DiagnosticInfoMask EncodingMask
Definition: types.h:214
struct OpcUa::NodeId::FourByteDataType FourByteData
OPC UA Address space part. GNU LGPL.
OpcUa::PublishResult Parameters
#define ASSERT_RESPONSE_HEADER_EQ(header)
OpcUa::ResponseHeader Header
std::vector< OpcUa::StatusCode > Results
OpcUa::PublishingModeResult Result
std::vector< OpcUa::DiagnosticInfo > DiagnosticInfos
#define ASSERT_EQ(val1, val2)
OpcUa::SubscriptionData Data
NodeIdEncoding Encoding
Definition: nodeid.h:46
int64_t Value
Definition: datetime.h:49
std::vector< uint32_t > AvailableSequenceNumbers
OpcUa::NotificationMessage NotificationMessage
std::vector< OpcUa::SubscriptionAcknowledgement > SubscriptionAcknowledgements
OpcUa::RequestHeader Header
const char DiagnosticInfo[]
Definition: strings.h:50
std::size_t RawSize(const T &obj)


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