harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r393689 - in /incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der: GeneralizedTimeTest.java UTCTimeTest.java
Date Thu, 13 Apr 2006 02:47:07 GMT
Author: smishura
Date: Wed Apr 12 19:47:05 2006
New Revision: 393689

URL: http://svn.apache.org/viewcvs?rev=393689&view=rev
Log:
New test for ASN1UTCTime

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/UTCTimeTest.java
  (with props)
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/GeneralizedTimeTest.java
  (contents, props changed)

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/GeneralizedTimeTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/GeneralizedTimeTest.java?rev=393689&r1=393688&r2=393689&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/GeneralizedTimeTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/GeneralizedTimeTest.java
Wed Apr 12 19:47:05 2006
@@ -1,125 +1,125 @@
-/*
- *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-
-package org.apache.harmony.security.asn1.der;
-
-import java.io.ByteArrayInputStream;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.TimeZone;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.security.asn1.ASN1GeneralizedTime;
-import org.apache.harmony.security.asn1.DerInputStream;
-import org.apache.harmony.security.asn1.DerOutputStream;
-
-/**
- * ASN.1 DER test for GeneralizedTime type
- * 
- * @see http://asn1.elibel.tm.fr/en/standards/index.htm
- */
-
-public class GeneralizedTimeTest extends TestCase {
-
-    // decoder/encoder for testing
-    private static final ASN1GeneralizedTime gtime = ASN1GeneralizedTime
-            .getInstance();
-
-    // data for testing with format: date string/DER encoding/Date object
-    private static final Object[][] validGeneralizedTimes;
-
-    static {
-        SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy HH:mm:ss");
-        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
-
-        validGeneralizedTimes = new Object[][] {
-                // YYYYMMDD-HHMMSS = "19000101000000Z"
-                {
-                        "1 Jan 1900 00:00:00",
-                        new byte[] { 0x18, 0x0F, 0x31, 0x39, 0x30, 0x30, 0x30,
-                                0x31, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30,
-                                0x30, 0x5A }, null },
-                // YYYYMMDD-HHMMSS = "19490203040506Z"
-                {
-                        "3 Feb 1949 04:05:06",
-                        new byte[] { 0x18, 0x0F, 0x31, 0x39, 0x34, 0x39, 0x30,
-                                0x32, 0x30, 0x33, 0x30, 0x34, 0x30, 0x35, 0x30,
-                                0x36, 0x5A }, null },
-                // YYYYMMDD-HHMMSS = "2000708091011Z"
-                {
-                        "8 Jul 2000 09:10:11",
-                        new byte[] { 0x18, 0x0F, 0x32, 0x30, 0x30, 0x30, 0x30,
-                                0x37, 0x30, 0x38, 0x30, 0x39, 0x31, 0x30, 0x31,
-                                0x31, 0x5A }, null },
-                // YYYYMMDD-HHMMSS = "20501213141516Z"
-                {
-                        "13 Dec 2050 14:15:16",
-                        new byte[] { 0x18, 0x0F, 0x32, 0x30, 0x35, 0x30, 0x31,
-                                0x32, 0x31, 0x33, 0x31, 0x34, 0x31, 0x35, 0x31,
-                                0x36, 0x5A }, null }, };
-
-        try {
-            // fill values for Date objects by parsing date string
-            for (int i = 0; i < validGeneralizedTimes.length; i++) {
-                validGeneralizedTimes[i][2] = sdf
-                        .parseObject((String) validGeneralizedTimes[i][0]);
-            }
-        } catch (ParseException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Verifies DER decoding/encoding ASN.1 GeneralizedTime.
-     * GeneralizedTime expresses Greenwich Mean Time by 
-     * the following pattern: YYYYMMDDHHMMSS'Z' 
-     */
-    public void test_Decode_Encode() throws Exception {
-
-        // decoding byte array
-        for (int i = 0; i < validGeneralizedTimes.length; i++) {
-            DerInputStream in = new DerInputStream(
-                    (byte[]) validGeneralizedTimes[i][1]);
-            assertEquals("Decoding array for " + validGeneralizedTimes[i][0],
-                    validGeneralizedTimes[i][2], //expected
-                    gtime.decode(in)); //decoded
-        }
-
-        // decoding input stream
-        for (int i = 0; i < validGeneralizedTimes.length; i++) {
-            DerInputStream in = new DerInputStream(new ByteArrayInputStream(
-                    (byte[]) validGeneralizedTimes[i][1]));
-            assertEquals("Decoding stream for " + validGeneralizedTimes[i][0],
-                    validGeneralizedTimes[i][2], //expected
-                    gtime.decode(in)); //decoded
-        }
-
-        // encoding date object
-        for (int i = 0; i < validGeneralizedTimes.length; i++) {
-            DerOutputStream out = new DerOutputStream(gtime,
-                    validGeneralizedTimes[i][2]);
-            assertTrue("Encoding date for " + validGeneralizedTimes[i][0],
-                    Arrays.equals((byte[]) validGeneralizedTimes[i][1], // expected
-                            out.encoded)); //encoded
-        }
-    }
-
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(GeneralizedTimeTest.class);
-    }
-}
+/*
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.security.asn1.der;
+
+import java.io.ByteArrayInputStream;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.TimeZone;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.security.asn1.ASN1GeneralizedTime;
+import org.apache.harmony.security.asn1.DerInputStream;
+import org.apache.harmony.security.asn1.DerOutputStream;
+
+/**
+ * ASN.1 DER test for GeneralizedTime type
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public class GeneralizedTimeTest extends TestCase {
+
+    // decoder/encoder for testing
+    private static final ASN1GeneralizedTime gtime = ASN1GeneralizedTime
+            .getInstance();
+
+    // data for testing with format: date string/DER encoding/Date object
+    private static final Object[][] validGeneralizedTimes;
+
+    static {
+        SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy HH:mm:ss");
+        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
+
+        validGeneralizedTimes = new Object[][] {
+                // YYYYMMDD-HHMMSS = "19000101000000Z"
+                {
+                        "1 Jan 1900 00:00:00",
+                        new byte[] { 0x18, 0x0F, 0x31, 0x39, 0x30, 0x30, 0x30,
+                                0x31, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30,
+                                0x30, 0x5A }, null },
+                // YYYYMMDD-HHMMSS = "19490203040506Z"
+                {
+                        "3 Feb 1949 04:05:06",
+                        new byte[] { 0x18, 0x0F, 0x31, 0x39, 0x34, 0x39, 0x30,
+                                0x32, 0x30, 0x33, 0x30, 0x34, 0x30, 0x35, 0x30,
+                                0x36, 0x5A }, null },
+                // YYYYMMDD-HHMMSS = "2000708091011Z"
+                {
+                        "8 Jul 2000 09:10:11",
+                        new byte[] { 0x18, 0x0F, 0x32, 0x30, 0x30, 0x30, 0x30,
+                                0x37, 0x30, 0x38, 0x30, 0x39, 0x31, 0x30, 0x31,
+                                0x31, 0x5A }, null },
+                // YYYYMMDD-HHMMSS = "20501213141516Z"
+                {
+                        "13 Dec 2050 14:15:16",
+                        new byte[] { 0x18, 0x0F, 0x32, 0x30, 0x35, 0x30, 0x31,
+                                0x32, 0x31, 0x33, 0x31, 0x34, 0x31, 0x35, 0x31,
+                                0x36, 0x5A }, null }, };
+
+        try {
+            // fill values for Date objects by parsing date string
+            for (int i = 0; i < validGeneralizedTimes.length; i++) {
+                validGeneralizedTimes[i][2] = sdf
+                        .parseObject((String) validGeneralizedTimes[i][0]);
+            }
+        } catch (ParseException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * Verifies DER decoding/encoding ASN.1 GeneralizedTime.
+     * GeneralizedTime expresses Greenwich Mean Time by 
+     * the following pattern: YYYYMMDDHHMMSS'Z' 
+     */
+    public void test_Decode_Encode() throws Exception {
+
+        // decoding byte array
+        for (int i = 0; i < validGeneralizedTimes.length; i++) {
+            DerInputStream in = new DerInputStream(
+                    (byte[]) validGeneralizedTimes[i][1]);
+            assertEquals("Decoding array for " + validGeneralizedTimes[i][0],
+                    validGeneralizedTimes[i][2], //expected
+                    gtime.decode(in)); //decoded
+        }
+
+        // decoding input stream
+        for (int i = 0; i < validGeneralizedTimes.length; i++) {
+            DerInputStream in = new DerInputStream(new ByteArrayInputStream(
+                    (byte[]) validGeneralizedTimes[i][1]));
+            assertEquals("Decoding stream for " + validGeneralizedTimes[i][0],
+                    validGeneralizedTimes[i][2], //expected
+                    gtime.decode(in)); //decoded
+        }
+
+        // encoding date object
+        for (int i = 0; i < validGeneralizedTimes.length; i++) {
+            DerOutputStream out = new DerOutputStream(gtime,
+                    validGeneralizedTimes[i][2]);
+            assertTrue("Encoding date for " + validGeneralizedTimes[i][0],
+                    Arrays.equals((byte[]) validGeneralizedTimes[i][1], // expected
+                            out.encoded)); //encoded
+        }
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(GeneralizedTimeTest.class);
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/GeneralizedTimeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/UTCTimeTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/UTCTimeTest.java?rev=393689&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/UTCTimeTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/UTCTimeTest.java
Wed Apr 12 19:47:05 2006
@@ -0,0 +1,126 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.security.asn1.der;
+
+import java.io.ByteArrayInputStream;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.TimeZone;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.security.asn1.ASN1UTCTime;
+import org.apache.harmony.security.asn1.DerInputStream;
+import org.apache.harmony.security.asn1.DerOutputStream;
+
+/**
+ * ASN.1 DER test for UTCTime type
+ * 
+ * @see http://asn1.elibel.tm.fr/en/standards/index.htm
+ */
+
+public class UTCTimeTest extends TestCase {
+
+    // UTC time decoder/encoder for testing
+    private static final ASN1UTCTime utime = ASN1UTCTime.getInstance();
+
+    // data for testing with format: date string/DER encoding/Date object
+    public static final Object[][] validUTCTimes;
+
+    static {
+        SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy HH:mm:ss");
+        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
+
+        validUTCTimes = new Object[][] {
+                // YYMMDD-HHMMSS = "500708091011Z"
+                {
+                        "8 Jul 1950 09:10:11",
+                        new byte[] { 0x17, 0x0D, 0x35, 0x30, 0x30, 0x37, 0x30,
+                                0x38, 0x30, 0x39, 0x31, 0x30, 0x31, 0x31, 0x5A },
+                        null },
+                //YYMMDD-HHMMSS = "991213141516Z"
+                {
+                        "13 Dec 1999 14:15:16",
+                        new byte[] { 0x17, 0x0D, 0x39, 0x39, 0x31, 0x32, 0x31,
+                                0x33, 0x31, 0x34, 0x31, 0x35, 0x31, 0x36, 0x5A },
+                        null },
+                // YYMMDD-HHMMSS = "000101000000Z"
+                {
+                        "01 Jan 2000 00:00:00",
+                        new byte[] { 0x17, 0x0D, 0x30, 0x30, 0x30, 0x31, 0x30,
+                                0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5A },
+                        null },
+                // YYMMDD-HHMMSS = "490203040506Z"
+// FIXME test case fails
+//                {
+//                        "3 Feb 2049 04:05:06",
+//                        new byte[] { 0x17, 0x0D, 0x34, 0x39, 0x30, 0x32, 0x30,
+//                                0x33, 0x30, 0x34, 0x30, 0x35, 0x30, 0x36, 0x5A },
+//                        null },
+                        };
+
+        try {
+            // fill values for Date objects by parsing date string
+            for (int i = 0; i < validUTCTimes.length; i++) {
+                validUTCTimes[i][2] = sdf
+                        .parseObject((String) validUTCTimes[i][0]);
+            }
+        } catch (ParseException e) {
+            throw new RuntimeException(e.getMessage());
+        }
+    }
+
+    /**
+     * Verifies decoding/encoding ASN.1 UTCTime.
+     * It must interpret the year field (YY) as follows:
+     *  - if YY is greater than or equal to 50 then interpreted as 19YY
+     *  - and if YY is less than 50 then interpreted as 20YY.
+     */
+    public void testDecodeEncode() throws Exception {
+
+        // decoding byte array
+        for (int i = 0; i < validUTCTimes.length; i++) {
+            DerInputStream in = new DerInputStream((byte[]) validUTCTimes[i][1]);
+            assertEquals("Decoding array for " + validUTCTimes[i][0],
+                    validUTCTimes[i][2], //expected
+                    utime.decode(in)); //decoded
+        }
+
+        // decoding input stream
+        for (int i = 0; i < validUTCTimes.length; i++) {
+            DerInputStream in = new DerInputStream(new ByteArrayInputStream(
+                    (byte[]) validUTCTimes[i][1]));
+            assertEquals("Decoding stream for " + validUTCTimes[i][0],
+                    validUTCTimes[i][2], //expected
+                    utime.decode(in)); //decoded
+        }
+
+        // encoding date object
+        for (int i = 0; i < validUTCTimes.length; i++) {
+            DerOutputStream out = new DerOutputStream(utime,
+                    validUTCTimes[i][2]);
+            assertTrue("Encoding date for " + validUTCTimes[i][0], Arrays
+                    .equals((byte[]) validUTCTimes[i][1], // expected
+                            out.encoded)); //encoded
+        }
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(UTCTimeTest.class);
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/org/apache/harmony/security/asn1/der/UTCTimeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message