binary_subscriptions.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include "common.h"
00012 
00013 #include <opc/ua/protocol/extension_identifiers.h>
00014 #include <opc/ua/protocol/message_identifiers.h>
00015 #include <opc/ua/protocol/binary/stream.h>
00016 #include <opc/ua/protocol/types.h>
00017 
00018 #include <algorithm>
00019 #include <stdexcept>
00020 
00021 class SubscriptionSerialization : public OpcUaBinarySerialization
00022 {
00023 };
00024 
00025 class SubscriptionDeserialization : public OpcUaBinaryDeserialization
00026 {
00027 };
00028 
00029 
00030 //-------------------------------------------------------
00031 // SubScriptionParameters
00032 //-------------------------------------------------------
00033 
00034 TEST_F(SubscriptionSerialization, CreateSubscriptionParameters)
00035 {
00036 
00037   using namespace OpcUa;
00038   using namespace OpcUa::Binary;
00039 
00040   CreateSubscriptionParameters params;
00041   params.RequestedPublishingInterval = 1200000;
00042   params.RequestedLifetimeCount = 2;
00043   params.RequestedMaxKeepAliveCount = 3;
00044   params.MaxNotificationsPerPublish = 4;
00045   params.PublishingEnabled = true;
00046   params.Priority = 5;
00047 
00048   GetStream() << params << flush;
00049 
00050   const std::vector<char> expectedData = {
00051     0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
00052     2,0,0,0,
00053     3,0,0,0,
00054     4,0,0,0,
00055     1,
00056     5
00057   };
00058 
00059   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00060   ASSERT_EQ(expectedData.size(), RawSize(params));
00061 }
00062 
00063 TEST_F(SubscriptionDeserialization, CreateSubscriptionParameters)
00064 {
00065   using namespace OpcUa;
00066   using namespace OpcUa::Binary;
00067 
00068   const std::vector<char> expectedData = {
00069     0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
00070     2,0,0,0,
00071     3,0,0,0,
00072     4,0,0,0,
00073     1,
00074     5
00075   };
00076 
00077   GetChannel().SetData(expectedData);
00078 
00079   CreateSubscriptionParameters params;
00080   GetStream() >> params;
00081 
00082   ASSERT_EQ(params.RequestedPublishingInterval, 1200000);
00083   ASSERT_EQ(params.RequestedLifetimeCount, 2);
00084   ASSERT_EQ(params.RequestedMaxKeepAliveCount, 3);
00085   ASSERT_EQ(params.MaxNotificationsPerPublish, 4);
00086   ASSERT_EQ(params.PublishingEnabled, true);
00087   ASSERT_EQ(params.Priority, 5);
00088 }
00089 
00090 //-------------------------------------------------------
00091 // CreateSubscriptionRequest
00092 //-------------------------------------------------------
00093 
00094 TEST_F(SubscriptionSerialization, CreateSubscriptionRequest)
00095 {
00096   using namespace OpcUa;
00097   using namespace OpcUa::Binary;
00098 
00099   CreateSubscriptionRequest request;
00100 
00101   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00102   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00103   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::CREATE_SUBSCRIPTION_REQUEST);
00104 
00105   FILL_TEST_REQUEST_HEADER(request.Header);
00106 
00107   request.Parameters.RequestedPublishingInterval = 1200000;
00108   request.Parameters.RequestedLifetimeCount = 2;
00109   request.Parameters.RequestedMaxKeepAliveCount = 3;
00110   request.Parameters.MaxNotificationsPerPublish = 4;
00111   request.Parameters.PublishingEnabled = true;
00112   request.Parameters.Priority = 5;
00113 
00114   GetStream() << request << flush;
00115 
00116   const std::vector<char> expectedData = {
00117     1, 0, (char)0x13, 0x3, // TypeId
00118 
00119     // RequestHeader
00120     TEST_REQUEST_HEADER_BINARY_DATA,
00121 
00122     0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
00123     2,0,0,0,
00124     3,0,0,0,
00125     4,0,0,0,
00126     1,
00127     5
00128   };
00129 
00130   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00131   ASSERT_EQ(expectedData.size(), RawSize(request));
00132 }
00133 
00134 TEST_F(SubscriptionDeserialization, CreateSubscriptionRequest)
00135 {
00136   using namespace OpcUa;
00137   using namespace OpcUa::Binary;
00138 
00139   const std::vector<char> expectedData = {
00140     1, 0, (char)0x13, 0x3, // TypeId
00141 
00142     // RequestHeader
00143     TEST_REQUEST_HEADER_BINARY_DATA,
00144 
00145     0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
00146     2,0,0,0,
00147     3,0,0,0,
00148     4,0,0,0,
00149     1,
00150     5
00151   };
00152 
00153   GetChannel().SetData(expectedData);
00154 
00155   CreateSubscriptionRequest request;
00156   GetStream() >> request;
00157 
00158   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00159   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00160   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::CREATE_SUBSCRIPTION_REQUEST);
00161 
00162   ASSERT_REQUEST_HEADER_EQ(request.Header);
00163 
00164   ASSERT_EQ(request.Parameters.RequestedPublishingInterval, 1200000);
00165   ASSERT_EQ(request.Parameters.RequestedLifetimeCount, 2);
00166   ASSERT_EQ(request.Parameters.RequestedMaxKeepAliveCount, 3);
00167   ASSERT_EQ(request.Parameters.MaxNotificationsPerPublish, 4);
00168   ASSERT_EQ(request.Parameters.PublishingEnabled, true);
00169   ASSERT_EQ(request.Parameters.Priority, 5);
00170 }
00171 
00172 //-------------------------------------------------------
00173 // SubscriptionData
00174 //-------------------------------------------------------
00175 
00176 TEST_F(SubscriptionSerialization, SubscriptionData)
00177 {
00178 
00179   using namespace OpcUa;
00180   using namespace OpcUa::Binary;
00181 
00182   SubscriptionData data;
00183   data.SubscriptionId = 2;
00184   data.RevisedPublishingInterval = 1200000;
00185   data.RevisedLifetimeCount = 3;
00186   data.RevisedMaxKeepAliveCount = 4;
00187 
00188   GetStream() << data << flush;
00189 
00190   const std::vector<char> expectedData = {
00191     2,0,0,0,
00192     0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
00193     3,0,0,0,
00194     4,0,0,0,
00195   };
00196 
00197   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00198   ASSERT_EQ(expectedData.size(), RawSize(data));
00199 }
00200 
00201 TEST_F(SubscriptionDeserialization, SubscriptionData)
00202 {
00203   using namespace OpcUa;
00204   using namespace OpcUa::Binary;
00205 
00206   const std::vector<char> expectedData = {
00207     2,0,0,0,
00208     0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
00209     3,0,0,0,
00210     4,0,0,0,
00211   };
00212 
00213   GetChannel().SetData(expectedData);
00214 
00215   SubscriptionData data;
00216   GetStream() >> data;
00217 
00218   ASSERT_EQ(data.SubscriptionId, 2);
00219   ASSERT_EQ(data.RevisedPublishingInterval, 1200000);
00220   ASSERT_EQ(data.RevisedLifetimeCount, 3);
00221   ASSERT_EQ(data.RevisedMaxKeepAliveCount, 4);
00222 }
00223 //-------------------------------------------------------
00224 // CreateSubscriptionResponse
00225 //-------------------------------------------------------
00226 
00227 TEST_F(SubscriptionSerialization, CreateSubscriptionResponse)
00228 {
00229   using namespace OpcUa;
00230   using namespace OpcUa::Binary;
00231 
00232   CreateSubscriptionResponse response;
00233 
00234   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00235   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00236   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::CREATE_SUBSCRIPTION_RESPONSE);
00237 
00238   FILL_TEST_RESPONSE_HEADER(response.Header);
00239 
00240   response.Data.SubscriptionId = 2;
00241   response.Data.RevisedPublishingInterval = 1200000;
00242   response.Data.RevisedLifetimeCount = 3;
00243   response.Data.RevisedMaxKeepAliveCount = 4;
00244 
00245   GetStream() << response << flush;
00246 
00247   const std::vector<char> expectedData = {
00248     1, 0, (char)0x16, 0x3, // TypeId
00249 
00250     // RequestHeader
00251     TEST_RESPONSE_HEADER_BINARY_DATA,
00252 
00253     2,0,0,0,
00254     0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
00255     3,0,0,0,
00256     4,0,0,0,
00257   };
00258 
00259   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00260   ASSERT_EQ(expectedData.size(), RawSize(response));
00261 }
00262 
00263 TEST_F(SubscriptionDeserialization, CreateSubscriptionResponse)
00264 {
00265   using namespace OpcUa;
00266   using namespace OpcUa::Binary;
00267 
00268   const std::vector<char> expectedData = {
00269     1, 0, (char)0x16, 0x3, // TypeId
00270 
00271     // RequestHeader
00272     TEST_RESPONSE_HEADER_BINARY_DATA,
00273 
00274     2,0,0,0,
00275     0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
00276     3,0,0,0,
00277     4,0,0,0,
00278   };
00279 
00280   GetChannel().SetData(expectedData);
00281 
00282   CreateSubscriptionResponse response;
00283   GetStream() >> response;
00284 
00285   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00286   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00287   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::CREATE_SUBSCRIPTION_RESPONSE);
00288 
00289   ASSERT_RESPONSE_HEADER_EQ(response.Header);
00290 
00291   ASSERT_EQ(response.Data.SubscriptionId, 2);
00292   ASSERT_EQ(response.Data.RevisedPublishingInterval, 1200000);
00293   ASSERT_EQ(response.Data.RevisedLifetimeCount, 3);
00294   ASSERT_EQ(response.Data.RevisedMaxKeepAliveCount, 4);
00295 }
00296 
00297 //-------------------------------------------------------
00298 // SubscriptionAcknowledgement
00299 //-------------------------------------------------------
00300 
00301 TEST_F(SubscriptionSerialization, SubscriptionAcknowledgement)
00302 {
00303 
00304   using namespace OpcUa;
00305   using namespace OpcUa::Binary;
00306 
00307   SubscriptionAcknowledgement ack;
00308   ack.SubscriptionId = 1;
00309   ack.SequenceNumber = 2;
00310 
00311   GetStream() << ack << flush;
00312 
00313   const std::vector<char> expectedData = {
00314     1,0,0,0,
00315     2,0,0,0,
00316   };
00317 
00318   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00319   ASSERT_EQ(expectedData.size(), RawSize(ack));
00320 }
00321 
00322 TEST_F(SubscriptionDeserialization, SubscriptionAcknowledgement)
00323 {
00324   using namespace OpcUa;
00325   using namespace OpcUa::Binary;
00326 
00327   const std::vector<char> expectedData = {
00328     1,0,0,0,
00329     2,0,0,0,
00330   };
00331 
00332   GetChannel().SetData(expectedData);
00333 
00334   SubscriptionAcknowledgement ack;
00335   GetStream() >> ack;
00336 
00337   ASSERT_EQ(ack.SubscriptionId, 1);
00338   ASSERT_EQ(ack.SequenceNumber, 2);
00339 }
00340 
00341 // //-------------------------------------------------------
00342 // // PublishParameters
00343 // //-------------------------------------------------------
00344 //
00345 // TEST_F(SubscriptionSerialization, PublishParameters)
00346 // {
00347 //   using namespace OpcUa;
00348 //   using namespace OpcUa::Binary;
00349 //
00350 //   SubscriptionAcknowledgement ack;
00351 //   ack.SubscriptionId = 1;
00352 //   ack.SequenceNumber = 2;
00353 //
00354 //   PublishParameters params;
00355 //   params.Acknowledgements.push_back(ack);
00356 //
00357 //   GetStream() << params << flush;
00358 //
00359 //   const std::vector<char> expectedData = {
00360 //     1,0,0,0, // Count of acks
00361 //     1,0,0,0,
00362 //     2,0,0,0,
00363 //   };
00364 //
00365 //   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00366 //   ASSERT_EQ(expectedData.size(), RawSize(params));
00367 // }
00368 
00369 // TEST_F(SubscriptionDeserialization, PublishParameters)
00370 // {
00371 //   using namespace OpcUa;
00372 //   using namespace OpcUa::Binary;
00373 //
00374 //   const std::vector<char> expectedData = {
00375 //     1,0,0,0, // Count of acks
00376 //     1,0,0,0,
00377 //     2,0,0,0,
00378 //   };
00379 //
00380 //   GetChannel().SetData(expectedData);
00381 //
00382 //   PublishParameters params;
00383 //   GetStream() >> params;
00384 //
00385 //   ASSERT_EQ(params.Acknowledgements.size(), 1);
00386 // }
00387 
00388 //-------------------------------------------------------
00389 // CreateSubscriptionRequest
00390 //-------------------------------------------------------
00391 
00392 TEST_F(SubscriptionSerialization, PublishRequest)
00393 {
00394   using namespace OpcUa;
00395   using namespace OpcUa::Binary;
00396 
00397   PublishRequest request;
00398 
00399   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00400   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00401   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::PUBLISH_REQUEST);
00402 
00403   FILL_TEST_REQUEST_HEADER(request.Header);
00404 
00405   SubscriptionAcknowledgement ack;
00406   ack.SubscriptionId = 1;
00407   ack.SequenceNumber = 2;
00408 
00409   request.SubscriptionAcknowledgements.push_back(ack);
00410 
00411   GetStream() << request << flush;
00412 
00413   const std::vector<char> expectedData = {
00414     1, 0, (char)0x3A, 0x3, // TypeId
00415 
00416     // RequestHeader
00417     TEST_REQUEST_HEADER_BINARY_DATA,
00418 
00419     // Parameters
00420     1,0,0,0, // Count of acks
00421     1,0,0,0,
00422     2,0,0,0
00423   };
00424 
00425   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00426   ASSERT_EQ(expectedData.size(), RawSize(request));
00427 }
00428 
00429 TEST_F(SubscriptionDeserialization, PublishRequest)
00430 {
00431   using namespace OpcUa;
00432   using namespace OpcUa::Binary;
00433 
00434   const std::vector<char> expectedData = {
00435     1, 0, (char)0x3A, 0x3, // TypeId
00436 
00437     // RequestHeader
00438     TEST_REQUEST_HEADER_BINARY_DATA,
00439 
00440     // Parameters
00441     1,0,0,0, // Count of acks
00442     1,0,0,0,
00443     2,0,0,0
00444   };
00445 
00446   GetChannel().SetData(expectedData);
00447 
00448   PublishRequest request;
00449   GetStream() >> request;
00450 
00451   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00452   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00453   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::PUBLISH_REQUEST);
00454 
00455   ASSERT_REQUEST_HEADER_EQ(request.Header);
00456 
00457   ASSERT_EQ(request.SubscriptionAcknowledgements.size(), 1);
00458 }
00459 
00460 //-------------------------------------------------------
00461 // NotificationMessage
00462 //-------------------------------------------------------
00463 
00464 TEST_F(SubscriptionSerialization, NotificationMessage)
00465 {
00466   using namespace OpcUa;
00467   using namespace OpcUa::Binary;
00468 
00469   NotificationMessage data;
00470   data.SequenceNumber = 1;
00471   data.PublishTime.Value = 2;
00472   data.NotificationData.push_back(NotificationData());
00473 
00474   GetStream() << data << flush;
00475 
00476   const std::vector<char> expectedData = {
00477     1,0,0,0, // SequenceId
00478     2,0,0,0,0,0,0,0, // PublishTime
00479 
00480     1,0,0,0, // Count of data
00481     //Message.Header
00482     0,0, // TypeId
00483     0,   // Encoding
00484   };
00485 
00486   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00487   ASSERT_EQ(expectedData.size(), RawSize(data));
00488 }
00489 
00490 TEST_F(SubscriptionDeserialization, NotificationMessage)
00491 {
00492   using namespace OpcUa;
00493   using namespace OpcUa::Binary;
00494 
00495   const std::vector<char> expectedData = {
00496     1,0,0,0, // SequenceId
00497     2,0,0,0,0,0,0,0, // PublishTime
00498     // Data vector
00499     1,0,0,0, //Count of Data
00500     0,0, // Data.Header.TypeId
00501     0,   // Data.Header.Encoding
00502   };
00503 
00504   GetChannel().SetData(expectedData);
00505 
00506   NotificationMessage message;
00507   GetStream() >> message;
00508 
00509   ASSERT_EQ(message.SequenceNumber, IntegerId(1));
00510   ASSERT_EQ(message.PublishTime, 2);
00511 }
00512 
00513 //-------------------------------------------------------
00514 // PublishResult
00515 //-------------------------------------------------------
00516 
00517 TEST_F(SubscriptionSerialization, PublishResult)
00518 {
00519   using namespace OpcUa;
00520   using namespace OpcUa::Binary;
00521 
00522   PublishResult result;
00523   result.SubscriptionId = 1;
00524   result.AvailableSequenceNumbers.push_back(2);
00525   result.MoreNotifications = true;
00526 
00527   result.NotificationMessage.SequenceNumber = 1;
00528   result.NotificationMessage.PublishTime.Value = 2;
00529   result.NotificationMessage.NotificationData.push_back(NotificationData());
00530 
00531   result.Results.push_back(StatusCode::Good);
00532 
00533   DiagnosticInfo diag;
00534   diag.EncodingMask = static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO);
00535   diag.LocalizedText = 4;
00536   diag.InnerDiagnostics.reset(new DiagnosticInfo());
00537   diag.InnerDiagnostics->EncodingMask = DIM_ADDITIONAL_INFO;
00538   diag.InnerDiagnostics->AdditionalInfo = "add";
00539   result.DiagnosticInfos.push_back(diag);
00540 
00541   GetStream() << result << flush;
00542 
00543   const std::vector<char> expectedData = {
00544     1,0,0,0, // SubscriptionId
00545     //AvailableSequenceNumbers
00546     1,0,0,0, // count
00547     2,0,0,0,
00548     // MoreNotifications
00549     1,
00550 
00551     // NotificationData
00552     1,0,0,0, // SequenceId
00553     2,0,0,0,0,0,0,0, // PublishTime
00554     // Data vector
00555     1,0,0,0, //Count of Data
00556     0,0, // Data.Header.TypeId
00557     0,   // Data.Header.Encoding
00558 
00559     // Statuses
00560     1,0,0,0,
00561     0,0,0,0,
00562     // Diagnostics
00563     1,0,0,0, // Count
00564     static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4,0,0,0, \
00565     DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
00566   };
00567 
00568   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00569   ASSERT_EQ(expectedData.size(), RawSize(result));
00570 }
00571 
00572 TEST_F(SubscriptionDeserialization, PublishResult)
00573 {
00574   using namespace OpcUa;
00575   using namespace OpcUa::Binary;
00576 
00577   const std::vector<char> expectedData = {
00578     1,0,0,0, // SubscriptionId
00579     //AvailableSequenceNumbers
00580     1,0,0,0, // count
00581     2,0,0,0,
00582     // MoreNotifications
00583     1,
00584 
00585     // NotificationData
00586     1,0,0,0, // SequenceId
00587     2,0,0,0,0,0,0,0, // PublishTime
00588     // Data vector
00589     1,0,0,0, //Count of Data
00590     0,0, // Data.Header.TypeId
00591     0,   // Data.Header.Encoding
00592 
00593     // Statuses
00594     1,0,0,0,
00595     0,0,0,0,
00596     // Diagnostics
00597     1,0,0,0, // Count
00598     static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4,0,0,0, \
00599     DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
00600   };
00601 
00602   GetChannel().SetData(expectedData);
00603 
00604   PublishResult result;
00605   GetStream() >> result;
00606 
00607   ASSERT_EQ(result.SubscriptionId, 1);
00608   ASSERT_EQ(result.AvailableSequenceNumbers.size(), 1);
00609   ASSERT_EQ(result.MoreNotifications, true);
00610   ASSERT_EQ(result.NotificationMessage.NotificationData.size(), 1);
00611   ASSERT_EQ(result.Results.size(), 1);
00612   ASSERT_EQ(result.DiagnosticInfos.size(), 1);
00613 }
00614 
00615 //-------------------------------------------------------
00616 // PublishResponse
00617 //-------------------------------------------------------
00618 
00619 TEST_F(SubscriptionSerialization, PublishResponse)
00620 {
00621   using namespace OpcUa;
00622   using namespace OpcUa::Binary;
00623 
00624   PublishResponse response;
00625 
00626   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00627   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00628   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::PUBLISH_RESPONSE);
00629 
00630   FILL_TEST_RESPONSE_HEADER(response.Header);
00631 
00632   PublishResult result;
00633   response.Parameters.SubscriptionId = 1;
00634   response.Parameters.AvailableSequenceNumbers.push_back(2);
00635   response.Parameters.MoreNotifications = true;
00636   response.Parameters.NotificationMessage.SequenceNumber = 1;
00637   response.Parameters.NotificationMessage.PublishTime.Value = 2;
00638   response.Parameters.NotificationMessage.NotificationData.push_back(NotificationData());
00639   response.Parameters.Results.push_back(StatusCode::Good);
00640 
00641   DiagnosticInfo diag;
00642   diag.EncodingMask = static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO);
00643   diag.LocalizedText = 4;
00644   diag.InnerDiagnostics.reset(new DiagnosticInfo());
00645   diag.InnerDiagnostics->EncodingMask = DIM_ADDITIONAL_INFO;
00646   diag.InnerDiagnostics->AdditionalInfo = "add";
00647   response.Parameters.DiagnosticInfos.push_back(diag);
00648 
00649   GetStream() << response << flush;
00650 
00651   const std::vector<char> expectedData = {
00652     1, 0, (char)0x3D, 0x3, // TypeId
00653 
00654     // RequestHeader
00655     TEST_RESPONSE_HEADER_BINARY_DATA,
00656 
00657     1,0,0,0, // SubscriptionId
00658     //AvailableSequenceNumbers
00659     1,0,0,0, // count
00660     2,0,0,0,
00661     // MoreNotifications
00662     1,
00663 
00664     // NotificationData
00665     1,0,0,0, // SequenceId
00666     2,0,0,0,0,0,0,0, // PublishTime
00667     // Data vector
00668     1,0,0,0, //Count of Data
00669     0,0, // Data.Header.TypeId
00670     0,   // Data.Header.Encoding
00671 
00672     // Statuses
00673     1,0,0,0,
00674     0,0,0,0,
00675     // Diagnostics
00676     1,0,0,0, // Count
00677     static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4,0,0,0, \
00678     DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
00679   };
00680 
00681   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00682   ASSERT_EQ(expectedData.size(), RawSize(response));
00683 }
00684 
00685 // TEST_F(SubscriptionSerialization, PublishResponse_Empty)
00686 // {
00687 //   using namespace OpcUa;
00688 //   using namespace OpcUa::Binary;
00689 //
00690 //   PublishResponse response;
00691 //
00692 //   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00693 //   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00694 //   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::PUBLISH_RESPONSE);
00695 //
00696 //   FILL_TEST_RESPONSE_HEADER(response.Header);
00697 //
00698 //   PublishResult result;
00699 //   response.Parameters.NotificationMessage.PublishTime.Value = 2;
00700 //
00701 //   GetStream() << response << flush;
00702 //
00703 //   const std::vector<char> expectedData = {
00704 //     1, 0, (char)0x3D, 0x3, // TypeId
00705 //
00706 //     // RequestHeader
00707 //     TEST_RESPONSE_HEADER_BINARY_DATA,
00708 //
00709 //     1,0,0,0, // SubscriptionId
00710 //     //AvailableSequenceNumbers
00711 //     0,0,0,0, // count
00712 //     // MoreNotifications
00713 //     0,
00714 //
00715 //     // NotificationData
00716 //     0,0,0,0, // SequenceId
00717 //     2,0,0,0,0,0,0,0, // PublishTime
00718 //     // Data vector
00719 //     0,0,0,0, //Count
00720 //
00721 //     // Statuses
00722 //     0,0,0,0, // Count
00723 //     // Diagnostics
00724 //     0,0,0,0, // Count
00725 //   };
00726 //
00727 //   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00728 //   ASSERT_EQ(expectedData.size(), RawSize(response));
00729 // }
00730 
00731 TEST_F(SubscriptionDeserialization, PublishResponse)
00732 {
00733   using namespace OpcUa;
00734   using namespace OpcUa::Binary;
00735 
00736   const std::vector<char> expectedData = {
00737     1, 0, (char)0x3D, 0x3, // TypeId
00738 
00739     // RequestHeader
00740     TEST_RESPONSE_HEADER_BINARY_DATA,
00741 
00742     1,0,0,0, // SubscriptionId
00743     //AvailableSequenceNumbers
00744     1,0,0,0, // count
00745     2,0,0,0,
00746     // MoreNotifications
00747     1,
00748 
00749     // NotificationData
00750     1,0,0,0, // SequenceId
00751     2,0,0,0,0,0,0,0, // PublishTime
00752     // Data vector
00753     1,0,0,0, //Count of Data
00754     0,0, // Data.Header.TypeId
00755     0,   // Data.Header.Encoding
00756 
00757     // Statuses
00758     1,0,0,0,
00759     0,0,0,0,
00760     // Diagnostics
00761     1,0,0,0, // Count
00762     static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4,0,0,0, \
00763     DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
00764   };
00765 
00766   GetChannel().SetData(expectedData);
00767 
00768   PublishResponse response;
00769   GetStream() >> response;
00770 
00771   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00772   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00773   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::PUBLISH_RESPONSE);
00774 
00775   ASSERT_RESPONSE_HEADER_EQ(response.Header);
00776 
00777   ASSERT_EQ(response.Parameters.DiagnosticInfos.size(), 1);
00778 }
00779 
00780 //-------------------------------------------------------
00781 // PublishingModeParameters
00782 //-------------------------------------------------------
00783 
00784 TEST_F(SubscriptionSerialization, PublishingModeParameters)
00785 {
00786   using namespace OpcUa;
00787   using namespace OpcUa::Binary;
00788 
00789   PublishingModeParameters params;
00790   params.PublishingEnabled = true;
00791   params.SubscriptionIds.push_back(1);
00792 
00793   GetStream() << params << flush;
00794 
00795   const std::vector<char> expectedData = {
00796     1,
00797     1,0,0,0, // SubscriptionId
00798     1,0,0,0
00799   };
00800 
00801   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00802   ASSERT_EQ(expectedData.size(), RawSize(params));
00803 }
00804 
00805 // TEST_F(SubscriptionSerialization, PublishingModeParameters_Empty)
00806 // {
00807 //   using namespace OpcUa;
00808 //   using namespace OpcUa::Binary;
00809 //
00810 //   PublishingModeParameters params;
00811 //
00812 //   GetStream() << params << flush;
00813 //
00814 //   const std::vector<char> expectedData = {
00815 //     0,
00816 //     0,0,0,0, // Count of subscriptions
00817 //   };
00818 //
00819 //   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00820 //   ASSERT_EQ(expectedData.size(), RawSize(params));
00821 // }
00822 
00823 
00824 TEST_F(SubscriptionDeserialization, PublishingModeParameters)
00825 {
00826   using namespace OpcUa;
00827   using namespace OpcUa::Binary;
00828 
00829   const std::vector<char> expectedData = {
00830     1,
00831     1,0,0,0, // SubscriptionId
00832     1,0,0,0
00833   };
00834 
00835   GetChannel().SetData(expectedData);
00836 
00837   PublishingModeParameters params;
00838   GetStream() >> params;
00839 
00840   ASSERT_EQ(params.PublishingEnabled, true);
00841   ASSERT_EQ(params.SubscriptionIds.size(), 1);
00842   ASSERT_EQ(params.SubscriptionIds[0], 1);
00843 }
00844 
00845 //-------------------------------------------------------
00846 // SetPublishingModeRequest
00847 //-------------------------------------------------------
00848 
00849 TEST_F(SubscriptionSerialization, SetPublishingModeRequest)
00850 {
00851   using namespace OpcUa;
00852   using namespace OpcUa::Binary;
00853 
00854   SetPublishingModeRequest request;
00855 
00856   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00857   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00858   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::SET_PUBLISHING_MODE_REQUEST);
00859 
00860   FILL_TEST_REQUEST_HEADER(request.Header);
00861 
00862   request.Parameters.PublishingEnabled = true;
00863   request.Parameters.SubscriptionIds.push_back(IntegerId());
00864 
00865   GetStream() << request << flush;
00866 
00867   const std::vector<char> expectedData = {
00868     1, 0, (char)0x1F, 0x3, // TypeId
00869 
00870     // RequestHeader
00871     TEST_REQUEST_HEADER_BINARY_DATA,
00872 
00873     // PublishingEnabled
00874     1, // Enabled
00875     1,0,0,0,
00876     1,0,0,0
00877   };
00878 
00879   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00880   ASSERT_EQ(expectedData.size(), RawSize(request));
00881 }
00882 
00883 TEST_F(SubscriptionDeserialization, SetPublishingModeRequest)
00884 {
00885   using namespace OpcUa;
00886   using namespace OpcUa::Binary;
00887 
00888   const std::vector<char> expectedData = {
00889     1, 0, (char)0x1F, 0x3, // TypeId
00890 
00891     // RequestHeader
00892     TEST_REQUEST_HEADER_BINARY_DATA,
00893 
00894     // Parameters
00895     1, // Enabled
00896     1,0,0,0,
00897     1,0,0,0
00898   };
00899 
00900   GetChannel().SetData(expectedData);
00901 
00902   SetPublishingModeRequest request;
00903   GetStream() >> request;
00904 
00905   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00906   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00907   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::SET_PUBLISHING_MODE_REQUEST);
00908 
00909   ASSERT_REQUEST_HEADER_EQ(request.Header);
00910 
00911   ASSERT_EQ(request.Parameters.PublishingEnabled, true);
00912   ASSERT_EQ(request.Parameters.SubscriptionIds.size(), 1);
00913   ASSERT_EQ(request.Parameters.SubscriptionIds[0], 1);
00914 }
00915 
00916 //-------------------------------------------------------
00917 // PublishingModeResult
00918 //-------------------------------------------------------
00919 
00920 // TEST_F(SubscriptionSerialization, PublishingModeResult)
00921 // {
00922 //   using namespace OpcUa;
00923 //   using namespace OpcUa::Binary;
00924 //
00925 //   PublishingModeResult result;
00926 //   result.Results.push_back(StatusCode::Good);
00927 //
00928 //   GetStream() << result << flush;
00929 //
00930 //   const std::vector<char> expectedData = {
00931 //     1,0,0,0,
00932 //     0,0,0,0, // StatusCode
00933 //     0,0,0,0  // Count of diagnostics
00934 //   };
00935 //
00936 //   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00937 //   ASSERT_EQ(expectedData.size(), RawSize(result));
00938 // }
00939 
00940 // TEST_F(SubscriptionSerialization, PublishingModeResult_Empty)
00941 // {
00942 //   using namespace OpcUa;
00943 //   using namespace OpcUa::Binary;
00944 //
00945 //   PublishingModeResult result;
00946 //
00947 //   GetStream() << result << flush;
00948 //
00949 //   const std::vector<char> expectedData = {
00950 //     0,0,0,0,
00951 //     0,0,0,0, // Count of subscriptions
00952 //   };
00953 //
00954 //   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
00955 //   ASSERT_EQ(expectedData.size(), RawSize(result));
00956 // }
00957 
00958 
00959 TEST_F(SubscriptionDeserialization, PublishingModeResult)
00960 {
00961   using namespace OpcUa;
00962   using namespace OpcUa::Binary;
00963 
00964   const std::vector<char> expectedData = {
00965     1,0,0,0,
00966     0,0,0,0, // StatusCode
00967     0,0,0,0  // Count of diagnostics
00968   };
00969 
00970   GetChannel().SetData(expectedData);
00971 
00972   PublishingModeResult result;
00973   GetStream() >> result;
00974 
00975   ASSERT_EQ(result.Results.size(), 1);
00976   ASSERT_EQ(result.Results[0], StatusCode::Good);
00977   ASSERT_EQ(result.DiagnosticInfos.size(), 0);
00978 }
00979 
00980 //-------------------------------------------------------
00981 // SetPublishingModeResponse
00982 //-------------------------------------------------------
00983 
00984 // TEST_F(SubscriptionSerialization, SetPublishingModeResponse)
00985 // {
00986 //   using namespace OpcUa;
00987 //   using namespace OpcUa::Binary;
00988 //
00989 //   SetPublishingModeResponse response;
00990 //
00991 //   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00992 //   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00993 //   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::SET_PUBLISHING_MODE_RESPONSE);
00994 //
00995 //   FILL_TEST_RESPONSE_HEADER(response.Header);
00996 //
00997 //   response.Result.Results.push_back(StatusCode::Good);
00998 //
00999 //   GetStream() << response << flush;
01000 //
01001 //   const std::vector<char> expectedData = {
01002 //     1, 0, (char)0x22, 0x3, // TypeId
01003 //
01004 //     // RequestHeader
01005 //     TEST_RESPONSE_HEADER_BINARY_DATA,
01006 //
01007 //     1,0,0,0,
01008 //     0,0,0,0, // StatusCode
01009 //     0,0,0,0  // Count of diagnostics
01010 //   };
01011 //
01012 //   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
01013 //   ASSERT_EQ(expectedData.size(), RawSize(response));
01014 // }
01015 
01016 // TEST_F(SubscriptionSerialization, SetPublishingModeResponse_Empty)
01017 // {
01018 //   using namespace OpcUa;
01019 //   using namespace OpcUa::Binary;
01020 //
01021 //   SetPublishingModeResponse response;
01022 //
01023 //   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
01024 //   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
01025 //   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::SET_PUBLISHING_MODE_RESPONSE);
01026 //
01027 //   FILL_TEST_RESPONSE_HEADER(response.Header);
01028 //
01029 //   GetStream() << response << flush;
01030 //
01031 //   const std::vector<char> expectedData = {
01032 //     1, 0, (char)0x22, 0x3, // TypeId
01033 //
01034 //     // RequestHeader
01035 //     TEST_RESPONSE_HEADER_BINARY_DATA,
01036 //
01037 //     0,0,0,0, // StatusCode
01038 //     0,0,0,0  // Count of diagnostics
01039 //   };
01040 //
01041 //   ASSERT_EQ(expectedData, GetChannel().SerializedData) << "Actual:" << std::endl << PrintData(GetChannel().SerializedData) << std::endl << "Expected" << std::endl << PrintData(expectedData);
01042 //   ASSERT_EQ(expectedData.size(), RawSize(response));
01043 // }
01044 
01045 TEST_F(SubscriptionDeserialization, SetPublishingModeResponse)
01046 {
01047   using namespace OpcUa;
01048   using namespace OpcUa::Binary;
01049 
01050   const std::vector<char> expectedData = {
01051     1, 0, (char)0x22, 0x3, // TypeId
01052 
01053     // RequestHeader
01054     TEST_RESPONSE_HEADER_BINARY_DATA,
01055 
01056     1,0,0,0,
01057     0,0,0,0, // StatusCode
01058     0,0,0,0  // Count of diagnostics
01059   };
01060 
01061   GetChannel().SetData(expectedData);
01062 
01063   SetPublishingModeResponse response;
01064   GetStream() >> response;
01065 
01066   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
01067   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
01068   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::SET_PUBLISHING_MODE_RESPONSE);
01069 
01070   ASSERT_RESPONSE_HEADER_EQ(response.Header);
01071 
01072   ASSERT_EQ(response.Result.Results.size(), 1);
01073   ASSERT_EQ(response.Result.DiagnosticInfos.size(), 0);
01074 }


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:40