check_session.c 2.1 KB

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