aboutsummaryrefslogtreecommitdiffstats
path: root/librecrypt_next_algorithm.c
blob: b825582f0d36247e1f63fa43e197c866ff3e892f (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
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


extern inline char *librecrypt_next_algorithm(char **hash);


#else


static void
testcase_1(void)
{
	char hash[] = ">a$b>c$d>e$f$";
	char *s = hash, *a;

	EXPECT((a = librecrypt_next_algorithm(&s)));
	EXPECT(s != NULL);
	EXPECT(!strcmp(a, ""));
	EXPECT(!strcmp(s, "a$b>c$d>e$f$"));

	EXPECT((a = librecrypt_next_algorithm(&s)));
	EXPECT(s != NULL);
	EXPECT(!strcmp(a, "a$b"));
	EXPECT(!strcmp(s, "c$d>e$f$"));

	EXPECT((a = librecrypt_next_algorithm(&s)));
	EXPECT(s != NULL);
	EXPECT(!strcmp(a, "c$d"));
	EXPECT(!strcmp(s, "e$f$"));

	EXPECT((a = librecrypt_next_algorithm(&s)));
	EXPECT(s == NULL);
	EXPECT(!strcmp(a, "e$f$"));

	EXPECT(librecrypt_next_algorithm(&s) == NULL);
	EXPECT(s == NULL);
}


static void
testcase_2(void)
{
	char hash[] = "a$b>c$d>e$f$>";
	char *s = hash, *a;

	EXPECT((a = librecrypt_next_algorithm(&s)));
	EXPECT(s != NULL);
	EXPECT(!strcmp(a, "a$b"));
	EXPECT(!strcmp(s, "c$d>e$f$>"));

	EXPECT((a = librecrypt_next_algorithm(&s)));
	EXPECT(s != NULL);
	EXPECT(!strcmp(a, "c$d"));
	EXPECT(!strcmp(s, "e$f$>"));

	EXPECT((a = librecrypt_next_algorithm(&s)));
	EXPECT(s != NULL);
	EXPECT(!strcmp(a, "e$f$"));
	EXPECT(!strcmp(s, ""));

	EXPECT((a = librecrypt_next_algorithm(&s)));
	EXPECT(s == NULL);
	EXPECT(!strcmp(a, ""));

	EXPECT(librecrypt_next_algorithm(&s) == NULL);
	EXPECT(s == NULL);
}


int
main(void)
{
	SET_UP_ALARM();
	testcase_1();
	testcase_2();
	return 0;
}


#endif