PageRenderTime 33ms CodeModel.GetById 12ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/security/nss/cmd/libpkix/pkix/results/test_verifynode.c

http://github.com/zpao/v8monkey
C | 153 lines | 77 code | 31 blank | 45 comment | 1 complexity | 48b4e668266a66792bbedc2c0b87193c MD5 | raw file
  1/* ***** BEGIN LICENSE BLOCK *****
  2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3 *
  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/
  8 *
  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.
 13 *
 14 * The Original Code is the PKIX-C library.
 15 *
 16 * The Initial Developer of the Original Code is
 17 * Sun Microsystems, Inc.
 18 * Portions created by the Initial Developer are
 19 * Copyright 2004-2007 Sun Microsystems, Inc.  All Rights Reserved.
 20 *
 21 * Contributor(s):
 22 *   Sun Microsystems, Inc.
 23 *
 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.
 35 *
 36 * ***** END LICENSE BLOCK ***** */
 37/*
 38 * test_verifynode.c
 39 *
 40 * Test VerifyNode Type
 41 *
 42 */
 43
 44#include "testutil.h"
 45#include "testutil_nss.h"
 46
 47static void *plContext =  NULL;
 48
 49static
 50void printUsage(void) {
 51        (void) printf("\nUSAGE:\ttest_verifynode path cert1 cert2 cert3\n\n");
 52}
 53
 54int test_verifynode(int argc, char *argv[]) {
 55
 56        /*
 57         * Create a tree with parent = cert1, child=cert2, grandchild=cert3
 58         */
 59        PKIX_PL_Cert *cert1 = NULL;
 60        PKIX_PL_Cert *cert2 = NULL;
 61	PKIX_PL_Cert *cert3 = NULL;
 62        PKIX_VerifyNode *parentNode = NULL;
 63        PKIX_VerifyNode *childNode = NULL;
 64        PKIX_VerifyNode *grandChildNode = NULL;
 65        PKIX_PL_String *parentString = NULL;
 66
 67        PKIX_UInt32 actualMinorVersion;
 68        PKIX_UInt32 j = 0;
 69        char *dirName = NULL;
 70	char *twoNodeAscii = "CERT[Issuer:CN=Trust Anchor,O=Test Cert"
 71		"ificates,C=US, Subject:CN=Trust Anchor,O=Test Certif"
 72		"icates,C=US], depth=0, error=(null)\n. CERT[Issuer:C"
 73		"N=Trust Anchor,O=Test Certificates,C=US, Subject:CN="
 74		"Good CA,O=Test Certificates,C=US], depth=1, error=(null)";
 75	char *threeNodeAscii = "CERT[Issuer:CN=Trust Anchor,O=Test Ce"
 76		"rtificates,C=US, Subject:CN=Trust Anchor,O=Test Cert"
 77		"ificates,C=US], depth=0, error=(null)\n. CERT[Issuer"
 78		":CN=Trust Anchor,O=Test Certificates,C=US, Subject:C"
 79		"N=Good CA,O=Test Certificates,C=US], depth=1, error="
 80		"(null)\n. . CERT[Issuer:CN=Good CA,O=Test Certificat"
 81		"es,C=US, Subject:CN=Valid EE Certificate Test1,O=Tes"
 82		"t Certificates,C=US], depth=2, error=(null)";
 83
 84        PKIX_TEST_STD_VARS();
 85
 86        if (argc < 3) {
 87                printUsage();
 88                return (0);
 89        }
 90
 91        startTests("VerifyNode");
 92
 93        PKIX_TEST_EXPECT_NO_ERROR(
 94            PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));
 95
 96        dirName = argv[++j];
 97
 98        subTest("Creating Certs");
 99
100        cert1 = createCert
101                (dirName, argv[++j], plContext);
102
103        cert2 = createCert
104                (dirName, argv[++j], plContext);
105
106        cert3 = createCert
107                (dirName, argv[++j], plContext);
108
109        subTest("Creating VerifyNode objects");
110
111        PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_Create
112		(cert1, 0, NULL, &parentNode, plContext));
113
114        PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_Create
115		(cert2, 1, NULL, &childNode, plContext));
116
117        PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_Create
118		(cert3, 2, NULL, &grandChildNode, plContext));
119
120        PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_AddToChain
121		(parentNode, childNode, plContext));
122
123        subTest("Creating VerifyNode ToString objects");
124
125	testToStringHelper
126		((PKIX_PL_Object *)parentNode, twoNodeAscii, plContext);
127
128        PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_AddToChain
129		(parentNode, grandChildNode, plContext));
130
131        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString
132                ((PKIX_PL_Object*)parentNode, &parentString, plContext));
133        (void) printf("parentNode is\n\t%s\n", parentString->escAsciiString);
134
135	testToStringHelper
136		((PKIX_PL_Object *)parentNode, threeNodeAscii, plContext);
137
138cleanup:
139
140        PKIX_TEST_DECREF_AC(cert1);
141        PKIX_TEST_DECREF_AC(cert2);
142        PKIX_TEST_DECREF_AC(parentNode);
143        PKIX_TEST_DECREF_AC(childNode);
144        PKIX_TEST_DECREF_AC(parentString);
145
146        PKIX_Shutdown(plContext);
147
148        PKIX_TEST_RETURN();
149
150        endTests("VerifyNode");
151
152        return (0);
153}