OpenDNSSEC-enforcer
1.4.5
Main Page
Data Structures
Files
File List
Globals
enforcer
test
cunit
test_keyword.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008-2009 Nominet UK. All rights reserved.
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
6
* are met:
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
12
*
13
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
23
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
*
25
*/
26
27
/*+
28
* Filename: test_keyword.c - Test Keyword Module
29
*
30
* Description:
31
* This is a short test module to check the functions in the keyword
32
* module.
33
*
34
* The test program makes use of the CUnit framework, as described in
35
* http://cunit.sourceforge.net
36
-*/
37
38
#include <stdlib.h>
39
#include <stdio.h>
40
#include <string.h>
41
#include <time.h>
42
43
#include "CUnit/Basic.h"
44
45
#include "
ksm/ksm.h
"
46
#include "
test_routines.h
"
47
48
49
/*+
50
* Test<type>KeywordConvert - Test Keyword Conversion Code
51
*
52
* Description:
53
* Tests the translation between the keywords and the values
54
* for the different keyword sets.
55
-*/
56
57
static
void
TestAlgorithmKeywordConvert(
void
)
58
{
59
/* Name to value */
60
61
CU_ASSERT_EQUAL(
KSM_ALGORITHM_RSAMD5
,
KsmKeywordAlgorithmNameToValue
(
"rsamd5"
));
62
CU_ASSERT_EQUAL(
KSM_ALGORITHM_RSAMD5
,
KsmKeywordAlgorithmNameToValue
(
"rsamd"
));
63
CU_ASSERT_EQUAL(
KSM_ALGORITHM_RSAMD5
,
KsmKeywordAlgorithmNameToValue
(
"rsam"
));
64
CU_ASSERT_EQUAL(0,
KsmKeywordAlgorithmNameToValue
(
"rsa"
));
65
CU_ASSERT_EQUAL(0,
KsmKeywordAlgorithmNameToValue
(
"rs"
));
66
CU_ASSERT_EQUAL(0,
KsmKeywordAlgorithmNameToValue
(
"r"
));
67
68
CU_ASSERT_EQUAL(
KSM_ALGORITHM_DH
,
KsmKeywordAlgorithmNameToValue
(
"dh"
));
69
CU_ASSERT_EQUAL(0,
KsmKeywordAlgorithmNameToValue
(
"d"
));
70
71
CU_ASSERT_EQUAL(
KSM_ALGORITHM_DSASHA1
,
KsmKeywordAlgorithmNameToValue
(
"dsa"
));
72
/*CU_ASSERT_EQUAL(KSM_ALGORITHM_DSASHA1, KsmKeywordAlgorithmNameToValue("ds"));*/
73
CU_ASSERT_EQUAL(0,
KsmKeywordAlgorithmNameToValue
(
"d"
));
74
75
CU_ASSERT_EQUAL(
KSM_ALGORITHM_RSASHA1
,
KsmKeywordAlgorithmNameToValue
(
"rsasha1"
));
76
/*CU_ASSERT_EQUAL(KSM_ALGORITHM_RSASHA1, KsmKeywordAlgorithmNameToValue("rsasha"));
77
CU_ASSERT_EQUAL(KSM_ALGORITHM_RSASHA1, KsmKeywordAlgorithmNameToValue("rsash"));
78
CU_ASSERT_EQUAL(KSM_ALGORITHM_RSASHA1, KsmKeywordAlgorithmNameToValue("rsas"));*/
79
CU_ASSERT_EQUAL(0,
KsmKeywordAlgorithmNameToValue
(
"rsa"
));
80
CU_ASSERT_EQUAL(0,
KsmKeywordAlgorithmNameToValue
(
"rs"
));
81
CU_ASSERT_EQUAL(0,
KsmKeywordAlgorithmNameToValue
(
"r"
));
82
83
/* add tests for dsa-nsec3-sha1, rsasha1-nsec3-sha1, rsasha256, rsasha512 */
84
85
CU_ASSERT_EQUAL(
KSM_ALGORITHM_INDIRECT
,
KsmKeywordAlgorithmNameToValue
(
"indirect"
));
86
CU_ASSERT_EQUAL(
KSM_ALGORITHM_INDIRECT
,
KsmKeywordAlgorithmNameToValue
(
"indirec"
));
87
CU_ASSERT_EQUAL(
KSM_ALGORITHM_INDIRECT
,
KsmKeywordAlgorithmNameToValue
(
"indire"
));
88
CU_ASSERT_EQUAL(
KSM_ALGORITHM_INDIRECT
,
KsmKeywordAlgorithmNameToValue
(
"indir"
));
89
CU_ASSERT_EQUAL(
KSM_ALGORITHM_INDIRECT
,
KsmKeywordAlgorithmNameToValue
(
"indi"
));
90
CU_ASSERT_EQUAL(
KSM_ALGORITHM_INDIRECT
,
KsmKeywordAlgorithmNameToValue
(
"ind"
));
91
CU_ASSERT_EQUAL(
KSM_ALGORITHM_INDIRECT
,
KsmKeywordAlgorithmNameToValue
(
"in"
));
92
CU_ASSERT_EQUAL(
KSM_ALGORITHM_INDIRECT
,
KsmKeywordAlgorithmNameToValue
(
"i"
));
93
94
CU_ASSERT_EQUAL(
KSM_ALGORITHM_PRIVDOM
,
KsmKeywordAlgorithmNameToValue
(
"domain"
));
95
CU_ASSERT_EQUAL(
KSM_ALGORITHM_PRIVDOM
,
KsmKeywordAlgorithmNameToValue
(
"domai"
));
96
CU_ASSERT_EQUAL(
KSM_ALGORITHM_PRIVDOM
,
KsmKeywordAlgorithmNameToValue
(
"doma"
));
97
CU_ASSERT_EQUAL(
KSM_ALGORITHM_PRIVDOM
,
KsmKeywordAlgorithmNameToValue
(
"dom"
));
98
CU_ASSERT_EQUAL(
KSM_ALGORITHM_PRIVDOM
,
KsmKeywordAlgorithmNameToValue
(
"do"
));
99
CU_ASSERT_EQUAL(0,
KsmKeywordAlgorithmNameToValue
(
"d"
));
100
101
CU_ASSERT_EQUAL(
KSM_ALGORITHM_PRIVOID
,
KsmKeywordAlgorithmNameToValue
(
"oid"
));
102
CU_ASSERT_EQUAL(
KSM_ALGORITHM_PRIVOID
,
KsmKeywordAlgorithmNameToValue
(
"oi"
));
103
CU_ASSERT_EQUAL(
KSM_ALGORITHM_PRIVOID
,
KsmKeywordAlgorithmNameToValue
(
"o"
));
104
105
CU_ASSERT_EQUAL(0,
KsmKeywordAlgorithmNameToValue
(
"xyz"
));
106
CU_ASSERT_EQUAL(0,
KsmKeywordAlgorithmNameToValue
(
""
));
107
CU_ASSERT_EQUAL(0,
KsmKeywordAlgorithmNameToValue
(NULL));
108
109
/* ... and the reverse */
110
111
CU_ASSERT_STRING_EQUAL(
"rsamd5"
,
KsmKeywordAlgorithmValueToName
(
KSM_ALGORITHM_RSAMD5
));
112
CU_ASSERT_STRING_EQUAL(
"dh"
,
KsmKeywordAlgorithmValueToName
(
KSM_ALGORITHM_DH
));
113
CU_ASSERT_STRING_EQUAL(
"dsa"
,
KsmKeywordAlgorithmValueToName
(
KSM_ALGORITHM_DSASHA1
));
114
CU_ASSERT_STRING_EQUAL(
"rsasha1"
,
KsmKeywordAlgorithmValueToName
(
KSM_ALGORITHM_RSASHA1
));
115
CU_ASSERT_STRING_EQUAL(
"indirect"
,
KsmKeywordAlgorithmValueToName
(
KSM_ALGORITHM_INDIRECT
));
116
CU_ASSERT_STRING_EQUAL(
"domain"
,
KsmKeywordAlgorithmValueToName
(
KSM_ALGORITHM_PRIVDOM
));
117
CU_ASSERT_STRING_EQUAL(
"oid"
,
KsmKeywordAlgorithmValueToName
(
KSM_ALGORITHM_PRIVOID
));
118
119
return
;
120
}
121
122
static
void
TestFormatKeywordConvert(
void
)
123
{
124
/* Name to value */
125
126
CU_ASSERT_EQUAL(
KSM_FORMAT_FILE
,
KsmKeywordFormatNameToValue
(
"file"
));
127
CU_ASSERT_EQUAL(
KSM_FORMAT_FILE
,
KsmKeywordFormatNameToValue
(
"fil"
));
128
CU_ASSERT_EQUAL(
KSM_FORMAT_FILE
,
KsmKeywordFormatNameToValue
(
"fi"
));
129
CU_ASSERT_EQUAL(
KSM_FORMAT_FILE
,
KsmKeywordFormatNameToValue
(
"f"
));
130
131
CU_ASSERT_EQUAL(
KSM_FORMAT_HSM
,
KsmKeywordFormatNameToValue
(
"hsm"
));
132
CU_ASSERT_EQUAL(
KSM_FORMAT_HSM
,
KsmKeywordFormatNameToValue
(
"hs"
));
133
CU_ASSERT_EQUAL(
KSM_FORMAT_HSM
,
KsmKeywordFormatNameToValue
(
"h"
));
134
135
CU_ASSERT_EQUAL(
KSM_FORMAT_URI
,
KsmKeywordFormatNameToValue
(
"uri"
));
136
CU_ASSERT_EQUAL(
KSM_FORMAT_URI
,
KsmKeywordFormatNameToValue
(
"ur"
));
137
CU_ASSERT_EQUAL(
KSM_FORMAT_URI
,
KsmKeywordFormatNameToValue
(
"u"
));
138
139
CU_ASSERT_EQUAL(0,
KsmKeywordFormatNameToValue
(
"xyz"
));
140
CU_ASSERT_EQUAL(0,
KsmKeywordFormatNameToValue
(
""
));
141
CU_ASSERT_EQUAL(0,
KsmKeywordFormatNameToValue
(NULL));
142
143
/* ... and the reverse */
144
145
CU_ASSERT_STRING_EQUAL(
"file"
,
KsmKeywordFormatValueToName
(
KSM_FORMAT_FILE
));
146
CU_ASSERT_STRING_EQUAL(
"hsm"
,
KsmKeywordFormatValueToName
(
KSM_FORMAT_HSM
));
147
CU_ASSERT_STRING_EQUAL(
"uri"
,
KsmKeywordFormatValueToName
(
KSM_FORMAT_URI
));
148
149
return
;
150
}
151
152
static
void
TestStateKeywordConvert(
void
)
153
{
154
CU_ASSERT_EQUAL(
KSM_STATE_GENERATE
,
KsmKeywordStateNameToValue
(
"generate"
));
155
CU_ASSERT_EQUAL(
KSM_STATE_GENERATE
,
KsmKeywordStateNameToValue
(
"generat"
));
156
CU_ASSERT_EQUAL(
KSM_STATE_GENERATE
,
KsmKeywordStateNameToValue
(
"genera"
));
157
CU_ASSERT_EQUAL(
KSM_STATE_GENERATE
,
KsmKeywordStateNameToValue
(
"gener"
));
158
CU_ASSERT_EQUAL(
KSM_STATE_GENERATE
,
KsmKeywordStateNameToValue
(
"gene"
));
159
CU_ASSERT_EQUAL(
KSM_STATE_GENERATE
,
KsmKeywordStateNameToValue
(
"gen"
));
160
CU_ASSERT_EQUAL(
KSM_STATE_GENERATE
,
KsmKeywordStateNameToValue
(
"ge"
));
161
CU_ASSERT_EQUAL(
KSM_STATE_GENERATE
,
KsmKeywordStateNameToValue
(
"g"
));
162
163
CU_ASSERT_EQUAL(
KSM_STATE_PUBLISH
,
KsmKeywordStateNameToValue
(
"publish"
));
164
CU_ASSERT_EQUAL(
KSM_STATE_PUBLISH
,
KsmKeywordStateNameToValue
(
"publis"
));
165
CU_ASSERT_EQUAL(
KSM_STATE_PUBLISH
,
KsmKeywordStateNameToValue
(
"publi"
));
166
CU_ASSERT_EQUAL(
KSM_STATE_PUBLISH
,
KsmKeywordStateNameToValue
(
"publ"
));
167
CU_ASSERT_EQUAL(
KSM_STATE_PUBLISH
,
KsmKeywordStateNameToValue
(
"pub"
));
168
CU_ASSERT_EQUAL(
KSM_STATE_PUBLISH
,
KsmKeywordStateNameToValue
(
"pu"
));
169
CU_ASSERT_EQUAL(
KSM_STATE_PUBLISH
,
KsmKeywordStateNameToValue
(
"p"
));
170
171
CU_ASSERT_EQUAL(
KSM_STATE_READY
,
KsmKeywordStateNameToValue
(
"ready"
));
172
CU_ASSERT_EQUAL(
KSM_STATE_READY
,
KsmKeywordStateNameToValue
(
"read"
));
173
CU_ASSERT_EQUAL(
KSM_STATE_READY
,
KsmKeywordStateNameToValue
(
"rea"
));
174
CU_ASSERT_EQUAL(0,
KsmKeywordStateNameToValue
(
"re"
));
/* Confused with "retired" */
175
CU_ASSERT_EQUAL(0,
KsmKeywordStateNameToValue
(
"r"
));
/* Confused with "retired" */
176
177
CU_ASSERT_EQUAL(
KSM_STATE_ACTIVE
,
KsmKeywordStateNameToValue
(
"active"
));
178
CU_ASSERT_EQUAL(
KSM_STATE_ACTIVE
,
KsmKeywordStateNameToValue
(
"activ"
));
179
CU_ASSERT_EQUAL(
KSM_STATE_ACTIVE
,
KsmKeywordStateNameToValue
(
"acti"
));
180
CU_ASSERT_EQUAL(
KSM_STATE_ACTIVE
,
KsmKeywordStateNameToValue
(
"act"
));
181
CU_ASSERT_EQUAL(
KSM_STATE_ACTIVE
,
KsmKeywordStateNameToValue
(
"ac"
));
182
CU_ASSERT_EQUAL(
KSM_STATE_ACTIVE
,
KsmKeywordStateNameToValue
(
"a"
));
183
184
CU_ASSERT_EQUAL(
KSM_STATE_RETIRE
,
KsmKeywordStateNameToValue
(
"retire"
));
185
CU_ASSERT_EQUAL(
KSM_STATE_RETIRE
,
KsmKeywordStateNameToValue
(
"retir"
));
186
CU_ASSERT_EQUAL(
KSM_STATE_RETIRE
,
KsmKeywordStateNameToValue
(
"reti"
));
187
CU_ASSERT_EQUAL(
KSM_STATE_RETIRE
,
KsmKeywordStateNameToValue
(
"ret"
));
188
CU_ASSERT_EQUAL(0,
KsmKeywordStateNameToValue
(
"re"
));
/* Confused with "ready" */
189
CU_ASSERT_EQUAL(0,
KsmKeywordStateNameToValue
(
"r"
));
/* Confused with "ready" */
190
191
CU_ASSERT_EQUAL(
KSM_STATE_DEAD
,
KsmKeywordStateNameToValue
(
"dead"
));
192
CU_ASSERT_EQUAL(
KSM_STATE_DEAD
,
KsmKeywordStateNameToValue
(
"dea"
));
193
CU_ASSERT_EQUAL(
KSM_STATE_DEAD
,
KsmKeywordStateNameToValue
(
"de"
));
194
CU_ASSERT_EQUAL(0,
KsmKeywordStateNameToValue
(
"d"
));
195
196
/* ... and the reverse */
197
198
CU_ASSERT_STRING_EQUAL(
"generate"
,
KsmKeywordStateValueToName
(
KSM_STATE_GENERATE
));
199
CU_ASSERT_STRING_EQUAL(
"publish"
,
KsmKeywordStateValueToName
(
KSM_STATE_PUBLISH
));
200
CU_ASSERT_STRING_EQUAL(
"ready"
,
KsmKeywordStateValueToName
(
KSM_STATE_READY
));
201
CU_ASSERT_STRING_EQUAL(
"active"
,
KsmKeywordStateValueToName
(
KSM_STATE_ACTIVE
));
202
CU_ASSERT_STRING_EQUAL(
"retire"
,
KsmKeywordStateValueToName
(
KSM_STATE_RETIRE
));
203
CU_ASSERT_STRING_EQUAL(
"dead"
,
KsmKeywordStateValueToName
(
KSM_STATE_DEAD
));
204
205
return
;
206
}
207
208
static
void
TestTypeKeywordConvert(
void
)
209
{
210
CU_ASSERT_EQUAL(
KSM_TYPE_KSK
,
KsmKeywordTypeNameToValue
(
"ksk"
));
211
CU_ASSERT_EQUAL(
KSM_TYPE_KSK
,
KsmKeywordTypeNameToValue
(
"ks"
));
212
CU_ASSERT_EQUAL(
KSM_TYPE_KSK
,
KsmKeywordTypeNameToValue
(
"k"
));
213
214
CU_ASSERT_EQUAL(
KSM_TYPE_ZSK
,
KsmKeywordTypeNameToValue
(
"zsk"
));
215
CU_ASSERT_EQUAL(
KSM_TYPE_ZSK
,
KsmKeywordTypeNameToValue
(
"zs"
));
216
CU_ASSERT_EQUAL(
KSM_TYPE_ZSK
,
KsmKeywordTypeNameToValue
(
"z"
));
217
218
/* ... and the reverse */
219
220
CU_ASSERT_STRING_EQUAL(
"ksk"
,
KsmKeywordTypeValueToName
(
KSM_TYPE_KSK
));
221
CU_ASSERT_STRING_EQUAL(
"zsk"
,
KsmKeywordTypeValueToName
(
KSM_TYPE_ZSK
));
222
223
return
;
224
}
225
226
227
228
/*
229
* TestKeyword - Create Test Suite
230
*
231
* Description:
232
* Adds the test suite to the CUnit test registry and adds all the tests
233
* to it.
234
*
235
* Arguments:
236
* None.
237
*
238
* Returns:
239
* int
240
* Return status. 0 => Success.
241
*/
242
243
int
TestKeyword
(
void
);
/* Declaration */
244
int
TestKeyword
(
void
)
245
{
246
struct
test_testdef
tests[] = {
247
{
"AlgorithmKeywordConvert"
, TestAlgorithmKeywordConvert},
248
{
"FormatKeywordConvert"
, TestFormatKeywordConvert},
249
{
"StateKeywordConvert"
, TestStateKeywordConvert},
250
{
"TypeKeywordConvert"
, TestTypeKeywordConvert},
251
{NULL, NULL}
252
};
253
254
return
TcuCreateSuite
(
"Keyword"
, NULL, NULL, tests);
255
}
Generated on Tue Jul 22 2014 00:37:50 for OpenDNSSEC-enforcer by
1.8.1.2