]> git.ozlabs.org Git - ccan/blob - ccan/agar/test/error-graph.c
agar: Add static graph initializer
[ccan] / ccan / agar / test / error-graph.c
1 #include "config.h"
2
3 #include <assert.h>
4
5 #include <ccan/agar/agar.h>
6 #include <ccan/container_of/container_of.h>
7 #include <ccan/ptrint/ptrint.h>
8
9 #include "simple-graphr.h"
10
11 static const void *error_first_edge_r(const struct agar_graph *gr,
12                                       const void *nr)
13 {
14         return int2ptr(1);
15 }
16
17 static const void *error_next_edge_r(const struct agar_graph *gr,
18                                      const void *nr, const void *e)
19 {
20         assert(ptr2int(e) == 1);
21
22         return NULL;
23 }
24
25 static int error_edge_info_r(const struct agar_graph *gr,
26                              const void *nr, const void *e,
27                              struct agar_edge_info *eir)
28 {
29         int fromindex = ptr2int(nr);
30
31         switch (fromindex) {
32         case 1:
33                 eir->to = int2ptr(2);
34                 break;
35
36         case 2:
37                 eir->to = NULL;
38                 break;
39
40         case 3:
41                 eir->to = int2ptr(4);
42                 break;
43
44         default:
45                 return -1;
46         }
47
48         return 0;
49 }
50
51 struct error_graphr error_graphr = {
52         AGAR_INIT_GRAPH(error_first_edge_r, error_next_edge_r,
53                         error_edge_info_r),
54 };