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
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
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,
00118
00119
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,
00141
00142
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
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
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,
00249
00250
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,
00270
00271
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
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
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
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,
00415
00416
00417 TEST_REQUEST_HEADER_BINARY_DATA,
00418
00419
00420 1,0,0,0,
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,
00436
00437
00438 TEST_REQUEST_HEADER_BINARY_DATA,
00439
00440
00441 1,0,0,0,
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
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,
00478 2,0,0,0,0,0,0,0,
00479
00480 1,0,0,0,
00481
00482 0,0,
00483 0,
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,
00497 2,0,0,0,0,0,0,0,
00498
00499 1,0,0,0,
00500 0,0,
00501 0,
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
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,
00545
00546 1,0,0,0,
00547 2,0,0,0,
00548
00549 1,
00550
00551
00552 1,0,0,0,
00553 2,0,0,0,0,0,0,0,
00554
00555 1,0,0,0,
00556 0,0,
00557 0,
00558
00559
00560 1,0,0,0,
00561 0,0,0,0,
00562
00563 1,0,0,0,
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,
00579
00580 1,0,0,0,
00581 2,0,0,0,
00582
00583 1,
00584
00585
00586 1,0,0,0,
00587 2,0,0,0,0,0,0,0,
00588
00589 1,0,0,0,
00590 0,0,
00591 0,
00592
00593
00594 1,0,0,0,
00595 0,0,0,0,
00596
00597 1,0,0,0,
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
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,
00653
00654
00655 TEST_RESPONSE_HEADER_BINARY_DATA,
00656
00657 1,0,0,0,
00658
00659 1,0,0,0,
00660 2,0,0,0,
00661
00662 1,
00663
00664
00665 1,0,0,0,
00666 2,0,0,0,0,0,0,0,
00667
00668 1,0,0,0,
00669 0,0,
00670 0,
00671
00672
00673 1,0,0,0,
00674 0,0,0,0,
00675
00676 1,0,0,0,
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
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
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,
00738
00739
00740 TEST_RESPONSE_HEADER_BINARY_DATA,
00741
00742 1,0,0,0,
00743
00744 1,0,0,0,
00745 2,0,0,0,
00746
00747 1,
00748
00749
00750 1,0,0,0,
00751 2,0,0,0,0,0,0,0,
00752
00753 1,0,0,0,
00754 0,0,
00755 0,
00756
00757
00758 1,0,0,0,
00759 0,0,0,0,
00760
00761 1,0,0,0,
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
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,
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
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
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,
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
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,
00869
00870
00871 TEST_REQUEST_HEADER_BINARY_DATA,
00872
00873
00874 1,
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,
00890
00891
00892 TEST_REQUEST_HEADER_BINARY_DATA,
00893
00894
00895 1,
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
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
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,
00967 0,0,0,0
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
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
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,
01052
01053
01054 TEST_RESPONSE_HEADER_BINARY_DATA,
01055
01056 1,0,0,0,
01057 0,0,0,0,
01058 0,0,0,0
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 }