123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941 |
- /*
- ============================================================================
- Name : check_builtin.c
- Author :
- Copyright : Your copyright notice
- Description :
- ============================================================================
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include "opcua.h"
- #include "ua_transport.h"
- #include "check.h"
- START_TEST(UA_Boolean_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_Boolean* arg = UA_NULL;
- // when
- UA_Boolean storageSize = UA_Boolean_calcSize(arg);
- // then
- ck_assert_int_eq(storageSize, 1);
- }
- END_TEST
- START_TEST(UA_SByte_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_SByte* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_SByte_calcSize(arg);
- // then
- ck_assert_int_ge(storageSize, 1);
- }
- END_TEST
- START_TEST(UA_Byte_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_Byte* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_Byte_calcSize(arg);
- // then
- ck_assert_int_ge(storageSize, 1);
- }
- END_TEST
- START_TEST(UA_Int16_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_Int16* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_Int16_calcSize(arg);
- // then
- ck_assert_int_ge(storageSize, 2);
- }
- END_TEST
- START_TEST(UA_UInt16_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_UInt16* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_UInt16_calcSize(arg);
- // then
- ck_assert_int_ge(storageSize, 2);
- }
- END_TEST
- START_TEST(UA_Int32_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_Int32* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_Int32_calcSize(arg);
- // then
- ck_assert_int_ge(storageSize, 4);
- }
- END_TEST
- START_TEST(UA_UInt32_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_UInt32* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_UInt32_calcSize(arg);
- // then
- ck_assert_int_ge(storageSize, 4);
- }
- END_TEST
- START_TEST(UA_Int64_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_Int64* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_Int64_calcSize(arg);
- // then
- ck_assert_int_ge(storageSize, 8);
- }
- END_TEST
- START_TEST(UA_UInt64_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_UInt64* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_UInt64_calcSize(arg);
- // then
- ck_assert_int_ge(storageSize, 8);
- }
- END_TEST
- START_TEST(UA_Float_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_Float* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_Float_calcSize(arg);
- // then
- ck_assert_int_ge(storageSize, 4);
- }
- END_TEST
- START_TEST(UA_Double_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_Double* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_Double_calcSize(arg);
- // then
- ck_assert_int_ge(storageSize, 8);
- }
- END_TEST
- START_TEST(UA_String_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_String* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_String_calcSize(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_String));
- ck_assert_int_ge(storageSize, UA_Int32_calcSize(UA_NULL) + sizeof(UA_NULL));
- }
- END_TEST
- START_TEST(UA_DateTime_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_DateTime* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_DateTime_calcSize(arg);
- // then
- ck_assert_int_ge(storageSize, 8);
- }
- END_TEST
- START_TEST(UA_Guid_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_Guid* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_Guid_calcSize(arg);
- // then
- ck_assert_int_ge(storageSize, 16);
- }
- END_TEST
- START_TEST(UA_ByteString_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_ByteString* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_ByteString_calcSize(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_ByteString));
- ck_assert_int_ge(storageSize, UA_Int32_calcSize(UA_NULL)+sizeof(UA_NULL));
- }
- END_TEST
- START_TEST(UA_XmlElement_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_XmlElement* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_XmlElement_calcSize(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_XmlElement));
- ck_assert_int_ge(storageSize, UA_Int32_calcSize(UA_NULL)+sizeof(UA_NULL));
- }
- END_TEST
- START_TEST(UA_NodeId_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_NodeId* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_NodeId_calcSize(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_NodeId));
- }
- END_TEST
- START_TEST(UA_ExpandedNodeId_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_ExpandedNodeId* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_ExpandedNodeId_calcSize(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_ExpandedNodeId));
- }
- END_TEST
- START_TEST(UA_StatusCode_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_StatusCode* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_StatusCode_calcSize(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_StatusCode));
- }
- END_TEST
- START_TEST(UA_QualifiedName_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_QualifiedName* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_QualifiedName_calcSize(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_QualifiedName));
- }
- END_TEST
- START_TEST(UA_LocalizedText_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_LocalizedText* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_LocalizedText_calcSize(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_LocalizedText));
- }
- END_TEST
- START_TEST(UA_ExtensionObject_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_ExtensionObject* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_ExtensionObject_calcSize(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_ExtensionObject));
- }
- END_TEST
- START_TEST(UA_ExtensionObject_calcSizeShallWorkOnExample)
- {
- // given
- UA_Byte data[3] = {1,2,3};
- UA_ExtensionObject extensionObject;
- // empty ExtensionObject, handcoded
- // when
- extensionObject.typeId.encodingByte = UA_NODEIDTYPE_TWOBYTE;
- extensionObject.typeId.identifier.numeric = 0;
- extensionObject.encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_NOBODYISENCODED;
- // then
- ck_assert_int_eq(UA_ExtensionObject_calcSize(&extensionObject), 1 + 1 + 1);
- // ExtensionObject with ByteString-Body
- // when
- extensionObject.encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING;
- extensionObject.body.data = data;
- extensionObject.body.length = 3;
- // then
- ck_assert_int_eq(UA_ExtensionObject_calcSize(&extensionObject), 3 + 4 + 3);
- }
- END_TEST
- START_TEST(UA_DataValue_calcSizeShallWorkOnExample)
- {
- // given
- UA_DataValue dataValue;
- dataValue.encodingMask = UA_DATAVALUE_ENCODINGMASK_STATUSCODE | UA_DATAVALUE_ENCODINGMASK_SOURCETIMESTAMP | UA_DATAVALUE_ENCODINGMASK_SOURCEPICOSECONDS;
- dataValue.status = 12;
- UA_DateTime dateTime;
- dateTime = 80;
- dataValue.sourceTimestamp = dateTime;
- UA_DateTime sourceTime;
- sourceTime = 214;
- dataValue.sourcePicoseconds = sourceTime;
- int size = 0;
- // when
- size = UA_DataValue_calcSize(&dataValue);
- // then
- ck_assert_int_eq(size, 21);
- }
- END_TEST
- START_TEST(UA_DataValue_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_DataValue* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_DataValue_calcSize(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_DataValue));
- }
- END_TEST
- START_TEST(UA_Variant_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_Variant* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_Variant_calcSize(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_Variant));
- }
- END_TEST
- START_TEST(UA_DiagnosticInfo_calcSizeShallWorkOnExample)
- {
- // given
- UA_DiagnosticInfo diagnosticInfo;
- diagnosticInfo.encodingMask = 0x01 | 0x02 | 0x04 | 0x08 | 0x10;
- diagnosticInfo.symbolicId = 30;
- diagnosticInfo.namespaceUri = 25;
- diagnosticInfo.localizedText = 22;
- UA_Byte additionalInfoData = 'd';
- diagnosticInfo.additionalInfo.data = &additionalInfoData;//"OPCUA";
- diagnosticInfo.additionalInfo.length = 5;
- // when & then
- ck_assert_int_eq(UA_DiagnosticInfo_calcSize(&diagnosticInfo),26);
- }
- END_TEST
- START_TEST(UA_DiagnosticInfo_calcSizeWithNullArgumentShallReturnStorageSize)
- {
- // given
- UA_DiagnosticInfo* arg = UA_NULL;
- // when
- UA_Int32 storageSize = UA_DiagnosticInfo_calcSize(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_DiagnosticInfo));
- }
- END_TEST
- START_TEST(UA_String_calcSizeWithNegativLengthShallReturnEncodingSize)
- {
- // given
- UA_String arg = {-1, UA_NULL};
- // when
- UA_Int32 encodingSize = UA_String_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 4);
- }
- END_TEST
- START_TEST(UA_String_calcSizeWithNegativLengthAndValidPointerShallReturnEncodingSize)
- {
- // given
- UA_String arg = {-1, (UA_Byte*) "OPC"};
- // when
- UA_Int32 encodingSize = UA_String_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 4);
- }
- END_TEST
- START_TEST(UA_String_calcSizeWithZeroLengthShallReturnEncodingSize)
- {
- // given
- UA_String arg = {0, UA_NULL};
- // when
- UA_Int32 encodingSize = UA_String_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 4);
- }
- END_TEST
- START_TEST(UA_String_calcSizeWithZeroLengthAndValidPointerShallReturnEncodingSize)
- {
- // given
- UA_String arg = {0, (UA_Byte*) "OPC"};
- // when
- UA_Int32 encodingSize = UA_String_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 4);
- }
- END_TEST
- START_TEST(UA_String_calcSizeShallReturnEncodingSize)
- {
- // given
- UA_String arg = {3, (UA_Byte*) "OPC"};
- // when
- UA_Int32 encodingSize = UA_String_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 4+3);
- }
- END_TEST
- START_TEST(UA_NodeId_calcSizeEncodingTwoByteShallReturnEncodingSize)
- {
- // given
- UA_NodeId arg;
- arg.encodingByte = UA_NODEIDTYPE_TWOBYTE;
- // when
- UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 2);
- }
- END_TEST
- START_TEST(UA_NodeId_calcSizeEncodingFourByteShallReturnEncodingSize)
- {
- // given
- UA_NodeId arg;
- arg.encodingByte = UA_NODEIDTYPE_FOURBYTE;
- // when
- UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 4);
- }
- END_TEST
- START_TEST(UA_NodeId_calcSizeEncodingStringShallReturnEncodingSize)
- {
- // given
- UA_NodeId arg;
- arg.encodingByte = UA_NODEIDTYPE_STRING;
- arg.identifier.string.length = 3;
- arg.identifier.string.data = (UA_Byte*) "PLT";
- // when
- UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 1+2+4+3);
- }
- END_TEST
- START_TEST(UA_NodeId_calcSizeEncodingStringNegativLengthShallReturnEncodingSize)
- {
- // given
- UA_NodeId arg;
- arg.encodingByte = UA_NODEIDTYPE_STRING;
- arg.identifier.string.length = -1;
- // when
- UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 1+2+4+0);
- }
- END_TEST
- START_TEST(UA_NodeId_calcSizeEncodingStringZeroLengthShallReturnEncodingSize)
- {
- // given
- UA_NodeId arg;
- arg.encodingByte = UA_NODEIDTYPE_STRING;
- arg.identifier.string.length = 0;
- // when
- UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 1+2+4+0);
- }
- END_TEST
- START_TEST(UA_ExpandedNodeId_calcSizeEncodingStringAndServerIndexShallReturnEncodingSize)
- {
- // given
- UA_ExpandedNodeId arg;
- arg.nodeId.encodingByte = UA_NODEIDTYPE_STRING | UA_NODEIDTYPE_SERVERINDEX_FLAG;
- arg.nodeId.identifier.string.length = 3;
- // when
- UA_Int32 encodingSize = UA_ExpandedNodeId_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 1+2+4+3+4);
- }
- END_TEST
- START_TEST(UA_ExpandedNodeId_calcSizeEncodingStringAndNamespaceUriShallReturnEncodingSize)
- {
- // given
- UA_ExpandedNodeId arg;
- arg.nodeId.encodingByte = UA_NODEIDTYPE_STRING | UA_NODEIDTYPE_NAMESPACE_URI_FLAG;
- arg.nodeId.identifier.string.length = 3;
- arg.namespaceUri.length = 7;
- // when
- UA_Int32 encodingSize = UA_ExpandedNodeId_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 1+2+4+3+4+7);
- }
- END_TEST
- START_TEST(UA_Guid_calcSizeShallReturnEncodingSize)
- {
- // given
- UA_Guid arg;
- // when
- UA_Int32 encodingSize = UA_Guid_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 16);
- }
- END_TEST
- START_TEST(UA_LocalizedText_calcSizeTextOnlyShallReturnEncodingSize)
- {
- // given
- UA_LocalizedText arg;
- arg.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT;
- arg.text.length = 42;
- // when
- UA_Int32 encodingSize = UA_LocalizedText_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 1+4+42);
- }
- END_TEST
- START_TEST(UA_LocalizedText_calcSizeLocaleOnlyShallReturnEncodingSize)
- {
- // given
- UA_LocalizedText arg;
- arg.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_LOCALE;
- arg.locale.length = 11;
- // when
- UA_Int32 encodingSize = UA_LocalizedText_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 1+4+11);
- }
- END_TEST
- START_TEST(UA_LocalizedText_calcSizeTextAndLocaleShallReturnEncodingSize)
- {
- // given
- UA_LocalizedText arg;
- arg.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_LOCALE | UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT;
- arg.text.length = 47;
- arg.locale.length = 11;
- // when
- UA_Int32 encodingSize = UA_LocalizedText_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 1+4+11+4+47);
- }
- END_TEST
- START_TEST(UA_Variant_calcSizeFixedSizeArrayShallReturnEncodingSize)
- {
- // given
- UA_Variant arg;
- arg.encodingMask = UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY;
- arg.vt = &UA_[UA_INT32];
- #define ARRAY_LEN 8
- arg.arrayLength = ARRAY_LEN;
- UA_Int32* data[ARRAY_LEN];
- arg.data = (void**) &data;
- // when
- UA_Int32 encodingSize = UA_Variant_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 1+4+ARRAY_LEN*4);
- #undef ARRAY_LEN
- }
- END_TEST
- START_TEST(UA_Variant_calcSizeVariableSizeArrayShallReturnEncodingSize)
- {
- // given
- UA_Variant arg;
- arg.encodingMask = UA_STRING_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY;
- arg.vt = &UA_[UA_STRING];
- #define ARRAY_LEN 3
- arg.arrayLength = ARRAY_LEN;
- UA_String s1 = {-1, UA_NULL };
- UA_String s2 = {3, (UA_Byte*) "PLT" };
- UA_String s3 = {47, UA_NULL };
- UA_String* data[ARRAY_LEN] = { &s1, &s2, &s3 };
- arg.data = (void**) &data;
- // when
- UA_Int32 encodingSize = UA_Variant_calcSize(&arg);
- // then
- ck_assert_int_eq(encodingSize, 1+4+(4+0)+(4+3)+(4+47));
- #undef ARRAY_LEN
- }
- END_TEST
- START_TEST(UA_Variant_calcSizeVariableSizeArrayWithNullPtrWillReturnWrongButLargeEnoughEncodingSize)
- {
- // given
- UA_Variant arg;
- arg.encodingMask = UA_STRING_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY;
- arg.vt = &UA_[UA_STRING];
- #define ARRAY_LEN 6
- arg.arrayLength = ARRAY_LEN;
- UA_String s1 = {-1, UA_NULL };
- UA_String s2 = {3, (UA_Byte*) "PLT" };
- UA_String s3 = {47, UA_NULL };
- UA_String* data[ARRAY_LEN] = { &s1, &s2, &s3 }; // will be filled with null-ptrs
- arg.data = (void**) &data;
- // when
- UA_Int32 encodingSize = UA_Variant_calcSize(&arg);
- // then
- ck_assert_int_ge(encodingSize, 1+4+(4+0)+(4+3)+(4+47)+(ARRAY_LEN-3)*(4+0));
- #undef ARRAY_LEN
- }
- END_TEST
- START_TEST(UA_Byte_decodeShallCopyAndAdvancePosition)
- {
- // given
- UA_Byte dst;
- UA_Byte data[]= { 0x08 };
- UA_ByteString src = {1, data};
- UA_Int32 pos = 0;
- // when
- UA_Int32 retval = UA_Byte_decodeBinary(&src, &pos, &dst);
- // then
- ck_assert_int_eq(retval, UA_SUCCESS);
- ck_assert_uint_eq(pos, 1);
- ck_assert_uint_eq(dst, 0x08);
- }
- END_TEST
- START_TEST(UA_Byte_decodeShallModifyOnlyCurrentPosition)
- {
- // given
- UA_Byte dst[] = { 0xFF, 0xFF, 0xFF };
- UA_Byte data[] = { 0x08 };
- UA_ByteString src = {1, data};
- UA_Int32 pos = 0;
- // when
- UA_Int32 retval = UA_Byte_decodeBinary(&src, &pos, &dst[1]);
- // then
- ck_assert_int_eq(retval, UA_SUCCESS);
- ck_assert_int_eq(pos, 1);
- ck_assert_uint_eq(dst[0], 0xFF);
- ck_assert_uint_eq(dst[1], 0x08);
- ck_assert_uint_eq(dst[2], 0xFF);
- }
- END_TEST
- START_TEST(UA_Int16_decodeShallAssumeLittleEndian)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = {
- 0x01,0x00, // 1
- 0x00,0x01 // 256
- };
- UA_ByteString src = { 4, data };
- // when
- UA_Int16 val_01_00, val_00_01;
- UA_Int32 retval = UA_Int16_decodeBinary(&src,&pos,&val_01_00);
- retval |= UA_Int16_decodeBinary(&src,&pos,&val_00_01);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(val_01_00,1);
- ck_assert_int_eq(val_00_01,256);
- ck_assert_int_eq(pos,4);
- }
- END_TEST
- START_TEST(UA_Int16_decodeShallRespectSign)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = {
- 0xFF,0xFF, // -1
- 0x00,0x80 // -32768
- };
- UA_ByteString src = {4,data};
- // when
- UA_Int16 val_ff_ff, val_00_80;
- UA_Int32 retval = UA_Int16_decodeBinary(&src,&pos,&val_ff_ff);
- retval |= UA_Int16_decodeBinary(&src,&pos,&val_00_80);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(val_ff_ff,-1);
- ck_assert_int_eq(val_00_80,-32768);
- }
- END_TEST
- START_TEST(UA_UInt16_decodeShallNotRespectSign)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = {
- 0xFF,0xFF, // (2^16)-1
- 0x00,0x80 // (2^15)
- };
- UA_ByteString src = {4,data};
- // when
- UA_UInt16 val_ff_ff, val_00_80;
- UA_Int32 retval = UA_UInt16_decodeBinary(&src,&pos,&val_ff_ff);
- retval |= UA_UInt16_decodeBinary(&src,&pos,&val_00_80);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(pos,4);
- ck_assert_uint_eq(val_ff_ff, (0x01 << 16)-1);
- ck_assert_uint_eq(val_00_80, (0x01 << 15));
- }
- END_TEST
- START_TEST(UA_Int32_decodeShallAssumeLittleEndian)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = {
- 0x01,0x00,0x00,0x00, // 1
- 0x00,0x01,0x00,0x00 // 256
- };
- UA_ByteString src = {8,data};
- // when
- UA_Int32 val_01_00, val_00_01;
- UA_Int32 retval = UA_Int32_decodeBinary(&src,&pos,&val_01_00);
- retval |= UA_Int32_decodeBinary(&src,&pos,&val_00_01);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(val_01_00,1);
- ck_assert_int_eq(val_00_01,256);
- ck_assert_int_eq(pos,8);
- }
- END_TEST
- START_TEST(UA_Int32_decodeShallRespectSign)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = {
- 0xFF,0xFF,0xFF,0xFF, // -1
- 0x00,0x80,0xFF,0xFF // -32768
- };
- UA_ByteString src = {8,data};
- // when
- UA_Int32 val_ff_ff, val_00_80;
- UA_Int32 retval = UA_Int32_decodeBinary(&src,&pos,&val_ff_ff);
- retval |= UA_Int32_decodeBinary(&src,&pos,&val_00_80);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(val_ff_ff,-1);
- ck_assert_int_eq(val_00_80,-32768);
- }
- END_TEST
- START_TEST(UA_UInt32_decodeShallNotRespectSign)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = {
- 0xFF,0xFF,0xFF,0xFF, // (2^32)-1
- 0x00,0x00,0x00,0x80 // (2^31)
- };
- UA_ByteString src = {8,data};
- // when
- UA_UInt32 val_ff_ff, val_00_80;
- UA_Int32 retval = UA_UInt32_decodeBinary(&src,&pos,&val_ff_ff);
- retval |= UA_UInt32_decodeBinary(&src,&pos,&val_00_80);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(pos,8);
- ck_assert_uint_eq(val_ff_ff, (UA_UInt32) ( (0x01LL << 32 ) - 1 ));
- ck_assert_uint_eq(val_00_80, (UA_UInt32) (0x01 << 31));
- }
- END_TEST
- START_TEST(UA_UInt64_decodeShallNotRespectSign)
- {
- // given
- UA_ByteString rawMessage;
- UA_UInt64 expectedVal = 0xFF;
- expectedVal = expectedVal << 56;
- UA_Byte mem[8] = {00,00,00,00,0x00,0x00,0x00,0xFF};
- rawMessage.data = mem;
- rawMessage.length = 8;
- UA_Int32 p = 0;
- UA_UInt64 val;
- // when
- UA_UInt64_decodeBinary(&rawMessage, &p, &val);
- // then
- ck_assert_uint_eq(val, expectedVal);
- }
- END_TEST
- START_TEST(UA_Int64_decodeShallRespectSign)
- {
- // given
- UA_ByteString rawMessage;
- UA_Int64 expectedVal = 0xFF;
- expectedVal = expectedVal << 56;
- UA_Byte mem[8] = {00,00,00,00,0x00,0x00,0x00,0xFF};
- rawMessage.data = mem;
- rawMessage.length = 8;
- UA_Int32 p = 0;
- UA_Int64 val;
- // when
- UA_Int64_decodeBinary(&rawMessage, &p, &val);
- //then
- ck_assert_uint_eq(val, expectedVal);
- }
- END_TEST
- START_TEST(UA_Float_decodeShallWorkOnExample)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = { 0x00,0x00,0xD0,0xC0 }; // -6.5
- UA_ByteString src = {4,data};
- UA_Float dst;
- // when
- UA_Int32 retval = UA_Float_decodeBinary(&src,&pos,&dst);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(pos,4);
- ck_assert(-6.5000001 < dst);
- ck_assert(dst < -6.49999999999);
- }
- END_TEST
- START_TEST(UA_Double_decodeShallGiveOne)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x3F }; // 1
- UA_ByteString src = {8,data}; // 1
- UA_Double dst;
- // when
- UA_Int32 retval = UA_Double_decodeBinary(&src,&pos,&dst);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(pos,8);
- ck_assert(0.9999999 < dst);
- ck_assert(dst < 1.00000000001);
- }
- END_TEST
- START_TEST(UA_Double_decodeShallGiveZero)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
- UA_ByteString src = {8,data}; // 1
- UA_Double dst;
- // when
- UA_Int32 retval = UA_Double_decodeBinary(&src,&pos,&dst);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(pos,8);
- ck_assert(-0.00000001 < dst);
- ck_assert(dst < 0.000000001);
- }
- END_TEST
- START_TEST(UA_Double_decodeShallGiveMinusTwo)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0 }; // -2
- UA_ByteString src = {8,data};
- UA_Double dst;
- // when
- UA_Int32 retval = UA_Double_decodeBinary(&src,&pos,&dst);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(pos,8);
- ck_assert(-1.9999999 > dst);
- ck_assert(dst > -2.00000000001);
- }
- END_TEST
- START_TEST(UA_String_decodeShallAllocateMemoryAndCopyString)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = {0x08,0x00,0x00,0x00,'A','C','P','L','T',' ','U','A',0xFF,0xFF,0xFF,0xFF,0xFF};
- UA_ByteString src = {16,data};
- UA_String dst;
- // when
- UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(dst.length,8);
- ck_assert_ptr_eq(dst.data,UA_alloc_lastptr);
- ck_assert_int_eq(dst.data[3],'L');
- // finally
- UA_String_deleteMembers(&dst);
- }
- END_TEST
- START_TEST(UA_String_decodeWithNegativeSizeShallNotAllocateMemoryAndNullPtr)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = {0xFF,0xFF,0xFF,0xFF,'A','C','P','L','T',' ','U','A',0xFF,0xFF,0xFF,0xFF,0xFF};
- UA_ByteString src = {16,data};
- UA_String dst;
- // when
- UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(dst.length,-1);
- ck_assert_ptr_eq(dst.data,UA_NULL);
- }
- END_TEST
- START_TEST(UA_String_decodeWithZeroSizeShallNotAllocateMemoryAndNullPtr)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = {0x00,0x00,0x00,0x00,'A','C','P','L','T',' ','U','A',0xFF,0xFF,0xFF,0xFF,0xFF};
- UA_ByteString src = {16,data};
- UA_String dst = { 2, (UA_Byte*) "XX" };
- // when
- UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(dst.length,-1); // shall we keep zero?
- ck_assert_ptr_eq(dst.data,UA_NULL);
- }
- END_TEST
- START_TEST(UA_NodeId_decodeTwoByteShallReadTwoBytesAndSetNamespaceToZero)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = { UA_NODEIDTYPE_TWOBYTE, 0x10 };
- UA_ByteString src = {2,data};
- UA_NodeId dst;
- // when
- UA_Int32 retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(pos,2);
- ck_assert_int_eq(dst.encodingByte, UA_NODEIDTYPE_TWOBYTE);
- ck_assert_int_eq(dst.identifier.numeric,16);
- ck_assert_int_eq(dst.namespace,0);
- }
- END_TEST
- START_TEST(UA_NodeId_decodeFourByteShallReadFourBytesAndRespectNamespace)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = { UA_NODEIDTYPE_FOURBYTE, 0x01, 0x00, 0x01 };
- UA_ByteString src = {4,data};
- UA_NodeId dst;
- // when
- UA_Int32 retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(pos,4);
- ck_assert_int_eq(dst.encodingByte, UA_NODEIDTYPE_FOURBYTE);
- ck_assert_int_eq(dst.identifier.numeric,256);
- ck_assert_int_eq(dst.namespace,1);
- }
- END_TEST
- START_TEST(UA_NodeId_decodeStringShallAllocateMemory)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[]= { UA_NODEIDTYPE_STRING, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 'P', 'L', 'T' };
- UA_ByteString src = {10,data};
- UA_NodeId dst;
- // when
- UA_Int32 retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(pos,10);
- ck_assert_int_eq(dst.encodingByte, UA_NODEIDTYPE_STRING);
- ck_assert_int_eq(dst.namespace,1);
- ck_assert_int_eq(dst.identifier.string.length,3);
- ck_assert_ptr_eq(dst.identifier.string.data,UA_alloc_lastptr);
- ck_assert_int_eq(dst.identifier.string.data[1],'L');
- // finally
- UA_NodeId_deleteMembers(&dst);
- }
- END_TEST
- START_TEST(UA_Variant_decodeWithOutArrayFlagSetShallSetVTAndAllocateMemoryForArray)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[] = { UA_INT32_NS0, 0xFF, 0x00, 0x00, 0x00};
- UA_ByteString src = {5,data};
- UA_Variant dst;
- // when
- UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(pos,5);
- ck_assert_uint_eq(dst.encodingMask, UA_INT32_NS0);
- ck_assert_ptr_eq(dst.vt, &UA_[UA_INT32]);
- ck_assert_int_eq(dst.arrayLength,1);
- ck_assert_ptr_ne(dst.data,UA_NULL);
- ck_assert_ptr_eq(dst.data[0],UA_alloc_lastptr);
- ck_assert_int_eq(*(UA_Int32*)dst.data[0],255);
- // finally
- UA_Variant_deleteMembers(&dst);
- }
- END_TEST
- START_TEST(UA_Variant_decodeWithArrayFlagSetShallSetVTAndAllocateMemoryForArray)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[]={ UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
- UA_ByteString src = {13,data};
- UA_Variant dst;
- // when
- UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- ck_assert_int_eq(pos,1+4+2*4);
- ck_assert_uint_eq(dst.encodingMask & UA_VARIANT_ENCODINGMASKTYPE_TYPEID_MASK, UA_INT32_NS0);
- ck_assert_uint_eq(dst.encodingMask & UA_VARIANT_ENCODINGMASKTYPE_ARRAY, UA_VARIANT_ENCODINGMASKTYPE_ARRAY);
- ck_assert_ptr_eq(dst.vt, &UA_[UA_INT32]);
- ck_assert_int_eq(dst.arrayLength,2);
- ck_assert_ptr_ne(dst.data,UA_NULL);
- ck_assert_ptr_eq(dst.data[1],UA_alloc_lastptr);
- ck_assert_int_eq(*((UA_Int32*)dst.data[0]),255);
- ck_assert_int_eq(*((UA_Int32*)dst.data[1]),-1);
- // finally
- UA_Variant_deleteMembers(&dst);
- }
- END_TEST
- START_TEST(UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[]= { UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
- UA_ByteString src = {13,data};
- UA_Variant dst;
- // when
- UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
- // then
- ck_assert_int_eq(retval,UA_SUCCESS);
- // finally - unfortunately we cannot express that not freeing three chunks is what we expect
- // UA_Variant_deleteMembers(&dst);
- }
- END_TEST
- START_TEST(UA_Variant_decodeWithTooSmallSourceShallReturnWithError)
- {
- // given
- UA_Int32 pos = 0;
- UA_Byte data[]= { UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
- UA_ByteString src = {4,data};
- UA_Variant dst;
- // when
- UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
- // then
- ck_assert_int_ne(retval,UA_SUCCESS);
- // finally - unfortunately we cannot express that not freeing three chunks is what we expect
- // UA_Variant_deleteMembers(&dst);
- }
- END_TEST
- START_TEST(UA_Byte_encode_test)
- {
- // given
- UA_Byte src;
- UA_Byte data[] = { 0x00, 0xFF };
- UA_ByteString dst = {2,data};
- UA_Int32 retval, pos = 0;
- ck_assert_uint_eq(dst.data[1], 0xFF);
- src = 8;
- retval = UA_Byte_encodeBinary(&src, &pos, &dst);
- ck_assert_uint_eq(dst.data[0], 0x08);
- ck_assert_uint_eq(dst.data[1], 0xFF);
- ck_assert_int_eq(pos, 1);
- ck_assert_int_eq(retval, UA_SUCCESS);
- // Test2
- // given
- src = 0xFF;
- dst.data[1] = 0x00;
- pos = 0;
- retval = UA_Byte_encodeBinary(&src, &pos, &dst);
- ck_assert_int_eq(dst.data[0], 0xFF);
- ck_assert_int_eq(dst.data[1], 0x00);
- ck_assert_int_eq(pos, 1);
- ck_assert_int_eq(retval, UA_SUCCESS);
- }
- END_TEST
- START_TEST(UA_UInt16_encodeNegativeShallEncodeLittleEndian)
- {
- // given
- UA_UInt16 src;
- UA_Byte data[] = { 0x55,0x55,
- 0x55,0x55
- };
- UA_ByteString dst = {4,data};
- UA_Int32 retval, pos = 0;
- // when test 1
- src = -1;
- retval = UA_UInt16_encodeBinary(&src, &pos, &dst);
- // then test 1
- ck_assert_int_eq(pos, 2);
- ck_assert_int_eq(dst.data[0], 0xFF);
- ck_assert_int_eq(dst.data[1], 0xFF);
- ck_assert_int_eq(retval, UA_SUCCESS);
- // when test 2
- src = -32768;
- retval = UA_UInt16_encodeBinary(&src, &pos, &dst);
- // then test 2
- ck_assert_int_eq(pos, 4);
- ck_assert_int_eq(dst.data[2], 0x00);
- ck_assert_int_eq(dst.data[3], 0x80);
- ck_assert_int_eq(retval, UA_SUCCESS);
- }
- END_TEST
- START_TEST(UA_UInt16_encodeShallEncodeLittleEndian)
- {
- // given
- UA_UInt16 src;
- UA_Byte data[] = { 0x55,0x55,
- 0x55,0x55
- };
- UA_ByteString dst = {4,data};
- UA_Int32 retval, pos = 0;
- // when test 1
- src = 0;
- retval = UA_UInt16_encodeBinary(&src, &pos, &dst);
- // then test 1
- ck_assert_int_eq(pos, 2);
- ck_assert_int_eq(dst.data[0], 0x00);
- ck_assert_int_eq(dst.data[1], 0x00);
- ck_assert_int_eq(retval, UA_SUCCESS);
- // when test 2
- src = 32767;
- retval = UA_UInt16_encodeBinary(&src, &pos, &dst);
- // then test 2
- ck_assert_int_eq(pos, 4);
- ck_assert_int_eq(dst.data[2], 0xFF);
- ck_assert_int_eq(dst.data[3], 0x7F);
- ck_assert_int_eq(retval, UA_SUCCESS);
- }
- END_TEST
- START_TEST(UA_UInt32_encodeShallEncodeLittleEndian)
- {
- // given
- UA_UInt32 src;
- UA_Byte data[] = { 0x55,0x55,0x55,0x55,
- 0x55,0x55,0x55,0x55
- };
- UA_ByteString dst = {8,data};
- UA_Int32 retval, pos = 0;
- // when test 1
- src = -1;
- retval = UA_UInt32_encodeBinary(&src, &pos, &dst);
- // then test 1
- ck_assert_int_eq(pos, 4);
- ck_assert_int_eq(dst.data[0], 0xFF);
- ck_assert_int_eq(dst.data[1], 0xFF);
- ck_assert_int_eq(dst.data[2], 0xFF);
- ck_assert_int_eq(dst.data[3], 0xFF);
- ck_assert_int_eq(retval, UA_SUCCESS);
- // when test 2
- src = 0x0101FF00;
- retval = UA_UInt32_encodeBinary(&src, &pos, &dst);
- // then test 2
- ck_assert_int_eq(pos, 8);
- ck_assert_int_eq(dst.data[4], 0x00);
- ck_assert_int_eq(dst.data[5], 0xFF);
- ck_assert_int_eq(dst.data[6], 0x01);
- ck_assert_int_eq(dst.data[7], 0x01);
- ck_assert_int_eq(retval, UA_SUCCESS);
- }
- END_TEST
- START_TEST(UA_Int32_encodeShallEncodeLittleEndian)
- {
- // given
- UA_Int32 src;
- UA_Byte data[] = { 0x55,0x55,0x55,0x55,
- 0x55,0x55,0x55,0x55
- };
- UA_ByteString dst = {8,data};
- UA_Int32 retval, pos = 0;
- // when test 1
- src = 1;
- retval = UA_Int32_encodeBinary(&src, &pos, &dst);
- // then test 1
- ck_assert_int_eq(pos, 4);
- ck_assert_int_eq(dst.data[0], 0x01);
- ck_assert_int_eq(dst.data[1], 0x00);
- ck_assert_int_eq(dst.data[2], 0x00);
- ck_assert_int_eq(dst.data[3], 0x00);
- ck_assert_int_eq(retval, UA_SUCCESS);
- // when test 2
- src = 0x7FFFFFFF;
- retval = UA_Int32_encodeBinary(&src, &pos, &dst);
- // then test 2
- ck_assert_int_eq(pos, 8);
- ck_assert_int_eq(dst.data[4], 0xFF);
- ck_assert_int_eq(dst.data[5], 0xFF);
- ck_assert_int_eq(dst.data[6], 0xFF);
- ck_assert_int_eq(dst.data[7], 0x7F);
- ck_assert_int_eq(retval, UA_SUCCESS);
- }
- END_TEST
- START_TEST(UA_Int32_encodeNegativeShallEncodeLittleEndian)
- {
- // given
- UA_Int32 src;
- UA_Byte data[] = { 0x55,0x55,0x55,0x55,
- 0x55,0x55,0x55,0x55
- };
- UA_ByteString dst = {8,data};
- UA_Int32 retval, pos = 0;
- // when test 1
- src = -1;
- retval = UA_Int32_encodeBinary(&src, &pos, &dst);
- // then test 1
- ck_assert_int_eq(pos, 4);
- ck_assert_int_eq(dst.data[0], 0xFF);
- ck_assert_int_eq(dst.data[1], 0xFF);
- ck_assert_int_eq(dst.data[2], 0xFF);
- ck_assert_int_eq(dst.data[3], 0xFF);
- ck_assert_int_eq(retval, UA_SUCCESS);
- }
- END_TEST
- START_TEST(UA_UInt64_encodeShallWorkOnExample)
- {
- // given
- UA_UInt64 src;
- UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
- 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
- };
- UA_ByteString dst = {16,data};
- UA_Int32 retval, pos = 0;
- // when test 1
- src = -1;
- retval = UA_UInt64_encodeBinary(&src, &pos, &dst);
- // then test 1
- ck_assert_int_eq(pos, 8);
- ck_assert_int_eq(dst.data[0], 0xFF);
- ck_assert_int_eq(dst.data[1], 0xFF);
- ck_assert_int_eq(dst.data[2], 0xFF);
- ck_assert_int_eq(dst.data[3], 0xFF);
- ck_assert_int_eq(dst.data[4], 0xFF);
- ck_assert_int_eq(dst.data[5], 0xFF);
- ck_assert_int_eq(dst.data[6], 0xFF);
- ck_assert_int_eq(dst.data[7], 0xFF);
- ck_assert_int_eq(retval, UA_SUCCESS);
- // when test 2
- src = 0x7F0033AA44EE6611;
- retval = UA_UInt64_encodeBinary(&src, &pos, &dst);
- // then test 2
- ck_assert_int_eq(pos, 16);
- ck_assert_int_eq(dst.data[8], 0x11);
- ck_assert_int_eq(dst.data[9], 0x66);
- ck_assert_int_eq(dst.data[10], 0xEE);
- ck_assert_int_eq(dst.data[11], 0x44);
- ck_assert_int_eq(dst.data[12], 0xAA);
- ck_assert_int_eq(dst.data[13], 0x33);
- ck_assert_int_eq(dst.data[14], 0x00);
- ck_assert_int_eq(dst.data[15], 0x7F);
- ck_assert_int_eq(retval, UA_SUCCESS);
- }
- END_TEST
- START_TEST(UA_Int64_encodeShallEncodeLittleEndian)
- {
- // given
- UA_Int64 src;
- UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
- 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
- };
- UA_ByteString dst = {16,data};
- UA_Int32 retval, pos = 0;
- // when test 1
- src = 0x7F0033AA44EE6611;
- retval = UA_Int64_encodeBinary(&src, &pos, &dst);
- // then test 1
- ck_assert_int_eq(pos, 8);
- ck_assert_int_eq(dst.data[0], 0x11);
- ck_assert_int_eq(dst.data[1], 0x66);
- ck_assert_int_eq(dst.data[2], 0xEE);
- ck_assert_int_eq(dst.data[3], 0x44);
- ck_assert_int_eq(dst.data[4], 0xAA);
- ck_assert_int_eq(dst.data[5], 0x33);
- ck_assert_int_eq(dst.data[6], 0x00);
- ck_assert_int_eq(dst.data[7], 0x7F);
- ck_assert_int_eq(retval, UA_SUCCESS);
- }
- END_TEST
- START_TEST(UA_Int64_encodeNegativeShallEncodeLittleEndian)
- {
- // given
- UA_Int64 src;
- UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
- 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
- };
- UA_ByteString dst = {16,data};
- UA_Int32 retval, pos = 0;
- // when test 1
- src = -1;
- retval = UA_Int64_encodeBinary(&src, &pos, &dst);
- // then test 1
- ck_assert_int_eq(pos, 8);
- ck_assert_int_eq(dst.data[0], 0xFF);
- ck_assert_int_eq(dst.data[1], 0xFF);
- ck_assert_int_eq(dst.data[2], 0xFF);
- ck_assert_int_eq(dst.data[3], 0xFF);
- ck_assert_int_eq(dst.data[4], 0xFF);
- ck_assert_int_eq(dst.data[5], 0xFF);
- ck_assert_int_eq(dst.data[6], 0xFF);
- ck_assert_int_eq(dst.data[7], 0xFF);
- ck_assert_int_eq(retval, UA_SUCCESS);
- }
- END_TEST
- START_TEST(UA_Float_encodeShallWorkOnExample)
- {
- // given
- UA_Float src;
- UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
- 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
- };
- UA_ByteString dst = {16,data};
- UA_Int32 retval, pos = 0;
- // when test 1
- src = -6.5;
- retval = UA_Float_encodeBinary(&src, &pos, &dst);
- // then test 1
- ck_assert_int_eq(pos, 4);
- ck_assert_int_eq(dst.data[2], 0xD0);
- ck_assert_int_eq(dst.data[3], 0xC0);
- ck_assert_int_eq(retval, UA_SUCCESS);
- }
- END_TEST
- /*START_TEST(UA_Double_encodeShallWorkOnExample)
- {
- // given
- UA_Double src;
- UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
- 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
- };
- UA_ByteString dst = {16,data};
- UA_Int32 retval, pos = 0;
- // when test 1
- src = -6.5;
- retval = UA_Double_encodeBinary(&src, &pos, &dst);
- // then test 1
- ck_assert_int_eq(pos, 8);
- ck_assert_int_eq(dst.data[6], 0xD0);
- ck_assert_int_eq(dst.data[7], 0xC0);
- ck_assert_int_eq(retval, UA_SUCCESS);
- }
- END_TEST*/
- START_TEST(UA_String_encodeShallWorkOnExample)
- {
- // given
- UA_String src;
- src.length = 11;
- UA_Byte mem[11] = "ACPLT OPCUA";
- src.data = mem;
- UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
- 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
- 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
- };
- UA_ByteString dst = {24,data};
- UA_Int32 retval, pos = 0;
- // when
- retval = UA_String_encodeBinary(&src, &pos, &dst);
- // then
- ck_assert_int_eq(pos, sizeof(UA_Int32)+11);
- ck_assert_int_eq(dst.data[0], 11);
- ck_assert_int_eq(dst.data[sizeof(UA_Int32)+0], 'A');
- ck_assert_int_eq(dst.data[sizeof(UA_Int32)+1], 'C');
- ck_assert_int_eq(dst.data[sizeof(UA_Int32)+2], 'P');
- ck_assert_int_eq(dst.data[sizeof(UA_Int32)+3], 'L');
- ck_assert_int_eq(dst.data[sizeof(UA_Int32)+4], 'T');
- ck_assert_int_eq(dst.data[sizeof(UA_Int32)+5], 0x20); //Space
- ck_assert_int_eq(retval, UA_SUCCESS);
- }
- END_TEST
- START_TEST(UA_DataValue_encodeShallWorkOnExampleWithoutVariant)
- {
- // given
- UA_DataValue src;
- src.serverTimestamp = 80;
- src.encodingMask = UA_DATAVALUE_ENCODINGMASK_SERVERTIMESTAMP; //Only the sourcePicoseconds
- UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
- 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
- 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
- };
- UA_ByteString dst = {24,data};
- UA_Int32 retval, pos = 0;
- // when
- retval = UA_DataValue_encodeBinary(&src, &pos, &dst);
- // then
- ck_assert_int_eq(pos, 9);// represents the length
- ck_assert_int_eq(dst.data[0], 0x08); // encodingMask
- ck_assert_int_eq(dst.data[1], 80); // 8 Byte serverTimestamp
- ck_assert_int_eq(dst.data[2], 0);
- ck_assert_int_eq(dst.data[3], 0);
- ck_assert_int_eq(dst.data[4], 0);
- ck_assert_int_eq(dst.data[5], 0);
- ck_assert_int_eq(dst.data[6], 0);
- ck_assert_int_eq(dst.data[7], 0);
- ck_assert_int_eq(dst.data[8], 0);
- ck_assert_int_eq(retval, UA_SUCCESS);
- }
- END_TEST
- START_TEST(UA_DataValue_encodeShallWorkOnExampleWithVariant)
- {
- // given
- UA_DataValue src;
- src.serverTimestamp = 80;
- src.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT | UA_DATAVALUE_ENCODINGMASK_SERVERTIMESTAMP; //Variant & SourvePicoseconds
- src.value.vt = &UA_[UA_INT32];
- src.value.arrayLength = 0;
- src.value.encodingMask = UA_INT32_NS0;
- UA_Int32 vdata = 45;
- UA_Int32* pvdata = &vdata;
- src.value.data = (void**) &pvdata;
- UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
- 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
- 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
- };
- UA_ByteString dst = {24,data};
- UA_Int32 retval, pos = 0;
- // when
- retval = UA_DataValue_encodeBinary(&src, &pos, &dst);
- // then
- ck_assert_int_eq(pos, 1+(1+4)+8);// represents the length
- ck_assert_int_eq(dst.data[0], 0x08 | 0x01); // encodingMask
- ck_assert_int_eq(dst.data[1], 0x06); // Variant's Encoding Mask - INT32
- ck_assert_int_eq(dst.data[2], 45); // the single value
- ck_assert_int_eq(dst.data[3], 0);
- ck_assert_int_eq(dst.data[4], 0);
- ck_assert_int_eq(dst.data[5], 0);
- ck_assert_int_eq(dst.data[6], 80); // the server timestamp
- ck_assert_int_eq(dst.data[7], 0);
- ck_assert_int_eq(retval, UA_SUCCESS);
- }
- END_TEST
- START_TEST(UA_DateTime_toStructShallWorkOnExample)
- {
- // given
- UA_DateTime src = 13974671891234567;
- //1397467189... is Mon, 14 Apr 2014 09:19:49 GMT
- //...1234567 are the milli-, micro- and nanoseconds
- UA_DateTimeStruct dst;
- // when
- dst = UA_DateTime_toStruct(src);
- // then
- ck_assert_int_eq(dst.nanoSec, 700);
- ck_assert_int_eq(dst.microSec, 456);
- ck_assert_int_eq(dst.milliSec, 123);
- ck_assert_int_eq(dst.sec, 49);
- ck_assert_int_eq(dst.min, 19);
- ck_assert_int_eq(dst.hour, 9);
- ck_assert_int_eq(dst.day, 14);
- ck_assert_int_eq(dst.mounth, 4);
- ck_assert_int_eq(dst.year, 2014);
- }
- END_TEST
- START_TEST(UA_DateTime_toStringShallWorkOnExample)
- {
- // given
- UA_DateTime src = 13974671891234567;
- //1397467189... is Mon, 14 Apr 2014 09:19:49 GMT
- //...1234567 are the milli-, micro- and nanoseconds
- char buf[80] = "80";
- UA_Byte *byteBuf = (UA_Byte*)buf;
- UA_String dst = {80, byteBuf};
- // when
- UA_DateTime_toString(src, &dst);
- // then
- ck_assert_int_eq(dst.length, 80);
- char df = 'a';
- UA_String_printf(&df, &dst);
- ck_assert_int_eq(dst.data[0], ' ');
- ck_assert_int_eq(dst.data[1], '4');
- ck_assert_int_eq(dst.data[2], '/');
- ck_assert_int_eq(dst.data[3], '1');
- ck_assert_int_eq(dst.data[4], '4');
- }
- END_TEST
- START_TEST(UA_ExtensionObject_copyShallWorkOnExample)
- {
- UA_ExtensionObject *value = UA_NULL;
- UA_ExtensionObject *valueCopied = UA_NULL;
- UA_Int32 i = 0;
- // given
- UA_Byte data[3] = {1,2,3};
- UA_ExtensionObject_new(&value);
- UA_ExtensionObject_new(&valueCopied);
- // empty ExtensionObject, handcoded
- // when
- value->typeId.encodingByte = UA_NODEIDTYPE_TWOBYTE;
- value->typeId.identifier.numeric = 0;
- value->encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_NOBODYISENCODED;
- value->encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING;
- value->body.data = data;
- value->body.length = 3;
- //when
- UA_ExtensionObject_copy(value,valueCopied);
- for(i=0; i<3; i++){
- ck_assert_int_eq(valueCopied->body.data[i],value->body.data[i]);
- }
- ck_assert_int_eq(valueCopied->encoding, value->encoding);
- ck_assert_int_eq(valueCopied->typeId.encodingByte,value->typeId.encodingByte);
- ck_assert_int_eq(valueCopied->typeId.identifier.numeric,value->typeId.identifier.numeric);
- //finally
- UA_free(value);
- UA_free(valueCopied);
- }
- END_TEST
- START_TEST(UA_Array_copyByteArrayShallWorkOnExample)
- {
- //given
- UA_String testString;
- UA_Byte* *srcArray = UA_NULL;
- UA_Byte** dstArray;
- UA_Int32 size = 5;
- UA_Int32 i = 0;
- testString.data = UA_NULL;
- UA_alloc((void**)&testString.data, size);
- UA_alloc((void*)&srcArray,sizeof(UA_Byte*)*5);
- testString.data[0] = 'O';
- testString.data[1] = 'P';
- testString.data[2] = 'C';
- testString.data[3] = 'U';
- testString.data[4] = 'A';
- testString.length = 5;
- srcArray[0] = &(testString.data[0]);
- srcArray[1] = &testString.data[1];
- srcArray[2] = &testString.data[2];
- srcArray[3] = &testString.data[3];
- srcArray[4] = &testString.data[4];
- //when
- UA_Array_copy((const void* const*)srcArray,5,UA_BYTE,(void***)&dstArray);
- //then
- for(i=0;i<size;i++){
- ck_assert_int_eq(*srcArray[i], *dstArray[i]);
- }
- //finally
- UA_free(*srcArray);
- UA_free(*dstArray);
- }
- END_TEST
- START_TEST(UA_Array_copyUA_StringShallWorkOnExample)
- {
- // given
- UA_Int32 i,j;
- UA_String **srcArray; UA_Array_new((void***)&srcArray,3,UA_STRING);
- UA_String **dstArray;
- UA_String_copycstring("open",srcArray[0]);
- UA_String_copycstring("62541",srcArray[1]);
- UA_String_copycstring("opc ua",srcArray[2]);
- //when
- UA_Array_copy((void const*const*)srcArray,3,UA_STRING,(void ***)&dstArray);
- //then
- for(i=0;i<3;i++){
- for(j=0;j<3;j++){
- ck_assert_int_eq(srcArray[i]->data[j], dstArray[i]->data[j]);
- }
- ck_assert_int_eq(srcArray[i]->length, dstArray[i]->length);
- }
- //finally
- UA_free(*srcArray);
- UA_free(*dstArray);
- }
- END_TEST
- START_TEST(UA_DiagnosticInfo_copyShallWorkOnExample)
- {
- //given
- UA_DiagnosticInfo *value = UA_NULL;
- UA_DiagnosticInfo *innerValue = UA_NULL;
- UA_DiagnosticInfo *copiedValue = UA_NULL;
- UA_String testString;
- UA_Int32 size = 5;
- UA_Int32 i = 0;
- testString.data = UA_NULL;
- UA_alloc((void**)&testString.data,size);
- testString.data[0] = 'O';
- testString.data[1] = 'P';
- testString.data[2] = 'C';
- testString.data[3] = 'U';
- testString.data[4] = 'A';
- testString.length = size;
- UA_DiagnosticInfo_new(&value);
- UA_DiagnosticInfo_new(&innerValue);
- value->encodingMask |= UA_DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO;
- value->innerDiagnosticInfo = innerValue;
- UA_alloc((void**)&copiedValue,UA_DiagnosticInfo_calcSize(UA_NULL));
- value->additionalInfo.length = testString.length;
- value->additionalInfo.data = testString.data;
- //when
- UA_DiagnosticInfo_copy(value, copiedValue);
- //then
- for(i=0; i<size; i++){
- ck_assert_int_eq(copiedValue->additionalInfo.data[i],value->additionalInfo.data[i]);
- }
- ck_assert_int_eq(copiedValue->additionalInfo.length, value->additionalInfo.length);
- ck_assert_int_eq(copiedValue->encodingMask, value->encodingMask);
- ck_assert_int_eq(copiedValue->innerDiagnosticInfo->locale,value->innerDiagnosticInfo->locale);
- ck_assert_int_eq(copiedValue->innerStatusCode,value->innerStatusCode);
- ck_assert_int_eq(copiedValue->locale,value->locale);
- ck_assert_int_eq(copiedValue->localizedText,value->localizedText);
- ck_assert_int_eq(copiedValue->namespaceUri,value->namespaceUri);
- ck_assert_int_eq(copiedValue->symbolicId,value->symbolicId);
- //finally
- UA_free(copiedValue);
- UA_free(value);
- }
- END_TEST
- START_TEST(UA_Variant_copyShallWorkOnSingleValueExample)
- {
- //given
- UA_Variant *value = UA_NULL;
- UA_Variant *copiedValue = UA_NULL;
- UA_Int32 i = 0;
- UA_String testString;
- UA_String* ptestString;
- UA_String* pCopiedString;
- testString.length = 5;
- UA_alloc((void**)&(testString.data),testString.length);
- testString.data[0] = 'O';
- testString.data[1] = 'P';
- testString.data[2] = 'C';
- testString.data[3] = 'U';
- testString.data[4] = 'A';
- UA_Variant_new(&value);
- UA_Variant_new(&copiedValue);
- ptestString = &testString;
- value->data = (void**)&ptestString;
- value->encodingMask |= UA_STRING_NS0;
- //value->encodingMask |= UA_VARIANT_ENCODINGMASKTYPE_DIMENSIONS;
- //when
- UA_Variant_copy(value,copiedValue);
- //then
- pCopiedString = *(UA_String**)copiedValue->data;
- for(i=0;i<3;i++){
- ck_assert_int_eq(pCopiedString->data[i], pCopiedString->data[i]);
- }
- ck_assert_int_eq(pCopiedString->length, pCopiedString->length);
- ck_assert_int_eq(value->encodingMask,copiedValue->encodingMask);
- ck_assert_int_eq(value->arrayDimensionsLength, copiedValue->arrayDimensionsLength);
- ck_assert_int_eq(value->arrayLength, copiedValue->arrayLength);
- //finally
- UA_free(value);
- UA_free(copiedValue);
- }
- END_TEST
- START_TEST(UA_Variant_copyShallWorkOn1DArrayExample)
- {
- // given
- UA_Variant *value = UA_NULL;
- UA_Variant *copiedValue = UA_NULL;
- UA_Int32 *dimensions;
- UA_Int32 i,j,i1,i2;
- UA_String **srcArray; UA_Array_new((void***)&srcArray,3,UA_STRING);
- UA_alloc((void**)&dimensions,UA_Int32_calcSize(UA_NULL));
- UA_String_copycstring("__open",srcArray[0]);
- UA_String_copycstring("_62541",srcArray[1]);
- UA_String_copycstring("opc ua",srcArray[2]);
- dimensions[0]=3;
- UA_Variant_new(&value);
- UA_Variant_new(&copiedValue);
- value->arrayLength = 3;
- value->data = (void**)srcArray;
- value->arrayDimensionsLength = 1;
- value->arrayDimensions = &dimensions;
- value->encodingMask |= UA_VARIANT_ENCODINGMASKTYPE_ARRAY;
- value->encodingMask |= UA_STRING_NS0;
- value->encodingMask |= UA_VARIANT_ENCODINGMASKTYPE_DIMENSIONS;
- //when
- UA_Variant_copy(value,copiedValue);
- //then
- i1 = *(value->arrayDimensions)[0],
- i2 = *(copiedValue->arrayDimensions)[0];
- ck_assert_int_eq(i1,i2);
- for(i=0;i<3;i++){
- for(j=0;j<6;j++){
- ck_assert_int_eq(((UA_String*)(value->data[i]))->data[j],((UA_String*)(copiedValue->data[i]))->data[j]);
- }
- ck_assert_int_eq(((UA_String*)(value->data[i]))->length,((UA_String*)(copiedValue->data[i]))->length);
- }
- ck_assert_int_eq(((UA_String*)(copiedValue->data[0]))->data[2],'o');
- ck_assert_int_eq(((UA_String*)(copiedValue->data[0]))->data[3],'p');
- ck_assert_int_eq(value->encodingMask,copiedValue->encodingMask);
- ck_assert_int_eq(value->arrayDimensionsLength, copiedValue->arrayDimensionsLength);
- ck_assert_int_eq(value->arrayLength, copiedValue->arrayLength);
- //finally
- UA_free(value);
- UA_free(copiedValue);
- }
- END_TEST
- START_TEST(UA_Variant_copyShallWorkOn2DArrayExample)
- {
- // given
- UA_Variant *value = UA_NULL;
- UA_Variant *copiedValue = UA_NULL;
- UA_Int32 **dimensions;
- UA_Int32 i,i1,i2;
- UA_Int32 dim1,dim2;
- UA_Int32 **srcArray;
- UA_Array_new((void***)&srcArray,6,UA_INT32);
- dim1 = 3;
- dim2 = 2;
- *srcArray[0] = 0;
- *srcArray[1] = 1;
- *srcArray[2] = 2;
- *srcArray[3] = 3;
- *srcArray[4] = 4;
- *srcArray[5] = 5;
- UA_Array_new((void***)&dimensions,2,UA_INT32);
- *(dimensions)[0] = dim1;
- *(dimensions)[1] = dim2;
- UA_Variant_new(&value);
- UA_Variant_new(&copiedValue);
- value->arrayLength = 6;
- value->data = (void**)srcArray;
- value->arrayDimensionsLength = 2;
- value->arrayDimensions = dimensions;
- value->encodingMask |= UA_VARIANT_ENCODINGMASKTYPE_ARRAY;
- value->encodingMask |= UA_INT32_NS0;
- value->encodingMask |= UA_VARIANT_ENCODINGMASKTYPE_DIMENSIONS;
- //when
- UA_Variant_copy(value, copiedValue);
- //then
- //1st dimension
- i1 = *(value->arrayDimensions)[0],
- i2 = *(copiedValue->arrayDimensions)[0];
- ck_assert_int_eq(i1,i2);
- ck_assert_int_eq(i1, dim1);
- //2nd dimension
- i1 = *(value->arrayDimensions)[1];
- i2 = *(copiedValue->arrayDimensions)[1];
- ck_assert_int_eq(i1,i2);
- ck_assert_int_eq(i1, dim2);
- for(i=0;i<6;i++){
- i1 = *((UA_Int32*)(value->data[i]));
- i2 = *((UA_Int32*)(copiedValue->data[i]));
- ck_assert_int_eq(i1,i2);
- ck_assert_int_eq(i2,i);
- }
- ck_assert_int_eq(value->encodingMask,copiedValue->encodingMask);
- ck_assert_int_eq(value->arrayDimensionsLength, copiedValue->arrayDimensionsLength);
- ck_assert_int_eq(value->arrayLength, copiedValue->arrayLength);
- //finally
- UA_free(value);
- UA_free(copiedValue);
- }
- END_TEST
- Suite *testSuite_builtin(void)
- {
- Suite *s = suite_create("Built-in Data Types 62541-6 Table 1");
- TCase *tc_calcSize = tcase_create("calcSize");
- tcase_add_test(tc_calcSize, UA_Boolean_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_SByte_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_Byte_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_Int16_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_UInt16_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_Int32_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_UInt32_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_Int64_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_UInt64_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_Float_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_Double_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_String_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_DateTime_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_Guid_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_ByteString_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_XmlElement_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_NodeId_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_StatusCode_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_QualifiedName_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_ExtensionObject_calcSizeShallWorkOnExample);
- tcase_add_test(tc_calcSize, UA_ExtensionObject_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_DataValue_calcSizeShallWorkOnExample);
- tcase_add_test(tc_calcSize, UA_DataValue_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_Variant_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_DiagnosticInfo_calcSizeShallWorkOnExample);
- tcase_add_test(tc_calcSize, UA_DiagnosticInfo_calcSizeWithNullArgumentShallReturnStorageSize);
- tcase_add_test(tc_calcSize, UA_String_calcSizeShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_String_calcSizeWithNegativLengthShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_String_calcSizeWithNegativLengthAndValidPointerShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_String_calcSizeWithZeroLengthShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_String_calcSizeWithZeroLengthAndValidPointerShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingTwoByteShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingFourByteShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringNegativLengthShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringZeroLengthShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeEncodingStringAndServerIndexShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeEncodingStringAndNamespaceUriShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_Guid_calcSizeShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_Guid_calcSizeShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeTextOnlyShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeLocaleOnlyShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeTextAndLocaleShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_Variant_calcSizeFixedSizeArrayShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_Variant_calcSizeVariableSizeArrayShallReturnEncodingSize);
- tcase_add_test(tc_calcSize, UA_Variant_calcSizeVariableSizeArrayWithNullPtrWillReturnWrongButLargeEnoughEncodingSize);
- tcase_add_test(tc_calcSize, UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem);
- suite_add_tcase(s,tc_calcSize);
- TCase *tc_decode = tcase_create("decode");
- tcase_add_test(tc_decode, UA_Byte_decodeShallCopyAndAdvancePosition);
- tcase_add_test(tc_decode, UA_Byte_decodeShallModifyOnlyCurrentPosition);
- tcase_add_test(tc_decode, UA_Int16_decodeShallAssumeLittleEndian);
- tcase_add_test(tc_decode, UA_Int16_decodeShallRespectSign);
- tcase_add_test(tc_decode, UA_UInt16_decodeShallNotRespectSign);
- tcase_add_test(tc_decode, UA_Int32_decodeShallAssumeLittleEndian);
- tcase_add_test(tc_decode, UA_Int32_decodeShallRespectSign);
- tcase_add_test(tc_decode, UA_UInt32_decodeShallNotRespectSign);
- tcase_add_test(tc_decode, UA_UInt64_decodeShallNotRespectSign);
- tcase_add_test(tc_decode, UA_Int64_decodeShallRespectSign);
- tcase_add_test(tc_decode, UA_Float_decodeShallWorkOnExample);
- tcase_add_test(tc_decode, UA_Double_decodeShallGiveOne);
- tcase_add_test(tc_decode, UA_Double_decodeShallGiveZero);
- tcase_add_test(tc_decode, UA_Double_decodeShallGiveMinusTwo);
- tcase_add_test(tc_decode, UA_Byte_encode_test);
- tcase_add_test(tc_decode, UA_String_decodeShallAllocateMemoryAndCopyString);
- tcase_add_test(tc_decode, UA_String_decodeWithNegativeSizeShallNotAllocateMemoryAndNullPtr);
- tcase_add_test(tc_decode, UA_String_decodeWithZeroSizeShallNotAllocateMemoryAndNullPtr);
- tcase_add_test(tc_decode, UA_NodeId_decodeTwoByteShallReadTwoBytesAndSetNamespaceToZero);
- tcase_add_test(tc_decode, UA_NodeId_decodeFourByteShallReadFourBytesAndRespectNamespace);
- tcase_add_test(tc_decode, UA_NodeId_decodeStringShallAllocateMemory);
- tcase_add_test(tc_decode, UA_Variant_decodeWithOutArrayFlagSetShallSetVTAndAllocateMemoryForArray);
- tcase_add_test(tc_decode, UA_Variant_decodeWithArrayFlagSetShallSetVTAndAllocateMemoryForArray);
- tcase_add_test(tc_decode, UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem);
- tcase_add_test(tc_decode, UA_Variant_decodeWithTooSmallSourceShallReturnWithError);
- suite_add_tcase(s,tc_decode);
- TCase *tc_encode = tcase_create("encode");
- tcase_add_test(tc_encode, UA_Byte_encode_test);
- tcase_add_test(tc_encode, UA_UInt16_encodeNegativeShallEncodeLittleEndian);
- tcase_add_test(tc_encode, UA_UInt16_encodeShallEncodeLittleEndian);
- tcase_add_test(tc_encode, UA_UInt32_encodeShallEncodeLittleEndian);
- tcase_add_test(tc_encode, UA_Int32_encodeShallEncodeLittleEndian);
- tcase_add_test(tc_encode, UA_Int32_encodeNegativeShallEncodeLittleEndian);
- tcase_add_test(tc_encode, UA_UInt64_encodeShallWorkOnExample);
- tcase_add_test(tc_encode, UA_Int64_encodeNegativeShallEncodeLittleEndian);
- tcase_add_test(tc_encode, UA_Int64_encodeShallEncodeLittleEndian);
- tcase_add_test(tc_encode, UA_Float_encodeShallWorkOnExample);
- //tcase_add_test(tc_encode, UA_Double_encodeShallWorkOnExample);
- tcase_add_test(tc_encode, UA_String_encodeShallWorkOnExample);
- tcase_add_test(tc_encode, UA_DataValue_encodeShallWorkOnExampleWithoutVariant);
- tcase_add_test(tc_encode, UA_DataValue_encodeShallWorkOnExampleWithVariant);
- suite_add_tcase(s,tc_encode);
- TCase *tc_convert = tcase_create("convert");
- tcase_add_test(tc_convert, UA_DateTime_toStructShallWorkOnExample);
- tcase_add_test(tc_convert, UA_DateTime_toStringShallWorkOnExample);
- suite_add_tcase(s,tc_convert);
- TCase *tc_copy = tcase_create("copy");
- tcase_add_test(tc_copy,UA_Array_copyByteArrayShallWorkOnExample);
- tcase_add_test(tc_copy,UA_Array_copyUA_StringShallWorkOnExample);
- tcase_add_test(tc_copy, UA_ExtensionObject_copyShallWorkOnExample);
- tcase_add_test(tc_copy, UA_Variant_copyShallWorkOnSingleValueExample);
- tcase_add_test(tc_copy, UA_Variant_copyShallWorkOn1DArrayExample);
- tcase_add_test(tc_copy, UA_Variant_copyShallWorkOn2DArrayExample);
- tcase_add_test(tc_copy, UA_DiagnosticInfo_copyShallWorkOnExample);
- suite_add_tcase(s,tc_copy);
- return s;
- }
- int main (void)
- {
- int number_failed = 0;
- Suite* s;
- SRunner* sr;
- s = testSuite_builtin();
- sr = srunner_create(s);
- srunner_run_all(sr,CK_NORMAL);
- number_failed += srunner_ntests_failed(sr);
- srunner_free(sr);
- return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
- }
|