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