summaryrefslogtreecommitdiffstats
path: root/security/nss/cmd/libpkix/pkix/crlsel/test_crlselector.c
blob: f17406be5dc670a6412ff83ef416065378dd1c07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
 * test_crlselector.c
 *
 * Test CRLSelector Type
 *
 */

#include "testutil.h"
#include "testutil_nss.h"

static void *plContext = NULL;

static void
testGetMatchCallback(PKIX_CRLSelector *goodObject)
{
    PKIX_CRLSelector_MatchCallback mCallback = NULL;

    PKIX_TEST_STD_VARS();

    subTest("testGetMatchCallback");

    PKIX_TEST_EXPECT_NO_ERROR(PKIX_CRLSelector_GetMatchCallback(goodObject, &mCallback, plContext));

    if (mCallback == NULL) {
        pkixTestErrorMsg = "MatchCallback is NULL";
    }

cleanup:

    PKIX_TEST_RETURN();
}

static void
testGetCRLSelectorContext(PKIX_CRLSelector *goodObject)
{
    PKIX_PL_Object *context = NULL;

    PKIX_TEST_STD_VARS();

    subTest("testGetCRLSelectorContext");

    PKIX_TEST_EXPECT_NO_ERROR(PKIX_CRLSelector_GetCRLSelectorContext(goodObject, (void *)&context, plContext));

    if (context == NULL) {
        pkixTestErrorMsg = "CRLSelectorContext is NULL";
    }

cleanup:

    PKIX_TEST_DECREF_AC(context);
    PKIX_TEST_RETURN();
}

static void
testCommonCRLSelectorParams(PKIX_CRLSelector *goodObject)
{
    PKIX_ComCRLSelParams *setParams = NULL;
    PKIX_ComCRLSelParams *getParams = NULL;
    PKIX_PL_Date *setDate = NULL;
    char *asciiDate = "040329134847Z";

    PKIX_TEST_STD_VARS();

    subTest("PKIX_ComCRLSelParams_Create");
    PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_Create(&setParams,
                                                          plContext));

    subTest("PKIX_ComCRLSelParams_Date Create");

    setDate = createDate(asciiDate, plContext);

    subTest("PKIX_ComCRLSelParams_SetDateAndTime");

    PKIX_TEST_EXPECT_NO_ERROR(PKIX_ComCRLSelParams_SetDateAndTime(setParams, setDate, plContext));

    subTest("PKIX_CRLSelector_SetCommonCRLSelectorParams");

    PKIX_TEST_EXPECT_NO_ERROR(PKIX_CRLSelector_SetCommonCRLSelectorParams(
        goodObject, setParams, plContext));

    subTest("PKIX_CRLSelector_GetCommonCRLSelectorParams");

    PKIX_TEST_EXPECT_NO_ERROR(PKIX_CRLSelector_GetCommonCRLSelectorParams(
        goodObject, &getParams, plContext));

    testEqualsHelper((PKIX_PL_Object *)setParams,
                     (PKIX_PL_Object *)getParams,
                     PKIX_TRUE,
                     plContext);

    testHashcodeHelper((PKIX_PL_Object *)setParams,
                       (PKIX_PL_Object *)getParams,
                       PKIX_TRUE,
                       plContext);

cleanup:

    PKIX_TEST_DECREF_AC(setDate);
    PKIX_TEST_DECREF_AC(setParams);
    PKIX_TEST_DECREF_AC(getParams);

    PKIX_TEST_RETURN();
}

/* Functional tests for CRLSelector public functions */

int
test_crlselector(int argc, char *argv[])
{

    PKIX_PL_Date *context = NULL;
    PKIX_CRLSelector *goodObject = NULL;
    PKIX_CRLSelector *diffObject = NULL;
    PKIX_UInt32 actualMinorVersion;
    PKIX_UInt32 j = 0;
    char *asciiDate = "040329134847Z";

    PKIX_TEST_STD_VARS();

    startTests("CRLSelector");

    PKIX_TEST_EXPECT_NO_ERROR(
        PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));

    context = createDate(asciiDate, plContext);

    subTest("PKIX_CRLSelector_Create");

    PKIX_TEST_EXPECT_NO_ERROR(PKIX_CRLSelector_Create(NULL,
                                                      (PKIX_PL_Object *)context,
                                                      &goodObject,
                                                      plContext));

    PKIX_TEST_EXPECT_NO_ERROR(PKIX_CRLSelector_Create(NULL,
                                                      (PKIX_PL_Object *)context,
                                                      &diffObject,
                                                      plContext));

    testGetMatchCallback(goodObject);

    testGetCRLSelectorContext(goodObject);

    testCommonCRLSelectorParams(goodObject);

    PKIX_TEST_EQ_HASH_TOSTR_DUP(goodObject,
                                goodObject,
                                diffObject,
                                NULL,
                                CRLSelector,
                                PKIX_TRUE);

cleanup:

    PKIX_TEST_DECREF_AC(goodObject);
    PKIX_TEST_DECREF_AC(diffObject);
    PKIX_TEST_DECREF_AC(context);

    PKIX_Shutdown(plContext);

    PKIX_TEST_RETURN();

    endTests("CRLSelector");

    return (0);
}