check_builtin.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553
  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_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. printf("UA_Double_decodeShallGiveOne %f\n",dst);
  773. ck_assert(0.9999999 < dst);
  774. ck_assert(dst < 1.00000000001);
  775. }
  776. END_TEST
  777. START_TEST(UA_Double_decodeShallGiveZero)
  778. {
  779. // given
  780. UA_Int32 pos = 0;
  781. UA_Byte data[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  782. UA_ByteString src = {8,data}; // 1
  783. UA_Double dst;
  784. // when
  785. UA_Int32 retval = UA_Double_decodeBinary(&src,&pos,&dst);
  786. // then
  787. ck_assert_int_eq(retval,UA_SUCCESS);
  788. ck_assert_int_eq(pos,8);
  789. printf("UA_Double_decodeShallGiveZero %f\n",dst);
  790. ck_assert(-0.00000001 < dst);
  791. ck_assert(dst < 0.000000001);
  792. }
  793. END_TEST
  794. START_TEST(UA_Double_decodeShallGiveMinusTwo)
  795. {
  796. // given
  797. UA_Int32 pos = 0;
  798. UA_Byte data[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0 }; // -2
  799. UA_ByteString src = {8,data};
  800. UA_Double dst;
  801. // when
  802. UA_Int32 retval = UA_Double_decodeBinary(&src,&pos,&dst);
  803. // then
  804. ck_assert_int_eq(retval,UA_SUCCESS);
  805. ck_assert_int_eq(pos,8);
  806. ck_assert(-1.9999999 > dst);
  807. ck_assert(dst > -2.00000000001);
  808. }
  809. END_TEST
  810. START_TEST(UA_String_decodeShallAllocateMemoryAndCopyString)
  811. {
  812. // given
  813. UA_Int32 pos = 0;
  814. UA_Byte data[] = {0x08,0x00,0x00,0x00,'A','C','P','L','T',' ','U','A',0xFF,0xFF,0xFF,0xFF,0xFF};
  815. UA_ByteString src = {16,data};
  816. UA_String dst;
  817. // when
  818. UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
  819. // then
  820. ck_assert_int_eq(retval,UA_SUCCESS);
  821. ck_assert_int_eq(dst.length,8);
  822. ck_assert_ptr_eq(dst.data,UA_alloc_lastptr);
  823. ck_assert_int_eq(dst.data[3],'L');
  824. // finally
  825. UA_String_deleteMembers(&dst);
  826. }
  827. END_TEST
  828. START_TEST(UA_String_decodeWithNegativeSizeShallNotAllocateMemoryAndNullPtr)
  829. {
  830. // given
  831. UA_Int32 pos = 0;
  832. UA_Byte data[] = {0xFF,0xFF,0xFF,0xFF,'A','C','P','L','T',' ','U','A',0xFF,0xFF,0xFF,0xFF,0xFF};
  833. UA_ByteString src = {16,data};
  834. UA_String dst;
  835. // when
  836. UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
  837. // then
  838. ck_assert_int_eq(retval,UA_SUCCESS);
  839. ck_assert_int_eq(dst.length,-1);
  840. ck_assert_ptr_eq(dst.data,UA_NULL);
  841. }
  842. END_TEST
  843. START_TEST(UA_String_decodeWithZeroSizeShallNotAllocateMemoryAndNullPtr)
  844. {
  845. // given
  846. UA_Int32 pos = 0;
  847. UA_Byte data[] = {0x00,0x00,0x00,0x00,'A','C','P','L','T',' ','U','A',0xFF,0xFF,0xFF,0xFF,0xFF};
  848. UA_ByteString src = {16,data};
  849. UA_String dst = { 2, (UA_Byte*) "XX" };
  850. // when
  851. UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
  852. // then
  853. ck_assert_int_eq(retval,UA_SUCCESS);
  854. ck_assert_int_eq(dst.length,0);
  855. ck_assert_ptr_eq(dst.data,UA_NULL);
  856. }
  857. END_TEST
  858. START_TEST(UA_NodeId_decodeTwoByteShallReadTwoBytesAndSetNamespaceToZero)
  859. {
  860. // given
  861. UA_Int32 pos = 0;
  862. UA_Byte data[] = { UA_NODEIDTYPE_TWOBYTE, 0x10 };
  863. UA_ByteString src = {2,data};
  864. UA_NodeId dst;
  865. // when
  866. UA_Int32 retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
  867. // then
  868. ck_assert_int_eq(retval,UA_SUCCESS);
  869. ck_assert_int_eq(pos,2);
  870. ck_assert_int_eq(dst.encodingByte, UA_NODEIDTYPE_TWOBYTE);
  871. ck_assert_int_eq(dst.identifier.numeric,16);
  872. ck_assert_int_eq(dst.namespace,0);
  873. }
  874. END_TEST
  875. START_TEST(UA_NodeId_decodeFourByteShallReadFourBytesAndRespectNamespace)
  876. {
  877. // given
  878. UA_Int32 pos = 0;
  879. UA_Byte data[] = { UA_NODEIDTYPE_FOURBYTE, 0x01, 0x00, 0x01 };
  880. UA_ByteString src = {4,data};
  881. UA_NodeId dst;
  882. // when
  883. UA_Int32 retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
  884. // then
  885. ck_assert_int_eq(retval,UA_SUCCESS);
  886. ck_assert_int_eq(pos,4);
  887. ck_assert_int_eq(dst.encodingByte, UA_NODEIDTYPE_FOURBYTE);
  888. ck_assert_int_eq(dst.identifier.numeric,256);
  889. ck_assert_int_eq(dst.namespace,1);
  890. }
  891. END_TEST
  892. START_TEST(UA_NodeId_decodeStringShallAllocateMemory)
  893. {
  894. // given
  895. UA_Int32 pos = 0;
  896. UA_Byte data[]= { UA_NODEIDTYPE_STRING, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 'P', 'L', 'T' };
  897. UA_ByteString src = {10,data};
  898. UA_NodeId dst;
  899. // when
  900. UA_Int32 retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
  901. // then
  902. ck_assert_int_eq(retval,UA_SUCCESS);
  903. ck_assert_int_eq(pos,10);
  904. ck_assert_int_eq(dst.encodingByte, UA_NODEIDTYPE_STRING);
  905. ck_assert_int_eq(dst.namespace,1);
  906. ck_assert_int_eq(dst.identifier.string.length,3);
  907. ck_assert_ptr_eq(dst.identifier.string.data,UA_alloc_lastptr);
  908. ck_assert_int_eq(dst.identifier.string.data[1],'L');
  909. // finally
  910. UA_NodeId_deleteMembers(&dst);
  911. }
  912. END_TEST
  913. START_TEST(UA_Variant_decodeWithOutArrayFlagSetShallSetVTAndAllocateMemoryForArray)
  914. {
  915. // given
  916. UA_Int32 pos = 0;
  917. UA_Byte data[] = { UA_INT32_NS0, 0xFF, 0x00, 0x00, 0x00};
  918. UA_ByteString src = {5,data};
  919. UA_Variant dst;
  920. // when
  921. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  922. // then
  923. ck_assert_int_eq(retval,UA_SUCCESS);
  924. ck_assert_int_eq(pos,5);
  925. ck_assert_uint_eq(dst.encodingMask, UA_INT32_NS0);
  926. ck_assert_ptr_eq(dst.vt, &UA_[UA_INT32]);
  927. ck_assert_int_eq(dst.arrayLength,1);
  928. ck_assert_ptr_ne(dst.data,UA_NULL);
  929. ck_assert_ptr_eq(dst.data[0],UA_alloc_lastptr);
  930. ck_assert_int_eq(*(UA_Int32*)dst.data[0],255);
  931. // finally
  932. UA_Variant_deleteMembers(&dst);
  933. }
  934. END_TEST
  935. START_TEST(UA_Variant_decodeWithArrayFlagSetShallSetVTAndAllocateMemoryForArray)
  936. {
  937. // given
  938. UA_Int32 pos = 0;
  939. UA_Byte data[]={ UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
  940. UA_ByteString src = {13,data};
  941. UA_Variant dst;
  942. // when
  943. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  944. // then
  945. ck_assert_int_eq(retval,UA_SUCCESS);
  946. ck_assert_int_eq(pos,1+4+2*4);
  947. ck_assert_uint_eq(dst.encodingMask & UA_VARIANT_ENCODINGMASKTYPE_TYPEID_MASK, UA_INT32_NS0);
  948. ck_assert_uint_eq(dst.encodingMask & UA_VARIANT_ENCODINGMASKTYPE_ARRAY, UA_VARIANT_ENCODINGMASKTYPE_ARRAY);
  949. ck_assert_ptr_eq(dst.vt, &UA_[UA_INT32]);
  950. ck_assert_int_eq(dst.arrayLength,2);
  951. ck_assert_ptr_ne(dst.data,UA_NULL);
  952. ck_assert_ptr_eq(dst.data[1],UA_alloc_lastptr);
  953. ck_assert_int_eq(*((UA_Int32*)dst.data[0]),255);
  954. ck_assert_int_eq(*((UA_Int32*)dst.data[1]),-1);
  955. // finally
  956. UA_Variant_deleteMembers(&dst);
  957. }
  958. END_TEST
  959. START_TEST(UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem)
  960. {
  961. // given
  962. UA_Int32 pos = 0;
  963. UA_Byte data[]= { UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
  964. UA_ByteString src = {13,data};
  965. UA_Variant dst;
  966. // when
  967. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  968. // then
  969. ck_assert_int_eq(retval,UA_SUCCESS);
  970. // finally - unfortunately we cannot express that not freeing three chunks is what we expect
  971. // UA_Variant_deleteMembers(&dst);
  972. }
  973. END_TEST
  974. START_TEST(UA_Variant_decodeWithTooSmallSourceShallReturnWithError)
  975. {
  976. // given
  977. UA_Int32 pos = 0;
  978. UA_Byte data[]= { UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
  979. UA_ByteString src = {4,data};
  980. UA_Variant dst;
  981. // when
  982. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  983. // then
  984. ck_assert_int_ne(retval,UA_SUCCESS);
  985. // finally - unfortunately we cannot express that not freeing three chunks is what we expect
  986. // UA_Variant_deleteMembers(&dst);
  987. }
  988. END_TEST
  989. START_TEST(UA_Byte_encode_test)
  990. {
  991. // given
  992. UA_Byte src;
  993. UA_Byte data[] = { 0x00, 0xFF };
  994. UA_ByteString dst = {2,data};
  995. UA_Int32 retval, pos = 0;
  996. ck_assert_uint_eq(dst.data[1], 0xFF);
  997. src = 8;
  998. retval = UA_Byte_encodeBinary(&src, &pos, &dst);
  999. ck_assert_uint_eq(dst.data[0], 0x08);
  1000. ck_assert_uint_eq(dst.data[1], 0xFF);
  1001. ck_assert_int_eq(pos, 1);
  1002. ck_assert_int_eq(retval, UA_SUCCESS);
  1003. // Test2
  1004. // given
  1005. src = 0xFF;
  1006. dst.data[1] = 0x00;
  1007. pos = 0;
  1008. retval = UA_Byte_encodeBinary(&src, &pos, &dst);
  1009. ck_assert_int_eq(dst.data[0], 0xFF);
  1010. ck_assert_int_eq(dst.data[1], 0x00);
  1011. ck_assert_int_eq(pos, 1);
  1012. ck_assert_int_eq(retval, UA_SUCCESS);
  1013. }
  1014. END_TEST
  1015. START_TEST(UA_UInt16_encodeNegativeShallEncodeLittleEndian)
  1016. {
  1017. // given
  1018. UA_UInt16 src;
  1019. UA_Byte data[] = { 0x55,0x55,
  1020. 0x55,0x55
  1021. };
  1022. UA_ByteString dst = {4,data};
  1023. UA_Int32 retval, pos = 0;
  1024. // when test 1
  1025. src = -1;
  1026. retval = UA_UInt16_encodeBinary(&src, &pos, &dst);
  1027. // then test 1
  1028. ck_assert_int_eq(pos, 2);
  1029. ck_assert_int_eq(dst.data[0], 0xFF);
  1030. ck_assert_int_eq(dst.data[1], 0xFF);
  1031. ck_assert_int_eq(retval, UA_SUCCESS);
  1032. // when test 2
  1033. src = -32768;
  1034. retval = UA_UInt16_encodeBinary(&src, &pos, &dst);
  1035. // then test 2
  1036. ck_assert_int_eq(pos, 4);
  1037. ck_assert_int_eq(dst.data[2], 0x00);
  1038. ck_assert_int_eq(dst.data[3], 0x80);
  1039. ck_assert_int_eq(retval, UA_SUCCESS);
  1040. }
  1041. END_TEST
  1042. START_TEST(UA_UInt16_encodeShallEncodeLittleEndian)
  1043. {
  1044. // given
  1045. UA_UInt16 src;
  1046. UA_Byte data[] = { 0x55,0x55,
  1047. 0x55,0x55
  1048. };
  1049. UA_ByteString dst = {4,data};
  1050. UA_Int32 retval, pos = 0;
  1051. // when test 1
  1052. src = 0;
  1053. retval = UA_UInt16_encodeBinary(&src, &pos, &dst);
  1054. // then test 1
  1055. ck_assert_int_eq(pos, 2);
  1056. ck_assert_int_eq(dst.data[0], 0x00);
  1057. ck_assert_int_eq(dst.data[1], 0x00);
  1058. ck_assert_int_eq(retval, UA_SUCCESS);
  1059. // when test 2
  1060. src = 32767;
  1061. retval = UA_UInt16_encodeBinary(&src, &pos, &dst);
  1062. // then test 2
  1063. ck_assert_int_eq(pos, 4);
  1064. ck_assert_int_eq(dst.data[2], 0xFF);
  1065. ck_assert_int_eq(dst.data[3], 0x7F);
  1066. ck_assert_int_eq(retval, UA_SUCCESS);
  1067. }
  1068. END_TEST
  1069. START_TEST(UA_UInt32_encodeShallEncodeLittleEndian)
  1070. {
  1071. // given
  1072. UA_UInt32 src;
  1073. UA_Byte data[] = { 0x55,0x55,0x55,0x55,
  1074. 0x55,0x55,0x55,0x55
  1075. };
  1076. UA_ByteString dst = {8,data};
  1077. UA_Int32 retval, pos = 0;
  1078. // when test 1
  1079. src = -1;
  1080. retval = UA_UInt32_encodeBinary(&src, &pos, &dst);
  1081. // then test 1
  1082. ck_assert_int_eq(pos, 4);
  1083. ck_assert_int_eq(dst.data[0], 0xFF);
  1084. ck_assert_int_eq(dst.data[1], 0xFF);
  1085. ck_assert_int_eq(dst.data[2], 0xFF);
  1086. ck_assert_int_eq(dst.data[3], 0xFF);
  1087. ck_assert_int_eq(retval, UA_SUCCESS);
  1088. // when test 2
  1089. src = 0x0101FF00;
  1090. retval = UA_UInt32_encodeBinary(&src, &pos, &dst);
  1091. // then test 2
  1092. ck_assert_int_eq(pos, 8);
  1093. ck_assert_int_eq(dst.data[4], 0x00);
  1094. ck_assert_int_eq(dst.data[5], 0xFF);
  1095. ck_assert_int_eq(dst.data[6], 0x01);
  1096. ck_assert_int_eq(dst.data[7], 0x01);
  1097. ck_assert_int_eq(retval, UA_SUCCESS);
  1098. }
  1099. END_TEST
  1100. START_TEST(UA_Int32_encodeShallEncodeLittleEndian)
  1101. {
  1102. // given
  1103. UA_Int32 src;
  1104. UA_Byte data[] = { 0x55,0x55,0x55,0x55,
  1105. 0x55,0x55,0x55,0x55
  1106. };
  1107. UA_ByteString dst = {8,data};
  1108. UA_Int32 retval, pos = 0;
  1109. // when test 1
  1110. src = 1;
  1111. retval = UA_Int32_encodeBinary(&src, &pos, &dst);
  1112. // then test 1
  1113. ck_assert_int_eq(pos, 4);
  1114. ck_assert_int_eq(dst.data[0], 0x01);
  1115. ck_assert_int_eq(dst.data[1], 0x00);
  1116. ck_assert_int_eq(dst.data[2], 0x00);
  1117. ck_assert_int_eq(dst.data[3], 0x00);
  1118. ck_assert_int_eq(retval, UA_SUCCESS);
  1119. // when test 2
  1120. src = 0x7FFFFFFF;
  1121. retval = UA_Int32_encodeBinary(&src, &pos, &dst);
  1122. // then test 2
  1123. ck_assert_int_eq(pos, 8);
  1124. ck_assert_int_eq(dst.data[4], 0xFF);
  1125. ck_assert_int_eq(dst.data[5], 0xFF);
  1126. ck_assert_int_eq(dst.data[6], 0xFF);
  1127. ck_assert_int_eq(dst.data[7], 0x7F);
  1128. ck_assert_int_eq(retval, UA_SUCCESS);
  1129. }
  1130. END_TEST
  1131. START_TEST(UA_Int32_encodeNegativeShallEncodeLittleEndian)
  1132. {
  1133. // given
  1134. UA_Int32 src;
  1135. UA_Byte data[] = { 0x55,0x55,0x55,0x55,
  1136. 0x55,0x55,0x55,0x55
  1137. };
  1138. UA_ByteString dst = {8,data};
  1139. UA_Int32 retval, pos = 0;
  1140. // when test 1
  1141. src = -1;
  1142. retval = UA_Int32_encodeBinary(&src, &pos, &dst);
  1143. // then test 1
  1144. ck_assert_int_eq(pos, 4);
  1145. ck_assert_int_eq(dst.data[0], 0xFF);
  1146. ck_assert_int_eq(dst.data[1], 0xFF);
  1147. ck_assert_int_eq(dst.data[2], 0xFF);
  1148. ck_assert_int_eq(dst.data[3], 0xFF);
  1149. ck_assert_int_eq(retval, UA_SUCCESS);
  1150. }
  1151. END_TEST
  1152. START_TEST(UA_UInt64_encodeShallWorkOnExample)
  1153. {
  1154. // given
  1155. UA_UInt64 src;
  1156. UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
  1157. 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
  1158. };
  1159. UA_ByteString dst = {16,data};
  1160. UA_Int32 retval, pos = 0;
  1161. // when test 1
  1162. src = -1;
  1163. retval = UA_UInt64_encodeBinary(&src, &pos, &dst);
  1164. // then test 1
  1165. ck_assert_int_eq(pos, 8);
  1166. ck_assert_int_eq(dst.data[0], 0xFF);
  1167. ck_assert_int_eq(dst.data[1], 0xFF);
  1168. ck_assert_int_eq(dst.data[2], 0xFF);
  1169. ck_assert_int_eq(dst.data[3], 0xFF);
  1170. ck_assert_int_eq(dst.data[4], 0xFF);
  1171. ck_assert_int_eq(dst.data[5], 0xFF);
  1172. ck_assert_int_eq(dst.data[6], 0xFF);
  1173. ck_assert_int_eq(dst.data[7], 0xFF);
  1174. ck_assert_int_eq(retval, UA_SUCCESS);
  1175. // when test 2
  1176. src = 0x7F0033AA44EE6611;
  1177. retval = UA_UInt64_encodeBinary(&src, &pos, &dst);
  1178. // then test 2
  1179. ck_assert_int_eq(pos, 16);
  1180. ck_assert_int_eq(dst.data[8], 0x11);
  1181. ck_assert_int_eq(dst.data[9], 0x66);
  1182. ck_assert_int_eq(dst.data[10], 0xEE);
  1183. ck_assert_int_eq(dst.data[11], 0x44);
  1184. ck_assert_int_eq(dst.data[12], 0xAA);
  1185. ck_assert_int_eq(dst.data[13], 0x33);
  1186. ck_assert_int_eq(dst.data[14], 0x00);
  1187. ck_assert_int_eq(dst.data[15], 0x7F);
  1188. ck_assert_int_eq(retval, UA_SUCCESS);
  1189. }
  1190. END_TEST
  1191. START_TEST(UA_Int64_encodeShallEncodeLittleEndian)
  1192. {
  1193. // given
  1194. UA_Int64 src;
  1195. UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
  1196. 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
  1197. };
  1198. UA_ByteString dst = {16,data};
  1199. UA_Int32 retval, pos = 0;
  1200. // when test 1
  1201. src = 0x7F0033AA44EE6611;
  1202. retval = UA_Int64_encodeBinary(&src, &pos, &dst);
  1203. // then test 1
  1204. ck_assert_int_eq(pos, 8);
  1205. ck_assert_int_eq(dst.data[0], 0x11);
  1206. ck_assert_int_eq(dst.data[1], 0x66);
  1207. ck_assert_int_eq(dst.data[2], 0xEE);
  1208. ck_assert_int_eq(dst.data[3], 0x44);
  1209. ck_assert_int_eq(dst.data[4], 0xAA);
  1210. ck_assert_int_eq(dst.data[5], 0x33);
  1211. ck_assert_int_eq(dst.data[6], 0x00);
  1212. ck_assert_int_eq(dst.data[7], 0x7F);
  1213. ck_assert_int_eq(retval, UA_SUCCESS);
  1214. }
  1215. END_TEST
  1216. START_TEST(UA_Int64_encodeNegativeShallEncodeLittleEndian)
  1217. {
  1218. // given
  1219. UA_Int64 src;
  1220. UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
  1221. 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
  1222. };
  1223. UA_ByteString dst = {16,data};
  1224. UA_Int32 retval, pos = 0;
  1225. // when test 1
  1226. src = -1;
  1227. retval = UA_Int64_encodeBinary(&src, &pos, &dst);
  1228. // then test 1
  1229. ck_assert_int_eq(pos, 8);
  1230. ck_assert_int_eq(dst.data[0], 0xFF);
  1231. ck_assert_int_eq(dst.data[1], 0xFF);
  1232. ck_assert_int_eq(dst.data[2], 0xFF);
  1233. ck_assert_int_eq(dst.data[3], 0xFF);
  1234. ck_assert_int_eq(dst.data[4], 0xFF);
  1235. ck_assert_int_eq(dst.data[5], 0xFF);
  1236. ck_assert_int_eq(dst.data[6], 0xFF);
  1237. ck_assert_int_eq(dst.data[7], 0xFF);
  1238. ck_assert_int_eq(retval, UA_SUCCESS);
  1239. }
  1240. END_TEST
  1241. START_TEST(UA_Float_encodeShallWorkOnExample)
  1242. {
  1243. // given
  1244. UA_Float src;
  1245. UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
  1246. 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
  1247. };
  1248. UA_ByteString dst = {16,data};
  1249. UA_Int32 retval, pos = 0;
  1250. // when test 1
  1251. src = -6.5;
  1252. retval = UA_Float_encodeBinary(&src, &pos, &dst);
  1253. // then test 1
  1254. ck_assert_int_eq(pos, 4);
  1255. ck_assert_int_eq(dst.data[2], 0xD0);
  1256. ck_assert_int_eq(dst.data[3], 0xC0);
  1257. ck_assert_int_eq(retval, UA_SUCCESS);
  1258. }
  1259. END_TEST
  1260. /*START_TEST(UA_Double_encodeShallWorkOnExample)
  1261. {
  1262. // given
  1263. UA_Double src;
  1264. UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
  1265. 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
  1266. };
  1267. UA_ByteString dst = {16,data};
  1268. UA_Int32 retval, pos = 0;
  1269. // when test 1
  1270. src = -6.5;
  1271. retval = UA_Double_encodeBinary(&src, &pos, &dst);
  1272. // then test 1
  1273. ck_assert_int_eq(pos, 8);
  1274. ck_assert_int_eq(dst.data[6], 0xD0);
  1275. ck_assert_int_eq(dst.data[7], 0xC0);
  1276. ck_assert_int_eq(retval, UA_SUCCESS);
  1277. }
  1278. END_TEST*/
  1279. START_TEST(UA_String_encodeShallWorkOnExample)
  1280. {
  1281. // given
  1282. UA_String src;
  1283. src.length = 11;
  1284. UA_Byte mem[11] = "ACPLT OPCUA";
  1285. src.data = mem;
  1286. UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
  1287. 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
  1288. 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
  1289. };
  1290. UA_ByteString dst = {24,data};
  1291. UA_Int32 retval, pos = 0;
  1292. // when
  1293. retval = UA_String_encodeBinary(&src, &pos, &dst);
  1294. // then
  1295. ck_assert_int_eq(pos, sizeof(UA_Int32)+11);
  1296. ck_assert_int_eq(dst.data[0], 11);
  1297. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+0], 'A');
  1298. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+1], 'C');
  1299. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+2], 'P');
  1300. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+3], 'L');
  1301. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+4], 'T');
  1302. ck_assert_int_eq(dst.data[sizeof(UA_Int32)+5], 0x20); //Space
  1303. ck_assert_int_eq(retval, UA_SUCCESS);
  1304. }
  1305. END_TEST
  1306. START_TEST(UA_DataValue_encodeShallWorkOnExampleWithoutVariant)
  1307. {
  1308. // given
  1309. UA_DataValue src;
  1310. src.serverTimestamp = 80;
  1311. src.encodingMask = UA_DATAVALUE_ENCODINGMASK_SERVERTIMESTAMP; //Only the sourcePicoseconds
  1312. UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
  1313. 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
  1314. 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
  1315. };
  1316. UA_ByteString dst = {24,data};
  1317. UA_Int32 retval, pos = 0;
  1318. // when
  1319. retval = UA_DataValue_encodeBinary(&src, &pos, &dst);
  1320. // then
  1321. ck_assert_int_eq(pos, 9);// represents the length
  1322. ck_assert_int_eq(dst.data[0], 0x08); // encodingMask
  1323. ck_assert_int_eq(dst.data[1], 80); // 8 Byte serverTimestamp
  1324. ck_assert_int_eq(dst.data[2], 0);
  1325. ck_assert_int_eq(dst.data[3], 0);
  1326. ck_assert_int_eq(dst.data[4], 0);
  1327. ck_assert_int_eq(dst.data[5], 0);
  1328. ck_assert_int_eq(dst.data[6], 0);
  1329. ck_assert_int_eq(dst.data[7], 0);
  1330. ck_assert_int_eq(dst.data[8], 0);
  1331. ck_assert_int_eq(retval, UA_SUCCESS);
  1332. }
  1333. END_TEST
  1334. START_TEST(UA_DataValue_encodeShallWorkOnExampleWithVariant)
  1335. {
  1336. // given
  1337. UA_DataValue src;
  1338. src.serverTimestamp = 80;
  1339. src.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT | UA_DATAVALUE_ENCODINGMASK_SERVERTIMESTAMP; //Variant & SourvePicoseconds
  1340. src.value.vt = &UA_[UA_INT32];
  1341. src.value.arrayLength = 0;
  1342. src.value.encodingMask = UA_INT32_NS0;
  1343. UA_Int32 vdata = 45;
  1344. UA_Int32* pvdata = &vdata;
  1345. src.value.data = (void**) &pvdata;
  1346. UA_Byte data[] = { 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
  1347. 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
  1348. 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
  1349. };
  1350. UA_ByteString dst = {24,data};
  1351. UA_Int32 retval, pos = 0;
  1352. // when
  1353. retval = UA_DataValue_encodeBinary(&src, &pos, &dst);
  1354. // then
  1355. ck_assert_int_eq(pos, 1+(1+4)+8);// represents the length
  1356. ck_assert_int_eq(dst.data[0], 0x08 | 0x01); // encodingMask
  1357. ck_assert_int_eq(dst.data[1], 0x06); // Variant's Encoding Mask - INT32
  1358. ck_assert_int_eq(dst.data[2], 45); // the single value
  1359. ck_assert_int_eq(dst.data[3], 0);
  1360. ck_assert_int_eq(dst.data[4], 0);
  1361. ck_assert_int_eq(dst.data[5], 0);
  1362. ck_assert_int_eq(dst.data[6], 80); // the server timestamp
  1363. ck_assert_int_eq(dst.data[7], 0);
  1364. ck_assert_int_eq(retval, UA_SUCCESS);
  1365. }
  1366. END_TEST
  1367. Suite *testSuite_builtin(void)
  1368. {
  1369. Suite *s = suite_create("Built-in Data Types 62541-6 Table 1");
  1370. TCase *tc_calcSize = tcase_create("calcSize");
  1371. tcase_add_test(tc_calcSize, UA_Boolean_calcSizeWithNullArgumentShallReturnStorageSize);
  1372. tcase_add_test(tc_calcSize, UA_SByte_calcSizeWithNullArgumentShallReturnStorageSize);
  1373. tcase_add_test(tc_calcSize, UA_Byte_calcSizeWithNullArgumentShallReturnStorageSize);
  1374. tcase_add_test(tc_calcSize, UA_Int16_calcSizeWithNullArgumentShallReturnStorageSize);
  1375. tcase_add_test(tc_calcSize, UA_UInt16_calcSizeWithNullArgumentShallReturnStorageSize);
  1376. tcase_add_test(tc_calcSize, UA_Int32_calcSizeWithNullArgumentShallReturnStorageSize);
  1377. tcase_add_test(tc_calcSize, UA_UInt32_calcSizeWithNullArgumentShallReturnStorageSize);
  1378. tcase_add_test(tc_calcSize, UA_Int64_calcSizeWithNullArgumentShallReturnStorageSize);
  1379. tcase_add_test(tc_calcSize, UA_UInt64_calcSizeWithNullArgumentShallReturnStorageSize);
  1380. tcase_add_test(tc_calcSize, UA_Float_calcSizeWithNullArgumentShallReturnStorageSize);
  1381. tcase_add_test(tc_calcSize, UA_Double_calcSizeWithNullArgumentShallReturnStorageSize);
  1382. tcase_add_test(tc_calcSize, UA_String_calcSizeWithNullArgumentShallReturnStorageSize);
  1383. tcase_add_test(tc_calcSize, UA_DateTime_calcSizeWithNullArgumentShallReturnStorageSize);
  1384. tcase_add_test(tc_calcSize, UA_Guid_calcSizeWithNullArgumentShallReturnStorageSize);
  1385. tcase_add_test(tc_calcSize, UA_ByteString_calcSizeWithNullArgumentShallReturnStorageSize);
  1386. tcase_add_test(tc_calcSize, UA_XmlElement_calcSizeWithNullArgumentShallReturnStorageSize);
  1387. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeWithNullArgumentShallReturnStorageSize);
  1388. tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeWithNullArgumentShallReturnStorageSize);
  1389. tcase_add_test(tc_calcSize, UA_StatusCode_calcSizeWithNullArgumentShallReturnStorageSize);
  1390. tcase_add_test(tc_calcSize, UA_QualifiedName_calcSizeWithNullArgumentShallReturnStorageSize);
  1391. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeWithNullArgumentShallReturnStorageSize);
  1392. tcase_add_test(tc_calcSize, UA_ExtensionObject_calcSizeShallWorkOnExample);
  1393. tcase_add_test(tc_calcSize, UA_ExtensionObject_calcSizeWithNullArgumentShallReturnStorageSize);
  1394. tcase_add_test(tc_calcSize, UA_DataValue_calcSizeShallWorkOnExample);
  1395. tcase_add_test(tc_calcSize, UA_DataValue_calcSizeWithNullArgumentShallReturnStorageSize);
  1396. tcase_add_test(tc_calcSize, UA_Variant_calcSizeWithNullArgumentShallReturnStorageSize);
  1397. tcase_add_test(tc_calcSize, UA_DiagnosticInfo_calcSizeShallWorkOnExample);
  1398. tcase_add_test(tc_calcSize, UA_DiagnosticInfo_calcSizeWithNullArgumentShallReturnStorageSize);
  1399. tcase_add_test(tc_calcSize, UA_String_calcSizeShallReturnEncodingSize);
  1400. tcase_add_test(tc_calcSize, UA_String_calcSizeWithNegativLengthShallReturnEncodingSize);
  1401. tcase_add_test(tc_calcSize, UA_String_calcSizeWithNegativLengthAndValidPointerShallReturnEncodingSize);
  1402. tcase_add_test(tc_calcSize, UA_String_calcSizeWithZeroLengthShallReturnEncodingSize);
  1403. tcase_add_test(tc_calcSize, UA_String_calcSizeWithZeroLengthAndValidPointerShallReturnEncodingSize);
  1404. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingTwoByteShallReturnEncodingSize);
  1405. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingFourByteShallReturnEncodingSize);
  1406. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringShallReturnEncodingSize);
  1407. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringNegativLengthShallReturnEncodingSize);
  1408. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringZeroLengthShallReturnEncodingSize);
  1409. tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeEncodingStringAndServerIndexShallReturnEncodingSize);
  1410. tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeEncodingStringAndNamespaceUriShallReturnEncodingSize);
  1411. tcase_add_test(tc_calcSize, UA_Guid_calcSizeShallReturnEncodingSize);
  1412. tcase_add_test(tc_calcSize, UA_Guid_calcSizeShallReturnEncodingSize);
  1413. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeTextOnlyShallReturnEncodingSize);
  1414. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeLocaleOnlyShallReturnEncodingSize);
  1415. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeTextAndLocaleShallReturnEncodingSize);
  1416. tcase_add_test(tc_calcSize, UA_Variant_calcSizeFixedSizeArrayShallReturnEncodingSize);
  1417. tcase_add_test(tc_calcSize, UA_Variant_calcSizeVariableSizeArrayShallReturnEncodingSize);
  1418. tcase_add_test(tc_calcSize, UA_Variant_calcSizeVariableSizeArrayWithNullPtrWillReturnWrongButLargeEnoughEncodingSize);
  1419. tcase_add_test(tc_calcSize, UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem);
  1420. suite_add_tcase(s,tc_calcSize);
  1421. TCase *tc_decode = tcase_create("decode");
  1422. tcase_add_test(tc_decode, UA_Byte_decodeShallCopyAndAdvancePosition);
  1423. tcase_add_test(tc_decode, UA_Byte_decodeShallModifyOnlyCurrentPosition);
  1424. tcase_add_test(tc_decode, UA_Int16_decodeShallAssumeLittleEndian);
  1425. tcase_add_test(tc_decode, UA_Int16_decodeShallRespectSign);
  1426. tcase_add_test(tc_decode, UA_UInt16_decodeShallNotRespectSign);
  1427. tcase_add_test(tc_decode, UA_Int32_decodeShallAssumeLittleEndian);
  1428. tcase_add_test(tc_decode, UA_Int32_decodeShallRespectSign);
  1429. tcase_add_test(tc_decode, UA_UInt32_decodeShallNotRespectSign);
  1430. tcase_add_test(tc_decode, UA_UInt64_decodeShallNotRespectSign);
  1431. tcase_add_test(tc_decode, UA_Int64_decodeShallRespectSign);
  1432. tcase_add_test(tc_decode, UA_Float_decodeShallWorkOnExample);
  1433. tcase_add_test(tc_decode, UA_Double_decodeShallGiveOne);
  1434. tcase_add_test(tc_decode, UA_Double_decodeShallGiveZero);
  1435. tcase_add_test(tc_decode, UA_Double_decodeShallGiveMinusTwo);
  1436. tcase_add_test(tc_decode, UA_Byte_encode_test);
  1437. tcase_add_test(tc_decode, UA_String_decodeShallAllocateMemoryAndCopyString);
  1438. tcase_add_test(tc_decode, UA_String_decodeWithNegativeSizeShallNotAllocateMemoryAndNullPtr);
  1439. tcase_add_test(tc_decode, UA_String_decodeWithZeroSizeShallNotAllocateMemoryAndNullPtr);
  1440. tcase_add_test(tc_decode, UA_NodeId_decodeTwoByteShallReadTwoBytesAndSetNamespaceToZero);
  1441. tcase_add_test(tc_decode, UA_NodeId_decodeFourByteShallReadFourBytesAndRespectNamespace);
  1442. tcase_add_test(tc_decode, UA_NodeId_decodeStringShallAllocateMemory);
  1443. tcase_add_test(tc_decode, UA_Variant_decodeWithOutArrayFlagSetShallSetVTAndAllocateMemoryForArray);
  1444. tcase_add_test(tc_decode, UA_Variant_decodeWithArrayFlagSetShallSetVTAndAllocateMemoryForArray);
  1445. tcase_add_test(tc_decode, UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem);
  1446. tcase_add_test(tc_decode, UA_Variant_decodeWithTooSmallSourceShallReturnWithError);
  1447. suite_add_tcase(s,tc_decode);
  1448. TCase *tc_encode = tcase_create("encode");
  1449. tcase_add_test(tc_encode, UA_Byte_encode_test);
  1450. tcase_add_test(tc_encode, UA_UInt16_encodeNegativeShallEncodeLittleEndian);
  1451. tcase_add_test(tc_encode, UA_UInt16_encodeShallEncodeLittleEndian);
  1452. tcase_add_test(tc_encode, UA_UInt32_encodeShallEncodeLittleEndian);
  1453. tcase_add_test(tc_encode, UA_Int32_encodeShallEncodeLittleEndian);
  1454. tcase_add_test(tc_encode, UA_Int32_encodeNegativeShallEncodeLittleEndian);
  1455. tcase_add_test(tc_encode, UA_UInt64_encodeShallWorkOnExample);
  1456. tcase_add_test(tc_encode, UA_Int64_encodeNegativeShallEncodeLittleEndian);
  1457. tcase_add_test(tc_encode, UA_Int64_encodeShallEncodeLittleEndian);
  1458. tcase_add_test(tc_encode, UA_Float_encodeShallWorkOnExample);
  1459. //tcase_add_test(tc_encode, UA_Double_encodeShallWorkOnExample);
  1460. tcase_add_test(tc_encode, UA_String_encodeShallWorkOnExample);
  1461. tcase_add_test(tc_encode, UA_DataValue_encodeShallWorkOnExampleWithoutVariant);
  1462. tcase_add_test(tc_encode, UA_DataValue_encodeShallWorkOnExampleWithVariant);
  1463. suite_add_tcase(s,tc_encode);
  1464. return s;
  1465. }
  1466. int main (void)
  1467. {
  1468. int number_failed = 0;
  1469. Suite* s;
  1470. SRunner* sr;
  1471. s = testSuite_builtin();
  1472. sr = srunner_create(s);
  1473. srunner_run_all(sr,CK_NORMAL);
  1474. number_failed += srunner_ntests_failed(sr);
  1475. srunner_free(sr);
  1476. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  1477. }