pdr: Add pldm_entity_association_tree_delete_node() API

This API deletes the specific entity node from the entity
association tree. We must handle the parent children and sibling
relationship before we delete the node from the entity association
tree.

Change-Id: I326adba8316a15c6af0696cdd9bdf2be7e592452
Signed-off-by: Pavithra Barithaya <pavithrabarithaya07@gmail.com>
diff --git a/tests/dsp/pdr.cpp b/tests/dsp/pdr.cpp
index 0d19de2..9c48215 100644
--- a/tests/dsp/pdr.cpp
+++ b/tests/dsp/pdr.cpp
@@ -7,6 +7,7 @@
 #include <cstdint>
 #include <cstdlib>
 #include <cstring>
+#include <memory>
 #include <vector>
 
 #include <gtest/gtest.h>
@@ -2589,3 +2590,71 @@
     pldm_pdr_destroy(repo);
 }
 #endif
+
+#ifdef LIBPLDM_API_TESTING
+TEST(EntityAssociationPDR, testDeleteNode)
+{
+    std::unique_ptr<pldm_entity, decltype(&free)> entities(
+        (pldm_entity*)malloc(sizeof(pldm_entity) * 4), &free);
+    ASSERT_NE(entities, nullptr);
+
+    entities.get()[0].entity_type = 1;
+
+    entities.get()[1].entity_type = 2;
+    entities.get()[1].entity_instance_num = 1;
+    entities.get()[1].entity_container_id = 2;
+
+    entities.get()[2].entity_type = 3;
+    entities.get()[2].entity_instance_num = 1;
+    entities.get()[2].entity_container_id = 2;
+
+    entities.get()[3].entity_type = 4;
+    entities.get()[3].entity_instance_num = 1;
+    entities.get()[3].entity_container_id = 2;
+
+    auto tree = pldm_entity_association_tree_init();
+    ASSERT_NE(tree, nullptr);
+
+    auto l1 = pldm_entity_association_tree_add_entity(
+        tree, &entities.get()[0], 0xffff, nullptr,
+        PLDM_ENTITY_ASSOCIAION_LOGICAL, false, true, 0xffff);
+    ASSERT_NE(l1, nullptr);
+
+    auto l2 = pldm_entity_association_tree_add_entity(
+        tree, &entities.get()[1], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL,
+        false, false, 0xffff);
+    ASSERT_NE(l2, nullptr);
+
+    auto l3 = pldm_entity_association_tree_add_entity(
+        tree, &entities.get()[2], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL,
+        false, true, 0xffff);
+    ASSERT_NE(l3, nullptr);
+
+    auto l4 = pldm_entity_association_tree_add_entity(
+        tree, &entities.get()[3], 0xffff, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL,
+        false, true, 0xffff);
+    ASSERT_NE(l4, nullptr);
+
+    EXPECT_EQ(pldm_entity_get_num_children(l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL),
+              3);
+
+    pldm_entity entity{};
+    entity.entity_type = 4;
+    entity.entity_instance_num = 1;
+    entity.entity_container_id = 2;
+
+    pldm_entity_association_tree_delete_node(tree, &entity);
+    EXPECT_EQ(pldm_entity_get_num_children(l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL),
+              2);
+
+    entity.entity_type = 3;
+    entity.entity_instance_num = 1;
+    entity.entity_container_id = 2;
+
+    pldm_entity_association_tree_delete_node(tree, &entity);
+    EXPECT_EQ(pldm_entity_get_num_children(l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL),
+              1);
+
+    pldm_entity_association_tree_destroy(tree);
+}
+#endif