check_builtin.c 61 KB

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