12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826 |
- #include <stdio.h>
- #include <stdlib.h>
- #include "ua_types.h"
- #include "ua_types_encoding_binary.h"
- #include "ua_transport.h"
- #include "check.h"
- START_TEST(UA_Boolean_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_Boolean *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_Boolean_calcSizeBinary(arg);
- // then
- ck_assert_int_eq(storageSize, 1);
- }
- END_TEST
- START_TEST(UA_SByte_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_SByte *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_SByte_calcSizeBinary(arg);
- // then
- ck_assert_int_ge(storageSize, 1);
- }
- END_TEST
- START_TEST(UA_Byte_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_Byte *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_Byte_calcSizeBinary(arg);
- // then
- ck_assert_int_ge(storageSize, 1);
- }
- END_TEST
- START_TEST(UA_Int16_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_Int16 *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_Int16_calcSizeBinary(arg);
- // then
- ck_assert_int_ge(storageSize, 2);
- }
- END_TEST
- START_TEST(UA_UInt16_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_UInt16 *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_UInt16_calcSizeBinary(arg);
- // then
- ck_assert_int_ge(storageSize, 2);
- }
- END_TEST
- START_TEST(UA_Int32_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_Int32 *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_Int32_calcSizeBinary(arg);
- // then
- ck_assert_int_ge(storageSize, 4);
- }
- END_TEST
- START_TEST(UA_UInt32_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_UInt32 *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_UInt32_calcSizeBinary(arg);
- // then
- ck_assert_int_ge(storageSize, 4);
- }
- END_TEST
- START_TEST(UA_Int64_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_Int64 *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_Int64_calcSizeBinary(arg);
- // then
- ck_assert_int_ge(storageSize, 8);
- }
- END_TEST
- START_TEST(UA_UInt64_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_UInt64 *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_UInt64_calcSizeBinary(arg);
- // then
- ck_assert_int_ge(storageSize, 8);
- }
- END_TEST
- START_TEST(UA_Float_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_Float *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_Float_calcSizeBinary(arg);
- // then
- ck_assert_int_ge(storageSize, 4);
- }
- END_TEST
- START_TEST(UA_Double_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_Double *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_Double_calcSizeBinary(arg);
- // then
- ck_assert_int_ge(storageSize, 8);
- }
- END_TEST
- START_TEST(UA_String_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_String *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_String_calcSizeBinary(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_String));
- ck_assert_int_ge(storageSize, UA_Int32_calcSizeBinary(UA_NULL) + sizeof(UA_NULL));
- }
- END_TEST
- START_TEST(UA_DateTime_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_DateTime *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_DateTime_calcSizeBinary(arg);
- // then
- ck_assert_int_ge(storageSize, 8);
- }
- END_TEST
- START_TEST(UA_Guid_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_Guid *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_Guid_calcSizeBinary(arg);
- // then
- ck_assert_int_ge(storageSize, 16);
- }
- END_TEST
- START_TEST(UA_ByteString_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_ByteString *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_ByteString_calcSizeBinary(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_ByteString));
- ck_assert_int_ge(storageSize, UA_Int32_calcSizeBinary(UA_NULL)+sizeof(UA_NULL));
- }
- END_TEST
- START_TEST(UA_XmlElement_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_XmlElement *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_XmlElement_calcSizeBinary(arg);
- // then
- ck_assert_int_eq(storageSize, sizeof(UA_XmlElement));
- ck_assert_int_ge(storageSize, UA_Int32_calcSizeBinary(UA_NULL)+sizeof(UA_NULL));
- }
- END_TEST
- START_TEST(UA_NodeId_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_NodeId *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_NodeId_calcSizeBinary(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_UInt32 storageSize = UA_ExpandedNodeId_calcSizeBinary(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_UInt32 storageSize = UA_StatusCode_calcSizeBinary(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_UInt32 storageSize = UA_QualifiedName_calcSizeBinary(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_UInt32 storageSize = UA_LocalizedText_calcSizeBinary(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_UInt32 storageSize = UA_ExtensionObject_calcSizeBinary(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_calcSizeBinary(&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_calcSizeBinary(&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_calcSizeBinary(&dataValue);
- // then
- ck_assert_int_eq(size, 21);
- }
- END_TEST
- START_TEST(UA_DataValue_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_DataValue *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_DataValue_calcSizeBinary(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_UInt32 storageSize = UA_Variant_calcSizeBinary(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_calcSizeBinary(&diagnosticInfo), 26);
- }
- END_TEST
- START_TEST(UA_DiagnosticInfo_calcSizeWithNullArgumentShallReturnStorageSize) {
- // given
- UA_DiagnosticInfo *arg = UA_NULL;
- // when
- UA_UInt32 storageSize = UA_DiagnosticInfo_calcSizeBinary(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_UInt32 encodingSize = UA_String_calcSizeBinary(&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_UInt32 encodingSize = UA_String_calcSizeBinary(&arg);
- // then
- ck_assert_int_eq(encodingSize, 4);
- }
- END_TEST
- START_TEST(UA_String_calcSizeWithZeroLengthShallReturnEncodingSize) {
- // given
- UA_String arg = { 0, UA_NULL };
- // when
- UA_UInt32 encodingSize = UA_String_calcSizeBinary(&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_UInt32 encodingSize = UA_String_calcSizeBinary(&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_UInt32 encodingSize = UA_String_calcSizeBinary(&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_UInt32 encodingSize = UA_NodeId_calcSizeBinary(&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_UInt32 encodingSize = UA_NodeId_calcSizeBinary(&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_UInt32 encodingSize = UA_NodeId_calcSizeBinary(&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_UInt32 encodingSize = UA_NodeId_calcSizeBinary(&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_UInt32 encodingSize = UA_NodeId_calcSizeBinary(&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_UInt32 encodingSize = UA_ExpandedNodeId_calcSizeBinary(&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_UInt32 encodingSize = UA_ExpandedNodeId_calcSizeBinary(&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_UInt32 encodingSize = UA_Guid_calcSizeBinary(&arg);
- // then
- ck_assert_int_eq(encodingSize, 16);
- }
- END_TEST
- START_TEST(UA_LocalizedText_calcSizeTextOnlyShallReturnEncodingSize) {
- // given
- UA_LocalizedText arg;
- UA_LocalizedText_init(&arg);
- arg.text = (UA_String) {8, (UA_Byte *)"12345678"};
- // when
- UA_UInt32 encodingSize = UA_LocalizedText_calcSizeBinary(&arg);
- // then
- ck_assert_int_eq(encodingSize, 1+4+8);
- // finally
- UA_LocalizedText_init(&arg); // do not delete text
- UA_LocalizedText_deleteMembers(&arg);
- }
- END_TEST
- START_TEST(UA_LocalizedText_calcSizeLocaleOnlyShallReturnEncodingSize) {
- // given
- UA_LocalizedText arg;
- UA_LocalizedText_init(&arg);
- arg.locale = (UA_String) {8, (UA_Byte *)"12345678"};
- // when
- UA_UInt32 encodingSize = UA_LocalizedText_calcSizeBinary(&arg);
- // then
- ck_assert_int_eq(encodingSize, 1+4+8);
- UA_LocalizedText_init(&arg); // do not delete locale
- UA_LocalizedText_deleteMembers(&arg);
- }
- END_TEST
- START_TEST(UA_LocalizedText_calcSizeTextAndLocaleShallReturnEncodingSize) {
- // given
- UA_LocalizedText arg;
- UA_LocalizedText_init(&arg);
- arg.locale = (UA_String) {8, (UA_Byte *)"12345678"};
- arg.text = (UA_String) {8, (UA_Byte *)"12345678"};
- // when
- UA_UInt32 encodingSize = UA_LocalizedText_calcSizeBinary(&arg);
- // then
- ck_assert_int_eq(encodingSize, 1+4+8+4+8);
- UA_LocalizedText_init(&arg); // do not delete locale and text
- UA_LocalizedText_deleteMembers(&arg);
- }
- END_TEST
- START_TEST(UA_Variant_calcSizeFixedSizeArrayShallReturnEncodingSize) {
- // given
- UA_Variant arg;
- UA_Variant_init(&arg);
- arg.vt = &UA_.types[UA_INT32];
- #define ARRAY_LEN 8
- arg.arrayLength = ARRAY_LEN;
- UA_Int32 *data[ARRAY_LEN];
- arg.data = (void *)data;
- // when
- UA_UInt32 encodingSize = UA_Variant_calcSizeBinary(&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;
- UA_Variant_init(&arg);
- arg.vt = &UA_.types[UA_STRING];
- #define ARRAY_LEN 3
- arg.arrayLength = ARRAY_LEN;
- UA_String strings[3];
- strings[0] = (UA_String) {-1, UA_NULL };
- strings[1] = (UA_String) {3, (UA_Byte *)"PLT" };
- strings[2] = (UA_String) {47, UA_NULL };
- arg.data = (void *)strings;
- // when
- UA_UInt32 encodingSize = UA_Variant_calcSizeBinary(&arg);
- // then
- ck_assert_int_eq(encodingSize, 1+4+(4+0)+(4+3)+(4+47));
- #undef ARRAY_LEN
- }
- END_TEST
- START_TEST(UA_Byte_decodeShallCopyAndAdvancePosition) {
- // given
- UA_Byte dst;
- UA_Byte data[] = { 0x08 };
- UA_ByteString src = { 1, data };
- UA_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_UInt32 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_ptr_eq(dst.vt, &UA_.types[UA_INT32]);
- ck_assert_int_eq(dst.arrayLength, 1);
- ck_assert_ptr_eq(dst.data, UA_alloc_lastptr);
- ck_assert_int_eq(*(UA_Int32 *)dst.data, 255);
- // finally
- UA_Variant_deleteMembers(&dst);
- }
- END_TEST
- START_TEST(UA_Variant_decodeWithArrayFlagSetShallSetVTAndAllocateMemoryForArray) {
- // given
- UA_UInt32 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_ptr_eq(dst.vt, &UA_.types[UA_INT32]);
- ck_assert_int_eq(dst.arrayLength, 2);
- ck_assert_ptr_eq(dst.data, 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_UInt32 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
- UA_Variant_deleteMembers(&dst);
- }
- END_TEST
- START_TEST(UA_Variant_decodeWithTooSmallSourceShallReturnWithError) {
- // given
- UA_UInt32 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
- 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 = 0;
- UA_UInt32 pos = 0;
- ck_assert_uint_eq(dst.data[1], 0xFF);
- src = 8;
- retval = UA_Byte_encodeBinary(&src, &dst, &pos);
- 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, &dst, &pos);
- 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 = 0;
- UA_UInt32 pos = 0;
- // when test 1
- src = -1;
- retval = UA_UInt16_encodeBinary(&src, &dst, &pos);
- // 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, &dst, &pos);
- // 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 = 0;
- UA_UInt32 pos = 0;
- // when test 1
- src = 0;
- retval = UA_UInt16_encodeBinary(&src, &dst, &pos);
- // 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, &dst, &pos);
- // 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 = 0;
- UA_UInt32 pos = 0;
- // when test 1
- src = -1;
- retval = UA_UInt32_encodeBinary(&src, &dst, &pos);
- // 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, &dst, &pos);
- // 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 = 0;
- UA_UInt32 pos = 0;
- // when test 1
- src = 1;
- retval = UA_Int32_encodeBinary(&src, &dst, &pos);
- // 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, &dst, &pos);
- // 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 = 0;
- UA_UInt32 pos = 0;
- // when test 1
- src = -1;
- retval = UA_Int32_encodeBinary(&src, &dst, &pos);
- // 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 = 0;
- UA_UInt32 pos = 0;
- // when test 1
- src = -1;
- retval = UA_UInt64_encodeBinary(&src, &dst, &pos);
- // 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, &dst, &pos);
- // 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 = 0;
- UA_UInt32 pos = 0;
- // when test 1
- src = 0x7F0033AA44EE6611;
- retval = UA_Int64_encodeBinary(&src, &dst, &pos);
- // 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 = 0;
- UA_UInt32 pos = 0;
- // when test 1
- src = -1;
- retval = UA_Int64_encodeBinary(&src, &dst, &pos);
- // 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 = 0;
- UA_UInt32 pos = 0;
- // when test 1
- src = -6.5;
- retval = UA_Float_encodeBinary(&src, &dst, &pos);
- // 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 = 0;
- UA_UInt32 pos = 0;
- // when
- retval = UA_String_encodeBinary(&src, &dst, &pos);
- // 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 = 0;
- UA_UInt32 pos = 0;
- // when
- retval = UA_DataValue_encodeBinary(&src, &dst, &pos);
- // 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
- UA_Variant_init(&src.value);
- src.value.vt = &UA_.types[UA_INT32];
- src.value.arrayLength = 1; // one element (encoded as not an array)
- UA_Int32 vdata = 45;
- src.value.data = (void *)&vdata;
- UA_Byte data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- UA_ByteString dst = { 24, data };
- UA_Int32 retval = 0;
- UA_UInt32 pos = 0;
- // when
- retval = UA_DataValue_encodeBinary(&src, &dst, &pos);
- // 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);
- 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) {
- // given
- UA_Byte data[3] = { 1, 2, 3 };
- UA_ExtensionObject value, valueCopied;
- UA_ExtensionObject_init(&value);
- UA_ExtensionObject_init(&valueCopied);
- value.typeId.encodingByte = UA_NODEIDTYPE_TWOBYTE;
- value.typeId.identifier.numeric = UA_BYTE;
- 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(UA_Int32 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
- value.body.data = UA_NULL; // we cannot free the static string
- UA_ExtensionObject_deleteMembers(&value);
- UA_ExtensionObject_deleteMembers(&valueCopied);
- }
- END_TEST
- START_TEST(UA_Array_copyByteArrayShallWorkOnExample) {
- //given
- UA_String testString;
- UA_Byte *dstArray;
- UA_Int32 size = 5;
- UA_Int32 i = 0;
- 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 = 5;
- //when
- UA_Array_copy((const void *)testString.data, 5, &UA_.types[UA_BYTE], (void **)&dstArray);
- //then
- for(i = 0;i < size;i++)
- ck_assert_int_eq(testString.data[i], dstArray[i]);
- //finally
- UA_String_deleteMembers(&testString);
- UA_free((void *)dstArray);
- }
- END_TEST
- START_TEST(UA_Array_copyUA_StringShallWorkOnExample) {
- // given
- UA_Int32 i, j;
- UA_String *srcArray;
- UA_Array_new((void **)&srcArray, 3, &UA_.types[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((const void *)srcArray, 3, &UA_.types[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_Array_delete(srcArray, 3, &UA_.types[UA_STRING]);
- UA_Array_delete(dstArray, 3, &UA_.types[UA_STRING]);
- }
- END_TEST
- START_TEST(UA_DiagnosticInfo_copyShallWorkOnExample) {
- //given
- UA_DiagnosticInfo value, innerValue, copiedValue;
- UA_String testString = (UA_String){5, (UA_Byte*)"OPCUA"};
- UA_DiagnosticInfo_init(&value);
- UA_DiagnosticInfo_init(&innerValue);
- value.encodingMask |= UA_DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO;
- value.innerDiagnosticInfo = &innerValue;
- value.additionalInfo = testString;
- //when
- UA_DiagnosticInfo_copy(&value, &copiedValue);
- //then
- for(UA_Int32 i = 0;i < testString.length;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
- value.additionalInfo.data = UA_NULL; // do not delete the static string
- value.innerDiagnosticInfo = UA_NULL; // do not delete the static innerdiagnosticinfo
- UA_DiagnosticInfo_deleteMembers(&value);
- UA_DiagnosticInfo_deleteMembers(&copiedValue);
- }
- END_TEST
- START_TEST(UA_ApplicationDescription_copyShallWorkOnExample) {
- //given
- UA_Int32 retval = UA_SUCCESS;
- UA_String appString = (UA_String){3, (UA_Byte*)"APP"};
- UA_String discString = (UA_String){4, (UA_Byte*)"DISC"};
- UA_String gateWayString = (UA_String){7, (UA_Byte*)"GATEWAY"};
- UA_String srcArray[3];
- srcArray[0] = (UA_String){ 6, (UA_Byte*)"__open" };
- srcArray[1] = (UA_String){ 6, (UA_Byte*)"_62541" };
- srcArray[2] = (UA_String){ 6, (UA_Byte*)"opc ua" };
- UA_ApplicationDescription value, copiedValue;
- UA_ApplicationDescription_init(&value);
- value.applicationUri = appString;
- value.discoveryProfileUri = discString;
- value.gatewayServerUri = gateWayString;
- value.discoveryUrlsSize = 3;
- value.discoveryUrls = srcArray;
- //when
- retval = UA_ApplicationDescription_copy(&value, &copiedValue);
- //then
- ck_assert_int_eq(retval, UA_SUCCESS);
- for(UA_Int32 i = 0;i < appString.length;i++)
- ck_assert_int_eq(copiedValue.applicationUri.data[i], value.applicationUri.data[i]);
- ck_assert_int_eq(copiedValue.applicationUri.length, value.applicationUri.length);
- for(UA_Int32 i = 0;i < discString.length;i++)
- ck_assert_int_eq(copiedValue.discoveryProfileUri.data[i], value.discoveryProfileUri.data[i]);
- ck_assert_int_eq(copiedValue.discoveryProfileUri.length, value.discoveryProfileUri.length);
- for(UA_Int32 i = 0;i < gateWayString.length;i++)
- ck_assert_int_eq(copiedValue.gatewayServerUri.data[i], value.gatewayServerUri.data[i]);
- ck_assert_int_eq(copiedValue.gatewayServerUri.length, value.gatewayServerUri.length);
- //String Array Test
- for(UA_Int32 i = 0;i < 3;i++) {
- for(UA_Int32 j = 0;j < 6;j++)
- ck_assert_int_eq(value.discoveryUrls[i].data[j], copiedValue.discoveryUrls[i].data[j]);
- ck_assert_int_eq(value.discoveryUrls[i].length, copiedValue.discoveryUrls[i].length);
- }
- ck_assert_int_eq(copiedValue.discoveryUrls[0].data[2], 'o');
- ck_assert_int_eq(copiedValue.discoveryUrls[0].data[3], 'p');
- ck_assert_int_eq(copiedValue.discoveryUrlsSize, value.discoveryUrlsSize);
- //finally
- // UA_ApplicationDescription_deleteMembers(&value); // do not free the members as they are statically allocated
- UA_ApplicationDescription_deleteMembers(&copiedValue);
- }
- END_TEST
- START_TEST(UA_Variant_copyShallWorkOnSingleValueExample) {
- //given
- UA_String testString = (UA_String){5, (UA_Byte*)"OPCUA"};
- UA_Variant value, copiedValue;
- UA_Variant_init(&value);
- UA_Variant_init(&copiedValue);
- UA_alloc((void**)&value.data, sizeof(UA_String));
- *((UA_String*)value.data) = testString;
- value.vt = &UA_.types[UA_STRING];
- value.arrayLength = 1;
- //when
- UA_Variant_copy(&value, &copiedValue);
- //then
- UA_String copiedString = *(UA_String*)(copiedValue.data);
- for(UA_Int32 i = 0;i < 5;i++)
- ck_assert_int_eq(copiedString.data[i], testString.data[i]);
- ck_assert_int_eq(copiedString.length, testString.length);
- ck_assert_int_eq(value.arrayDimensionsLength, copiedValue.arrayDimensionsLength);
- ck_assert_int_eq(value.arrayLength, copiedValue.arrayLength);
- //finally
- ((UA_String*)value.data)->data = UA_NULL; // the string is statically allocated. do not free it.
- UA_Variant_deleteMembers(&value);
- UA_Variant_deleteMembers(&copiedValue);
- }
- END_TEST
- START_TEST(UA_Variant_copyShallWorkOn1DArrayExample) {
- // given
- UA_String *srcArray;
- UA_Array_new((void **)&srcArray, 3, &UA_.types[UA_STRING]);
- UA_String_copycstring("__open", &srcArray[0]);
- UA_String_copycstring("_62541", &srcArray[1]);
- UA_String_copycstring("opc ua", &srcArray[2]);
- UA_Int32 *dimensions;
- UA_alloc((void **)&dimensions, UA_Int32_calcSizeBinary(UA_NULL));
- dimensions[0] = 3;
- UA_Variant value, copiedValue;
- UA_Variant_init(&value);
- UA_Variant_init(&copiedValue);
- value.arrayLength = 3;
- value.data = (void **)srcArray;
- value.arrayDimensionsLength = 1;
- value.arrayDimensions = dimensions;
- value.vt = &UA_.types[UA_STRING];
- //when
- UA_Variant_copy(&value, &copiedValue);
- //then
- UA_Int32 i1 = value.arrayDimensions[0];
- UA_Int32 i2 = copiedValue.arrayDimensions[0];
- ck_assert_int_eq(i1, i2);
- for(UA_Int32 i = 0;i < 3;i++) {
- for(UA_Int32 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.arrayDimensionsLength, copiedValue.arrayDimensionsLength);
- ck_assert_int_eq(value.arrayLength, copiedValue.arrayLength);
- //finally
- UA_Variant_deleteMembers(&value);
- UA_Variant_deleteMembers(&copiedValue);
- }
- END_TEST
- START_TEST(UA_Variant_copyShallWorkOn2DArrayExample) {
- // given
- UA_Int32 *srcArray;
- UA_Array_new((void **)&srcArray, 6, &UA_.types[UA_INT32]);
- srcArray[0] = 0;
- srcArray[1] = 1;
- srcArray[2] = 2;
- srcArray[3] = 3;
- srcArray[4] = 4;
- srcArray[5] = 5;
- UA_Int32 *dimensions;
- UA_Array_new((void **)&dimensions, 2, &UA_.types[UA_INT32]);
- UA_Int32 dim1 = 3;
- UA_Int32 dim2 = 2;
- dimensions[0] = dim1;
- dimensions[1] = dim2;
- UA_Variant value, copiedValue;
- UA_Variant_init(&value);
- UA_Variant_init(&copiedValue);
- value.arrayLength = 6;
- value.data = (void **)srcArray;
- value.arrayDimensionsLength = 2;
- value.arrayDimensions = dimensions;
- value.vt = &UA_.types[UA_INT32];
- //when
- UA_Variant_copy(&value, &copiedValue);
- //then
- //1st dimension
- UA_Int32 i1 = value.arrayDimensions[0];
- UA_Int32 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(UA_Int32 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.arrayDimensionsLength, copiedValue.arrayDimensionsLength);
- ck_assert_int_eq(value.arrayLength, copiedValue.arrayLength);
- //finally
- UA_Variant_deleteMembers(&value);
- UA_Variant_deleteMembers(&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_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);
- tcase_add_test(tc_copy, UA_ApplicationDescription_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_set_fork_status(sr, CK_NOFORK);
- srunner_run_all(sr, CK_NORMAL);
- number_failed += srunner_ntests_failed(sr);
- srunner_free(sr);
- return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
- }
|