check_session.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "ua_types.h"
  4. #include "server/ua_services.h"
  5. #include "check.h"
  6. START_TEST(Session_init_ShallWork) {
  7. UA_Session session;
  8. UA_Session_init(&session);
  9. UA_NodeId tmpNodeId;
  10. UA_NodeId_init(&tmpNodeId);
  11. UA_ApplicationDescription tmpAppDescription;
  12. UA_ApplicationDescription_init(&tmpAppDescription);
  13. UA_DateTime tmpDateTime;
  14. UA_DateTime_init(&tmpDateTime);
  15. ck_assert_int_eq(session.activated, false);
  16. ck_assert_int_eq(session.authenticationToken.identifier.numeric, tmpNodeId.identifier.numeric);
  17. ck_assert_int_eq(session.availableContinuationPoints, UA_MAXCONTINUATIONPOINTS);
  18. ck_assert_ptr_eq(session.channel, NULL);
  19. ck_assert_ptr_eq(session.clientDescription.applicationName.locale.data, NULL);
  20. ck_assert_ptr_eq(session.continuationPoints.lh_first, NULL);
  21. ck_assert_int_eq(session.maxRequestMessageSize, 0);
  22. ck_assert_int_eq(session.maxResponseMessageSize, 0);
  23. ck_assert_int_eq(session.sessionId.identifier.numeric, tmpNodeId.identifier.numeric);
  24. ck_assert_ptr_eq(session.sessionName.data, NULL);
  25. ck_assert_int_eq((int)session.timeout, 0);
  26. ck_assert_int_eq(session.validTill, tmpDateTime);
  27. }
  28. END_TEST
  29. START_TEST(Session_updateLifetime_ShallWork) {
  30. UA_Session session;
  31. UA_Session_init(&session);
  32. UA_DateTime tmpDateTime;
  33. tmpDateTime = session.validTill;
  34. UA_Session_updateLifetime(&session);
  35. UA_Int32 result = (session.validTill > tmpDateTime);
  36. ck_assert_int_gt(result,0);
  37. }
  38. END_TEST
  39. static Suite* testSuite_Session(void) {
  40. Suite *s = suite_create("Session");
  41. TCase *tc_core = tcase_create("Core");
  42. tcase_add_test(tc_core, Session_init_ShallWork);
  43. tcase_add_test(tc_core, Session_updateLifetime_ShallWork);
  44. suite_add_tcase(s,tc_core);
  45. return s;
  46. }
  47. int main(void) {
  48. int number_failed = 0;
  49. Suite *s;
  50. SRunner *sr;
  51. s = testSuite_Session();
  52. sr = srunner_create(s);
  53. srunner_run_all(sr,CK_NORMAL);
  54. number_failed += srunner_ntests_failed(sr);
  55. srunner_free(sr);
  56. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  57. }