check_stack.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_UInt32 i;
  54. UA_Byte buf[256];
  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_encode((void const**)array, noElements, UA_BYTESTRING, &pos, buf);
  62. // check size
  63. ck_assert_int_eq(pos, 4 + 4 + 6 + 4);
  64. // check result
  65. for (i=0; i < sizeof(result); i++) {
  66. ck_assert_int_eq(buf[i],result[i]);
  67. }
  68. }
  69. END_TEST
  70. /**Suite *testSuite_getPacketType(void)
  71. {
  72. Suite *s = suite_create("getPacketType");
  73. TCase *tc_core = tcase_create("Core");
  74. tcase_add_test(tc_core,test_getPacketType_validParameter);
  75. suite_add_tcase(s,tc_core);
  76. return s;
  77. }**/
  78. Suite* testSuite_encode_builtInDatatypeArray()
  79. {
  80. Suite *s = suite_create("encode_builtInDatatypeArray");
  81. TCase *tc_core = tcase_create("Core");
  82. tcase_add_test(tc_core, encode_builtInDatatypeArray_test_String);
  83. suite_add_tcase(s,tc_core);
  84. return s;
  85. }
  86. /*
  87. Suite* TL_<TESTSUITENAME>(void)
  88. {
  89. Suite *s = suite_create("<TESTSUITENAME>");
  90. TCase *tc_core = tcase_create("Core");
  91. tcase_add_test(tc_core,<TEST_NAME>);
  92. suite_add_tcase(s,tc_core);
  93. return s;
  94. }
  95. */
  96. int main (void)
  97. {
  98. int number_failed = 0;
  99. Suite *s;
  100. SRunner *sr;
  101. /* s = testSuite_getPacketType();
  102. sr = srunner_create(s);
  103. srunner_run_all(sr,CK_NORMAL);
  104. number_failed = srunner_ntests_failed(sr);
  105. srunner_free(sr); */
  106. s = testSuite_encode_builtInDatatypeArray();
  107. sr = srunner_create(s);
  108. srunner_run_all(sr,CK_NORMAL);
  109. number_failed += srunner_ntests_failed(sr);
  110. srunner_free(sr);
  111. /* <TESTSUITE_TEMPLATE>
  112. s = <TESTSUITENAME>;
  113. sr = srunner_create(s);
  114. srunner_run_all(sr,CK_NORMAL);
  115. number_failed += srunner_ntests_failed(sr);
  116. srunner_free(sr);
  117. */
  118. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  119. }