check_builtin.c 59 KB

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