summaryrefslogtreecommitdiff
path: root/ccan/agar/test/error-graph.c
blob: efd83a37bf0fba6ba27c5007cf9991b8ef379701 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "config.h"

#include <assert.h>

#include <ccan/agar/agar.h>
#include <ccan/container_of/container_of.h>
#include <ccan/ptrint/ptrint.h>

#include "simple-graphr.h"

static const void *error_first_edge_r(const struct agar_graph *gr,
				      const void *nr)
{
	return int2ptr(1);
}

static const void *error_next_edge_r(const struct agar_graph *gr,
				     const void *nr, const void *e)
{
	assert(ptr2int(e) == 1);

	return NULL;
}

static int error_edge_info_r(const struct agar_graph *gr,
			     const void *nr, const void *e,
			     struct agar_edge_info *eir)
{
	int fromindex = ptr2int(nr);

	switch (fromindex) {
	case 1:
		eir->to = int2ptr(2);
		break;

	case 2:
		eir->to = NULL;
		break;

	case 3:
		eir->to = int2ptr(4);
		break;

	default:
		return -1;
	}

	return 0;
}

void error_graphr_init(struct error_graphr *egr)
{
	agar_init_graph(&egr->gr, error_first_edge_r, error_next_edge_r,
			error_edge_info_r);
}