X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Faga%2Ftest%2Ferror-graph.c;fp=ccan%2Faga%2Ftest%2Ferror-graph.c;h=a52544b175fbc344958cf8586e22d0774cf57849;hb=2192bdd98afbb1ddb489c863edd191877051de8b;hp=0000000000000000000000000000000000000000;hpb=3b7409ea08a7d1643bc7de31ece63e20b89f319b;p=ccan diff --git a/ccan/aga/test/error-graph.c b/ccan/aga/test/error-graph.c new file mode 100644 index 00000000..a52544b1 --- /dev/null +++ b/ccan/aga/test/error-graph.c @@ -0,0 +1,56 @@ +#include "config.h" + +#include + +#include +#include +#include + +#include "simple-graph.h" + +static ptrint_t *error_first_edge(const struct aga_graph *g, + const struct aga_node *n) +{ + return int2ptr(1); +} + +static ptrint_t *error_next_edge(const struct aga_graph *g, + const struct aga_node *n, + ptrint_t *edge) +{ + assert(edge == int2ptr(1)); + + return NULL; +} + +static int error_edge_info(const struct aga_graph *g, const struct aga_node *n, + ptrint_t *edge, struct aga_edge_info *ei) +{ + struct error_graph *eg = container_of(g, struct error_graph, sg.g); + int fromindex = n - eg->sg.nodes; + + switch (fromindex) { + case 1: + ei->to = &eg->sg.nodes[2]; + break; + + case 2: + ei->to = NULL; + break; + + case 3: + ei->to = &eg->sg.nodes[4]; + break; + + default: + return -1; + } + + return 0; +} + +void error_graph_init(struct error_graph *eg) +{ + simple_graph_init(&eg->sg, error_first_edge, error_next_edge, + error_edge_info); +}