00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "common.h"
00012
00013 using namespace testing;
00014
00015
00016
00017
00018
00019 TEST_F(OpcUaBinaryDeserialization, UInt8)
00020 {
00021 std::vector<char> serializedData = {-1};
00022 GetChannel().SetData(serializedData);
00023 uint8_t byte = 0;
00024 GetStream() >> byte;
00025 ASSERT_EQ(byte, 0xff);
00026 }
00027
00028 TEST_F(OpcUaBinaryDeserialization, Int8)
00029 {
00030 std::vector<char> serializedData = {-1};
00031 GetChannel().SetData(serializedData);
00032 int8_t byte = 0;
00033 GetStream() >> byte;
00034 ASSERT_EQ(byte, -1);
00035 }
00036
00037 TEST_F(OpcUaBinaryDeserialization, UInt16)
00038 {
00039 std::vector<char> serializedData = {0, -1};
00040 GetChannel().SetData(serializedData);
00041 uint16_t word = 0;
00042 GetStream() >> word;
00043 ASSERT_EQ(word, 0xff00);
00044 }
00045
00046 TEST_F(OpcUaBinaryDeserialization, Int16)
00047 {
00048 std::vector<char> serializedData = {0, -1};
00049 GetChannel().SetData(serializedData);
00050 int16_t word = 0;
00051 GetStream() >> word;
00052 ASSERT_EQ(word, -256);
00053 }
00054
00055 TEST_F(OpcUaBinaryDeserialization, UInt32)
00056 {
00057 std::vector<char> serializedData = {0, -1, 0, -1};
00058 GetChannel().SetData(serializedData);
00059 uint32_t dword = 0;
00060 GetStream() >> dword;
00061 ASSERT_EQ(dword, 0xff00ff00);
00062 }
00063
00064 TEST_F(OpcUaBinaryDeserialization, Int32)
00065 {
00066 std::vector<char> serializedData = {0, -1, 0, -1};
00067 GetChannel().SetData(serializedData);
00068 int32_t sdword = 0;
00069 GetStream() >> sdword;
00070 ASSERT_EQ(sdword, (int32_t)0xff00ff00);
00071 }
00072
00073 TEST_F(OpcUaBinaryDeserialization, UInt64)
00074 {
00075 std::vector<char> serializedData = {0, -1, 0, -1, 0, 0, -1, -1};
00076 GetChannel().SetData(serializedData);
00077 uint64_t qword = 0;
00078 GetStream() >> qword;
00079 ASSERT_EQ(qword, 0xffff0000ff00ff00);
00080 }
00081
00082 TEST_F(OpcUaBinaryDeserialization, Int64)
00083 {
00084 std::vector<char> serializedData = {0, -1, 0, -1, 0, 0, -1, -1};
00085 GetChannel().SetData(serializedData);
00086 int64_t sqword = 0;
00087 GetStream() >> sqword;
00088 ASSERT_EQ(sqword, -281470698455296);
00089 }
00090
00091
00092
00093
00094
00095 TEST_F(OpcUaBinaryDeserialization, Float)
00096 {
00097 const std::vector<char> serializedData = {0, 0, (char)0xD0, (char)0xC0};
00098 GetChannel().SetData(serializedData);
00099 float num = 0;
00100 GetStream() >> num;
00101 ASSERT_EQ(num, -6.5);
00102 }
00103
00104 TEST_F(OpcUaBinaryDeserialization, Double)
00105 {
00106 std::vector<char> serializedData = {0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41};
00107 GetChannel().SetData(serializedData);
00108 double num = 0;
00109 GetStream() >> num;
00110 ASSERT_EQ(num, 1200000);
00111 }
00112
00113
00114
00115
00116
00117 TEST_F(OpcUaBinaryDeserialization, StdString)
00118 {
00119 const std::vector<char> serializedData = {3, 0, 0, 0, 'u', 'r', 'l'};
00120 GetChannel().SetData(serializedData);
00121
00122 std::string deserializedString;
00123 GetStream() >> deserializedString;
00124
00125 std::string expectedString = {'u', 'r', 'l'};
00126 ASSERT_EQ(deserializedString, expectedString);
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 TEST_F(OpcUaBinaryDeserialization, EmptyStdString)
00143 {
00144 const std::vector<char> serializedData = {-1, -1, -1, -1};
00145 GetChannel().SetData(serializedData);
00146
00147 std::string deserializedString;
00148 GetStream() >> deserializedString;
00149
00150 std::string expectedString;
00151 ASSERT_EQ(deserializedString, expectedString);
00152 }
00153
00154
00155
00156
00157
00158
00159 TEST_F(OpcUaBinaryDeserialization, ByteString)
00160 {
00161 const std::vector<char> serializedData = {3, 0, 0, 0, 'u', 'r', 'l'};
00162 GetChannel().SetData(serializedData);
00163
00164 std::vector<uint8_t> deserializedBytes;
00165 GetStream() >> deserializedBytes;
00166
00167 std::vector<uint8_t> expectedBytes = {'u', 'r', 'l'};
00168 ASSERT_EQ(deserializedBytes, expectedBytes);
00169 }
00170
00171 TEST_F(OpcUaBinaryDeserialization, AbsentBytes)
00172 {
00173 const std::vector<char> serializedData = {-1, -1, -1, -1};
00174 GetChannel().SetData(serializedData);
00175
00176 std::vector<uint8_t> deserializedBytes;
00177 GetStream() >> deserializedBytes;
00178
00179 std::vector<uint8_t> expectedBytes;
00180 ASSERT_EQ(deserializedBytes, expectedBytes);
00181 }
00182
00183
00184
00185
00186
00187 TEST_F(OpcUaBinaryDeserialization, RawBuffer)
00188 {
00189 const std::vector<char> serializedData = {3, 0, 0, 0, 'u', 'r', 'l'};
00190 GetChannel().SetData(serializedData);
00191
00192 std::vector<char> deserializedBytes(serializedData.size());
00193 OpcUa::Binary::RawBuffer rawBuffer(&deserializedBytes[0], deserializedBytes.size());
00194 GetStream() >> rawBuffer;
00195
00196 ASSERT_EQ(rawBuffer.Size, serializedData.size());
00197 ASSERT_EQ(deserializedBytes, serializedData);
00198 }
00199
00200
00201
00202
00203
00204 TEST_F(OpcUaBinaryDeserialization, LocalizedText_Full)
00205 {
00206 const std::vector<char> serializedData = {3, 2,0,0,0,'e','n', 4,0,0,0,'t','e','x','t'};
00207 GetChannel().SetData(serializedData);
00208
00209 OpcUa::LocalizedText lt;
00210 GetStream() >> lt;
00211
00212 ASSERT_EQ(lt.Locale, "en");
00213 ASSERT_EQ(lt.Text, "text");
00214 }
00215
00216 TEST_F(OpcUaBinaryDeserialization, LocalizedText_Locale)
00217 {
00218 const std::vector<char> serializedData = {1, 2,0,0,0,'e','n', 4,0,0,0,'t','e','x','t'};
00219 GetChannel().SetData(serializedData);
00220
00221 OpcUa::LocalizedText lt;
00222 GetStream() >> lt;
00223
00224 ASSERT_EQ(lt.Locale, "en");
00225 ASSERT_EQ(lt.Text, "");
00226 }
00227
00228 TEST_F(OpcUaBinaryDeserialization, LocalizedText_Text)
00229 {
00230 const std::vector<char> serializedData = {2, 2,0,0,0,'e','n', 4,0,0,0,'t','e','x','t'};
00231 GetChannel().SetData(serializedData);
00232
00233 OpcUa::LocalizedText lt;
00234 GetStream() >> lt;
00235
00236 ASSERT_EQ(lt.Locale, "");
00237 ASSERT_EQ(lt.Text, "en");
00238 }
00239
00240
00241
00242
00243
00244
00245 TEST_F(OpcUaBinaryDeserialization, MessageTypeHello)
00246 {
00247 const std::vector<char> serializedData = {'H', 'E', 'L'};
00248 GetChannel().SetData(serializedData);
00249
00250 OpcUa::Binary::MessageType msgType = OpcUa::Binary::MT_ERROR;
00251 GetStream() >> msgType;
00252
00253 ASSERT_EQ(msgType, OpcUa::Binary::MT_HELLO);
00254 }
00255
00256 TEST_F(OpcUaBinaryDeserialization, MessageTypeAcknowledge)
00257 {
00258 const std::vector<char> serializedData = {'A', 'C', 'K'};
00259 GetChannel().SetData(serializedData);
00260
00261 OpcUa::Binary::MessageType msgType = OpcUa::Binary::MT_ERROR;
00262 GetStream() >> msgType;
00263
00264 ASSERT_EQ(msgType, OpcUa::Binary::MT_ACKNOWLEDGE);
00265 }
00266
00267 TEST_F(OpcUaBinaryDeserialization, MessageTypeError)
00268 {
00269 const std::vector<char> serializedData = {'E', 'R', 'R'};
00270 GetChannel().SetData(serializedData);
00271
00272 OpcUa::Binary::MessageType msgType = OpcUa::Binary::MT_HELLO;
00273 GetStream() >> msgType;
00274
00275 ASSERT_EQ(msgType, OpcUa::Binary::MT_ERROR);
00276 }
00277
00278 TEST_F(OpcUaBinaryDeserialization, MessageTypeSecureOpen)
00279 {
00280 const std::vector<char> serializedData = {'O', 'P', 'N'};
00281 GetChannel().SetData(serializedData);
00282
00283 OpcUa::Binary::MessageType msgType = OpcUa::Binary::MT_ERROR;
00284 GetStream() >> msgType;
00285
00286 ASSERT_EQ(msgType, OpcUa::Binary::MT_SECURE_OPEN);
00287 }
00288
00289 TEST_F(OpcUaBinaryDeserialization, MessageTypeSecureClose)
00290 {
00291 const std::vector<char> serializedData = {'C', 'L', 'O'};
00292 GetChannel().SetData(serializedData);
00293
00294 OpcUa::Binary::MessageType msgType = OpcUa::Binary::MT_ERROR;
00295 GetStream() >> msgType;
00296
00297 ASSERT_EQ(msgType, OpcUa::Binary::MT_SECURE_CLOSE);
00298 }
00299
00300 TEST_F(OpcUaBinaryDeserialization, MessageTypeInvalid)
00301 {
00302 const std::vector<char> serializedData = {'I', 'N', 'V'};
00303 GetChannel().SetData(serializedData);
00304
00305 OpcUa::Binary::MessageType msgType = OpcUa::Binary::MT_ERROR;
00306 ASSERT_THROW(GetStream() >> msgType, std::logic_error);
00307 }
00308
00309
00310
00311
00312
00313 TEST_F(OpcUaBinaryDeserialization, ChunkTypeSingle)
00314 {
00315 const std::vector<char> serializedData = {'F'};
00316 GetChannel().SetData(serializedData);
00317
00318 OpcUa::Binary::ChunkType chunkType = OpcUa::Binary::CHT_FINAL;
00319 GetStream() >> chunkType;
00320
00321 ASSERT_EQ(chunkType, OpcUa::Binary::CHT_SINGLE);
00322 }
00323
00324 TEST_F(OpcUaBinaryDeserialization, ChunkTypeIntermediate)
00325 {
00326 const std::vector<char> serializedData = {'C'};
00327 GetChannel().SetData(serializedData);
00328
00329 OpcUa::Binary::ChunkType chunkType = OpcUa::Binary::CHT_FINAL;
00330 GetStream() >> chunkType;
00331
00332 ASSERT_EQ(chunkType, OpcUa::Binary::CHT_INTERMEDIATE);
00333 }
00334
00335 TEST_F(OpcUaBinaryDeserialization, ChunkTypeFinal)
00336 {
00337 const std::vector<char> serializedData = {'A'};
00338 GetChannel().SetData(serializedData);
00339
00340 OpcUa::Binary::ChunkType chunkType = OpcUa::Binary::CHT_SINGLE;
00341 GetStream() >> chunkType;
00342
00343 ASSERT_EQ(chunkType, OpcUa::Binary::CHT_FINAL);
00344 }
00345
00346 TEST_F(OpcUaBinaryDeserialization, ChunkTypeInvalid)
00347 {
00348 const std::vector<char> serializedData = {'I'};
00349 GetChannel().SetData(serializedData);
00350
00351 OpcUa::Binary::ChunkType chunkType = OpcUa::Binary::CHT_SINGLE;
00352 ASSERT_THROW(GetStream() >> chunkType, std::logic_error);
00353 }
00354
00355
00356
00357
00358
00359
00360 TEST_F(OpcUaBinaryDeserialization, MessageHeader)
00361 {
00362 const std::vector<char> serializedData = {'H', 'E', 'L', 'F', 4, 3, 2, 1};
00363 GetChannel().SetData(serializedData);
00364
00365 OpcUa::Binary::Header hdr;
00366 GetStream() >> hdr;
00367
00368 ASSERT_EQ(hdr.Type, OpcUa::Binary::MT_HELLO);
00369 ASSERT_EQ(hdr.Chunk, OpcUa::Binary::CHT_SINGLE);
00370 ASSERT_EQ(hdr.Size, (uint32_t)0x01020304);
00371 }
00372
00373
00374
00375
00376
00377
00378 TEST_F(OpcUaBinaryDeserialization, Message)
00379 {
00380 const std::vector<char> serializedData = {
00381 1, 0, 0, 0,
00382 2, 0, 0, 0,
00383 3, 0, 0, 0,
00384 4, 0, 0, 0,
00385 5, 0, 0, 0,
00386 3, 0, 0, 0,
00387 'u', 'r', 'l'
00388 };
00389
00390 GetChannel().SetData(serializedData);
00391
00392 OpcUa::Binary::Hello message;
00393 GetStream() >> message;
00394
00395 ASSERT_EQ(message.ProtocolVersion, 1);
00396 ASSERT_EQ(message.ReceiveBufferSize, 2);
00397 ASSERT_EQ(message.SendBufferSize, 3);
00398 ASSERT_EQ(message.MaxMessageSize, 4);
00399 ASSERT_EQ(message.MaxChunkCount, 5);
00400 ASSERT_EQ(message.EndpointUrl, "url");
00401 }
00402
00403 TEST_F(OpcUaBinaryDeserialization, InvalidMessage)
00404 {
00405 const std::vector<char> serializedData = {
00406
00407 4, 3, 2, 1,
00408 4, 3, 2, 1,
00409 4, 3, 2, 1,
00410 4, 3, 2, 1,
00411 3, 0, 0, 0,
00412 'u', 'r', 'l'
00413 };
00414
00415 GetChannel().SetData(serializedData);
00416
00417 OpcUa::Binary::Hello message;
00418 ASSERT_THROW(GetStream() >> message, std::logic_error);
00419 }
00420
00421
00422
00423
00424
00425
00426 TEST_F(OpcUaBinaryDeserialization, Acknowledge)
00427 {
00428 std::vector<char> serializedData = {
00429 1, 0, 0, 0,
00430 2, 0, 0, 0,
00431 3, 0, 0, 0,
00432 4, 0, 0, 0,
00433 5, 0, 0, 0,
00434 };
00435
00436 GetChannel().SetData(serializedData);
00437
00438 OpcUa::Binary::Acknowledge message;
00439 GetStream() >> message;
00440
00441 ASSERT_EQ(message.ProtocolVersion, 1);
00442 ASSERT_EQ(message.ReceiveBufferSize, 2);
00443 ASSERT_EQ(message.SendBufferSize, 3);
00444 ASSERT_EQ(message.MaxMessageSize, 4);
00445 ASSERT_EQ(message.MaxChunkCount, 5);
00446 }
00447
00448 TEST_F(OpcUaBinaryDeserialization, InvalidAcknowledge)
00449 {
00450 std::vector<char> serializedData = {
00451
00452 4, 3, 2, 1,
00453 4, 3, 2, 1,
00454 4, 3, 2, 1,
00455 };
00456
00457 GetChannel().SetData(serializedData);
00458
00459 OpcUa::Binary::Acknowledge message;
00460 ASSERT_THROW(GetStream() >> message, std::logic_error);
00461 }
00462
00463
00464
00465
00466
00467 TEST_F(OpcUaBinaryDeserialization, Error)
00468 {
00469 std::vector<char> serializedData = {
00470 4, 3, 2, 1,
00471 3, 0, 0, 0,
00472 'u', 'r', 'l'
00473 };
00474
00475 GetChannel().SetData(serializedData);
00476
00477 OpcUa::Binary::Error message;
00478 ASSERT_NO_THROW(GetStream() >> message);
00479
00480 uint32_t tmpInt = 0x01020304;
00481 ASSERT_EQ(message.Code, tmpInt);
00482 ASSERT_EQ(message.Reason, "url");
00483 }
00484
00485 TEST_F(OpcUaBinaryDeserialization, InvalidError)
00486 {
00487 std::vector<char> serializedData = {
00488
00489 3, 0, 0, 0,
00490 'u', 'r', 'l'
00491 };
00492
00493 GetChannel().SetData(serializedData);
00494
00495 OpcUa::Binary::Error message;
00496 ASSERT_THROW(GetStream() >> message, std::logic_error);
00497 }
00498
00499
00500
00501
00502
00503 TEST_F(OpcUaBinaryDeserialization, SecureMessageHeader)
00504 {
00505 const std::vector<char> serializedData =
00506 {
00507 'H', 'E', 'L',
00508 'F',
00509 4, 3, 2, 1,
00510 1, 0, 0, 0
00511 };
00512
00513 GetChannel().SetData(serializedData);
00514
00515 OpcUa::Binary::SecureHeader hdr;
00516 GetStream() >> hdr;
00517
00518 ASSERT_EQ(hdr.Type, OpcUa::Binary::MT_HELLO);
00519 ASSERT_EQ(hdr.Chunk, OpcUa::Binary::CHT_SINGLE);
00520 ASSERT_EQ(hdr.Size, (uint32_t)0x01020304);
00521 ASSERT_EQ(hdr.ChannelId, (uint32_t)0x1);
00522 }
00523
00524
00525
00526
00527
00528 TEST_F(OpcUaBinaryDeserialization, Asymmetric)
00529 {
00530 const std::vector<char> serializedData = {
00531 3, 0, 0, 0,
00532 'p', 'o', 'l',
00533 3, 0, 0, 0,
00534 1, 2, 3,
00535 3, 0, 0, 0,
00536 4, 5, 6
00537 };
00538
00539 GetChannel().SetData(serializedData);
00540
00541 OpcUa::Binary::AsymmetricAlgorithmHeader header;
00542 GetStream() >> header;
00543
00544 ASSERT_EQ(header.SecurityPolicyUri, std::string("pol"));
00545 const std::vector<uint8_t> cert = {1, 2, 3};
00546 ASSERT_EQ(header.SenderCertificate, cert);
00547 const std::vector<uint8_t> thumb = {4, 5, 6};
00548 ASSERT_EQ(header.ReceiverCertificateThumbPrint, thumb);
00549 }
00550
00551
00552
00553
00554
00555 TEST_F(OpcUaBinaryDeserialization, Symmetric)
00556 {
00557 const std::vector<char> serializedData = {
00558 7, 6, 5, 4
00559 };
00560
00561 GetChannel().SetData(serializedData);
00562
00563 OpcUa::Binary::SymmetricAlgorithmHeader header;
00564 GetStream() >> header;
00565 ASSERT_EQ(header.TokenId, 0x04050607);
00566 }
00567
00568
00569
00570
00571
00572 TEST_F(OpcUaBinaryDeserialization, SequenceHeader)
00573 {
00574 const std::vector<char> serializedData = {
00575 3, 0, 0, 0,
00576 1, 0, 0, 0,
00577 };
00578
00579 GetChannel().SetData(serializedData);
00580
00581 OpcUa::Binary::SequenceHeader header;
00582 GetStream() >> header;
00583
00584 ASSERT_EQ(header.SequenceNumber, 0x3);
00585 ASSERT_EQ(header.RequestId, 0x1);
00586 }
00587
00588
00589
00590
00591
00592 TEST_F(OpcUaBinaryDeserialization, AdditionalHeader)
00593 {
00594 using namespace OpcUa;
00595
00596 const std::vector<char> expectedData = {
00597 int8_t(EV_STRING | EV_NAMESPACE_URI_FLAG | EV_Server_INDEX_FLAG),
00598 1, 0,
00599 2, 0, 0, 0,
00600 'i', 'd',
00601 3, 0, 0, 0,
00602 'u', 'r', 'i',
00603 1, 0, 0, 0,
00604 1
00605 };
00606
00607 GetChannel().SetData(expectedData);
00608
00609 AdditionalHeader header;
00610 GetStream() >> header;
00611
00612 ASSERT_EQ(header.TypeId.Encoding, uint8_t(EV_STRING | EV_NAMESPACE_URI_FLAG | EV_Server_INDEX_FLAG));
00613 ASSERT_EQ(header.TypeId.StringData.NamespaceIndex, 0x1);
00614 ASSERT_EQ(header.TypeId.StringData.Identifier, "id");
00615 ASSERT_EQ(header.TypeId.NamespaceURI, "uri");
00616 ASSERT_EQ(header.TypeId.ServerIndex, 1);
00617 ASSERT_EQ(header.Encoding, 1);
00618
00619 ASSERT_EQ(expectedData.size(), Binary::RawSize(header));
00620 }
00621
00622
00623
00624
00625
00626 TEST_F(OpcUaBinaryDeserialization, RequestHeader)
00627 {
00628 using namespace OpcUa;
00629
00630 const std::vector<char> expectedData = {
00631 EV_TWO_BYTE, 1,
00632 2, 0, 0, 0, 0, 0, 0, 0,
00633 3, 0, 0, 0,
00634 4, 0, 0, 0,
00635 5, 0, 0, 0,
00636 'a', 'u', 'd', 'i', 't',
00637 5, 0, 0, 0,
00638 0,
00639 6,
00640 8
00641 };
00642
00643 GetChannel().SetData(expectedData);
00644
00645 RequestHeader header;
00646 GetStream() >> header;
00647
00648 ASSERT_EQ(header.SessionAuthenticationToken.Encoding, EV_TWO_BYTE);
00649 ASSERT_EQ(header.SessionAuthenticationToken.TwoByteData.Identifier, 1);
00650 ASSERT_EQ(header.UtcTime, 2);
00651 ASSERT_EQ(header.RequestHandle, 3);
00652 ASSERT_EQ(header.ReturnDiagnostics, 4);
00653 ASSERT_EQ(header.AuditEntryId, "audit");
00654 ASSERT_EQ(header.Timeout, 5);
00655 ASSERT_EQ(header.Additional.TypeId.Encoding, EV_TWO_BYTE);
00656 ASSERT_EQ(header.Additional.TypeId.TwoByteData.Identifier, 6);
00657 ASSERT_EQ(header.Additional.Encoding, 8);
00658
00659 ASSERT_EQ(expectedData.size(), Binary::RawSize(header));
00660 }
00661
00662
00663
00664
00665
00666 TEST_F(OpcUaBinaryDeserialization, DiagnosticInfo_Empty)
00667 {
00668 using namespace OpcUa;
00669
00670 const std::vector<char> expectedData = {
00671 0
00672 };
00673
00674 GetChannel().SetData(expectedData);
00675
00676 DiagnosticInfo info;
00677 GetStream() >> info;
00678 ASSERT_EQ(info.EncodingMask, 0);
00679 }
00680
00681 TEST_F(OpcUaBinaryDeserialization, DiagnosticInfo_SymbolicId)
00682 {
00683 using namespace OpcUa;
00684
00685 const std::vector<char> expectedData = {
00686 DIM_SYMBOLIC_Id,
00687 2, 0, 0, 0,
00688 };
00689
00690 GetChannel().SetData(expectedData);
00691
00692 DiagnosticInfo info;
00693 GetStream() >> info;
00694
00695 ASSERT_EQ(info.EncodingMask, DIM_SYMBOLIC_Id);
00696 ASSERT_EQ(info.SymbolicId, 2);
00697 ASSERT_EQ(expectedData.size(), Binary::RawSize(info));
00698 }
00699
00700 TEST_F(OpcUaBinaryDeserialization, DiagnosticInfo_SymbolicId_Namespace)
00701 {
00702 using namespace OpcUa;
00703
00704 const std::vector<char> expectedData = {
00705 DIM_SYMBOLIC_Id | DIM_NAMESPACE,
00706 2, 0, 0, 0,
00707 3, 0, 0, 0,
00708 };
00709
00710 GetChannel().SetData(expectedData);
00711
00712 DiagnosticInfo info;
00713 GetStream() >> info;
00714
00715 ASSERT_EQ(info.EncodingMask, DIM_SYMBOLIC_Id | DIM_NAMESPACE);
00716 ASSERT_EQ(info.SymbolicId, 2);
00717 ASSERT_EQ(info.NamespaceURI, 3);
00718 }
00719
00720 TEST_F(OpcUaBinaryDeserialization, DiagnosticInfo_SymbolicId_LocalizedText)
00721 {
00722 using namespace OpcUa;
00723
00724 const std::vector<char> expectedData = {
00725 DIM_SYMBOLIC_Id | DIM_LOCALIZED_TEXT,
00726 2, 0, 0, 0,
00727 4, 0, 0, 0,
00728 };
00729
00730 GetChannel().SetData(expectedData);
00731
00732 DiagnosticInfo info;
00733 GetStream() >> info;
00734
00735 ASSERT_EQ(info.EncodingMask, DIM_SYMBOLIC_Id | DIM_LOCALIZED_TEXT);
00736 ASSERT_EQ(info.SymbolicId, 2);
00737 ASSERT_EQ(info.LocalizedText, 4);
00738 }
00739
00740 TEST_F(OpcUaBinaryDeserialization, DiagnosticInfo_LocalizedText_Locale)
00741 {
00742 using namespace OpcUa;
00743
00744 const std::vector<char> expectedData = {
00745 DIM_LOCALIZED_TEXT | DIM_LOCALE,
00746 2, 0, 0, 0,
00747 4, 0, 0, 0,
00748 };
00749
00750 GetChannel().SetData(expectedData);
00751
00752 DiagnosticInfo info;
00753 GetStream() >> info;
00754
00755 ASSERT_EQ(info.EncodingMask, DIM_LOCALIZED_TEXT | DIM_LOCALE);
00756 ASSERT_EQ(info.LocalizedText, 2);
00757 ASSERT_EQ(info.Locale, 4);
00758 }
00759
00760 TEST_F(OpcUaBinaryDeserialization, DiagnosticInfo_AdditionalInfo)
00761 {
00762 using namespace OpcUa;
00763
00764 const std::vector<char> expectedData = {
00765 DIM_ADDITIONAL_INFO,
00766 3,0,0,0,
00767 'a', 'd', 'd'
00768 };
00769
00770 GetChannel().SetData(expectedData);
00771
00772 DiagnosticInfo info;
00773 GetStream() >> info;
00774
00775 ASSERT_EQ(info.EncodingMask, DIM_ADDITIONAL_INFO);
00776 ASSERT_EQ(info.AdditionalInfo, "add");
00777 }
00778
00779 TEST_F(OpcUaBinaryDeserialization, DiagnosticInfo_InnerStatusCode)
00780 {
00781 using namespace OpcUa;
00782
00783 const std::vector<char> expectedData = {
00784 DIM_INNER_STATUS_CODE,
00785 6,0,0,0,
00786 };
00787
00788 GetChannel().SetData(expectedData);
00789
00790 DiagnosticInfo info;
00791 GetStream() >> info;
00792
00793 ASSERT_EQ(info.EncodingMask, DIM_INNER_STATUS_CODE);
00794 ASSERT_EQ(info.InnerStatusCode, static_cast<StatusCode>(6));
00795 }
00796
00797
00798
00799
00800
00801 TEST_F(OpcUaBinaryDeserialization, ResponseHeader)
00802 {
00803 using namespace OpcUa;
00804
00805 const std::vector<char> expectedData = {
00806 TEST_RESPONSE_HEADER_BINARY_DATA
00807 };
00808
00809 GetChannel().SetData(expectedData);
00810
00811 ResponseHeader header;
00812 GetStream() >> header;
00813
00814 ASSERT_RESPONSE_HEADER_EQ(header);
00815 }
00816
00817
00818
00819
00820
00821 TEST_F(OpcUaBinaryDeserialization, OpenSequreChannelRequest)
00822 {
00823 using namespace OpcUa;
00824
00825 const std::vector<char> expectedData = {
00826 1, 0, (char)0xbe, 0x1,
00827
00828
00829 TEST_REQUEST_HEADER_BINARY_DATA,
00830 1, 0, 0, 0,
00831 (uint32_t)SecurityTokenRequestType::Renew, 0, 0, 0,
00832 (uint32_t)MessageSecurityMode::Sign, 0, 0, 0,
00833 1, 0, 0, 0,
00834 1,
00835 5, 0, 0, 0,
00836 };
00837
00838 GetChannel().SetData(expectedData);
00839
00840 OpenSecureChannelRequest request;
00841 GetStream() >> request;
00842
00843 ASSERT_EQ(request.Parameters.ClientProtocolVersion, 1);
00844 ASSERT_EQ(request.Parameters.RequestType, SecurityTokenRequestType::Renew);
00845 ASSERT_EQ(request.Parameters.SecurityMode, MessageSecurityMode::Sign);
00846 ASSERT_EQ(request.Parameters.ClientNonce, std::vector<uint8_t>(1, 1));
00847 ASSERT_EQ(request.Parameters.RequestLifeTime, 5);
00848
00849 ASSERT_REQUEST_HEADER_EQ(request.Header);
00850 }
00851
00852
00853
00854
00855
00856 TEST_F(OpcUaBinaryDeserialization, SecurityToken)
00857 {
00858 using namespace OpcUa;
00859
00860 const std::vector<char> expectedData = {
00861 1, 0, 0, 0,
00862 2, 0, 0, 0,
00863 3, 0, 0, 0, 0, 0, 0, 0,
00864 4, 0, 0, 0,
00865 };
00866
00867 GetChannel().SetData(expectedData);
00868
00869 SecurityToken token;
00870 GetStream() >> token;
00871
00872 ASSERT_EQ(token.SecureChannelId, 1);
00873 ASSERT_EQ(token.TokenId, 2);
00874 ASSERT_EQ(token.CreatedAt, 3);
00875 ASSERT_EQ(token.RevisedLifetime, 4);
00876 }
00877
00878
00879
00880
00881
00882 TEST_F(OpcUaBinaryDeserialization, OpenSecureChannelResponse)
00883 {
00884 using namespace OpcUa;
00885
00886 const std::vector<char> expectedData = {
00887 1, 0, (char)0xC1, 0x1,
00888
00889
00890 TEST_RESPONSE_HEADER_BINARY_DATA,
00891
00892 1, 0, 0, 0,
00893 2, 0, 0, 0,
00894 3, 0, 0, 0,
00895 4, 0, 0, 0, 0, 0, 0, 0,
00896 5, 0, 0, 0,
00897 1, 0, 0, 0,
00898 6
00899 };
00900
00901 GetChannel().SetData(expectedData);
00902
00903 OpenSecureChannelResponse response;
00904 GetStream() >> response;
00905
00906 ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00907 ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00908 ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::OPEN_SECURE_CHANNEL_RESPONSE);
00909
00910 ASSERT_RESPONSE_HEADER_EQ(response.Header);
00911
00912 ASSERT_EQ(response.ServerProtocolVersion, 1);
00913 ASSERT_EQ(response.ChannelSecurityToken.SecureChannelId, 2);
00914 ASSERT_EQ(response.ChannelSecurityToken.TokenId, 3);
00915 ASSERT_EQ(response.ChannelSecurityToken.CreatedAt, 4);
00916 ASSERT_EQ(response.ChannelSecurityToken.RevisedLifetime, 5);
00917 ASSERT_EQ(response.ServerNonce, std::vector<uint8_t>(1, 6));
00918
00919 }
00920
00921
00922
00923
00924
00925 TEST_F(OpcUaBinaryDeserialization, CloseSequreChannelRequest)
00926 {
00927 using namespace OpcUa;
00928
00929 const std::vector<char> expectedData = {
00930 1, 0, (char)0xc4, 0x1,
00931
00932
00933 TEST_REQUEST_HEADER_BINARY_DATA,
00934 };
00935
00936 GetChannel().SetData(expectedData);
00937
00938 CloseSecureChannelRequest request;
00939 GetStream() >> request;
00940
00941 ASSERT_REQUEST_HEADER_EQ(request.Header);
00942 }
00943
00944
00945
00946
00947
00948 TEST_F(OpcUaBinaryDeserialization, SignatureData)
00949 {
00950
00951 using namespace OpcUa;
00952
00953 const std::vector<char> expectedData = {
00954 3, 0, 0, 0, 'a','e','s',
00955 4, 0, 0, 0, 1,2,3,4
00956 };
00957
00958 GetChannel().SetData(expectedData);
00959
00960 SignatureData s;
00961 GetStream() >> s;
00962
00963 ASSERT_EQ(s.Signature, ByteString(std::vector<uint8_t>{1,2,3,4}));
00964 ASSERT_EQ(s.Algorithm, "aes");
00965 }
00966
00967
00968
00969
00970
00971 TEST_F(OpcUaBinaryDeserialization, ExtensionObjectHeader)
00972 {
00973 using namespace OpcUa;
00974
00975 const std::vector<char> expectedData = {
00976 1, 0, (char)0x41, 0x1,
00977 HAS_BINARY_BODY
00978 };
00979
00980 GetChannel().SetData(expectedData);
00981 ExtensionObjectHeader header(OpcUa::USER_IdENTIFY_TOKEN_ANONYMOUS, HAS_BINARY_BODY);
00982 GetStream() >> header;
00983
00984 ASSERT_EQ(header.TypeId.Encoding, EV_FOUR_BYTE);
00985 ASSERT_EQ(header.TypeId.FourByteData.NamespaceIndex, 0);
00986 ASSERT_EQ(header.TypeId.FourByteData.Identifier, OpcUa::USER_IdENTIFY_TOKEN_ANONYMOUS);
00987 ASSERT_EQ(header.Encoding, HAS_BINARY_BODY);
00988 }
00989
00990
00991
00992
00993
00994 TEST_F(OpcUaBinaryDeserialization, QualifiedName)
00995 {
00996 using namespace OpcUa;
00997
00998 const std::vector<char> expectedData = {
00999 1, 0,
01000 4, 0, 0, 0, 'n','a','m','e'
01001 };
01002
01003 GetChannel().SetData(expectedData);
01004
01005 QualifiedName name;
01006 GetStream() >> name;
01007
01008 ASSERT_EQ(name.NamespaceIndex, 1);
01009 ASSERT_EQ(name.Name, "name");
01010 }
01011
01012
01013
01014
01015
01016 TEST_F(OpcUaBinaryDeserialization, IntegerId)
01017 {
01018 using namespace OpcUa;
01019 using namespace OpcUa::Binary;
01020
01021 const std::vector<char> expectedData = {
01022 5, 0, 0, 0
01023 };
01024
01025 GetChannel().SetData(expectedData);
01026
01027 IntegerId id;
01028 GetStream() >> id;
01029
01030 ASSERT_EQ(id, 5);
01031 }
01032