check_stack.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 "ua_transport.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_ByteString dst = { sizeof(buf), buf };
  55. UA_Byte result[] = {
  56. 0x02, 0x00, 0x00, 0x00, // noElements
  57. 0x06, 0x00, 0x00, 0x00, // s1.Length
  58. 'O', 'P', 'C', ' ', 'U', 'A', // s1.Data
  59. 0xFF, 0xFF, 0xFF, 0xFF // s2.Length
  60. };
  61. UA_Array_encodeBinary((void const**)array, noElements, UA_BYTESTRING, &pos, &dst);
  62. // check size
  63. ck_assert_int_eq(pos, 4 + 4 + 6 + 4);
  64. ck_assert_int_eq(pos, sizeof(result));
  65. // check result
  66. ck_assert_int_eq(buf[0],result[0]);
  67. ck_assert_int_eq(buf[1],result[1]);
  68. ck_assert_int_eq(buf[2],result[2]);
  69. ck_assert_int_eq(buf[3],result[3]);
  70. ck_assert_int_eq(buf[4],result[4]);
  71. ck_assert_int_eq(buf[5],result[5]);
  72. ck_assert_int_eq(buf[6],result[6]);
  73. ck_assert_int_eq(buf[7],result[7]);
  74. ck_assert_int_eq(buf[8],result[8]);
  75. ck_assert_int_eq(buf[9],result[9]);
  76. ck_assert_int_eq(buf[10],result[10]);
  77. ck_assert_int_eq(buf[11],result[11]);
  78. ck_assert_int_eq(buf[12],result[12]);
  79. ck_assert_int_eq(buf[13],result[13]);
  80. ck_assert_int_eq(buf[14],result[14]);
  81. ck_assert_int_eq(buf[15],result[15]);
  82. ck_assert_int_eq(buf[16],result[16]);
  83. ck_assert_int_eq(buf[17],result[17]);
  84. }
  85. END_TEST
  86. /**Suite *testSuite_getPacketType(void)
  87. {
  88. Suite *s = suite_create("getPacketType");
  89. TCase *tc_core = tcase_create("Core");
  90. tcase_add_test(tc_core,test_getPacketType_validParameter);
  91. suite_add_tcase(s,tc_core);
  92. return s;
  93. }**/
  94. Suite* testSuite_encode_builtInDatatypeArray()
  95. {
  96. Suite *s = suite_create("encode_builtInDatatypeArray");
  97. TCase *tc_core = tcase_create("Core");
  98. tcase_add_test(tc_core, encode_builtInDatatypeArray_test_String);
  99. suite_add_tcase(s,tc_core);
  100. return s;
  101. }
  102. /*
  103. Suite* TL_<TESTSUITENAME>(void)
  104. {
  105. Suite *s = suite_create("<TESTSUITENAME>");
  106. TCase *tc_core = tcase_create("Core");
  107. tcase_add_test(tc_core,<TEST_NAME>);
  108. suite_add_tcase(s,tc_core);
  109. return s;
  110. }
  111. */
  112. int main (void)
  113. {
  114. int number_failed = 0;
  115. Suite *s;
  116. SRunner *sr;
  117. /* s = testSuite_getPacketType();
  118. sr = srunner_create(s);
  119. srunner_run_all(sr,CK_NORMAL);
  120. number_failed = srunner_ntests_failed(sr);
  121. srunner_free(sr); */
  122. s = testSuite_encode_builtInDatatypeArray();
  123. sr = srunner_create(s);
  124. srunner_run_all(sr,CK_NORMAL);
  125. number_failed += srunner_ntests_failed(sr);
  126. srunner_free(sr);
  127. /* <TESTSUITE_TEMPLATE>
  128. s = <TESTSUITENAME>;
  129. sr = srunner_create(s);
  130. srunner_run_all(sr,CK_NORMAL);
  131. number_failed += srunner_ntests_failed(sr);
  132. srunner_free(sr);
  133. */
  134. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  135. }