check_builtin.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  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_transportLayer.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_calcSizeShallWorkOnExample)
  188. {
  189. //ToDo: Function needs to be filled
  190. UA_Int32 valreal = 300;
  191. UA_Int32 valcalc = 0;
  192. ck_assert_int_eq(valcalc,valreal);
  193. }
  194. END_TEST
  195. START_TEST(UA_ExpandedNodeId_calcSizeWithNullArgumentShallReturnStorageSize)
  196. {
  197. // given
  198. UA_ExpandedNodeId* arg = UA_NULL;
  199. // when
  200. UA_Int32 storageSize = UA_ExpandedNodeId_calcSize(arg);
  201. // then
  202. ck_assert_int_eq(storageSize, sizeof(UA_ExpandedNodeId));
  203. }
  204. END_TEST
  205. START_TEST(UA_StatusCode_calcSizeWithNullArgumentShallReturnStorageSize)
  206. {
  207. // given
  208. UA_StatusCode* arg = UA_NULL;
  209. // when
  210. UA_Int32 storageSize = UA_StatusCode_calcSize(arg);
  211. // then
  212. ck_assert_int_eq(storageSize, sizeof(UA_StatusCode));
  213. }
  214. END_TEST
  215. START_TEST(UA_QualifiedName_calcSizeWithNullArgumentShallReturnStorageSize)
  216. {
  217. // given
  218. UA_QualifiedName* arg = UA_NULL;
  219. // when
  220. UA_Int32 storageSize = UA_QualifiedName_calcSize(arg);
  221. // then
  222. ck_assert_int_eq(storageSize, sizeof(UA_QualifiedName));
  223. }
  224. END_TEST
  225. START_TEST(UA_LocalizedText_calcSizeWithNullArgumentShallReturnStorageSize)
  226. {
  227. // given
  228. UA_LocalizedText* arg = UA_NULL;
  229. // when
  230. UA_Int32 storageSize = UA_LocalizedText_calcSize(arg);
  231. // then
  232. ck_assert_int_eq(storageSize, sizeof(UA_LocalizedText));
  233. }
  234. END_TEST
  235. START_TEST(UA_ExtensionObject_calcSizeWithNullArgumentShallReturnStorageSize)
  236. {
  237. // given
  238. UA_ExtensionObject* arg = UA_NULL;
  239. // when
  240. UA_Int32 storageSize = UA_ExtensionObject_calcSize(arg);
  241. // then
  242. ck_assert_int_eq(storageSize, sizeof(UA_ExtensionObject));
  243. }
  244. END_TEST
  245. START_TEST(UA_ExtensionObject_calcSizeShallWorkOnExample)
  246. {
  247. // given
  248. UA_Byte data[3] = {1,2,3};
  249. UA_ExtensionObject extensionObject;
  250. // empty ExtensionObject, handcoded
  251. // when
  252. extensionObject.typeId.encodingByte = UA_NODEIDTYPE_TWOBYTE;
  253. extensionObject.typeId.identifier.numeric = 0;
  254. extensionObject.encoding = UA_EXTENSIONOBJECT_ENCODINGMASKTYPE_NOBODYISENCODED;
  255. // then
  256. ck_assert_int_eq(UA_ExtensionObject_calcSize(&extensionObject), 1 + 1 + 1);
  257. // ExtensionObject with ByteString-Body
  258. // when
  259. extensionObject.encoding = UA_EXTENSIONOBJECT_ENCODINGMASKTYPE_BODYISBYTESTRING;
  260. extensionObject.body.data = data;
  261. extensionObject.body.length = 3;
  262. // then
  263. ck_assert_int_eq(UA_ExtensionObject_calcSize(&extensionObject), 3 + 4 + 3);
  264. }
  265. END_TEST
  266. START_TEST(UA_DataValue_calcSizeShallWorkOnExample)
  267. {
  268. // given
  269. UA_DataValue dataValue;
  270. dataValue.encodingMask = UA_DATAVALUE_STATUSCODE | UA_DATAVALUE_SOURCETIMESTAMP | UA_DATAVALUE_SOURCEPICOSECONDS;
  271. dataValue.status = 12;
  272. UA_DateTime dateTime;
  273. dateTime = 80;
  274. dataValue.sourceTimestamp = dateTime;
  275. UA_DateTime sourceTime;
  276. sourceTime = 214;
  277. dataValue.sourcePicoseconds = sourceTime;
  278. int size = 0;
  279. // when
  280. size = UA_DataValue_calcSize(&dataValue);
  281. // then
  282. ck_assert_int_eq(size, 21);
  283. }
  284. END_TEST
  285. START_TEST(UA_DataValue_calcSizeWithNullArgumentShallReturnStorageSize)
  286. {
  287. // given
  288. UA_DataValue* arg = UA_NULL;
  289. // when
  290. UA_Int32 storageSize = UA_DataValue_calcSize(arg);
  291. // then
  292. ck_assert_int_eq(storageSize, sizeof(UA_DataValue));
  293. }
  294. END_TEST
  295. START_TEST(UA_Variant_calcSizeWithNullArgumentShallReturnStorageSize)
  296. {
  297. // given
  298. UA_Variant* arg = UA_NULL;
  299. // when
  300. UA_Int32 storageSize = UA_Variant_calcSize(arg);
  301. // then
  302. ck_assert_int_eq(storageSize, sizeof(UA_Variant));
  303. }
  304. END_TEST
  305. START_TEST(UA_DiagnosticInfo_calcSizeShallWorkOnExample)
  306. {
  307. // given
  308. UA_DiagnosticInfo diagnosticInfo;
  309. diagnosticInfo.encodingMask = 0x01 | 0x02 | 0x04 | 0x08 | 0x10;
  310. diagnosticInfo.symbolicId = 30;
  311. diagnosticInfo.namespaceUri = 25;
  312. diagnosticInfo.localizedText = 22;
  313. UA_Byte additionalInfoData = 'd';
  314. diagnosticInfo.additionalInfo.data = &additionalInfoData;//"OPCUA";
  315. diagnosticInfo.additionalInfo.length = 5;
  316. // when & then
  317. ck_assert_int_eq(UA_DiagnosticInfo_calcSize(&diagnosticInfo),26);
  318. }
  319. END_TEST
  320. START_TEST(UA_DiagnosticInfo_calcSizeWithNullArgumentShallReturnStorageSize)
  321. {
  322. // given
  323. UA_DiagnosticInfo* arg = UA_NULL;
  324. // when
  325. UA_Int32 storageSize = UA_DiagnosticInfo_calcSize(arg);
  326. // then
  327. ck_assert_int_eq(storageSize, sizeof(UA_DiagnosticInfo));
  328. }
  329. END_TEST
  330. START_TEST(UA_String_calcSizeWithNegativLengthShallReturnEncodingSize)
  331. {
  332. // given
  333. UA_String arg = {-1, UA_NULL};
  334. // when
  335. UA_Int32 encodingSize = UA_String_calcSize(&arg);
  336. // then
  337. ck_assert_int_eq(encodingSize, 4);
  338. }
  339. END_TEST
  340. START_TEST(UA_String_calcSizeWithNegativLengthAndValidPointerShallReturnEncodingSize)
  341. {
  342. // given
  343. UA_String arg = {-1, (UA_Byte*) "OPC"};
  344. // when
  345. UA_Int32 encodingSize = UA_String_calcSize(&arg);
  346. // then
  347. ck_assert_int_eq(encodingSize, 4);
  348. }
  349. END_TEST
  350. START_TEST(UA_String_calcSizeWithZeroLengthShallReturnEncodingSize)
  351. {
  352. // given
  353. UA_String arg = {0, UA_NULL};
  354. // when
  355. UA_Int32 encodingSize = UA_String_calcSize(&arg);
  356. // then
  357. ck_assert_int_eq(encodingSize, 4);
  358. }
  359. END_TEST
  360. START_TEST(UA_String_calcSizeWithZeroLengthAndValidPointerShallReturnEncodingSize)
  361. {
  362. // given
  363. UA_String arg = {0, (UA_Byte*) "OPC"};
  364. // when
  365. UA_Int32 encodingSize = UA_String_calcSize(&arg);
  366. // then
  367. ck_assert_int_eq(encodingSize, 4);
  368. }
  369. END_TEST
  370. START_TEST(UA_String_calcSizeShallReturnEncodingSize)
  371. {
  372. // given
  373. UA_String arg = {3, (UA_Byte*) "OPC"};
  374. // when
  375. UA_Int32 encodingSize = UA_String_calcSize(&arg);
  376. // then
  377. ck_assert_int_eq(encodingSize, 4+3);
  378. }
  379. END_TEST
  380. START_TEST(UA_NodeId_calcSizeEncodingTwoByteShallReturnEncodingSize)
  381. {
  382. // given
  383. UA_NodeId arg;
  384. arg.encodingByte = UA_NODEIDTYPE_TWOBYTE;
  385. // when
  386. UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
  387. // then
  388. ck_assert_int_eq(encodingSize, 2);
  389. }
  390. END_TEST
  391. START_TEST(UA_NodeId_calcSizeEncodingFourByteShallReturnEncodingSize)
  392. {
  393. // given
  394. UA_NodeId arg;
  395. arg.encodingByte = UA_NODEIDTYPE_FOURBYTE;
  396. // when
  397. UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
  398. // then
  399. ck_assert_int_eq(encodingSize, 4);
  400. }
  401. END_TEST
  402. START_TEST(UA_NodeId_calcSizeEncodingStringShallReturnEncodingSize)
  403. {
  404. // given
  405. UA_NodeId arg;
  406. arg.encodingByte = UA_NODEIDTYPE_STRING;
  407. arg.identifier.string.length = 3;
  408. arg.identifier.string.data = (UA_Byte*) "PLT";
  409. // when
  410. UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
  411. // then
  412. ck_assert_int_eq(encodingSize, 1+2+4+3);
  413. }
  414. END_TEST
  415. START_TEST(UA_NodeId_calcSizeEncodingStringNegativLengthShallReturnEncodingSize)
  416. {
  417. // given
  418. UA_NodeId arg;
  419. arg.encodingByte = UA_NODEIDTYPE_STRING;
  420. arg.identifier.string.length = -1;
  421. // when
  422. UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
  423. // then
  424. ck_assert_int_eq(encodingSize, 1+2+4+0);
  425. }
  426. END_TEST
  427. START_TEST(UA_NodeId_calcSizeEncodingStringZeroLengthShallReturnEncodingSize)
  428. {
  429. // given
  430. UA_NodeId arg;
  431. arg.encodingByte = UA_NODEIDTYPE_STRING;
  432. arg.identifier.string.length = 0;
  433. // when
  434. UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
  435. // then
  436. ck_assert_int_eq(encodingSize, 1+2+4+0);
  437. }
  438. END_TEST
  439. START_TEST(UA_ExpandedNodeId_calcSizeEncodingStringAndServerIndexShallReturnEncodingSize)
  440. {
  441. // given
  442. UA_ExpandedNodeId arg;
  443. arg.nodeId.encodingByte = UA_NODEIDTYPE_STRING | UA_NODEIDTYPE_SERVERINDEX_FLAG;
  444. arg.nodeId.identifier.string.length = 3;
  445. // when
  446. UA_Int32 encodingSize = UA_ExpandedNodeId_calcSize(&arg);
  447. // then
  448. ck_assert_int_eq(encodingSize, 1+2+4+3+4);
  449. }
  450. END_TEST
  451. START_TEST(UA_ExpandedNodeId_calcSizeEncodingStringAndNamespaceUriShallReturnEncodingSize)
  452. {
  453. // given
  454. UA_ExpandedNodeId arg;
  455. arg.nodeId.encodingByte = UA_NODEIDTYPE_STRING | UA_NODEIDTYPE_NAMESPACE_URI_FLAG;
  456. arg.nodeId.identifier.string.length = 3;
  457. arg.namespaceUri.length = 7;
  458. // when
  459. UA_Int32 encodingSize = UA_ExpandedNodeId_calcSize(&arg);
  460. // then
  461. ck_assert_int_eq(encodingSize, 1+2+4+3+4+7);
  462. }
  463. END_TEST
  464. START_TEST(UA_Guid_calcSizeShallReturnEncodingSize)
  465. {
  466. // given
  467. UA_Guid arg;
  468. // when
  469. UA_Int32 encodingSize = UA_Guid_calcSize(&arg);
  470. // then
  471. ck_assert_int_eq(encodingSize, 16);
  472. }
  473. END_TEST
  474. START_TEST(UA_LocalizedText_calcSizeTextOnlyShallReturnEncodingSize)
  475. {
  476. // given
  477. UA_LocalizedText arg;
  478. arg.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT;
  479. arg.text.length = 42;
  480. // when
  481. UA_Int32 encodingSize = UA_LocalizedText_calcSize(&arg);
  482. // then
  483. ck_assert_int_eq(encodingSize, 1+4+42);
  484. }
  485. END_TEST
  486. START_TEST(UA_LocalizedText_calcSizeLocaleOnlyShallReturnEncodingSize)
  487. {
  488. // given
  489. UA_LocalizedText arg;
  490. arg.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_LOCALE;
  491. arg.locale.length = 11;
  492. // when
  493. UA_Int32 encodingSize = UA_LocalizedText_calcSize(&arg);
  494. // then
  495. ck_assert_int_eq(encodingSize, 1+4+11);
  496. }
  497. END_TEST
  498. START_TEST(UA_LocalizedText_calcSizeTextAndLocaleShallReturnEncodingSize)
  499. {
  500. // given
  501. UA_LocalizedText arg;
  502. arg.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_LOCALE | UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT;
  503. arg.text.length = 47;
  504. arg.locale.length = 11;
  505. // when
  506. UA_Int32 encodingSize = UA_LocalizedText_calcSize(&arg);
  507. // then
  508. ck_assert_int_eq(encodingSize, 1+4+11+4+47);
  509. }
  510. END_TEST
  511. START_TEST(UA_Variant_calcSizeFixedSizeArrayShallReturnEncodingSize)
  512. {
  513. // given
  514. UA_Variant arg;
  515. arg.encodingMask = UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY;
  516. arg.vt = &UA_[UA_INT32];
  517. #define ARRAY_LEN 8
  518. arg.arrayLength = ARRAY_LEN;
  519. UA_Int32* data[ARRAY_LEN];
  520. arg.data = (void**) &data;
  521. // when
  522. UA_Int32 encodingSize = UA_Variant_calcSize(&arg);
  523. // then
  524. ck_assert_int_eq(encodingSize, 1+4+ARRAY_LEN*4);
  525. #undef ARRAY_LEN
  526. }
  527. END_TEST
  528. START_TEST(UA_Variant_calcSizeVariableSizeArrayShallReturnEncodingSize)
  529. {
  530. // given
  531. UA_Variant arg;
  532. arg.encodingMask = UA_STRING_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY;
  533. arg.vt = &UA_[UA_STRING];
  534. #define ARRAY_LEN 3
  535. arg.arrayLength = ARRAY_LEN;
  536. UA_String s1 = {-1, UA_NULL };
  537. UA_String s2 = {3, (UA_Byte*) "PLT" };
  538. UA_String s3 = {47, UA_NULL };
  539. UA_String* data[ARRAY_LEN] = { &s1, &s2, &s3 };
  540. arg.data = (void**) &data;
  541. // when
  542. UA_Int32 encodingSize = UA_Variant_calcSize(&arg);
  543. // then
  544. ck_assert_int_eq(encodingSize, 1+4+(4+0)+(4+3)+(4+47));
  545. #undef ARRAY_LEN
  546. }
  547. END_TEST
  548. START_TEST(UA_Variant_calcSizeVariableSizeArrayWithNullPtrWillReturnWrongButLargeEnoughEncodingSize)
  549. {
  550. // given
  551. UA_Variant arg;
  552. arg.encodingMask = UA_STRING_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY;
  553. arg.vt = &UA_[UA_STRING];
  554. #define ARRAY_LEN 6
  555. arg.arrayLength = ARRAY_LEN;
  556. UA_String s1 = {-1, UA_NULL };
  557. UA_String s2 = {3, (UA_Byte*) "PLT" };
  558. UA_String s3 = {47, UA_NULL };
  559. UA_String* data[ARRAY_LEN] = { &s1, &s2, &s3 }; // will be filled with null-ptrs
  560. arg.data = (void**) &data;
  561. // when
  562. UA_Int32 encodingSize = UA_Variant_calcSize(&arg);
  563. // then
  564. ck_assert_int_ge(encodingSize, 1+4+(4+0)+(4+3)+(4+47)+(ARRAY_LEN-3)*(4+0));
  565. #undef ARRAY_LEN
  566. }
  567. END_TEST
  568. START_TEST(UA_Byte_decodeShallCopyAndAdvancePosition)
  569. {
  570. // given
  571. UA_Byte dst;
  572. UA_Byte data[]= { 0x08 };
  573. UA_ByteString src = {1, data};
  574. UA_Int32 pos = 0;
  575. // when
  576. UA_Int32 retval = UA_Byte_decodeBinary(&src, &pos, &dst);
  577. // then
  578. ck_assert_int_eq(retval, UA_SUCCESS);
  579. ck_assert_uint_eq(pos, 1);
  580. ck_assert_uint_eq(dst, 0x08);
  581. }
  582. END_TEST
  583. START_TEST(UA_Byte_decodeShallModifyOnlyCurrentPosition)
  584. {
  585. // given
  586. UA_Byte dst[] = { 0xFF, 0xFF, 0xFF };
  587. UA_Byte data[] = { 0x08 };
  588. UA_ByteString src = {1, data};
  589. UA_Int32 pos = 0;
  590. // when
  591. UA_Int32 retval = UA_Byte_decodeBinary(&src, &pos, &dst[1]);
  592. // then
  593. ck_assert_int_eq(retval, UA_SUCCESS);
  594. ck_assert_int_eq(pos, 1);
  595. ck_assert_uint_eq(dst[0], 0xFF);
  596. ck_assert_uint_eq(dst[1], 0x08);
  597. ck_assert_uint_eq(dst[2], 0xFF);
  598. }
  599. END_TEST
  600. START_TEST(UA_Int16_decodeShallAssumeLittleEndian)
  601. {
  602. // given
  603. UA_Int32 pos = 0;
  604. UA_Byte data[] = {
  605. 0x01,0x00, // 1
  606. 0x00,0x01 // 256
  607. };
  608. UA_ByteString src = { 4, data };
  609. // when
  610. UA_Int16 val_01_00, val_00_01;
  611. UA_Int32 retval = UA_Int16_decodeBinary(&src,&pos,&val_01_00);
  612. retval |= UA_Int16_decodeBinary(&src,&pos,&val_00_01);
  613. // then
  614. ck_assert_int_eq(retval,UA_SUCCESS);
  615. ck_assert_int_eq(val_01_00,1);
  616. ck_assert_int_eq(val_00_01,256);
  617. ck_assert_int_eq(pos,4);
  618. }
  619. END_TEST
  620. START_TEST(UA_Int16_decodeShallRespectSign)
  621. {
  622. // given
  623. UA_Int32 pos = 0;
  624. UA_Byte data[] = {
  625. 0xFF,0xFF, // -1
  626. 0x00,0x80 // -32768
  627. };
  628. UA_ByteString src = {4,data};
  629. // when
  630. UA_Int16 val_ff_ff, val_00_80;
  631. UA_Int32 retval = UA_Int16_decodeBinary(&src,&pos,&val_ff_ff);
  632. retval |= UA_Int16_decodeBinary(&src,&pos,&val_00_80);
  633. // then
  634. ck_assert_int_eq(retval,UA_SUCCESS);
  635. ck_assert_int_eq(val_ff_ff,-1);
  636. ck_assert_int_eq(val_00_80,-32768);
  637. }
  638. END_TEST
  639. START_TEST(UA_UInt16_decodeShallNotRespectSign)
  640. {
  641. // given
  642. UA_Int32 pos = 0;
  643. UA_Byte data[] = {
  644. 0xFF,0xFF, // (2^16)-1
  645. 0x00,0x80 // (2^15)
  646. };
  647. UA_ByteString src = {4,data};
  648. // when
  649. UA_UInt16 val_ff_ff, val_00_80;
  650. UA_Int32 retval = UA_UInt16_decodeBinary(&src,&pos,&val_ff_ff);
  651. retval |= UA_UInt16_decodeBinary(&src,&pos,&val_00_80);
  652. // then
  653. ck_assert_int_eq(retval,UA_SUCCESS);
  654. ck_assert_int_eq(pos,4);
  655. ck_assert_uint_eq(val_ff_ff, (0x01 << 16)-1);
  656. ck_assert_uint_eq(val_00_80, (0x01 << 15));
  657. }
  658. END_TEST
  659. START_TEST(UA_Int32_decodeShallAssumeLittleEndian)
  660. {
  661. // given
  662. UA_Int32 pos = 0;
  663. UA_Byte data[] = {
  664. 0x01,0x00,0x00,0x00, // 1
  665. 0x00,0x01,0x00,0x00 // 256
  666. };
  667. UA_ByteString src = {8,data};
  668. // when
  669. UA_Int32 val_01_00, val_00_01;
  670. UA_Int32 retval = UA_Int32_decodeBinary(&src,&pos,&val_01_00);
  671. retval |= UA_Int32_decodeBinary(&src,&pos,&val_00_01);
  672. // then
  673. ck_assert_int_eq(retval,UA_SUCCESS);
  674. ck_assert_int_eq(val_01_00,1);
  675. ck_assert_int_eq(val_00_01,256);
  676. ck_assert_int_eq(pos,8);
  677. }
  678. END_TEST
  679. START_TEST(UA_Int32_decodeShallRespectSign)
  680. {
  681. // given
  682. UA_Int32 pos = 0;
  683. UA_Byte data[] = {
  684. 0xFF,0xFF,0xFF,0xFF, // -1
  685. 0x00,0x80,0xFF,0xFF // -32768
  686. };
  687. UA_ByteString src = {8,data};
  688. // when
  689. UA_Int32 val_ff_ff, val_00_80;
  690. UA_Int32 retval = UA_Int32_decodeBinary(&src,&pos,&val_ff_ff);
  691. retval |= UA_Int32_decodeBinary(&src,&pos,&val_00_80);
  692. // then
  693. ck_assert_int_eq(retval,UA_SUCCESS);
  694. ck_assert_int_eq(val_ff_ff,-1);
  695. ck_assert_int_eq(val_00_80,-32768);
  696. }
  697. END_TEST
  698. START_TEST(UA_UInt32_decodeShallNotRespectSign)
  699. {
  700. // given
  701. UA_Int32 pos = 0;
  702. UA_Byte data[] = {
  703. 0xFF,0xFF,0xFF,0xFF, // (2^32)-1
  704. 0x00,0x00,0x00,0x80 // (2^31)
  705. };
  706. UA_ByteString src = {8,data};
  707. // when
  708. UA_UInt32 val_ff_ff, val_00_80;
  709. UA_Int32 retval = UA_UInt32_decodeBinary(&src,&pos,&val_ff_ff);
  710. retval |= UA_UInt32_decodeBinary(&src,&pos,&val_00_80);
  711. // then
  712. ck_assert_int_eq(retval,UA_SUCCESS);
  713. ck_assert_int_eq(pos,8);
  714. ck_assert_uint_eq(val_ff_ff, (UA_UInt32) ( (0x01LL << 32 ) - 1 ));
  715. ck_assert_uint_eq(val_00_80, (UA_UInt32) (0x01 << 31));
  716. }
  717. END_TEST
  718. /*START_TEST(UA_UInt64_decodeShallNotRespectSign)
  719. {
  720. // given
  721. UA_ByteString rawMessage;
  722. UA_UInt64 expectedVal = 0xFF;
  723. expectedVal = expectedVal << 56;
  724. UA_Byte mem[8] = {00,00,00,00,0x00,0x00,0x00,0xFF};
  725. rawMessage.data = mem;
  726. rawMessage.length = 8;
  727. UA_Int32 p = 0;
  728. UA_UInt64 val;
  729. // when
  730. UA_UInt64_decodeBinary(rawMessage.data, &p, &val);
  731. // then
  732. ck_assert_uint_eq(val, expectedVal);
  733. }
  734. END_TEST
  735. START_TEST(UA_Int64_decodeShallRespectSign)
  736. {
  737. // given
  738. UA_ByteString rawMessage;
  739. UA_Int64 expectedVal = 0xFF;
  740. expectedVal = expectedVal << 56;
  741. UA_Byte mem[8] = {00,00,00,00,0x00,0x00,0x00,0xFF};
  742. rawMessage.data = mem;
  743. rawMessage.length = 8;
  744. UA_Int32 p = 0;
  745. UA_Int64 val;
  746. // when
  747. UA_Int64_decodeBinary(rawMessage.data, &p, &val);
  748. //then
  749. ck_assert_uint_eq(val, expectedVal);
  750. }
  751. END_TEST*/
  752. START_TEST(UA_Float_decodeShallWorkOnExample)
  753. {
  754. // given
  755. UA_Int32 pos = 0;
  756. UA_Byte data[] = { 0x00,0x00,0xD0,0xC0 }; // -6.5
  757. UA_ByteString src = {4,data};
  758. UA_Float dst;
  759. // when
  760. UA_Int32 retval = UA_Float_decodeBinary(&src,&pos,&dst);
  761. // then
  762. ck_assert_int_eq(retval,UA_SUCCESS);
  763. ck_assert_int_eq(pos,4);
  764. ck_assert(-6.5000001 < dst);
  765. ck_assert(dst < -6.49999999999);
  766. }
  767. END_TEST
  768. START_TEST(UA_Double_decodeShallGiveOne)
  769. {
  770. // given
  771. UA_Int32 pos = 0;
  772. UA_Byte data[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x3F }; // 1
  773. UA_ByteString src = {8,data}; // 1
  774. UA_Double dst;
  775. // when
  776. UA_Int32 retval = UA_Double_decodeBinary(&src,&pos,&dst);
  777. // then
  778. ck_assert_int_eq(retval,UA_SUCCESS);
  779. ck_assert_int_eq(pos,8);
  780. printf("UA_Double_decodeShallGiveOne %f\n",dst);
  781. ck_assert(0.9999999 < dst);
  782. ck_assert(dst < 1.00000000001);
  783. }
  784. END_TEST
  785. START_TEST(UA_Double_decodeShallGiveZero)
  786. {
  787. // given
  788. UA_Int32 pos = 0;
  789. UA_Byte data[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  790. UA_ByteString src = {8,data}; // 1
  791. UA_Double dst;
  792. // when
  793. UA_Int32 retval = UA_Double_decodeBinary(&src,&pos,&dst);
  794. // then
  795. ck_assert_int_eq(retval,UA_SUCCESS);
  796. ck_assert_int_eq(pos,8);
  797. printf("UA_Double_decodeShallGiveZero %f\n",dst);
  798. ck_assert(-0.00000001 < dst);
  799. ck_assert(dst < 0.000000001);
  800. }
  801. END_TEST
  802. START_TEST(UA_Double_decodeShallGiveMinusTwo)
  803. {
  804. // given
  805. UA_Int32 pos = 0;
  806. UA_Byte data[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0 }; // -2
  807. UA_ByteString src = {8,data};
  808. UA_Double dst;
  809. // when
  810. UA_Int32 retval = UA_Double_decodeBinary(&src,&pos,&dst);
  811. // then
  812. ck_assert_int_eq(retval,UA_SUCCESS);
  813. ck_assert_int_eq(pos,8);
  814. ck_assert(-1.9999999 > dst);
  815. ck_assert(dst > -2.00000000001);
  816. }
  817. END_TEST
  818. START_TEST(UA_String_decodeShallAllocateMemoryAndCopyString)
  819. {
  820. // given
  821. UA_Int32 pos = 0;
  822. UA_Byte data[] = {0x08,0x00,0x00,0x00,'A','C','P','L','T',' ','U','A',0xFF,0xFF,0xFF,0xFF,0xFF};
  823. UA_ByteString src = {16,data};
  824. UA_String dst;
  825. // when
  826. UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
  827. // then
  828. ck_assert_int_eq(retval,UA_SUCCESS);
  829. ck_assert_int_eq(dst.length,8);
  830. ck_assert_ptr_eq(dst.data,UA_alloc_lastptr);
  831. ck_assert_int_eq(dst.data[3],'L');
  832. // finally
  833. UA_String_deleteMembers(&dst);
  834. }
  835. END_TEST
  836. START_TEST(UA_String_decodeWithNegativeSizeShallNotAllocateMemoryAndNullPtr)
  837. {
  838. // given
  839. UA_Int32 pos = 0;
  840. UA_Byte data[] = {0xFF,0xFF,0xFF,0xFF,'A','C','P','L','T',' ','U','A',0xFF,0xFF,0xFF,0xFF,0xFF};
  841. UA_ByteString src = {16,data};
  842. UA_String dst;
  843. // when
  844. UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
  845. // then
  846. ck_assert_int_eq(retval,UA_SUCCESS);
  847. ck_assert_int_eq(dst.length,-1);
  848. ck_assert_ptr_eq(dst.data,UA_NULL);
  849. }
  850. END_TEST
  851. START_TEST(UA_String_decodeWithZeroSizeShallNotAllocateMemoryAndNullPtr)
  852. {
  853. // given
  854. UA_Int32 pos = 0;
  855. UA_Byte data[] = {0x00,0x00,0x00,0x00,'A','C','P','L','T',' ','U','A',0xFF,0xFF,0xFF,0xFF,0xFF};
  856. UA_ByteString src = {16,data};
  857. UA_String dst = { 2, (UA_Byte*) "XX" };
  858. // when
  859. UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
  860. // then
  861. ck_assert_int_eq(retval,UA_SUCCESS);
  862. ck_assert_int_eq(dst.length,0);
  863. ck_assert_ptr_eq(dst.data,UA_NULL);
  864. }
  865. END_TEST
  866. START_TEST(UA_NodeId_decodeTwoByteShallReadTwoBytesAndSetNamespaceToZero)
  867. {
  868. // given
  869. UA_Int32 pos = 0;
  870. UA_Byte data[] = { UA_NODEIDTYPE_TWOBYTE, 0x10 };
  871. UA_ByteString src = {2,data};
  872. UA_NodeId dst;
  873. // when
  874. UA_Int32 retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
  875. // then
  876. ck_assert_int_eq(retval,UA_SUCCESS);
  877. ck_assert_int_eq(pos,2);
  878. ck_assert_int_eq(dst.encodingByte, UA_NODEIDTYPE_TWOBYTE);
  879. ck_assert_int_eq(dst.identifier.numeric,16);
  880. ck_assert_int_eq(dst.namespace,0);
  881. }
  882. END_TEST
  883. START_TEST(UA_NodeId_decodeFourByteShallReadFourBytesAndRespectNamespace)
  884. {
  885. // given
  886. UA_Int32 pos = 0;
  887. UA_Byte data[] = { UA_NODEIDTYPE_FOURBYTE, 0x01, 0x00, 0x01 };
  888. UA_ByteString src = {4,data};
  889. UA_NodeId dst;
  890. // when
  891. UA_Int32 retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
  892. // then
  893. ck_assert_int_eq(retval,UA_SUCCESS);
  894. ck_assert_int_eq(pos,4);
  895. ck_assert_int_eq(dst.encodingByte, UA_NODEIDTYPE_FOURBYTE);
  896. ck_assert_int_eq(dst.identifier.numeric,256);
  897. ck_assert_int_eq(dst.namespace,1);
  898. }
  899. END_TEST
  900. START_TEST(UA_NodeId_decodeStringShallAllocateMemory)
  901. {
  902. // given
  903. UA_Int32 pos = 0;
  904. UA_Byte data[]= { UA_NODEIDTYPE_STRING, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 'P', 'L', 'T' };
  905. UA_ByteString src = {10,data};
  906. UA_NodeId dst;
  907. // when
  908. UA_Int32 retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
  909. // then
  910. ck_assert_int_eq(retval,UA_SUCCESS);
  911. ck_assert_int_eq(pos,10);
  912. ck_assert_int_eq(dst.encodingByte, UA_NODEIDTYPE_STRING);
  913. ck_assert_int_eq(dst.namespace,1);
  914. ck_assert_int_eq(dst.identifier.string.length,3);
  915. ck_assert_ptr_eq(dst.identifier.string.data,UA_alloc_lastptr);
  916. ck_assert_int_eq(dst.identifier.string.data[1],'L');
  917. // finally
  918. UA_NodeId_deleteMembers(&dst);
  919. }
  920. END_TEST
  921. START_TEST(UA_Variant_decodeWithOutArrayFlagSetShallSetVTAndAllocateMemoryForArray)
  922. {
  923. // given
  924. UA_Int32 pos = 0;
  925. UA_Byte data[] = { UA_INT32_NS0, 0xFF, 0x00, 0x00, 0x00};
  926. UA_ByteString src = {5,data};
  927. UA_Variant dst;
  928. // when
  929. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  930. // then
  931. ck_assert_int_eq(retval,UA_SUCCESS);
  932. ck_assert_int_eq(pos,5);
  933. ck_assert_uint_eq(dst.encodingMask, UA_INT32_NS0);
  934. ck_assert_ptr_eq(dst.vt, &UA_[UA_INT32]);
  935. ck_assert_int_eq(dst.arrayLength,1);
  936. ck_assert_ptr_ne(dst.data,UA_NULL);
  937. ck_assert_ptr_eq(dst.data[0],UA_alloc_lastptr);
  938. ck_assert_int_eq(*(UA_Int32*)dst.data[0],255);
  939. // finally
  940. UA_Variant_deleteMembers(&dst);
  941. }
  942. END_TEST
  943. START_TEST(UA_Variant_decodeWithArrayFlagSetShallSetVTAndAllocateMemoryForArray)
  944. {
  945. // given
  946. UA_Int32 pos = 0;
  947. UA_Byte data[]={ UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
  948. UA_ByteString src = {13,data};
  949. UA_Variant dst;
  950. // when
  951. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  952. // then
  953. ck_assert_int_eq(retval,UA_SUCCESS);
  954. ck_assert_int_eq(pos,1+4+2*4);
  955. ck_assert_uint_eq(dst.encodingMask & UA_VARIANT_ENCODINGMASKTYPE_TYPEID_MASK, UA_INT32_NS0);
  956. ck_assert_uint_eq(dst.encodingMask & UA_VARIANT_ENCODINGMASKTYPE_ARRAY, UA_VARIANT_ENCODINGMASKTYPE_ARRAY);
  957. ck_assert_ptr_eq(dst.vt, &UA_[UA_INT32]);
  958. ck_assert_int_eq(dst.arrayLength,2);
  959. ck_assert_ptr_ne(dst.data,UA_NULL);
  960. ck_assert_ptr_eq(dst.data[1],UA_alloc_lastptr);
  961. ck_assert_int_eq(*((UA_Int32*)dst.data[0]),255);
  962. ck_assert_int_eq(*((UA_Int32*)dst.data[1]),-1);
  963. // finally
  964. UA_Variant_deleteMembers(&dst);
  965. }
  966. END_TEST
  967. START_TEST(UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem)
  968. {
  969. // given
  970. UA_Int32 pos = 0;
  971. UA_Byte data[]= { UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
  972. UA_ByteString src = {13,data};
  973. UA_Variant dst;
  974. // when
  975. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  976. // then
  977. ck_assert_int_eq(retval,UA_SUCCESS);
  978. // finally - unfortunately we cannot express that not freeing three chunks is what we expect
  979. // UA_Variant_deleteMembers(&dst);
  980. }
  981. END_TEST
  982. START_TEST(UA_Variant_decodeWithTooSmallSourceShallReturnWithError)
  983. {
  984. // given
  985. UA_Int32 pos = 0;
  986. UA_Byte data[]= { UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
  987. UA_ByteString src = {4,data};
  988. UA_Variant dst;
  989. // when
  990. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  991. // then
  992. ck_assert_int_ne(retval,UA_SUCCESS);
  993. // finally - unfortunately we cannot express that not freeing three chunks is what we expect
  994. // UA_Variant_deleteMembers(&dst);
  995. }
  996. END_TEST
  997. START_TEST(UA_Byte_encode_test)
  998. {
  999. // given
  1000. UA_Byte src;
  1001. UA_Byte data[] = { 0x00, 0xFF };
  1002. UA_ByteString dst = {2,data};
  1003. UA_Int32 retval, pos = 0;
  1004. ck_assert_uint_eq(dst.data[1], 0xFF);
  1005. src = 8;
  1006. retval = UA_Byte_encodeBinary(&src, &pos, &dst);
  1007. ck_assert_uint_eq(dst.data[0], 0x08);
  1008. ck_assert_uint_eq(dst.data[1], 0xFF);
  1009. ck_assert_int_eq(pos, 1);
  1010. ck_assert_int_eq(retval, UA_SUCCESS);
  1011. // Test2
  1012. // given
  1013. src = 0xFF;
  1014. dst.data[1] = 0x00;
  1015. pos = 0;
  1016. retval = UA_Byte_encodeBinary(&src, &pos, &dst);
  1017. ck_assert_int_eq(dst.data[0], 0xFF);
  1018. ck_assert_int_eq(dst.data[1], 0x00);
  1019. ck_assert_int_eq(pos, 1);
  1020. ck_assert_int_eq(retval, UA_SUCCESS);
  1021. }
  1022. END_TEST
  1023. /*START_TEST(UA_ByteString_encodeShallWorkOnExample)
  1024. {
  1025. // given
  1026. UA_ByteString rawMessage;
  1027. UA_Int32 position = 0;
  1028. UA_Byte *mem = malloc(sizeof(UA_Byte));
  1029. rawMessage.data = mem;
  1030. UA_Byte testByte = 0x08;
  1031. rawMessage.length = 1;
  1032. position = 0;
  1033. // when
  1034. UA_Byte_encodeBinary(&(testByte), &position, rawMessage.data);
  1035. // then
  1036. ck_assert_int_eq(rawMessage.data[0], 0x08);
  1037. ck_assert_int_eq(rawMessage.length, 1);
  1038. ck_assert_int_eq(position, 1);
  1039. // finally
  1040. free(mem);
  1041. }
  1042. END_TEST
  1043. START_TEST(UA_Int16_encodeShallWorkOnExample)
  1044. {
  1045. // given
  1046. UA_ByteString rawMessage;
  1047. UA_Int32 position = 0;
  1048. UA_Byte *mem = malloc(sizeof(UA_UInt16));
  1049. rawMessage.data = mem;
  1050. UA_UInt16 testUInt16 = 1;
  1051. rawMessage.length = 2;
  1052. position = 0;
  1053. // when
  1054. UA_UInt16_encodeBinary(&testUInt16, &position, rawMessage.data);
  1055. // then
  1056. ck_assert_int_eq(position, 2);
  1057. UA_Int32 p = 0;
  1058. UA_UInt16 val;
  1059. UA_UInt16_decodeBinary(rawMessage.data, &p, &val);
  1060. ck_assert_int_eq(val,testUInt16);
  1061. //ck_assert_int_eq(rawMessage.data[0], 0xAB);
  1062. // finally
  1063. free(mem);
  1064. }
  1065. END_TEST
  1066. START_TEST(UA_UInt16_encodeShallWorkOnExample)
  1067. {
  1068. // given
  1069. UA_ByteString rawMessage;
  1070. UA_Int32 position = 0;
  1071. UA_Byte *mem = (UA_Byte*) malloc(sizeof(UA_UInt16));
  1072. rawMessage.data = mem;
  1073. UA_UInt16 testUInt16 = 1;
  1074. rawMessage.length = 2;
  1075. position = 0;
  1076. // when
  1077. UA_UInt16_encodeBinary(&testUInt16, &position, rawMessage.data);
  1078. // then
  1079. ck_assert_int_eq(position, 2);
  1080. UA_Int32 p = 0;
  1081. UA_UInt16 val;
  1082. UA_UInt16_decodeBinary(rawMessage.data, &p, &val);
  1083. ck_assert_int_eq(val,testUInt16);
  1084. //ck_assert_int_eq(rawMessage.data[0], 0xAB);
  1085. // finally
  1086. free(mem);
  1087. }
  1088. END_TEST
  1089. START_TEST(UA_UInt32_encodeShallWorkOnExample)
  1090. {
  1091. // given
  1092. UA_ByteString rawMessage;
  1093. UA_UInt32 value = 0x0101FF00;
  1094. rawMessage.data = (UA_Byte*) malloc(2 * sizeof(UA_UInt32));
  1095. rawMessage.length = 8;
  1096. UA_Int32 p = 4;
  1097. // when
  1098. UA_UInt32_encodeBinary(&value,&p,rawMessage.data);
  1099. // then
  1100. ck_assert_uint_eq(rawMessage.data[4],0x00);
  1101. ck_assert_uint_eq(rawMessage.data[5],0xFF);
  1102. ck_assert_uint_eq(rawMessage.data[6],0x01);
  1103. ck_assert_uint_eq(rawMessage.data[7],0x01);
  1104. ck_assert_int_eq(p,8);
  1105. // finally
  1106. free(rawMessage.data);
  1107. }
  1108. END_TEST
  1109. START_TEST(UA_Int32_encodeShallEncodeLittleEndian)
  1110. {
  1111. // given
  1112. UA_Int32 value = 0x01020304;
  1113. UA_Byte buf[4];
  1114. UA_Int32 p = 0;
  1115. // when
  1116. UA_Int32_encodeBinary(&value,&p,buf);
  1117. // then
  1118. ck_assert_int_eq(p,4);
  1119. ck_assert_uint_eq(buf[0],0x04);
  1120. ck_assert_uint_eq(buf[1],0x03);
  1121. ck_assert_uint_eq(buf[2],0x02);
  1122. ck_assert_uint_eq(buf[3],0x01);
  1123. }
  1124. END_TEST
  1125. START_TEST(UA_Int32_encodeNegativeShallEncodeLittleEndian)
  1126. {
  1127. // given
  1128. UA_Int32 value = -1;
  1129. UA_Byte buf[4];
  1130. UA_Int32 p = 0;
  1131. // when
  1132. UA_Int32_encodeBinary(&value,&p,buf);
  1133. // then
  1134. ck_assert_int_eq(p,4);
  1135. ck_assert_uint_eq(buf[0],0xFF);
  1136. ck_assert_uint_eq(buf[1],0xFF);
  1137. ck_assert_uint_eq(buf[2],0xFF);
  1138. ck_assert_uint_eq(buf[3],0xFF);
  1139. }
  1140. END_TEST
  1141. START_TEST(UA_UInt64_encodeShallWorkOnExample)
  1142. {
  1143. // given
  1144. UA_ByteString rawMessage;
  1145. UA_UInt64 value = 0x0101FF00FF00FF00;
  1146. rawMessage.data = (UA_Byte*) malloc(sizeof(UA_UInt64));
  1147. rawMessage.length = 8;
  1148. UA_Int32 p = 0;
  1149. // when
  1150. UA_UInt64_encodeBinary(&value, &p,rawMessage.data);
  1151. // then
  1152. ck_assert_uint_eq((UA_Byte)rawMessage.data[0],0x00);
  1153. ck_assert_uint_eq((UA_Byte)rawMessage.data[1],0xFF);
  1154. ck_assert_uint_eq((UA_Byte)rawMessage.data[2],0x00);
  1155. ck_assert_uint_eq((UA_Byte)rawMessage.data[3],0xFF);
  1156. ck_assert_uint_eq((UA_Byte)rawMessage.data[4],0x00);
  1157. ck_assert_uint_eq((UA_Byte)rawMessage.data[5],0xFF);
  1158. ck_assert_uint_eq((UA_Byte)rawMessage.data[6],0x01);
  1159. ck_assert_uint_eq((UA_Byte)rawMessage.data[7],0x01);
  1160. // finally
  1161. free(rawMessage.data);
  1162. }
  1163. END_TEST
  1164. START_TEST(UA_Int64_encodeShallWorkOnExample)
  1165. {
  1166. // given
  1167. UA_ByteString rawMessage;
  1168. UA_UInt64 value = 0x0101FF00FF00FF00;
  1169. rawMessage.data = (UA_Byte*) malloc(sizeof(UA_UInt64));
  1170. rawMessage.length = 8;
  1171. UA_Int32 p = 0;
  1172. // when
  1173. UA_UInt64_encodeBinary(&value, &p,rawMessage.data);
  1174. // then
  1175. ck_assert_uint_eq(rawMessage.data[0],0x00);
  1176. ck_assert_uint_eq(rawMessage.data[1],0xFF);
  1177. ck_assert_uint_eq(rawMessage.data[2],0x00);
  1178. ck_assert_uint_eq(rawMessage.data[3],0xFF);
  1179. ck_assert_uint_eq(rawMessage.data[4],0x00);
  1180. ck_assert_uint_eq(rawMessage.data[5],0xFF);
  1181. ck_assert_uint_eq(rawMessage.data[6],0x01);
  1182. ck_assert_uint_eq(rawMessage.data[7],0x01);
  1183. // finally
  1184. free(rawMessage.data);
  1185. }
  1186. END_TEST
  1187. START_TEST(UA_Float_encodeShallWorkOnExample)
  1188. {
  1189. // given
  1190. UA_Float value = -6.5;
  1191. UA_Int32 pos = 0;
  1192. UA_Byte* buf = (UA_Byte*)malloc(sizeof(UA_Float));
  1193. // when
  1194. UA_Float_encodeBinary(&value,&pos,buf);
  1195. // then
  1196. ck_assert_uint_eq(buf[2],0xD0);
  1197. ck_assert_uint_eq(buf[3],0xC0);
  1198. // finally
  1199. free(buf);
  1200. }
  1201. END_TEST
  1202. START_TEST(encodeDouble_test)
  1203. {
  1204. UA_Double value = -6.5;
  1205. UA_Int32 pos = 0;
  1206. UA_Byte* buf = (char*)malloc(sizeof(UA_Double));
  1207. UA_Double_encode(&value,&pos,buf);
  1208. ck_assert_uint_eq(buf[6],0xD0);
  1209. ck_assert_uint_eq(buf[7],0xC0);
  1210. free(buf);
  1211. }
  1212. END_TEST
  1213. START_TEST(UA_String_encodeShallWorkOnExample)
  1214. {
  1215. // given
  1216. UA_Int32 pos = 0;
  1217. UA_String string;
  1218. UA_Int32 l = 11;
  1219. UA_Byte mem[11] = "ACPLT OPCUA";
  1220. UA_Byte *dstBuf = (UA_Byte*) malloc(sizeof(UA_Int32)+l);
  1221. string.data = mem;
  1222. string.length = 11;
  1223. // when
  1224. UA_String_encodeBinary(&string, &pos, dstBuf);
  1225. // then
  1226. ck_assert_int_eq(dstBuf[0],11);
  1227. ck_assert_int_eq(dstBuf[0+sizeof(UA_Int32)],'A');
  1228. // finally
  1229. free(dstBuf);
  1230. }
  1231. END_TEST
  1232. START_TEST(UA_DataValue_encodeShallWorkOnExampleWithoutVariant)
  1233. {
  1234. // given
  1235. UA_DataValue dataValue;
  1236. UA_Int32 pos = 0;
  1237. UA_Byte* buf = (UA_Byte*) malloc(15);
  1238. UA_DateTime dateTime;
  1239. dateTime = 80;
  1240. dataValue.serverTimestamp = dateTime;
  1241. dataValue.encodingMask = UA_DATAVALUE_SERVERTIMPSTAMP; //Only the sourcePicoseconds
  1242. // when
  1243. UA_DataValue_encodeBinary(&dataValue, &pos, buf);
  1244. //then
  1245. ck_assert_int_eq(pos, 9);// represents the length
  1246. ck_assert_uint_eq(buf[0], 0x08); // encodingMask
  1247. ck_assert_uint_eq(buf[1], 80); // 8 Byte serverTimestamp
  1248. ck_assert_uint_eq(buf[2], 0);
  1249. ck_assert_uint_eq(buf[3], 0);
  1250. ck_assert_uint_eq(buf[4], 0);
  1251. ck_assert_uint_eq(buf[5], 0);
  1252. ck_assert_uint_eq(buf[6], 0);
  1253. ck_assert_uint_eq(buf[7], 0);
  1254. ck_assert_uint_eq(buf[8], 0);
  1255. // finally
  1256. free(buf);
  1257. }
  1258. END_TEST
  1259. START_TEST(UA_DataValue_encodeShallWorkOnExampleWithVariant)
  1260. {
  1261. // given
  1262. UA_DataValue dataValue;
  1263. UA_Int32 pos = 0, retval;
  1264. UA_Byte* buf = (UA_Byte*) malloc(15);
  1265. dataValue.encodingMask = UA_DATAVALUE_VARIANT | UA_DATAVALUE_SERVERTIMPSTAMP; //Variant & SourvePicoseconds
  1266. dataValue.value.vt = &UA_[UA_INT32];
  1267. dataValue.value.arrayLength = 0;
  1268. dataValue.value.encodingMask = UA_INT32_NS0;
  1269. UA_DateTime serverTime = 80;
  1270. dataValue.serverTimestamp = serverTime;
  1271. UA_Int32 data = 45;
  1272. UA_Int32* pdata = &data;
  1273. dataValue.value.data = (void**) &pdata;
  1274. pos = 0;
  1275. // when
  1276. retval = UA_DataValue_encodeBinary(&dataValue, &pos, buf);
  1277. // then
  1278. ck_assert_int_eq(retval, UA_SUCCESS);
  1279. ck_assert_int_eq(pos, 1+(1+4)+8);// represents the length
  1280. ck_assert_uint_eq(buf[0], 0x08 | 0x01); // encodingMask
  1281. ck_assert_uint_eq(buf[1], 0x06); // Variant's Encoding Mask - INT32
  1282. ck_assert_uint_eq(buf[2], 45); // the single value
  1283. ck_assert_uint_eq(buf[3], 0);
  1284. ck_assert_uint_eq(buf[4], 0);
  1285. ck_assert_uint_eq(buf[5], 0);
  1286. ck_assert_uint_eq(buf[6], 80); // the server timestamp
  1287. ck_assert_uint_eq(buf[7], 0);
  1288. // finally
  1289. free(buf);
  1290. }
  1291. END_TEST*/
  1292. Suite *testSuite_builtin(void)
  1293. {
  1294. Suite *s = suite_create("Built-in Data Types 62541-6 Table 1");
  1295. TCase *tc_calcSize = tcase_create("calcSize");
  1296. tcase_add_test(tc_calcSize, UA_Boolean_calcSizeWithNullArgumentShallReturnStorageSize);
  1297. tcase_add_test(tc_calcSize, UA_SByte_calcSizeWithNullArgumentShallReturnStorageSize);
  1298. tcase_add_test(tc_calcSize, UA_Byte_calcSizeWithNullArgumentShallReturnStorageSize);
  1299. tcase_add_test(tc_calcSize, UA_Int16_calcSizeWithNullArgumentShallReturnStorageSize);
  1300. tcase_add_test(tc_calcSize, UA_UInt16_calcSizeWithNullArgumentShallReturnStorageSize);
  1301. tcase_add_test(tc_calcSize, UA_Int32_calcSizeWithNullArgumentShallReturnStorageSize);
  1302. tcase_add_test(tc_calcSize, UA_UInt32_calcSizeWithNullArgumentShallReturnStorageSize);
  1303. tcase_add_test(tc_calcSize, UA_Int64_calcSizeWithNullArgumentShallReturnStorageSize);
  1304. tcase_add_test(tc_calcSize, UA_UInt64_calcSizeWithNullArgumentShallReturnStorageSize);
  1305. tcase_add_test(tc_calcSize, UA_Float_calcSizeWithNullArgumentShallReturnStorageSize);
  1306. tcase_add_test(tc_calcSize, UA_Double_calcSizeWithNullArgumentShallReturnStorageSize);
  1307. tcase_add_test(tc_calcSize, UA_String_calcSizeWithNullArgumentShallReturnStorageSize);
  1308. tcase_add_test(tc_calcSize, UA_DateTime_calcSizeWithNullArgumentShallReturnStorageSize);
  1309. tcase_add_test(tc_calcSize, UA_Guid_calcSizeWithNullArgumentShallReturnStorageSize);
  1310. tcase_add_test(tc_calcSize, UA_ByteString_calcSizeWithNullArgumentShallReturnStorageSize);
  1311. tcase_add_test(tc_calcSize, UA_XmlElement_calcSizeWithNullArgumentShallReturnStorageSize);
  1312. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeWithNullArgumentShallReturnStorageSize);
  1313. tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeWithNullArgumentShallReturnStorageSize);
  1314. tcase_add_test(tc_calcSize, UA_StatusCode_calcSizeWithNullArgumentShallReturnStorageSize);
  1315. tcase_add_test(tc_calcSize, UA_QualifiedName_calcSizeWithNullArgumentShallReturnStorageSize);
  1316. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeWithNullArgumentShallReturnStorageSize);
  1317. tcase_add_test(tc_calcSize, UA_ExtensionObject_calcSizeShallWorkOnExample);
  1318. tcase_add_test(tc_calcSize, UA_ExtensionObject_calcSizeWithNullArgumentShallReturnStorageSize);
  1319. tcase_add_test(tc_calcSize, UA_DataValue_calcSizeShallWorkOnExample);
  1320. tcase_add_test(tc_calcSize, UA_DataValue_calcSizeWithNullArgumentShallReturnStorageSize);
  1321. tcase_add_test(tc_calcSize, UA_Variant_calcSizeWithNullArgumentShallReturnStorageSize);
  1322. tcase_add_test(tc_calcSize, UA_DiagnosticInfo_calcSizeShallWorkOnExample);
  1323. tcase_add_test(tc_calcSize, UA_DiagnosticInfo_calcSizeWithNullArgumentShallReturnStorageSize);
  1324. tcase_add_test(tc_calcSize, UA_String_calcSizeShallReturnEncodingSize);
  1325. tcase_add_test(tc_calcSize, UA_String_calcSizeWithNegativLengthShallReturnEncodingSize);
  1326. tcase_add_test(tc_calcSize, UA_String_calcSizeWithNegativLengthAndValidPointerShallReturnEncodingSize);
  1327. tcase_add_test(tc_calcSize, UA_String_calcSizeWithZeroLengthShallReturnEncodingSize);
  1328. tcase_add_test(tc_calcSize, UA_String_calcSizeWithZeroLengthAndValidPointerShallReturnEncodingSize);
  1329. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingTwoByteShallReturnEncodingSize);
  1330. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingFourByteShallReturnEncodingSize);
  1331. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringShallReturnEncodingSize);
  1332. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringNegativLengthShallReturnEncodingSize);
  1333. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringZeroLengthShallReturnEncodingSize);
  1334. tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeShallWorkOnExample);
  1335. tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeEncodingStringAndServerIndexShallReturnEncodingSize);
  1336. tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeEncodingStringAndNamespaceUriShallReturnEncodingSize);
  1337. tcase_add_test(tc_calcSize, UA_Guid_calcSizeShallReturnEncodingSize);
  1338. tcase_add_test(tc_calcSize, UA_Guid_calcSizeShallReturnEncodingSize);
  1339. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeTextOnlyShallReturnEncodingSize);
  1340. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeLocaleOnlyShallReturnEncodingSize);
  1341. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeTextAndLocaleShallReturnEncodingSize);
  1342. tcase_add_test(tc_calcSize, UA_Variant_calcSizeFixedSizeArrayShallReturnEncodingSize);
  1343. tcase_add_test(tc_calcSize, UA_Variant_calcSizeVariableSizeArrayShallReturnEncodingSize);
  1344. tcase_add_test(tc_calcSize, UA_Variant_calcSizeVariableSizeArrayWithNullPtrWillReturnWrongButLargeEnoughEncodingSize);
  1345. tcase_add_test(tc_calcSize, UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem);
  1346. suite_add_tcase(s,tc_calcSize);
  1347. TCase *tc_decode = tcase_create("decode");
  1348. tcase_add_test(tc_decode, UA_Byte_decodeShallCopyAndAdvancePosition);
  1349. tcase_add_test(tc_decode, UA_Byte_decodeShallModifyOnlyCurrentPosition);
  1350. tcase_add_test(tc_decode, UA_Int16_decodeShallAssumeLittleEndian);
  1351. tcase_add_test(tc_decode, UA_Int16_decodeShallRespectSign);
  1352. tcase_add_test(tc_decode, UA_UInt16_decodeShallNotRespectSign);
  1353. tcase_add_test(tc_decode, UA_Int32_decodeShallAssumeLittleEndian);
  1354. tcase_add_test(tc_decode, UA_Int32_decodeShallRespectSign);
  1355. tcase_add_test(tc_decode, UA_UInt32_decodeShallNotRespectSign);
  1356. // tcase_add_test(tc_decode, UA_UInt64_decodeShallNotRespectSign);
  1357. // tcase_add_test(tc_decode, UA_Int64_decodeShallRespectSign);
  1358. tcase_add_test(tc_decode, UA_Float_decodeShallWorkOnExample);
  1359. tcase_add_test(tc_decode, UA_Double_decodeShallGiveOne);
  1360. tcase_add_test(tc_decode, UA_Double_decodeShallGiveZero);
  1361. tcase_add_test(tc_decode, UA_Double_decodeShallGiveMinusTwo);
  1362. tcase_add_test(tc_decode, UA_Byte_encode_test);
  1363. tcase_add_test(tc_decode, UA_String_decodeShallAllocateMemoryAndCopyString);
  1364. tcase_add_test(tc_decode, UA_String_decodeWithNegativeSizeShallNotAllocateMemoryAndNullPtr);
  1365. tcase_add_test(tc_decode, UA_String_decodeWithZeroSizeShallNotAllocateMemoryAndNullPtr);
  1366. tcase_add_test(tc_decode, UA_NodeId_decodeTwoByteShallReadTwoBytesAndSetNamespaceToZero);
  1367. tcase_add_test(tc_decode, UA_NodeId_decodeFourByteShallReadFourBytesAndRespectNamespace);
  1368. tcase_add_test(tc_decode, UA_NodeId_decodeStringShallAllocateMemory);
  1369. tcase_add_test(tc_decode, UA_Variant_decodeWithOutArrayFlagSetShallSetVTAndAllocateMemoryForArray);
  1370. tcase_add_test(tc_decode, UA_Variant_decodeWithArrayFlagSetShallSetVTAndAllocateMemoryForArray);
  1371. tcase_add_test(tc_decode, UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem);
  1372. tcase_add_test(tc_decode, UA_Variant_decodeWithTooSmallSourceShallReturnWithError);
  1373. suite_add_tcase(s,tc_decode);
  1374. TCase *tc_encode = tcase_create("encode");
  1375. tcase_add_test(tc_encode, UA_Byte_encode_test);
  1376. /* tcase_add_test(tc_encode, UA_ByteString_encodeShallWorkOnExample);
  1377. tcase_add_test(tc_encode, UA_Int16_encodeShallWorkOnExample);
  1378. tcase_add_test(tc_encode, UA_UInt16_encodeShallWorkOnExample);
  1379. tcase_add_test(tc_encode, UA_UInt32_encodeShallWorkOnExample);
  1380. tcase_add_test(tc_encode, UA_Int32_encodeShallEncodeLittleEndian);
  1381. tcase_add_test(tc_encode, UA_Int32_encodeNegativeShallEncodeLittleEndian);
  1382. tcase_add_test(tc_encode, UA_UInt64_encodeShallWorkOnExample);
  1383. tcase_add_test(tc_encode, UA_Int64_encodeShallWorkOnExample);
  1384. tcase_add_test(tc_encode, UA_Float_encodeShallWorkOnExample);
  1385. tcase_add_test(tc_encode, UA_String_encodeShallWorkOnExample);
  1386. tcase_add_test(tc_encode, UA_DataValue_encodeShallWorkOnExampleWithoutVariant);
  1387. tcase_add_test(tc_encode, UA_DataValue_encodeShallWorkOnExampleWithVariant);*/
  1388. suite_add_tcase(s,tc_encode);
  1389. return s;
  1390. }
  1391. int main (void)
  1392. {
  1393. int number_failed = 0;
  1394. Suite* s;
  1395. SRunner* sr;
  1396. s = testSuite_builtin();
  1397. sr = srunner_create(s);
  1398. srunner_run_all(sr,CK_NORMAL);
  1399. number_failed += srunner_ntests_failed(sr);
  1400. srunner_free(sr);
  1401. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  1402. }