check_builtin.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "ua_types.h"
  4. #include "ua_types_encoding_binary.h"
  5. #include "ua_transport.h"
  6. #include "check.h"
  7. START_TEST(UA_Boolean_calcSizeWithNullArgumentShallReturnStorageSize) {
  8. // given
  9. UA_Boolean *arg = UA_NULL;
  10. // when
  11. UA_UInt32 storageSize = UA_Boolean_calcSizeBinary(arg);
  12. // then
  13. ck_assert_int_eq(storageSize, 1);
  14. }
  15. END_TEST
  16. START_TEST(UA_SByte_calcSizeWithNullArgumentShallReturnStorageSize) {
  17. // given
  18. UA_SByte *arg = UA_NULL;
  19. // when
  20. UA_UInt32 storageSize = UA_SByte_calcSizeBinary(arg);
  21. // then
  22. ck_assert_int_ge(storageSize, 1);
  23. }
  24. END_TEST
  25. START_TEST(UA_Byte_calcSizeWithNullArgumentShallReturnStorageSize) {
  26. // given
  27. UA_Byte *arg = UA_NULL;
  28. // when
  29. UA_UInt32 storageSize = UA_Byte_calcSizeBinary(arg);
  30. // then
  31. ck_assert_int_ge(storageSize, 1);
  32. }
  33. END_TEST
  34. START_TEST(UA_Int16_calcSizeWithNullArgumentShallReturnStorageSize) {
  35. // given
  36. UA_Int16 *arg = UA_NULL;
  37. // when
  38. UA_UInt32 storageSize = UA_Int16_calcSizeBinary(arg);
  39. // then
  40. ck_assert_int_ge(storageSize, 2);
  41. }
  42. END_TEST
  43. START_TEST(UA_UInt16_calcSizeWithNullArgumentShallReturnStorageSize) {
  44. // given
  45. UA_UInt16 *arg = UA_NULL;
  46. // when
  47. UA_UInt32 storageSize = UA_UInt16_calcSizeBinary(arg);
  48. // then
  49. ck_assert_int_ge(storageSize, 2);
  50. }
  51. END_TEST
  52. START_TEST(UA_Int32_calcSizeWithNullArgumentShallReturnStorageSize) {
  53. // given
  54. UA_Int32 *arg = UA_NULL;
  55. // when
  56. UA_UInt32 storageSize = UA_Int32_calcSizeBinary(arg);
  57. // then
  58. ck_assert_int_ge(storageSize, 4);
  59. }
  60. END_TEST
  61. START_TEST(UA_UInt32_calcSizeWithNullArgumentShallReturnStorageSize) {
  62. // given
  63. UA_UInt32 *arg = UA_NULL;
  64. // when
  65. UA_UInt32 storageSize = UA_UInt32_calcSizeBinary(arg);
  66. // then
  67. ck_assert_int_ge(storageSize, 4);
  68. }
  69. END_TEST
  70. START_TEST(UA_Int64_calcSizeWithNullArgumentShallReturnStorageSize) {
  71. // given
  72. UA_Int64 *arg = UA_NULL;
  73. // when
  74. UA_UInt32 storageSize = UA_Int64_calcSizeBinary(arg);
  75. // then
  76. ck_assert_int_ge(storageSize, 8);
  77. }
  78. END_TEST
  79. START_TEST(UA_UInt64_calcSizeWithNullArgumentShallReturnStorageSize) {
  80. // given
  81. UA_UInt64 *arg = UA_NULL;
  82. // when
  83. UA_UInt32 storageSize = UA_UInt64_calcSizeBinary(arg);
  84. // then
  85. ck_assert_int_ge(storageSize, 8);
  86. }
  87. END_TEST
  88. START_TEST(UA_Float_calcSizeWithNullArgumentShallReturnStorageSize) {
  89. // given
  90. UA_Float *arg = UA_NULL;
  91. // when
  92. UA_UInt32 storageSize = UA_Float_calcSizeBinary(arg);
  93. // then
  94. ck_assert_int_ge(storageSize, 4);
  95. }
  96. END_TEST
  97. START_TEST(UA_Double_calcSizeWithNullArgumentShallReturnStorageSize) {
  98. // given
  99. UA_Double *arg = UA_NULL;
  100. // when
  101. UA_UInt32 storageSize = UA_Double_calcSizeBinary(arg);
  102. // then
  103. ck_assert_int_ge(storageSize, 8);
  104. }
  105. END_TEST
  106. START_TEST(UA_String_calcSizeWithNullArgumentShallReturnStorageSize) {
  107. // given
  108. UA_String *arg = UA_NULL;
  109. // when
  110. UA_UInt32 storageSize = UA_String_calcSizeBinary(arg);
  111. // then
  112. ck_assert_int_eq(storageSize, sizeof(UA_String));
  113. ck_assert_int_ge(storageSize, UA_Int32_calcSizeBinary(UA_NULL) + sizeof(UA_NULL));
  114. }
  115. END_TEST
  116. START_TEST(UA_DateTime_calcSizeWithNullArgumentShallReturnStorageSize) {
  117. // given
  118. UA_DateTime *arg = UA_NULL;
  119. // when
  120. UA_UInt32 storageSize = UA_DateTime_calcSizeBinary(arg);
  121. // then
  122. ck_assert_int_ge(storageSize, 8);
  123. }
  124. END_TEST
  125. START_TEST(UA_Guid_calcSizeWithNullArgumentShallReturnStorageSize) {
  126. // given
  127. UA_Guid *arg = UA_NULL;
  128. // when
  129. UA_UInt32 storageSize = UA_Guid_calcSizeBinary(arg);
  130. // then
  131. ck_assert_int_ge(storageSize, 16);
  132. }
  133. END_TEST
  134. START_TEST(UA_ByteString_calcSizeWithNullArgumentShallReturnStorageSize) {
  135. // given
  136. UA_ByteString *arg = UA_NULL;
  137. // when
  138. UA_UInt32 storageSize = UA_ByteString_calcSizeBinary(arg);
  139. // then
  140. ck_assert_int_eq(storageSize, sizeof(UA_ByteString));
  141. ck_assert_int_ge(storageSize, UA_Int32_calcSizeBinary(UA_NULL)+sizeof(UA_NULL));
  142. }
  143. END_TEST
  144. START_TEST(UA_XmlElement_calcSizeWithNullArgumentShallReturnStorageSize) {
  145. // given
  146. UA_XmlElement *arg = UA_NULL;
  147. // when
  148. UA_UInt32 storageSize = UA_XmlElement_calcSizeBinary(arg);
  149. // then
  150. ck_assert_int_eq(storageSize, sizeof(UA_XmlElement));
  151. ck_assert_int_ge(storageSize, UA_Int32_calcSizeBinary(UA_NULL)+sizeof(UA_NULL));
  152. }
  153. END_TEST
  154. START_TEST(UA_NodeId_calcSizeWithNullArgumentShallReturnStorageSize) {
  155. // given
  156. UA_NodeId *arg = UA_NULL;
  157. // when
  158. UA_UInt32 storageSize = UA_NodeId_calcSizeBinary(arg);
  159. // then
  160. ck_assert_int_eq(storageSize, sizeof(UA_NodeId));
  161. }
  162. END_TEST
  163. START_TEST(UA_ExpandedNodeId_calcSizeWithNullArgumentShallReturnStorageSize) {
  164. // given
  165. UA_ExpandedNodeId *arg = UA_NULL;
  166. // when
  167. UA_UInt32 storageSize = UA_ExpandedNodeId_calcSizeBinary(arg);
  168. // then
  169. ck_assert_int_eq(storageSize, sizeof(UA_ExpandedNodeId));
  170. }
  171. END_TEST
  172. START_TEST(UA_StatusCode_calcSizeWithNullArgumentShallReturnStorageSize) {
  173. // given
  174. UA_StatusCode *arg = UA_NULL;
  175. // when
  176. UA_UInt32 storageSize = UA_StatusCode_calcSizeBinary(arg);
  177. // then
  178. ck_assert_int_eq(storageSize, sizeof(UA_StatusCode));
  179. }
  180. END_TEST
  181. START_TEST(UA_QualifiedName_calcSizeWithNullArgumentShallReturnStorageSize) {
  182. // given
  183. UA_QualifiedName *arg = UA_NULL;
  184. // when
  185. UA_UInt32 storageSize = UA_QualifiedName_calcSizeBinary(arg);
  186. // then
  187. ck_assert_int_eq(storageSize, sizeof(UA_QualifiedName));
  188. }
  189. END_TEST
  190. START_TEST(UA_LocalizedText_calcSizeWithNullArgumentShallReturnStorageSize) {
  191. // given
  192. UA_LocalizedText *arg = UA_NULL;
  193. // when
  194. UA_UInt32 storageSize = UA_LocalizedText_calcSizeBinary(arg);
  195. // then
  196. ck_assert_int_eq(storageSize, sizeof(UA_LocalizedText));
  197. }
  198. END_TEST
  199. START_TEST(UA_ExtensionObject_calcSizeWithNullArgumentShallReturnStorageSize) {
  200. // given
  201. UA_ExtensionObject *arg = UA_NULL;
  202. // when
  203. UA_UInt32 storageSize = UA_ExtensionObject_calcSizeBinary(arg);
  204. // then
  205. ck_assert_int_eq(storageSize, sizeof(UA_ExtensionObject));
  206. }
  207. END_TEST
  208. START_TEST(UA_ExtensionObject_calcSizeShallWorkOnExample) {
  209. // given
  210. UA_Byte data[3] = { 1, 2, 3 };
  211. UA_ExtensionObject extensionObject;
  212. // empty ExtensionObject, handcoded
  213. // when
  214. UA_ExtensionObject_init(&extensionObject);
  215. extensionObject.typeId.identifierType = UA_NODEIDTYPE_NUMERIC;
  216. extensionObject.typeId.identifier.numeric = 0;
  217. extensionObject.encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_NOBODYISENCODED;
  218. // then
  219. ck_assert_int_eq(UA_ExtensionObject_calcSizeBinary(&extensionObject), 1 + 1 + 1);
  220. // ExtensionObject with ByteString-Body
  221. // when
  222. extensionObject.encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING;
  223. extensionObject.body.data = data;
  224. extensionObject.body.length = 3;
  225. // then
  226. ck_assert_int_eq(UA_ExtensionObject_calcSizeBinary(&extensionObject), 3 + 4 + 3);
  227. }
  228. END_TEST
  229. START_TEST(UA_DataValue_calcSizeShallWorkOnExample) {
  230. // given
  231. UA_DataValue dataValue;
  232. dataValue.encodingMask = UA_DATAVALUE_ENCODINGMASK_STATUSCODE | UA_DATAVALUE_ENCODINGMASK_SOURCETIMESTAMP |
  233. UA_DATAVALUE_ENCODINGMASK_SOURCEPICOSECONDS;
  234. dataValue.status = 12;
  235. UA_DateTime dateTime;
  236. dateTime = 80;
  237. dataValue.sourceTimestamp = dateTime;
  238. UA_DateTime sourceTime;
  239. sourceTime = 214;
  240. dataValue.sourcePicoseconds = sourceTime;
  241. int size = 0;
  242. // when
  243. size = UA_DataValue_calcSizeBinary(&dataValue);
  244. // then
  245. ck_assert_int_eq(size, 21);
  246. }
  247. END_TEST
  248. START_TEST(UA_DataValue_calcSizeWithNullArgumentShallReturnStorageSize) {
  249. // given
  250. UA_DataValue *arg = UA_NULL;
  251. // when
  252. UA_UInt32 storageSize = UA_DataValue_calcSizeBinary(arg);
  253. // then
  254. ck_assert_int_eq(storageSize, sizeof(UA_DataValue));
  255. }
  256. END_TEST
  257. START_TEST(UA_Variant_calcSizeWithNullArgumentShallReturnStorageSize) {
  258. // given
  259. UA_Variant *arg = UA_NULL;
  260. // when
  261. UA_UInt32 storageSize = UA_Variant_calcSizeBinary(arg);
  262. // then
  263. ck_assert_int_eq(storageSize, sizeof(UA_Variant));
  264. }
  265. END_TEST
  266. START_TEST(UA_DiagnosticInfo_calcSizeShallWorkOnExample) {
  267. // given
  268. UA_DiagnosticInfo diagnosticInfo;
  269. diagnosticInfo.encodingMask = 0x01 | 0x02 | 0x04 | 0x08 | 0x10;
  270. diagnosticInfo.symbolicId = 30;
  271. diagnosticInfo.namespaceUri = 25;
  272. diagnosticInfo.localizedText = 22;
  273. UA_Byte additionalInfoData = 'd';
  274. diagnosticInfo.additionalInfo.data = &additionalInfoData; //"OPCUA";
  275. diagnosticInfo.additionalInfo.length = 5;
  276. // when & then
  277. ck_assert_int_eq(UA_DiagnosticInfo_calcSizeBinary(&diagnosticInfo), 26);
  278. }
  279. END_TEST
  280. START_TEST(UA_DiagnosticInfo_calcSizeWithNullArgumentShallReturnStorageSize) {
  281. // given
  282. UA_DiagnosticInfo *arg = UA_NULL;
  283. // when
  284. UA_UInt32 storageSize = UA_DiagnosticInfo_calcSizeBinary(arg);
  285. // then
  286. ck_assert_int_eq(storageSize, sizeof(UA_DiagnosticInfo));
  287. }
  288. END_TEST
  289. START_TEST(UA_String_calcSizeWithNegativLengthShallReturnEncodingSize) {
  290. // given
  291. UA_String arg = { -1, UA_NULL };
  292. // when
  293. UA_UInt32 encodingSize = UA_String_calcSizeBinary(&arg);
  294. // then
  295. ck_assert_int_eq(encodingSize, 4);
  296. }
  297. END_TEST
  298. START_TEST(UA_String_calcSizeWithNegativLengthAndValidPointerShallReturnEncodingSize) {
  299. // given
  300. UA_String arg = { -1, (UA_Byte *)"OPC" };
  301. // when
  302. UA_UInt32 encodingSize = UA_String_calcSizeBinary(&arg);
  303. // then
  304. ck_assert_int_eq(encodingSize, 4);
  305. }
  306. END_TEST
  307. START_TEST(UA_String_calcSizeWithZeroLengthShallReturnEncodingSize) {
  308. // given
  309. UA_String arg = { 0, UA_NULL };
  310. // when
  311. UA_UInt32 encodingSize = UA_String_calcSizeBinary(&arg);
  312. // then
  313. ck_assert_int_eq(encodingSize, 4);
  314. }
  315. END_TEST
  316. START_TEST(UA_String_calcSizeWithZeroLengthAndValidPointerShallReturnEncodingSize) {
  317. // given
  318. UA_String arg = { 0, (UA_Byte *)"OPC" };
  319. // when
  320. UA_UInt32 encodingSize = UA_String_calcSizeBinary(&arg);
  321. // then
  322. ck_assert_int_eq(encodingSize, 4);
  323. }
  324. END_TEST
  325. START_TEST(UA_String_calcSizeShallReturnEncodingSize) {
  326. // given
  327. UA_String arg = { 3, (UA_Byte *)"OPC" };
  328. // when
  329. UA_UInt32 encodingSize = UA_String_calcSizeBinary(&arg);
  330. // then
  331. ck_assert_int_eq(encodingSize, 4+3);
  332. }
  333. END_TEST
  334. START_TEST(UA_NodeId_calcSizeEncodingTwoByteShallReturnEncodingSize) {
  335. // given
  336. UA_NodeId arg;
  337. arg.identifierType = UA_NODEIDTYPE_NUMERIC;
  338. arg.namespaceIndex = 0;
  339. arg.identifier.numeric = 1;
  340. // when
  341. UA_UInt32 encodingSize = UA_NodeId_calcSizeBinary(&arg);
  342. // then
  343. ck_assert_int_eq(encodingSize, 2);
  344. }
  345. END_TEST
  346. START_TEST(UA_NodeId_calcSizeEncodingFourByteShallReturnEncodingSize) {
  347. // given
  348. UA_NodeId arg;
  349. arg.identifierType = UA_NODEIDTYPE_NUMERIC;
  350. arg.namespaceIndex = 1;
  351. arg.identifier.numeric = 1;
  352. // when
  353. UA_UInt32 encodingSize = UA_NodeId_calcSizeBinary(&arg);
  354. // then
  355. ck_assert_int_eq(encodingSize, 4);
  356. }
  357. END_TEST
  358. START_TEST(UA_NodeId_calcSizeEncodingStringShallReturnEncodingSize) {
  359. // given
  360. UA_NodeId arg;
  361. arg.identifierType = UA_NODEIDTYPE_STRING;
  362. arg.identifier.string.length = 3;
  363. arg.identifier.string.data = (UA_Byte *)"PLT";
  364. // when
  365. UA_UInt32 encodingSize = UA_NodeId_calcSizeBinary(&arg);
  366. // then
  367. ck_assert_int_eq(encodingSize, 1+2+4+3);
  368. }
  369. END_TEST
  370. START_TEST(UA_NodeId_calcSizeEncodingStringNegativLengthShallReturnEncodingSize) {
  371. // given
  372. UA_NodeId arg;
  373. arg.identifierType = UA_NODEIDTYPE_STRING;
  374. arg.identifier.string.length = -1;
  375. // when
  376. UA_UInt32 encodingSize = UA_NodeId_calcSizeBinary(&arg);
  377. // then
  378. ck_assert_int_eq(encodingSize, 1+2+4+0);
  379. }
  380. END_TEST
  381. START_TEST(UA_NodeId_calcSizeEncodingStringZeroLengthShallReturnEncodingSize) {
  382. // given
  383. UA_NodeId arg;
  384. arg.identifierType = UA_NODEIDTYPE_STRING;
  385. arg.identifier.string.length = 0;
  386. // when
  387. UA_UInt32 encodingSize = UA_NodeId_calcSizeBinary(&arg);
  388. // then
  389. ck_assert_int_eq(encodingSize, 1+2+4+0);
  390. }
  391. END_TEST
  392. START_TEST(UA_ExpandedNodeId_calcSizeEncodingStringAndServerIndexShallReturnEncodingSize) {
  393. // given
  394. UA_ExpandedNodeId arg;
  395. UA_ExpandedNodeId_init(&arg);
  396. arg.nodeId.identifierType = UA_NODEIDTYPE_STRING;
  397. arg.serverIndex = 1;
  398. arg.nodeId.identifier.string.length = 3;
  399. // when
  400. UA_UInt32 encodingSize = UA_ExpandedNodeId_calcSizeBinary(&arg);
  401. // then
  402. ck_assert_int_eq(encodingSize, 1+2+4+3+4);
  403. }
  404. END_TEST
  405. START_TEST(UA_ExpandedNodeId_calcSizeEncodingStringAndNamespaceUriShallReturnEncodingSize) {
  406. // given
  407. UA_ExpandedNodeId arg;
  408. UA_ExpandedNodeId_init(&arg);
  409. arg.nodeId.identifierType = UA_NODEIDTYPE_STRING;
  410. arg.nodeId.identifier.string.length = 3;
  411. arg.namespaceUri.length = 7;
  412. // when
  413. UA_UInt32 encodingSize = UA_ExpandedNodeId_calcSizeBinary(&arg);
  414. // then
  415. ck_assert_int_eq(encodingSize, 1+2+4+3+4+7);
  416. }
  417. END_TEST
  418. START_TEST(UA_Guid_calcSizeShallReturnEncodingSize) {
  419. // given
  420. UA_Guid arg;
  421. // when
  422. UA_UInt32 encodingSize = UA_Guid_calcSizeBinary(&arg);
  423. // then
  424. ck_assert_int_eq(encodingSize, 16);
  425. }
  426. END_TEST
  427. START_TEST(UA_LocalizedText_calcSizeTextOnlyShallReturnEncodingSize) {
  428. // given
  429. UA_LocalizedText arg;
  430. UA_LocalizedText_init(&arg);
  431. arg.text = (UA_String) {8, (UA_Byte *)"12345678"};
  432. // when
  433. UA_UInt32 encodingSize = UA_LocalizedText_calcSizeBinary(&arg);
  434. // then
  435. ck_assert_int_eq(encodingSize, 1+4+8);
  436. // finally
  437. UA_LocalizedText_init(&arg); // do not delete text
  438. UA_LocalizedText_deleteMembers(&arg);
  439. }
  440. END_TEST
  441. START_TEST(UA_LocalizedText_calcSizeLocaleOnlyShallReturnEncodingSize) {
  442. // given
  443. UA_LocalizedText arg;
  444. UA_LocalizedText_init(&arg);
  445. arg.locale = (UA_String) {8, (UA_Byte *)"12345678"};
  446. // when
  447. UA_UInt32 encodingSize = UA_LocalizedText_calcSizeBinary(&arg);
  448. // then
  449. ck_assert_int_eq(encodingSize, 1+4+8);
  450. UA_LocalizedText_init(&arg); // do not delete locale
  451. UA_LocalizedText_deleteMembers(&arg);
  452. }
  453. END_TEST
  454. START_TEST(UA_LocalizedText_calcSizeTextAndLocaleShallReturnEncodingSize) {
  455. // given
  456. UA_LocalizedText arg;
  457. UA_LocalizedText_init(&arg);
  458. arg.locale = (UA_String) {8, (UA_Byte *)"12345678"};
  459. arg.text = (UA_String) {8, (UA_Byte *)"12345678"};
  460. // when
  461. UA_UInt32 encodingSize = UA_LocalizedText_calcSizeBinary(&arg);
  462. // then
  463. ck_assert_int_eq(encodingSize, 1+4+8+4+8);
  464. UA_LocalizedText_init(&arg); // do not delete locale and text
  465. UA_LocalizedText_deleteMembers(&arg);
  466. }
  467. END_TEST
  468. START_TEST(UA_Variant_calcSizeFixedSizeArrayShallReturnEncodingSize) {
  469. // given
  470. UA_Variant arg;
  471. UA_Variant_init(&arg);
  472. arg.vt = &UA_.types[UA_INT32];
  473. #define ARRAY_LEN 8
  474. arg.arrayLength = ARRAY_LEN;
  475. UA_Int32 *data[ARRAY_LEN];
  476. arg.data = (void *)data;
  477. // when
  478. UA_UInt32 encodingSize = UA_Variant_calcSizeBinary(&arg);
  479. // then
  480. ck_assert_int_eq(encodingSize, 1+4+ARRAY_LEN*4);
  481. #undef ARRAY_LEN
  482. }
  483. END_TEST
  484. START_TEST(UA_Variant_calcSizeVariableSizeArrayShallReturnEncodingSize) {
  485. // given
  486. UA_Variant arg;
  487. UA_Variant_init(&arg);
  488. arg.vt = &UA_.types[UA_STRING];
  489. #define ARRAY_LEN 3
  490. arg.arrayLength = ARRAY_LEN;
  491. UA_String strings[3];
  492. strings[0] = (UA_String) {-1, UA_NULL };
  493. strings[1] = (UA_String) {3, (UA_Byte *)"PLT" };
  494. strings[2] = (UA_String) {47, UA_NULL };
  495. arg.data = (void *)strings;
  496. // when
  497. UA_UInt32 encodingSize = UA_Variant_calcSizeBinary(&arg);
  498. // then
  499. ck_assert_int_eq(encodingSize, 1+4+(4+0)+(4+3)+(4+47));
  500. #undef ARRAY_LEN
  501. }
  502. END_TEST
  503. START_TEST(UA_Byte_decodeShallCopyAndAdvancePosition) {
  504. // given
  505. UA_Byte dst;
  506. UA_Byte data[] = { 0x08 };
  507. UA_ByteString src = { 1, data };
  508. UA_UInt32 pos = 0;
  509. // when
  510. UA_Int32 retval = UA_Byte_decodeBinary(&src, &pos, &dst);
  511. // then
  512. ck_assert_int_eq(retval, UA_SUCCESS);
  513. ck_assert_uint_eq(pos, 1);
  514. ck_assert_uint_eq(dst, 0x08);
  515. }
  516. END_TEST
  517. START_TEST(UA_Byte_decodeShallModifyOnlyCurrentPosition) {
  518. // given
  519. UA_Byte dst[] = { 0xFF, 0xFF, 0xFF };
  520. UA_Byte data[] = { 0x08 };
  521. UA_ByteString src = { 1, data };
  522. UA_UInt32 pos = 0;
  523. // when
  524. UA_Int32 retval = UA_Byte_decodeBinary(&src, &pos, &dst[1]);
  525. // then
  526. ck_assert_int_eq(retval, UA_SUCCESS);
  527. ck_assert_int_eq(pos, 1);
  528. ck_assert_uint_eq(dst[0], 0xFF);
  529. ck_assert_uint_eq(dst[1], 0x08);
  530. ck_assert_uint_eq(dst[2], 0xFF);
  531. }
  532. END_TEST
  533. START_TEST(UA_Int16_decodeShallAssumeLittleEndian) {
  534. // given
  535. UA_UInt32 pos = 0;
  536. UA_Byte data[] = {
  537. 0x01, 0x00, // 1
  538. 0x00, 0x01 // 256
  539. };
  540. UA_ByteString src = { 4, data };
  541. // when
  542. UA_Int16 val_01_00, val_00_01;
  543. UA_Int32 retval = UA_Int16_decodeBinary(&src, &pos, &val_01_00);
  544. retval |= UA_Int16_decodeBinary(&src, &pos, &val_00_01);
  545. // then
  546. ck_assert_int_eq(retval, UA_SUCCESS);
  547. ck_assert_int_eq(val_01_00, 1);
  548. ck_assert_int_eq(val_00_01, 256);
  549. ck_assert_int_eq(pos, 4);
  550. }
  551. END_TEST
  552. START_TEST(UA_Int16_decodeShallRespectSign) {
  553. // given
  554. UA_UInt32 pos = 0;
  555. UA_Byte data[] = {
  556. 0xFF, 0xFF, // -1
  557. 0x00, 0x80 // -32768
  558. };
  559. UA_ByteString src = { 4, data };
  560. // when
  561. UA_Int16 val_ff_ff, val_00_80;
  562. UA_Int32 retval = UA_Int16_decodeBinary(&src, &pos, &val_ff_ff);
  563. retval |= UA_Int16_decodeBinary(&src, &pos, &val_00_80);
  564. // then
  565. ck_assert_int_eq(retval, UA_SUCCESS);
  566. ck_assert_int_eq(val_ff_ff, -1);
  567. ck_assert_int_eq(val_00_80, -32768);
  568. }
  569. END_TEST
  570. START_TEST(UA_UInt16_decodeShallNotRespectSign) {
  571. // given
  572. UA_UInt32 pos = 0;
  573. UA_Byte data[] = {
  574. 0xFF, 0xFF, // (2^16)-1
  575. 0x00, 0x80 // (2^15)
  576. };
  577. UA_ByteString src = { 4, data };
  578. // when
  579. UA_UInt16 val_ff_ff, val_00_80;
  580. UA_Int32 retval = UA_UInt16_decodeBinary(&src, &pos, &val_ff_ff);
  581. retval |= UA_UInt16_decodeBinary(&src, &pos, &val_00_80);
  582. // then
  583. ck_assert_int_eq(retval, UA_SUCCESS);
  584. ck_assert_int_eq(pos, 4);
  585. ck_assert_uint_eq(val_ff_ff, (0x01 << 16)-1);
  586. ck_assert_uint_eq(val_00_80, (0x01 << 15));
  587. }
  588. END_TEST
  589. START_TEST(UA_Int32_decodeShallAssumeLittleEndian) {
  590. // given
  591. UA_UInt32 pos = 0;
  592. UA_Byte data[] = {
  593. 0x01, 0x00, 0x00, 0x00, // 1
  594. 0x00, 0x01, 0x00, 0x00 // 256
  595. };
  596. UA_ByteString src = { 8, data };
  597. // when
  598. UA_Int32 val_01_00, val_00_01;
  599. UA_Int32 retval = UA_Int32_decodeBinary(&src, &pos, &val_01_00);
  600. retval |= UA_Int32_decodeBinary(&src, &pos, &val_00_01);
  601. // then
  602. ck_assert_int_eq(retval, UA_SUCCESS);
  603. ck_assert_int_eq(val_01_00, 1);
  604. ck_assert_int_eq(val_00_01, 256);
  605. ck_assert_int_eq(pos, 8);
  606. }
  607. END_TEST
  608. START_TEST(UA_Int32_decodeShallRespectSign) {
  609. // given
  610. UA_UInt32 pos = 0;
  611. UA_Byte data[] = {
  612. 0xFF, 0xFF, 0xFF, 0xFF, // -1
  613. 0x00, 0x80, 0xFF, 0xFF // -32768
  614. };
  615. UA_ByteString src = { 8, data };
  616. // when
  617. UA_Int32 val_ff_ff, val_00_80;
  618. UA_Int32 retval = UA_Int32_decodeBinary(&src, &pos, &val_ff_ff);
  619. retval |= UA_Int32_decodeBinary(&src, &pos, &val_00_80);
  620. // then
  621. ck_assert_int_eq(retval, UA_SUCCESS);
  622. ck_assert_int_eq(val_ff_ff, -1);
  623. ck_assert_int_eq(val_00_80, -32768);
  624. }
  625. END_TEST
  626. START_TEST(UA_UInt32_decodeShallNotRespectSign) {
  627. // given
  628. UA_UInt32 pos = 0;
  629. UA_Byte data[] = {
  630. 0xFF, 0xFF, 0xFF, 0xFF, // (2^32)-1
  631. 0x00, 0x00, 0x00, 0x80 // (2^31)
  632. };
  633. UA_ByteString src = { 8, data };
  634. // when
  635. UA_UInt32 val_ff_ff, val_00_80;
  636. UA_Int32 retval = UA_UInt32_decodeBinary(&src, &pos, &val_ff_ff);
  637. retval |= UA_UInt32_decodeBinary(&src, &pos, &val_00_80);
  638. // then
  639. ck_assert_int_eq(retval, UA_SUCCESS);
  640. ck_assert_int_eq(pos, 8);
  641. ck_assert_uint_eq(val_ff_ff, (UA_UInt32)( (0x01LL << 32 ) - 1 ));
  642. ck_assert_uint_eq(val_00_80, (UA_UInt32)(0x01 << 31));
  643. }
  644. END_TEST
  645. START_TEST(UA_UInt64_decodeShallNotRespectSign) {
  646. // given
  647. UA_ByteString rawMessage;
  648. UA_UInt64 expectedVal = 0xFF;
  649. expectedVal = expectedVal << 56;
  650. UA_Byte mem[8] = { 00, 00, 00, 00, 0x00, 0x00, 0x00, 0xFF };
  651. rawMessage.data = mem;
  652. rawMessage.length = 8;
  653. UA_UInt32 p = 0;
  654. UA_UInt64 val;
  655. // when
  656. UA_UInt64_decodeBinary(&rawMessage, &p, &val);
  657. // then
  658. ck_assert_uint_eq(val, expectedVal);
  659. }
  660. END_TEST
  661. START_TEST(UA_Int64_decodeShallRespectSign) {
  662. // given
  663. UA_ByteString rawMessage;
  664. UA_Int64 expectedVal = 0xFF;
  665. expectedVal = expectedVal << 56;
  666. UA_Byte mem[8] = { 00, 00, 00, 00, 0x00, 0x00, 0x00, 0xFF };
  667. rawMessage.data = mem;
  668. rawMessage.length = 8;
  669. UA_UInt32 p = 0;
  670. UA_Int64 val;
  671. // when
  672. UA_Int64_decodeBinary(&rawMessage, &p, &val);
  673. //then
  674. ck_assert_uint_eq(val, expectedVal);
  675. }
  676. END_TEST
  677. START_TEST(UA_Float_decodeShallWorkOnExample) {
  678. // given
  679. UA_UInt32 pos = 0;
  680. UA_Byte data[] = { 0x00, 0x00, 0xD0, 0xC0 }; // -6.5
  681. UA_ByteString src = { 4, data };
  682. UA_Float dst;
  683. // when
  684. UA_Int32 retval = UA_Float_decodeBinary(&src, &pos, &dst);
  685. // then
  686. ck_assert_int_eq(retval, UA_SUCCESS);
  687. ck_assert_int_eq(pos, 4);
  688. ck_assert(-6.5000001 < dst);
  689. ck_assert(dst < -6.49999999999);
  690. }
  691. END_TEST
  692. START_TEST(UA_Double_decodeShallGiveOne) {
  693. // given
  694. UA_UInt32 pos = 0;
  695. UA_Byte data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F }; // 1
  696. UA_ByteString src = { 8, data }; // 1
  697. UA_Double dst;
  698. // when
  699. UA_Int32 retval = UA_Double_decodeBinary(&src, &pos, &dst);
  700. // then
  701. ck_assert_int_eq(retval, UA_SUCCESS);
  702. ck_assert_int_eq(pos, 8);
  703. ck_assert(0.9999999 < dst);
  704. ck_assert(dst < 1.00000000001);
  705. }
  706. END_TEST
  707. START_TEST(UA_Double_decodeShallGiveZero) {
  708. // given
  709. UA_UInt32 pos = 0;
  710. UA_Byte data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  711. UA_ByteString src = { 8, data }; // 1
  712. UA_Double dst;
  713. // when
  714. UA_Int32 retval = UA_Double_decodeBinary(&src, &pos, &dst);
  715. // then
  716. ck_assert_int_eq(retval, UA_SUCCESS);
  717. ck_assert_int_eq(pos, 8);
  718. ck_assert(-0.00000001 < dst);
  719. ck_assert(dst < 0.000000001);
  720. }
  721. END_TEST
  722. START_TEST(UA_Double_decodeShallGiveMinusTwo) {
  723. // given
  724. UA_UInt32 pos = 0;
  725. UA_Byte data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0 }; // -2
  726. UA_ByteString src = { 8, data };
  727. UA_Double dst;
  728. // when
  729. UA_Int32 retval = UA_Double_decodeBinary(&src, &pos, &dst);
  730. // then
  731. ck_assert_int_eq(retval, UA_SUCCESS);
  732. ck_assert_int_eq(pos, 8);
  733. ck_assert(-1.9999999 > dst);
  734. ck_assert(dst > -2.00000000001);
  735. }
  736. END_TEST
  737. START_TEST(UA_String_decodeShallAllocateMemoryAndCopyString) {
  738. // given
  739. UA_UInt32 pos = 0;
  740. UA_Byte data[] =
  741. { 0x08, 0x00, 0x00, 0x00, 'A', 'C', 'P', 'L', 'T', ' ', 'U', 'A', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  742. UA_ByteString src = { 16, data };
  743. UA_String dst;
  744. // when
  745. UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
  746. // then
  747. ck_assert_int_eq(retval, UA_SUCCESS);
  748. ck_assert_int_eq(dst.length, 8);
  749. ck_assert_ptr_eq(dst.data, UA_alloc_lastptr);
  750. ck_assert_int_eq(dst.data[3], 'L');
  751. // finally
  752. UA_String_deleteMembers(&dst);
  753. }
  754. END_TEST
  755. START_TEST(UA_String_decodeWithNegativeSizeShallNotAllocateMemoryAndNullPtr) {
  756. // given
  757. UA_UInt32 pos = 0;
  758. UA_Byte data[] =
  759. { 0xFF, 0xFF, 0xFF, 0xFF, 'A', 'C', 'P', 'L', 'T', ' ', 'U', 'A', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  760. UA_ByteString src = { 16, data };
  761. UA_String dst;
  762. // when
  763. UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
  764. // then
  765. ck_assert_int_eq(retval, UA_SUCCESS);
  766. ck_assert_int_eq(dst.length, -1);
  767. ck_assert_ptr_eq(dst.data, UA_NULL);
  768. }
  769. END_TEST
  770. START_TEST(UA_String_decodeWithZeroSizeShallNotAllocateMemoryAndNullPtr) {
  771. // given
  772. UA_UInt32 pos = 0;
  773. UA_Byte data[] =
  774. { 0x00, 0x00, 0x00, 0x00, 'A', 'C', 'P', 'L', 'T', ' ', 'U', 'A', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  775. UA_ByteString src = { 16, data };
  776. UA_String dst = { 2, (UA_Byte *)"XX" };
  777. // when
  778. UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
  779. // then
  780. ck_assert_int_eq(retval, UA_SUCCESS);
  781. ck_assert_int_eq(dst.length, -1); // shall we keep zero?
  782. ck_assert_ptr_eq(dst.data, UA_NULL);
  783. }
  784. END_TEST
  785. START_TEST(UA_NodeId_decodeTwoByteShallReadTwoBytesAndSetNamespaceToZero) {
  786. // given
  787. UA_UInt32 pos = 0;
  788. UA_Byte data[] = { 0 /* UA_NODEIDTYPE_TWOBYTE */, 0x10 };
  789. UA_ByteString src = { 2, data };
  790. UA_NodeId dst;
  791. // when
  792. UA_Int32 retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
  793. // then
  794. ck_assert_int_eq(retval, UA_SUCCESS);
  795. ck_assert_int_eq(pos, 2);
  796. ck_assert_int_eq(dst.identifierType, UA_NODEIDTYPE_NUMERIC);
  797. ck_assert_int_eq(dst.identifier.numeric, 16);
  798. ck_assert_int_eq(dst.namespaceIndex, 0);
  799. }
  800. END_TEST
  801. START_TEST(UA_NodeId_decodeFourByteShallReadFourBytesAndRespectNamespace) {
  802. // given
  803. UA_UInt32 pos = 0;
  804. UA_Byte data[] = { 1 /* UA_NODEIDTYPE_FOURBYTE */, 0x01, 0x00, 0x01 };
  805. UA_ByteString src = { 4, data };
  806. UA_NodeId dst;
  807. // when
  808. UA_Int32 retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
  809. // then
  810. ck_assert_int_eq(retval, UA_SUCCESS);
  811. ck_assert_int_eq(pos, 4);
  812. ck_assert_int_eq(dst.identifierType, UA_NODEIDTYPE_NUMERIC);
  813. ck_assert_int_eq(dst.identifier.numeric, 256);
  814. ck_assert_int_eq(dst.namespaceIndex, 1);
  815. }
  816. END_TEST
  817. START_TEST(UA_NodeId_decodeStringShallAllocateMemory) {
  818. // given
  819. UA_UInt32 pos = 0;
  820. UA_Byte data[] = { UA_NODEIDTYPE_STRING, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 'P', 'L', 'T' };
  821. UA_ByteString src = { 10, data };
  822. UA_NodeId dst;
  823. // when
  824. UA_Int32 retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
  825. // then
  826. ck_assert_int_eq(retval, UA_SUCCESS);
  827. ck_assert_int_eq(pos, 10);
  828. ck_assert_int_eq(dst.identifierType, UA_NODEIDTYPE_STRING);
  829. ck_assert_int_eq(dst.namespaceIndex, 1);
  830. ck_assert_int_eq(dst.identifier.string.length, 3);
  831. ck_assert_ptr_eq(dst.identifier.string.data, UA_alloc_lastptr);
  832. ck_assert_int_eq(dst.identifier.string.data[1], 'L');
  833. // finally
  834. UA_NodeId_deleteMembers(&dst);
  835. }
  836. END_TEST
  837. START_TEST(UA_Variant_decodeWithOutArrayFlagSetShallSetVTAndAllocateMemoryForArray) {
  838. // given
  839. UA_UInt32 pos = 0;
  840. UA_Byte data[] = { UA_INT32_NS0, 0xFF, 0x00, 0x00, 0x00 };
  841. UA_ByteString src = { 5, data };
  842. UA_Variant dst;
  843. // when
  844. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  845. // then
  846. ck_assert_int_eq(retval, UA_SUCCESS);
  847. ck_assert_int_eq(pos, 5);
  848. ck_assert_ptr_eq(dst.vt, &UA_.types[UA_INT32]);
  849. ck_assert_int_eq(dst.arrayLength, 1);
  850. ck_assert_ptr_eq(dst.data, UA_alloc_lastptr);
  851. ck_assert_int_eq(*(UA_Int32 *)dst.data, 255);
  852. // finally
  853. UA_Variant_deleteMembers(&dst);
  854. }
  855. END_TEST
  856. START_TEST(UA_Variant_decodeWithArrayFlagSetShallSetVTAndAllocateMemoryForArray) {
  857. // given
  858. UA_UInt32 pos = 0;
  859. UA_Byte data[] =
  860. { UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF,
  861. 0xFF, 0xFF };
  862. UA_ByteString src = { 13, data };
  863. UA_Variant dst;
  864. // when
  865. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  866. // then
  867. ck_assert_int_eq(retval, UA_SUCCESS);
  868. ck_assert_int_eq(pos, 1+4+2*4);
  869. ck_assert_ptr_eq(dst.vt, &UA_.types[UA_INT32]);
  870. ck_assert_int_eq(dst.arrayLength, 2);
  871. ck_assert_ptr_eq(dst.data, UA_alloc_lastptr);
  872. ck_assert_int_eq(((UA_Int32 *)dst.data)[0], 255);
  873. ck_assert_int_eq(((UA_Int32 *)dst.data)[1], -1);
  874. // finally
  875. UA_Variant_deleteMembers(&dst);
  876. }
  877. END_TEST
  878. START_TEST(UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem) {
  879. // given
  880. UA_UInt32 pos = 0;
  881. UA_Byte data[] =
  882. { UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF,
  883. 0xFF, 0xFF };
  884. UA_ByteString src = { 13, data };
  885. UA_Variant dst;
  886. // when
  887. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  888. // then
  889. ck_assert_int_eq(retval, UA_SUCCESS);
  890. // finally
  891. UA_Variant_deleteMembers(&dst);
  892. }
  893. END_TEST
  894. START_TEST(UA_Variant_decodeWithTooSmallSourceShallReturnWithError) {
  895. // given
  896. UA_UInt32 pos = 0;
  897. UA_Byte data[] =
  898. { UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF,
  899. 0xFF, 0xFF };
  900. UA_ByteString src = { 4, data };
  901. UA_Variant dst;
  902. // when
  903. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  904. // then
  905. ck_assert_int_ne(retval, UA_SUCCESS);
  906. // finally
  907. UA_Variant_deleteMembers(&dst);
  908. }
  909. END_TEST
  910. START_TEST(UA_Byte_encode_test) {
  911. // given
  912. UA_Byte src;
  913. UA_Byte data[] = { 0x00, 0xFF };
  914. UA_ByteString dst = { 2, data };
  915. UA_Int32 retval = 0;
  916. UA_UInt32 pos = 0;
  917. ck_assert_uint_eq(dst.data[1], 0xFF);
  918. src = 8;
  919. retval = UA_Byte_encodeBinary(&src, &dst, &pos);
  920. ck_assert_uint_eq(dst.data[0], 0x08);
  921. ck_assert_uint_eq(dst.data[1], 0xFF);
  922. ck_assert_int_eq(pos, 1);
  923. ck_assert_int_eq(retval, UA_SUCCESS);
  924. // Test2
  925. // given
  926. src = 0xFF;
  927. dst.data[1] = 0x00;
  928. pos = 0;
  929. retval = UA_Byte_encodeBinary(&src, &dst, &pos);
  930. ck_assert_int_eq(dst.data[0], 0xFF);
  931. ck_assert_int_eq(dst.data[1], 0x00);
  932. ck_assert_int_eq(pos, 1);
  933. ck_assert_int_eq(retval, UA_SUCCESS);
  934. }
  935. END_TEST
  936. START_TEST(UA_UInt16_encodeNegativeShallEncodeLittleEndian) {
  937. // given
  938. UA_UInt16 src;
  939. UA_Byte data[] = { 0x55, 0x55,
  940. 0x55, 0x55 };
  941. UA_ByteString dst = { 4, data };
  942. UA_Int32 retval = 0;
  943. UA_UInt32 pos = 0;
  944. // when test 1
  945. src = -1;
  946. retval = UA_UInt16_encodeBinary(&src, &dst, &pos);
  947. // then test 1
  948. ck_assert_int_eq(pos, 2);
  949. ck_assert_int_eq(dst.data[0], 0xFF);
  950. ck_assert_int_eq(dst.data[1], 0xFF);
  951. ck_assert_int_eq(retval, UA_SUCCESS);
  952. // when test 2
  953. src = -32768;
  954. retval = UA_UInt16_encodeBinary(&src, &dst, &pos);
  955. // then test 2
  956. ck_assert_int_eq(pos, 4);
  957. ck_assert_int_eq(dst.data[2], 0x00);
  958. ck_assert_int_eq(dst.data[3], 0x80);
  959. ck_assert_int_eq(retval, UA_SUCCESS);
  960. }
  961. END_TEST
  962. START_TEST(UA_UInt16_encodeShallEncodeLittleEndian) {
  963. // given
  964. UA_UInt16 src;
  965. UA_Byte data[] = { 0x55, 0x55,
  966. 0x55, 0x55 };
  967. UA_ByteString dst = { 4, data };
  968. UA_Int32 retval = 0;
  969. UA_UInt32 pos = 0;
  970. // when test 1
  971. src = 0;
  972. retval = UA_UInt16_encodeBinary(&src, &dst, &pos);
  973. // then test 1
  974. ck_assert_int_eq(pos, 2);
  975. ck_assert_int_eq(dst.data[0], 0x00);
  976. ck_assert_int_eq(dst.data[1], 0x00);
  977. ck_assert_int_eq(retval, UA_SUCCESS);
  978. // when test 2
  979. src = 32767;
  980. retval = UA_UInt16_encodeBinary(&src, &dst, &pos);
  981. // then test 2
  982. ck_assert_int_eq(pos, 4);
  983. ck_assert_int_eq(dst.data[2], 0xFF);
  984. ck_assert_int_eq(dst.data[3], 0x7F);
  985. ck_assert_int_eq(retval, UA_SUCCESS);
  986. }
  987. END_TEST
  988. START_TEST(UA_UInt32_encodeShallEncodeLittleEndian) {
  989. // given
  990. UA_UInt32 src;
  991. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55,
  992. 0x55, 0x55, 0x55, 0x55 };
  993. UA_ByteString dst = { 8, data };
  994. UA_Int32 retval = 0;
  995. UA_UInt32 pos = 0;
  996. // when test 1
  997. src = -1;
  998. retval = UA_UInt32_encodeBinary(&src, &dst, &pos);
  999. // then test 1
  1000. ck_assert_int_eq(pos, 4);
  1001. ck_assert_int_eq(dst.data[0], 0xFF);
  1002. ck_assert_int_eq(dst.data[1], 0xFF);
  1003. ck_assert_int_eq(dst.data[2], 0xFF);
  1004. ck_assert_int_eq(dst.data[3], 0xFF);
  1005. ck_assert_int_eq(retval, UA_SUCCESS);
  1006. // when test 2
  1007. src = 0x0101FF00;
  1008. retval = UA_UInt32_encodeBinary(&src, &dst, &pos);
  1009. // then test 2
  1010. ck_assert_int_eq(pos, 8);
  1011. ck_assert_int_eq(dst.data[4], 0x00);
  1012. ck_assert_int_eq(dst.data[5], 0xFF);
  1013. ck_assert_int_eq(dst.data[6], 0x01);
  1014. ck_assert_int_eq(dst.data[7], 0x01);
  1015. ck_assert_int_eq(retval, UA_SUCCESS);
  1016. }
  1017. END_TEST
  1018. START_TEST(UA_Int32_encodeShallEncodeLittleEndian) {
  1019. // given
  1020. UA_Int32 src;
  1021. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55,
  1022. 0x55, 0x55, 0x55, 0x55 };
  1023. UA_ByteString dst = { 8, data };
  1024. UA_Int32 retval = 0;
  1025. UA_UInt32 pos = 0;
  1026. // when test 1
  1027. src = 1;
  1028. retval = UA_Int32_encodeBinary(&src, &dst, &pos);
  1029. // then test 1
  1030. ck_assert_int_eq(pos, 4);
  1031. ck_assert_int_eq(dst.data[0], 0x01);
  1032. ck_assert_int_eq(dst.data[1], 0x00);
  1033. ck_assert_int_eq(dst.data[2], 0x00);
  1034. ck_assert_int_eq(dst.data[3], 0x00);
  1035. ck_assert_int_eq(retval, UA_SUCCESS);
  1036. // when test 2
  1037. src = 0x7FFFFFFF;
  1038. retval = UA_Int32_encodeBinary(&src, &dst, &pos);
  1039. // then test 2
  1040. ck_assert_int_eq(pos, 8);
  1041. ck_assert_int_eq(dst.data[4], 0xFF);
  1042. ck_assert_int_eq(dst.data[5], 0xFF);
  1043. ck_assert_int_eq(dst.data[6], 0xFF);
  1044. ck_assert_int_eq(dst.data[7], 0x7F);
  1045. ck_assert_int_eq(retval, UA_SUCCESS);
  1046. }
  1047. END_TEST
  1048. START_TEST(UA_Int32_encodeNegativeShallEncodeLittleEndian) {
  1049. // given
  1050. UA_Int32 src;
  1051. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55,
  1052. 0x55, 0x55, 0x55, 0x55 };
  1053. UA_ByteString dst = { 8, data };
  1054. UA_Int32 retval = 0;
  1055. UA_UInt32 pos = 0;
  1056. // when test 1
  1057. src = -1;
  1058. retval = UA_Int32_encodeBinary(&src, &dst, &pos);
  1059. // then test 1
  1060. ck_assert_int_eq(pos, 4);
  1061. ck_assert_int_eq(dst.data[0], 0xFF);
  1062. ck_assert_int_eq(dst.data[1], 0xFF);
  1063. ck_assert_int_eq(dst.data[2], 0xFF);
  1064. ck_assert_int_eq(dst.data[3], 0xFF);
  1065. ck_assert_int_eq(retval, UA_SUCCESS);
  1066. }
  1067. END_TEST
  1068. START_TEST(UA_UInt64_encodeShallWorkOnExample) {
  1069. // given
  1070. UA_UInt64 src;
  1071. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  1072. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
  1073. UA_ByteString dst = { 16, data };
  1074. UA_Int32 retval = 0;
  1075. UA_UInt32 pos = 0;
  1076. // when test 1
  1077. src = -1;
  1078. retval = UA_UInt64_encodeBinary(&src, &dst, &pos);
  1079. // then test 1
  1080. ck_assert_int_eq(pos, 8);
  1081. ck_assert_int_eq(dst.data[0], 0xFF);
  1082. ck_assert_int_eq(dst.data[1], 0xFF);
  1083. ck_assert_int_eq(dst.data[2], 0xFF);
  1084. ck_assert_int_eq(dst.data[3], 0xFF);
  1085. ck_assert_int_eq(dst.data[4], 0xFF);
  1086. ck_assert_int_eq(dst.data[5], 0xFF);
  1087. ck_assert_int_eq(dst.data[6], 0xFF);
  1088. ck_assert_int_eq(dst.data[7], 0xFF);
  1089. ck_assert_int_eq(retval, UA_SUCCESS);
  1090. // when test 2
  1091. src = 0x7F0033AA44EE6611;
  1092. retval = UA_UInt64_encodeBinary(&src, &dst, &pos);
  1093. // then test 2
  1094. ck_assert_int_eq(pos, 16);
  1095. ck_assert_int_eq(dst.data[8], 0x11);
  1096. ck_assert_int_eq(dst.data[9], 0x66);
  1097. ck_assert_int_eq(dst.data[10], 0xEE);
  1098. ck_assert_int_eq(dst.data[11], 0x44);
  1099. ck_assert_int_eq(dst.data[12], 0xAA);
  1100. ck_assert_int_eq(dst.data[13], 0x33);
  1101. ck_assert_int_eq(dst.data[14], 0x00);
  1102. ck_assert_int_eq(dst.data[15], 0x7F);
  1103. ck_assert_int_eq(retval, UA_SUCCESS);
  1104. }
  1105. END_TEST
  1106. START_TEST(UA_Int64_encodeShallEncodeLittleEndian) {
  1107. // given
  1108. UA_Int64 src;
  1109. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  1110. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
  1111. UA_ByteString dst = { 16, data };
  1112. UA_Int32 retval = 0;
  1113. UA_UInt32 pos = 0;
  1114. // when test 1
  1115. src = 0x7F0033AA44EE6611;
  1116. retval = UA_Int64_encodeBinary(&src, &dst, &pos);
  1117. // then test 1
  1118. ck_assert_int_eq(pos, 8);
  1119. ck_assert_int_eq(dst.data[0], 0x11);
  1120. ck_assert_int_eq(dst.data[1], 0x66);
  1121. ck_assert_int_eq(dst.data[2], 0xEE);
  1122. ck_assert_int_eq(dst.data[3], 0x44);
  1123. ck_assert_int_eq(dst.data[4], 0xAA);
  1124. ck_assert_int_eq(dst.data[5], 0x33);
  1125. ck_assert_int_eq(dst.data[6], 0x00);
  1126. ck_assert_int_eq(dst.data[7], 0x7F);
  1127. ck_assert_int_eq(retval, UA_SUCCESS);
  1128. }
  1129. END_TEST
  1130. START_TEST(UA_Int64_encodeNegativeShallEncodeLittleEndian) {
  1131. // given
  1132. UA_Int64 src;
  1133. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  1134. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
  1135. UA_ByteString dst = { 16, data };
  1136. UA_Int32 retval = 0;
  1137. UA_UInt32 pos = 0;
  1138. // when test 1
  1139. src = -1;
  1140. retval = UA_Int64_encodeBinary(&src, &dst, &pos);
  1141. // then test 1
  1142. ck_assert_int_eq(pos, 8);
  1143. ck_assert_int_eq(dst.data[0], 0xFF);
  1144. ck_assert_int_eq(dst.data[1], 0xFF);
  1145. ck_assert_int_eq(dst.data[2], 0xFF);
  1146. ck_assert_int_eq(dst.data[3], 0xFF);
  1147. ck_assert_int_eq(dst.data[4], 0xFF);
  1148. ck_assert_int_eq(dst.data[5], 0xFF);
  1149. ck_assert_int_eq(dst.data[6], 0xFF);
  1150. ck_assert_int_eq(dst.data[7], 0xFF);
  1151. ck_assert_int_eq(retval, UA_SUCCESS);
  1152. }
  1153. END_TEST
  1154. START_TEST(UA_Float_encodeShallWorkOnExample) {
  1155. // given
  1156. UA_Float src;
  1157. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  1158. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
  1159. UA_ByteString dst = { 16, data };
  1160. UA_Int32 retval = 0;
  1161. UA_UInt32 pos = 0;
  1162. // when test 1
  1163. src = -6.5;
  1164. retval = UA_Float_encodeBinary(&src, &dst, &pos);
  1165. // then test 1
  1166. ck_assert_int_eq(pos, 4);
  1167. ck_assert_int_eq(dst.data[2], 0xD0);
  1168. ck_assert_int_eq(dst.data[3], 0xC0);
  1169. ck_assert_int_eq(retval, UA_SUCCESS);
  1170. }
  1171. END_TEST
  1172. /*START_TEST(UA_Double_encodeShallWorkOnExample)
  1173. {
  1174. // given
  1175. UA_Double src;
  1176. UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
  1177. 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
  1178. };
  1179. UA_ByteString dst = {16,data};
  1180. UA_Int32 retval, pos = 0;
  1181. // when test 1
  1182. src = -6.5;
  1183. retval = UA_Double_encodeBinary(&src, &pos, &dst);
  1184. // then test 1
  1185. ck_assert_int_eq(pos, 8);
  1186. ck_assert_int_eq(dst.data[6], 0xD0);
  1187. ck_assert_int_eq(dst.data[7], 0xC0);
  1188. ck_assert_int_eq(retval, UA_SUCCESS);
  1189. }
  1190. END_TEST*/
  1191. START_TEST(UA_String_encodeShallWorkOnExample) {
  1192. // given
  1193. UA_String src;
  1194. src.length = 11;
  1195. UA_Byte mem[11] = "ACPLT OPCUA";
  1196. src.data = mem;
  1197. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  1198. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  1199. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
  1200. UA_ByteString dst = { 24, data };
  1201. UA_Int32 retval = 0;
  1202. UA_UInt32 pos = 0;
  1203. // when
  1204. retval = UA_String_encodeBinary(&src, &dst, &pos);
  1205. // then
  1206. ck_assert_int_eq(pos, sizeof(UA_Int32)+11);
  1207. ck_assert_int_eq(dst.data[0], 11);
  1208. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+0], 'A');
  1209. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+1], 'C');
  1210. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+2], 'P');
  1211. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+3], 'L');
  1212. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+4], 'T');
  1213. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+5], 0x20); //Space
  1214. ck_assert_int_eq(retval, UA_SUCCESS);
  1215. }
  1216. END_TEST
  1217. START_TEST(UA_DataValue_encodeShallWorkOnExampleWithoutVariant) {
  1218. // given
  1219. UA_DataValue src;
  1220. src.serverTimestamp = 80;
  1221. src.encodingMask = UA_DATAVALUE_ENCODINGMASK_SERVERTIMESTAMP; //Only the sourcePicoseconds
  1222. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  1223. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  1224. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
  1225. UA_ByteString dst = { 24, data };
  1226. UA_Int32 retval = 0;
  1227. UA_UInt32 pos = 0;
  1228. // when
  1229. retval = UA_DataValue_encodeBinary(&src, &dst, &pos);
  1230. // then
  1231. ck_assert_int_eq(pos, 9); // represents the length
  1232. ck_assert_int_eq(dst.data[0], 0x08); // encodingMask
  1233. ck_assert_int_eq(dst.data[1], 80); // 8 Byte serverTimestamp
  1234. ck_assert_int_eq(dst.data[2], 0);
  1235. ck_assert_int_eq(dst.data[3], 0);
  1236. ck_assert_int_eq(dst.data[4], 0);
  1237. ck_assert_int_eq(dst.data[5], 0);
  1238. ck_assert_int_eq(dst.data[6], 0);
  1239. ck_assert_int_eq(dst.data[7], 0);
  1240. ck_assert_int_eq(dst.data[8], 0);
  1241. ck_assert_int_eq(retval, UA_SUCCESS);
  1242. }
  1243. END_TEST
  1244. START_TEST(UA_DataValue_encodeShallWorkOnExampleWithVariant) {
  1245. // given
  1246. UA_DataValue src;
  1247. src.serverTimestamp = 80;
  1248. src.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT | UA_DATAVALUE_ENCODINGMASK_SERVERTIMESTAMP; //Variant & SourvePicoseconds
  1249. UA_Variant_init(&src.value);
  1250. src.value.vt = &UA_.types[UA_INT32];
  1251. src.value.arrayLength = 1; // one element (encoded as not an array)
  1252. UA_Int32 vdata = 45;
  1253. src.value.data = (void *)&vdata;
  1254. UA_Byte data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1255. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1256. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1257. UA_ByteString dst = { 24, data };
  1258. UA_Int32 retval = 0;
  1259. UA_UInt32 pos = 0;
  1260. // when
  1261. retval = UA_DataValue_encodeBinary(&src, &dst, &pos);
  1262. // then
  1263. ck_assert_int_eq(pos, 1+(1+4)+8); // represents the length
  1264. ck_assert_int_eq(dst.data[0], 0x08 | 0x01); // encodingMask
  1265. ck_assert_int_eq(dst.data[1], 0x06); // Variant's Encoding Mask - INT32
  1266. ck_assert_int_eq(dst.data[2], 45); // the single value
  1267. ck_assert_int_eq(dst.data[3], 0);
  1268. ck_assert_int_eq(dst.data[4], 0);
  1269. ck_assert_int_eq(dst.data[5], 0);
  1270. ck_assert_int_eq(dst.data[6], 80); // the server timestamp
  1271. ck_assert_int_eq(dst.data[7], 0);
  1272. ck_assert_int_eq(retval, UA_SUCCESS);
  1273. }
  1274. END_TEST
  1275. START_TEST(UA_DateTime_toStructShallWorkOnExample) {
  1276. // given
  1277. UA_DateTime src = 13974671891234567;
  1278. //1397467189... is Mon, 14 Apr 2014 09:19:49 GMT
  1279. //...1234567 are the milli-, micro- and nanoseconds
  1280. UA_DateTimeStruct dst;
  1281. // when
  1282. dst = UA_DateTime_toStruct(src);
  1283. // then
  1284. ck_assert_int_eq(dst.nanoSec, 700);
  1285. ck_assert_int_eq(dst.microSec, 456);
  1286. ck_assert_int_eq(dst.milliSec, 123);
  1287. ck_assert_int_eq(dst.sec, 49);
  1288. ck_assert_int_eq(dst.min, 19);
  1289. ck_assert_int_eq(dst.hour, 9);
  1290. ck_assert_int_eq(dst.day, 14);
  1291. ck_assert_int_eq(dst.mounth, 4);
  1292. ck_assert_int_eq(dst.year, 2014);
  1293. }
  1294. END_TEST
  1295. START_TEST(UA_DateTime_toStringShallWorkOnExample) {
  1296. // given
  1297. UA_DateTime src = 13974671891234567;
  1298. //1397467189... is Mon, 14 Apr 2014 09:19:49 GMT
  1299. //...1234567 are the milli-, micro- and nanoseconds
  1300. char buf[80] = "80";
  1301. UA_Byte *byteBuf = (UA_Byte *)buf;
  1302. UA_String dst = { 80, byteBuf };
  1303. // when
  1304. UA_DateTime_toString(src, &dst);
  1305. // then
  1306. ck_assert_int_eq(dst.length, 80);
  1307. ck_assert_int_eq(dst.data[0], ' ');
  1308. ck_assert_int_eq(dst.data[1], '4');
  1309. ck_assert_int_eq(dst.data[2], '/');
  1310. ck_assert_int_eq(dst.data[3], '1');
  1311. ck_assert_int_eq(dst.data[4], '4');
  1312. }
  1313. END_TEST
  1314. START_TEST(UA_ExtensionObject_copyShallWorkOnExample) {
  1315. // given
  1316. UA_Byte data[3] = { 1, 2, 3 };
  1317. UA_ExtensionObject value, valueCopied;
  1318. UA_ExtensionObject_init(&value);
  1319. UA_ExtensionObject_init(&valueCopied);
  1320. value.typeId.identifierType = UA_NODEIDTYPE_NUMERIC;
  1321. value.typeId.identifier.numeric = UA_BYTE;
  1322. value.encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_NOBODYISENCODED;
  1323. value.encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING;
  1324. value.body.data = data;
  1325. value.body.length = 3;
  1326. //when
  1327. UA_ExtensionObject_copy(&value, &valueCopied);
  1328. for(UA_Int32 i = 0;i < 3;i++)
  1329. ck_assert_int_eq(valueCopied.body.data[i], value.body.data[i]);
  1330. ck_assert_int_eq(valueCopied.encoding, value.encoding);
  1331. ck_assert_int_eq(valueCopied.typeId.identifierType, value.typeId.identifierType);
  1332. ck_assert_int_eq(valueCopied.typeId.identifier.numeric, value.typeId.identifier.numeric);
  1333. //finally
  1334. value.body.data = UA_NULL; // we cannot free the static string
  1335. UA_ExtensionObject_deleteMembers(&value);
  1336. UA_ExtensionObject_deleteMembers(&valueCopied);
  1337. }
  1338. END_TEST
  1339. START_TEST(UA_Array_copyByteArrayShallWorkOnExample) {
  1340. //given
  1341. UA_String testString;
  1342. UA_Byte *dstArray;
  1343. UA_Int32 size = 5;
  1344. UA_Int32 i = 0;
  1345. UA_alloc((void **)&testString.data, size);
  1346. testString.data[0] = 'O';
  1347. testString.data[1] = 'P';
  1348. testString.data[2] = 'C';
  1349. testString.data[3] = 'U';
  1350. testString.data[4] = 'A';
  1351. testString.length = 5;
  1352. //when
  1353. UA_Array_copy((const void *)testString.data, 5, &UA_.types[UA_BYTE], (void **)&dstArray);
  1354. //then
  1355. for(i = 0;i < size;i++)
  1356. ck_assert_int_eq(testString.data[i], dstArray[i]);
  1357. //finally
  1358. UA_String_deleteMembers(&testString);
  1359. UA_free((void *)dstArray);
  1360. }
  1361. END_TEST
  1362. START_TEST(UA_Array_copyUA_StringShallWorkOnExample) {
  1363. // given
  1364. UA_Int32 i, j;
  1365. UA_String *srcArray;
  1366. UA_Array_new((void **)&srcArray, 3, &UA_.types[UA_STRING]);
  1367. UA_String *dstArray;
  1368. UA_String_copycstring("open", &srcArray[0]);
  1369. UA_String_copycstring("62541", &srcArray[1]);
  1370. UA_String_copycstring("opc ua", &srcArray[2]);
  1371. //when
  1372. UA_Array_copy((const void *)srcArray, 3, &UA_.types[UA_STRING], (void **)&dstArray);
  1373. //then
  1374. for(i = 0;i < 3;i++) {
  1375. for(j = 0;j < 3;j++)
  1376. ck_assert_int_eq(srcArray[i].data[j], dstArray[i].data[j]);
  1377. ck_assert_int_eq(srcArray[i].length, dstArray[i].length);
  1378. }
  1379. //finally
  1380. UA_Array_delete(srcArray, 3, &UA_.types[UA_STRING]);
  1381. UA_Array_delete(dstArray, 3, &UA_.types[UA_STRING]);
  1382. }
  1383. END_TEST
  1384. START_TEST(UA_DiagnosticInfo_copyShallWorkOnExample) {
  1385. //given
  1386. UA_DiagnosticInfo value, innerValue, copiedValue;
  1387. UA_String testString = (UA_String){5, (UA_Byte*)"OPCUA"};
  1388. UA_DiagnosticInfo_init(&value);
  1389. UA_DiagnosticInfo_init(&innerValue);
  1390. value.encodingMask |= UA_DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO;
  1391. value.innerDiagnosticInfo = &innerValue;
  1392. value.additionalInfo = testString;
  1393. //when
  1394. UA_DiagnosticInfo_copy(&value, &copiedValue);
  1395. //then
  1396. for(UA_Int32 i = 0;i < testString.length;i++)
  1397. ck_assert_int_eq(copiedValue.additionalInfo.data[i], value.additionalInfo.data[i]);
  1398. ck_assert_int_eq(copiedValue.additionalInfo.length, value.additionalInfo.length);
  1399. ck_assert_int_eq(copiedValue.encodingMask, value.encodingMask);
  1400. ck_assert_int_eq(copiedValue.innerDiagnosticInfo->locale, value.innerDiagnosticInfo->locale);
  1401. ck_assert_int_eq(copiedValue.innerStatusCode, value.innerStatusCode);
  1402. ck_assert_int_eq(copiedValue.locale, value.locale);
  1403. ck_assert_int_eq(copiedValue.localizedText, value.localizedText);
  1404. ck_assert_int_eq(copiedValue.namespaceUri, value.namespaceUri);
  1405. ck_assert_int_eq(copiedValue.symbolicId, value.symbolicId);
  1406. //finally
  1407. value.additionalInfo.data = UA_NULL; // do not delete the static string
  1408. value.innerDiagnosticInfo = UA_NULL; // do not delete the static innerdiagnosticinfo
  1409. UA_DiagnosticInfo_deleteMembers(&value);
  1410. UA_DiagnosticInfo_deleteMembers(&copiedValue);
  1411. }
  1412. END_TEST
  1413. START_TEST(UA_ApplicationDescription_copyShallWorkOnExample) {
  1414. //given
  1415. UA_Int32 retval = UA_SUCCESS;
  1416. UA_String appString = (UA_String){3, (UA_Byte*)"APP"};
  1417. UA_String discString = (UA_String){4, (UA_Byte*)"DISC"};
  1418. UA_String gateWayString = (UA_String){7, (UA_Byte*)"GATEWAY"};
  1419. UA_String srcArray[3];
  1420. srcArray[0] = (UA_String){ 6, (UA_Byte*)"__open" };
  1421. srcArray[1] = (UA_String){ 6, (UA_Byte*)"_62541" };
  1422. srcArray[2] = (UA_String){ 6, (UA_Byte*)"opc ua" };
  1423. UA_ApplicationDescription value, copiedValue;
  1424. UA_ApplicationDescription_init(&value);
  1425. value.applicationUri = appString;
  1426. value.discoveryProfileUri = discString;
  1427. value.gatewayServerUri = gateWayString;
  1428. value.discoveryUrlsSize = 3;
  1429. value.discoveryUrls = srcArray;
  1430. //when
  1431. retval = UA_ApplicationDescription_copy(&value, &copiedValue);
  1432. //then
  1433. ck_assert_int_eq(retval, UA_SUCCESS);
  1434. for(UA_Int32 i = 0;i < appString.length;i++)
  1435. ck_assert_int_eq(copiedValue.applicationUri.data[i], value.applicationUri.data[i]);
  1436. ck_assert_int_eq(copiedValue.applicationUri.length, value.applicationUri.length);
  1437. for(UA_Int32 i = 0;i < discString.length;i++)
  1438. ck_assert_int_eq(copiedValue.discoveryProfileUri.data[i], value.discoveryProfileUri.data[i]);
  1439. ck_assert_int_eq(copiedValue.discoveryProfileUri.length, value.discoveryProfileUri.length);
  1440. for(UA_Int32 i = 0;i < gateWayString.length;i++)
  1441. ck_assert_int_eq(copiedValue.gatewayServerUri.data[i], value.gatewayServerUri.data[i]);
  1442. ck_assert_int_eq(copiedValue.gatewayServerUri.length, value.gatewayServerUri.length);
  1443. //String Array Test
  1444. for(UA_Int32 i = 0;i < 3;i++) {
  1445. for(UA_Int32 j = 0;j < 6;j++)
  1446. ck_assert_int_eq(value.discoveryUrls[i].data[j], copiedValue.discoveryUrls[i].data[j]);
  1447. ck_assert_int_eq(value.discoveryUrls[i].length, copiedValue.discoveryUrls[i].length);
  1448. }
  1449. ck_assert_int_eq(copiedValue.discoveryUrls[0].data[2], 'o');
  1450. ck_assert_int_eq(copiedValue.discoveryUrls[0].data[3], 'p');
  1451. ck_assert_int_eq(copiedValue.discoveryUrlsSize, value.discoveryUrlsSize);
  1452. //finally
  1453. // UA_ApplicationDescription_deleteMembers(&value); // do not free the members as they are statically allocated
  1454. UA_ApplicationDescription_deleteMembers(&copiedValue);
  1455. }
  1456. END_TEST
  1457. START_TEST(UA_QualifiedName_copyShallWorkOnInputExample) {
  1458. // given
  1459. UA_String srcName = (UA_String){8, (UA_Byte*)"tEsT123!"};
  1460. UA_QualifiedName src = {5, srcName};
  1461. UA_QualifiedName dst;
  1462. UA_Int32 ret;
  1463. // when
  1464. ret = UA_QualifiedName_copy(&src, &dst);
  1465. // then
  1466. ck_assert_int_eq(ret, UA_SUCCESS);
  1467. ck_assert_int_eq('E', dst.name.data[1]);
  1468. ck_assert_int_eq('!', dst.name.data[7]);
  1469. ck_assert_int_eq(8, dst.name.length);
  1470. ck_assert_int_eq(5, dst.namespaceIndex);
  1471. }
  1472. END_TEST
  1473. START_TEST(UA_QualifiedName_copyNULLInput) {
  1474. // given
  1475. UA_QualifiedName *src;
  1476. src = UA_NULL;
  1477. UA_QualifiedName dst;
  1478. UA_Int32 ret;
  1479. // when
  1480. ret = UA_QualifiedName_copy(src, &dst);
  1481. // then
  1482. ck_assert_int_eq(ret, UA_ERROR);
  1483. }
  1484. END_TEST
  1485. START_TEST(UA_Guid_copyShallWorkOnInputExample) {
  1486. //given
  1487. const UA_Guid src = {3, 45, 1222, {8, 7, 6, 5, 4, 3, 2, 1}};
  1488. UA_Guid dst;
  1489. UA_Int32 ret;
  1490. //when
  1491. ret = UA_Guid_copy(&src, &dst);
  1492. //then
  1493. ck_assert_int_eq(ret, UA_SUCCESS);
  1494. ck_assert_int_eq(src.data1, dst.data1);
  1495. ck_assert_int_eq(src.data3, dst.data3);
  1496. ck_assert_int_eq(src.data4[4], dst.data4[4]);
  1497. //finally
  1498. }
  1499. END_TEST
  1500. START_TEST(UA_Guid_copyWithNullArgumentShallReturn) {
  1501. //given
  1502. UA_Guid *src = UA_NULL;
  1503. UA_Guid *dst = UA_NULL;
  1504. UA_Int32 ret;
  1505. //when
  1506. ret = UA_Guid_copy(src, dst);
  1507. //then
  1508. ck_assert_int_eq(ret, UA_ERROR);
  1509. //finally
  1510. }
  1511. END_TEST
  1512. START_TEST(UA_LocalizedText_copycstringShallWorkOnInputExample) {
  1513. // given
  1514. const char src[7] = {'t', 'e', 'X', 't', '1', '2', '3'};
  1515. UA_LocalizedText dst;
  1516. UA_Int32 ret;
  1517. // when
  1518. ret = UA_LocalizedText_copycstring(src, &dst);
  1519. // then
  1520. ck_assert_int_eq(ret, UA_SUCCESS);
  1521. ck_assert_int_eq('E', dst.locale.data[0]);
  1522. ck_assert_int_eq('N', dst.locale.data[1]);
  1523. ck_assert_int_eq('1', dst.text.data[4]);
  1524. ck_assert_int_eq(2, dst.locale.length);
  1525. ck_assert_int_eq(7, dst.text.length);
  1526. }
  1527. END_TEST
  1528. START_TEST(UA_LocalizedText_copycstringNULLInput) {
  1529. // given
  1530. const char src[7] = {'t', 'e', 'X', 't', '1', '2', '3'};
  1531. UA_LocalizedText *dst = UA_NULL;
  1532. UA_Int32 ret;
  1533. // when
  1534. ret = UA_LocalizedText_copycstring(src, dst);
  1535. // then
  1536. ck_assert_int_eq(ret, UA_ERROR);
  1537. }
  1538. END_TEST
  1539. START_TEST(UA_DataValue_copyShallWorkOnInputExample) {
  1540. // given
  1541. UA_Variant srcVariant;
  1542. UA_Variant_init(&srcVariant);
  1543. UA_DataValue src = {5, srcVariant, 44, 4, 77, 58, 8};
  1544. UA_DataValue dst;
  1545. UA_Int32 ret;
  1546. // when
  1547. ret = UA_DataValue_copy(&src, &dst);
  1548. // then
  1549. ck_assert_int_eq(ret, UA_SUCCESS);
  1550. ck_assert_int_eq(5, dst.encodingMask);
  1551. ck_assert_int_eq(4, dst.sourceTimestamp);
  1552. ck_assert_int_eq(77, dst.sourcePicoseconds);
  1553. ck_assert_int_eq(8, dst.serverPicoseconds);
  1554. }
  1555. END_TEST
  1556. START_TEST(UA_Variant_copyShallWorkOnSingleValueExample) {
  1557. //given
  1558. UA_String testString = (UA_String){5, (UA_Byte*)"OPCUA"};
  1559. UA_Variant value, copiedValue;
  1560. UA_Variant_init(&value);
  1561. UA_Variant_init(&copiedValue);
  1562. UA_alloc((void**)&value.data, sizeof(UA_String));
  1563. *((UA_String*)value.data) = testString;
  1564. value.vt = &UA_.types[UA_STRING];
  1565. value.arrayLength = 1;
  1566. //when
  1567. UA_Variant_copy(&value, &copiedValue);
  1568. //then
  1569. UA_String copiedString = *(UA_String*)(copiedValue.data);
  1570. for(UA_Int32 i = 0;i < 5;i++)
  1571. ck_assert_int_eq(copiedString.data[i], testString.data[i]);
  1572. ck_assert_int_eq(copiedString.length, testString.length);
  1573. ck_assert_int_eq(value.arrayDimensionsLength, copiedValue.arrayDimensionsLength);
  1574. ck_assert_int_eq(value.arrayLength, copiedValue.arrayLength);
  1575. //finally
  1576. ((UA_String*)value.data)->data = UA_NULL; // the string is statically allocated. do not free it.
  1577. UA_Variant_deleteMembers(&value);
  1578. UA_Variant_deleteMembers(&copiedValue);
  1579. }
  1580. END_TEST
  1581. START_TEST(UA_Variant_copyShallWorkOn1DArrayExample) {
  1582. // given
  1583. UA_String *srcArray;
  1584. UA_Array_new((void **)&srcArray, 3, &UA_.types[UA_STRING]);
  1585. UA_String_copycstring("__open", &srcArray[0]);
  1586. UA_String_copycstring("_62541", &srcArray[1]);
  1587. UA_String_copycstring("opc ua", &srcArray[2]);
  1588. UA_Int32 *dimensions;
  1589. UA_alloc((void **)&dimensions, UA_Int32_calcSizeBinary(UA_NULL));
  1590. dimensions[0] = 3;
  1591. UA_Variant value, copiedValue;
  1592. UA_Variant_init(&value);
  1593. UA_Variant_init(&copiedValue);
  1594. value.arrayLength = 3;
  1595. value.data = (void **)srcArray;
  1596. value.arrayDimensionsLength = 1;
  1597. value.arrayDimensions = dimensions;
  1598. value.vt = &UA_.types[UA_STRING];
  1599. //when
  1600. UA_Variant_copy(&value, &copiedValue);
  1601. //then
  1602. UA_Int32 i1 = value.arrayDimensions[0];
  1603. UA_Int32 i2 = copiedValue.arrayDimensions[0];
  1604. ck_assert_int_eq(i1, i2);
  1605. for(UA_Int32 i = 0;i < 3;i++) {
  1606. for(UA_Int32 j = 0;j < 6;j++)
  1607. ck_assert_int_eq(((UA_String *)value.data)[i].data[j], ((UA_String *)copiedValue.data)[i].data[j]);
  1608. ck_assert_int_eq(((UA_String *)value.data)[i].length, ((UA_String *)copiedValue.data)[i].length);
  1609. }
  1610. ck_assert_int_eq(((UA_String *)copiedValue.data)[0].data[2], 'o');
  1611. ck_assert_int_eq(((UA_String *)copiedValue.data)[0].data[3], 'p');
  1612. ck_assert_int_eq(value.arrayDimensionsLength, copiedValue.arrayDimensionsLength);
  1613. ck_assert_int_eq(value.arrayLength, copiedValue.arrayLength);
  1614. //finally
  1615. UA_Variant_deleteMembers(&value);
  1616. UA_Variant_deleteMembers(&copiedValue);
  1617. }
  1618. END_TEST
  1619. START_TEST(UA_Variant_copyShallWorkOn2DArrayExample) {
  1620. // given
  1621. UA_Int32 *srcArray;
  1622. UA_Array_new((void **)&srcArray, 6, &UA_.types[UA_INT32]);
  1623. srcArray[0] = 0;
  1624. srcArray[1] = 1;
  1625. srcArray[2] = 2;
  1626. srcArray[3] = 3;
  1627. srcArray[4] = 4;
  1628. srcArray[5] = 5;
  1629. UA_Int32 *dimensions;
  1630. UA_Array_new((void **)&dimensions, 2, &UA_.types[UA_INT32]);
  1631. UA_Int32 dim1 = 3;
  1632. UA_Int32 dim2 = 2;
  1633. dimensions[0] = dim1;
  1634. dimensions[1] = dim2;
  1635. UA_Variant value, copiedValue;
  1636. UA_Variant_init(&value);
  1637. UA_Variant_init(&copiedValue);
  1638. value.arrayLength = 6;
  1639. value.data = (void **)srcArray;
  1640. value.arrayDimensionsLength = 2;
  1641. value.arrayDimensions = dimensions;
  1642. value.vt = &UA_.types[UA_INT32];
  1643. //when
  1644. UA_Variant_copy(&value, &copiedValue);
  1645. //then
  1646. //1st dimension
  1647. UA_Int32 i1 = value.arrayDimensions[0];
  1648. UA_Int32 i2 = copiedValue.arrayDimensions[0];
  1649. ck_assert_int_eq(i1, i2);
  1650. ck_assert_int_eq(i1, dim1);
  1651. //2nd dimension
  1652. i1 = value.arrayDimensions[1];
  1653. i2 = copiedValue.arrayDimensions[1];
  1654. ck_assert_int_eq(i1, i2);
  1655. ck_assert_int_eq(i1, dim2);
  1656. for(UA_Int32 i = 0;i < 6;i++) {
  1657. i1 = ((UA_Int32 *)value.data)[i];
  1658. i2 = ((UA_Int32 *)copiedValue.data)[i];
  1659. ck_assert_int_eq(i1, i2);
  1660. ck_assert_int_eq(i2, i);
  1661. }
  1662. ck_assert_int_eq(value.arrayDimensionsLength, copiedValue.arrayDimensionsLength);
  1663. ck_assert_int_eq(value.arrayLength, copiedValue.arrayLength);
  1664. //finally
  1665. UA_Variant_deleteMembers(&value);
  1666. UA_Variant_deleteMembers(&copiedValue);
  1667. }
  1668. END_TEST
  1669. Suite *testSuite_builtin(void) {
  1670. Suite *s = suite_create("Built-in Data Types 62541-6 Table 1");
  1671. TCase *tc_calcSize = tcase_create("calcSize");
  1672. tcase_add_test(tc_calcSize, UA_Boolean_calcSizeWithNullArgumentShallReturnStorageSize);
  1673. tcase_add_test(tc_calcSize, UA_SByte_calcSizeWithNullArgumentShallReturnStorageSize);
  1674. tcase_add_test(tc_calcSize, UA_Byte_calcSizeWithNullArgumentShallReturnStorageSize);
  1675. tcase_add_test(tc_calcSize, UA_Int16_calcSizeWithNullArgumentShallReturnStorageSize);
  1676. tcase_add_test(tc_calcSize, UA_UInt16_calcSizeWithNullArgumentShallReturnStorageSize);
  1677. tcase_add_test(tc_calcSize, UA_Int32_calcSizeWithNullArgumentShallReturnStorageSize);
  1678. tcase_add_test(tc_calcSize, UA_UInt32_calcSizeWithNullArgumentShallReturnStorageSize);
  1679. tcase_add_test(tc_calcSize, UA_Int64_calcSizeWithNullArgumentShallReturnStorageSize);
  1680. tcase_add_test(tc_calcSize, UA_UInt64_calcSizeWithNullArgumentShallReturnStorageSize);
  1681. tcase_add_test(tc_calcSize, UA_Float_calcSizeWithNullArgumentShallReturnStorageSize);
  1682. tcase_add_test(tc_calcSize, UA_Double_calcSizeWithNullArgumentShallReturnStorageSize);
  1683. tcase_add_test(tc_calcSize, UA_String_calcSizeWithNullArgumentShallReturnStorageSize);
  1684. tcase_add_test(tc_calcSize, UA_DateTime_calcSizeWithNullArgumentShallReturnStorageSize);
  1685. tcase_add_test(tc_calcSize, UA_Guid_calcSizeWithNullArgumentShallReturnStorageSize);
  1686. tcase_add_test(tc_calcSize, UA_ByteString_calcSizeWithNullArgumentShallReturnStorageSize);
  1687. tcase_add_test(tc_calcSize, UA_XmlElement_calcSizeWithNullArgumentShallReturnStorageSize);
  1688. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeWithNullArgumentShallReturnStorageSize);
  1689. tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeWithNullArgumentShallReturnStorageSize);
  1690. tcase_add_test(tc_calcSize, UA_StatusCode_calcSizeWithNullArgumentShallReturnStorageSize);
  1691. tcase_add_test(tc_calcSize, UA_QualifiedName_calcSizeWithNullArgumentShallReturnStorageSize);
  1692. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeWithNullArgumentShallReturnStorageSize);
  1693. tcase_add_test(tc_calcSize, UA_ExtensionObject_calcSizeShallWorkOnExample);
  1694. tcase_add_test(tc_calcSize, UA_ExtensionObject_calcSizeWithNullArgumentShallReturnStorageSize);
  1695. tcase_add_test(tc_calcSize, UA_DataValue_calcSizeShallWorkOnExample);
  1696. tcase_add_test(tc_calcSize, UA_DataValue_calcSizeWithNullArgumentShallReturnStorageSize);
  1697. tcase_add_test(tc_calcSize, UA_Variant_calcSizeWithNullArgumentShallReturnStorageSize);
  1698. tcase_add_test(tc_calcSize, UA_DiagnosticInfo_calcSizeShallWorkOnExample);
  1699. tcase_add_test(tc_calcSize, UA_DiagnosticInfo_calcSizeWithNullArgumentShallReturnStorageSize);
  1700. tcase_add_test(tc_calcSize, UA_String_calcSizeShallReturnEncodingSize);
  1701. tcase_add_test(tc_calcSize, UA_String_calcSizeWithNegativLengthShallReturnEncodingSize);
  1702. tcase_add_test(tc_calcSize, UA_String_calcSizeWithNegativLengthAndValidPointerShallReturnEncodingSize);
  1703. tcase_add_test(tc_calcSize, UA_String_calcSizeWithZeroLengthShallReturnEncodingSize);
  1704. tcase_add_test(tc_calcSize, UA_String_calcSizeWithZeroLengthAndValidPointerShallReturnEncodingSize);
  1705. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingTwoByteShallReturnEncodingSize);
  1706. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingFourByteShallReturnEncodingSize);
  1707. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringShallReturnEncodingSize);
  1708. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringNegativLengthShallReturnEncodingSize);
  1709. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringZeroLengthShallReturnEncodingSize);
  1710. tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeEncodingStringAndServerIndexShallReturnEncodingSize);
  1711. tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeEncodingStringAndNamespaceUriShallReturnEncodingSize);
  1712. tcase_add_test(tc_calcSize, UA_Guid_calcSizeShallReturnEncodingSize);
  1713. tcase_add_test(tc_calcSize, UA_Guid_calcSizeShallReturnEncodingSize);
  1714. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeTextOnlyShallReturnEncodingSize);
  1715. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeLocaleOnlyShallReturnEncodingSize);
  1716. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeTextAndLocaleShallReturnEncodingSize);
  1717. tcase_add_test(tc_calcSize, UA_Variant_calcSizeFixedSizeArrayShallReturnEncodingSize);
  1718. tcase_add_test(tc_calcSize, UA_Variant_calcSizeVariableSizeArrayShallReturnEncodingSize);
  1719. tcase_add_test(tc_calcSize, UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem);
  1720. suite_add_tcase(s, tc_calcSize);
  1721. TCase *tc_decode = tcase_create("decode");
  1722. tcase_add_test(tc_decode, UA_Byte_decodeShallCopyAndAdvancePosition);
  1723. tcase_add_test(tc_decode, UA_Byte_decodeShallModifyOnlyCurrentPosition);
  1724. tcase_add_test(tc_decode, UA_Int16_decodeShallAssumeLittleEndian);
  1725. tcase_add_test(tc_decode, UA_Int16_decodeShallRespectSign);
  1726. tcase_add_test(tc_decode, UA_UInt16_decodeShallNotRespectSign);
  1727. tcase_add_test(tc_decode, UA_Int32_decodeShallAssumeLittleEndian);
  1728. tcase_add_test(tc_decode, UA_Int32_decodeShallRespectSign);
  1729. tcase_add_test(tc_decode, UA_UInt32_decodeShallNotRespectSign);
  1730. tcase_add_test(tc_decode, UA_UInt64_decodeShallNotRespectSign);
  1731. tcase_add_test(tc_decode, UA_Int64_decodeShallRespectSign);
  1732. tcase_add_test(tc_decode, UA_Float_decodeShallWorkOnExample);
  1733. tcase_add_test(tc_decode, UA_Double_decodeShallGiveOne);
  1734. tcase_add_test(tc_decode, UA_Double_decodeShallGiveZero);
  1735. tcase_add_test(tc_decode, UA_Double_decodeShallGiveMinusTwo);
  1736. tcase_add_test(tc_decode, UA_Byte_encode_test);
  1737. tcase_add_test(tc_decode, UA_String_decodeShallAllocateMemoryAndCopyString);
  1738. tcase_add_test(tc_decode, UA_String_decodeWithNegativeSizeShallNotAllocateMemoryAndNullPtr);
  1739. tcase_add_test(tc_decode, UA_String_decodeWithZeroSizeShallNotAllocateMemoryAndNullPtr);
  1740. tcase_add_test(tc_decode, UA_NodeId_decodeTwoByteShallReadTwoBytesAndSetNamespaceToZero);
  1741. tcase_add_test(tc_decode, UA_NodeId_decodeFourByteShallReadFourBytesAndRespectNamespace);
  1742. tcase_add_test(tc_decode, UA_NodeId_decodeStringShallAllocateMemory);
  1743. tcase_add_test(tc_decode, UA_Variant_decodeWithOutArrayFlagSetShallSetVTAndAllocateMemoryForArray);
  1744. tcase_add_test(tc_decode, UA_Variant_decodeWithArrayFlagSetShallSetVTAndAllocateMemoryForArray);
  1745. tcase_add_test(tc_decode, UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem);
  1746. tcase_add_test(tc_decode, UA_Variant_decodeWithTooSmallSourceShallReturnWithError);
  1747. suite_add_tcase(s, tc_decode);
  1748. TCase *tc_encode = tcase_create("encode");
  1749. tcase_add_test(tc_encode, UA_Byte_encode_test);
  1750. tcase_add_test(tc_encode, UA_UInt16_encodeNegativeShallEncodeLittleEndian);
  1751. tcase_add_test(tc_encode, UA_UInt16_encodeShallEncodeLittleEndian);
  1752. tcase_add_test(tc_encode, UA_UInt32_encodeShallEncodeLittleEndian);
  1753. tcase_add_test(tc_encode, UA_Int32_encodeShallEncodeLittleEndian);
  1754. tcase_add_test(tc_encode, UA_Int32_encodeNegativeShallEncodeLittleEndian);
  1755. tcase_add_test(tc_encode, UA_UInt64_encodeShallWorkOnExample);
  1756. tcase_add_test(tc_encode, UA_Int64_encodeNegativeShallEncodeLittleEndian);
  1757. tcase_add_test(tc_encode, UA_Int64_encodeShallEncodeLittleEndian);
  1758. tcase_add_test(tc_encode, UA_Float_encodeShallWorkOnExample);
  1759. //tcase_add_test(tc_encode, UA_Double_encodeShallWorkOnExample);
  1760. tcase_add_test(tc_encode, UA_String_encodeShallWorkOnExample);
  1761. tcase_add_test(tc_encode, UA_DataValue_encodeShallWorkOnExampleWithoutVariant);
  1762. tcase_add_test(tc_encode, UA_DataValue_encodeShallWorkOnExampleWithVariant);
  1763. suite_add_tcase(s, tc_encode);
  1764. TCase *tc_convert = tcase_create("convert");
  1765. tcase_add_test(tc_convert, UA_DateTime_toStructShallWorkOnExample);
  1766. tcase_add_test(tc_convert, UA_DateTime_toStringShallWorkOnExample);
  1767. suite_add_tcase(s, tc_convert);
  1768. TCase *tc_copy = tcase_create("copy");
  1769. tcase_add_test(tc_copy, UA_Array_copyByteArrayShallWorkOnExample);
  1770. tcase_add_test(tc_copy, UA_Array_copyUA_StringShallWorkOnExample);
  1771. tcase_add_test(tc_copy, UA_ExtensionObject_copyShallWorkOnExample);
  1772. tcase_add_test(tc_copy, UA_Variant_copyShallWorkOnSingleValueExample);
  1773. tcase_add_test(tc_copy, UA_Variant_copyShallWorkOn1DArrayExample);
  1774. tcase_add_test(tc_copy, UA_Variant_copyShallWorkOn2DArrayExample);
  1775. tcase_add_test(tc_copy, UA_DiagnosticInfo_copyShallWorkOnExample);
  1776. tcase_add_test(tc_copy, UA_ApplicationDescription_copyShallWorkOnExample);
  1777. tcase_add_test(tc_copy, UA_QualifiedName_copyShallWorkOnInputExample);
  1778. tcase_add_test(tc_copy, UA_QualifiedName_copyNULLInput);
  1779. tcase_add_test(tc_copy, UA_Guid_copyWithNullArgumentShallReturn);
  1780. tcase_add_test(tc_copy, UA_Guid_copyShallWorkOnInputExample);
  1781. tcase_add_test(tc_copy, UA_LocalizedText_copycstringShallWorkOnInputExample);
  1782. tcase_add_test(tc_copy, UA_LocalizedText_copycstringNULLInput);
  1783. tcase_add_test(tc_copy, UA_DataValue_copyShallWorkOnInputExample);
  1784. suite_add_tcase(s, tc_copy);
  1785. return s;
  1786. }
  1787. int main(void) {
  1788. int number_failed = 0;
  1789. Suite *s;
  1790. SRunner *sr;
  1791. s = testSuite_builtin();
  1792. sr = srunner_create(s);
  1793. //srunner_set_fork_status(sr, CK_NOFORK);
  1794. srunner_run_all(sr, CK_NORMAL);
  1795. number_failed += srunner_ntests_failed(sr);
  1796. srunner_free(sr);
  1797. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  1798. }