check_builtin.c 42 KB

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