summaryrefslogtreecommitdiffstats
path: root/security/nss/cmd/libpkix/pkix_pl/pki/test_date.c
blob: 4fb3718c199deae400184c58c6e2749787e5a5dc (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
/* 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_date.c
 *
 * Test Date Type
 *
 */

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

static void *plContext = NULL;

static void
createDates(char *goodInput, char *diffInput,
            PKIX_PL_Date **goodDate,
            PKIX_PL_Date **equalDate,
            PKIX_PL_Date **diffDate)
{

    subTest("PKIX_PL_Date_Create <goodDate>");
    *goodDate = createDate(goodInput, plContext);

    subTest("PKIX_PL_Date_Create <equalDate>");
    *equalDate = createDate(goodInput, plContext);

    subTest("PKIX_PL_Date_Create <diffDate>");
    *diffDate = createDate(diffInput, plContext);
}

static void
testDestroy(void *goodObject, void *equalObject, void *diffObject)
{
    PKIX_TEST_STD_VARS();

    subTest("PKIX_PL_Date_Destroy");

    PKIX_TEST_DECREF_BC(goodObject);
    PKIX_TEST_DECREF_BC(equalObject);
    PKIX_TEST_DECREF_BC(diffObject);

cleanup:

    PKIX_TEST_RETURN();
}

static void
testDate(char *goodInput, char *diffInput)
{

    PKIX_PL_Date *goodDate = NULL;
    PKIX_PL_Date *equalDate = NULL;
    PKIX_PL_Date *diffDate = NULL;

    /*
         * The ASCII rep of the date will vary by platform and locale
         * This particular string was generated on a SPARC running Solaris 9
         * in an English locale
         */
    /* char *expectedAscii = "Mon Mar 29 08:48:47 2004"; */
    char *expectedAscii = "Mon Mar 29, 2004";

    PKIX_TEST_STD_VARS();

    createDates(goodInput, diffInput,
                &goodDate, &equalDate, &diffDate);

    PKIX_TEST_EQ_HASH_TOSTR_DUP(goodDate, equalDate, diffDate, expectedAscii, Date, PKIX_TRUE);

    testDestroy(goodDate, equalDate, diffDate);

    PKIX_TEST_RETURN();
}

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

    char *goodInput = NULL;
    char *diffInput = NULL;
    PKIX_UInt32 actualMinorVersion;
    PKIX_UInt32 j = 0;

    PKIX_TEST_STD_VARS();

    startTests("Date");

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

    goodInput = "040329134847Z";
    diffInput = "050329135847Z";
    testDate(goodInput, diffInput);

cleanup:

    PKIX_Shutdown(plContext);

    PKIX_TEST_RETURN();

    endTests("Date");

    return (0);
}