check_namespace.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. ============================================================================
  3. Name : check_stack.c
  4. Author :
  5. Version :
  6. Copyright : Your copyright notice
  7. Description :
  8. ============================================================================
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include "opcua.h"
  13. #include "ua_namespace.h"
  14. #include "check.h"
  15. START_TEST(test_Namespace) {
  16. namespace *ns = UA_NULL;
  17. create_ns(&ns, 512);
  18. delete_ns(ns);
  19. }
  20. END_TEST
  21. UA_Int32 createNode(UA_Node** p, UA_Int16 nsid, UA_Int32 id) {
  22. UA_Node_new(p);
  23. (*p)->nodeId.encodingByte = UA_NODEIDTYPE_FOURBYTE;
  24. (*p)->nodeId.namespace = nsid;
  25. (*p)->nodeId.identifier.numeric = id;
  26. return UA_SUCCESS;
  27. }
  28. START_TEST(findNodeInNamespaceWithSingleEntry) {
  29. // given
  30. namespace *ns;
  31. create_ns(&ns, 512);
  32. UA_Node* n1; createNode(&n1,0,2253); insert_node(ns,n1);
  33. const UA_Node* nr = UA_NULL;
  34. ns_lock* nl = UA_NULL;
  35. UA_Int32 retval;
  36. // when
  37. retval = get_node(ns,&(n1->nodeId),&nr,&nl);
  38. // then
  39. ck_assert_int_eq(retval, UA_SUCCESS);
  40. ck_assert_ptr_eq(nr,n1);
  41. // finally
  42. delete_ns(ns);
  43. }
  44. END_TEST
  45. START_TEST(findNodeInNamespaceWithTwoEntries) {
  46. // given
  47. namespace *ns;
  48. create_ns(&ns, 512);
  49. UA_Node* n1; createNode(&n1,0,2253); insert_node(ns,n1);
  50. UA_Node* n2; createNode(&n2,0,2255); insert_node(ns,n2);
  51. const UA_Node* nr = UA_NULL;
  52. ns_lock* nl = UA_NULL;
  53. UA_Int32 retval;
  54. // when
  55. retval = get_node(ns,&(n2->nodeId),&nr,&nl);
  56. // then
  57. ck_assert_int_eq(retval, UA_SUCCESS);
  58. ck_assert_ptr_eq(nr,n2);
  59. // finally
  60. delete_ns(ns);
  61. }
  62. END_TEST
  63. Suite * namespace_suite (void) {
  64. Suite *s = suite_create ("Namespace");
  65. TCase *tc_cd = tcase_create ("Create/Delete");
  66. tcase_add_test (tc_cd, test_Namespace);
  67. suite_add_tcase (s, tc_cd);
  68. TCase* tc_find = tcase_create ("Find");
  69. tcase_add_test (tc_find, findNodeInNamespaceWithSingleEntry);
  70. tcase_add_test (tc_find, findNodeInNamespaceWithTwoEntries);
  71. suite_add_tcase (s, tc_find);
  72. return s;
  73. }
  74. int main (void) {
  75. int number_failed =0;
  76. Suite *s = namespace_suite ();
  77. SRunner *sr = srunner_create (s);
  78. // srunner_set_fork_status(sr,CK_NOFORK);
  79. srunner_run_all (sr, CK_NORMAL);
  80. number_failed += srunner_ntests_failed (sr);
  81. srunner_free (sr);
  82. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  83. }