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
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.
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 ***** */
45 #include "testutil_nss.h"
47 void *plContext
= NULL
;
49 static PKIX_PL_X500Name
*
50 createX500Name(char *asciiName
, PKIX_Boolean expectedToPass
){
52 PKIX_PL_X500Name
*x500Name
= NULL
;
53 PKIX_PL_String
*plString
= NULL
;
57 PKIX_TEST_EXPECT_NO_ERROR
58 (PKIX_PL_String_Create
59 (PKIX_ESCASCII
, asciiName
, 0, &plString
, plContext
));
62 PKIX_TEST_EXPECT_NO_ERROR
63 (PKIX_PL_X500Name_Create
64 (plString
, &x500Name
, plContext
));
66 PKIX_TEST_EXPECT_ERROR
67 (PKIX_PL_X500Name_Create
68 (plString
, &x500Name
, plContext
));
73 PKIX_TEST_DECREF_AC(plString
);
81 createX500Names(char *goodInput
, char *diffInput
, char *diffInputMatch
,
82 PKIX_PL_X500Name
**goodObject
,
83 PKIX_PL_X500Name
**equalObject
,
84 PKIX_PL_X500Name
**diffObject
,
85 PKIX_PL_X500Name
**diffObjectMatch
)
87 char *badAscii
= "cn=yas#sir,ou=labs,o=sun,c=us";
88 PKIX_PL_X500Name
*badObject
= NULL
;
90 subTest("PKIX_PL_X500Name_Create <goodObject>");
91 *goodObject
= createX500Name(goodInput
, PKIX_TRUE
);
93 subTest("PKIX_PL_X500Name_Create <equalObject>");
94 *equalObject
= createX500Name(goodInput
, PKIX_TRUE
);
96 subTest("PKIX_PL_X500Name_Create <diffObject>");
97 *diffObject
= createX500Name(diffInput
, PKIX_TRUE
);
99 subTest("PKIX_PL_X500Name_Create <diffObjectMatch>");
100 *diffObjectMatch
= createX500Name(diffInputMatch
, PKIX_TRUE
);
102 subTest("PKIX_PL_X500Name_Create <negative>");
103 badObject
= createX500Name(badAscii
, PKIX_FALSE
);
106 static void testMatchHelper
107 (PKIX_PL_X500Name
*goodName
, PKIX_PL_X500Name
*otherName
, PKIX_Boolean match
)
109 PKIX_Boolean cmpResult
;
111 PKIX_TEST_STD_VARS();
113 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_X500Name_Match
119 if ((match
&& !cmpResult
) || (!match
&& cmpResult
)){
120 testError("unexpected mismatch");
121 (void) printf("Actual value:\t%d\n", cmpResult
);
122 (void) printf("Expected value:\t%d\n", match
);
132 testMatch(void *goodObject
, void *diffObject
, void *diffObjectMatch
)
134 subTest("PKIX_PL_X500Name_Match <match>");
135 testMatchHelper((PKIX_PL_X500Name
*)diffObject
,
136 (PKIX_PL_X500Name
*)diffObjectMatch
,
139 subTest("PKIX_PL_X500Name_Match <non-match>");
140 testMatchHelper((PKIX_PL_X500Name
*)goodObject
,
141 (PKIX_PL_X500Name
*)diffObject
,
145 static void testDestroy
146 (void *goodObject
, void *equalObject
, void *diffObject
, void *diffObjectMatch
)
148 PKIX_TEST_STD_VARS();
150 subTest("PKIX_PL_X500Name_Destroy");
152 PKIX_TEST_DECREF_BC(goodObject
);
153 PKIX_TEST_DECREF_BC(equalObject
);
154 PKIX_TEST_DECREF_BC(diffObject
);
155 PKIX_TEST_DECREF_BC(diffObjectMatch
);
163 int main(int argc
, char *argv
[]) {
165 PKIX_PL_X500Name
*goodObject
= NULL
;
166 PKIX_PL_X500Name
*equalObject
= NULL
;
167 PKIX_PL_X500Name
*diffObject
= NULL
;
168 PKIX_PL_X500Name
*diffObjectMatch
= NULL
;
169 PKIX_Boolean useArenas
= PKIX_FALSE
;
170 PKIX_UInt32 actualMinorVersion
;
173 /* goodInput is encoded in PKIX_ESCASCII */
174 char *goodInput
= "cn=Strauß,ou=labs,o=sun,c=us";
175 char *diffInput
= "cn=steve,ou=labs,o=sun,c=us";
176 char *diffInputMatch
= "Cn=SteVe,Ou=lABs,o=SUn,c=uS";
177 char *expectedAscii
= "CN=Strauß,OU=labs,O=sun,C=us";
179 PKIX_TEST_STD_VARS();
181 startTests("X500Name");
183 useArenas
= PKIX_TEST_ARENAS_ARG(argv
[1]);
185 PKIX_TEST_EXPECT_NO_ERROR(PKIX_Initialize
186 (PKIX_TRUE
, /* nssInitNeeded */
195 (goodInput
, diffInput
, diffInputMatch
,
196 &goodObject
, &equalObject
, &diffObject
, &diffObjectMatch
);
198 PKIX_TEST_EQ_HASH_TOSTR_DUP
206 testMatch(goodObject
, diffObject
, diffObjectMatch
);
208 testDestroy(goodObject
, equalObject
, diffObject
, diffObjectMatch
);
212 PKIX_Shutdown(plContext
);
216 endTests("X500Name");