check_session.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 <stdio.h>
  5. #include <stdlib.h>
  6. #include "ua_types.h"
  7. #include "server/ua_services.h"
  8. #include "check.h"
  9. START_TEST(Session_init_ShallWork) {
  10. UA_Session session;
  11. UA_Session_init(&session);
  12. UA_NodeId tmpNodeId;
  13. UA_NodeId_init(&tmpNodeId);
  14. UA_ApplicationDescription tmpAppDescription;
  15. UA_ApplicationDescription_init(&tmpAppDescription);
  16. UA_DateTime tmpDateTime = 0;
  17. ck_assert_int_eq(session.activated, false);
  18. ck_assert_int_eq(session.header.authenticationToken.identifier.numeric, tmpNodeId.identifier.numeric);
  19. ck_assert_int_eq(session.availableContinuationPoints, UA_MAXCONTINUATIONPOINTS);
  20. ck_assert_ptr_eq(session.header.channel, NULL);
  21. ck_assert_ptr_eq(session.clientDescription.applicationName.locale.data, NULL);
  22. ck_assert_ptr_eq(session.continuationPoints.lh_first, NULL);
  23. ck_assert_int_eq(session.maxRequestMessageSize, 0);
  24. ck_assert_int_eq(session.maxResponseMessageSize, 0);
  25. ck_assert_int_eq(session.sessionId.identifier.numeric, tmpNodeId.identifier.numeric);
  26. ck_assert_ptr_eq(session.sessionName.data, NULL);
  27. ck_assert_int_eq((int)session.timeout, 0);
  28. ck_assert_int_eq(session.validTill, tmpDateTime);
  29. }
  30. END_TEST
  31. START_TEST(Session_updateLifetime_ShallWork) {
  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_set_fork_status(sr, CK_NOFORK);
  56. srunner_run_all(sr,CK_NORMAL);
  57. number_failed += srunner_ntests_failed(sr);
  58. srunner_free(sr);
  59. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  60. }