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