harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r488552 - /harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java
Date Tue, 19 Dec 2006 06:45:55 GMT
Author: smishura
Date: Mon Dec 18 22:45:54 2006
New Revision: 488552

URL: http://svn.apache.org/viewvc?view=rev&rev=488552
Log:
Added a separate test case for AlgorithmParameters.init(byte[] params)
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=488552&r1=488551&r2=488552
==============================================================================
--- 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
Mon Dec 18 22:45:54 2006
@@ -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;
 
@@ -197,8 +200,6 @@
 
         ap.init(new byte[6]);
 
-        assertTrue("init() failed", MyAlgorithmParameters.runEngineInit2);
-
         try {
             ap.init(new MyAlgorithmParameterSpec());
             fail("getEncoded(format): No expected InvalidParameterSpecException");
@@ -309,6 +310,73 @@
         assertSame(p, ap.getProvider());
     }
 
+    /**
+     * @tests java.security.AlgorithmParameters#init(byte[])
+     */
+    public void test_init$B() throws Exception {
+
+        //
+        // test: corresponding spi method is invoked
+        //
+        final byte[] enc = new byte[] { 0x02, 0x01, 0x03 };
+
+        MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {
+            protected void engineInit(byte[] params) throws IOException {
+                runEngineInitB$ = true;
+                assertSame(enc, params);
+            }
+        };
+
+        AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p,
+                "algorithm");
+
+        params.init(enc);
+        assertTrue(paramSpi.runEngineInitB$);
+
+        //
+        // test: IOException if already initialized
+        //
+        try {
+            params.init(enc);
+            fail("No expected IOException");
+        } catch (IOException e) {
+            // expected
+        }
+
+        params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
+        params.init(new MyAlgorithmParameterSpec());
+        try {
+            params.init(enc);
+            fail("No expected IOException");
+        } catch (IOException e) {
+            // expected
+        }
+
+        params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
+        params.init(enc, "format");
+        try {
+            params.init(enc);
+            fail("No expected IOException");
+        } catch (IOException e) {
+            // expected
+        }
+
+        //
+        // test: if params is null
+        //
+        paramSpi = new MyAlgorithmParameters() {
+
+            protected void engineInit(byte[] params) throws IOException {
+                runEngineInitB$ = true;
+                assertNull(params); // null is passed to spi-provider
+            }
+        };
+
+        params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
+        params.init((byte[]) null);
+        assertTrue(paramSpi.runEngineInitB$);
+    }
+
 	private void checkUnititialized(AlgorithmParameters ap) {
         assertNull("Unititialized: toString() failed", ap.toString());
 	}
@@ -347,7 +415,7 @@
 
         public static boolean runEngineInit1 = false;
 
-        public static boolean runEngineInit2 = false;
+        public boolean runEngineInitB$ = false;
 
         public static boolean runEngineInit3 = false;
 
@@ -359,7 +427,6 @@
         }
 
         protected void engineInit(byte[] params) throws IOException {
-            runEngineInit2 = true;
         }
 
         protected void engineInit(byte[] params, String format)



Mime
View raw message