harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r497735 - in /harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security: AlgorithmParameters2Test.java AlgorithmParametersTest.java
Date Fri, 19 Jan 2007 08:22:07 GMT
Author: smishura
Date: Fri Jan 19 00:22:06 2007
New Revision: 497735

URL: http://svn.apache.org/viewvc?view=rev&rev=497735
Log:
Merge tests for DSA provider into one test case

Removed:
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParameters2Test.java
Modified:
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java?view=diff&rev=497735&r1=497734&r2=497735
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java
Fri Jan 19 00:22:06 2007
@@ -23,12 +23,15 @@
 package org.apache.harmony.security.tests.java.security;
 
 import java.io.IOException;
+import java.math.BigInteger;
 import java.security.AlgorithmParameters;
 import java.security.AlgorithmParametersSpi;
 import java.security.Provider;
 import java.security.Security;
 import java.security.spec.AlgorithmParameterSpec;
+import java.security.spec.DSAParameterSpec;
 import java.security.spec.InvalidParameterSpecException;
+import java.util.Arrays;
 
 import junit.framework.TestCase;
 
@@ -512,6 +515,53 @@
         assertSame(str, params.toString());
     }
 
+    /**
+     * Tests DSA AlgorithmParameters provider
+     */
+    public void testDSAProvider() throws Exception {
+        AlgorithmParameters params = AlgorithmParameters.getInstance("DSA");
+
+        assertEquals("Algorithm", "DSA", params.getAlgorithm());
+
+        // init(AlgorithmParameterSpec)
+        BigInteger p = BigInteger.ONE;
+        BigInteger q = BigInteger.TEN;
+        BigInteger g = BigInteger.ZERO;
+        params.init(new DSAParameterSpec(p, q, g));
+
+        // getEncoded() and getEncoded(String) (TODO verify returned encoding)
+        byte[] enc = params.getEncoded();
+        assertNotNull(enc);
+        assertNotNull(params.getEncoded("ASN.1"));
+        // TODO assertNotNull(params.getEncoded(null)); // HARMONY-2680
+
+        // getParameterSpec(Class)
+        DSAParameterSpec spec = params.getParameterSpec(DSAParameterSpec.class);
+        assertEquals("p is wrong ", p, spec.getP());
+        assertEquals("q is wrong ", q, spec.getQ());
+        assertEquals("g is wrong ", g, spec.getG());
+
+        // init(byte[])
+        params = AlgorithmParameters.getInstance("DSA");
+        params.init(enc);
+        assertTrue("param encoded is different", Arrays.equals(enc, params
+                .getEncoded()));
+
+        // init(byte[], String)
+        params = AlgorithmParameters.getInstance("DSA");
+        params.init(enc, "ASN.1");
+        assertTrue("param encoded is different", Arrays.equals(enc, params
+                .getEncoded()));
+
+        params = AlgorithmParameters.getInstance("DSA");
+        try {
+            params.init(enc, "DOUGLASMAWSON");
+            fail("unsupported format should have raised IOException");
+        } catch (Exception e) {
+            // expected
+        }
+    }
+    
 	private void checkUnititialized(AlgorithmParameters ap) {
         assertNull("Uninitialized: toString() failed", ap.toString());
 	}



Mime
View raw message