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/data_value.h>
00017 #include <opc/ua/protocol/types.h>
00018 #include <opc/ua/protocol/variant.h>
00019
00020 #include <algorithm>
00021 #include <stdexcept>
00022
00023
00024
00025
00026
00027 TEST_F(OpcUaBinarySerialization, Variant_NUL)
00028 {
00029
00030 using namespace OpcUa;
00031 using namespace OpcUa::Binary;
00032
00033 Variant var;
00034
00035 GetStream() << var << flush;
00036
00037 const std::vector<char> expectedData = {
00038 0
00039 };
00040
00041 ASSERT_EQ(expectedData.size(), RawSize(var));
00042 ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00043 }
00044
00045 TEST_F(OpcUaBinarySerialization, Variant_BOOLEAN)
00046 {
00047
00048 using namespace OpcUa;
00049 using namespace OpcUa::Binary;
00050
00051 Variant var = true;
00052
00053 GetStream() << var << flush;
00054
00055 char encodingMask = static_cast<uint8_t>(VariantType::BOOLEAN);
00056 const std::vector<char> expectedData = {
00057 encodingMask,
00058 1
00059 };
00060
00061 ASSERT_EQ(expectedData.size(), RawSize(var));
00062 ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00063 }
00064
00065 TEST_F(OpcUaBinarySerialization, Variant_BOOLEAN_Array)
00066 {
00067
00068 using namespace OpcUa;
00069 using namespace OpcUa::Binary;
00070
00071 Variant var = std::vector<bool>{true, true};
00072
00073 GetStream() << var << flush;
00074
00075 char encodingMask = static_cast<uint8_t>(VariantType::BOOLEAN) | HAS_ARRAY_MASK;
00076 const std::vector<char> expectedData = {
00077 encodingMask,
00078 2,0,0,0,
00079 1,
00080 1
00081 };
00082
00083 ASSERT_EQ(expectedData.size(), RawSize(var));
00084 ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00085 }
00086
00087
00088 TEST_F(OpcUaBinarySerialization, Variant_BOOLEAN_DIMENSIONS)
00089 {
00090
00091 using namespace OpcUa;
00092 using namespace OpcUa::Binary;
00093
00094 Variant var = true;
00095 var.Dimensions.push_back(1);
00096
00097 GetStream() << var << flush;
00098
00099 char encodingMask = static_cast<uint8_t>(VariantType::BOOLEAN) | HAS_DIMENSIONS_MASK;
00100 const std::vector<char> expectedData = {
00101 encodingMask,
00102 1,
00103 1,0,0,0,
00104 1,0,0,0
00105 };
00106
00107 ASSERT_EQ(expectedData.size(), RawSize(var));
00108 ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00109 }
00110
00111
00112
00113
00114
00115
00116 TEST_F(OpcUaBinaryDeserialization, Variant_NUL)
00117 {
00118 using namespace OpcUa;
00119 using namespace OpcUa::Binary;
00120
00121 const std::vector<char> expectedData = {
00122 0
00123 };
00124
00125 GetChannel().SetData(expectedData);
00126
00127 Variant var;
00128 GetStream() >> var;
00129
00130 ASSERT_EQ(var.Type(), VariantType::NUL);
00131 ASSERT_TRUE(var.IsNul());
00132 ASSERT_FALSE(var.IsArray());
00133 }
00134
00135 TEST_F(OpcUaBinaryDeserialization, Variant_BOOLEAN)
00136 {
00137 using namespace OpcUa;
00138 using namespace OpcUa::Binary;
00139
00140 char encodingMask = static_cast<uint8_t>(VariantType::BOOLEAN);
00141
00142 const std::vector<char> expectedData = {
00143 encodingMask,
00144 1
00145 };
00146
00147 GetChannel().SetData(expectedData);
00148
00149 Variant var;
00150 GetStream() >> var;
00151
00152 ASSERT_EQ(var.Type(), VariantType::BOOLEAN);
00153 ASSERT_TRUE(var.As<bool>());
00154 ASSERT_FALSE(var.IsNul());
00155 ASSERT_FALSE(var.IsArray());
00156 }
00157
00158 TEST_F(OpcUaBinaryDeserialization, Variant_BOOLEAN_Array)
00159 {
00160 using namespace OpcUa;
00161 using namespace OpcUa::Binary;
00162
00163 char encodingMask = static_cast<uint8_t>(VariantType::BOOLEAN) | HAS_ARRAY_MASK;
00164
00165 const std::vector<char> expectedData = {
00166 encodingMask,
00167 2,0,0,0,
00168 1,
00169 1
00170 };
00171
00172 GetChannel().SetData(expectedData);
00173
00174 Variant var;
00175 GetStream() >> var;
00176
00177 ASSERT_EQ(var.Type(), VariantType::BOOLEAN);
00178 std::vector<bool> vals;
00179 ASSERT_NO_THROW(vals = var.As<std::vector<bool>>());
00180 ASSERT_EQ(vals.size(), 2);
00181 ASSERT_EQ(vals[0], true);
00182 ASSERT_EQ(vals[1], true);
00183 ASSERT_FALSE(var.IsNul());
00184 ASSERT_TRUE(var.IsArray());
00185 }
00186
00187
00188 TEST_F(OpcUaBinaryDeserialization, Variant_BOOLEAN_DIMENSIONS)
00189 {
00190 using namespace OpcUa;
00191 using namespace OpcUa::Binary;
00192
00193 char encodingMask = static_cast<uint8_t>(VariantType::BOOLEAN) | HAS_DIMENSIONS_MASK;
00194
00195 const std::vector<char> expectedData = {
00196 encodingMask,
00197 1,
00198 1,0,0,0,
00199 1,0,0,0,
00200 };
00201
00202 GetChannel().SetData(expectedData);
00203
00204 Variant var;
00205 GetStream() >> var;
00206
00207 ASSERT_EQ(var.Type(), VariantType::BOOLEAN);
00208 ASSERT_TRUE(var.As<bool>());
00209 ASSERT_FALSE(var.IsNul());
00210 ASSERT_FALSE(var.IsArray());
00211 }
00213 TEST_F(OpcUaBinaryDeserialization, Variant_BYTE)
00214 {
00215 using namespace OpcUa;
00216 using namespace OpcUa::Binary;
00217
00218 char encodingMask = static_cast<char>(VariantType::BYTE);
00219
00220 const std::vector<char> expectedData = {
00221 encodingMask,
00222 (char)200
00223 };
00224
00225 GetChannel().SetData(expectedData);
00226
00227 Variant var;
00228 GetStream() >> var;
00229
00230 ASSERT_EQ(var.Type(), VariantType::BYTE);
00231 ASSERT_EQ(var.As<uint8_t>(), 200);
00232 ASSERT_FALSE(var.IsNul());
00233 ASSERT_FALSE(var.IsArray());
00234 }
00235
00236 TEST_F(OpcUaBinaryDeserialization, Variant_BYTE_Array)
00237 {
00238 using namespace OpcUa;
00239 using namespace OpcUa::Binary;
00240
00241 char encodingMask = static_cast<uint8_t>(VariantType::BYTE) | HAS_ARRAY_MASK;
00242
00243 const std::vector<char> expectedData = {
00244 encodingMask,
00245 2,0,0,0,
00246 (char)200,
00247 (char)201
00248 };
00249
00250 GetChannel().SetData(expectedData);
00251
00252 Variant var;
00253 GetStream() >> var;
00254
00255 ASSERT_EQ(var.Type(), VariantType::BYTE);
00256 std::vector<uint8_t> vals;
00257 ASSERT_NO_THROW(vals = var.As<std::vector<uint8_t>>());
00258 ASSERT_EQ(vals.size(), 2);
00259 ASSERT_EQ(vals[0], 200);
00260 ASSERT_EQ(vals[1], 201);
00261 ASSERT_FALSE(var.IsNul());
00262 ASSERT_TRUE(var.IsArray());
00263 ASSERT_TRUE(var.Dimensions.empty());
00264 }
00265
00266
00267 TEST_F(OpcUaBinaryDeserialization, Variant_BYTE_DIMENSIONS)
00268 {
00269 using namespace OpcUa;
00270 using namespace OpcUa::Binary;
00271
00272 char encodingMask = static_cast<uint8_t>(VariantType::BYTE) | HAS_DIMENSIONS_MASK;
00273
00274 const std::vector<char> expectedData = {
00275 encodingMask,
00276 (char)200,
00277 2,0,0,0,
00278 2,0,0,0,
00279 3,0,0,0,
00280 };
00281
00282 GetChannel().SetData(expectedData);
00283
00284 Variant var;
00285 GetStream() >> var;
00286
00287 ASSERT_EQ(var.Type(), VariantType::BYTE);
00288 ASSERT_EQ(var.As<uint8_t>(), 200);
00289 ASSERT_FALSE(var.IsNul());
00290 ASSERT_FALSE(var.IsArray());
00291 ASSERT_EQ(var.Dimensions.size(), 2);
00292 ASSERT_EQ(var.Dimensions[0], 2);
00293 ASSERT_EQ(var.Dimensions[1], 3);
00294 }
00296 TEST_F(OpcUaBinaryDeserialization, Variant_SBYTE)
00297 {
00298 using namespace OpcUa;
00299 using namespace OpcUa::Binary;
00300
00301 char encodingMask = static_cast<char>(VariantType::SBYTE);
00302
00303 const std::vector<char> expectedData = {
00304 encodingMask,
00305 (char)-5
00306 };
00307
00308 GetChannel().SetData(expectedData);
00309
00310 Variant var;
00311 GetStream() >> var;
00312
00313 ASSERT_EQ(var.Type(), VariantType::SBYTE);
00314 ASSERT_EQ(var.As<int8_t>(), -5);
00315 ASSERT_FALSE(var.IsNul());
00316 ASSERT_FALSE(var.IsArray());
00317 }
00318
00319 TEST_F(OpcUaBinaryDeserialization, Variant_SBYTE_Array)
00320 {
00321 using namespace OpcUa;
00322 using namespace OpcUa::Binary;
00323
00324 char encodingMask = static_cast<uint8_t>(VariantType::SBYTE) | HAS_ARRAY_MASK;
00325
00326 const std::vector<char> expectedData = {
00327 encodingMask,
00328 2,0,0,0,
00329 -2,
00330 -3
00331 };
00332
00333 GetChannel().SetData(expectedData);
00334
00335 Variant var;
00336 GetStream() >> var;
00337
00338 ASSERT_EQ(var.Type(), VariantType::SBYTE);
00339 std::vector<int8_t> vals;
00340 ASSERT_NO_THROW(vals = var.As<std::vector<int8_t>>());
00341 ASSERT_EQ(vals.size(), 2);
00342 ASSERT_EQ(vals[0], -2);
00343 ASSERT_EQ(vals[1], -3);
00344 ASSERT_FALSE(var.IsNul());
00345 ASSERT_TRUE(var.IsArray());
00346 ASSERT_TRUE(var.Dimensions.empty());
00347 }
00348
00349
00350 TEST_F(OpcUaBinaryDeserialization, Variant_SBYTE_DIMENSIONS)
00351 {
00352 using namespace OpcUa;
00353 using namespace OpcUa::Binary;
00354
00355 char encodingMask = static_cast<uint8_t>(VariantType::SBYTE) | HAS_DIMENSIONS_MASK;
00356
00357 const std::vector<char> expectedData = {
00358 encodingMask,
00359 -5,
00360 1,0,0,0,
00361 1,0,0,0,
00362 };
00363
00364 GetChannel().SetData(expectedData);
00365
00366 Variant var;
00367 GetStream() >> var;
00368
00369 ASSERT_EQ(var.Type(), VariantType::SBYTE);
00370 ASSERT_EQ(var.As<int8_t>(), -5);
00371 ASSERT_FALSE(var.IsNul());
00372 ASSERT_FALSE(var.IsArray());
00373 }
00374
00376 TEST_F(OpcUaBinaryDeserialization, Variant_INT16)
00377 {
00378 using namespace OpcUa;
00379 using namespace OpcUa::Binary;
00380
00381 char encodingMask = static_cast<char>(VariantType::INT16);
00382
00383 const std::vector<char> expectedData = {
00384 encodingMask,
00385 0x00, 0x20
00386 };
00387
00388 GetChannel().SetData(expectedData);
00389
00390 Variant var;
00391 GetStream() >> var;
00392
00393 ASSERT_EQ(var.Type(), VariantType::INT16);
00394 ASSERT_EQ(var.As<int16_t>(), 8192);
00395 ASSERT_FALSE(var.IsNul());
00396 ASSERT_FALSE(var.IsArray());
00397 ASSERT_TRUE(var.Dimensions.empty());
00398 }
00399
00400 TEST_F(OpcUaBinaryDeserialization, Variant_INT16_Array)
00401 {
00402 using namespace OpcUa;
00403 using namespace OpcUa::Binary;
00404
00405 char encodingMask = static_cast<uint8_t>(VariantType::INT16) | HAS_ARRAY_MASK;
00406
00407 const std::vector<char> expectedData = {
00408 encodingMask,
00409 2,0,0,0,
00410 0x00, 0x20,
00411 0x00, 0x20
00412 };
00413
00414 GetChannel().SetData(expectedData);
00415
00416 Variant var;
00417 GetStream() >> var;
00418
00419 ASSERT_EQ(var.Type(), VariantType::INT16);
00420 std::vector<int16_t> vals;
00421 ASSERT_NO_THROW(vals = var.As<std::vector<int16_t>>());
00422 ASSERT_EQ(vals.size(), 2);
00423 ASSERT_EQ(vals[0], 8192);
00424 ASSERT_EQ(vals[1], 8192);
00425 ASSERT_FALSE(var.IsNul());
00426 ASSERT_TRUE(var.IsArray());
00427 ASSERT_TRUE(var.Dimensions.empty());
00428 }
00429
00430
00431 TEST_F(OpcUaBinaryDeserialization, Variant_INT16_DIMENSIONS)
00432 {
00433 using namespace OpcUa;
00434 using namespace OpcUa::Binary;
00435
00436 char encodingMask = static_cast<uint8_t>(VariantType::INT16) | HAS_DIMENSIONS_MASK;
00437
00438 const std::vector<char> expectedData = {
00439 encodingMask,
00440 0x00, 0x20,
00441 1,0,0,0,
00442 1,0,0,0,
00443 };
00444
00445 GetChannel().SetData(expectedData);
00446
00447 Variant var;
00448 GetStream() >> var;
00449
00450 ASSERT_EQ(var.Type(), VariantType::INT16);
00451 ASSERT_EQ(var.As<int16_t>(), 8192);
00452 ASSERT_FALSE(var.IsNul());
00453 ASSERT_FALSE(var.IsArray());
00454 ASSERT_EQ(var.Dimensions.size(), 1);
00455 ASSERT_EQ(var.Dimensions[0], 1);
00456 }
00457
00459 TEST_F(OpcUaBinaryDeserialization, Variant_UINT16)
00460 {
00461 using namespace OpcUa;
00462 using namespace OpcUa::Binary;
00463
00464 char encodingMask = static_cast<char>(VariantType::UINT16);
00465
00466 const std::vector<char> expectedData = {
00467 encodingMask,
00468 0x00, 0x20
00469 };
00470
00471 GetChannel().SetData(expectedData);
00472
00473 Variant var;
00474 GetStream() >> var;
00475
00476 ASSERT_EQ(var.Type(), VariantType::UINT16);
00477 ASSERT_EQ(var.As<uint16_t>(), 8192);
00478 ASSERT_FALSE(var.IsNul());
00479 ASSERT_FALSE(var.IsArray());
00480 ASSERT_TRUE(var.Dimensions.empty());
00481 }
00482
00483 TEST_F(OpcUaBinaryDeserialization, Variant_UINT16_Array)
00484 {
00485 using namespace OpcUa;
00486 using namespace OpcUa::Binary;
00487
00488 char encodingMask = static_cast<uint8_t>(VariantType::UINT16) | HAS_ARRAY_MASK;
00489
00490 const std::vector<char> expectedData = {
00491 encodingMask,
00492 2,0,0,0,
00493 0x00, 0x20,
00494 0x00, 0x20
00495 };
00496
00497 GetChannel().SetData(expectedData);
00498
00499 Variant var;
00500 GetStream() >> var;
00501
00502 ASSERT_EQ(var.Type(), VariantType::UINT16);
00503 std::vector<uint16_t> vals;
00504 ASSERT_NO_THROW(vals = var.As<std::vector<uint16_t>>());
00505 ASSERT_EQ(vals.size(), 2);
00506 ASSERT_EQ(vals[0], 8192);
00507 ASSERT_EQ(vals[1], 8192);
00508 ASSERT_FALSE(var.IsNul());
00509 ASSERT_TRUE(var.IsArray());
00510 ASSERT_TRUE(var.Dimensions.empty());
00511 }
00512
00513
00514 TEST_F(OpcUaBinaryDeserialization, Variant_UINT16_DIMENSIONS)
00515 {
00516 using namespace OpcUa;
00517 using namespace OpcUa::Binary;
00518
00519 char encodingMask = static_cast<uint8_t>(VariantType::UINT16) | HAS_DIMENSIONS_MASK;
00520
00521 const std::vector<char> expectedData = {
00522 encodingMask,
00523 0x00, 0x20,
00524 1,0,0,0,
00525 1,0,0,0,
00526 };
00527
00528 GetChannel().SetData(expectedData);
00529
00530 Variant var;
00531 GetStream() >> var;
00532
00533 ASSERT_EQ(var.Type(), VariantType::UINT16);
00534 ASSERT_EQ(var.As<uint16_t>(), 8192);
00535 ASSERT_FALSE(var.IsNul());
00536 ASSERT_FALSE(var.IsArray());
00537 ASSERT_EQ(var.Dimensions.size(), 1);
00538 ASSERT_EQ(var.Dimensions[0], 1);
00539 }
00540
00542 TEST_F(OpcUaBinaryDeserialization, Variant_INT32)
00543 {
00544 using namespace OpcUa;
00545 using namespace OpcUa::Binary;
00546
00547 char encodingMask = static_cast<char>(VariantType::INT32);
00548
00549 const std::vector<char> expectedData = {
00550 encodingMask,
00551 0x00,0x20,0,0
00552 };
00553
00554 GetChannel().SetData(expectedData);
00555
00556 Variant var;
00557 GetStream() >> var;
00558
00559 ASSERT_EQ(var.Type(), VariantType::INT32);
00560 ASSERT_EQ(var.As<int32_t>(), 8192);
00561 ASSERT_FALSE(var.IsNul());
00562 ASSERT_FALSE(var.IsArray());
00563 ASSERT_TRUE(var.Dimensions.empty());
00564 }
00565
00566 TEST_F(OpcUaBinaryDeserialization, Variant_INT32_Array)
00567 {
00568 using namespace OpcUa;
00569 using namespace OpcUa::Binary;
00570
00571 char encodingMask = static_cast<uint8_t>(VariantType::INT32) | HAS_ARRAY_MASK;
00572
00573 const std::vector<char> expectedData = {
00574 encodingMask,
00575 2,0,0,0,
00576 0x00, 0x20, 0, 0,
00577 0x00, 0x20, 0, 0
00578 };
00579
00580 GetChannel().SetData(expectedData);
00581
00582 Variant var;
00583 GetStream() >> var;
00584
00585 ASSERT_EQ(var.Type(), VariantType::INT32);
00586 std::vector<int32_t> vals;
00587 ASSERT_NO_THROW(vals = var.As<std::vector<int32_t>>());
00588 ASSERT_EQ(vals.size(), 2);
00589 ASSERT_EQ(vals[0], 8192);
00590 ASSERT_EQ(vals[1], 8192);
00591 ASSERT_FALSE(var.IsNul());
00592 ASSERT_TRUE(var.IsArray());
00593 ASSERT_TRUE(var.Dimensions.empty());
00594 }
00595
00596
00597 TEST_F(OpcUaBinaryDeserialization, Variant_INT32_DIMENSIONS)
00598 {
00599 using namespace OpcUa;
00600 using namespace OpcUa::Binary;
00601
00602 char encodingMask = static_cast<uint8_t>(VariantType::INT32) | HAS_DIMENSIONS_MASK;
00603
00604 const std::vector<char> expectedData = {
00605 encodingMask,
00606 0x00, 0x20, 0, 0,
00607 1,0,0,0,
00608 1,0,0,0,
00609 };
00610
00611 GetChannel().SetData(expectedData);
00612
00613 Variant var;
00614 GetStream() >> var;
00615
00616 ASSERT_EQ(var.Type(), VariantType::INT32);
00617 ASSERT_EQ(var.As<int32_t>(), 8192);
00618 ASSERT_FALSE(var.IsNul());
00619 ASSERT_FALSE(var.IsArray());
00620 ASSERT_EQ(var.Dimensions.size(), 1);
00621 ASSERT_EQ(var.Dimensions[0], 1);
00622 }
00623
00625 TEST_F(OpcUaBinaryDeserialization, Variant_UINT32)
00626 {
00627 using namespace OpcUa;
00628 using namespace OpcUa::Binary;
00629
00630 char encodingMask = static_cast<char>(VariantType::UINT32);
00631
00632 const std::vector<char> expectedData = {
00633 encodingMask,
00634 0x00, 0x20,0,0
00635 };
00636
00637 GetChannel().SetData(expectedData);
00638
00639 Variant var;
00640 GetStream() >> var;
00641
00642 ASSERT_EQ(var.Type(), VariantType::UINT32);
00643 ASSERT_EQ(var.As<uint32_t>(), 8192);
00644 ASSERT_FALSE(var.IsNul());
00645 ASSERT_FALSE(var.IsArray());
00646 ASSERT_TRUE(var.Dimensions.empty());
00647 }
00648
00649 TEST_F(OpcUaBinaryDeserialization, Variant_UINT32_Array)
00650 {
00651 using namespace OpcUa;
00652 using namespace OpcUa::Binary;
00653
00654 char encodingMask = static_cast<uint8_t>(VariantType::UINT32) | HAS_ARRAY_MASK;
00655
00656 const std::vector<char> expectedData = {
00657 encodingMask,
00658 2,0,0,0,
00659 0x00, 0x20,0,0,
00660 0x00, 0x20,0,0
00661 };
00662
00663 GetChannel().SetData(expectedData);
00664
00665 Variant var;
00666 GetStream() >> var;
00667
00668 ASSERT_EQ(var.Type(), VariantType::UINT32);
00669 std::vector<uint32_t> vals;
00670 ASSERT_NO_THROW(vals = var.As<std::vector<uint32_t>>());
00671 ASSERT_EQ(vals.size(), 2);
00672 ASSERT_EQ(vals[0], 8192);
00673 ASSERT_EQ(vals[1], 8192);
00674 ASSERT_FALSE(var.IsNul());
00675 ASSERT_TRUE(var.IsArray());
00676 ASSERT_TRUE(var.Dimensions.empty());
00677 }
00678
00679
00680 TEST_F(OpcUaBinaryDeserialization, Variant_UINT32_DIMENSIONS)
00681 {
00682 using namespace OpcUa;
00683 using namespace OpcUa::Binary;
00684
00685 char encodingMask = static_cast<uint8_t>(VariantType::UINT32) | HAS_DIMENSIONS_MASK;
00686
00687 const std::vector<char> expectedData = {
00688 encodingMask,
00689 0x00, 0x20,0,0,
00690 1,0,0,0,
00691 1,0,0,0,
00692 };
00693
00694 GetChannel().SetData(expectedData);
00695
00696 Variant var;
00697 GetStream() >> var;
00698
00699 ASSERT_EQ(var.Type(), VariantType::UINT32);
00700 ASSERT_EQ(var.As<uint32_t>(), 8192);
00701 ASSERT_FALSE(var.IsNul());
00702 ASSERT_FALSE(var.IsArray());
00703 ASSERT_EQ(var.Dimensions.size(), 1);
00704 ASSERT_EQ(var.Dimensions[0], 1);
00705 }
00706
00708 TEST_F(OpcUaBinaryDeserialization, Variant_INT64)
00709 {
00710 using namespace OpcUa;
00711 using namespace OpcUa::Binary;
00712
00713 char encodingMask = static_cast<char>(VariantType::INT64);
00714
00715 const std::vector<char> expectedData = {
00716 encodingMask,
00717 0x00,0x20,0,0, 0,0,0,0
00718 };
00719
00720 GetChannel().SetData(expectedData);
00721
00722 Variant var;
00723 GetStream() >> var;
00724
00725 ASSERT_EQ(var.Type(), VariantType::INT64);
00726 ASSERT_EQ(var.As<int64_t>(), 8192);
00727 ASSERT_FALSE(var.IsNul());
00728 ASSERT_FALSE(var.IsArray());
00729 ASSERT_TRUE(var.Dimensions.empty());
00730 }
00731
00732 TEST_F(OpcUaBinaryDeserialization, Variant_INT64_Array)
00733 {
00734 using namespace OpcUa;
00735 using namespace OpcUa::Binary;
00736
00737 char encodingMask = static_cast<uint8_t>(VariantType::INT64) | HAS_ARRAY_MASK;
00738
00739 const std::vector<char> expectedData = {
00740 encodingMask,
00741 2,0,0,0,
00742 0x00,0x20,0,0, 0,0,0,0,
00743 0x00,0x20,0,0, 0,0,0,0
00744 };
00745
00746 GetChannel().SetData(expectedData);
00747
00748 Variant var;
00749 GetStream() >> var;
00750
00751 ASSERT_EQ(var.Type(), VariantType::INT64);
00752 std::vector<int64_t> vals;
00753 ASSERT_NO_THROW(vals = var.As<std::vector<int64_t>>());
00754 ASSERT_EQ(vals.size(), 2);
00755 ASSERT_EQ(vals[0], 8192);
00756 ASSERT_EQ(vals[1], 8192);
00757 ASSERT_FALSE(var.IsNul());
00758 ASSERT_TRUE(var.IsArray());
00759 ASSERT_TRUE(var.Dimensions.empty());
00760 }
00761
00762
00763 TEST_F(OpcUaBinaryDeserialization, Variant_INT64_DIMENSIONS)
00764 {
00765 using namespace OpcUa;
00766 using namespace OpcUa::Binary;
00767
00768 char encodingMask = static_cast<uint8_t>(VariantType::INT64) | HAS_DIMENSIONS_MASK;
00769
00770 const std::vector<char> expectedData = {
00771 encodingMask,
00772 0x00,0x20,0,0, 0,0,0,0,
00773 1,0,0,0,
00774 1,0,0,0,
00775 };
00776
00777 GetChannel().SetData(expectedData);
00778
00779 Variant var;
00780 GetStream() >> var;
00781
00782 ASSERT_EQ(var.Type(), VariantType::INT64);
00783 ASSERT_EQ(var.As<int64_t>(), 8192);
00784 ASSERT_FALSE(var.IsNul());
00785 ASSERT_FALSE(var.IsArray());
00786 ASSERT_EQ(var.Dimensions.size(), 1);
00787 ASSERT_EQ(var.Dimensions[0], 1);
00788 }
00789
00791 TEST_F(OpcUaBinaryDeserialization, Variant_UINT64)
00792 {
00793 using namespace OpcUa;
00794 using namespace OpcUa::Binary;
00795
00796 char encodingMask = static_cast<char>(VariantType::UINT64);
00797
00798 const std::vector<char> expectedData = {
00799 encodingMask,
00800 0x00,0x20,0,0, 0,0,0,0
00801 };
00802
00803 GetChannel().SetData(expectedData);
00804
00805 Variant var;
00806 GetStream() >> var;
00807
00808 ASSERT_EQ(var.Type(), VariantType::UINT64);
00809 ASSERT_EQ(var.As<uint64_t>(), 8192);
00810 ASSERT_FALSE(var.IsNul());
00811 ASSERT_FALSE(var.IsArray());
00812 ASSERT_TRUE(var.Dimensions.empty());
00813 }
00814
00815 TEST_F(OpcUaBinaryDeserialization, Variant_UINT64_Array)
00816 {
00817 using namespace OpcUa;
00818 using namespace OpcUa::Binary;
00819
00820 char encodingMask = static_cast<uint8_t>(VariantType::UINT64) | HAS_ARRAY_MASK;
00821
00822 const std::vector<char> expectedData = {
00823 encodingMask,
00824 2,0,0,0,
00825 0x00,0x20,0,0, 0,0,0,0,
00826 0x00,0x20,0,0, 0,0,0,0
00827 };
00828
00829 GetChannel().SetData(expectedData);
00830
00831 Variant var;
00832 GetStream() >> var;
00833
00834 ASSERT_EQ(var.Type(), VariantType::UINT64);
00835 std::vector<uint64_t> vals;
00836 ASSERT_NO_THROW(vals = var.As<std::vector<uint64_t>>());
00837 ASSERT_EQ(vals.size(), 2);
00838 ASSERT_EQ(vals[0], 8192);
00839 ASSERT_EQ(vals[1], 8192);
00840 ASSERT_FALSE(var.IsNul());
00841 ASSERT_TRUE(var.IsArray());
00842 ASSERT_TRUE(var.Dimensions.empty());
00843 }
00844
00845
00846 TEST_F(OpcUaBinaryDeserialization, Variant_UINT64_DIMENSIONS)
00847 {
00848 using namespace OpcUa;
00849 using namespace OpcUa::Binary;
00850
00851 char encodingMask = static_cast<uint8_t>(VariantType::UINT64) | HAS_DIMENSIONS_MASK;
00852
00853 const std::vector<char> expectedData = {
00854 encodingMask,
00855 0x00,0x20,0,0, 0,0,0,0,
00856 1,0,0,0,
00857 1,0,0,0,
00858 };
00859
00860 GetChannel().SetData(expectedData);
00861
00862 Variant var;
00863 GetStream() >> var;
00864
00865 ASSERT_EQ(var.Type(), VariantType::UINT64);
00866 ASSERT_EQ(var.As<uint64_t>(), 8192);
00867 ASSERT_FALSE(var.IsNul());
00868 ASSERT_FALSE(var.IsArray());
00869 ASSERT_EQ(var.Dimensions.size(), 1);
00870 ASSERT_EQ(var.Dimensions[0], 1);
00871 }
00872
00874 TEST_F(OpcUaBinaryDeserialization, Variant_FLOAT)
00875 {
00876 using namespace OpcUa;
00877 using namespace OpcUa::Binary;
00878
00879 char encodingMask = static_cast<char>(VariantType::FLOAT);
00880
00881 const std::vector<char> expectedData = {
00882 encodingMask,
00883
00884 0, 0, (char)0xD0, (char)0xC0
00885 };
00886
00887 GetChannel().SetData(expectedData);
00888
00889 Variant var;
00890 GetStream() >> var;
00891
00892 ASSERT_EQ(var.Type(), VariantType::FLOAT);
00893 ASSERT_EQ(var.As<float>(), -6.5);
00894 ASSERT_FALSE(var.IsNul());
00895 ASSERT_FALSE(var.IsArray());
00896 ASSERT_TRUE(var.Dimensions.empty());
00897 }
00898
00899 TEST_F(OpcUaBinaryDeserialization, Variant_FLOAT_Array)
00900 {
00901 using namespace OpcUa;
00902 using namespace OpcUa::Binary;
00903
00904 char encodingMask = static_cast<uint8_t>(VariantType::FLOAT) | HAS_ARRAY_MASK;
00905
00906 const std::vector<char> expectedData = {
00907 encodingMask,
00908 2,0,0,0,
00909 0, 0, (char)0xD0, (char)0xC0,
00910 0, 0, (char)0xD0, (char)0xC0
00911
00912
00913 };
00914
00915 GetChannel().SetData(expectedData);
00916
00917 Variant var;
00918 GetStream() >> var;
00919
00920 ASSERT_EQ(var.Type(), VariantType::FLOAT);
00921 std::vector<float> vals;
00922 ASSERT_NO_THROW(vals = var.As<std::vector<float>>());
00923 ASSERT_EQ(vals.size(), 2);
00924 ASSERT_EQ(vals[0], -6.5);
00925 ASSERT_EQ(vals[1], -6.5);
00926 ASSERT_FALSE(var.IsNul());
00927 ASSERT_TRUE(var.IsArray());
00928 ASSERT_TRUE(var.Dimensions.empty());
00929 }
00930
00931
00932 TEST_F(OpcUaBinaryDeserialization, Variant_FLOAT_DIMENSIONS)
00933 {
00934 using namespace OpcUa;
00935 using namespace OpcUa::Binary;
00936
00937 char encodingMask = static_cast<uint8_t>(VariantType::FLOAT) | HAS_DIMENSIONS_MASK;
00938
00939 const std::vector<char> expectedData = {
00940 encodingMask,
00941 0, 0, (char)0xD0, (char)0xC0,
00942
00943 1,0,0,0,
00944 1,0,0,0,
00945 };
00946
00947 GetChannel().SetData(expectedData);
00948
00949 Variant var;
00950 GetStream() >> var;
00951
00952 ASSERT_EQ(var.Type(), VariantType::FLOAT);
00953 ASSERT_EQ(var.As<float>(), -6.5);
00954 ASSERT_FALSE(var.IsNul());
00955 ASSERT_FALSE(var.IsArray());
00956 ASSERT_EQ(var.Dimensions.size(), 1);
00957 ASSERT_EQ(var.Dimensions[0], 1);
00958 }
00959
00961 TEST_F(OpcUaBinaryDeserialization, Variant_DOUBLE)
00962 {
00963 using namespace OpcUa;
00964 using namespace OpcUa::Binary;
00965
00966 char encodingMask = static_cast<char>(VariantType::DOUBLE);
00967
00968 const std::vector<char> expectedData = {
00969 encodingMask,
00970 0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41
00971 };
00972
00973 GetChannel().SetData(expectedData);
00974
00975 Variant var;
00976 GetStream() >> var;
00977
00978 ASSERT_EQ(var.Type(), VariantType::DOUBLE);
00979 ASSERT_EQ(var.As<double>(), 1200000);
00980 ASSERT_FALSE(var.IsNul());
00981 ASSERT_FALSE(var.IsArray());
00982 ASSERT_TRUE(var.Dimensions.empty());
00983 }
00984
00985 TEST_F(OpcUaBinaryDeserialization, Variant_DOUBLE_Array)
00986 {
00987 using namespace OpcUa;
00988 using namespace OpcUa::Binary;
00989
00990 char encodingMask = static_cast<uint8_t>(VariantType::DOUBLE) | HAS_ARRAY_MASK;
00991
00992 const std::vector<char> expectedData = {
00993 encodingMask,
00994 2,0,0,0,
00995 0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
00996 0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41
00997 };
00998
00999 GetChannel().SetData(expectedData);
01000
01001 Variant var;
01002 GetStream() >> var;
01003
01004 ASSERT_EQ(var.Type(), VariantType::DOUBLE);
01005 std::vector<double> vals;
01006 ASSERT_NO_THROW(vals = var.As<std::vector<double>>());
01007 ASSERT_EQ(vals.size(), 2);
01008 ASSERT_EQ(vals[0], 1200000);
01009 ASSERT_EQ(vals[1], 1200000);
01010 ASSERT_FALSE(var.IsNul());
01011 ASSERT_TRUE(var.IsArray());
01012 ASSERT_TRUE(var.Dimensions.empty());
01013 }
01014
01015
01016 TEST_F(OpcUaBinaryDeserialization, Variant_DOUBLE_DIMENSIONS)
01017 {
01018 using namespace OpcUa;
01019 using namespace OpcUa::Binary;
01020
01021 char encodingMask = static_cast<uint8_t>(VariantType::DOUBLE) | HAS_DIMENSIONS_MASK;
01022
01023 const std::vector<char> expectedData = {
01024 encodingMask,
01025 0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
01026 1,0,0,0,
01027 1,0,0,0,
01028 };
01029
01030 GetChannel().SetData(expectedData);
01031
01032 Variant var;
01033 GetStream() >> var;
01034
01035 ASSERT_EQ(var.Type(), VariantType::DOUBLE);
01036 ASSERT_EQ(var.As<double>(), 1200000);
01037 ASSERT_FALSE(var.IsNul());
01038 ASSERT_FALSE(var.IsArray());
01039 ASSERT_EQ(var.Dimensions.size(), 1);
01040 ASSERT_EQ(var.Dimensions[0], 1);
01041 }
01042
01043 OpcUa::Guid CreateTestGuid()
01044 {
01045 OpcUa::Guid guid;
01046 guid.Data1 = 0x01020304;
01047 guid.Data2 = 0x0506;
01048 guid.Data3 = 0x0708;
01049
01050 for (unsigned i = 0; i < 8; ++i)
01051 {
01052 guid.Data4[i] = i + 1;
01053 }
01054 return guid;
01055 }
01056
01058 TEST_F(OpcUaBinaryDeserialization, Variant_GUId)
01059 {
01060 using namespace OpcUa;
01061 using namespace OpcUa::Binary;
01062
01063 char encodingMask = static_cast<char>(VariantType::GUId);
01064
01065 const std::vector<char> expectedData = {
01066 encodingMask,
01067 4,3,2,1, 6,5, 8,7, 1,2,3,4,5,6,7,8
01068 };
01069
01070 GetChannel().SetData(expectedData);
01071
01072 Variant var;
01073 GetStream() >> var;
01074
01075 OpcUa::Guid guid = CreateTestGuid();
01076
01077 ASSERT_EQ(var.Type(), VariantType::GUId);
01078 ASSERT_EQ(var.As<Guid>(), guid);
01079 ASSERT_FALSE(var.IsNul());
01080 ASSERT_FALSE(var.IsArray());
01081 ASSERT_TRUE(var.Dimensions.empty());
01082 }
01083
01084 TEST_F(OpcUaBinaryDeserialization, Variant_GUId_Array)
01085 {
01086 using namespace OpcUa;
01087 using namespace OpcUa::Binary;
01088
01089 char encodingMask = static_cast<uint8_t>(VariantType::GUId) | HAS_ARRAY_MASK;
01090
01091 const std::vector<char> expectedData = {
01092 encodingMask,
01093 2,0,0,0,
01094 4,3,2,1, 6,5, 8,7, 1,2,3,4,5,6,7,8,
01095 4,3,2,1, 6,5, 8,7, 1,2,3,4,5,6,7,8
01096 };
01097
01098 GetChannel().SetData(expectedData);
01099
01100 Variant var;
01101 GetStream() >> var;
01102
01103 OpcUa::Guid guid = CreateTestGuid();
01104
01105 ASSERT_EQ(var.Type(), VariantType::GUId);
01106 std::vector<Guid> vals;
01107 ASSERT_NO_THROW(vals = var.As<std::vector<Guid>>());
01108 ASSERT_EQ(vals.size(), 2);
01109 ASSERT_EQ(vals[0], guid);
01110 ASSERT_EQ(vals[1], guid);
01111 ASSERT_FALSE(var.IsNul());
01112 ASSERT_TRUE(var.IsArray());
01113 ASSERT_TRUE(var.Dimensions.empty());
01114 }
01115
01116
01117 TEST_F(OpcUaBinaryDeserialization, Variant_GUId_DIMENSIONS)
01118 {
01119 using namespace OpcUa;
01120 using namespace OpcUa::Binary;
01121
01122 char encodingMask = static_cast<uint8_t>(VariantType::GUId) | HAS_DIMENSIONS_MASK;
01123
01124 const std::vector<char> expectedData = {
01125 encodingMask,
01126 4,3,2,1, 6,5, 8,7, 1,2,3,4,5,6,7,8,
01127 1,0,0,0,
01128 1,0,0,0,
01129 };
01130
01131 GetChannel().SetData(expectedData);
01132
01133 Variant var;
01134 GetStream() >> var;
01135
01136 OpcUa::Guid guid = CreateTestGuid();
01137
01138 ASSERT_EQ(var.Type(), VariantType::GUId);
01139 ASSERT_EQ(var.As<Guid>(), guid);
01140 ASSERT_FALSE(var.IsNul());
01141 ASSERT_FALSE(var.IsArray());
01142 ASSERT_EQ(var.Dimensions.size(), 1);
01143 ASSERT_EQ(var.Dimensions[0], 1);
01144 }
01145
01147 TEST_F(OpcUaBinaryDeserialization, Variant_STRING)
01148 {
01149 using namespace OpcUa;
01150 using namespace OpcUa::Binary;
01151
01152 char encodingMask = static_cast<char>(VariantType::STRING);
01153
01154 const std::vector<char> expectedData = {
01155 encodingMask,
01156 4,0,0,0, 'R','o','o','t'
01157 };
01158
01159 GetChannel().SetData(expectedData);
01160
01161 Variant var;
01162 GetStream() >> var;
01163
01164 ASSERT_EQ(var.Type(), VariantType::STRING);
01165 ASSERT_EQ(var.As<std::string>(), std::string("Root"));
01166 ASSERT_FALSE(var.IsNul());
01167 ASSERT_FALSE(var.IsArray());
01168 ASSERT_TRUE(var.Dimensions.empty());
01169 }
01170
01171 TEST_F(OpcUaBinaryDeserialization, Variant_STRING_Array)
01172 {
01173 using namespace OpcUa;
01174 using namespace OpcUa::Binary;
01175
01176 char encodingMask = static_cast<uint8_t>(VariantType::STRING) | HAS_ARRAY_MASK;
01177
01178 const std::vector<char> expectedData = {
01179 encodingMask,
01180 2,0,0,0,
01181 4,0,0,0, 'R','o','o','t',
01182 4,0,0,0, 'R','o','o','t'
01183 };
01184
01185 GetChannel().SetData(expectedData);
01186
01187 Variant var;
01188 GetStream() >> var;
01189
01190 OpcUa::Guid guid = CreateTestGuid();
01191
01192 ASSERT_EQ(var.Type(), VariantType::STRING);
01193 std::vector<std::string> vals;
01194 ASSERT_NO_THROW(vals = var.As<std::vector<std::string>>());
01195 ASSERT_EQ(vals.size(), 2);
01196 ASSERT_EQ(vals[0], std::string("Root"));
01197 ASSERT_EQ(vals[1], std::string("Root"));
01198 ASSERT_FALSE(var.IsNul());
01199 ASSERT_TRUE(var.IsArray());
01200 ASSERT_TRUE(var.Dimensions.empty());
01201 }
01202
01203
01204 TEST_F(OpcUaBinaryDeserialization, Variant_STRING_DIMENSIONS)
01205 {
01206 using namespace OpcUa;
01207 using namespace OpcUa::Binary;
01208
01209 char encodingMask = static_cast<uint8_t>(VariantType::STRING) | HAS_DIMENSIONS_MASK;
01210
01211 const std::vector<char> expectedData = {
01212 encodingMask,
01213 4,0,0,0, 'R','o','o','t',
01214 1,0,0,0,
01215 1,0,0,0,
01216 };
01217
01218 GetChannel().SetData(expectedData);
01219
01220 Variant var;
01221 GetStream() >> var;
01222
01223 OpcUa::Guid guid = CreateTestGuid();
01224
01225 ASSERT_EQ(var.Type(), VariantType::STRING);
01226 ASSERT_EQ(var.As<std::string>(), std::string("Root"));
01227 ASSERT_FALSE(var.IsNul());
01228 ASSERT_FALSE(var.IsArray());
01229 ASSERT_EQ(var.Dimensions.size(), 1);
01230 ASSERT_EQ(var.Dimensions[0], 1);
01231 }
01232
01234 TEST_F(OpcUaBinaryDeserialization, Variant_BYTE_STRING)
01235 {
01236 using namespace OpcUa;
01237 using namespace OpcUa::Binary;
01238
01239 char encodingMask = static_cast<char>(VariantType::BYTE_STRING);
01240
01241 const std::vector<char> expectedData = {
01242 encodingMask,
01243 2,0,0,0, 1,2
01244 };
01245
01246 GetChannel().SetData(expectedData);
01247
01248 Variant var;
01249 GetStream() >> var;
01250
01251 ASSERT_EQ(var.Type(), VariantType::BYTE_STRING);
01252 ASSERT_EQ(var.As<ByteString>(), ByteString(std::vector<uint8_t>{1,2}));
01253 ASSERT_FALSE(var.IsNul());
01254 ASSERT_FALSE(var.IsArray());
01255 ASSERT_TRUE(var.Dimensions.empty());
01256 }
01257
01258 TEST_F(OpcUaBinaryDeserialization, Variant_BYTE_STRING_Array)
01259 {
01260 using namespace OpcUa;
01261 using namespace OpcUa::Binary;
01262
01263 char encodingMask = static_cast<uint8_t>(VariantType::BYTE_STRING) | HAS_ARRAY_MASK;
01264
01265 const std::vector<char> expectedData = {
01266 encodingMask,
01267 2,0,0,0,
01268 2,0,0,0, 1,2,
01269 2,0,0,0, 1,2
01270 };
01271
01272 GetChannel().SetData(expectedData);
01273
01274 Variant var;
01275 GetStream() >> var;
01276
01277 ASSERT_EQ(var.Type(), VariantType::BYTE_STRING);
01278 std::vector<ByteString> vals;
01279 ASSERT_NO_THROW(vals = var.As<std::vector<ByteString>>());
01280 ASSERT_EQ(vals.size(), 2);
01281 ASSERT_EQ(vals[0], ByteString(std::vector<uint8_t>{1,2}));
01282 ASSERT_EQ(vals[1], ByteString(std::vector<uint8_t>{1,2}));
01283 ASSERT_FALSE(var.IsNul());
01284 ASSERT_TRUE(var.IsArray());
01285 ASSERT_TRUE(var.Dimensions.empty());
01286 }
01287
01288
01289 TEST_F(OpcUaBinaryDeserialization, Variant_BYTE_STRING_DIMENSIONS)
01290 {
01291 using namespace OpcUa;
01292 using namespace OpcUa::Binary;
01293
01294 char encodingMask = static_cast<uint8_t>(VariantType::BYTE_STRING) | HAS_DIMENSIONS_MASK;
01295
01296 const std::vector<char> expectedData = {
01297 encodingMask,
01298 2,0,0,0, 1,2,
01299 1,0,0,0,
01300 1,0,0,0,
01301 };
01302
01303 GetChannel().SetData(expectedData);
01304
01305 Variant var;
01306 GetStream() >> var;
01307
01308 OpcUa::Guid guid = CreateTestGuid();
01309
01310 ASSERT_EQ(var.Type(), VariantType::BYTE_STRING);
01311 ASSERT_EQ(var.As<ByteString>(), ByteString(std::vector<uint8_t>{1,2}));
01312 ASSERT_FALSE(var.IsNul());
01313 ASSERT_FALSE(var.IsArray());
01314 ASSERT_EQ(var.Dimensions.size(), 1);
01315 ASSERT_EQ(var.Dimensions[0], 1);
01316 }
01317
01319 TEST_F(OpcUaBinaryDeserialization, Variant_DATETIME)
01320 {
01321 using namespace OpcUa;
01322 using namespace OpcUa::Binary;
01323
01324 char encodingMask = static_cast<char>(VariantType::DATE_TIME);
01325
01326 const std::vector<char> expectedData = {
01327 encodingMask,
01328 8, 7, 6, 5, 4, 3, 2, 1
01329 };
01330
01331 GetChannel().SetData(expectedData);
01332
01333 Variant var;
01334 GetStream() >> var;
01335
01336 ASSERT_EQ(var.Type(), VariantType::DATE_TIME);
01337 ASSERT_EQ(var.As<DateTime>(), 0x0102030405060708);
01338 ASSERT_FALSE(var.IsNul());
01339 ASSERT_FALSE(var.IsArray());
01340 ASSERT_TRUE(var.Dimensions.empty());
01341 }
01342
01343 TEST_F(OpcUaBinaryDeserialization, Variant_DATE_TIME_Array)
01344 {
01345 using namespace OpcUa;
01346 using namespace OpcUa::Binary;
01347
01348 char encodingMask = static_cast<uint8_t>(VariantType::DATE_TIME) | HAS_ARRAY_MASK;
01349
01350 const std::vector<char> expectedData = {
01351 encodingMask,
01352 2,0,0,0,
01353 8, 7, 6, 5, 4, 3, 2, 1,
01354 8, 7, 6, 5, 4, 3, 2, 1
01355 };
01356
01357 GetChannel().SetData(expectedData);
01358
01359 Variant var;
01360 GetStream() >> var;
01361
01362 ASSERT_EQ(var.Type(), VariantType::DATE_TIME);
01363 std::vector<DateTime> vals;
01364 ASSERT_NO_THROW(vals = var.As<std::vector<DateTime>>());
01365 ASSERT_EQ(vals.size(), 2);
01366 ASSERT_EQ(vals[0], 0x0102030405060708);
01367 ASSERT_EQ(vals[1], 0x0102030405060708);
01368 ASSERT_FALSE(var.IsNul());
01369 ASSERT_TRUE(var.IsArray());
01370 ASSERT_TRUE(var.Dimensions.empty());
01371 }
01372
01373
01374 TEST_F(OpcUaBinaryDeserialization, Variant_DATE_TIME_DIMENSIONS)
01375 {
01376 using namespace OpcUa;
01377 using namespace OpcUa::Binary;
01378
01379 char encodingMask = static_cast<uint8_t>(VariantType::DATE_TIME) | HAS_DIMENSIONS_MASK;
01380
01381 const std::vector<char> expectedData = {
01382 encodingMask,
01383 8, 7, 6, 5, 4, 3, 2, 1,
01384 1,0,0,0,
01385 1,0,0,0,
01386 };
01387
01388 GetChannel().SetData(expectedData);
01389
01390 Variant var;
01391 GetStream() >> var;
01392
01393 ASSERT_EQ(var.Type(), VariantType::DATE_TIME);
01394 ASSERT_EQ(var.As<DateTime>(), 0x0102030405060708);
01395 ASSERT_FALSE(var.IsNul());
01396 ASSERT_FALSE(var.IsArray());
01397 ASSERT_EQ(var.Dimensions.size(), 1);
01398 ASSERT_EQ(var.Dimensions[0], 1);
01399 }
01400
01402 TEST_F(OpcUaBinaryDeserialization, Variant_LOCALIZED_TEXT)
01403 {
01404 using namespace OpcUa;
01405 using namespace OpcUa::Binary;
01406
01407 char encodingMask = static_cast<char>(VariantType::LOCALIZED_TEXT);
01408
01409 const std::vector<char> expectedData = {
01410 encodingMask,
01411 2, 4,0,0,0,'t','e','x','t'
01412 };
01413
01414 GetChannel().SetData(expectedData);
01415
01416 Variant var;
01417 GetStream() >> var;
01418
01419 ASSERT_EQ(var.Type(), VariantType::LOCALIZED_TEXT);
01420 ASSERT_EQ(var.As<LocalizedText>(), LocalizedText("text"));
01421 ASSERT_FALSE(var.IsNul());
01422 ASSERT_FALSE(var.IsArray());
01423 ASSERT_TRUE(var.Dimensions.empty());
01424 }
01425
01426 TEST_F(OpcUaBinaryDeserialization, Variant_LOCALIZED_TEXT_Array)
01427 {
01428 using namespace OpcUa;
01429 using namespace OpcUa::Binary;
01430
01431 char encodingMask = static_cast<uint8_t>(VariantType::LOCALIZED_TEXT) | HAS_ARRAY_MASK;
01432
01433 const std::vector<char> expectedData = {
01434 encodingMask,
01435 2,0,0,0,
01436 2, 4,0,0,0,'t','e','x','t',
01437 2, 4,0,0,0,'t','e','x','t'
01438 };
01439
01440 GetChannel().SetData(expectedData);
01441
01442 Variant var;
01443 GetStream() >> var;
01444
01445 ASSERT_EQ(var.Type(), VariantType::LOCALIZED_TEXT);
01446 std::vector<LocalizedText> vals;
01447 ASSERT_NO_THROW(vals = var.As<std::vector<LocalizedText>>());
01448 ASSERT_EQ(vals.size(), 2);
01449 ASSERT_EQ(vals[0], LocalizedText("text"));
01450 ASSERT_EQ(vals[1], LocalizedText("text"));
01451 ASSERT_FALSE(var.IsNul());
01452 ASSERT_TRUE(var.IsArray());
01453 ASSERT_TRUE(var.Dimensions.empty());
01454 }
01455
01456
01457 TEST_F(OpcUaBinaryDeserialization, Variant_LOCALIZED_TEXT_DIMENSIONS)
01458 {
01459 using namespace OpcUa;
01460 using namespace OpcUa::Binary;
01461
01462 char encodingMask = static_cast<uint8_t>(VariantType::LOCALIZED_TEXT) | HAS_DIMENSIONS_MASK;
01463
01464 const std::vector<char> expectedData = {
01465 encodingMask,
01466 2, 4,0,0,0,'t','e','x','t',
01467 1,0,0,0,
01468 1,0,0,0,
01469 };
01470
01471 GetChannel().SetData(expectedData);
01472
01473 Variant var;
01474 GetStream() >> var;
01475
01476 ASSERT_EQ(var.Type(), VariantType::LOCALIZED_TEXT);
01477 ASSERT_EQ(var.As<LocalizedText>(), LocalizedText("text"));
01478 ASSERT_FALSE(var.IsNul());
01479 ASSERT_FALSE(var.IsArray());
01480 ASSERT_EQ(var.Dimensions.size(), 1);
01481 ASSERT_EQ(var.Dimensions[0], 1);
01482 }
01483
01485 TEST_F(OpcUaBinaryDeserialization, Variant_QUALIFIED_NAME)
01486 {
01487 using namespace OpcUa;
01488 using namespace OpcUa::Binary;
01489
01490 char encodingMask = static_cast<char>(VariantType::QUALIFIED_NAME);
01491
01492 const std::vector<char> expectedData = {
01493 encodingMask,
01494 1,0, 4,0,0,0, 'n','a','m','e'
01495 };
01496
01497 GetChannel().SetData(expectedData);
01498
01499 Variant var;
01500 GetStream() >> var;
01501
01502 ASSERT_EQ(var.Type(), VariantType::QUALIFIED_NAME);
01503 ASSERT_EQ(var.As<QualifiedName>(), QualifiedName(1, "name"));
01504 ASSERT_FALSE(var.IsNul());
01505 ASSERT_FALSE(var.IsArray());
01506 ASSERT_TRUE(var.Dimensions.empty());
01507 }
01508
01509 TEST_F(OpcUaBinaryDeserialization, Variant_QUALIFIED_NAME_Array)
01510 {
01511 using namespace OpcUa;
01512 using namespace OpcUa::Binary;
01513
01514 char encodingMask = static_cast<uint8_t>(VariantType::QUALIFIED_NAME) | HAS_ARRAY_MASK;
01515
01516 const std::vector<char> expectedData = {
01517 encodingMask,
01518 2,0,0,0,
01519 1,0, 4,0,0,0, 'n','a','m','e',
01520 1,0, 4,0,0,0, 'n','a','m','e'
01521 };
01522
01523 GetChannel().SetData(expectedData);
01524
01525 Variant var;
01526 GetStream() >> var;
01527
01528 ASSERT_EQ(var.Type(), VariantType::QUALIFIED_NAME);
01529 std::vector<QualifiedName> vals;
01530 ASSERT_NO_THROW(vals = var.As<std::vector<QualifiedName>>());
01531 ASSERT_EQ(vals.size(), 2);
01532 ASSERT_EQ(vals[0], QualifiedName(1, "name"));
01533 ASSERT_EQ(vals[1], QualifiedName(1, "name"));
01534 ASSERT_FALSE(var.IsNul());
01535 ASSERT_TRUE(var.IsArray());
01536 ASSERT_TRUE(var.Dimensions.empty());
01537 }
01538
01539
01540 TEST_F(OpcUaBinaryDeserialization, Variant_QUALIFIED_NAME_DIMENSIONS)
01541 {
01542 using namespace OpcUa;
01543 using namespace OpcUa::Binary;
01544
01545 char encodingMask = static_cast<uint8_t>(VariantType::QUALIFIED_NAME) | HAS_DIMENSIONS_MASK;
01546
01547 const std::vector<char> expectedData = {
01548 encodingMask,
01549 1,0, 4,0,0,0, 'n','a','m','e',
01550 1,0,0,0,
01551 1,0,0,0,
01552 };
01553
01554 GetChannel().SetData(expectedData);
01555
01556 Variant var;
01557 GetStream() >> var;
01558
01559 ASSERT_EQ(var.Type(), VariantType::QUALIFIED_NAME);
01560 ASSERT_EQ(var.As<QualifiedName>(), QualifiedName(1, "name"));
01561 ASSERT_FALSE(var.IsNul());
01562 ASSERT_FALSE(var.IsArray());
01563 ASSERT_EQ(var.Dimensions.size(), 1);
01564 ASSERT_EQ(var.Dimensions[0], 1);
01565 }
01566
01568 TEST_F(OpcUaBinaryDeserialization, Variant_NODE_Id)
01569 {
01570 using namespace OpcUa;
01571 using namespace OpcUa::Binary;
01572
01573 char encodingMask = static_cast<char>(VariantType::NODE_Id);
01574
01575 const std::vector<char> expectedData = {
01576 encodingMask,
01577 1, 0, (char)0xC1, 0x1
01578 };
01579
01580 GetChannel().SetData(expectedData);
01581
01582 Variant var;
01583 GetStream() >> var;
01584
01585 ASSERT_EQ(var.Type(), VariantType::NODE_Id);
01586 ASSERT_EQ(var.As<NodeId>(), OpcUa::FourByteNodeId(449));
01587 ASSERT_FALSE(var.IsNul());
01588 ASSERT_FALSE(var.IsArray());
01589 ASSERT_TRUE(var.Dimensions.empty());
01590 }
01591
01592 TEST_F(OpcUaBinaryDeserialization, Variant_NODE_Id_Array)
01593 {
01594 using namespace OpcUa;
01595 using namespace OpcUa::Binary;
01596
01597 char encodingMask = static_cast<uint8_t>(VariantType::NODE_Id) | HAS_ARRAY_MASK;
01598
01599 const std::vector<char> expectedData = {
01600 encodingMask,
01601 2,0,0,0,
01602 1, 0, (char)0xC1, 0x1,
01603 1, 0, (char)0xC1, 0x1
01604 };
01605
01606 GetChannel().SetData(expectedData);
01607
01608 Variant var;
01609 GetStream() >> var;
01610
01611 ASSERT_EQ(var.Type(), VariantType::NODE_Id);
01612 std::vector<NodeId> vals;
01613 ASSERT_NO_THROW(vals = var.As<std::vector<NodeId>>());
01614 ASSERT_EQ(vals.size(), 2);
01615 ASSERT_EQ(vals[0], OpcUa::FourByteNodeId(449));
01616 ASSERT_EQ(vals[1], OpcUa::FourByteNodeId(449));
01617 ASSERT_FALSE(var.IsNul());
01618 ASSERT_TRUE(var.IsArray());
01619 ASSERT_TRUE(var.Dimensions.empty());
01620 }
01621
01622 TEST_F(OpcUaBinaryDeserialization, Variant_NODE_Id_DIMENSIONS)
01623 {
01624 using namespace OpcUa;
01625 using namespace OpcUa::Binary;
01626
01627 char encodingMask = static_cast<uint8_t>(VariantType::NODE_Id) | HAS_DIMENSIONS_MASK;
01628
01629 const std::vector<char> expectedData = {
01630 encodingMask,
01631 1, 0, (char)0xC1, 0x1,
01632 1,0,0,0,
01633 1,0,0,0,
01634 };
01635
01636 GetChannel().SetData(expectedData);
01637
01638 Variant var;
01639 GetStream() >> var;
01640
01641 ASSERT_EQ(var.Type(), VariantType::NODE_Id);
01642 ASSERT_EQ(var.As<NodeId>(), OpcUa::FourByteNodeId(449));
01643 ASSERT_FALSE(var.IsNul());
01644 ASSERT_FALSE(var.IsArray());
01645 ASSERT_EQ(var.Dimensions.size(), 1);
01646 ASSERT_EQ(var.Dimensions[0], 1);
01647 }
01648
01650
01651 TEST(Variant, InitializeNUL)
01652 {
01653 const OpcUa::Variant var;
01654 ASSERT_EQ(var.Type(), OpcUa::VariantType::NUL);
01655 ASSERT_FALSE(var.IsArray());
01656 ASSERT_TRUE(var.IsNul());
01657 }
01658
01659 TEST(Variant, InitializeWithBoolValue)
01660 {
01661 const OpcUa::Variant var(true);
01662 ASSERT_EQ(var.Type(), OpcUa::VariantType::BOOLEAN);
01663 ASSERT_FALSE(var.IsArray());
01664 ASSERT_FALSE(var.IsNul());
01665 }
01666
01667 TEST(Variant, AssignBoolValue)
01668 {
01669 OpcUa::Variant var;
01670 var = true;
01671 ASSERT_EQ(var.Type(), OpcUa::VariantType::BOOLEAN);
01672 ASSERT_FALSE(var.IsArray());
01673 ASSERT_FALSE(var.IsNul());
01674 }
01675
01676
01677
01678 TEST(Variant, InitializeWithBoolVector)
01679 {
01680 const std::vector<bool> vec{true, false};
01681 const OpcUa::Variant var(vec);
01682 ASSERT_EQ(var.Type(), OpcUa::VariantType::BOOLEAN);
01683 ASSERT_TRUE(var.IsArray());
01684 ASSERT_FALSE(var.IsNul());
01685 }
01686
01687 TEST(Variant, InitializeWithString)
01688 {
01689 const OpcUa::Variant var(std::string("string"));
01690 ASSERT_EQ(var.Type(), OpcUa::VariantType::STRING);
01691 ASSERT_FALSE(var.IsArray());
01692 ASSERT_FALSE(var.IsNul());
01693 }
01694
01695 TEST(Variant, InitializeWithVariant)
01696 {
01697 const OpcUa::Variant var((uint32_t)OpcUa::NodeClass::Object);
01698 ASSERT_EQ(var.Type(), OpcUa::VariantType::UINT32);
01699 ASSERT_FALSE(var.IsArray());
01700 ASSERT_FALSE(var.IsNul());
01701 }
01702
01703 TEST(Variant, InitializeObjectId)
01704 {
01705 const OpcUa::Variant var = OpcUa::ObjectId::RootFolder;
01706 ASSERT_EQ(var.Type(), OpcUa::VariantType::NODE_Id);
01707 ASSERT_EQ(var, OpcUa::ObjectId::RootFolder);
01708 ASSERT_FALSE(var.IsArray());
01709 ASSERT_FALSE(var.IsNul());
01710 }
01711
01712 TEST(Variant, InitializeMessageId)
01713 {
01714 const OpcUa::Variant var = OpcUa::MessageId::READ_RESPONSE;
01715 ASSERT_EQ(var.Type(), OpcUa::VariantType::NODE_Id);
01716 ASSERT_EQ(var, OpcUa::MessageId::READ_RESPONSE);
01717 ASSERT_FALSE(var.IsArray());
01718 ASSERT_FALSE(var.IsNul());
01719 }
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753
01754
01755
01756
01757
01758
01759 TEST(Variant, Comparable)
01760 {
01761 ASSERT_EQ(OpcUa::Variant(), OpcUa::Variant());
01762
01763 ASSERT_EQ(OpcUa::Variant(1), OpcUa::Variant(1));
01764 ASSERT_EQ(OpcUa::Variant(1), 1);
01765 ASSERT_NE(OpcUa::Variant(1), 2);
01766
01767 ASSERT_EQ(OpcUa::Variant(true), OpcUa::Variant(true));
01768 ASSERT_EQ(OpcUa::Variant(true), true);
01769
01770 ASSERT_NE(OpcUa::Variant(true), OpcUa::Variant(false));
01771 ASSERT_NE(OpcUa::Variant(true), false);
01772 }