]> git.ozlabs.org Git - ccan/blob - ccan/aga/test/error-graph.c
crypto/shachain/tools: update to new rbuf API.
[ccan] / ccan / aga / test / error-graph.c
1 #include "config.h"
2
3 #include <assert.h>
4
5 #include <ccan/aga/aga.h>
6 #include <ccan/container_of/container_of.h>
7 #include <ccan/ptrint/ptrint.h>
8
9 #include "simple-graph.h"
10
11 static ptrint_t *error_first_edge(const struct aga_graph *g,
12                                   const struct aga_node *n)
13 {
14         return int2ptr(1);
15 }
16
17 static ptrint_t *error_next_edge(const struct aga_graph *g,
18                                  const struct aga_node *n,
19                                  ptrint_t *edge)
20 {
21         assert(edge == int2ptr(1));
22
23         return NULL;
24 }
25
26 static int error_edge_info(const struct aga_graph *g, const struct aga_node *n,
27                            ptrint_t *edge, struct aga_edge_info *ei)
28 {
29         struct error_graph *eg = container_of(g, struct error_graph, sg.g);
30         int fromindex = n - eg->sg.nodes;
31
32         switch (fromindex) {
33         case 1:
34                 ei->to = &eg->sg.nodes[2];
35                 break;
36
37         case 2:
38                 ei->to = NULL;
39                 break;
40
41         case 3:
42                 ei->to = &eg->sg.nodes[4];
43                 break;
44
45         default:
46                 return -1;
47         }
48
49         return 0;
50 }
51
52 void error_graph_init(struct error_graph *eg)
53 {
54         simple_graph_init(&eg->sg, error_first_edge, error_next_edge,
55                           error_edge_info);
56 }