Browse Source

add a unit test whether references are deleted with the nodes

Julius Pfrommer 7 years ago
parent
commit
20d70c9a91
1 changed files with 50 additions and 1 deletions
  1. 50 1
      tests/check_services_nodemanagement.c

+ 50 - 1
tests/check_services_nodemanagement.c

@@ -166,12 +166,60 @@ START_TEST(DeleteObjectWithDestructor) {
     /* Delete the object */
     UA_Server_deleteNode(server, objectid, true);
 
-    /* Verify that the denstructor was called */
+    /* Verify that the destructor was called */
     ck_assert_int_eq(destructorCalled, true);
 
     UA_Server_delete(server);
 } END_TEST
 
+START_TEST(DeleteObjectAndReferences) {
+    UA_Server *server = UA_Server_new(UA_ServerConfig_standard);
+
+    /* Add an object of the type */
+    UA_ObjectAttributes attr;
+    UA_ObjectAttributes_init(&attr);
+    attr.displayName = UA_LOCALIZEDTEXT("en_US","my object");
+    UA_NodeId objectid = UA_NODEID_NUMERIC(0, 23372337);
+    UA_StatusCode res;
+    res = UA_Server_addObjectNode(server, objectid, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
+                                  UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), UA_QUALIFIEDNAME(0, ""),
+                                  UA_NODEID_NULL, attr, NULL, NULL);
+    ck_assert_int_eq(res, UA_STATUSCODE_GOOD);
+
+    /* Verify that we have a reference to the node from the objects folder */
+    UA_BrowseDescription bd;
+    UA_BrowseDescription_init(&bd);
+    bd.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
+    bd.referenceTypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT);
+    bd.browseDirection = UA_BROWSEDIRECTION_FORWARD;
+    
+    UA_BrowseResult br = UA_Server_browse(server, 0, &bd);
+    ck_assert_int_eq(br.statusCode, UA_STATUSCODE_GOOD);
+    UA_Boolean found = false;
+    for(size_t i = 0; i < br.referencesSize; ++i) {
+        if(UA_NodeId_equal(&br.references[i].nodeId.nodeId, &objectid))
+            found = true;
+    }
+    ck_assert_int_eq(found, true);
+    UA_BrowseResult_deleteMembers(&br);
+
+    /* Delete the object */
+    UA_Server_deleteNode(server, objectid, true);
+
+    /* Browse again, this time we expect that no reference is found */
+    br = UA_Server_browse(server, 0, &bd);
+    ck_assert_int_eq(br.statusCode, UA_STATUSCODE_GOOD);
+    found = false;
+    for(size_t i = 0; i < br.referencesSize; ++i) {
+        if(UA_NodeId_equal(&br.references[i].nodeId.nodeId, &objectid))
+            found = true;
+    }
+    ck_assert_int_eq(found, false);
+    UA_BrowseResult_deleteMembers(&br);
+
+    UA_Server_delete(server);
+} END_TEST
+
 static Suite * testSuite_services_nodemanagement(void) {
     Suite *s = suite_create("services_nodemanagement");
 
@@ -183,6 +231,7 @@ static Suite * testSuite_services_nodemanagement(void) {
 
     TCase *tc_deletenodes = tcase_create("deletenodes");
     tcase_add_test(tc_addnodes, DeleteObjectWithDestructor);
+    tcase_add_test(tc_addnodes, DeleteObjectAndReferences);
 
     suite_add_tcase(s, tc_addnodes);
     suite_add_tcase(s, tc_deletenodes);