check_builtin.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. /*
  2. ============================================================================
  3. Name : check_stack.c
  4. Author :
  5. Copyright : Your copyright notice
  6. Description :
  7. ============================================================================
  8. */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include "opcua.h"
  12. #include "check.h"
  13. START_TEST(UA_Boolean_calcSizeWithNullArgumentShallReturnStorageSize)
  14. {
  15. // given
  16. UA_Boolean* arg = UA_NULL;
  17. // when
  18. UA_Boolean storageSize = UA_Boolean_calcSize(arg);
  19. // then
  20. ck_assert_int_eq(storageSize, 1);
  21. }
  22. END_TEST
  23. START_TEST(UA_SByte_calcSizeWithNullArgumentShallReturnStorageSize)
  24. {
  25. // given
  26. UA_SByte* arg = UA_NULL;
  27. // when
  28. UA_Int32 storageSize = UA_SByte_calcSize(arg);
  29. // then
  30. ck_assert_int_ge(storageSize, 1);
  31. }
  32. END_TEST
  33. START_TEST(UA_Byte_calcSizeWithNullArgumentShallReturnStorageSize)
  34. {
  35. // given
  36. UA_Byte* arg = UA_NULL;
  37. // when
  38. UA_Int32 storageSize = UA_Byte_calcSize(arg);
  39. // then
  40. ck_assert_int_ge(storageSize, 1);
  41. }
  42. END_TEST
  43. START_TEST(UA_Int16_calcSizeWithNullArgumentShallReturnStorageSize)
  44. {
  45. // given
  46. UA_Int16* arg = UA_NULL;
  47. // when
  48. UA_Int32 storageSize = UA_Int16_calcSize(arg);
  49. // then
  50. ck_assert_int_ge(storageSize, 2);
  51. }
  52. END_TEST
  53. START_TEST(UA_UInt16_calcSizeWithNullArgumentShallReturnStorageSize)
  54. {
  55. // given
  56. UA_UInt16* arg = UA_NULL;
  57. // when
  58. UA_Int32 storageSize = UA_UInt16_calcSize(arg);
  59. // then
  60. ck_assert_int_ge(storageSize, 2);
  61. }
  62. END_TEST
  63. START_TEST(UA_Int32_calcSizeWithNullArgumentShallReturnStorageSize)
  64. {
  65. // given
  66. UA_Int32* arg = UA_NULL;
  67. // when
  68. UA_Int32 storageSize = UA_Int32_calcSize(arg);
  69. // then
  70. ck_assert_int_ge(storageSize, 4);
  71. }
  72. END_TEST
  73. START_TEST(UA_UInt32_calcSizeWithNullArgumentShallReturnStorageSize)
  74. {
  75. // given
  76. UA_UInt32* arg = UA_NULL;
  77. // when
  78. UA_Int32 storageSize = UA_UInt32_calcSize(arg);
  79. // then
  80. ck_assert_int_ge(storageSize, 4);
  81. }
  82. END_TEST
  83. START_TEST(UA_Int64_calcSizeWithNullArgumentShallReturnStorageSize)
  84. {
  85. // given
  86. UA_Int64* arg = UA_NULL;
  87. // when
  88. UA_Int32 storageSize = UA_Int64_calcSize(arg);
  89. // then
  90. ck_assert_int_ge(storageSize, 8);
  91. }
  92. END_TEST
  93. START_TEST(UA_UInt64_calcSizeWithNullArgumentShallReturnStorageSize)
  94. {
  95. // given
  96. UA_UInt64* arg = UA_NULL;
  97. // when
  98. UA_Int32 storageSize = UA_UInt64_calcSize(arg);
  99. // then
  100. ck_assert_int_ge(storageSize, 8);
  101. }
  102. END_TEST
  103. START_TEST(UA_Float_calcSizeWithNullArgumentShallReturnStorageSize)
  104. {
  105. // given
  106. UA_Float* arg = UA_NULL;
  107. // when
  108. UA_Int32 storageSize = UA_Float_calcSize(arg);
  109. // then
  110. ck_assert_int_ge(storageSize, 4);
  111. }
  112. END_TEST
  113. START_TEST(UA_Double_calcSizeWithNullArgumentShallReturnStorageSize)
  114. {
  115. // given
  116. UA_Double* arg = UA_NULL;
  117. // when
  118. UA_Int32 storageSize = UA_Double_calcSize(arg);
  119. // then
  120. ck_assert_int_ge(storageSize, 8);
  121. }
  122. END_TEST
  123. START_TEST(UA_String_calcSizeWithNullArgumentShallReturnStorageSize)
  124. {
  125. // given
  126. UA_String* arg = UA_NULL;
  127. // when
  128. UA_Int32 storageSize = UA_String_calcSize(arg);
  129. // then
  130. ck_assert_int_eq(storageSize, sizeof(UA_String));
  131. ck_assert_int_ge(storageSize, UA_Int32_calcSize(UA_NULL) + sizeof(UA_NULL));
  132. }
  133. END_TEST
  134. START_TEST(UA_DateTime_calcSizeWithNullArgumentShallReturnStorageSize)
  135. {
  136. // given
  137. UA_DateTime* arg = UA_NULL;
  138. // when
  139. UA_Int32 storageSize = UA_DateTime_calcSize(arg);
  140. // then
  141. ck_assert_int_ge(storageSize, 8);
  142. }
  143. END_TEST
  144. START_TEST(UA_Guid_calcSizeWithNullArgumentShallReturnStorageSize)
  145. {
  146. // given
  147. UA_Guid* arg = UA_NULL;
  148. // when
  149. UA_Int32 storageSize = UA_Guid_calcSize(arg);
  150. // then
  151. ck_assert_int_ge(storageSize, 16);
  152. }
  153. END_TEST
  154. START_TEST(UA_ByteString_calcSizeWithNullArgumentShallReturnStorageSize)
  155. {
  156. // given
  157. UA_ByteString* arg = UA_NULL;
  158. // when
  159. UA_Int32 storageSize = UA_ByteString_calcSize(arg);
  160. // then
  161. ck_assert_int_eq(storageSize, sizeof(UA_ByteString));
  162. ck_assert_int_ge(storageSize, UA_Int32_calcSize(UA_NULL)+sizeof(UA_NULL));
  163. }
  164. END_TEST
  165. START_TEST(UA_XmlElement_calcSizeWithNullArgumentShallReturnStorageSize)
  166. {
  167. // given
  168. UA_XmlElement* arg = UA_NULL;
  169. // when
  170. UA_Int32 storageSize = UA_XmlElement_calcSize(arg);
  171. // then
  172. ck_assert_int_eq(storageSize, sizeof(UA_XmlElement));
  173. ck_assert_int_ge(storageSize, UA_Int32_calcSize(UA_NULL)+sizeof(UA_NULL));
  174. }
  175. END_TEST
  176. START_TEST(UA_NodeId_calcSizeWithNullArgumentShallReturnStorageSize)
  177. {
  178. // given
  179. UA_NodeId* arg = UA_NULL;
  180. // when
  181. UA_Int32 storageSize = UA_NodeId_calcSize(arg);
  182. // then
  183. ck_assert_int_eq(storageSize, sizeof(UA_NodeId));
  184. }
  185. END_TEST
  186. START_TEST(UA_ExpandedNodeId_calcSizeWithNullArgumentShallReturnStorageSize)
  187. {
  188. // given
  189. UA_ExpandedNodeId* arg = UA_NULL;
  190. // when
  191. UA_Int32 storageSize = UA_ExpandedNodeId_calcSize(arg);
  192. // then
  193. ck_assert_int_eq(storageSize, sizeof(UA_ExpandedNodeId));
  194. }
  195. END_TEST
  196. START_TEST(UA_StatusCode_calcSizeWithNullArgumentShallReturnStorageSize)
  197. {
  198. // given
  199. UA_StatusCode* arg = UA_NULL;
  200. // when
  201. UA_Int32 storageSize = UA_StatusCode_calcSize(arg);
  202. // then
  203. ck_assert_int_eq(storageSize, sizeof(UA_StatusCode));
  204. }
  205. END_TEST
  206. START_TEST(UA_QualifiedName_calcSizeWithNullArgumentShallReturnStorageSize)
  207. {
  208. // given
  209. UA_QualifiedName* arg = UA_NULL;
  210. // when
  211. UA_Int32 storageSize = UA_QualifiedName_calcSize(arg);
  212. // then
  213. ck_assert_int_eq(storageSize, sizeof(UA_QualifiedName));
  214. }
  215. END_TEST
  216. START_TEST(UA_LocalizedText_calcSizeWithNullArgumentShallReturnStorageSize)
  217. {
  218. // given
  219. UA_LocalizedText* arg = UA_NULL;
  220. // when
  221. UA_Int32 storageSize = UA_LocalizedText_calcSize(arg);
  222. // then
  223. ck_assert_int_eq(storageSize, sizeof(UA_LocalizedText));
  224. }
  225. END_TEST
  226. START_TEST(UA_ExtensionObject_calcSizeWithNullArgumentShallReturnStorageSize)
  227. {
  228. // given
  229. UA_ExtensionObject* arg = UA_NULL;
  230. // when
  231. UA_Int32 storageSize = UA_ExtensionObject_calcSize(arg);
  232. // then
  233. ck_assert_int_eq(storageSize, sizeof(UA_ExtensionObject));
  234. }
  235. END_TEST
  236. START_TEST(UA_DataValue_calcSizeWithNullArgumentShallReturnStorageSize)
  237. {
  238. // given
  239. UA_DataValue* arg = UA_NULL;
  240. // when
  241. UA_Int32 storageSize = UA_DataValue_calcSize(arg);
  242. // then
  243. ck_assert_int_eq(storageSize, sizeof(UA_DataValue));
  244. }
  245. END_TEST
  246. START_TEST(UA_Variant_calcSizeWithNullArgumentShallReturnStorageSize)
  247. {
  248. // given
  249. UA_Variant* arg = UA_NULL;
  250. // when
  251. UA_Int32 storageSize = UA_Variant_calcSize(arg);
  252. // then
  253. ck_assert_int_eq(storageSize, sizeof(UA_Variant));
  254. }
  255. END_TEST
  256. START_TEST(UA_DiagnosticInfo_calcSizeWithNullArgumentShallReturnStorageSize)
  257. {
  258. // given
  259. UA_DiagnosticInfo* arg = UA_NULL;
  260. // when
  261. UA_Int32 storageSize = UA_DiagnosticInfo_calcSize(arg);
  262. // then
  263. ck_assert_int_eq(storageSize, sizeof(UA_DiagnosticInfo));
  264. }
  265. END_TEST
  266. START_TEST(UA_String_calcSizeWithNegativLengthShallReturnEncodingSize)
  267. {
  268. // given
  269. UA_String arg = {-1, UA_NULL};
  270. // when
  271. UA_Int32 encodingSize = UA_String_calcSize(&arg);
  272. // then
  273. ck_assert_int_eq(encodingSize, 4);
  274. }
  275. END_TEST
  276. START_TEST(UA_String_calcSizeWithNegativLengthAndValidPointerShallReturnEncodingSize)
  277. {
  278. // given
  279. UA_String arg = {-1, (UA_Byte*) "OPC"};
  280. // when
  281. UA_Int32 encodingSize = UA_String_calcSize(&arg);
  282. // then
  283. ck_assert_int_eq(encodingSize, 4);
  284. }
  285. END_TEST
  286. START_TEST(UA_String_calcSizeWithZeroLengthShallReturnEncodingSize)
  287. {
  288. // given
  289. UA_String arg = {0, UA_NULL};
  290. // when
  291. UA_Int32 encodingSize = UA_String_calcSize(&arg);
  292. // then
  293. ck_assert_int_eq(encodingSize, 4);
  294. }
  295. END_TEST
  296. START_TEST(UA_String_calcSizeWithZeroLengthAndValidPointerShallReturnEncodingSize)
  297. {
  298. // given
  299. UA_String arg = {0, (UA_Byte*) "OPC"};
  300. // when
  301. UA_Int32 encodingSize = UA_String_calcSize(&arg);
  302. // then
  303. ck_assert_int_eq(encodingSize, 4);
  304. }
  305. END_TEST
  306. START_TEST(UA_String_calcSizeShallReturnEncodingSize)
  307. {
  308. // given
  309. UA_String arg = {3, (UA_Byte*) "OPC"};
  310. // when
  311. UA_Int32 encodingSize = UA_String_calcSize(&arg);
  312. // then
  313. ck_assert_int_eq(encodingSize, 4+3);
  314. }
  315. END_TEST
  316. START_TEST(UA_NodeId_calcSizeEncodingTwoByteShallReturnEncodingSize)
  317. {
  318. // given
  319. UA_NodeId arg;
  320. arg.encodingByte = UA_NODEIDTYPE_TWOBYTE;
  321. // when
  322. UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
  323. // then
  324. ck_assert_int_eq(encodingSize, 2);
  325. }
  326. END_TEST
  327. START_TEST(UA_NodeId_calcSizeEncodingFourByteShallReturnEncodingSize)
  328. {
  329. // given
  330. UA_NodeId arg;
  331. arg.encodingByte = UA_NODEIDTYPE_FOURBYTE;
  332. // when
  333. UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
  334. // then
  335. ck_assert_int_eq(encodingSize, 4);
  336. }
  337. END_TEST
  338. START_TEST(UA_NodeId_calcSizeEncodingStringShallReturnEncodingSize)
  339. {
  340. // given
  341. UA_NodeId arg;
  342. arg.encodingByte = UA_NODEIDTYPE_STRING;
  343. arg.identifier.string.length = 3;
  344. arg.identifier.string.data = (UA_Byte*) "PLT";
  345. // when
  346. UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
  347. // then
  348. ck_assert_int_eq(encodingSize, 1+2+4+3);
  349. }
  350. END_TEST
  351. START_TEST(UA_NodeId_calcSizeEncodingStringNegativLengthShallReturnEncodingSize)
  352. {
  353. // given
  354. UA_NodeId arg;
  355. arg.encodingByte = UA_NODEIDTYPE_STRING;
  356. arg.identifier.string.length = -1;
  357. // when
  358. UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
  359. // then
  360. ck_assert_int_eq(encodingSize, 1+2+4+0);
  361. }
  362. END_TEST
  363. START_TEST(UA_NodeId_calcSizeEncodingStringZeroLengthShallReturnEncodingSize)
  364. {
  365. // given
  366. UA_NodeId arg;
  367. arg.encodingByte = UA_NODEIDTYPE_STRING;
  368. arg.identifier.string.length = 0;
  369. // when
  370. UA_Int32 encodingSize = UA_NodeId_calcSize(&arg);
  371. // then
  372. ck_assert_int_eq(encodingSize, 1+2+4+0);
  373. }
  374. END_TEST
  375. START_TEST(UA_ExpandedNodeId_calcSizeEncodingStringAndServerIndexShallReturnEncodingSize)
  376. {
  377. // given
  378. UA_ExpandedNodeId arg;
  379. arg.nodeId.encodingByte = UA_NODEIDTYPE_STRING | UA_NODEIDTYPE_SERVERINDEX_FLAG;
  380. arg.nodeId.identifier.string.length = 3;
  381. // when
  382. UA_Int32 encodingSize = UA_ExpandedNodeId_calcSize(&arg);
  383. // then
  384. ck_assert_int_eq(encodingSize, 1+2+4+3+4);
  385. }
  386. END_TEST
  387. START_TEST(UA_ExpandedNodeId_calcSizeEncodingStringAndNamespaceUriShallReturnEncodingSize)
  388. {
  389. // given
  390. UA_ExpandedNodeId arg;
  391. arg.nodeId.encodingByte = UA_NODEIDTYPE_STRING | UA_NODEIDTYPE_NAMESPACE_URI_FLAG;
  392. arg.nodeId.identifier.string.length = 3;
  393. arg.namespaceUri.length = 7;
  394. // when
  395. UA_Int32 encodingSize = UA_ExpandedNodeId_calcSize(&arg);
  396. // then
  397. ck_assert_int_eq(encodingSize, 1+2+4+3+4+7);
  398. }
  399. END_TEST
  400. START_TEST(UA_Guid_calcSizeShallReturnEncodingSize)
  401. {
  402. // given
  403. UA_Guid arg;
  404. // when
  405. UA_Int32 encodingSize = UA_Guid_calcSize(&arg);
  406. // then
  407. ck_assert_int_eq(encodingSize, 16);
  408. }
  409. END_TEST
  410. START_TEST(UA_LocalizedText_calcSizeTextOnlyShallReturnEncodingSize)
  411. {
  412. // given
  413. UA_LocalizedText arg;
  414. arg.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT;
  415. arg.text.length = 42;
  416. // when
  417. UA_Int32 encodingSize = UA_LocalizedText_calcSize(&arg);
  418. // then
  419. ck_assert_int_eq(encodingSize, 1+4+42);
  420. }
  421. END_TEST
  422. START_TEST(UA_LocalizedText_calcSizeLocaleOnlyShallReturnEncodingSize)
  423. {
  424. // given
  425. UA_LocalizedText arg;
  426. arg.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_LOCALE;
  427. arg.locale.length = 11;
  428. // when
  429. UA_Int32 encodingSize = UA_LocalizedText_calcSize(&arg);
  430. // then
  431. ck_assert_int_eq(encodingSize, 1+4+11);
  432. }
  433. END_TEST
  434. START_TEST(UA_LocalizedText_calcSizeTextAndLocaleShallReturnEncodingSize)
  435. {
  436. // given
  437. UA_LocalizedText arg;
  438. arg.encodingMask = UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_LOCALE | UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT;
  439. arg.text.length = 47;
  440. arg.locale.length = 11;
  441. // when
  442. UA_Int32 encodingSize = UA_LocalizedText_calcSize(&arg);
  443. // then
  444. ck_assert_int_eq(encodingSize, 1+4+11+4+47);
  445. }
  446. END_TEST
  447. START_TEST(UA_Variant_calcSizeFixedSizeArrayShallReturnEncodingSize)
  448. {
  449. // given
  450. UA_Variant arg;
  451. arg.encodingMask = UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY;
  452. arg.vt = &UA_[UA_INT32];
  453. #define ARRAY_LEN 8
  454. arg.arrayLength = ARRAY_LEN;
  455. UA_Int32* data[ARRAY_LEN];
  456. arg.data = (void**) &data;
  457. // when
  458. UA_Int32 encodingSize = UA_Variant_calcSize(&arg);
  459. // then
  460. ck_assert_int_eq(encodingSize, 1+4+ARRAY_LEN*4);
  461. #undef ARRAY_LEN
  462. }
  463. END_TEST
  464. START_TEST(UA_Variant_calcSizeVariableSizeArrayShallReturnEncodingSize)
  465. {
  466. // given
  467. UA_Variant arg;
  468. arg.encodingMask = UA_STRING_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY;
  469. arg.vt = &UA_[UA_STRING];
  470. #define ARRAY_LEN 3
  471. arg.arrayLength = ARRAY_LEN;
  472. UA_String s1 = {-1, UA_NULL };
  473. UA_String s2 = {3, (UA_Byte*) "PLT" };
  474. UA_String s3 = {47, UA_NULL };
  475. UA_String* data[ARRAY_LEN] = { &s1, &s2, &s3 };
  476. arg.data = (void**) &data;
  477. // when
  478. UA_Int32 encodingSize = UA_Variant_calcSize(&arg);
  479. // then
  480. ck_assert_int_eq(encodingSize, 1+4+(4+0)+(4+3)+(4+47));
  481. #undef ARRAY_LEN
  482. }
  483. END_TEST
  484. START_TEST(UA_Variant_calcSizeVariableSizeArrayWithNullPtrWillReturnWrongButLargeEnoughEncodingSize)
  485. {
  486. // given
  487. UA_Variant arg;
  488. arg.encodingMask = UA_STRING_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY;
  489. arg.vt = &UA_[UA_STRING];
  490. #define ARRAY_LEN 6
  491. arg.arrayLength = ARRAY_LEN;
  492. UA_String s1 = {-1, UA_NULL };
  493. UA_String s2 = {3, (UA_Byte*) "PLT" };
  494. UA_String s3 = {47, UA_NULL };
  495. UA_String* data[ARRAY_LEN] = { &s1, &s2, &s3 }; // will be filled with null-ptrs
  496. arg.data = (void**) &data;
  497. // when
  498. UA_Int32 encodingSize = UA_Variant_calcSize(&arg);
  499. // then
  500. ck_assert_int_ge(encodingSize, 1+4+(4+0)+(4+3)+(4+47)+(ARRAY_LEN-3)*(4+0));
  501. #undef ARRAY_LEN
  502. }
  503. END_TEST
  504. START_TEST(UA_Byte_decodeShallCopyAndAdvancePosition)
  505. {
  506. // given
  507. UA_Byte dst;
  508. UA_Byte data[]= { 0x08 };
  509. UA_ByteString src = {1, data};
  510. UA_Int32 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. {
  521. // given
  522. UA_Byte dst[] = { 0xFF, 0xFF, 0xFF };
  523. UA_Byte data[] = { 0x08 };
  524. UA_ByteString src = {1, data};
  525. UA_Int32 pos = 0;
  526. // when
  527. UA_Int32 retval = UA_Byte_decodeBinary(&src, &pos, &dst[1]);
  528. // then
  529. ck_assert_int_eq(retval, UA_SUCCESS);
  530. ck_assert_int_eq(pos, 1);
  531. ck_assert_uint_eq(dst[0], 0xFF);
  532. ck_assert_uint_eq(dst[1], 0x08);
  533. ck_assert_uint_eq(dst[2], 0xFF);
  534. }
  535. END_TEST
  536. START_TEST(UA_Int16_decodeShallAssumeLittleEndian)
  537. {
  538. // given
  539. UA_Int32 pos = 0;
  540. UA_Byte data[] = {
  541. 0x01,0x00, // 1
  542. 0x00,0x01 // 256
  543. };
  544. UA_ByteString src = { 4, data };
  545. // when
  546. UA_Int16 val_01_00, val_00_01;
  547. UA_Int32 retval = UA_Int16_decodeBinary(&src,&pos,&val_01_00);
  548. retval |= UA_Int16_decodeBinary(&src,&pos,&val_00_01);
  549. // then
  550. ck_assert_int_eq(retval,UA_SUCCESS);
  551. ck_assert_int_eq(val_01_00,1);
  552. ck_assert_int_eq(val_00_01,256);
  553. ck_assert_int_eq(pos,4);
  554. }
  555. END_TEST
  556. START_TEST(UA_Int16_decodeShallRespectSign)
  557. {
  558. // given
  559. UA_Int32 pos = 0;
  560. UA_Byte data[] = {
  561. 0xFF,0xFF, // -1
  562. 0x00,0x80 // -32768
  563. };
  564. UA_ByteString src = {4,data};
  565. // when
  566. UA_Int16 val_ff_ff, val_00_80;
  567. UA_Int32 retval = UA_Int16_decodeBinary(&src,&pos,&val_ff_ff);
  568. retval |= UA_Int16_decodeBinary(&src,&pos,&val_00_80);
  569. // then
  570. ck_assert_int_eq(retval,UA_SUCCESS);
  571. ck_assert_int_eq(val_ff_ff,-1);
  572. ck_assert_int_eq(val_00_80,-32768);
  573. }
  574. END_TEST
  575. START_TEST(UA_UInt16_decodeShallNotRespectSign)
  576. {
  577. // given
  578. UA_Int32 pos = 0;
  579. UA_Byte data[] = {
  580. 0xFF,0xFF, // (2^16)-1
  581. 0x00,0x80 // (2^15)
  582. };
  583. UA_ByteString src = {4,data};
  584. // when
  585. UA_UInt16 val_ff_ff, val_00_80;
  586. UA_Int32 retval = UA_UInt16_decodeBinary(&src,&pos,&val_ff_ff);
  587. retval |= UA_UInt16_decodeBinary(&src,&pos,&val_00_80);
  588. // then
  589. ck_assert_int_eq(retval,UA_SUCCESS);
  590. ck_assert_int_eq(pos,4);
  591. ck_assert_uint_eq(val_ff_ff, (0x01 << 16)-1);
  592. ck_assert_uint_eq(val_00_80, (0x01 << 15));
  593. }
  594. END_TEST
  595. START_TEST(UA_Int32_decodeShallAssumeLittleEndian)
  596. {
  597. // given
  598. UA_Int32 pos = 0;
  599. UA_Byte data[] = {
  600. 0x01,0x00,0x00,0x00, // 1
  601. 0x00,0x01,0x00,0x00 // 256
  602. };
  603. UA_ByteString src = {8,data};
  604. // when
  605. UA_Int32 val_01_00, val_00_01;
  606. UA_Int32 retval = UA_Int32_decodeBinary(&src,&pos,&val_01_00);
  607. retval |= UA_Int32_decodeBinary(&src,&pos,&val_00_01);
  608. // then
  609. ck_assert_int_eq(retval,UA_SUCCESS);
  610. ck_assert_int_eq(val_01_00,1);
  611. ck_assert_int_eq(val_00_01,256);
  612. ck_assert_int_eq(pos,8);
  613. }
  614. END_TEST
  615. START_TEST(UA_Int32_decodeShallRespectSign)
  616. {
  617. // given
  618. UA_Int32 pos = 0;
  619. UA_Byte data[] = {
  620. 0xFF,0xFF,0xFF,0xFF, // -1
  621. 0x00,0x80,0xFF,0xFF // -32768
  622. };
  623. UA_ByteString src = {8,data};
  624. // when
  625. UA_Int32 val_ff_ff, val_00_80;
  626. UA_Int32 retval = UA_Int32_decodeBinary(&src,&pos,&val_ff_ff);
  627. retval |= UA_Int32_decodeBinary(&src,&pos,&val_00_80);
  628. // then
  629. ck_assert_int_eq(retval,UA_SUCCESS);
  630. ck_assert_int_eq(val_ff_ff,-1);
  631. ck_assert_int_eq(val_00_80,-32768);
  632. }
  633. END_TEST
  634. START_TEST(UA_UInt32_decodeShallNotRespectSign)
  635. {
  636. // given
  637. UA_Int32 pos = 0;
  638. UA_Byte data[] = {
  639. 0xFF,0xFF,0xFF,0xFF, // (2^32)-1
  640. 0x00,0x00,0x00,0x80 // (2^31)
  641. };
  642. UA_ByteString src = {8,data};
  643. // when
  644. UA_UInt32 val_ff_ff, val_00_80;
  645. UA_Int32 retval = UA_UInt32_decodeBinary(&src,&pos,&val_ff_ff);
  646. retval |= UA_UInt32_decodeBinary(&src,&pos,&val_00_80);
  647. // then
  648. ck_assert_int_eq(retval,UA_SUCCESS);
  649. ck_assert_int_eq(pos,8);
  650. ck_assert_uint_eq(val_ff_ff, (UA_UInt32) ( (0x01LL << 32 ) - 1 ));
  651. ck_assert_uint_eq(val_00_80, (UA_UInt32) (0x01 << 31));
  652. }
  653. END_TEST
  654. START_TEST(UA_Float_decodeShallWorkOnExample)
  655. {
  656. // given
  657. UA_Int32 pos = 0;
  658. UA_Byte data[] = { 0x00,0x00,0xD0,0xC0 }; // -6.5
  659. UA_ByteString src = {4,data};
  660. UA_Float dst;
  661. // when
  662. UA_Int32 retval = UA_Float_decodeBinary(&src,&pos,&dst);
  663. // then
  664. ck_assert_int_eq(retval,UA_SUCCESS);
  665. ck_assert_int_eq(pos,4);
  666. ck_assert(-6.5000001 < dst);
  667. ck_assert(dst < -6.49999999999);
  668. }
  669. END_TEST
  670. START_TEST(UA_Double_decodeShallGiveOne)
  671. {
  672. // given
  673. UA_Int32 pos = 0;
  674. UA_Byte data[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x3F }; // 1
  675. UA_ByteString src = {8,data}; // 1
  676. UA_Double dst;
  677. // when
  678. UA_Int32 retval = UA_Double_decodeBinary(&src,&pos,&dst);
  679. // then
  680. ck_assert_int_eq(retval,UA_SUCCESS);
  681. ck_assert_int_eq(pos,8);
  682. printf("UA_Double_decodeShallGiveOne %f\n",dst);
  683. ck_assert(0.9999999 < dst);
  684. ck_assert(dst < 1.00000000001);
  685. }
  686. END_TEST
  687. START_TEST(UA_Double_decodeShallGiveZero)
  688. {
  689. // given
  690. UA_Int32 pos = 0;
  691. UA_Byte data[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  692. UA_ByteString src = {8,data}; // 1
  693. UA_Double dst;
  694. // when
  695. UA_Int32 retval = UA_Double_decodeBinary(&src,&pos,&dst);
  696. // then
  697. ck_assert_int_eq(retval,UA_SUCCESS);
  698. ck_assert_int_eq(pos,8);
  699. printf("UA_Double_decodeShallGiveZero %f\n",dst);
  700. ck_assert(-0.00000001 < dst);
  701. ck_assert(dst < 0.000000001);
  702. }
  703. END_TEST
  704. START_TEST(UA_Double_decodeShallGiveMinusTwo)
  705. {
  706. // given
  707. UA_Int32 pos = 0;
  708. UA_Byte data[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0 }; // -2
  709. UA_ByteString src = {8,data};
  710. UA_Double dst;
  711. // when
  712. UA_Int32 retval = UA_Double_decodeBinary(&src,&pos,&dst);
  713. // then
  714. ck_assert_int_eq(retval,UA_SUCCESS);
  715. ck_assert_int_eq(pos,8);
  716. ck_assert(-1.9999999 > dst);
  717. ck_assert(dst > -2.00000000001);
  718. }
  719. END_TEST
  720. START_TEST(UA_String_decodeShallAllocateMemoryAndCopyString)
  721. {
  722. // given
  723. UA_Int32 pos = 0;
  724. UA_Byte data[] = {0x08,0x00,0x00,0x00,'A','C','P','L','T',' ','U','A',0xFF,0xFF,0xFF,0xFF,0xFF};
  725. UA_ByteString src = {16,data};
  726. UA_String dst;
  727. // when
  728. UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
  729. // then
  730. ck_assert_int_eq(retval,UA_SUCCESS);
  731. ck_assert_int_eq(dst.length,8);
  732. ck_assert_ptr_eq(dst.data,UA_alloc_lastptr);
  733. ck_assert_int_eq(dst.data[3],'L');
  734. // finally
  735. UA_String_deleteMembers(&dst);
  736. }
  737. END_TEST
  738. START_TEST(UA_String_decodeWithNegativeSizeShallNotAllocateMemoryAndNullPtr)
  739. {
  740. // given
  741. UA_Int32 pos = 0;
  742. UA_Byte data[] = {0xFF,0xFF,0xFF,0xFF,'A','C','P','L','T',' ','U','A',0xFF,0xFF,0xFF,0xFF,0xFF};
  743. UA_ByteString src = {16,data};
  744. UA_String dst;
  745. // when
  746. UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
  747. // then
  748. ck_assert_int_eq(retval,UA_SUCCESS);
  749. ck_assert_int_eq(dst.length,-1);
  750. ck_assert_ptr_eq(dst.data,UA_NULL);
  751. }
  752. END_TEST
  753. START_TEST(UA_String_decodeWithZeroSizeShallNotAllocateMemoryAndNullPtr)
  754. {
  755. // given
  756. UA_Int32 pos = 0;
  757. UA_Byte data[] = {0x00,0x00,0x00,0x00,'A','C','P','L','T',' ','U','A',0xFF,0xFF,0xFF,0xFF,0xFF};
  758. UA_ByteString src = {16,data};
  759. UA_String dst = { 2, (UA_Byte*) "XX" };
  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,0);
  765. ck_assert_ptr_eq(dst.data,UA_NULL);
  766. }
  767. END_TEST
  768. START_TEST(UA_NodeId_decodeTwoByteShallReadTwoBytesAndSetNamespaceToZero)
  769. {
  770. // given
  771. UA_Int32 pos = 0;
  772. UA_Byte data[] = { UA_NODEIDTYPE_TWOBYTE, 0x10 };
  773. UA_ByteString src = {2,data};
  774. UA_NodeId dst;
  775. // when
  776. UA_Int32 retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
  777. // then
  778. ck_assert_int_eq(retval,UA_SUCCESS);
  779. ck_assert_int_eq(pos,2);
  780. ck_assert_int_eq(dst.encodingByte, UA_NODEIDTYPE_TWOBYTE);
  781. ck_assert_int_eq(dst.identifier.numeric,16);
  782. ck_assert_int_eq(dst.namespace,0);
  783. }
  784. END_TEST
  785. START_TEST(UA_NodeId_decodeFourByteShallReadFourBytesAndRespectNamespace)
  786. {
  787. // given
  788. UA_Int32 pos = 0;
  789. UA_Byte data[] = { UA_NODEIDTYPE_FOURBYTE, 0x01, 0x00, 0x01 };
  790. UA_ByteString src = {4,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,4);
  797. ck_assert_int_eq(dst.encodingByte, UA_NODEIDTYPE_FOURBYTE);
  798. ck_assert_int_eq(dst.identifier.numeric,256);
  799. ck_assert_int_eq(dst.namespace,1);
  800. }
  801. END_TEST
  802. START_TEST(UA_NodeId_decodeStringShallAllocateMemory)
  803. {
  804. // given
  805. UA_Int32 pos = 0;
  806. UA_Byte data[]= { UA_NODEIDTYPE_STRING, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 'P', 'L', 'T' };
  807. UA_ByteString src = {10,data};
  808. UA_NodeId dst;
  809. // when
  810. UA_Int32 retval = UA_NodeId_decodeBinary(&src, &pos, &dst);
  811. // then
  812. ck_assert_int_eq(retval,UA_SUCCESS);
  813. ck_assert_int_eq(pos,10);
  814. ck_assert_int_eq(dst.encodingByte, UA_NODEIDTYPE_STRING);
  815. ck_assert_int_eq(dst.namespace,1);
  816. ck_assert_int_eq(dst.identifier.string.length,3);
  817. ck_assert_ptr_eq(dst.identifier.string.data,UA_alloc_lastptr);
  818. ck_assert_int_eq(dst.identifier.string.data[1],'L');
  819. // finally
  820. UA_NodeId_deleteMembers(&dst);
  821. }
  822. END_TEST
  823. START_TEST(UA_Variant_decodeWithOutArrayFlagSetShallSetVTAndAllocateMemoryForArray)
  824. {
  825. // given
  826. UA_Int32 pos = 0;
  827. UA_Byte data[] = { UA_INT32_NS0, 0xFF, 0x00, 0x00, 0x00};
  828. UA_ByteString src = {5,data};
  829. UA_Variant dst;
  830. // when
  831. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  832. // then
  833. ck_assert_int_eq(retval,UA_SUCCESS);
  834. ck_assert_int_eq(pos,5);
  835. ck_assert_uint_eq(dst.encodingMask, UA_INT32_NS0);
  836. ck_assert_ptr_eq(dst.vt, &UA_[UA_INT32]);
  837. ck_assert_int_eq(dst.arrayLength,1);
  838. ck_assert_ptr_ne(dst.data,UA_NULL);
  839. ck_assert_ptr_eq(dst.data[0],UA_alloc_lastptr);
  840. ck_assert_int_eq(*(UA_Int32*)dst.data[0],255);
  841. // finally
  842. UA_Variant_deleteMembers(&dst);
  843. }
  844. END_TEST
  845. START_TEST(UA_Variant_decodeWithArrayFlagSetShallSetVTAndAllocateMemoryForArray)
  846. {
  847. // given
  848. UA_Int32 pos = 0;
  849. UA_Byte data[]={ UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
  850. UA_ByteString src = {13,data};
  851. UA_Variant dst;
  852. // when
  853. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  854. // then
  855. ck_assert_int_eq(retval,UA_SUCCESS);
  856. ck_assert_int_eq(pos,1+4+2*4);
  857. ck_assert_uint_eq(dst.encodingMask & UA_VARIANT_ENCODINGMASKTYPE_TYPEID_MASK, UA_INT32_NS0);
  858. ck_assert_uint_eq(dst.encodingMask & UA_VARIANT_ENCODINGMASKTYPE_ARRAY, UA_VARIANT_ENCODINGMASKTYPE_ARRAY);
  859. ck_assert_ptr_eq(dst.vt, &UA_[UA_INT32]);
  860. ck_assert_int_eq(dst.arrayLength,2);
  861. ck_assert_ptr_ne(dst.data,UA_NULL);
  862. ck_assert_ptr_eq(dst.data[1],UA_alloc_lastptr);
  863. ck_assert_int_eq(*((UA_Int32*)dst.data[0]),255);
  864. ck_assert_int_eq(*((UA_Int32*)dst.data[1]),-1);
  865. // finally
  866. UA_Variant_deleteMembers(&dst);
  867. }
  868. END_TEST
  869. START_TEST(UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem)
  870. {
  871. // given
  872. UA_Int32 pos = 0;
  873. UA_Byte data[]= { UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
  874. UA_ByteString src = {13,data};
  875. UA_Variant dst;
  876. // when
  877. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  878. // then
  879. ck_assert_int_eq(retval,UA_SUCCESS);
  880. // finally - unfortunately we cannot express that not freeing three chunks is what we expect
  881. // UA_Variant_deleteMembers(&dst);
  882. }
  883. END_TEST
  884. START_TEST(UA_Variant_decodeWithTooSmallSourceShallReturnWithError)
  885. {
  886. // given
  887. UA_Int32 pos = 0;
  888. UA_Byte data[]= { UA_INT32_NS0 | UA_VARIANT_ENCODINGMASKTYPE_ARRAY, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
  889. UA_ByteString src = {4,data};
  890. UA_Variant dst;
  891. // when
  892. UA_Int32 retval = UA_Variant_decodeBinary(&src, &pos, &dst);
  893. // then
  894. ck_assert_int_ne(retval,UA_SUCCESS);
  895. // finally - unfortunately we cannot express that not freeing three chunks is what we expect
  896. // UA_Variant_deleteMembers(&dst);
  897. }
  898. END_TEST
  899. START_TEST(UA_Byte_encode_test)
  900. {
  901. UA_Byte src;
  902. UA_Byte data[] = { 0x00, 0xFF };
  903. UA_ByteString dst = {2,data};
  904. UA_Int32 retval, pos = 0;
  905. ck_assert_uint_eq(dst.data[1], 0xFF);
  906. src = 8;
  907. retval = UA_Byte_encodeBinary(&src, &pos, &dst);
  908. ck_assert_uint_eq(dst.data[0], 0x08);
  909. ck_assert_uint_eq(dst.data[1], 0xFF);
  910. ck_assert_int_eq(pos, 1);
  911. ck_assert_int_eq(retval, UA_SUCCESS);
  912. src = 0xFF;
  913. dst.data[1] = 0x00;
  914. pos = 0;
  915. retval = UA_Byte_encodeBinary(&src, &pos, &dst);
  916. ck_assert_int_eq(dst.data[0], 0xFF);
  917. ck_assert_int_eq(dst.data[1], 0x00);
  918. ck_assert_int_eq(pos, 1);
  919. ck_assert_int_eq(retval, UA_SUCCESS);
  920. }
  921. END_TEST
  922. Suite *testSuite_builtin(void)
  923. {
  924. Suite *s = suite_create("Built-in Data Types 62541-6 Table 1");
  925. TCase *tc_calcSize = tcase_create("calcSize");
  926. tcase_add_test(tc_calcSize, UA_Boolean_calcSizeWithNullArgumentShallReturnStorageSize);
  927. tcase_add_test(tc_calcSize, UA_SByte_calcSizeWithNullArgumentShallReturnStorageSize);
  928. tcase_add_test(tc_calcSize, UA_Byte_calcSizeWithNullArgumentShallReturnStorageSize);
  929. tcase_add_test(tc_calcSize, UA_Int16_calcSizeWithNullArgumentShallReturnStorageSize);
  930. tcase_add_test(tc_calcSize, UA_UInt16_calcSizeWithNullArgumentShallReturnStorageSize);
  931. tcase_add_test(tc_calcSize, UA_Int32_calcSizeWithNullArgumentShallReturnStorageSize);
  932. tcase_add_test(tc_calcSize, UA_UInt32_calcSizeWithNullArgumentShallReturnStorageSize);
  933. tcase_add_test(tc_calcSize, UA_Int64_calcSizeWithNullArgumentShallReturnStorageSize);
  934. tcase_add_test(tc_calcSize, UA_UInt64_calcSizeWithNullArgumentShallReturnStorageSize);
  935. tcase_add_test(tc_calcSize, UA_Float_calcSizeWithNullArgumentShallReturnStorageSize);
  936. tcase_add_test(tc_calcSize, UA_Double_calcSizeWithNullArgumentShallReturnStorageSize);
  937. tcase_add_test(tc_calcSize, UA_String_calcSizeWithNullArgumentShallReturnStorageSize);
  938. tcase_add_test(tc_calcSize, UA_DateTime_calcSizeWithNullArgumentShallReturnStorageSize);
  939. tcase_add_test(tc_calcSize, UA_Guid_calcSizeWithNullArgumentShallReturnStorageSize);
  940. tcase_add_test(tc_calcSize, UA_ByteString_calcSizeWithNullArgumentShallReturnStorageSize);
  941. tcase_add_test(tc_calcSize, UA_XmlElement_calcSizeWithNullArgumentShallReturnStorageSize);
  942. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeWithNullArgumentShallReturnStorageSize);
  943. tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeWithNullArgumentShallReturnStorageSize);
  944. tcase_add_test(tc_calcSize, UA_StatusCode_calcSizeWithNullArgumentShallReturnStorageSize);
  945. tcase_add_test(tc_calcSize, UA_QualifiedName_calcSizeWithNullArgumentShallReturnStorageSize);
  946. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeWithNullArgumentShallReturnStorageSize);
  947. tcase_add_test(tc_calcSize, UA_ExtensionObject_calcSizeWithNullArgumentShallReturnStorageSize);
  948. tcase_add_test(tc_calcSize, UA_DataValue_calcSizeWithNullArgumentShallReturnStorageSize);
  949. tcase_add_test(tc_calcSize, UA_Variant_calcSizeWithNullArgumentShallReturnStorageSize);
  950. tcase_add_test(tc_calcSize, UA_DiagnosticInfo_calcSizeWithNullArgumentShallReturnStorageSize);
  951. tcase_add_test(tc_calcSize, UA_String_calcSizeShallReturnEncodingSize);
  952. tcase_add_test(tc_calcSize, UA_String_calcSizeWithNegativLengthShallReturnEncodingSize);
  953. tcase_add_test(tc_calcSize, UA_String_calcSizeWithNegativLengthAndValidPointerShallReturnEncodingSize);
  954. tcase_add_test(tc_calcSize, UA_String_calcSizeWithZeroLengthShallReturnEncodingSize);
  955. tcase_add_test(tc_calcSize, UA_String_calcSizeWithZeroLengthAndValidPointerShallReturnEncodingSize);
  956. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingTwoByteShallReturnEncodingSize);
  957. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingFourByteShallReturnEncodingSize);
  958. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringShallReturnEncodingSize);
  959. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringNegativLengthShallReturnEncodingSize);
  960. tcase_add_test(tc_calcSize, UA_NodeId_calcSizeEncodingStringZeroLengthShallReturnEncodingSize);
  961. tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeEncodingStringAndServerIndexShallReturnEncodingSize);
  962. tcase_add_test(tc_calcSize, UA_ExpandedNodeId_calcSizeEncodingStringAndNamespaceUriShallReturnEncodingSize);
  963. tcase_add_test(tc_calcSize, UA_Guid_calcSizeShallReturnEncodingSize);
  964. tcase_add_test(tc_calcSize, UA_Guid_calcSizeShallReturnEncodingSize);
  965. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeTextOnlyShallReturnEncodingSize);
  966. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeLocaleOnlyShallReturnEncodingSize);
  967. tcase_add_test(tc_calcSize, UA_LocalizedText_calcSizeTextAndLocaleShallReturnEncodingSize);
  968. tcase_add_test(tc_calcSize, UA_Variant_calcSizeFixedSizeArrayShallReturnEncodingSize);
  969. tcase_add_test(tc_calcSize, UA_Variant_calcSizeVariableSizeArrayShallReturnEncodingSize);
  970. tcase_add_test(tc_calcSize, UA_Variant_calcSizeVariableSizeArrayWithNullPtrWillReturnWrongButLargeEnoughEncodingSize);
  971. tcase_add_test(tc_calcSize, UA_Variant_decodeWithOutDeleteMembersShallFailInCheckMem);
  972. suite_add_tcase(s,tc_calcSize);
  973. TCase *tc_decode = tcase_create("decode");
  974. tcase_add_test(tc_decode, UA_Byte_decodeShallCopyAndAdvancePosition);
  975. tcase_add_test(tc_decode, UA_Byte_decodeShallModifyOnlyCurrentPosition);
  976. tcase_add_test(tc_decode, UA_Int16_decodeShallAssumeLittleEndian);
  977. tcase_add_test(tc_decode, UA_Int16_decodeShallRespectSign);
  978. tcase_add_test(tc_decode, UA_UInt16_decodeShallNotRespectSign);
  979. tcase_add_test(tc_decode, UA_Int32_decodeShallAssumeLittleEndian);
  980. tcase_add_test(tc_decode, UA_Int32_decodeShallRespectSign);
  981. tcase_add_test(tc_decode, UA_UInt32_decodeShallNotRespectSign);
  982. tcase_add_test(tc_decode, UA_Float_decodeShallWorkOnExample);
  983. tcase_add_test(tc_decode, UA_Double_decodeShallGiveOne);
  984. tcase_add_test(tc_decode, UA_Double_decodeShallGiveZero);
  985. tcase_add_test(tc_decode, UA_Double_decodeShallGiveMinusTwo);
  986. tcase_add_test(tc_decode, UA_String_decodeShallAllocateMemoryAndCopyString);
  987. tcase_add_test(tc_decode, UA_String_decodeWithNegativeSizeShallNotAllocateMemoryAndNullPtr);
  988. tcase_add_test(tc_decode, UA_String_decodeWithZeroSizeShallNotAllocateMemoryAndNullPtr);
  989. tcase_add_test(tc_decode, UA_NodeId_decodeTwoByteShallReadTwoBytesAndSetNamespaceToZero);
  990. tcase_add_test(tc_decode, UA_NodeId_decodeFourByteShallReadFourBytesAndRespectNamespace);
  991. tcase_add_test(tc_decode, UA_NodeId_decodeStringShallAllocateMemory);
  992. tcase_add_test(tc_decode, UA_Variant_decodeWithOutArrayFlagSetShallSetVTAndAllocateMemoryForArray);
  993. tcase_add_test(tc_decode, UA_Variant_decodeWithArrayFlagSetShallSetVTAndAllocateMemoryForArray);
  994. suite_add_tcase(s,tc_decode);
  995. return s;
  996. }
  997. int main (void)
  998. {
  999. int number_failed = 0;
  1000. Suite* s;
  1001. SRunner* sr;
  1002. s = testSuite_builtin();
  1003. sr = srunner_create(s);
  1004. srunner_run_all(sr,CK_NORMAL);
  1005. number_failed += srunner_ntests_failed(sr);
  1006. srunner_free(sr);
  1007. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  1008. }