summaryrefslogtreecommitdiff
path: root/tests/set.c
blob: e00a253f56cb153198ed804dab67a3b74c8cf82c (plain) (blame)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "../src/set.c"

#include "../src/testing.h"



static int
test_set_new(void) {
	int rc = -1;

	const struct Set *s = NULL;

	test_start("set_new()");
	{
		testing("simple allocation");

		const size_t size = sizeof(long long);
		if (set_new(size, &s)) {
			logerr("set_new()");
			goto out;
		}

		assert(s->value_size == size);

		set_free(&s);

		test_ok();
	}

	rc = 0;
out:
	if (s != NULL) {
		set_free(&s);
	}
	return rc;
}

static int
test_set_free(void) {
	int rc = -1;

	const struct Set *s = NULL;

	test_start("set_free()");
	{
		testing("*s becomes NULL again after set_free(&s)");

		assert(s == NULL);
		if (set_new(1U, &s)) {
			logerr("set_new()");
			goto out;
		}

		assert(s != NULL);
		set_free(&s);
		assert(s == NULL);

		test_ok();
	}

	rc = 0;
out:
	if (s != NULL) {
		set_free(&s);
	}
	return rc;
}


int
main(void) {
	int rc = EXIT_FAILURE;

	if (test_set_new()) {
		logerr("test_set_new()");
		goto out;
	}

	if (test_set_free()) {
		logerr("test_set_free()");
		goto out;
	}

	rc = EXIT_SUCCESS;
out:
	return rc;
}