diff options
author | Sergio Giro <sgiro@google.com> | 2016-02-01 14:37:23 +0000 |
---|---|---|
committer | Sergio Giro <sgiro@google.com> | 2016-02-01 15:16:12 +0000 |
commit | 397d32894b89b506dc318e0f83446187c9b76ebe (patch) | |
tree | 8229ff72c8cbb06f49dce3a8382930919fa6fc2b /bcprov/src/main/java/org/bouncycastle/asn1/test/UTCTimeTest.java | |
parent | 9b30eb05e5be69d51881a0d1b31e503e97acd784 (diff) | |
parent | 6d876f3f0ae553704a1dcf7e89003fcf14717037 (diff) | |
download | android_external_bouncycastle-397d32894b89b506dc318e0f83446187c9b76ebe.tar.gz android_external_bouncycastle-397d32894b89b506dc318e0f83446187c9b76ebe.tar.bz2 android_external_bouncycastle-397d32894b89b506dc318e0f83446187c9b76ebe.zip |
Merge remote-tracking branch 'aosp/upstream-master' into merge-152-from-upstream
As to set a common ancestor for future merges from aosp/upstream-master
(when updating to new versions of bouncycastle).
We'll override all the changes of this commit with patch
https://android-review.googlesource.com/#/c/199872
Change-Id: I53a7f797b520a6e119878dbae53246cdcc585ddf
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/asn1/test/UTCTimeTest.java')
-rw-r--r-- | bcprov/src/main/java/org/bouncycastle/asn1/test/UTCTimeTest.java | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/asn1/test/UTCTimeTest.java b/bcprov/src/main/java/org/bouncycastle/asn1/test/UTCTimeTest.java new file mode 100644 index 0000000..8067e78 --- /dev/null +++ b/bcprov/src/main/java/org/bouncycastle/asn1/test/UTCTimeTest.java @@ -0,0 +1,108 @@ +package org.bouncycastle.asn1.test; + +import org.bouncycastle.asn1.DERUTCTime; +import org.bouncycastle.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()); + } +} |