Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ static char *graph_error_messages[] = {
"No node has been found",
"Label not present",
"Allocation failed (OOM?)",
"Hashtable error",
"The connection hasn't been found"
};

Expand Down Expand Up @@ -87,8 +88,13 @@ graph_destroy(graph_t *graph)
int
graph_node_delete(graph_t *graph, char *label __attribute__ ((unused)), graph_node_t **connections, int max_connections)
{
if (!graph || !label) {
if (graph) graph->errno = EGRAPHNOLABEL;
return -1;
}

graph_node_t *node = NULL;
int rc = ht_delete(graph->nodes, node->label, strlen(node->label), (void **)&node, NULL);
int rc = ht_delete(graph->nodes, label, strlen(label), (void **)&node, NULL);
if (rc != 0) {
graph->errno = EGRAPHTABLEERR;
return -1;
Expand Down
5 changes: 5 additions & 0 deletions test/graph_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ int main(int argc, char **argv)
test_node2 = graph_node_next(node2);
ut_result(test_node == node3 && test_node2 == node4, "Node selection doesn't honor weights returned by the chooser");

ut_testing("Deleting an existing node from the graph");
int delete_ret;
delete_ret = graph_node_delete(graph, "start_node", NULL, 100);
ut_result(delete_ret == 0, "Delete failed");

graph_destroy(graph);

ut_summary();
Expand Down