check_builtin.c 44 KB

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