summaryrefslogtreecommitdiff
path: root/tests/hash.c
blob: b3c2aadfaec5fce01291246ae3045bf5af42fb38 (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
#include "../src/hash.c"

#include <stdlib.h>

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



static void
test_HASH_OUTPUT_LENGTH(void) {
	test_start("HASH_OUTPUT_LENGTH");

	{
		testing("Enforce we're always consistent with SipHash");

		assert((int)HASH_OUTPUT_LENGTH == (int)SIPHASH_OUTPUT_LENGTH);

		test_ok();
	}
}

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

	test_start("hash_setup()");

	{
		testing("SEED_INITIALIZED changes after calling hash_setup()");

		assert(SEED_INITIALIZED == false);

		if (hash_setup()) {
			logerr("hash_setup()");
			goto out;
		}
		assert(SEED_INITIALIZED == true);

		test_ok();
	}

	rc = 0;
out:
	return rc;
}

int
main(void) {
	int rc = EXIT_FAILURE;

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

	test_HASH_OUTPUT_LENGTH();

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

	rc = EXIT_SUCCESS;
out:
	if (random_end()) {
		if (rc == EXIT_SUCCESS) {
			rc = EXIT_FAILURE;
		}
	}

	return rc;
}