check_builtin.c 46 KB

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