check_builtin.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "ua_types.h"
  4. #include "ua_types_encoding_binary.h"
  5. #include "ua_types_generated.h"
  6. #include "ua_types_generated_encoding_binary.h"
  7. //#include "ua_transport.h"
  8. #include "ua_util.h"
  9. #include "check.h"
  10. /* copied here from encoding_binary.c */
  11. enum UA_VARIANT_ENCODINGMASKTYPE_enum {
  12. UA_VARIANT_ENCODINGMASKTYPE_TYPEID_MASK = 0x3F, // bits 0:5
  13. UA_VARIANT_ENCODINGMASKTYPE_DIMENSIONS = (0x01 << 6), // bit 6
  14. UA_VARIANT_ENCODINGMASKTYPE_ARRAY = (0x01 << 7) // bit 7
  15. };
  16. START_TEST(UA_Byte_decodeShallCopyAndAdvancePosition) {
  17. // given
  18. UA_Byte dst;
  19. UA_Byte data[] = { 0x08 };
  20. UA_ByteString src = { 1, data };
  21. size_t pos = 0;
  22. // when
  23. UA_StatusCode retval = UA_Byte_decodeBinary(&src, &pos, &dst);
  24. // then
  25. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  26. ck_assert_uint_eq(pos, 1);
  27. ck_assert_uint_eq(dst, 0x08);
  28. }
  29. END_TEST
  30. START_TEST(UA_Byte_decodeShallModifyOnlyCurrentPosition) {
  31. // given
  32. UA_Byte dst[] = { 0xFF, 0xFF, 0xFF };
  33. UA_Byte data[] = { 0x08 };
  34. UA_ByteString src = { 1, data };
  35. size_t pos = 0;
  36. // when
  37. UA_StatusCode retval = UA_Byte_decodeBinary(&src, &pos, &dst[1]);
  38. // then
  39. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  40. ck_assert_int_eq(pos, 1);
  41. ck_assert_uint_eq(dst[0], 0xFF);
  42. ck_assert_uint_eq(dst[1], 0x08);
  43. ck_assert_uint_eq(dst[2], 0xFF);
  44. }
  45. END_TEST
  46. START_TEST(UA_Int16_decodeShallAssumeLittleEndian) {
  47. // given
  48. size_t pos = 0;
  49. UA_Byte data[] = {
  50. 0x01, 0x00, // 1
  51. 0x00, 0x01 // 256
  52. };
  53. UA_ByteString src = { 4, data };
  54. // when
  55. UA_Int16 val_01_00, val_00_01;
  56. UA_StatusCode retval = UA_Int16_decodeBinary(&src, &pos, &val_01_00);
  57. retval |= UA_Int16_decodeBinary(&src, &pos, &val_00_01);
  58. // then
  59. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  60. ck_assert_int_eq(val_01_00, 1);
  61. ck_assert_int_eq(val_00_01, 256);
  62. ck_assert_int_eq(pos, 4);
  63. }
  64. END_TEST
  65. START_TEST(UA_Int16_decodeShallRespectSign) {
  66. // given
  67. size_t pos = 0;
  68. UA_Byte data[] = {
  69. 0xFF, 0xFF, // -1
  70. 0x00, 0x80 // -32768
  71. };
  72. UA_ByteString src = { 4, data };
  73. // when
  74. UA_Int16 val_ff_ff, val_00_80;
  75. UA_StatusCode retval = UA_Int16_decodeBinary(&src, &pos, &val_ff_ff);
  76. retval |= UA_Int16_decodeBinary(&src, &pos, &val_00_80);
  77. // then
  78. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  79. ck_assert_int_eq(val_ff_ff, -1);
  80. ck_assert_int_eq(val_00_80, -32768);
  81. }
  82. END_TEST
  83. START_TEST(UA_UInt16_decodeShallNotRespectSign) {
  84. // given
  85. size_t pos = 0;
  86. UA_Byte data[] = {
  87. 0xFF, 0xFF, // (2^16)-1
  88. 0x00, 0x80 // (2^15)
  89. };
  90. UA_ByteString src = { 4, data };
  91. // when
  92. UA_UInt16 val_ff_ff, val_00_80;
  93. UA_StatusCode retval = UA_UInt16_decodeBinary(&src, &pos, &val_ff_ff);
  94. retval |= UA_UInt16_decodeBinary(&src, &pos, &val_00_80);
  95. // then
  96. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  97. ck_assert_int_eq(pos, 4);
  98. ck_assert_uint_eq(val_ff_ff, (0x01 << 16)-1);
  99. ck_assert_uint_eq(val_00_80, (0x01 << 15));
  100. }
  101. END_TEST
  102. START_TEST(UA_Int32_decodeShallAssumeLittleEndian) {
  103. // given
  104. size_t pos = 0;
  105. UA_Byte data[] = {
  106. 0x01, 0x00, 0x00, 0x00, // 1
  107. 0x00, 0x01, 0x00, 0x00 // 256
  108. };
  109. UA_ByteString src = { 8, data };
  110. // when
  111. UA_Int32 val_01_00, val_00_01;
  112. UA_StatusCode retval = UA_Int32_decodeBinary(&src, &pos, &val_01_00);
  113. retval |= UA_Int32_decodeBinary(&src, &pos, &val_00_01);
  114. // then
  115. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  116. ck_assert_int_eq(val_01_00, 1);
  117. ck_assert_int_eq(val_00_01, 256);
  118. ck_assert_int_eq(pos, 8);
  119. }
  120. END_TEST
  121. START_TEST(UA_Int32_decodeShallRespectSign) {
  122. // given
  123. size_t pos = 0;
  124. UA_Byte data[] = {
  125. 0xFF, 0xFF, 0xFF, 0xFF, // -1
  126. 0x00, 0x80, 0xFF, 0xFF // -32768
  127. };
  128. UA_ByteString src = { 8, data };
  129. // when
  130. UA_Int32 val_ff_ff, val_00_80;
  131. UA_StatusCode retval = UA_Int32_decodeBinary(&src, &pos, &val_ff_ff);
  132. retval |= UA_Int32_decodeBinary(&src, &pos, &val_00_80);
  133. // then
  134. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  135. ck_assert_int_eq(val_ff_ff, -1);
  136. ck_assert_int_eq(val_00_80, -32768);
  137. }
  138. END_TEST
  139. START_TEST(UA_UInt32_decodeShallNotRespectSign) {
  140. // given
  141. size_t pos = 0;
  142. UA_Byte data[] = {
  143. 0xFF, 0xFF, 0xFF, 0xFF, // (2^32)-1
  144. 0x00, 0x00, 0x00, 0x80 // (2^31)
  145. };
  146. UA_ByteString src = { 8, data };
  147. // when
  148. UA_UInt32 val_ff_ff, val_00_80;
  149. UA_StatusCode retval = UA_UInt32_decodeBinary(&src, &pos, &val_ff_ff);
  150. retval |= UA_UInt32_decodeBinary(&src, &pos, &val_00_80);
  151. // then
  152. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  153. ck_assert_int_eq(pos, 8);
  154. ck_assert_uint_eq(val_ff_ff, (UA_UInt32)( (0x01LL << 32 ) - 1 ));
  155. ck_assert_uint_eq(val_00_80, (UA_UInt32)(0x01 << 31));
  156. }
  157. END_TEST
  158. START_TEST(UA_UInt64_decodeShallNotRespectSign) {
  159. // given
  160. UA_ByteString rawMessage;
  161. UA_UInt64 expectedVal = 0xFF;
  162. expectedVal = expectedVal << 56;
  163. UA_Byte mem[8] = { 00, 00, 00, 00, 0x00, 0x00, 0x00, 0xFF };
  164. rawMessage.data = mem;
  165. rawMessage.length = 8;
  166. size_t pos = 0;
  167. UA_UInt64 val;
  168. // when
  169. UA_UInt64_decodeBinary(&rawMessage, &pos, &val);
  170. // then
  171. ck_assert_uint_eq(val, expectedVal);
  172. }
  173. END_TEST
  174. START_TEST(UA_Int64_decodeShallRespectSign) {
  175. // given
  176. UA_ByteString rawMessage;
  177. UA_Int64 expectedVal = 0xFF;
  178. expectedVal = expectedVal << 56;
  179. UA_Byte mem[8] = { 00, 00, 00, 00, 0x00, 0x00, 0x00, 0xFF };
  180. rawMessage.data = mem;
  181. rawMessage.length = 8;
  182. size_t pos = 0;
  183. UA_Int64 val;
  184. // when
  185. UA_Int64_decodeBinary(&rawMessage, &pos, &val);
  186. //then
  187. ck_assert_uint_eq(val, expectedVal);
  188. }
  189. END_TEST
  190. START_TEST(UA_Float_decodeShallWorkOnExample) {
  191. // given
  192. size_t pos = 0;
  193. UA_Byte data[] = { 0x00, 0x00, 0xD0, 0xC0 }; // -6.5
  194. UA_ByteString src = { 4, data };
  195. UA_Float dst;
  196. // when
  197. UA_StatusCode retval = UA_Float_decodeBinary(&src, &pos, &dst);
  198. // then
  199. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  200. ck_assert_int_eq(pos, 4);
  201. ck_assert(-6.5000001 < dst);
  202. ck_assert(dst < -6.49999999999);
  203. }
  204. END_TEST
  205. START_TEST(UA_Double_decodeShallGiveOne) {
  206. // given
  207. size_t pos = 0;
  208. UA_Byte data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F }; // 1
  209. UA_ByteString src = { 8, data }; // 1
  210. UA_Double dst;
  211. // when
  212. UA_StatusCode retval = UA_Double_decodeBinary(&src, &pos, &dst);
  213. // then
  214. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  215. ck_assert_int_eq(pos, 8);
  216. ck_assert(0.9999999 < dst);
  217. ck_assert(dst < 1.00000000001);
  218. }
  219. END_TEST
  220. START_TEST(UA_Double_decodeShallGiveZero) {
  221. // given
  222. size_t pos = 0;
  223. UA_Byte data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  224. UA_ByteString src = { 8, data }; // 1
  225. UA_Double dst;
  226. // when
  227. UA_StatusCode retval = UA_Double_decodeBinary(&src, &pos, &dst);
  228. // then
  229. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  230. ck_assert_int_eq(pos, 8);
  231. ck_assert(-0.00000001 < dst);
  232. ck_assert(dst < 0.000000001);
  233. }
  234. END_TEST
  235. START_TEST(UA_Double_decodeShallGiveMinusTwo) {
  236. // given
  237. size_t pos = 0;
  238. UA_Byte data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0 }; // -2
  239. UA_ByteString src = { 8, data };
  240. UA_Double dst;
  241. // when
  242. UA_StatusCode retval = UA_Double_decodeBinary(&src, &pos, &dst);
  243. // then
  244. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  245. ck_assert_int_eq(pos, 8);
  246. ck_assert(-1.9999999 > dst);
  247. ck_assert(dst > -2.00000000001);
  248. }
  249. END_TEST
  250. START_TEST(UA_Double_decodeShallGive2147483648) {
  251. // given
  252. size_t pos = 0;
  253. UA_Byte data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x41 }; //2147483648
  254. UA_ByteString src = { 8, data }; // 1
  255. UA_Double dst;
  256. // when
  257. UA_StatusCode retval = UA_Double_decodeBinary(&src, &pos, &dst);
  258. // then
  259. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  260. ck_assert_int_eq(pos, 8);
  261. ck_assert(2147483647.9999999 <= dst);
  262. ck_assert(dst <= 2147483648.00000001);
  263. }
  264. END_TEST
  265. START_TEST(UA_String_decodeShallAllocateMemoryAndCopyString) {
  266. // given
  267. size_t pos = 0;
  268. UA_Byte data[] =
  269. { 0x08, 0x00, 0x00, 0x00, 'A', 'C', 'P', 'L', 'T', ' ', 'U', 'A', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  270. UA_ByteString src = { 16, data };
  271. UA_String dst;
  272. // when
  273. UA_StatusCode retval = UA_String_decodeBinary(&src, &pos, &dst);
  274. // then
  275. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  276. ck_assert_int_eq(dst.length, 8);
  277. ck_assert_int_eq(dst.data[3], 'L');
  278. // finally
  279. UA_String_deleteMembers(&dst);
  280. }
  281. END_TEST
  282. START_TEST(UA_String_decodeWithNegativeSizeShallNotAllocateMemoryAndNullPtr) {
  283. // given
  284. size_t pos = 0;
  285. UA_Byte data[] =
  286. { 0xFF, 0xFF, 0xFF, 0xFF, 'A', 'C', 'P', 'L', 'T', ' ', 'U', 'A', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  287. UA_ByteString src = { 16, data };
  288. UA_String dst;
  289. // when
  290. UA_StatusCode retval = UA_String_decodeBinary(&src, &pos, &dst);
  291. // then
  292. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  293. ck_assert_int_eq(dst.length, 0);
  294. ck_assert_ptr_eq(dst.data, NULL);
  295. }
  296. END_TEST
  297. START_TEST(UA_String_decodeWithZeroSizeShallNotAllocateMemoryAndNullPtr) {
  298. // given
  299. size_t pos = 0;
  300. UA_Byte data[] =
  301. { 0x00, 0x00, 0x00, 0x00, 'A', 'C', 'P', 'L', 'T', ' ', 'U', 'A', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  302. UA_ByteString src = { 17, data };
  303. UA_String dst;
  304. // when
  305. UA_StatusCode retval = UA_String_decodeBinary(&src, &pos, &dst);
  306. // then
  307. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  308. ck_assert_int_eq(dst.length, 0);
  309. ck_assert_ptr_eq(dst.data, UA_EMPTY_ARRAY_SENTINEL);
  310. }
  311. END_TEST
  312. START_TEST(UA_NodeId_decodeTwoByteShallReadTwoBytesAndSetNamespaceToZero) {
  313. // given
  314. size_t pos = 0;
  315. UA_Byte data[] = { 0 /* UA_NODEIDTYPE_TWOBYTE */, 0x10 };
  316. UA_ByteString src = { 2, data };
  317. UA_NodeId dst;
  318. // when
  319. UA_StatusCode retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
  320. // then
  321. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  322. ck_assert_int_eq(pos, 2);
  323. ck_assert_int_eq(dst.identifierType, UA_NODEIDTYPE_NUMERIC);
  324. ck_assert_int_eq(dst.identifier.numeric, 16);
  325. ck_assert_int_eq(dst.namespaceIndex, 0);
  326. }
  327. END_TEST
  328. START_TEST(UA_NodeId_decodeFourByteShallReadFourBytesAndRespectNamespace) {
  329. // given
  330. size_t pos = 0;
  331. UA_Byte data[] = { 1 /* UA_NODEIDTYPE_FOURBYTE */, 0x01, 0x00, 0x01 };
  332. UA_ByteString src = { 4, data };
  333. UA_NodeId dst;
  334. // when
  335. UA_StatusCode retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
  336. // then
  337. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  338. ck_assert_int_eq(pos, 4);
  339. ck_assert_int_eq(dst.identifierType, UA_NODEIDTYPE_NUMERIC);
  340. ck_assert_int_eq(dst.identifier.numeric, 256);
  341. ck_assert_int_eq(dst.namespaceIndex, 1);
  342. }
  343. END_TEST
  344. START_TEST(UA_NodeId_decodeStringShallAllocateMemory) {
  345. // given
  346. size_t pos = 0;
  347. UA_Byte data[] = { UA_NODEIDTYPE_STRING, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 'P', 'L', 'T' };
  348. UA_ByteString src = { 10, data };
  349. UA_NodeId dst;
  350. // when
  351. UA_StatusCode retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
  352. // then
  353. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  354. ck_assert_int_eq(pos, 10);
  355. ck_assert_int_eq(dst.identifierType, UA_NODEIDTYPE_STRING);
  356. ck_assert_int_eq(dst.namespaceIndex, 1);
  357. ck_assert_int_eq(dst.identifier.string.length, 3);
  358. ck_assert_int_eq(dst.identifier.string.data[1], 'L');
  359. // finally
  360. UA_NodeId_deleteMembers(&dst);
  361. }
  362. END_TEST
  363. START_TEST(UA_Variant_decodeWithOutArrayFlagSetShallSetVTAndAllocateMemoryForArray) {
  364. // given
  365. size_t pos = 0;
  366. UA_Byte data[] = { UA_TYPES[UA_TYPES_INT32].typeId.identifier.numeric, 0xFF, 0x00, 0x00, 0x00 };
  367. UA_ByteString src = { 5, data };
  368. UA_Variant dst;
  369. // when
  370. UA_StatusCode retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  371. // then
  372. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  373. ck_assert_int_eq(pos, 5);
  374. //ck_assert_ptr_eq((const void *)dst.type, (const void *)&UA_TYPES[UA_TYPES_INT32]); //does not compile in gcc 4.6
  375. ck_assert_int_eq((uintptr_t)dst.type, (uintptr_t)&UA_TYPES[UA_TYPES_INT32]);
  376. ck_assert_int_eq(dst.arrayLength, 0);
  377. ck_assert_int_ne((uintptr_t)dst.data, 0);
  378. ck_assert_int_eq(*(UA_Int32 *)dst.data, 255);
  379. // finally
  380. UA_Variant_deleteMembers(&dst);
  381. }
  382. END_TEST
  383. START_TEST(UA_Variant_decodeWithArrayFlagSetShallSetVTAndAllocateMemoryForArray) {
  384. // given
  385. size_t pos = 0;
  386. UA_Byte data[] = { UA_TYPES[UA_TYPES_INT32].typeId.identifier.numeric | UA_VARIANT_ENCODINGMASKTYPE_ARRAY,
  387. 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF,
  388. 0xFF, 0xFF };
  389. UA_ByteString src = { 13, data };
  390. UA_Variant dst;
  391. // when
  392. UA_StatusCode retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  393. // then
  394. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  395. ck_assert_int_eq(pos, 1+4+2*4);
  396. //ck_assert_ptr_eq((const (void*))dst.type, (const void*)&UA_TYPES[UA_TYPES_INT32]); //does not compile in gcc 4.6
  397. ck_assert_int_eq((uintptr_t)dst.type,(uintptr_t)&UA_TYPES[UA_TYPES_INT32]);
  398. ck_assert_int_eq(dst.arrayLength, 2);
  399. ck_assert_int_eq(((UA_Int32 *)dst.data)[0], 255);
  400. ck_assert_int_eq(((UA_Int32 *)dst.data)[1], -1);
  401. // finally
  402. UA_Variant_deleteMembers(&dst);
  403. }
  404. END_TEST
  405. START_TEST(UA_Variant_decodeSingleExtensionObjectShallSetVTAndAllocateMemory){
  406. /* // given */
  407. /* size_t pos = 0; */
  408. /* UA_Variant dst; */
  409. /* UA_NodeId tmpNodeId; */
  410. /* UA_NodeId_init(&tmpNodeId); */
  411. /* tmpNodeId.identifier.numeric = 22; */
  412. /* tmpNodeId.namespaceIndex = 2; */
  413. /* tmpNodeId.identifierType = UA_NODEIDTYPE_NUMERIC; */
  414. /* UA_ExtensionObject tmpExtensionObject; */
  415. /* UA_ExtensionObject_init(&tmpExtensionObject); */
  416. /* tmpExtensionObject.encoding = UA_EXTENSIONOBJECT_ENCODED_BYTESTRING; */
  417. /* tmpExtensionObject.content.encoded.body = UA_ByteString_withSize(3); */
  418. /* tmpExtensionObject.content.encoded.body.data[0]= 10; */
  419. /* tmpExtensionObject.content.encoded.body.data[1]= 20; */
  420. /* tmpExtensionObject.content.encoded.body.data[2]= 30; */
  421. /* tmpExtensionObject.content.encoded.typeId = tmpNodeId; */
  422. /* UA_Variant tmpVariant; */
  423. /* UA_Variant_init(&tmpVariant); */
  424. /* tmpVariant.arrayDimensions = NULL; */
  425. /* tmpVariant.arrayDimensionsSize = -1; */
  426. /* tmpVariant.arrayLength = -1; */
  427. /* tmpVariant.storageType = UA_VARIANT_DATA_NODELETE; */
  428. /* tmpVariant.type = &UA_TYPES[UA_TYPES_EXTENSIONOBJECT]; */
  429. /* tmpVariant.data = &tmpExtensionObject; */
  430. /* UA_ByteString srcByteString = UA_ByteString_withSize(200); */
  431. /* pos = 0; */
  432. /* UA_Variant_encodeBinary(&tmpVariant,&srcByteString,&pos); */
  433. /* // when */
  434. /* pos = 0; */
  435. /* UA_StatusCode retval = UA_Variant_decodeBinary(&srcByteString, &pos, &dst); */
  436. /* // then */
  437. /* ck_assert_int_eq(retval, UA_STATUSCODE_GOOD); */
  438. /* // TODO!! */
  439. /* /\* ck_assert_int_eq(dst.encoding, UA_EXTENSIONOBJECT_DECODED); *\/ */
  440. /* /\* ck_assert_int_eq((uintptr_t)dst.content.decoded.type, (uintptr_t)&UA_TYPES[UA_TYPES_EXTENSIONOBJECT]); *\/ */
  441. /* /\* ck_assert_int_eq(dst.arrayLength, -1); *\/ */
  442. /* /\* ck_assert_int_eq(((UA_ExtensionObject *)dst.data)->body.data[0], 10); *\/ */
  443. /* /\* ck_assert_int_eq(((UA_ExtensionObject *)dst.data)->body.data[1], 20); *\/ */
  444. /* /\* ck_assert_int_eq(((UA_ExtensionObject *)dst.data)->body.data[2], 30); *\/ */
  445. /* /\* ck_assert_int_eq(((UA_ExtensionObject *)dst.data)->body.length, 3); *\/ */
  446. /* // finally */
  447. /* UA_Variant_deleteMembers(&dst); */
  448. /* UA_ByteString_deleteMembers(&srcByteString); */
  449. /* UA_ExtensionObject_deleteMembers(&tmpExtensionObject); */
  450. }
  451. END_TEST
  452. START_TEST(UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem) {
  453. // given
  454. size_t pos = 0;
  455. UA_Byte data[] = { UA_TYPES[UA_TYPES_INT32].typeId.identifier.numeric | UA_VARIANT_ENCODINGMASKTYPE_ARRAY,
  456. 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF };
  457. UA_ByteString src = { 13, data };
  458. UA_Variant dst;
  459. // when
  460. UA_StatusCode retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  461. // then
  462. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  463. // finally
  464. UA_Variant_deleteMembers(&dst);
  465. }
  466. END_TEST
  467. START_TEST(UA_Variant_decodeWithTooSmallSourceShallReturnWithError) {
  468. // given
  469. size_t pos = 0;
  470. UA_Byte data[] = { UA_TYPES[UA_TYPES_INT32].typeId.identifier.numeric | UA_VARIANT_ENCODINGMASKTYPE_ARRAY,
  471. 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF };
  472. UA_ByteString src = { 4, data };
  473. UA_Variant dst;
  474. // when
  475. UA_StatusCode retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  476. // then
  477. ck_assert_int_ne(retval, UA_STATUSCODE_GOOD);
  478. // finally
  479. UA_Variant_deleteMembers(&dst);
  480. }
  481. END_TEST
  482. START_TEST(UA_Byte_encode_test) {
  483. // given
  484. UA_Byte src;
  485. UA_Byte data[] = { 0x00, 0xFF };
  486. UA_ByteString dst = { 2, data };
  487. UA_Int32 retval = 0;
  488. size_t pos = 0;
  489. ck_assert_uint_eq(dst.data[1], 0xFF);
  490. src = 8;
  491. retval = UA_Byte_encodeBinary(&src, &dst, &pos);
  492. ck_assert_uint_eq(dst.data[0], 0x08);
  493. ck_assert_uint_eq(dst.data[1], 0xFF);
  494. ck_assert_int_eq(pos, 1);
  495. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  496. // Test2
  497. // given
  498. src = 0xFF;
  499. dst.data[1] = 0x00;
  500. pos = 0;
  501. retval = UA_Byte_encodeBinary(&src, &dst, &pos);
  502. ck_assert_int_eq(dst.data[0], 0xFF);
  503. ck_assert_int_eq(dst.data[1], 0x00);
  504. ck_assert_int_eq(pos, 1);
  505. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  506. }
  507. END_TEST
  508. START_TEST(UA_UInt16_encodeNegativeShallEncodeLittleEndian) {
  509. // given
  510. UA_UInt16 src;
  511. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55 };
  512. UA_ByteString dst = { 4, data };
  513. UA_StatusCode retval = 0;
  514. size_t pos = 0;
  515. // when test 1
  516. src = -1;
  517. retval = UA_UInt16_encodeBinary(&src, &dst, &pos);
  518. // then test 1
  519. ck_assert_int_eq(pos, 2);
  520. ck_assert_int_eq(dst.data[0], 0xFF);
  521. ck_assert_int_eq(dst.data[1], 0xFF);
  522. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  523. // when test 2
  524. src = -32768;
  525. retval = UA_UInt16_encodeBinary(&src, &dst, &pos);
  526. // then test 2
  527. ck_assert_int_eq(pos, 4);
  528. ck_assert_int_eq(dst.data[2], 0x00);
  529. ck_assert_int_eq(dst.data[3], 0x80);
  530. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  531. }
  532. END_TEST
  533. START_TEST(UA_UInt16_encodeShallEncodeLittleEndian) {
  534. // given
  535. UA_UInt16 src;
  536. UA_Byte data[] = { 0x55, 0x55,
  537. 0x55, 0x55 };
  538. UA_ByteString dst = { 4, data };
  539. UA_StatusCode retval = 0;
  540. size_t pos = 0;
  541. // when test 1
  542. src = 0;
  543. retval = UA_UInt16_encodeBinary(&src, &dst, &pos);
  544. // then test 1
  545. ck_assert_int_eq(pos, 2);
  546. ck_assert_int_eq(dst.data[0], 0x00);
  547. ck_assert_int_eq(dst.data[1], 0x00);
  548. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  549. // when test 2
  550. src = 32767;
  551. retval = UA_UInt16_encodeBinary(&src, &dst, &pos);
  552. // then test 2
  553. ck_assert_int_eq(pos, 4);
  554. ck_assert_int_eq(dst.data[2], 0xFF);
  555. ck_assert_int_eq(dst.data[3], 0x7F);
  556. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  557. }
  558. END_TEST
  559. START_TEST(UA_UInt32_encodeShallEncodeLittleEndian) {
  560. // given
  561. UA_UInt32 src;
  562. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
  563. UA_ByteString dst = { 8, data };
  564. UA_StatusCode retval = 0;
  565. size_t pos = 0;
  566. // when test 1
  567. src = -1;
  568. retval = UA_UInt32_encodeBinary(&src, &dst, &pos);
  569. // then test 1
  570. ck_assert_int_eq(pos, 4);
  571. ck_assert_int_eq(dst.data[0], 0xFF);
  572. ck_assert_int_eq(dst.data[1], 0xFF);
  573. ck_assert_int_eq(dst.data[2], 0xFF);
  574. ck_assert_int_eq(dst.data[3], 0xFF);
  575. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  576. // when test 2
  577. src = 0x0101FF00;
  578. retval = UA_UInt32_encodeBinary(&src, &dst, &pos);
  579. // then test 2
  580. ck_assert_int_eq(pos, 8);
  581. ck_assert_int_eq(dst.data[4], 0x00);
  582. ck_assert_int_eq(dst.data[5], 0xFF);
  583. ck_assert_int_eq(dst.data[6], 0x01);
  584. ck_assert_int_eq(dst.data[7], 0x01);
  585. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  586. }
  587. END_TEST
  588. START_TEST(UA_Int32_encodeShallEncodeLittleEndian) {
  589. // given
  590. UA_Int32 src;
  591. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
  592. UA_ByteString dst = { 8, data };
  593. UA_Int32 retval = 0;
  594. size_t pos = 0;
  595. // when test 1
  596. src = 1;
  597. retval = UA_Int32_encodeBinary(&src, &dst, &pos);
  598. // then test 1
  599. ck_assert_int_eq(pos, 4);
  600. ck_assert_int_eq(dst.data[0], 0x01);
  601. ck_assert_int_eq(dst.data[1], 0x00);
  602. ck_assert_int_eq(dst.data[2], 0x00);
  603. ck_assert_int_eq(dst.data[3], 0x00);
  604. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  605. // when test 2
  606. src = 0x7FFFFFFF;
  607. retval = UA_Int32_encodeBinary(&src, &dst, &pos);
  608. // then test 2
  609. ck_assert_int_eq(pos, 8);
  610. ck_assert_int_eq(dst.data[4], 0xFF);
  611. ck_assert_int_eq(dst.data[5], 0xFF);
  612. ck_assert_int_eq(dst.data[6], 0xFF);
  613. ck_assert_int_eq(dst.data[7], 0x7F);
  614. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  615. }
  616. END_TEST
  617. START_TEST(UA_Int32_encodeNegativeShallEncodeLittleEndian) {
  618. // given
  619. UA_Int32 src;
  620. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55,
  621. 0x55, 0x55, 0x55, 0x55 };
  622. UA_ByteString dst = { 8, data };
  623. UA_Int32 retval = 0;
  624. size_t pos = 0;
  625. // when test 1
  626. src = -1;
  627. retval = UA_Int32_encodeBinary(&src, &dst, &pos);
  628. // then test 1
  629. ck_assert_int_eq(pos, 4);
  630. ck_assert_int_eq(dst.data[0], 0xFF);
  631. ck_assert_int_eq(dst.data[1], 0xFF);
  632. ck_assert_int_eq(dst.data[2], 0xFF);
  633. ck_assert_int_eq(dst.data[3], 0xFF);
  634. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  635. }
  636. END_TEST
  637. START_TEST(UA_UInt64_encodeShallWorkOnExample) {
  638. // given
  639. UA_UInt64 src;
  640. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  641. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
  642. UA_ByteString dst = { 16, data };
  643. UA_StatusCode retval = 0;
  644. size_t pos = 0;
  645. // when test 1
  646. src = -1;
  647. retval = UA_UInt64_encodeBinary(&src, &dst, &pos);
  648. // then test 1
  649. ck_assert_int_eq(pos, 8);
  650. ck_assert_int_eq(dst.data[0], 0xFF);
  651. ck_assert_int_eq(dst.data[1], 0xFF);
  652. ck_assert_int_eq(dst.data[2], 0xFF);
  653. ck_assert_int_eq(dst.data[3], 0xFF);
  654. ck_assert_int_eq(dst.data[4], 0xFF);
  655. ck_assert_int_eq(dst.data[5], 0xFF);
  656. ck_assert_int_eq(dst.data[6], 0xFF);
  657. ck_assert_int_eq(dst.data[7], 0xFF);
  658. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  659. // when test 2
  660. src = 0x7F0033AA44EE6611;
  661. retval = UA_UInt64_encodeBinary(&src, &dst, &pos);
  662. // then test 2
  663. ck_assert_int_eq(pos, 16);
  664. ck_assert_int_eq(dst.data[8], 0x11);
  665. ck_assert_int_eq(dst.data[9], 0x66);
  666. ck_assert_int_eq(dst.data[10], 0xEE);
  667. ck_assert_int_eq(dst.data[11], 0x44);
  668. ck_assert_int_eq(dst.data[12], 0xAA);
  669. ck_assert_int_eq(dst.data[13], 0x33);
  670. ck_assert_int_eq(dst.data[14], 0x00);
  671. ck_assert_int_eq(dst.data[15], 0x7F);
  672. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  673. }
  674. END_TEST
  675. START_TEST(UA_Int64_encodeShallEncodeLittleEndian) {
  676. // given
  677. UA_Int64 src;
  678. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  679. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
  680. UA_ByteString dst = { 16, data };
  681. UA_Int32 retval = 0;
  682. size_t pos = 0;
  683. // when test 1
  684. src = 0x7F0033AA44EE6611;
  685. retval = UA_Int64_encodeBinary(&src, &dst, &pos);
  686. // then test 1
  687. ck_assert_int_eq(pos, 8);
  688. ck_assert_int_eq(dst.data[0], 0x11);
  689. ck_assert_int_eq(dst.data[1], 0x66);
  690. ck_assert_int_eq(dst.data[2], 0xEE);
  691. ck_assert_int_eq(dst.data[3], 0x44);
  692. ck_assert_int_eq(dst.data[4], 0xAA);
  693. ck_assert_int_eq(dst.data[5], 0x33);
  694. ck_assert_int_eq(dst.data[6], 0x00);
  695. ck_assert_int_eq(dst.data[7], 0x7F);
  696. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  697. }
  698. END_TEST
  699. START_TEST(UA_Int64_encodeNegativeShallEncodeLittleEndian) {
  700. // given
  701. UA_Int64 src;
  702. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  703. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
  704. UA_ByteString dst = { 16, data };
  705. UA_Int32 retval = 0;
  706. size_t pos = 0;
  707. // when test 1
  708. src = -1;
  709. retval = UA_Int64_encodeBinary(&src, &dst, &pos);
  710. // then test 1
  711. ck_assert_int_eq(pos, 8);
  712. ck_assert_int_eq(dst.data[0], 0xFF);
  713. ck_assert_int_eq(dst.data[1], 0xFF);
  714. ck_assert_int_eq(dst.data[2], 0xFF);
  715. ck_assert_int_eq(dst.data[3], 0xFF);
  716. ck_assert_int_eq(dst.data[4], 0xFF);
  717. ck_assert_int_eq(dst.data[5], 0xFF);
  718. ck_assert_int_eq(dst.data[6], 0xFF);
  719. ck_assert_int_eq(dst.data[7], 0xFF);
  720. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  721. }
  722. END_TEST
  723. START_TEST(UA_Float_encodeShallWorkOnExample) {
  724. // given
  725. UA_Float src;
  726. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  727. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
  728. UA_ByteString dst = { 16, data };
  729. UA_Int32 retval = 0;
  730. size_t pos = 0;
  731. // when test 1
  732. src = -6.5;
  733. retval = UA_Float_encodeBinary(&src, &dst, &pos);
  734. // then test 1
  735. ck_assert_int_eq(pos, 4);
  736. ck_assert_int_eq(dst.data[2], 0xD0);
  737. ck_assert_int_eq(dst.data[3], 0xC0);
  738. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  739. }
  740. END_TEST
  741. START_TEST(UA_Double_encodeShallWorkOnExample)
  742. {
  743. // given
  744. UA_Double src;
  745. UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
  746. 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
  747. };
  748. UA_ByteString dst = {16,data};
  749. UA_Int32 retval;
  750. size_t pos = 0;
  751. // when test 1
  752. src = -6.5;
  753. retval = UA_Double_encodeBinary(&src, &dst, &pos);
  754. // then test 1
  755. ck_assert_int_eq(pos, 8);
  756. ck_assert_int_eq(dst.data[6], 0x1A);
  757. ck_assert_int_eq(dst.data[7], 0xC0);
  758. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  759. }
  760. END_TEST
  761. START_TEST(UA_String_encodeShallWorkOnExample) {
  762. // given
  763. UA_String src;
  764. src.length = 11;
  765. UA_Byte mem[11] = "ACPLT OPCUA";
  766. src.data = mem;
  767. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  768. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  769. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
  770. UA_ByteString dst = { 24, data };
  771. UA_Int32 retval = 0;
  772. size_t pos = 0;
  773. // when
  774. retval = UA_String_encodeBinary(&src, &dst, &pos);
  775. // then
  776. ck_assert_int_eq(pos, sizeof(UA_Int32)+11);
  777. ck_assert_int_eq(dst.data[0], 11);
  778. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+0], 'A');
  779. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+1], 'C');
  780. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+2], 'P');
  781. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+3], 'L');
  782. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+4], 'T');
  783. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+5], 0x20); //Space
  784. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  785. }
  786. END_TEST
  787. START_TEST(UA_DataValue_encodeShallWorkOnExampleWithoutVariant) {
  788. // given
  789. UA_DataValue src;
  790. UA_DataValue_init(&src);
  791. src.serverTimestamp = 80;
  792. src.hasServerTimestamp = UA_TRUE;
  793. UA_Byte data[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  794. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
  795. 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 };
  796. UA_ByteString dst = { 24, data };
  797. UA_Int32 retval = 0;
  798. size_t pos = 0;
  799. // when
  800. retval = UA_DataValue_encodeBinary(&src, &dst, &pos);
  801. // then
  802. ck_assert_int_eq(pos, 9); // represents the length
  803. ck_assert_int_eq(dst.data[0], 0x08); // encodingMask
  804. ck_assert_int_eq(dst.data[1], 80); // 8 Byte serverTimestamp
  805. ck_assert_int_eq(dst.data[2], 0);
  806. ck_assert_int_eq(dst.data[3], 0);
  807. ck_assert_int_eq(dst.data[4], 0);
  808. ck_assert_int_eq(dst.data[5], 0);
  809. ck_assert_int_eq(dst.data[6], 0);
  810. ck_assert_int_eq(dst.data[7], 0);
  811. ck_assert_int_eq(dst.data[8], 0);
  812. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  813. }
  814. END_TEST
  815. START_TEST(UA_DataValue_encodeShallWorkOnExampleWithVariant) {
  816. // given
  817. UA_DataValue src;
  818. UA_DataValue_init(&src);
  819. src.serverTimestamp = 80;
  820. src.hasValue = UA_TRUE;
  821. src.hasServerTimestamp = UA_TRUE;
  822. src.value.type = &UA_TYPES[UA_TYPES_INT32];
  823. src.value.arrayLength = 0; // one element (encoded as not an array)
  824. UA_Int32 vdata = 45;
  825. src.value.data = (void *)&vdata;
  826. UA_Byte data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  827. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  828. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  829. UA_ByteString dst = { 24, data };
  830. UA_Int32 retval = 0;
  831. size_t pos = 0;
  832. // when
  833. retval = UA_DataValue_encodeBinary(&src, &dst, &pos);
  834. // then
  835. ck_assert_int_eq(pos, 1+(1+4)+8); // represents the length
  836. ck_assert_int_eq(dst.data[0], 0x08 | 0x01); // encodingMask
  837. ck_assert_int_eq(dst.data[1], 0x06); // Variant's Encoding Mask - INT32
  838. ck_assert_int_eq(dst.data[2], 45); // the single value
  839. ck_assert_int_eq(dst.data[3], 0);
  840. ck_assert_int_eq(dst.data[4], 0);
  841. ck_assert_int_eq(dst.data[5], 0);
  842. ck_assert_int_eq(dst.data[6], 80); // the server timestamp
  843. ck_assert_int_eq(dst.data[7], 0);
  844. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  845. }
  846. END_TEST
  847. START_TEST(UA_DateTime_toStructShallWorkOnExample) {
  848. // given
  849. UA_DateTime src = 13974671891234567 + (11644473600 * 10000000); // ua counts since 1601, unix since 1970
  850. //1397467189... is Mon, 14 Apr 2014 09:19:49 GMT
  851. //...1234567 are the milli-, micro- and nanoseconds
  852. UA_DateTimeStruct dst;
  853. // when
  854. dst = UA_DateTime_toStruct(src);
  855. // then
  856. ck_assert_int_eq(dst.nanoSec, 700);
  857. ck_assert_int_eq(dst.microSec, 456);
  858. ck_assert_int_eq(dst.milliSec, 123);
  859. ck_assert_int_eq(dst.sec, 49);
  860. ck_assert_int_eq(dst.min, 19);
  861. ck_assert_int_eq(dst.hour, 9);
  862. ck_assert_int_eq(dst.day, 14);
  863. ck_assert_int_eq(dst.month, 4);
  864. ck_assert_int_eq(dst.year, 2014);
  865. }
  866. END_TEST
  867. START_TEST(UA_DateTime_toStringShallWorkOnExample) {
  868. // given
  869. UA_DateTime src = 13974671891234567 + (11644473600 * 10000000); // ua counts since 1601, unix since 1970
  870. //1397467189... is Mon, 14 Apr 2014 09:19:49 GMT
  871. //...1234567 are the milli-, micro- and nanoseconds
  872. UA_String dst;
  873. // when
  874. dst = UA_DateTime_toString(src);
  875. // then
  876. ck_assert_int_eq(dst.data[0], '0');
  877. ck_assert_int_eq(dst.data[1], '4');
  878. ck_assert_int_eq(dst.data[2], '/');
  879. ck_assert_int_eq(dst.data[3], '1');
  880. ck_assert_int_eq(dst.data[4], '4');
  881. UA_String_deleteMembers(&dst);
  882. }
  883. END_TEST
  884. START_TEST(UA_ExtensionObject_copyShallWorkOnExample) {
  885. // given
  886. /* UA_Byte data[3] = { 1, 2, 3 }; */
  887. /* UA_ExtensionObject value, valueCopied; */
  888. /* UA_ExtensionObject_init(&value); */
  889. /* UA_ExtensionObject_init(&valueCopied); */
  890. //Todo!!
  891. /* value.typeId = UA_TYPES[UA_TYPES_BYTE].typeId; */
  892. /* value.encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_NOBODYISENCODED; */
  893. /* value.encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING; */
  894. /* value.body.data = data; */
  895. /* value.body.length = 3; */
  896. /* //when */
  897. /* UA_ExtensionObject_copy(&value, &valueCopied); */
  898. /* for(UA_Int32 i = 0;i < 3;i++) */
  899. /* ck_assert_int_eq(valueCopied.body.data[i], value.body.data[i]); */
  900. /* ck_assert_int_eq(valueCopied.encoding, value.encoding); */
  901. /* ck_assert_int_eq(valueCopied.typeId.identifierType, value.typeId.identifierType); */
  902. /* ck_assert_int_eq(valueCopied.typeId.identifier.numeric, value.typeId.identifier.numeric); */
  903. /* //finally */
  904. /* value.body.data = NULL; // we cannot free the static string */
  905. /* UA_ExtensionObject_deleteMembers(&value); */
  906. /* UA_ExtensionObject_deleteMembers(&valueCopied); */
  907. }
  908. END_TEST
  909. START_TEST(UA_Array_copyByteArrayShallWorkOnExample) {
  910. //given
  911. UA_String testString;
  912. UA_Byte *dstArray;
  913. UA_Int32 size = 5;
  914. UA_Int32 i = 0;
  915. testString.data = UA_malloc(size);
  916. testString.data[0] = 'O';
  917. testString.data[1] = 'P';
  918. testString.data[2] = 'C';
  919. testString.data[3] = 'U';
  920. testString.data[4] = 'A';
  921. testString.length = 5;
  922. //when
  923. UA_StatusCode retval;
  924. retval = UA_Array_copy((const void *)testString.data, 5, (void **)&dstArray, &UA_TYPES[UA_TYPES_BYTE]);
  925. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  926. //then
  927. for(i = 0;i < size;i++)
  928. ck_assert_int_eq(testString.data[i], dstArray[i]);
  929. //finally
  930. UA_String_deleteMembers(&testString);
  931. UA_free((void *)dstArray);
  932. }
  933. END_TEST
  934. START_TEST(UA_Array_copyUA_StringShallWorkOnExample) {
  935. // given
  936. UA_Int32 i, j;
  937. UA_String *srcArray = UA_Array_new(3, &UA_TYPES[UA_TYPES_STRING]);
  938. UA_String *dstArray;
  939. srcArray[0] = UA_STRING_ALLOC("open");
  940. srcArray[1] = UA_STRING_ALLOC("62541");
  941. srcArray[2] = UA_STRING_ALLOC("opc ua");
  942. //when
  943. UA_StatusCode retval;
  944. retval = UA_Array_copy((const void *)srcArray, 3, (void **)&dstArray, &UA_TYPES[UA_TYPES_STRING]);
  945. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  946. //then
  947. for(i = 0;i < 3;i++) {
  948. for(j = 0;j < 3;j++)
  949. ck_assert_int_eq(srcArray[i].data[j], dstArray[i].data[j]);
  950. ck_assert_int_eq(srcArray[i].length, dstArray[i].length);
  951. }
  952. //finally
  953. UA_Array_delete(srcArray, 3, &UA_TYPES[UA_TYPES_STRING]);
  954. UA_Array_delete(dstArray, 3, &UA_TYPES[UA_TYPES_STRING]);
  955. }
  956. END_TEST
  957. START_TEST(UA_DiagnosticInfo_copyShallWorkOnExample) {
  958. //given
  959. UA_DiagnosticInfo value, innerValue, copiedValue;
  960. UA_String testString = (UA_String){5, (UA_Byte*)"OPCUA"};
  961. UA_DiagnosticInfo_init(&value);
  962. UA_DiagnosticInfo_init(&innerValue);
  963. value.hasInnerDiagnosticInfo = UA_TRUE;
  964. value.innerDiagnosticInfo = &innerValue;
  965. value.hasAdditionalInfo = UA_TRUE;
  966. value.additionalInfo = testString;
  967. //when
  968. UA_DiagnosticInfo_copy(&value, &copiedValue);
  969. //then
  970. for(size_t i = 0;i < testString.length;i++)
  971. ck_assert_int_eq(copiedValue.additionalInfo.data[i], value.additionalInfo.data[i]);
  972. ck_assert_int_eq(copiedValue.additionalInfo.length, value.additionalInfo.length);
  973. ck_assert_int_eq(copiedValue.hasInnerDiagnosticInfo, value.hasInnerDiagnosticInfo);
  974. ck_assert_int_eq(copiedValue.innerDiagnosticInfo->locale, value.innerDiagnosticInfo->locale);
  975. ck_assert_int_eq(copiedValue.innerStatusCode, value.innerStatusCode);
  976. ck_assert_int_eq(copiedValue.locale, value.locale);
  977. ck_assert_int_eq(copiedValue.localizedText, value.localizedText);
  978. ck_assert_int_eq(copiedValue.namespaceUri, value.namespaceUri);
  979. ck_assert_int_eq(copiedValue.symbolicId, value.symbolicId);
  980. //finally
  981. value.additionalInfo.data = NULL; // do not delete the static string
  982. value.innerDiagnosticInfo = NULL; // do not delete the static innerdiagnosticinfo
  983. UA_DiagnosticInfo_deleteMembers(&value);
  984. UA_DiagnosticInfo_deleteMembers(&copiedValue);
  985. }
  986. END_TEST
  987. START_TEST(UA_ApplicationDescription_copyShallWorkOnExample) {
  988. //given
  989. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  990. UA_String appString = (UA_String){3, (UA_Byte*)"APP"};
  991. UA_String discString = (UA_String){4, (UA_Byte*)"DISC"};
  992. UA_String gateWayString = (UA_String){7, (UA_Byte*)"GATEWAY"};
  993. UA_String srcArray[3];
  994. srcArray[0] = (UA_String){ 6, (UA_Byte*)"__open" };
  995. srcArray[1] = (UA_String){ 6, (UA_Byte*)"_62541" };
  996. srcArray[2] = (UA_String){ 6, (UA_Byte*)"opc ua" };
  997. UA_ApplicationDescription value, copiedValue;
  998. UA_ApplicationDescription_init(&value);
  999. value.applicationUri = appString;
  1000. value.discoveryProfileUri = discString;
  1001. value.gatewayServerUri = gateWayString;
  1002. value.discoveryUrlsSize = 3;
  1003. value.discoveryUrls = srcArray;
  1004. //when
  1005. retval = UA_ApplicationDescription_copy(&value, &copiedValue);
  1006. //then
  1007. ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
  1008. for(size_t i = 0; i < appString.length; i++)
  1009. ck_assert_int_eq(copiedValue.applicationUri.data[i], value.applicationUri.data[i]);
  1010. ck_assert_int_eq(copiedValue.applicationUri.length, value.applicationUri.length);
  1011. for(size_t i = 0; i < discString.length; i++)
  1012. ck_assert_int_eq(copiedValue.discoveryProfileUri.data[i], value.discoveryProfileUri.data[i]);
  1013. ck_assert_int_eq(copiedValue.discoveryProfileUri.length, value.discoveryProfileUri.length);
  1014. for(size_t i = 0; i < gateWayString.length; i++)
  1015. ck_assert_int_eq(copiedValue.gatewayServerUri.data[i], value.gatewayServerUri.data[i]);
  1016. ck_assert_int_eq(copiedValue.gatewayServerUri.length, value.gatewayServerUri.length);
  1017. //String Array Test
  1018. for(UA_Int32 i = 0;i < 3;i++) {
  1019. for(UA_Int32 j = 0;j < 6;j++)
  1020. ck_assert_int_eq(value.discoveryUrls[i].data[j], copiedValue.discoveryUrls[i].data[j]);
  1021. ck_assert_int_eq(value.discoveryUrls[i].length, copiedValue.discoveryUrls[i].length);
  1022. }
  1023. ck_assert_int_eq(copiedValue.discoveryUrls[0].data[2], 'o');
  1024. ck_assert_int_eq(copiedValue.discoveryUrls[0].data[3], 'p');
  1025. ck_assert_int_eq(copiedValue.discoveryUrlsSize, value.discoveryUrlsSize);
  1026. //finally
  1027. // UA_ApplicationDescription_deleteMembers(&value); // do not free the members as they are statically allocated
  1028. UA_ApplicationDescription_deleteMembers(&copiedValue);
  1029. }
  1030. END_TEST
  1031. START_TEST(UA_QualifiedName_copyShallWorkOnInputExample) {
  1032. // given
  1033. UA_String srcName = (UA_String){8, (UA_Byte*)"tEsT123!"};
  1034. UA_QualifiedName src = {5, srcName};
  1035. UA_QualifiedName dst;
  1036. // when
  1037. UA_StatusCode ret = UA_QualifiedName_copy(&src, &dst);
  1038. // then
  1039. ck_assert_int_eq(ret, UA_STATUSCODE_GOOD);
  1040. ck_assert_int_eq('E', dst.name.data[1]);
  1041. ck_assert_int_eq('!', dst.name.data[7]);
  1042. ck_assert_int_eq(8, dst.name.length);
  1043. ck_assert_int_eq(5, dst.namespaceIndex);
  1044. // finally
  1045. UA_QualifiedName_deleteMembers(&dst);
  1046. }
  1047. END_TEST
  1048. START_TEST(UA_Guid_copyShallWorkOnInputExample) {
  1049. //given
  1050. const UA_Guid src = {3, 45, 1222, {8, 7, 6, 5, 4, 3, 2, 1}};
  1051. UA_Guid dst;
  1052. //when
  1053. UA_StatusCode ret = UA_Guid_copy(&src, &dst);
  1054. //then
  1055. ck_assert_int_eq(ret, UA_STATUSCODE_GOOD);
  1056. ck_assert_int_eq(src.data1, dst.data1);
  1057. ck_assert_int_eq(src.data3, dst.data3);
  1058. ck_assert_int_eq(src.data4[4], dst.data4[4]);
  1059. //finally
  1060. }
  1061. END_TEST
  1062. START_TEST(UA_LocalizedText_copycstringShallWorkOnInputExample) {
  1063. // given
  1064. char src[8] = {'t', 'e', 'X', 't', '1', '2', '3', (char)0};
  1065. const UA_LocalizedText dst = UA_LOCALIZEDTEXT("", src);
  1066. // then
  1067. ck_assert_int_eq('1', dst.text.data[4]);
  1068. ck_assert_int_eq(0, dst.locale.length);
  1069. ck_assert_int_eq(7, dst.text.length);
  1070. }
  1071. END_TEST
  1072. START_TEST(UA_DataValue_copyShallWorkOnInputExample) {
  1073. // given
  1074. UA_Variant srcVariant;
  1075. UA_Variant_init(&srcVariant);
  1076. UA_DataValue src;
  1077. UA_DataValue_init(&src);
  1078. src.hasSourceTimestamp = UA_TRUE;
  1079. src.sourceTimestamp = 4;
  1080. src.hasSourcePicoseconds = UA_TRUE;
  1081. src.sourcePicoseconds = 77;
  1082. src.hasServerPicoseconds = UA_TRUE;
  1083. src.serverPicoseconds = 8;
  1084. UA_DataValue dst;
  1085. // when
  1086. UA_StatusCode ret = UA_DataValue_copy(&src, &dst);
  1087. // then
  1088. ck_assert_int_eq(ret, UA_STATUSCODE_GOOD);
  1089. ck_assert_int_eq(4, dst.sourceTimestamp);
  1090. ck_assert_int_eq(77, dst.sourcePicoseconds);
  1091. ck_assert_int_eq(8, dst.serverPicoseconds);
  1092. }
  1093. END_TEST
  1094. START_TEST(UA_Variant_copyShallWorkOnSingleValueExample) {
  1095. //given
  1096. UA_String testString = (UA_String){5, (UA_Byte*)"OPCUA"};
  1097. UA_Variant value, copiedValue;
  1098. UA_Variant_init(&value);
  1099. UA_Variant_init(&copiedValue);
  1100. value.data = UA_malloc(sizeof(UA_String));
  1101. *((UA_String*)value.data) = testString;
  1102. value.type = &UA_TYPES[UA_TYPES_STRING];
  1103. value.arrayLength = 1;
  1104. //when
  1105. UA_Variant_copy(&value, &copiedValue);
  1106. //then
  1107. UA_String copiedString = *(UA_String*)(copiedValue.data);
  1108. for(UA_Int32 i = 0;i < 5;i++)
  1109. ck_assert_int_eq(copiedString.data[i], testString.data[i]);
  1110. ck_assert_int_eq(copiedString.length, testString.length);
  1111. ck_assert_int_eq(value.arrayDimensionsSize, copiedValue.arrayDimensionsSize);
  1112. ck_assert_int_eq(value.arrayLength, copiedValue.arrayLength);
  1113. //finally
  1114. ((UA_String*)value.data)->data = NULL; // the string is statically allocated. do not free it.
  1115. UA_Variant_deleteMembers(&value);
  1116. UA_Variant_deleteMembers(&copiedValue);
  1117. }
  1118. END_TEST
  1119. START_TEST(UA_Variant_copyShallWorkOn1DArrayExample) {
  1120. // given
  1121. UA_String *srcArray = UA_Array_new(3, &UA_TYPES[UA_TYPES_STRING]);
  1122. srcArray[0] = UA_STRING_ALLOC("__open");
  1123. srcArray[1] = UA_STRING_ALLOC("_62541");
  1124. srcArray[2] = UA_STRING_ALLOC("opc ua");
  1125. UA_UInt32 *dimensions;
  1126. dimensions = UA_malloc(sizeof(UA_UInt32));
  1127. dimensions[0] = 3;
  1128. UA_Variant value, copiedValue;
  1129. UA_Variant_init(&value);
  1130. UA_Variant_init(&copiedValue);
  1131. value.arrayLength = 3;
  1132. value.data = (void *)srcArray;
  1133. value.arrayDimensionsSize = 1;
  1134. value.arrayDimensions = dimensions;
  1135. value.type = &UA_TYPES[UA_TYPES_STRING];
  1136. //when
  1137. UA_Variant_copy(&value, &copiedValue);
  1138. //then
  1139. UA_Int32 i1 = value.arrayDimensions[0];
  1140. UA_Int32 i2 = copiedValue.arrayDimensions[0];
  1141. ck_assert_int_eq(i1, i2);
  1142. for(UA_Int32 i = 0;i < 3;i++) {
  1143. for(UA_Int32 j = 0;j < 6;j++) {
  1144. ck_assert_int_eq(((UA_String *)value.data)[i].data[j],
  1145. ((UA_String *)copiedValue.data)[i].data[j]);
  1146. }
  1147. ck_assert_int_eq(((UA_String *)value.data)[i].length,
  1148. ((UA_String *)copiedValue.data)[i].length);
  1149. }
  1150. ck_assert_int_eq(((UA_String *)copiedValue.data)[0].data[2], 'o');
  1151. ck_assert_int_eq(((UA_String *)copiedValue.data)[0].data[3], 'p');
  1152. ck_assert_int_eq(value.arrayDimensionsSize, copiedValue.arrayDimensionsSize);
  1153. ck_assert_int_eq(value.arrayLength, copiedValue.arrayLength);
  1154. //finally
  1155. UA_Variant_deleteMembers(&value);
  1156. UA_Variant_deleteMembers(&copiedValue);
  1157. }
  1158. END_TEST
  1159. START_TEST(UA_Variant_copyShallWorkOn2DArrayExample) {
  1160. // given
  1161. UA_Int32 *srcArray = UA_Array_new(6, &UA_TYPES[UA_TYPES_INT32]);
  1162. srcArray[0] = 0;
  1163. srcArray[1] = 1;
  1164. srcArray[2] = 2;
  1165. srcArray[3] = 3;
  1166. srcArray[4] = 4;
  1167. srcArray[5] = 5;
  1168. UA_UInt32 *dimensions = UA_Array_new(2, &UA_TYPES[UA_TYPES_UINT32]);
  1169. UA_Int32 dim1 = 3;
  1170. UA_Int32 dim2 = 2;
  1171. dimensions[0] = dim1;
  1172. dimensions[1] = dim2;
  1173. UA_Variant value, copiedValue;
  1174. UA_Variant_init(&value);
  1175. UA_Variant_init(&copiedValue);
  1176. value.arrayLength = 6;
  1177. value.data = srcArray;
  1178. value.arrayDimensionsSize = 2;
  1179. value.arrayDimensions = dimensions;
  1180. value.type = &UA_TYPES[UA_TYPES_INT32];
  1181. //when
  1182. UA_Variant_copy(&value, &copiedValue);
  1183. //then
  1184. //1st dimension
  1185. UA_Int32 i1 = value.arrayDimensions[0];
  1186. UA_Int32 i2 = copiedValue.arrayDimensions[0];
  1187. ck_assert_int_eq(i1, i2);
  1188. ck_assert_int_eq(i1, dim1);
  1189. //2nd dimension
  1190. i1 = value.arrayDimensions[1];
  1191. i2 = copiedValue.arrayDimensions[1];
  1192. ck_assert_int_eq(i1, i2);
  1193. ck_assert_int_eq(i1, dim2);
  1194. for(UA_Int32 i = 0;i < 6;i++) {
  1195. i1 = ((UA_Int32 *)value.data)[i];
  1196. i2 = ((UA_Int32 *)copiedValue.data)[i];
  1197. ck_assert_int_eq(i1, i2);
  1198. ck_assert_int_eq(i2, i);
  1199. }
  1200. ck_assert_int_eq(value.arrayDimensionsSize, copiedValue.arrayDimensionsSize);
  1201. ck_assert_int_eq(value.arrayLength, copiedValue.arrayLength);
  1202. //finally
  1203. UA_Variant_deleteMembers(&value);
  1204. UA_Variant_deleteMembers(&copiedValue);
  1205. }
  1206. END_TEST
  1207. START_TEST(UA_ExtensionObject_encodeDecodeShallWorkOnExtensionObject) {
  1208. /* UA_Int32 val = 42; */
  1209. /* UA_VariableAttributes varAttr; */
  1210. /* UA_VariableAttributes_init(&varAttr); */
  1211. /* varAttr.dataType = UA_TYPES[UA_TYPES_INT32].typeId; */
  1212. /* UA_Variant_init(&varAttr.value); */
  1213. /* varAttr.value.type = &UA_TYPES[UA_TYPES_INT32]; */
  1214. /* varAttr.value.data = &val; */
  1215. /* varAttr.value.arrayLength = -1; */
  1216. /* varAttr.userWriteMask = 41; */
  1217. /* varAttr.specifiedAttributes |= UA_NODEATTRIBUTESMASK_DATATYPE; */
  1218. /* varAttr.specifiedAttributes |= UA_NODEATTRIBUTESMASK_VALUE; */
  1219. /* varAttr.specifiedAttributes |= UA_NODEATTRIBUTESMASK_USERWRITEMASK; */
  1220. /* /\* wrap it into a extension object attributes *\/ */
  1221. /* UA_ExtensionObject extensionObject; */
  1222. /* UA_ExtensionObject_init(&extensionObject); */
  1223. /* extensionObject.typeId = UA_TYPES[UA_TYPES_VARIABLEATTRIBUTES].typeId; */
  1224. /* UA_Byte extensionData[50]; */
  1225. /* extensionObject.body = (UA_ByteString){.data = extensionData, .length=50}; */
  1226. /* size_t posEncode = 0; */
  1227. /* UA_VariableAttributes_encodeBinary(&varAttr, &extensionObject.body, &posEncode); */
  1228. /* extensionObject.body.length = posEncode; */
  1229. /* extensionObject.encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING; */
  1230. /* UA_Byte data[50]; */
  1231. /* UA_ByteString dst = {.data = data, .length=50}; */
  1232. /* posEncode = 0; */
  1233. /* UA_ExtensionObject_encodeBinary(&extensionObject, &dst, &posEncode); */
  1234. /* UA_ExtensionObject extensionObjectDecoded; */
  1235. /* size_t posDecode = 0; */
  1236. /* UA_ExtensionObject_decodeBinary(&dst, &posDecode, &extensionObjectDecoded); */
  1237. /* ck_assert_int_eq(posEncode, posDecode); */
  1238. /* ck_assert_int_eq(extensionObjectDecoded.body.length, extensionObject.body.length); */
  1239. /* UA_VariableAttributes varAttrDecoded; */
  1240. /* UA_VariableAttributes_init(&varAttrDecoded); */
  1241. /* posDecode = 0; */
  1242. /* UA_VariableAttributes_decodeBinary(&extensionObjectDecoded.body, &posDecode, &varAttrDecoded); */
  1243. /* ck_assert_uint_eq(41, varAttrDecoded.userWriteMask); */
  1244. /* ck_assert_int_eq(-1, varAttrDecoded.value.arrayLength); */
  1245. /* // finally */
  1246. /* UA_ExtensionObject_deleteMembers(&extensionObjectDecoded); */
  1247. /* UA_Variant_deleteMembers(&varAttrDecoded.value); */
  1248. }
  1249. END_TEST
  1250. static Suite *testSuite_builtin(void) {
  1251. Suite *s = suite_create("Built-in Data Types 62541-6 Table 1");
  1252. TCase *tc_decode = tcase_create("decode");
  1253. tcase_add_test(tc_decode, UA_Byte_decodeShallCopyAndAdvancePosition);
  1254. tcase_add_test(tc_decode, UA_Byte_decodeShallModifyOnlyCurrentPosition);
  1255. tcase_add_test(tc_decode, UA_Int16_decodeShallAssumeLittleEndian);
  1256. tcase_add_test(tc_decode, UA_Int16_decodeShallRespectSign);
  1257. tcase_add_test(tc_decode, UA_UInt16_decodeShallNotRespectSign);
  1258. tcase_add_test(tc_decode, UA_Int32_decodeShallAssumeLittleEndian);
  1259. tcase_add_test(tc_decode, UA_Int32_decodeShallRespectSign);
  1260. tcase_add_test(tc_decode, UA_UInt32_decodeShallNotRespectSign);
  1261. tcase_add_test(tc_decode, UA_UInt64_decodeShallNotRespectSign);
  1262. tcase_add_test(tc_decode, UA_Int64_decodeShallRespectSign);
  1263. tcase_add_test(tc_decode, UA_Float_decodeShallWorkOnExample);
  1264. tcase_add_test(tc_decode, UA_Double_decodeShallGiveOne);
  1265. tcase_add_test(tc_decode, UA_Double_decodeShallGiveZero);
  1266. tcase_add_test(tc_decode, UA_Double_decodeShallGiveMinusTwo);
  1267. tcase_add_test(tc_decode, UA_Double_decodeShallGive2147483648);
  1268. tcase_add_test(tc_decode, UA_Byte_encode_test);
  1269. tcase_add_test(tc_decode, UA_String_decodeShallAllocateMemoryAndCopyString);
  1270. tcase_add_test(tc_decode, UA_String_decodeWithNegativeSizeShallNotAllocateMemoryAndNullPtr);
  1271. tcase_add_test(tc_decode, UA_String_decodeWithZeroSizeShallNotAllocateMemoryAndNullPtr);
  1272. tcase_add_test(tc_decode, UA_NodeId_decodeTwoByteShallReadTwoBytesAndSetNamespaceToZero);
  1273. tcase_add_test(tc_decode, UA_NodeId_decodeFourByteShallReadFourBytesAndRespectNamespace);
  1274. tcase_add_test(tc_decode, UA_NodeId_decodeStringShallAllocateMemory);
  1275. tcase_add_test(tc_decode, UA_Variant_decodeSingleExtensionObjectShallSetVTAndAllocateMemory);
  1276. tcase_add_test(tc_decode, UA_Variant_decodeWithOutArrayFlagSetShallSetVTAndAllocateMemoryForArray);
  1277. tcase_add_test(tc_decode, UA_Variant_decodeWithArrayFlagSetShallSetVTAndAllocateMemoryForArray);
  1278. tcase_add_test(tc_decode, UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem);
  1279. tcase_add_test(tc_decode, UA_Variant_decodeWithTooSmallSourceShallReturnWithError);
  1280. suite_add_tcase(s, tc_decode);
  1281. TCase *tc_encode = tcase_create("encode");
  1282. tcase_add_test(tc_encode, UA_Byte_encode_test);
  1283. tcase_add_test(tc_encode, UA_UInt16_encodeNegativeShallEncodeLittleEndian);
  1284. tcase_add_test(tc_encode, UA_UInt16_encodeShallEncodeLittleEndian);
  1285. tcase_add_test(tc_encode, UA_UInt32_encodeShallEncodeLittleEndian);
  1286. tcase_add_test(tc_encode, UA_Int32_encodeShallEncodeLittleEndian);
  1287. tcase_add_test(tc_encode, UA_Int32_encodeNegativeShallEncodeLittleEndian);
  1288. tcase_add_test(tc_encode, UA_UInt64_encodeShallWorkOnExample);
  1289. tcase_add_test(tc_encode, UA_Int64_encodeNegativeShallEncodeLittleEndian);
  1290. tcase_add_test(tc_encode, UA_Int64_encodeShallEncodeLittleEndian);
  1291. tcase_add_test(tc_encode, UA_Float_encodeShallWorkOnExample);
  1292. tcase_add_test(tc_encode, UA_Double_encodeShallWorkOnExample);
  1293. tcase_add_test(tc_encode, UA_String_encodeShallWorkOnExample);
  1294. tcase_add_test(tc_encode, UA_DataValue_encodeShallWorkOnExampleWithoutVariant);
  1295. tcase_add_test(tc_encode, UA_DataValue_encodeShallWorkOnExampleWithVariant);
  1296. tcase_add_test(tc_encode, UA_ExtensionObject_encodeDecodeShallWorkOnExtensionObject);
  1297. suite_add_tcase(s, tc_encode);
  1298. TCase *tc_convert = tcase_create("convert");
  1299. tcase_add_test(tc_convert, UA_DateTime_toStructShallWorkOnExample);
  1300. tcase_add_test(tc_convert, UA_DateTime_toStringShallWorkOnExample);
  1301. suite_add_tcase(s, tc_convert);
  1302. TCase *tc_copy = tcase_create("copy");
  1303. tcase_add_test(tc_copy, UA_Array_copyByteArrayShallWorkOnExample);
  1304. tcase_add_test(tc_copy, UA_Array_copyUA_StringShallWorkOnExample);
  1305. tcase_add_test(tc_copy, UA_ExtensionObject_copyShallWorkOnExample);
  1306. tcase_add_test(tc_copy, UA_Variant_copyShallWorkOnSingleValueExample);
  1307. tcase_add_test(tc_copy, UA_Variant_copyShallWorkOn1DArrayExample);
  1308. tcase_add_test(tc_copy, UA_Variant_copyShallWorkOn2DArrayExample);
  1309. tcase_add_test(tc_copy, UA_DiagnosticInfo_copyShallWorkOnExample);
  1310. tcase_add_test(tc_copy, UA_ApplicationDescription_copyShallWorkOnExample);
  1311. tcase_add_test(tc_copy, UA_QualifiedName_copyShallWorkOnInputExample);
  1312. tcase_add_test(tc_copy, UA_Guid_copyShallWorkOnInputExample);
  1313. tcase_add_test(tc_copy, UA_LocalizedText_copycstringShallWorkOnInputExample);
  1314. tcase_add_test(tc_copy, UA_DataValue_copyShallWorkOnInputExample);
  1315. suite_add_tcase(s, tc_copy);
  1316. return s;
  1317. }
  1318. int main(void) {
  1319. int number_failed = 0;
  1320. Suite *s;
  1321. SRunner *sr;
  1322. s = testSuite_builtin();
  1323. sr = srunner_create(s);
  1324. srunner_set_fork_status(sr, CK_NOFORK);
  1325. srunner_run_all(sr, CK_NORMAL);
  1326. number_failed += srunner_ntests_failed(sr);
  1327. srunner_free(sr);
  1328. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  1329. }