check_builtin.c 62 KB

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