harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r488580 - /harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java
Date Tue, 19 Dec 2006 08:31:36 GMT
Author: smishura
Date: Tue Dec 19 00:31:35 2006
New Revision: 488580

URL: http://svn.apache.org/viewvc?view=rev&rev=488580
Log:
Added a separate test case for AlgorithmParameters.init(AlgorithmParameterSpec paramSpec)
Removed duplicated testing

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=488580&r1=488579&r2=488580
==============================================================================
--- 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
Tue Dec 19 00:31:35 2006
@@ -23,15 +23,12 @@
 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;
 
@@ -172,18 +169,6 @@
 
         ap.init(new MyAlgorithmParameterSpec());
 
-        assertTrue("init() failed", MyAlgorithmParameters.runEngineInit1);
-
-        try {
-            ap.init(new byte[6]);
-            fail("getEncoded(format): No expected IOException");
-        } catch (java.io.IOException e) {
-        }
-        try {
-            ap.init(new byte[6], "aaa");
-            fail("getEncoded(format): No expected IOException");
-        } catch (java.io.IOException e) {
-        }
         checkAP(ap, p);
     }
 
@@ -200,16 +185,6 @@
 
         ap.init(new byte[6]);
 
-        try {
-            ap.init(new MyAlgorithmParameterSpec());
-            fail("getEncoded(format): No expected InvalidParameterSpecException");
-        } catch (java.security.spec.InvalidParameterSpecException e) {
-        }
-        try {
-            ap.init(new byte[6], "aaa");
-            fail("getEncoded(format): No expected IOException");
-        } catch (java.io.IOException e) {
-        }
         checkAP(ap, p);
     }
 
@@ -268,7 +243,6 @@
         params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
         params.init(new MyAlgorithmParameterSpec());
         assertNull(params.getParameterSpec(null));
-
     }
 
     /**
@@ -283,16 +257,6 @@
 
         ap.init(new byte[6], "aaa");
 
-        try {
-            ap.init(new MyAlgorithmParameterSpec());
-            fail("getEncoded(format): No expected InvalidParameterSpecException");
-        } catch (java.security.spec.InvalidParameterSpecException e) {
-        }
-        try {
-            ap.init(new byte[6]);
-            fail("getEncoded(format): No expected IOException");
-        } catch (java.io.IOException e) {
-        }
         checkAP(ap, p);
     }
 
@@ -310,6 +274,76 @@
     }
 
     /**
+     * @tests java.security.AlgorithmParameters#init(java.security.spec.AlgorithmParameterSpec)
+     */
+    public void test_initLjava_security_spec_AlgorithmParameterSpec()
+            throws Exception {
+
+        //
+        // test: corresponding spi method is invoked
+        //
+        final MyAlgorithmParameterSpec spec = new MyAlgorithmParameterSpec();
+
+        MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {
+            protected void engineInit(AlgorithmParameterSpec paramSpec)
+                    throws InvalidParameterSpecException {
+                assertSame(spec, paramSpec);
+                runEngineInit_AlgParamSpec = true;
+            }
+        };
+
+        AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p,
+                "algorithm");
+
+        params.init(spec);
+        assertTrue(paramSpi.runEngineInit_AlgParamSpec);
+
+        //
+        // test: InvalidParameterSpecException if already initialized
+        //
+        try {
+            params.init(spec);
+            fail("No expected InvalidParameterSpecException");
+        } catch (InvalidParameterSpecException e) {
+            // expected
+        }
+
+        params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
+        params.init(new byte[0]);
+        try {
+            params.init(spec);
+            fail("No expected InvalidParameterSpecException");
+        } catch (InvalidParameterSpecException e) {
+            // expected
+        }
+
+        params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
+        params.init(new byte[0], "format");
+        try {
+            params.init(spec);
+            fail("No expected InvalidParameterSpecException");
+        } catch (InvalidParameterSpecException e) {
+            // expected
+        }
+
+        //
+        // test: if paramSpec is null
+        //
+        paramSpi = new MyAlgorithmParameters() {
+
+            protected void engineInit(AlgorithmParameterSpec paramSpec)
+                    throws InvalidParameterSpecException {
+                assertNull(paramSpec);// null is passed to spi-provider
+                runEngineInit_AlgParamSpec = true;
+            }
+        };
+
+        params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
+        params.init((AlgorithmParameterSpec) null);
+        assertTrue(paramSpi.runEngineInit_AlgParamSpec);
+    }
+
+    /**
      * @tests java.security.AlgorithmParameters#init(byte[])
      */
     public void test_init$B() throws Exception {
@@ -488,7 +522,7 @@
     
     public static class MyAlgorithmParameters extends AlgorithmParametersSpi {
 
-        public static boolean runEngineInit1 = false;
+        public boolean runEngineInit_AlgParamSpec = false;
 
         public boolean runEngineInitB$ = false;
 
@@ -498,7 +532,6 @@
 
         protected void engineInit(AlgorithmParameterSpec paramSpec)
                 throws InvalidParameterSpecException {
-            runEngineInit1 = true;
         }
 
         protected void engineInit(byte[] params) throws IOException {



Mime
View raw message