check_session.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include <open62541/types.h>
  5. #include "server/ua_services.h"
  6. #include <check.h>
  7. START_TEST(Session_init_ShallWork) {
  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 = 0;
  15. ck_assert_int_eq(session.activated, false);
  16. ck_assert_int_eq(session.header.authenticationToken.identifier.numeric, tmpNodeId.identifier.numeric);
  17. ck_assert_int_eq(session.availableContinuationPoints, UA_MAXCONTINUATIONPOINTS);
  18. ck_assert_ptr_eq(session.header.channel, NULL);
  19. ck_assert_ptr_eq(session.clientDescription.applicationName.locale.data, NULL);
  20. ck_assert_ptr_eq(session.continuationPoints, 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_set_fork_status(sr, CK_NOFORK);
  54. srunner_run_all(sr,CK_NORMAL);
  55. number_failed += srunner_ntests_failed(sr);
  56. srunner_free(sr);
  57. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  58. }