check_builtin.c 58 KB

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