GRU - Generic Reusable Utilities
Loading...
Searching...
No Matches
collection/gru_node_test.c

GRU node example.

GRU node example

#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
static bool test_set_next() {
uint32_t value1 = 10;
uint32_t value2 = 20;
gru_node_t *node1 = gru_node_new(&value1);
gru_node_t *node2 = gru_node_new(&value2);
gru_node_set_next(node1, node2);
// A *very* simple test to check the circular relationship between the nodes
uint32_t d1 = gru_node_get_data(uint32_t, node1->next);
uint32_t d2 = gru_node_get_data(uint32_t, node2->previous);
if (d1 == 20) {
if (d2 == 10) {
if (node1 != NULL || node2 != NULL) {
printf("Node incorrectly destroyed\n");
return false;
}
return true;
}
}
if (node1 != NULL || node2 != NULL) {
printf("Node incorrectly destroyed\n");
}
return false;
}
static bool test_set_previous() {
uint32_t value1 = 10;
uint32_t value2 = 20;
gru_node_t *node1 = gru_node_new(&value1);
gru_node_t *node2 = gru_node_new(&value2);
gru_node_set_previous(node2, node1);
// A *very* simple test to check the circular relationship between the nodes
uint32_t d1 = gru_node_get_data(uint32_t, node1->next);
uint32_t d2 = gru_node_get_data(uint32_t, node2->previous);
if (d1 == 20) {
if (d2 == 10) {
if (node1 != NULL || node2 != NULL) {
printf("Node incorrectly destroyed\n");
return false;
}
return true;
}
}
if (node1 != NULL || node2 != NULL) {
printf("Node incorrectly destroyed\n");
}
return false;
}
/*
*
*/
int main(int argc, char **argv) {
if (test_set_next()) {
if (test_set_previous()) {
return EXIT_SUCCESS;
}
}
return EXIT_FAILURE;
}
int main(int argc, char **argv)
Definition: gru_list_test.c:198
void gru_node_destroy(gru_node_t **node)
Destroys a node and sets is address to NULL.
Definition: gru_node.c:33
void gru_node_set_previous(gru_node_t *node, gru_node_t *previous)
Definition: gru_node.c:40
gru_node_t * gru_node_new(const void *ptr)
Creates a new node.
Definition: gru_node.c:18
void gru_node_set_next(gru_node_t *node, gru_node_t *next)
Definition: gru_node.c:52
#define gru_node_get_data(type, node)
Definition: gru_node.h:73
Definition: gru_node.h:25
struct gru_node_t_ * next
Definition: gru_node.h:26
struct gru_node_t_ * previous
Definition: gru_node.h:27