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 #include <opc/ua/protocol/view.h>
00018
00019 #include <algorithm>
00020 #include <stdexcept>
00021
00022 class ViewSerialization : public OpcUaBinarySerialization
00023 {
00024 };
00025
00026 class ViewDeserialization : public OpcUaBinaryDeserialization
00027 {
00028 };
00029
00030
00031
00032
00033
00034
00035 TEST_F(ViewSerialization, BrowseDirection)
00036 {
00037
00038 using namespace OpcUa;
00039 using namespace OpcUa::Binary;
00040
00041 GetStream() << BrowseDirection::Both << flush;
00042
00043 const std::vector<char> expectedData = {
00044 2,0,0,0
00045 };
00046
00047 ASSERT_EQ(expectedData, GetChannel().SerializedData);
00048 ASSERT_EQ(expectedData.size(), RawSize(BrowseDirection::Both));
00049 }
00050
00051 TEST_F(ViewDeserialization, BrowseDirection)
00052 {
00053 using namespace OpcUa;
00054 using namespace OpcUa::Binary;
00055
00056 const std::vector<char> expectedData = {
00057 2,0,0,0
00058 };
00059
00060 GetChannel().SetData(expectedData);
00061
00062 BrowseDirection direction;
00063 GetStream() >> direction;
00064
00065 ASSERT_EQ(direction, BrowseDirection::Both);
00066 }
00067
00068
00069
00070
00071
00072 TEST_F(ViewSerialization, ViewDescription)
00073 {
00074
00075 using namespace OpcUa;
00076 using namespace OpcUa::Binary;
00077
00078 ViewDescription desc;
00079
00080 desc.Id.Encoding = EV_TWO_BYTE;
00081 desc.Id.TwoByteData.Identifier = 1;
00082 desc.Timestamp.Value = 2;
00083 desc.Version = 3;
00084
00085 GetStream() << desc << flush;
00086
00087 const std::vector<char> expectedData = {
00088 0, 1,
00089 2,0,0,0,0,0,0,0,
00090 3,0,0,0
00091 };
00092
00093 ASSERT_EQ(expectedData, GetChannel().SerializedData);
00094 ASSERT_EQ(expectedData.size(), RawSize(desc));
00095 }
00096
00097 TEST_F(ViewDeserialization, ViewDescription)
00098 {
00099
00100 using namespace OpcUa;
00101 using namespace OpcUa::Binary;
00102
00103 const std::vector<char> expectedData = {
00104 0, 1,
00105 2,0,0,0,0,0,0,0,
00106 3,0,0,0
00107 };
00108
00109 GetChannel().SetData(expectedData);
00110
00111 ViewDescription desc;
00112 GetStream() >> desc;
00113
00114 ASSERT_EQ(desc.Id.Encoding, EV_TWO_BYTE);
00115 ASSERT_EQ(desc.Id.TwoByteData.Identifier, 1);
00116 ASSERT_EQ(desc.Timestamp, 2);
00117 ASSERT_EQ(desc.Version, 3);
00118 }
00119
00120
00121
00122
00123
00124 TEST_F(ViewSerialization, BrowseDescription)
00125 {
00126
00127 using namespace OpcUa;
00128 using namespace OpcUa::Binary;
00129
00130 BrowseDescription desc;
00131
00132 desc.NodeToBrowse.Encoding = EV_TWO_BYTE;
00133 desc.NodeToBrowse.TwoByteData.Identifier = 1;
00134 desc.Direction = BrowseDirection::Inverse;
00135 desc.ReferenceTypeId.Encoding = EV_TWO_BYTE;
00136 desc.ReferenceTypeId.TwoByteData.Identifier = 2;
00137 desc.IncludeSubtypes = true;
00138 desc.NodeClasses = NodeClass::Variable;
00139 desc.ResultMask = BrowseResultMask::NodeClass;
00140
00141 GetStream() << desc << flush;
00142
00143 const std::vector<char> expectedData = {
00144 0, 1,
00145 1,0,0,0,
00146 0, 2,
00147 1,
00148 2,0,0,0,
00149 4,0,0,0
00150 };
00151
00152 ASSERT_EQ(expectedData, GetChannel().SerializedData);
00153 ASSERT_EQ(expectedData.size(), RawSize(desc));
00154 }
00155
00156 TEST_F(ViewDeserialization, BrowseDescription)
00157 {
00158
00159 using namespace OpcUa;
00160 using namespace OpcUa::Binary;
00161
00162 const std::vector<char> expectedData = {
00163 0, 1,
00164 1,0,0,0,
00165 0, 2,
00166 1,
00167 2,0,0,0,
00168 4,0,0,0
00169 };
00170
00171 GetChannel().SetData(expectedData);
00172
00173 BrowseDescription desc;
00174 GetStream() >> desc;
00175
00176 ASSERT_EQ(desc.NodeToBrowse.Encoding, EV_TWO_BYTE);
00177 ASSERT_EQ(desc.NodeToBrowse.TwoByteData.Identifier, 1);
00178 ASSERT_EQ(desc.Direction, BrowseDirection::Inverse);
00179 ASSERT_EQ(desc.ReferenceTypeId.Encoding, EV_TWO_BYTE);
00180 ASSERT_EQ(desc.ReferenceTypeId.TwoByteData.Identifier, 2);
00181 ASSERT_EQ(desc.IncludeSubtypes, true);
00182 ASSERT_EQ(desc.NodeClasses, NodeClass::Variable);
00183 ASSERT_EQ(desc.ResultMask, BrowseResultMask::NodeClass);
00184 }
00185
00186
00187
00188
00189
00190 OpcUa::BrowseDescription CreateBrowseDescription()
00191 {
00192 using namespace OpcUa;
00193 using namespace OpcUa::Binary;
00194 BrowseDescription desc;
00195 desc.NodeToBrowse.Encoding = EV_TWO_BYTE;
00196 desc.NodeToBrowse.TwoByteData.Identifier = 1;
00197 desc.Direction = BrowseDirection::Inverse;
00198 desc.ReferenceTypeId.Encoding = EV_TWO_BYTE;
00199 desc.ReferenceTypeId.TwoByteData.Identifier = 2;
00200 desc.IncludeSubtypes = true;
00201 desc.NodeClasses = NodeClass::Variable;
00202 desc.ResultMask = BrowseResultMask::NodeClass;
00203 return desc;
00204 }
00205
00206 bool operator==(const OpcUa::BrowseDescription& lhs, const OpcUa::BrowseDescription& rhs)
00207 {
00208 return
00209 rhs.NodeToBrowse.Encoding == lhs.NodeToBrowse.Encoding &&
00210 rhs.NodeToBrowse.TwoByteData.Identifier == lhs.NodeToBrowse.TwoByteData.Identifier &&
00211 rhs.Direction == lhs.Direction &&
00212 rhs.ReferenceTypeId.Encoding == lhs.ReferenceTypeId.Encoding &&
00213 rhs.ReferenceTypeId.TwoByteData.Identifier == lhs.ReferenceTypeId.TwoByteData.Identifier &&
00214 rhs.IncludeSubtypes == lhs.IncludeSubtypes &&
00215 rhs.NodeClasses == lhs.NodeClasses &&
00216 rhs.ResultMask == lhs.ResultMask;
00217 }
00218
00219 TEST_F(ViewSerialization, BrowseRequest)
00220 {
00221
00222 using namespace OpcUa;
00223 using namespace OpcUa::Binary;
00224
00225 BrowseRequest request;
00226
00227 ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00228 ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00229 ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::BROWSE_REQUEST);
00230
00231 FILL_TEST_REQUEST_HEADER(request.Header);
00232
00233 request.Query.View.Id.Encoding = EV_TWO_BYTE;
00234 request.Query.View.Id.TwoByteData.Identifier = 1;
00235 request.Query.View.Timestamp.Value = 2;
00236 request.Query.View.Version = 3;
00237
00238 request.Query.MaxReferenciesPerNode = 4;
00239
00240 request.Query.NodesToBrowse.push_back(CreateBrowseDescription());
00241 request.Query.NodesToBrowse.push_back(CreateBrowseDescription());
00242
00243 GetStream() << request << flush;
00244
00245 const std::vector<char> expectedData = {
00246 1, 0, (char)0x0f, 0x2,
00247
00248 TEST_REQUEST_HEADER_BINARY_DATA,
00249
00250 0, 1,
00251 2,0,0,0,0,0,0,0,
00252 3,0,0,0,
00253
00254 4,0,0,0,
00255
00256 2,0,0,0,
00257 0,1, 1,0,0,0, 0,2, 1, 2,0,0,0, 4,0,0,0,
00258 0,1, 1,0,0,0, 0,2, 1, 2,0,0,0, 4,0,0,0,
00259
00260
00261 };
00262
00263 ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00264 ASSERT_EQ(expectedData.size(), RawSize(request));
00265 }
00266
00267 TEST_F(ViewDeserialization, BrowseRequest)
00268 {
00269
00270 using namespace OpcUa;
00271 using namespace OpcUa::Binary;
00272
00273 const std::vector<char> expectedData = {
00274 1, 0, (char)0x0f, 0x2,
00275
00276 TEST_REQUEST_HEADER_BINARY_DATA,
00277
00278 0, 1,
00279 2,0,0,0,0,0,0,0,
00280 3,0,0,0,
00281
00282 4,0,0,0,
00283
00284 2,0,0,0,
00285 0,1, 1,0,0,0, 0,2, 1, 2,0,0,0, 4,0,0,0,
00286 0,1, 1,0,0,0, 0,2, 1, 2,0,0,0, 4,0,0,0,
00287
00288 };
00289
00290 GetChannel().SetData(expectedData);
00291 BrowseRequest request;
00292 GetStream() >> request;
00293
00294 ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00295 ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00296 ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::BROWSE_REQUEST);
00297
00298 ASSERT_REQUEST_HEADER_EQ(request.Header);
00299
00300 ASSERT_EQ(request.Query.View.Id.Encoding, EV_TWO_BYTE);
00301 ASSERT_EQ(request.Query.View.Id.TwoByteData.Identifier, 1);
00302 ASSERT_EQ(request.Query.View.Timestamp, 2);
00303 ASSERT_EQ(request.Query.View.Version, 3);
00304
00305 ASSERT_EQ(request.Query.MaxReferenciesPerNode, 4);
00306
00307 ASSERT_FALSE(request.Query.NodesToBrowse.empty());
00308
00309 BrowseDescription desc = CreateBrowseDescription();
00310
00311 ASSERT_TRUE(request.Query.NodesToBrowse[0] == desc);
00312 ASSERT_TRUE(request.Query.NodesToBrowse[1] == desc);
00313
00314 }
00315
00316
00317
00318
00319
00320 TEST_F(ViewSerialization, ReferenceDescription)
00321 {
00322
00323 using namespace OpcUa;
00324 using namespace OpcUa::Binary;
00325
00326 ReferenceDescription desc;
00327
00328 desc.ReferenceTypeId.Encoding = EV_TWO_BYTE;
00329 desc.ReferenceTypeId.TwoByteData.Identifier = 1;
00330
00331 desc.IsForward = true;
00332
00333 desc.TargetNodeId.Encoding = EV_TWO_BYTE;
00334 desc.TargetNodeId.TwoByteData.Identifier = 2;
00335
00336 desc.BrowseName.NamespaceIndex = 3;
00337 desc.BrowseName.Name = "name";
00338
00339 desc.DisplayName.Encoding = HAS_LOCALE | HAS_TEXT;
00340 desc.DisplayName.Locale = "loc";
00341 desc.DisplayName.Text = "text";
00342
00343 desc.TargetNodeClass = NodeClass::Method;
00344
00345 desc.TargetNodeTypeDefinition.Encoding = EV_TWO_BYTE;
00346 desc.TargetNodeTypeDefinition.TwoByteData.Identifier = 5;
00347
00348
00349 GetStream() << desc << flush;
00350
00351 const std::vector<char> expectedData = {
00352 0, 1,
00353 1,
00354 0, 2,
00355 3,0, 4,0,0,0, 'n','a','m','e',
00356 3,
00357 3,0,0,0, 'l','o','c',
00358 4,0,0,0, 't','e','x','t',
00359 4,0,0,0,
00360 0, 5
00361 };
00362
00363 ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00364 ASSERT_EQ(expectedData.size(), RawSize(desc));
00365 }
00366
00367 TEST_F(ViewDeserialization, ReferenceDescription)
00368 {
00369
00370 using namespace OpcUa;
00371 using namespace OpcUa::Binary;
00372
00373 const std::vector<char> expectedData = {
00374 0, 1,
00375 1,
00376 0, 2,
00377 3,0, 4,0,0,0, 'n','a','m','e',
00378 3,
00379 3,0,0,0, 'l','o','c',
00380 4,0,0,0, 't','e','x','t',
00381 4,0,0,0,
00382 0, 5
00383 };
00384
00385 GetChannel().SetData(expectedData);
00386
00387 ReferenceDescription desc;
00388
00389 GetStream() >> desc;
00390
00391 ASSERT_EQ(desc.ReferenceTypeId.Encoding, EV_TWO_BYTE);
00392 ASSERT_EQ(desc.ReferenceTypeId.TwoByteData.Identifier, 1);
00393
00394 ASSERT_EQ(desc.IsForward, true);
00395
00396 ASSERT_EQ(desc.TargetNodeId.Encoding, EV_TWO_BYTE);
00397 ASSERT_EQ(desc.TargetNodeId.TwoByteData.Identifier, 2);
00398
00399 ASSERT_EQ(desc.BrowseName.NamespaceIndex, 3);
00400 ASSERT_EQ(desc.BrowseName.Name, "name");
00401
00402 ASSERT_EQ(desc.DisplayName.Encoding, HAS_LOCALE | HAS_TEXT);
00403 ASSERT_EQ(desc.DisplayName.Locale, "loc");
00404 ASSERT_EQ(desc.DisplayName.Text, "text");
00405
00406 ASSERT_EQ(desc.TargetNodeClass, NodeClass::Method);
00407
00408 ASSERT_EQ(desc.TargetNodeTypeDefinition.Encoding, EV_TWO_BYTE);
00409 ASSERT_EQ(desc.TargetNodeTypeDefinition.TwoByteData.Identifier, 5);
00410 }
00411
00412
00413
00414
00415
00416 OpcUa::ReferenceDescription CreateReferenceDescription()
00417 {
00418 using namespace OpcUa;
00419 using namespace OpcUa::Binary;
00420 ReferenceDescription desc;
00421
00422 desc.ReferenceTypeId.Encoding = EV_TWO_BYTE;
00423 desc.ReferenceTypeId.TwoByteData.Identifier = 1;
00424
00425 desc.IsForward = true;
00426
00427 desc.TargetNodeId.Encoding = EV_TWO_BYTE;
00428 desc.TargetNodeId.TwoByteData.Identifier = 2;
00429
00430 desc.BrowseName.NamespaceIndex = 3;
00431 desc.BrowseName.Name = "name";
00432
00433 desc.DisplayName.Encoding = HAS_LOCALE | HAS_TEXT;
00434 desc.DisplayName.Locale = "loc";
00435 desc.DisplayName.Text = "text";
00436
00437 desc.TargetNodeClass = NodeClass::Method;
00438
00439 desc.TargetNodeTypeDefinition.Encoding = EV_TWO_BYTE;
00440 desc.TargetNodeTypeDefinition.TwoByteData.Identifier = 5;
00441 return desc;
00442 }
00443
00444 TEST_F(ViewSerialization, BrowseResult)
00445 {
00446
00447 using namespace OpcUa;
00448 using namespace OpcUa::Binary;
00449
00450 BrowseResult result;
00451 result.Status = static_cast<OpcUa::StatusCode>(1);
00452 result.ContinuationPoint = {2,3,4,5};
00453 result.Referencies.push_back(CreateReferenceDescription());
00454
00455 GetStream() << result << flush;
00456
00457 const std::vector<char> expectedData = {
00458 1,0,0,0,
00459 4,0,0,0, 2,3,4,5,
00460
00461 1,0,0,0,
00462 0, 1,
00463 1,
00464 0, 2,
00465 3,0, 4,0,0,0, 'n','a','m','e',
00466 3,
00467 3,0,0,0, 'l','o','c',
00468 4,0,0,0, 't','e','x','t',
00469 4,0,0,0,
00470 0, 5
00471 };
00472
00473 ASSERT_EQ(expectedData.size(), RawSize(result));
00474 ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00475 }
00476
00477 TEST_F(ViewDeserialization, BrowseResult)
00478 {
00479 using namespace OpcUa;
00480 using namespace OpcUa::Binary;
00481
00482 const std::vector<char> expectedData = {
00483 1,0,0,0,
00484 4,0,0,0, 2,3,4,5,
00485
00486 1,0,0,0,
00487 0, 1,
00488 1,
00489 0, 2,
00490 3,0, 4,0,0,0, 'n','a','m','e',
00491 3,
00492 3,0,0,0, 'l','o','c',
00493 4,0,0,0, 't','e','x','t',
00494 4,0,0,0,
00495 0, 5
00496 };
00497
00498 GetChannel().SetData(expectedData);
00499
00500 BrowseResult result;
00501 GetStream() >> result;
00502
00503 ASSERT_EQ(result.Status, static_cast<OpcUa::StatusCode>(1));
00504 std::vector<uint8_t> cont = {2,3,4,5};
00505 ASSERT_EQ(result.ContinuationPoint, cont);
00506 ASSERT_FALSE(result.Referencies.empty());
00507
00508 const ReferenceDescription& desc = result.Referencies[0];
00509 ASSERT_EQ(desc.ReferenceTypeId.Encoding, EV_TWO_BYTE);
00510 ASSERT_EQ(desc.ReferenceTypeId.TwoByteData.Identifier, 1);
00511 ASSERT_EQ(desc.IsForward, true);
00512 ASSERT_EQ(desc.TargetNodeId.Encoding, EV_TWO_BYTE);
00513 ASSERT_EQ(desc.TargetNodeId.TwoByteData.Identifier, 2);
00514 ASSERT_EQ(desc.BrowseName.NamespaceIndex, 3);
00515 ASSERT_EQ(desc.BrowseName.Name, "name");
00516 ASSERT_EQ(desc.DisplayName.Encoding, HAS_LOCALE | HAS_TEXT);
00517 ASSERT_EQ(desc.DisplayName.Locale, "loc");
00518 ASSERT_EQ(desc.DisplayName.Text, "text");
00519 ASSERT_EQ(desc.TargetNodeClass, NodeClass::Method);
00520 ASSERT_EQ(desc.TargetNodeTypeDefinition.Encoding, EV_TWO_BYTE);
00521 ASSERT_EQ(desc.TargetNodeTypeDefinition.TwoByteData.Identifier, 5);
00522 }
00523
00524
00525
00526
00527
00528 OpcUa::BrowseResult CreateBrowseResult()
00529 {
00530 OpcUa::BrowseResult result;
00531 result.Status = static_cast<OpcUa::StatusCode>(1);
00532 result.ContinuationPoint = {2,3,4,5};
00533 result.Referencies.push_back(CreateReferenceDescription());
00534 return result;
00535 }
00536
00537 TEST_F(ViewSerialization, BrowseResponse)
00538 {
00539 using namespace OpcUa;
00540 using namespace OpcUa::Binary;
00541
00542 BrowseResponse response;
00543
00544 ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00545 ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00546 ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::BROWSE_RESPONSE);
00547
00548 FILL_TEST_RESPONSE_HEADER(response.Header);
00549
00550 response.Results.push_back(CreateBrowseResult());
00551
00552 DiagnosticInfo diag1;
00553 diag1.EncodingMask = DIM_LOCALIZED_TEXT;
00554 diag1.LocalizedText = 4;
00555 DiagnosticInfo diag2;
00556 diag2.EncodingMask = DIM_ADDITIONAL_INFO;
00557 diag2.AdditionalInfo = "add";
00558 response.Diagnostics.push_back(diag1);
00559 response.Diagnostics.push_back(diag2);
00560
00561 GetStream() << response << flush;
00562
00563 const std::vector<char> expectedData = {
00564 1, 0, (char)0x12, 0x2,
00565
00566 TEST_RESPONSE_HEADER_BINARY_DATA,
00567
00568
00569 1,0,0,0,
00570
00571 1,0,0,0,
00572 4,0,0,0, 2,3,4,5,
00573 1,0,0,0,
00574 0, 1,
00575 1,
00576 0, 2,
00577 3,0, 4,0,0,0, 'n','a','m','e',
00578 3,
00579 3,0,0,0, 'l','o','c',
00580 4,0,0,0, 't','e','x','t',
00581 4,0,0,0,
00582 0, 5,
00583
00584 2,0,0,0,
00585
00586 DIM_LOCALIZED_TEXT, 4,0,0,0, \
00587 DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
00588 };
00589
00590 ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00591 ASSERT_EQ(expectedData.size(), RawSize(response));
00592 }
00593
00594 TEST_F(ViewDeserialization, BrowseResponse)
00595 {
00596 using namespace OpcUa;
00597 using namespace OpcUa::Binary;
00598
00599 const std::vector<char> expectedData = {
00600 1, 0, (char)0x12, 0x2,
00601
00602 TEST_RESPONSE_HEADER_BINARY_DATA,
00603
00604
00605 1,0,0,0,
00606
00607 1,0,0,0,
00608 4,0,0,0, 2,3,4,5,
00609 1,0,0,0,
00610 0, 1,
00611 1,
00612 0, 2,
00613 3,0, 4,0,0,0, 'n','a','m','e',
00614 3,
00615 3,0,0,0, 'l','o','c',
00616 4,0,0,0, 't','e','x','t',
00617 4,0,0,0,
00618 0, 5,
00619
00620 2,0,0,0,
00621
00622 DIM_LOCALIZED_TEXT, 4,0,0,0, \
00623 DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
00624 };
00625
00626
00627 GetChannel().SetData(expectedData);
00628
00629 BrowseResponse response;
00630 GetStream() >> response;
00631
00632 ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00633 ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00634 ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::BROWSE_RESPONSE);
00635
00636 ASSERT_RESPONSE_HEADER_EQ(response.Header);
00637
00638 ASSERT_EQ(response.Results.size(), 1);
00639 ASSERT_EQ(response.Diagnostics.size(), 2);
00640 }
00641
00642
00643
00644
00645
00646
00647 TEST_F(ViewSerialization, BrowseNextRequest)
00648 {
00649 using namespace OpcUa;
00650 using namespace OpcUa::Binary;
00651
00652 BrowseNextRequest request;
00653
00654 ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00655 ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00656 ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::BROWSE_NEXT_REQUEST);
00657
00658 FILL_TEST_REQUEST_HEADER(request.Header);
00659
00660 request.ReleaseContinuationPoints = true;
00661 request.ContinuationPoints.push_back(std::vector<uint8_t>{1});
00662
00663 GetStream() << request << flush;
00664
00665 const std::vector<char> expectedData = {
00666 1, 0, (char)0x15, 0x2,
00667
00668 TEST_REQUEST_HEADER_BINARY_DATA,
00669
00670 1,
00671 1,0,0,0, 1,0,0,0, 1
00672 };
00673
00674 ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00675 ASSERT_EQ(expectedData.size(), RawSize(request));
00676 }
00677
00678 TEST_F(ViewDeserialization, BrowseNextRequest)
00679 {
00680
00681 using namespace OpcUa;
00682 using namespace OpcUa::Binary;
00683
00684 const std::vector<char> expectedData = {
00685 1, 0, (char)0x15, 0x2,
00686
00687 TEST_REQUEST_HEADER_BINARY_DATA,
00688
00689 1,
00690 1,0,0,0, 1,0,0,0, 1
00691 };
00692
00693 GetChannel().SetData(expectedData);
00694 BrowseNextRequest request;
00695 GetStream() >> request;
00696
00697 ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00698 ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00699 ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::BROWSE_NEXT_REQUEST);
00700
00701 ASSERT_REQUEST_HEADER_EQ(request.Header);
00702
00703 ASSERT_EQ(request.ReleaseContinuationPoints, true);
00704 ASSERT_TRUE(!request.ContinuationPoints.empty());
00705 ASSERT_EQ(request.ContinuationPoints[0], std::vector<uint8_t>(1,1));
00706 }
00707
00708
00709
00710
00711
00712 TEST_F(ViewSerialization, BrowseNextResponse)
00713 {
00714 using namespace OpcUa;
00715 using namespace OpcUa::Binary;
00716
00717 BrowseNextResponse response;
00718
00719 ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00720 ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00721 ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::BROWSE_NEXT_RESPONSE);
00722
00723 FILL_TEST_RESPONSE_HEADER(response.Header);
00724
00725 response.Results.push_back(CreateBrowseResult());
00726 DiagnosticInfo diag;
00727 diag.EncodingMask = static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO);
00728 diag.LocalizedText = 4;
00729 diag.InnerDiagnostics.reset(new DiagnosticInfo());
00730 diag.InnerDiagnostics->EncodingMask = DIM_ADDITIONAL_INFO;
00731 diag.InnerDiagnostics->AdditionalInfo = "add";
00732 response.Diagnostics.push_back(diag);
00733
00734 GetStream() << response << flush;
00735
00736 const std::vector<char> expectedData = {
00737 1, 0, (char)0x18, 0x2,
00738
00739 TEST_RESPONSE_HEADER_BINARY_DATA,
00740
00741
00742 1,0,0,0,
00743
00744 1,0,0,0,
00745 4,0,0,0, 2,3,4,5,
00746 1,0,0,0,
00747 0, 1,
00748 1,
00749 0, 2,
00750 3,0, 4,0,0,0, 'n','a','m','e',
00751 3,
00752 3,0,0,0, 'l','o','c',
00753 4,0,0,0, 't','e','x','t',
00754 4,0,0,0,
00755 0, 5,
00756
00757 1,0,0,0,
00758
00759 static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4,0,0,0, \
00760 DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
00761 };
00762
00763 ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00764 ASSERT_EQ(expectedData.size(), RawSize(response));
00765 }
00766
00767 TEST_F(ViewDeserialization, BrowseNextResponse)
00768 {
00769 using namespace OpcUa;
00770 using namespace OpcUa::Binary;
00771
00772 const std::vector<char> expectedData = {
00773 1, 0, (char)0x18, 0x2,
00774
00775 TEST_RESPONSE_HEADER_BINARY_DATA,
00776
00777
00778 1,0,0,0,
00779
00780 1,0,0,0,
00781 4,0,0,0, 2,3,4,5,
00782 1,0,0,0,
00783 0, 1,
00784 1,
00785 0, 2,
00786 3,0, 4,0,0,0, 'n','a','m','e',
00787 3,
00788 3,0,0,0, 'l','o','c',
00789 4,0,0,0, 't','e','x','t',
00790 4,0,0,0,
00791 0, 5,
00792
00793 1,0,0,0,
00794
00795 static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4,0,0,0, \
00796 DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
00797 };
00798
00799
00800 GetChannel().SetData(expectedData);
00801
00802 BrowseNextResponse response;
00803 GetStream() >> response;
00804
00805 ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00806 ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00807 ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::BROWSE_NEXT_RESPONSE);
00808
00809 ASSERT_RESPONSE_HEADER_EQ(response.Header);
00810
00811 ASSERT_EQ(response.Results.size(), 1);
00812 ASSERT_EQ(response.Diagnostics.size(), 1);
00813 }
00814
00815
00816
00817
00818
00819 TEST_F(ViewSerialization, BrowsePathTarget)
00820 {
00821 using namespace OpcUa;
00822 using namespace OpcUa::Binary;
00823
00824 BrowsePathTarget target;
00825
00826 target.Node.Encoding = EV_TWO_BYTE;
00827 target.Node.TwoByteData.Identifier = 1;
00828 target.RemainingPathIndex = 2;
00829
00830 GetStream() << target << flush;
00831
00832 const std::vector<char> expectedData = {
00833 0, 1,
00834 2,0,0,0,
00835 };
00836
00837 ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00838 ASSERT_EQ(expectedData.size(), RawSize(target));
00839 }
00840
00841 TEST_F(ViewDeserialization, BrowsePathTarget)
00842 {
00843
00844 using namespace OpcUa;
00845 using namespace OpcUa::Binary;
00846
00847 const std::vector<char> expectedData = {
00848 0, 1,
00849 2,0,0,0,
00850 };
00851
00852 GetChannel().SetData(expectedData);
00853
00854 BrowsePathTarget target;
00855
00856 GetStream() >> target;
00857
00858 ASSERT_EQ(target.Node.Encoding, EV_TWO_BYTE);
00859 ASSERT_EQ(target.Node.TwoByteData.Identifier, 1);
00860 ASSERT_EQ(target.RemainingPathIndex, 2);
00861 }
00862
00863
00864
00865
00866
00867 TEST_F(ViewSerialization, BrowsePathResult)
00868 {
00869 using namespace OpcUa;
00870 using namespace OpcUa::Binary;
00871
00872
00873 BrowsePathTarget target;
00874 target.Node.Encoding = EV_TWO_BYTE;
00875 target.Node.TwoByteData.Identifier = 1;
00876 target.RemainingPathIndex = 2;
00877
00878 BrowsePathResult result;
00879 result.Status = static_cast<StatusCode>(3);
00880 result.Targets.push_back(target);
00881
00882 GetStream() << result << flush;
00883
00884 const std::vector<char> expectedData = {
00885 3,0,0,0,
00886 1,0,0,0,
00887 0, 1,
00888 2,0,0,0,
00889 };
00890
00891 ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00892 ASSERT_EQ(expectedData.size(), RawSize(result));
00893 }
00894
00895 TEST_F(ViewDeserialization, BrowsePathResult)
00896 {
00897
00898 using namespace OpcUa;
00899 using namespace OpcUa::Binary;
00900
00901 const std::vector<char> expectedData = {
00902 3,0,0,0,
00903 1,0,0,0,
00904 0, 1,
00905 2,0,0,0,
00906 };
00907
00908 GetChannel().SetData(expectedData);
00909
00910 BrowsePathResult result;
00911
00912 GetStream() >> result;
00913
00914 ASSERT_EQ(result.Status, static_cast<StatusCode>(3));
00915 ASSERT_EQ(result.Targets.size(), 1);
00916 ASSERT_EQ(result.Targets[0].Node.Encoding, EV_TWO_BYTE);
00917 ASSERT_EQ(result.Targets[0].Node.TwoByteData.Identifier, 1);
00918 ASSERT_EQ(result.Targets[0].RemainingPathIndex, 2);
00919 }
00920
00921
00922
00923
00924
00925 TEST_F(ViewSerialization, TranslateBrowsePathsResult)
00926 {
00927 using namespace OpcUa;
00928 using namespace OpcUa::Binary;
00929
00930
00931 BrowsePathTarget target;
00932 target.Node.Encoding = EV_TWO_BYTE;
00933 target.Node.TwoByteData.Identifier = 1;
00934 target.RemainingPathIndex = 2;
00935
00936 BrowsePathResult result;
00937 result.Status = static_cast<StatusCode>(3);
00938 result.Targets.push_back(target);
00939
00940 TranslateBrowsePathsResult translateResult;
00941 translateResult.Paths.push_back(result);
00942
00943 GetStream() << translateResult << flush;
00944
00945 const std::vector<char> expectedData = {
00946 1,0,0,0,
00947 3,0,0,0,
00948 1,0,0,0,
00949 0, 1,
00950 2,0,0,0,
00951
00952 0,0,0,0,
00953 };
00954
00955 ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00956 ASSERT_EQ(expectedData.size(), RawSize(translateResult));
00957 }
00958
00959 TEST_F(ViewDeserialization, TranslateBrowsePathsResult)
00960 {
00961 using namespace OpcUa;
00962 using namespace OpcUa::Binary;
00963
00964 const std::vector<char> expectedData = {
00965 1,0,0,0,
00966 3,0,0,0,
00967 1,0,0,0,
00968 0, 1,
00969 2,0,0,0,
00970
00971 0,0,0,0,
00972 };
00973
00974 GetChannel().SetData(expectedData);
00975
00976 TranslateBrowsePathsResult translateResult;
00977
00978 GetStream() >> translateResult;
00979
00980 ASSERT_EQ(translateResult.Paths.size(), 1);
00981 ASSERT_EQ(translateResult.Diagnostics.size(), 0);
00982 }
00983
00984
00985
00986
00987
00988 TEST_F(ViewSerialization, TranslateBrowsePathsToNodeIdsResponse)
00989 {
00990 using namespace OpcUa;
00991 using namespace OpcUa::Binary;
00992
00993 BrowsePathTarget target;
00994 target.Node.Encoding = EV_TWO_BYTE;
00995 target.Node.TwoByteData.Identifier = 1;
00996 target.RemainingPathIndex = 2;
00997
00998 BrowsePathResult result;
00999 result.Status = static_cast<StatusCode>(3);
01000 result.Targets.push_back(target);
01001
01002 TranslateBrowsePathsToNodeIdsResponse response;
01003 response.Result.Paths.push_back(result);
01004
01005 ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
01006 ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
01007 ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::TRANSLATE_BROWSE_PATHS_TO_NODE_IdS_RESPONSE);
01008
01009 FILL_TEST_RESPONSE_HEADER(response.Header);
01010
01011 DiagnosticInfo diag;
01012 diag.EncodingMask = static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO);
01013 diag.LocalizedText = 4;
01014 diag.InnerDiagnostics.reset(new DiagnosticInfo());
01015 diag.InnerDiagnostics->EncodingMask = DIM_ADDITIONAL_INFO;
01016 diag.InnerDiagnostics->AdditionalInfo = "add";
01017 response.Result.Diagnostics.push_back(diag);
01018
01019 GetStream() << response << flush;
01020
01021 const std::vector<char> expectedData = {
01022 1, 0, (char)0x2D, 0x2,
01023
01024 TEST_RESPONSE_HEADER_BINARY_DATA,
01025
01026
01027 1,0,0,0,
01028 3,0,0,0,
01029 1,0,0,0,
01030 0, 1,
01031 2,0,0,0,
01032
01033
01034 1,0,0,0,
01035 static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4,0,0,0, \
01036 DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \
01037 };
01038
01039 ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
01040 ASSERT_EQ(expectedData.size(), RawSize(response));
01041 }
01042
01043 TEST_F(ViewDeserialization, TranslateBrowsePathsToNodeIdsResponse)
01044 {
01045 using namespace OpcUa;
01046 using namespace OpcUa::Binary;
01047
01048 const std::vector<char> expectedData = {
01049 1, 0, (char)0x2D, 0x2,
01050
01051 TEST_RESPONSE_HEADER_BINARY_DATA,
01052
01053
01054 1,0,0,0,
01055 3,0,0,0,
01056 1,0,0,0,
01057 0, 1,
01058 2,0,0,0,
01059
01060
01061 1,0,0,0,
01062 static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4,0,0,0, \
01063 DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd',
01064 };
01065
01066 GetChannel().SetData(expectedData);
01067
01068 TranslateBrowsePathsToNodeIdsResponse response;
01069 GetStream() >> response;
01070
01071 ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
01072 ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
01073 ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::TRANSLATE_BROWSE_PATHS_TO_NODE_IdS_RESPONSE);
01074
01075 ASSERT_RESPONSE_HEADER_EQ(response.Header);
01076
01077 ASSERT_EQ(response.Result.Paths.size(), 1);
01078 ASSERT_EQ(response.Result.Diagnostics.size(), 1);
01079 }
01080
01081
01082
01083
01084
01085 TEST_F(ViewSerialization, TranslateBrowsePathsToNodeIdsRequest)
01086 {
01087 using namespace OpcUa;
01088 using namespace OpcUa::Binary;
01089
01090 RelativePathElement element;
01091 element.ReferenceTypeId = OpcUa::TwoByteNodeId(1);
01092 element.IsInverse = true;
01093 element.IncludeSubtypes = true;
01094 element.TargetName.NamespaceIndex = 2;
01095 element.TargetName.Name = "name";
01096
01097 BrowsePath browse;
01098 browse.StartingNode = OpcUa::TwoByteNodeId(2);
01099 browse.Path.Elements.push_back(element);
01100
01101 TranslateBrowsePathsToNodeIdsRequest request;
01102 request.Parameters.BrowsePaths.push_back(browse);
01103
01104 ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
01105 ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
01106 ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::TRANSLATE_BROWSE_PATHS_TO_NODE_IdS_REQUEST);
01107
01108 FILL_TEST_REQUEST_HEADER(request.Header);
01109
01110 GetStream() << request << flush;
01111
01112 const std::vector<char> expectedData = {
01113 1, 0, (char)0x2A, 0x2,
01114
01115 TEST_REQUEST_HEADER_BINARY_DATA,
01116
01117 1,0,0,0,
01118 0,2,
01119 1,0,0,0,
01120 0,1,
01121 1,
01122 1,
01123 2,0, 4,0,0,0, 'n','a','m','e',
01124 };
01125
01126 ASSERT_EQ(expectedData, GetChannel().SerializedData) <<
01127 "Serialized: " << std::endl << PrintData(GetChannel().SerializedData) << std::endl <<
01128 "Expected" << std::endl << PrintData(expectedData);
01129 ASSERT_EQ(expectedData.size(), RawSize(request));
01130 }
01131
01132 TEST_F(ViewDeserialization, TranslateBrowsePathsToNodeIdsRequest)
01133 {
01134 using namespace OpcUa;
01135 using namespace OpcUa::Binary;
01136
01137 const std::vector<char> expectedData = {
01138 1, 0, (char)0x2A, 0x2,
01139
01140 TEST_REQUEST_HEADER_BINARY_DATA,
01141
01142 1,0,0,0,
01143 0,2,
01144 1,0,0,0,
01145 0,1,
01146 1,
01147 1,
01148 2,0, 4,0,0,0, 'n','a','m','e',
01149 };
01150
01151 GetChannel().SetData(expectedData);
01152
01153 TranslateBrowsePathsToNodeIdsRequest request;
01154 GetStream() >> request;
01155
01156 ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
01157 ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
01158 ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::TRANSLATE_BROWSE_PATHS_TO_NODE_IdS_REQUEST);
01159
01160 ASSERT_REQUEST_HEADER_EQ(request.Header);
01161
01162 ASSERT_EQ(request.Parameters.BrowsePaths.size(), 1);
01163 const BrowsePath& browsePath = request.Parameters.BrowsePaths[0];
01164 ASSERT_EQ(browsePath.StartingNode, OpcUa::TwoByteNodeId(2));
01165 ASSERT_EQ(browsePath.Path.Elements.size(), 1);
01166
01167 const RelativePathElement& element = browsePath.Path.Elements[0];
01168 ASSERT_TRUE(element.IncludeSubtypes);
01169 ASSERT_TRUE(element.IsInverse);
01170 ASSERT_EQ(element.ReferenceTypeId, OpcUa::TwoByteNodeId(1));
01171 ASSERT_EQ(element.TargetName.NamespaceIndex, 2);
01172 ASSERT_EQ(element.TargetName.Name, "name");
01173 }