GRU - Generic Reusable Utilities
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
collection/gru_node_test.c

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;
}