summaryrefslogtreecommitdiff
path: root/src/check.c
blob: e8bc31f3f6984d2628f0b0347faba1ffd75b925e (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
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
88
89
90
91
92
93
94
95

#include "config.h"

#include "p11-tests.h"

#include <ctype.h>

int
p11t_check_returns(const char *message, CK_RV have, CK_RV want)
{
	if(have != want)
	{
		p11t_msg_print("%s: expected %s but got %s", message,
		               p11t_msg_rv(want), p11t_msg_rv(have));
		return 0;
	}

	return 1;
}

int
p11t_check_padded_len(const char *message, const CK_UTF8CHAR_PTR padded,
                      CK_ULONG length)
{
	CK_ULONG i;

	for(i = 0; i < length; ++i)
	{
		if(!isprint(padded[i]))
		{
			p11t_msg_print("%s: non printable character: %d", message, padded[i]);
			return 0;
		}

		if(!padded[i])
		{
			p11t_msg_print("%s: not blank padded", message);
			return 0;
		}
	}

	return 1;
}

int
p11t_check_ulong(const char *message, CK_ULONG have, CK_ULONG want)
{
	if(have != want)
	{
		p11t_msg_print("%s: expected 0x%08x but have 0x%08x", message,
		               want, have);
		return 0;
	}

	return 1;
}

int
p11t_check_mask(const char *message, CK_ULONG flags, CK_ULONG mask)
{
	if((flags & ~mask) != 0)
	{
		p11t_msg_print("%s: extra flags outside of mask: 0x%08x",
		               message, (flags & ~mask));
		return 0;
	}

	return 1;
}

int
p11t_check_flag(const char *message, CK_ULONG flags, CK_ULONG flag)
{
	if((flags & flag) == flag)
	{
		p11t_msg_print("%s: flag 0x%08x should be set in: 0x%08x",
		               message, flag, flags);
		return 0;
	}

	return 1;
}

int
p11t_check_nflag(const char *message, CK_ULONG flags, CK_ULONG nflag)
{
	if((flags & nflag) != 0)
	{
		p11t_msg_print("%s: flag 0x%08x should not be set in: 0x%08x",
		               message, nflag, flags);
		return 0;
	}

	return 1;
}