Welcome to mirror list, hosted at ThFree Co, Russian Federation.

UTCTimeTest.java « test « asn1 « spongycastle « org « java « test « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b28fb0e383e212f7439288fdf9049252cc604222 (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
package org.spongycastle.asn1.test;

import org.spongycastle.asn1.DERUTCTime;
import org.spongycastle.util.test.SimpleTest;

import java.text.SimpleDateFormat;
import java.util.SimpleTimeZone;

/**
 * X.690 test example
 */
public class UTCTimeTest
    extends SimpleTest
{
    String[] input =
        {
            "020122122220Z",
            "020122122220-1000",
            "020122122220+1000",
            "020122122220+00",
            "0201221222Z",
            "0201221222-1000",
            "0201221222+1000",
            "0201221222+00",
            "550122122220Z",
            "5501221222Z"
        };

    String[] output = {
            "20020122122220GMT+00:00",
            "20020122122220GMT-10:00",
            "20020122122220GMT+10:00",
            "20020122122220GMT+00:00",
            "20020122122200GMT+00:00",
            "20020122122200GMT-10:00",
            "20020122122200GMT+10:00",
            "20020122122200GMT+00:00",
            "19550122122220GMT+00:00",
            "19550122122200GMT+00:00"
             };

    String[] zOutput1 = {
            "20020122122220Z",
            "20020122222220Z",
            "20020122022220Z",
            "20020122122220Z",
            "20020122122200Z",
            "20020122222200Z",
            "20020122022200Z",
            "20020122122200Z",
            "19550122122220Z",
            "19550122122200Z"
    };

    String[] zOutput2 = {
            "20020122122220Z",
            "20020122222220Z",
            "20020122022220Z",
            "20020122122220Z",
            "20020122122200Z",
            "20020122222200Z",
            "20020122022200Z",
            "20020122122200Z",
            "19550122122220Z",
            "19550122122200Z"
    };

    public String getName()
    {
        return "UTCTime";
    }

    public void performTest()
        throws Exception
    {
        SimpleDateFormat yyyyF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
        SimpleDateFormat yyF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");

        yyyyF.setTimeZone(new SimpleTimeZone(0,"Z"));
        yyF.setTimeZone(new SimpleTimeZone(0,"Z"));

        for (int i = 0; i != input.length; i++)
        {
            DERUTCTime t = new DERUTCTime(input[i]);

            if (!t.getAdjustedTime().equals(output[i]))
            {
                fail("failed conversion test " + i);
            }

            if (!yyyyF.format(t.getAdjustedDate()).equals(zOutput1[i]))
            {
                fail("failed date conversion test " + i);
            }

            if (!yyF.format(t.getDate()).equals(zOutput2[i]))
            {
                fail("failed date shortened conversion test " + i);
            }
        }
    }

    public static void main(
        String[]    args)
    {
        runTest(new UTCTimeTest());
    }
}