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;
  17. UA_DateTime_init(&tmpDateTime);
  18. ck_assert_int_eq(session.activated, false);
  19. ck_assert_int_eq(session.authenticationToken.identifier.numeric, tmpNodeId.identifier.numeric);
  20. ck_assert_int_eq(session.availableContinuationPoints, UA_MAXCONTINUATIONPOINTS);
  21. ck_assert_ptr_eq(session.channel, NULL);
  22. ck_assert_ptr_eq(session.clientDescription.applicationName.locale.data, NULL);
  23. ck_assert_ptr_eq(session.continuationPoints.lh_first, NULL);
  24. ck_assert_int_eq(session.maxRequestMessageSize, 0);
  25. ck_assert_int_eq(session.maxResponseMessageSize, 0);
  26. ck_assert_int_eq(session.sessionId.identifier.numeric, tmpNodeId.identifier.numeric);
  27. ck_assert_ptr_eq(session.sessionName.data, NULL);
  28. ck_assert_int_eq((int)session.timeout, 0);
  29. ck_assert_int_eq(session.validTill, tmpDateTime);
  30. }
  31. END_TEST
  32. START_TEST(Session_updateLifetime_ShallWork) {
  33. UA_Session session;
  34. UA_Session_init(&session);
  35. UA_DateTime tmpDateTime;
  36. tmpDateTime = session.validTill;
  37. UA_Session_updateLifetime(&session);
  38. UA_Int32 result = (session.validTill > tmpDateTime);
  39. ck_assert_int_gt(result,0);
  40. }
  41. END_TEST
  42. static Suite* testSuite_Session(void) {
  43. Suite *s = suite_create("Session");
  44. TCase *tc_core = tcase_create("Core");
  45. tcase_add_test(tc_core, Session_init_ShallWork);
  46. tcase_add_test(tc_core, Session_updateLifetime_ShallWork);
  47. suite_add_tcase(s,tc_core);
  48. return s;
  49. }
  50. int main(void) {
  51. int number_failed = 0;
  52. Suite *s;
  53. SRunner *sr;
  54. s = testSuite_Session();
  55. sr = srunner_create(s);
  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. }