Import from 1.9a8 tarball
[mozilla-nss.git] / security / nss / cmd / libpkix / pkix / crlsel / test_comcrlselparams.c
blob1c5133df3ca4a79add8d72628cf88cb6cfce84c3
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Sun Microsystems
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 * test_comcrlselparams.c
40 * Test ComCRLSelParams Type
44 #include "testutil.h"
45 #include "testutil_nss.h"
47 void *plContext = NULL;
49 static void
50 testIssuer(PKIX_ComCRLSelParams *goodObject)
52 PKIX_PL_String *issuer1String = NULL;
53 PKIX_PL_String *issuer2String = NULL;
54 PKIX_PL_String *issuer3String = NULL;
55 PKIX_PL_X500Name *issuerName1 = NULL;
56 PKIX_PL_X500Name *issuerName2 = NULL;
57 PKIX_PL_X500Name *issuerName3 = NULL;
58 PKIX_List *setIssuerList = NULL;
59 PKIX_List *getIssuerList = NULL;
60 PKIX_PL_String *issuerListString = NULL;
61 char *name1 = "CN=yassir,OU=bcn,OU=east,O=sun,C=us";
62 char *name2 = "CN=richard,OU=bcn,OU=east,O=sun,C=us";
63 char *name3 = "CN=hanfei,OU=bcn,OU=east,O=sun,C=us";
64 PKIX_Int32 length;
65 PKIX_Boolean result = PKIX_FALSE;
66 char *expectedAscii =
67 "(CN=yassir,OU=bcn,OU=east,O=sun,"
68 "C=us, CN=richard,OU=bcn,OU=east,O=sun,C=us, "
69 "CN=hanfei,OU=bcn,OU=east,O=sun,C=us)";
71 PKIX_TEST_STD_VARS();
73 subTest("PKIX_ComCRLSelParams Create Issuers");
75 length = PL_strlen(name1);
77 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create
78 (PKIX_UTF8,
79 name1,
80 length,
81 &issuer1String,
82 plContext));
84 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_X500Name_Create(issuer1String,
85 &issuerName1,
86 plContext));
88 length = PL_strlen(name2);
90 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create
91 (PKIX_UTF8,
92 name2,
93 length,
94 &issuer2String,
95 plContext));
97 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_X500Name_Create(issuer2String,
98 &issuerName2,
99 plContext));
101 length = PL_strlen(name3);
103 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create
104 (PKIX_UTF8,
105 name3,
106 length,
107 &issuer3String,
108 plContext));
110 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_X500Name_Create
111 (issuer3String,
112 &issuerName3,
113 plContext));
115 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_Create(&setIssuerList, plContext));
117 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem
118 (setIssuerList,
119 (PKIX_PL_Object *)issuerName1,
120 plContext));
122 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem
123 (setIssuerList,
124 (PKIX_PL_Object *)issuerName2,
125 plContext));
127 subTest("PKIX_ComCRLSelParams_AddIssuerName");
129 /* Test adding an issuer to an empty list */
130 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_AddIssuerName
131 (goodObject, issuerName3, plContext));
133 subTest("PKIX_ComCRLSelParams_GetIssuerNames");
135 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_GetIssuerNames
136 (goodObject, &getIssuerList, plContext));
138 /* DECREF for GetIssuerNames */
139 PKIX_TEST_DECREF_BC(getIssuerList);
140 /* DECREF for AddIssuerName so next SetIssuerName start clean */
141 PKIX_TEST_DECREF_BC(getIssuerList);
143 /* Test setting issuer names on the list */
144 subTest("PKIX_ComCRLSelParams_SetIssuerNames");
146 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_SetIssuerNames
147 (goodObject, setIssuerList, plContext));
149 subTest("PKIX_ComCRLSelParams_GetIssuerNames");
151 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_GetIssuerNames
152 (goodObject, &getIssuerList, plContext));
154 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals
155 ((PKIX_PL_Object *)setIssuerList,
156 (PKIX_PL_Object *)getIssuerList,
157 &result,
158 plContext));
160 if (result != PKIX_TRUE) {
161 pkixTestErrorMsg = "unexpected Issuers mismatch";
164 /* Test adding an issuer to existing list */
165 subTest("PKIX_ComCRLSelParams_AddIssuerName");
167 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_AddIssuerName
168 (goodObject, issuerName3, plContext));
170 subTest("PKIX_ComCRLSelParams_GetIssuerNames");
171 PKIX_TEST_DECREF_BC(getIssuerList);
173 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_GetIssuerNames
174 (goodObject, &getIssuerList, plContext));
177 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString
178 ((PKIX_PL_Object *)getIssuerList,
179 &issuerListString,
180 plContext));
182 testToStringHelper((PKIX_PL_Object *)getIssuerList,
183 expectedAscii, plContext);
185 cleanup:
187 PKIX_TEST_DECREF_AC(issuer1String);
188 PKIX_TEST_DECREF_AC(issuer2String);
189 PKIX_TEST_DECREF_AC(issuer3String);
190 PKIX_TEST_DECREF_AC(issuerListString);
191 PKIX_TEST_DECREF_AC(issuerName1);
192 PKIX_TEST_DECREF_AC(issuerName2);
193 PKIX_TEST_DECREF_AC(issuerName3);
194 PKIX_TEST_DECREF_AC(setIssuerList);
195 PKIX_TEST_DECREF_AC(getIssuerList);
197 PKIX_TEST_RETURN();
201 void testCertificateChecking(
202 char *dataCentralDir,
203 char *goodInput,
204 PKIX_ComCRLSelParams *goodObject)
206 PKIX_PL_Cert *setCert = NULL;
207 PKIX_PL_Cert *getCert = NULL;
208 PKIX_Boolean result = PKIX_FALSE;
210 PKIX_TEST_STD_VARS();
212 subTest("Test CertificateChecking Cert Create");
213 setCert = createCert(dataCentralDir, goodInput, plContext);
214 if (setCert == NULL) {
215 pkixTestErrorMsg = "create certificate failed";
216 goto cleanup;
219 subTest("PKIX_ComCRLSelParams_SetCertificateChecking");
221 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_SetCertificateChecking
222 (goodObject, setCert, plContext));
224 subTest("PKIX_ComCRLSelParams_GetCertificateChecking");
226 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_GetCertificateChecking
227 (goodObject, &getCert, plContext));
229 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals
230 ((PKIX_PL_Object *)setCert,
231 (PKIX_PL_Object *)getCert,
232 &result, plContext));
234 if (result != PKIX_TRUE) {
235 pkixTestErrorMsg = "unexpected Cert mismatch";
238 cleanup:
240 PKIX_TEST_DECREF_AC(setCert);
241 PKIX_TEST_DECREF_AC(getCert);
243 PKIX_TEST_RETURN();
246 void testDateAndTime(PKIX_ComCRLSelParams *goodObject){
248 PKIX_PL_Date *setDate = NULL;
249 PKIX_PL_Date *getDate = NULL;
250 char *asciiDate = "040329134847Z";
251 PKIX_Boolean result = PKIX_FALSE;
253 PKIX_TEST_STD_VARS();
255 subTest("PKIX_ComCRLSelParams_Date Create");
256 setDate = createDate(asciiDate, plContext);
258 subTest("PKIX_ComCRLSelParams_SetDateAndTime");
259 PKIX_TEST_EXPECT_NO_ERROR
260 (PKIX_ComCRLSelParams_SetDateAndTime
261 (goodObject, setDate, plContext));
263 subTest("PKIX_ComCRLSelParams_GetDateAndTime");
264 PKIX_TEST_EXPECT_NO_ERROR
265 (PKIX_ComCRLSelParams_GetDateAndTime
266 (goodObject, &getDate, plContext));
268 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals
269 ((PKIX_PL_Object *)setDate,
270 (PKIX_PL_Object *)getDate,
271 &result, plContext));
273 if (result != PKIX_TRUE) {
274 pkixTestErrorMsg = "unexpected DateAndTime mismatch";
277 cleanup:
279 PKIX_TEST_DECREF_AC(setDate);
280 PKIX_TEST_DECREF_AC(getDate);
282 PKIX_TEST_RETURN();
285 void testMaxMinCRLNumbers(PKIX_ComCRLSelParams *goodObject){
286 PKIX_PL_BigInt *setMaxCrlNumber = NULL;
287 PKIX_PL_BigInt *getMaxCrlNumber = NULL;
288 PKIX_PL_BigInt *setMinCrlNumber = NULL;
289 PKIX_PL_BigInt *getMinCrlNumber = NULL;
290 char *asciiCrlNumber1 = "01";
291 char *asciiCrlNumber99999 = "0909090909";
292 PKIX_PL_String *crlNumber1String = NULL;
293 PKIX_PL_String *crlNumber99999String = NULL;
295 PKIX_Boolean result = PKIX_FALSE;
297 PKIX_TEST_STD_VARS();
299 subTest("PKIX_ComCRLSelParams_SetMinCRLNumber");
301 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create
302 (PKIX_ESCASCII,
303 asciiCrlNumber1,
304 PL_strlen(asciiCrlNumber1),
305 &crlNumber1String,
306 NULL));
308 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_BigInt_Create
309 (crlNumber1String, &setMinCrlNumber, NULL));
311 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_SetMinCRLNumber
312 (goodObject, setMinCrlNumber, NULL));
314 subTest("PKIX_ComCRLSelParams_GetMinCRLNumber");
316 PKIX_TEST_EXPECT_NO_ERROR
317 (PKIX_ComCRLSelParams_GetMinCRLNumber
318 (goodObject, &getMinCrlNumber, NULL));
320 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals
321 ((PKIX_PL_Object *)setMinCrlNumber,
322 (PKIX_PL_Object *)getMinCrlNumber,
323 &result, NULL));
325 if (result != PKIX_TRUE) {
326 pkixTestErrorMsg = "unexpected Minimum CRL Number mismatch";
329 subTest("PKIX_ComCRLSelParams_SetMaxCRLNumber");
331 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create
332 (PKIX_ESCASCII,
333 asciiCrlNumber99999,
334 PL_strlen(asciiCrlNumber99999),
335 &crlNumber99999String,
336 NULL));
338 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_BigInt_Create
339 (crlNumber99999String, &setMaxCrlNumber, NULL));
341 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_SetMaxCRLNumber
342 (goodObject, setMaxCrlNumber, NULL));
344 subTest("PKIX_ComCRLSelParams_GetMaxCRLNumber");
346 PKIX_TEST_EXPECT_NO_ERROR
347 (PKIX_ComCRLSelParams_GetMaxCRLNumber
348 (goodObject, &getMaxCrlNumber, NULL));
350 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals
351 ((PKIX_PL_Object *)setMaxCrlNumber,
352 (PKIX_PL_Object *)getMaxCrlNumber,
353 &result, NULL));
355 if (result != PKIX_TRUE) {
356 pkixTestErrorMsg = "unexpected Maximum CRL Number mismatch";
359 cleanup:
361 PKIX_TEST_DECREF_AC(setMaxCrlNumber);
362 PKIX_TEST_DECREF_AC(getMaxCrlNumber);
363 PKIX_TEST_DECREF_AC(setMinCrlNumber);
364 PKIX_TEST_DECREF_AC(getMinCrlNumber);
365 PKIX_TEST_DECREF_AC(crlNumber1String);
366 PKIX_TEST_DECREF_AC(crlNumber99999String);
368 PKIX_TEST_RETURN();
371 void testDuplicate(PKIX_ComCRLSelParams *goodObject){
373 PKIX_ComCRLSelParams *dupObject = NULL;
374 PKIX_Boolean result = PKIX_FALSE;
376 PKIX_TEST_STD_VARS();
378 subTest("PKIX_ComCRLSelParams_Duplicate");
379 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Duplicate
380 ((PKIX_PL_Object *)goodObject,
381 (PKIX_PL_Object **)&dupObject,
382 plContext));
384 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_Equals
385 ((PKIX_PL_Object *)goodObject,
386 (PKIX_PL_Object *)dupObject,
387 &result, plContext));
389 if (result != PKIX_TRUE) {
390 pkixTestErrorMsg =
391 "unexpected Duplicate ComCRLSelParams mismatch";
394 cleanup:
396 PKIX_TEST_DECREF_AC(dupObject);
397 PKIX_TEST_RETURN();
400 void printUsage(char *pName){
401 printf("\nUSAGE: %s <central-data-dir>\n\n", pName);
404 /* Functional tests for ComCRLSelParams public functions */
406 int main(int argc, char *argv[]){
408 char *dataCentralDir = NULL;
409 char *goodInput = "yassir2yassir";
410 PKIX_ComCRLSelParams *goodObject = NULL;
411 PKIX_ComCRLSelParams *diffObject = NULL;
412 PKIX_UInt32 actualMinorVersion;
413 PKIX_UInt32 j = 0;
414 PKIX_Boolean useArenas = PKIX_FALSE;
416 PKIX_TEST_STD_VARS();
418 startTests("ComCRLSelParams");
420 useArenas = PKIX_TEST_ARENAS_ARG(argv[1]);
422 PKIX_TEST_EXPECT_NO_ERROR(PKIX_Initialize
423 (PKIX_TRUE, /* nssInitNeeded */
424 useArenas,
425 PKIX_MAJOR_VERSION,
426 PKIX_MINOR_VERSION,
427 PKIX_MINOR_VERSION,
428 &actualMinorVersion,
429 &plContext));
431 if (argc < 2){
432 printUsage(argv[0]);
433 return (0);
436 dataCentralDir = argv[j+1];
438 subTest("PKIX_ComCRLSelParams_Create");
440 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_Create
441 (&goodObject,
442 plContext));
444 PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_Create
445 (&diffObject,
446 plContext));
448 testIssuer(goodObject);
450 testCertificateChecking(dataCentralDir, goodInput, goodObject);
452 testDateAndTime(goodObject);
454 testMaxMinCRLNumbers(goodObject);
456 testDuplicate(goodObject);
458 PKIX_TEST_EQ_HASH_TOSTR_DUP
459 (goodObject,
460 goodObject,
461 diffObject,
462 NULL,
463 ComCRLSelParams,
464 PKIX_TRUE);
466 cleanup:
468 PKIX_TEST_DECREF_AC(goodObject);
469 PKIX_TEST_DECREF_AC(diffObject);
471 PKIX_Shutdown(plContext);
473 PKIX_TEST_RETURN();
475 endTests("ComCRLSelParams");
477 return (0);