check_stack.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. ============================================================================
  3. Name : check_stack.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. /*
  16. START_TEST(test_getPacketType_validParameter)
  17. {
  18. char buf[] = {'C','L','O'};
  19. UA_Int32 pos = 0;
  20. UA_ByteString msg;
  21. msg.data = buf;
  22. msg.length = 3;
  23. ck_assert_int_eq(TL_getPacketType(&msg, &pos),packetType_CLO);
  24. }
  25. END_TEST
  26. */
  27. /*
  28. START_TEST(decodeRequestHeader_test_validParameter)
  29. {
  30. char testMessage = {0x00,0x00,0x72,0xf1,0xdc,0xc9,0x87,0x0b,
  31. 0xcf,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
  32. 0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,
  33. 0x00,0x00,0x00,0x00,0x00};
  34. UA_ByteString rawMessage;
  35. rawMessage.data = &testMessage;
  36. rawMessage.length = 29;
  37. Int32 position = 0;
  38. T_RequestHeader requestHeader;
  39. decodeRequestHeader(rawMessage,&position,&requestHeader);
  40. ck_assert_int_eq(requestHeader.authenticationToken.EncodingByte,0);
  41. ck_assert_int_eq(requestHeader.returnDiagnostics,0);
  42. ck_assert_int_eq(requestHeader.authenticationToken.EncodingByte,0);
  43. }
  44. END_TEST
  45. */
  46. START_TEST(encode_builtInDatatypeArray_test_String)
  47. {
  48. UA_Int32 noElements = 2;
  49. UA_ByteString s1 = { 6, (UA_Byte*) "OPC UA" };
  50. UA_ByteString s2 = { -1, UA_NULL };
  51. UA_ByteString* array[] = { &s1, &s2 };
  52. UA_Int32 pos = 0;
  53. UA_Byte buf[256];
  54. UA_Byte result[] = {
  55. 0x02, 0x00, 0x00, 0x00, // noElements
  56. 0x06, 0x00, 0x00, 0x00, // s1.Length
  57. 'O', 'P', 'C', ' ', 'U', 'A', // s1.Data
  58. 0xFF, 0xFF, 0xFF, 0xFF // s2.Length
  59. };
  60. UA_Array_encode((void const**)array, noElements, UA_BYTESTRING, &pos, buf);
  61. // check size
  62. ck_assert_int_eq(pos, 4 + 4 + 6 + 4);
  63. ck_assert_int_eq(pos, sizeof(result));
  64. // check result
  65. ck_assert_int_eq(buf[0],result[0]);
  66. ck_assert_int_eq(buf[1],result[1]);
  67. ck_assert_int_eq(buf[2],result[2]);
  68. ck_assert_int_eq(buf[3],result[3]);
  69. ck_assert_int_eq(buf[4],result[4]);
  70. ck_assert_int_eq(buf[5],result[5]);
  71. ck_assert_int_eq(buf[6],result[6]);
  72. ck_assert_int_eq(buf[7],result[7]);
  73. ck_assert_int_eq(buf[8],result[8]);
  74. ck_assert_int_eq(buf[9],result[9]);
  75. ck_assert_int_eq(buf[10],result[10]);
  76. ck_assert_int_eq(buf[11],result[11]);
  77. ck_assert_int_eq(buf[12],result[12]);
  78. ck_assert_int_eq(buf[13],result[13]);
  79. ck_assert_int_eq(buf[14],result[14]);
  80. ck_assert_int_eq(buf[15],result[15]);
  81. ck_assert_int_eq(buf[16],result[16]);
  82. ck_assert_int_eq(buf[17],result[17]);
  83. }
  84. END_TEST
  85. /**Suite *testSuite_getPacketType(void)
  86. {
  87. Suite *s = suite_create("getPacketType");
  88. TCase *tc_core = tcase_create("Core");
  89. tcase_add_test(tc_core,test_getPacketType_validParameter);
  90. suite_add_tcase(s,tc_core);
  91. return s;
  92. }**/
  93. Suite* testSuite_encode_builtInDatatypeArray()
  94. {
  95. Suite *s = suite_create("encode_builtInDatatypeArray");
  96. TCase *tc_core = tcase_create("Core");
  97. tcase_add_test(tc_core, encode_builtInDatatypeArray_test_String);
  98. suite_add_tcase(s,tc_core);
  99. return s;
  100. }
  101. /*
  102. Suite* TL_<TESTSUITENAME>(void)
  103. {
  104. Suite *s = suite_create("<TESTSUITENAME>");
  105. TCase *tc_core = tcase_create("Core");
  106. tcase_add_test(tc_core,<TEST_NAME>);
  107. suite_add_tcase(s,tc_core);
  108. return s;
  109. }
  110. */
  111. int main (void)
  112. {
  113. int number_failed = 0;
  114. Suite *s;
  115. SRunner *sr;
  116. /* s = testSuite_getPacketType();
  117. sr = srunner_create(s);
  118. srunner_run_all(sr,CK_NORMAL);
  119. number_failed = srunner_ntests_failed(sr);
  120. srunner_free(sr); */
  121. s = testSuite_encode_builtInDatatypeArray();
  122. sr = srunner_create(s);
  123. srunner_run_all(sr,CK_NORMAL);
  124. number_failed += srunner_ntests_failed(sr);
  125. srunner_free(sr);
  126. /* <TESTSUITE_TEMPLATE>
  127. s = <TESTSUITENAME>;
  128. sr = srunner_create(s);
  129. srunner_run_all(sr,CK_NORMAL);
  130. number_failed += srunner_ntests_failed(sr);
  131. srunner_free(sr);
  132. */
  133. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  134. }