check_builtin.c 61 KB

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