check_calcSize.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. ============================================================================
  3. Name : check_calcsize.c
  4. Author :
  5. Version :
  6. Copyright : Your copyright notice
  7. Description :
  8. ============================================================================
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include "opcua.h"
  13. #include "opcua_transportLayer.h"
  14. #include "check.h"
  15. START_TEST(diagnosticInfo_calcSize_test)
  16. {
  17. UA_Int32 valreal = 0;
  18. UA_Int32 valcalc = 0;
  19. UA_DiagnosticInfo diagnosticInfo;
  20. diagnosticInfo.encodingMask = 0x01 | 0x02 | 0x04 | 0x08 | 0x10;
  21. diagnosticInfo.symbolicId = 30;
  22. diagnosticInfo.namespaceUri = 25;
  23. diagnosticInfo.localizedText = 22;
  24. diagnosticInfo.additionalInfo.data = "OPCUA";
  25. diagnosticInfo.additionalInfo.length = 5;
  26. ck_assert_int_eq(UA_DiagnosticInfo_calcSize(&diagnosticInfo),26);
  27. }
  28. END_TEST
  29. START_TEST(extensionObject_calcSize_test)
  30. {
  31. UA_Int32 valreal = 0;
  32. UA_Int32 valcalc = 0;
  33. UA_Byte data[3] = {1,2,3};
  34. UA_ExtensionObject extensionObject;
  35. // empty ExtensionObject, handcoded
  36. extensionObject.typeId.encodingByte = UA_NODEIDTYPE_TWOBYTE;
  37. extensionObject.typeId.identifier.numeric = 0;
  38. extensionObject.encoding = UA_EXTENSIONOBJECT_ENCODINGMASKTYPE_NOBODYISENCODED;
  39. ck_assert_int_eq(UA_ExtensionObject_calcSize(&extensionObject), 1 + 1 + 1);
  40. // ExtensionObject with ByteString-Body
  41. extensionObject.encoding = UA_EXTENSIONOBJECT_ENCODINGMASKTYPE_BODYISBYTESTRING;
  42. extensionObject.body.data = data;
  43. extensionObject.body.length = 3;
  44. ck_assert_int_eq(UA_ExtensionObject_calcSize(&extensionObject), 3 + 4 + 3);
  45. }
  46. END_TEST
  47. START_TEST(responseHeader_calcSize_test)
  48. {
  49. UA_ResponseHeader responseHeader;
  50. UA_DiagnosticInfo diagnosticInfo;
  51. UA_ExtensionObject extensionObject;
  52. UA_DiagnosticInfo emptyDO = {0x00};
  53. UA_ExtensionObject emptyEO = {{UA_NODEIDTYPE_TWOBYTE,0},UA_EXTENSIONOBJECT_ENCODINGMASKTYPE_NOBODYISENCODED};
  54. //Should have the size of 26 Bytes
  55. diagnosticInfo.encodingMask = UA_DIAGNOSTICINFO_ENCODINGMASKTYPE_SYMBOLICID | UA_DIAGNOSTICINFO_ENCODINGMASKTYPE_NAMESPACE | UA_DIAGNOSTICINFO_ENCODINGMASKTYPE_LOCALIZEDTEXT | UA_DIAGNOSTICINFO_ENCODINGMASKTYPE_LOCALE | UA_DIAGNOSTICINFO_ENCODINGMASKTYPE_ADDITIONALINFO; // Byte: 1
  56. // Indices into to Stringtable of the responseHeader (62541-6 §5.5.12 )
  57. diagnosticInfo.symbolicId = -1; // Int32: 4
  58. diagnosticInfo.namespaceUri = -1; // Int32: 4
  59. diagnosticInfo.localizedText = -1; // Int32: 4
  60. diagnosticInfo.locale = -1; // Int32: 4
  61. // Additional Info
  62. diagnosticInfo.additionalInfo.length = 5; // Int32: 4
  63. diagnosticInfo.additionalInfo.data = "OPCUA"; // Byte[]: 5
  64. responseHeader.serviceDiagnostics = &diagnosticInfo;
  65. ck_assert_int_eq(UA_DiagnosticInfo_calcSize(&diagnosticInfo),1+(4+4+4+4)+(4+5));
  66. responseHeader.stringTableSize = -1; // Int32: 4
  67. responseHeader.stringTable = NULL;
  68. responseHeader.additionalHeader = &emptyEO; // 3
  69. ck_assert_int_eq(UA_ResponseHeader_calcSize(&responseHeader),16+26+4+3);
  70. responseHeader.serviceDiagnostics = &emptyDO;
  71. ck_assert_int_eq(UA_ResponseHeader_calcSize(&responseHeader),16+1+4+3);
  72. }
  73. END_TEST
  74. //ToDo: Function needs to be filled
  75. START_TEST(expandedNodeId_calcSize_test)
  76. {
  77. UA_Int32 valreal = 300;
  78. UA_Int32 valcalc = 0;
  79. ck_assert_int_eq(valcalc,valreal);
  80. }
  81. END_TEST
  82. START_TEST(DataValue_calcSize_test)
  83. {
  84. UA_DataValue dataValue;
  85. dataValue.encodingMask = UA_DATAVALUE_STATUSCODE | UA_DATAVALUE_SOURCETIMESTAMP | UA_DATAVALUE_SOURCEPICOSECONDS;
  86. dataValue.status = 12;
  87. UA_DateTime dateTime;
  88. dateTime = 80;
  89. dataValue.sourceTimestamp = dateTime;
  90. UA_DateTime sourceTime;
  91. dateTime = 214;
  92. dataValue.sourcePicoseconds = sourceTime;
  93. int size = 0;
  94. size = UA_DataValue_calcSize(&dataValue);
  95. ck_assert_int_eq(size, 21);
  96. }
  97. END_TEST
  98. Suite* testSuite_diagnosticInfo_calcSize()
  99. {
  100. Suite *s = suite_create("diagnosticInfo_calcSize");
  101. TCase *tc_core = tcase_create("Core");
  102. tcase_add_test(tc_core, diagnosticInfo_calcSize_test);
  103. suite_add_tcase(s,tc_core);
  104. return s;
  105. }
  106. Suite* testSuite_extensionObject_calcSize()
  107. {
  108. Suite *s = suite_create("extensionObject_calcSize");
  109. TCase *tc_core = tcase_create("Core");
  110. tcase_add_test(tc_core, extensionObject_calcSize_test);
  111. suite_add_tcase(s,tc_core);
  112. return s;
  113. }
  114. Suite* testSuite_responseHeader_calcSize()
  115. {
  116. Suite *s = suite_create("responseHeader_calcSize");
  117. TCase *tc_core = tcase_create("Core");
  118. tcase_add_test(tc_core, responseHeader_calcSize_test);
  119. suite_add_tcase(s,tc_core);
  120. return s;
  121. }
  122. Suite* testSuite_dataValue_calcSize(void)
  123. {
  124. Suite *s = suite_create("dataValue_calcSize");
  125. TCase *tc_core = tcase_create("Core");
  126. tcase_add_test(tc_core,DataValue_calcSize_test);
  127. suite_add_tcase(s,tc_core);
  128. return s;
  129. }
  130. Suite* testSuite_expandedNodeId_calcSize(void)
  131. {
  132. Suite *s = suite_create("expandedNodeId_calcSize");
  133. TCase *tc_core = tcase_create("Core");
  134. tcase_add_test(tc_core,expandedNodeId_calcSize_test);
  135. suite_add_tcase(s,tc_core);
  136. return s;
  137. }
  138. int main (void)
  139. {
  140. int number_failed = 0;
  141. Suite *s = testSuite_diagnosticInfo_calcSize();
  142. SRunner *sr = srunner_create(s);
  143. srunner_run_all(sr,CK_NORMAL);
  144. number_failed += srunner_ntests_failed(sr);
  145. srunner_free(sr);
  146. s = testSuite_extensionObject_calcSize();
  147. sr = srunner_create(s);
  148. srunner_run_all(sr,CK_NORMAL);
  149. number_failed += srunner_ntests_failed(sr);
  150. srunner_free(sr);
  151. s = testSuite_responseHeader_calcSize();
  152. sr = srunner_create(s);
  153. srunner_run_all(sr,CK_NORMAL);
  154. number_failed += srunner_ntests_failed(sr);
  155. srunner_free(sr);
  156. s = testSuite_expandedNodeId_calcSize();
  157. sr = srunner_create(s);
  158. srunner_run_all(sr,CK_NORMAL);
  159. number_failed += srunner_ntests_failed(sr);
  160. srunner_free(sr);
  161. s = testSuite_dataValue_calcSize();
  162. sr = srunner_create(s);
  163. srunner_run_all(sr,CK_NORMAL);
  164. number_failed += srunner_ntests_failed(sr);
  165. srunner_free(sr);
  166. s = testSuite_expandedNodeId_calcSize();
  167. sr = srunner_create(s);
  168. srunner_run_all(sr,CK_NORMAL);
  169. number_failed += srunner_ntests_failed(sr);
  170. srunner_free(sr);
  171. s = testSuite_dataValue_calcSize();
  172. sr = srunner_create(s);
  173. srunner_run_all(sr,CK_NORMAL);
  174. number_failed += srunner_ntests_failed(sr);
  175. srunner_free(sr);
  176. /* <TESTSUITE_TEMPLATE>
  177. s = <TESTSUITENAME>;
  178. sr = srunner_create(s);
  179. srunner_run_all(sr,CK_NORMAL);
  180. number_failed += srunner_ntests_failed(sr);
  181. srunner_free(sr);
  182. */
  183. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  184. }