harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r407748 [3/3] - in /incubator/harmony/enhanced/classlib/trunk/modules/crypto: make/common/ src/test/api/ src/test/api/java.injected/ src/test/api/java.injected/javax/ src/test/api/java.injected/javax/crypto/ src/test/api/java.injected/javax...
Date Fri, 19 May 2006 08:45:05 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/Cipher_ImplTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/Cipher_ImplTest.java?rev=407748&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/Cipher_ImplTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/Cipher_ImplTest.java Fri May 19 01:44:59 2006
@@ -0,0 +1,477 @@
+/*
+ *  Copyright 2005 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.
+ */
+/**
+* @author Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package javax.crypto;
+
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.Security;
+import java.security.spec.InvalidKeySpecException;
+
+import org.apache.harmony.security.support.TestKeyPair;
+
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for <code>Cipher</code> class constructors and methods.
+ * 
+ */
+public class Cipher_ImplTest extends TestCase {
+
+	private Provider p1;
+	private Provider p2;
+	private TestKeyPair tkp = null;
+	private Key key = null;
+	
+	private boolean noKey = false;
+	
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		p1 = new MyProvider1();
+		p2 = new MyProvider2();
+		Security.insertProviderAt(p1, 1);
+		Security.insertProviderAt(p2, 1);
+		try {
+			tkp = new TestKeyPair("DSA");
+		} catch (NoSuchAlgorithmException e) {
+			e.printStackTrace();
+			noKey = true;
+			return;
+		}
+		
+		try {
+			key = tkp.getPrivate();
+		} catch (InvalidKeySpecException e) {
+			e.printStackTrace();
+			noKey = true;
+			return;
+		}
+
+	}
+
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		Security.removeProvider("MyProvider1");
+		Security.removeProvider("MyProvider2");
+	}
+
+	/*
+	 * Class under test for Cipher getInstance(String)
+	 */
+	public void testGetInstanceString1() throws NoSuchAlgorithmException,
+            NoSuchPaddingException {
+		
+		Cipher c = Cipher.getInstance("DES");
+		assertSame(p2, c.getProvider());
+	}
+
+	/*
+	 * Class under test for Cipher getInstance(String)
+	 */
+	public void testGetInstanceString2() throws NoSuchAlgorithmException,
+            NoSuchPaddingException {
+		
+		Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding");
+		assertSame("Case1:", p1, c.getProvider());
+
+		Security.removeProvider(p1.getName());
+
+		c = Cipher.getInstance("DES/CBC/PKCS5Padding");
+		assertSame("Case2:", p2, c.getProvider());
+	}
+
+	/*
+	 * Class under test for Cipher getInstance(String)
+	 */
+	public void testGetInstanceString3() throws NoSuchAlgorithmException,
+            NoSuchPaddingException {
+		
+		try {
+			Cipher.getInstance("DES/CBC/");
+			fail("Case1: No expected NoSuchAlgorithmException");
+		} catch (NoSuchAlgorithmException e) {
+		}
+
+		try {
+			Cipher.getInstance("DES//PKCS5Padding");
+			fail("Case2: No expected NoSuchAlgorithmException");
+		} catch (NoSuchAlgorithmException e) {
+		}
+
+		try {
+			Cipher.getInstance("DES/CBC/IncorrectPadding");
+			fail("No expected NoSuchPaddingException");
+		} catch (NoSuchPaddingException e) {
+		}
+	}	
+
+	
+	/*
+	 * Class under test for Cipher getInstance(String, String)
+	 */
+	public void testGetInstanceStringString1() throws NoSuchAlgorithmException,
+            NoSuchProviderException, NoSuchPaddingException {
+
+		try {
+			Cipher.getInstance("DES/CBC/", "MyProvider2");
+			fail("Case1: No expected NoSuchAlgorithmException");
+		} catch (NoSuchAlgorithmException e) {
+		}
+
+		try {
+			Cipher.getInstance("DES//PKCS5Padding", "MyProvider2");
+			fail("Case2: No expected NoSuchAlgorithmException");
+		} catch (NoSuchAlgorithmException e) {
+		}
+
+		try {
+			Cipher.getInstance("DES/CBC/IncorrectPadding", "MyProvider2");
+			fail("No expected NoSuchPaddingException");
+		} catch (NoSuchPaddingException e) {
+		}
+		
+		try {
+			Cipher.getInstance("DES/CBC/PKCS5Padding", "IncorrectProvider");
+			fail("No expected NoSuchProviderException");
+		} catch (NoSuchProviderException e) {
+		}		
+	}
+
+	/*
+	 * Class under test for Cipher getInstance(String, String)
+	 */
+	public void testGetInstanceStringString2() throws NoSuchAlgorithmException,
+            NoSuchProviderException, NoSuchPaddingException {
+
+		Cipher c = Cipher.getInstance("DES", "MyProvider2");
+		assertSame("Case1:", p2, c.getProvider());
+		
+		c = Cipher.getInstance("DES/CBC/PKCS5Padding", "MyProvider2");
+		assertSame("Case2:", p2, c.getProvider());
+	}
+	/*
+	 * Class under test for Cipher getInstance(String, Provider)
+	 */
+	public void testGetInstanceStringProvider1()
+            throws NoSuchAlgorithmException, NoSuchPaddingException {
+
+		try {
+			Cipher.getInstance("DES/CBC/", p2);
+			fail("Case1: No expected NoSuchAlgorithmException");
+		} catch (NoSuchAlgorithmException e) {
+		}
+
+		try {
+			Cipher.getInstance("DES//PKCS5Padding", p2);
+			fail("Case2: No expected NoSuchAlgorithmException");
+		} catch (NoSuchAlgorithmException e) {
+		}
+
+		try {
+			Cipher.getInstance("DES/CBC/IncorrectPadding", p2);
+			fail("No expected NoSuchProviderException");
+		} catch (NoSuchPaddingException e) {
+		}
+		
+		try {
+			Cipher.getInstance("DES/CBC/PKCS5Padding", "IncorrectProvider");
+			fail("No expected NoSuchProviderException");
+		} catch (NoSuchProviderException e) {
+		}		
+	}
+
+	/*
+	 * Class under test for Cipher getInstance(String, Provider)
+	 */
+	public void testGetInstanceStringProvider2()
+            throws NoSuchAlgorithmException, NoSuchPaddingException {
+
+		Cipher c = Cipher.getInstance("DES", p2);
+		assertSame("Case1:", p2, c.getProvider());
+		
+		c = Cipher.getInstance("DES/CBC/PKCS5Padding", p2);
+		assertSame("Case2:", p2, c.getProvider());
+		assertFalse("getAlgorithm", "DES".equals(c.getAlgorithm()));
+	}
+
+	public void testGetBlockSize() throws NoSuchAlgorithmException,
+            NoSuchPaddingException {
+
+		Cipher c = Cipher.getInstance("DES");
+		assertEquals("getBlockSize", 111, c.getBlockSize());
+	}
+
+	public void testGetOutputSize() throws NoSuchAlgorithmException,
+            NoSuchPaddingException, InvalidKeyException {
+
+		Cipher c = Cipher.getInstance("DES");
+		try {
+			c.getOutputSize(111);
+			fail("No expected IllegalStateException");
+		} catch (IllegalStateException e){
+		}
+
+		if (noKey) {
+			return;
+		}
+
+		c.init(Cipher.DECRYPT_MODE, key);
+		assertEquals("getOutputSize", 121, c.getOutputSize(111));
+	}
+
+	public void testGetIV() throws NoSuchAlgorithmException,
+            NoSuchPaddingException {
+
+		Cipher c = Cipher.getInstance("DES");
+		assertEquals(3, c.getIV().length);
+	}
+
+	public void testGetParameters() throws NoSuchAlgorithmException,
+            NoSuchPaddingException {
+
+		Cipher c = Cipher.getInstance("DES");
+		assertNull(c.getParameters());
+	}
+
+	public void testGetExemptionMechanism() {
+//FIXME implement testGetExemptionMechanism
+	}
+
+	/*
+	 * Class under test for void init(int, Key)
+	 */
+	public void testInitintKey() {
+	}
+
+	/*
+	 * Class under test for void init(int, Key, SecureRandom)
+	 */
+	public void testInitintKeySecureRandom() {
+	}
+
+	/*
+	 * Class under test for void init(int, Key, AlgorithmParameterSpec)
+	 */
+	public void testInitintKeyAlgorithmParameterSpec() {
+	}
+
+	/*
+	 * Class under test for void init(int, Key, AlgorithmParameterSpec, SecureRandom)
+	 */
+	public void testInitintKeyAlgorithmParameterSpecSecureRandom() {
+	}
+
+	/*
+	 * Class under test for void init(int, Key, AlgorithmParameters)
+	 */
+	public void testInitintKeyAlgorithmParameters() {
+	}
+
+	/*
+	 * Class under test for void init(int, Key, AlgorithmParameters, SecureRandom)
+	 */
+	public void testInitintKeyAlgorithmParametersSecureRandom() {
+	}
+
+	/*
+	 * Class under test for void init(int, Certificate)
+	 */
+	public void testInitintCertificate() {
+	}
+
+	/*
+	 * Class under test for void init(int, Certificate, SecureRandom)
+	 */
+	public void testInitintCertificateSecureRandom() {
+	}
+
+	/*
+	 * Class under test for byte[] update(byte[])
+	 */
+	public void testUpdatebyteArray() throws NoSuchAlgorithmException,
+            NoSuchPaddingException, InvalidKeyException {
+
+		Cipher c = Cipher.getInstance("DES");
+
+		byte[] b = {1,2,3,4};
+		try {
+			c.update(b);
+			fail("No expected IllegalStateException");
+		} catch (IllegalStateException e){
+		}
+		if (noKey) {
+			return;
+		}
+
+		c.init(Cipher.DECRYPT_MODE, key);
+		try {
+			c.update(null);
+			fail("No expected IllegalArgumentException");
+		} catch (IllegalArgumentException e){
+		}
+		assertNull(c.update(new byte[0]));
+	}
+
+	/*
+	 * Class under test for byte[] update(byte[], int, int)
+	 */
+	public void testUpdatebyteArrayintint() {
+	}
+
+	/*
+	 * Class under test for int update(byte[], int, int, byte[])
+	 */
+	public void testUpdatebyteArrayintintbyteArray() {
+	}
+
+	/*
+	 * Class under test for int update(byte[], int, int, byte[], int)
+	 */
+	public void testUpdatebyteArrayintintbyteArrayint() {
+//		try {
+//			spi.engineUpdate(b, 3, 6, b1, 5);
+//			fail("No expected ShortBufferException");
+//		} catch (ShortBufferException e) {
+//		}
+	}
+
+	/*
+	 * Class under test for int update(ByteBuffer, ByteBuffer)
+	 */
+	public void testUpdateByteBufferByteBuffer() {
+	}
+
+	/*
+	 * Class under test for byte[] doFinal()
+	 */
+	public void testDoFinal() {
+	}
+
+	/*
+	 * Class under test for int doFinal(byte[], int)
+	 */
+	public void testDoFinalbyteArrayint() {
+	}
+
+	/*
+	 * Class under test for byte[] doFinal(byte[])
+	 */
+	public void testDoFinalbyteArray() {
+	}
+
+	/*
+	 * Class under test for byte[] doFinal(byte[], int, int)
+	 */
+	public void testDoFinalbyteArrayintint() {
+	}
+
+	/*
+	 * Class under test for int doFinal(byte[], int, int, byte[])
+	 */
+	public void testDoFinalbyteArrayintintbyteArray() {
+	}
+
+	/*
+	 * Class under test for int doFinal(byte[], int, int, byte[], int)
+	 */
+	public void testDoFinalbyteArrayintintbyteArrayint() {
+//		try {
+//			spi.engineDoFinal(b, 3, 6, b1, 5);
+//			fail("No expected ShortBufferException");
+//		} catch (ShortBufferException e) {
+//		} catch (Exception e) {
+//			fail(e.toString());
+//		}
+	}
+
+	/*
+	 * Class under test for int doFinal(ByteBuffer, ByteBuffer)
+	 */
+	public void testDoFinalByteBufferByteBuffer() {
+	}
+
+	public void testWrap() {
+	}
+
+	public void testUnwrap() {
+	}
+
+	public void testGetMaxAllowedKeyLength() throws NoSuchAlgorithmException {
+		try {
+			Cipher.getMaxAllowedKeyLength(null);
+			fail("No expected NullPointerException");
+		} catch (NullPointerException e) {
+		}
+		try {
+			Cipher.getMaxAllowedKeyLength("//CBC/PKCS5Paddin");
+			fail("No expected NoSuchAlgorithmException");
+		} catch (NoSuchAlgorithmException e) {
+		}
+		try {
+			Cipher.getMaxAllowedKeyLength("/DES/CBC/PKCS5Paddin/1");
+			fail("No expected NoSuchAlgorithmException");
+		} catch (NoSuchAlgorithmException e) {
+		}
+	}
+
+	public void testGetMaxAllowedParameterSpec()
+            throws NoSuchAlgorithmException {
+		try {
+			Cipher.getMaxAllowedParameterSpec(null);
+			fail("No expected NullPointerException");
+		} catch (NullPointerException e) {
+		}
+		try {
+			Cipher.getMaxAllowedParameterSpec("/DES//PKCS5Paddin");
+			fail("No expected NoSuchAlgorithmException");
+		} catch (NoSuchAlgorithmException e) {
+		}
+		try {
+			Cipher.getMaxAllowedParameterSpec("/DES/CBC/ /1");
+			fail("No expected NoSuchAlgorithmException");
+		} catch (NoSuchAlgorithmException e) {
+		}
+	}
+	
+	private class MyProvider1 extends Provider {
+		MyProvider1() {
+			super("MyProvider1", 1.0, "Provider1 for testing");
+			put("Cipher.DES/CBC/PKCS5Padding", "org.apache.harmony.crypto.tests.support.MyCipher");
+			put("Cipher.DES/ECB/PKCS5Padding", "org.apache.harmony.crypto.tests.support.MyCipher");
+		}	
+	}
+	private class MyProvider2 extends Provider {
+		MyProvider2() {
+			super("MyProvider2", 1.0, "Provider2 for testing");
+			put("Cipher.DES", "org.apache.harmony.crypto.tests.support.MyCipher");
+		}	
+		
+	}
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/KeyAgreement_ImplTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/KeyAgreement_ImplTest.java?rev=407748&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/KeyAgreement_ImplTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/KeyAgreement_ImplTest.java Fri May 19 01:44:59 2006
@@ -0,0 +1,271 @@
+/*
+ *  Copyright 2005 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.
+ */
+
+/**
+* @author Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package javax.crypto;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.spec.AlgorithmParameterSpec;
+import java.security.spec.InvalidKeySpecException;
+
+import org.apache.harmony.security.SpiEngUtils;
+import junit.framework.TestCase;
+
+
+/**
+ * Tests for KeyAgreement class constructors and methods
+ * 
+ */
+
+public class KeyAgreement_ImplTest extends TestCase {
+    
+    private static final String srvKeyAgreement = "KeyAgreement";
+
+    private static final String defaultAlg = "MyKeyAgr";
+    
+    private static final String KeyAgreementProviderClass = "org.apache.harmony.crypto.tests.support.MyKeyAgreementSpi";
+
+    private static final String[] invalidValues = SpiEngUtils.invalidValues;
+
+    private static final String[] validValues;
+
+    static {
+        validValues = new String[4];
+        validValues[0] = defaultAlg;
+        validValues[1] = defaultAlg.toLowerCase();
+        validValues[2] = "myKeyagr";
+        validValues[3] = "mYkeYAGR";
+    }
+
+    Provider mProv;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        mProv = (new SpiEngUtils()).new MyProvider("MyKAProvider", "Testing provider", 
+                srvKeyAgreement.concat(".").concat(defaultAlg), 
+                KeyAgreementProviderClass);
+        Security.insertProviderAt(mProv, 1);
+    }
+    
+    /**
+     * @see TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        Security.removeProvider(mProv.getName());
+    }
+
+    /**
+     * Constructor for SecurityManagerFactoryTest2.
+     * 
+     * @param arg0
+     */
+    public KeyAgreement_ImplTest(String arg0) {
+        super(arg0);
+    }
+    
+    protected void checkResult(KeyAgreement keyAgr) 
+            throws InvalidKeyException, ShortBufferException, 
+            NoSuchAlgorithmException, IllegalStateException,
+            InvalidAlgorithmParameterException {
+        assertNull("Not null result", keyAgr.doPhase(null, true));
+        try {
+            keyAgr.doPhase(null, false);
+            fail("IllegalStateException must be thrown");
+        } catch (IllegalStateException e) {
+        }
+        byte[] bb = keyAgr.generateSecret();
+        assertEquals("Length is not 0", bb.length, 0);        
+        assertEquals("Returned integer is not 0", 
+                keyAgr.generateSecret(new byte[1], 10), 
+                -1);
+        assertNull("Not null result", keyAgr.generateSecret("aaa"));
+        try {
+            keyAgr.generateSecret("");
+            fail("NoSuchAlgorithmException must be throwm");
+        } catch (NoSuchAlgorithmException e) {
+        }
+        Key key = null;
+        try {
+            keyAgr.init(key, new SecureRandom());
+            fail("IllegalArgumentException must be throwm");
+        } catch (IllegalArgumentException e) {
+        }
+        AlgorithmParameterSpec params = null;
+        try {
+            keyAgr.init(key, params, new SecureRandom());
+            fail("IllegalArgumentException must be throwm");
+        } catch (IllegalArgumentException e) {
+        }
+    }
+
+    /**
+     * Test for <code>getInstance(String algorithm)</code> method
+     * Assertions:
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is incorrect;
+     * returns KeyAgreement object
+     */
+    public void testGetInstance01() throws NoSuchAlgorithmException,
+            InvalidKeySpecException, InvalidKeyException,
+            ShortBufferException, InvalidAlgorithmParameterException {
+        try {
+            KeyAgreement.getInstance(null);
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                KeyAgreement.getInstance(invalidValues[i]);
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        KeyAgreement keyAgr;
+        for (int i = 0; i < validValues.length; i++) {
+            keyAgr = KeyAgreement.getInstance(validValues[i]);
+            assertEquals("Incorrect algorithm", keyAgr.getAlgorithm(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", keyAgr.getProvider(), mProv);
+            checkResult(keyAgr);
+        }
+    }
+    /**
+     * Test for <code>getInstance(String algorithm, String provider)</code>
+     * method
+     * Assertions: 
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is null or incorrect;
+     * throws IllegalArgumentException when provider is null or null;
+     * throws NoSuchProviderException when provider is available;
+     * returns KeyAgreement object
+     */
+    public void testGetInstance02() throws NoSuchAlgorithmException,
+            NoSuchProviderException, IllegalArgumentException,
+            InvalidKeySpecException, InvalidKeyException,
+            ShortBufferException, InvalidAlgorithmParameterException {            
+        try {
+            KeyAgreement.getInstance(null, mProv.getName());
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                KeyAgreement.getInstance(invalidValues[i], mProv
+                        .getName());
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        String prov = null;
+        for (int i = 0; i < validValues.length; i++) {
+            try {
+                KeyAgreement.getInstance(validValues[i], prov);
+                fail("IllegalArgumentException must be thrown when provider is null (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (IllegalArgumentException e) {
+            }
+            try {
+                KeyAgreement.getInstance(validValues[i], "");
+                fail("IllegalArgumentException must be thrown when provider is empty (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (IllegalArgumentException e) {
+            }
+            for (int j = 1; j < invalidValues.length; j++) {
+                try {
+                    KeyAgreement.getInstance(validValues[i],
+                            invalidValues[j]);
+                    fail("NoSuchProviderException must be thrown (algorithm: "
+                            .concat(invalidValues[i]).concat(" provider: ")
+                            .concat(invalidValues[j]).concat(")"));
+                } catch (NoSuchProviderException e) {
+                }
+            }
+        }
+        KeyAgreement keyAgr;
+        for (int i = 0; i < validValues.length; i++) {
+            keyAgr = KeyAgreement.getInstance(validValues[i], mProv
+                    .getName());
+            assertEquals("Incorrect algorithm", keyAgr.getAlgorithm(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", keyAgr.getProvider().getName(),
+                    mProv.getName());
+            checkResult(keyAgr);
+        }
+    }
+
+    /**
+     * Test for <code>getInstance(String algorithm, Provider provider)</code>
+     * method
+     * Assertions:
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is null or incorrect;
+     * throws IllegalArgumentException when provider is null;
+     * returns KeyAgreement object
+     * 
+     */
+    public void testGetInstance03() throws NoSuchAlgorithmException,
+            IllegalArgumentException,
+            InvalidKeySpecException, InvalidKeyException,
+            ShortBufferException, InvalidAlgorithmParameterException {
+        try {
+            KeyAgreement.getInstance(null, mProv);
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                KeyAgreement.getInstance(invalidValues[i], mProv);
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        Provider prov = null;
+        for (int i = 0; i < validValues.length; i++) {
+            try {
+                KeyAgreement.getInstance(validValues[i], prov);
+                fail("IllegalArgumentException must be thrown when provider is null (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (IllegalArgumentException e) {
+            }
+        }
+        KeyAgreement keyAgr;
+        for (int i = 0; i < validValues.length; i++) {
+            keyAgr = KeyAgreement.getInstance(validValues[i], mProv);
+            assertEquals("Incorrect algorithm", keyAgr.getAlgorithm(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", keyAgr.getProvider(), mProv);
+            checkResult(keyAgr);
+       }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/KeyGenerator_ImplTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/KeyGenerator_ImplTest.java?rev=407748&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/KeyGenerator_ImplTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/KeyGenerator_ImplTest.java Fri May 19 01:44:59 2006
@@ -0,0 +1,278 @@
+/*
+ *  Copyright 2005 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.
+ */
+
+/**
+* @author Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package javax.crypto;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.spec.AlgorithmParameterSpec;
+import java.security.spec.InvalidKeySpecException;
+
+import org.apache.harmony.security.SpiEngUtils;
+import junit.framework.TestCase;
+
+
+/**
+ * Tests for <code>KeyGenerator</code> class constructors and methods
+ * 
+ */
+
+public class KeyGenerator_ImplTest extends TestCase {
+    
+    private static final String srvKeyGenerator = "KeyGenerator";
+
+    private static final String defaultAlg = "MyKeyGen";
+    
+    private static final String KeyGeneratorProviderClass = "org.apache.harmony.crypto.tests.support.MyKeyGeneratorSpi";
+
+    private static final String[] invalidValues = SpiEngUtils.invalidValues;
+
+    private static final String[] validValues;
+
+    static {
+        validValues = new String[4];
+        validValues[0] = defaultAlg;
+        validValues[1] = defaultAlg.toLowerCase();
+        validValues[2] = "myKeyGen";
+        validValues[3] = "mYkeYgeN";
+    }
+
+    Provider mProv;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        mProv = (new SpiEngUtils()).new MyProvider("MyKGProvider", "Testing provider", 
+                srvKeyGenerator.concat(".").concat(defaultAlg), 
+                KeyGeneratorProviderClass);
+        Security.insertProviderAt(mProv, 1);
+    }
+    
+    /*
+     * @see TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        Security.removeProvider(mProv.getName());
+    }
+
+    /**
+     * Constructor for SecurityManagerFactoryTest2.
+     * 
+     * @param arg0
+     */
+    public KeyGenerator_ImplTest(String arg0) {
+        super(arg0);
+    }
+
+    private void checkResult(KeyGenerator keyGen) {
+        AlgorithmParameterSpec paramsNull = null;
+        AlgorithmParameterSpec params = new APSpec();
+        try {
+            keyGen.init(0, new SecureRandom());
+            fail("IllegalArgumentException must be thrown");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            keyGen.init(77, new SecureRandom());
+            fail("IllegalArgumentException must be thrown");
+        } catch (IllegalArgumentException e) {
+        }
+        keyGen.init(78, new SecureRandom());
+        try {
+            keyGen.init(new SecureRandom());
+            fail("IllegalArgumentException must be thrown");                
+        } catch (IllegalArgumentException e) {
+        }
+        assertNull("generateKey must return null", keyGen.generateKey());
+        try {
+            keyGen.init(paramsNull, new SecureRandom());
+            fail("InvalidAlgorithmParameterException must be thrown");
+        } catch (InvalidAlgorithmParameterException e) {
+        }
+        try {
+            keyGen.init(params, new SecureRandom());                
+        } catch (Exception e) {
+            fail("Unexpected: " + e.toString() + " was thrown");
+        }
+        try {
+            keyGen.init(paramsNull);
+            fail("InvalidAlgorithmParameterException must be thrown");
+        } catch (InvalidAlgorithmParameterException e) {
+        }
+        try {
+            keyGen.init(params);                
+        } catch (Exception e) {
+            fail("Unexpected: " + e.toString() + " was thrown");
+        }
+    }
+    
+    /**
+     * Test for <code>getInstance(String algorithm)</code> method
+     * Assertions:
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is incorrect;
+     * returns KeyGenerator object
+     */
+    public void testGetInstance01() throws NoSuchAlgorithmException,
+            InvalidKeySpecException, InvalidKeyException {
+        try {
+            KeyGenerator.getInstance(null);
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                KeyGenerator.getInstance(invalidValues[i]);
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        KeyGenerator keyGen;
+        for (int i = 0; i < validValues.length; i++) {
+            keyGen = KeyGenerator.getInstance(validValues[i]);
+            assertEquals("Incorrect algorithm", keyGen.getAlgorithm(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", keyGen.getProvider(), mProv);
+            checkResult(keyGen);
+        }
+    }
+
+    /**
+     * Test for <code>getInstance(String algorithm, String provider)</code>
+     * method
+     * Assertions: 
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is null or incorrect;
+     * throws IllegalArgumentException when provider is null or empty;
+     * throws NoSuchProviderException when provider is available;
+     * returns KeyGenerator object
+     */
+    public void testGetInstance02() throws NoSuchAlgorithmException,
+            NoSuchProviderException, IllegalArgumentException,
+            InvalidKeySpecException, InvalidKeyException {            
+        try {
+            KeyGenerator.getInstance(null, mProv.getName());
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                KeyGenerator.getInstance(invalidValues[i], mProv
+                        .getName());
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        String prov = null;
+        for (int i = 0; i < validValues.length; i++) {
+            try {
+                KeyGenerator.getInstance(validValues[i], prov);
+                fail("IllegalArgumentException must be thrown when provider is null (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (IllegalArgumentException e) {
+            }
+            try {
+                KeyGenerator.getInstance(validValues[i], "");
+                fail("IllegalArgumentException must be thrown when provider is empty (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (IllegalArgumentException e) {
+            }
+            for (int j = 1; j < invalidValues.length; j++) {
+                try {
+                    KeyGenerator.getInstance(validValues[i],
+                            invalidValues[j]);
+                    fail("NoSuchProviderException must be thrown (algorithm: "
+                            .concat(invalidValues[i]).concat(" provider: ")
+                            .concat(invalidValues[j]).concat(")"));
+                } catch (NoSuchProviderException e) {
+                }
+            }
+        }
+        KeyGenerator keyGen;
+        for (int i = 0; i < validValues.length; i++) {
+            keyGen = KeyGenerator.getInstance(validValues[i], mProv
+                    .getName());
+            assertEquals("Incorrect algorithm", keyGen.getAlgorithm(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", keyGen.getProvider().getName(),
+                    mProv.getName());
+            checkResult(keyGen);
+        }
+    }
+
+    /**
+     * Test for <code>getInstance(String algorithm, Provider provider)</code>
+     * method
+     * Assertions:
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is null or incorrect;
+     * throws IllegalArgumentException when provider is null;
+     * returns KeyGenerator object
+     */
+    public void testGetInstance03() throws NoSuchAlgorithmException,
+            IllegalArgumentException,
+            InvalidKeySpecException, InvalidKeyException {
+        try {
+            KeyGenerator.getInstance(null, mProv);
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                KeyGenerator.getInstance(invalidValues[i], mProv);
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        Provider prov = null;
+        for (int i = 0; i < validValues.length; i++) {
+            try {
+                KeyGenerator.getInstance(validValues[i], prov);
+                fail("IllegalArgumentException must be thrown when provider is null (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (IllegalArgumentException e) {
+            }
+        }
+        KeyGenerator keyGen;
+        for (int i = 0; i < validValues.length; i++) {
+            keyGen = KeyGenerator.getInstance(validValues[i], mProv);
+            assertEquals("Incorrect algorithm", keyGen.getAlgorithm(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", keyGen.getProvider(), mProv);
+            checkResult(keyGen);
+        }
+    }
+}
+
+class APSpec implements AlgorithmParameterSpec {
+    
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/Mac_ImplTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/Mac_ImplTest.java?rev=407748&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/Mac_ImplTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/Mac_ImplTest.java Fri May 19 01:44:59 2006
@@ -0,0 +1,288 @@
+/*
+ *  Copyright 2005 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.
+ */
+
+/**
+* @author Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package javax.crypto;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.Security;
+import java.security.spec.AlgorithmParameterSpec;
+
+import javax.crypto.spec.SecretKeySpec;
+
+import org.apache.harmony.security.SpiEngUtils;
+import junit.framework.TestCase;
+
+
+/**
+ * Tests for Mac class constructors and methods
+ * 
+ */
+
+public class Mac_ImplTest extends TestCase {
+    
+    private static final String srvMac = "Mac";
+
+    private static final String defaultAlg = "MyMacProv";
+    
+    private static final String MacProviderClass = "org.apache.harmony.crypto.tests.support.MyMacSpi";
+
+    private static final String[] invalidValues = SpiEngUtils.invalidValues;
+
+    private static final String[] validValues;
+
+    static {
+        validValues = new String[5];
+        validValues[0] = defaultAlg;
+        validValues[1] = defaultAlg.toUpperCase();
+        validValues[2] = defaultAlg.toLowerCase();
+        validValues[3] = "myMACprov";
+        validValues[4] = "MyMaCpRoV";
+    }
+
+    Provider mProv;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        mProv = (new SpiEngUtils()).new MyProvider("MyMacProvider", "Testing provider", 
+                srvMac.concat(".").concat(defaultAlg), 
+                MacProviderClass);
+        Security.insertProviderAt(mProv, 2);
+    }
+    
+    /*
+     * @see TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        Security.removeProvider(mProv.getName());
+    }
+
+    /**
+     * Constructor for SecurityManagerFactoryTest2.
+     * 
+     * @param arg0
+     */
+    public Mac_ImplTest(String arg0) {
+        super(arg0);
+    }
+    
+    protected void checkResult(Mac mac) throws InvalidKeyException,
+            InvalidAlgorithmParameterException {
+        assertEquals("Incorrect MacLength", mac.getMacLength(), 0);
+        byte [] b = {(byte)0, (byte)0, (byte)0, (byte)0, (byte)0};
+        SecretKeySpec scs = new SecretKeySpec(b, "SHA1");
+        AlgParSpec parms = new AlgParSpec();
+        tmpKey tKey = new tmpKey();
+        mac.init(scs);        
+        byte[] bb = mac.doFinal();
+        assertEquals(bb.length, 0);
+        mac.reset();
+        bb = mac.doFinal();
+        assertEquals(bb.length, 1);
+        try {
+            mac.init(null);
+            fail("InvalidKeyException should be thrown");
+        } catch (InvalidKeyException e) {
+        }
+        try {
+            mac.init(null, null);
+            fail("InvalidKeyException should be thrown");
+        } catch (InvalidKeyException e) {
+        }
+        mac.init(scs, null);
+        mac.init(scs, parms);
+        try {
+            mac.init(tKey, null);
+            fail("InvalidAlgorithmParameterException or IllegalArgumentException "
+                    + "should be thrown for incorrect parameter");
+        } catch (IllegalArgumentException e) {
+        } catch (InvalidAlgorithmParameterException e) {
+        }
+        try {
+            mac.clone();
+            fail("No expected CloneNotSupportedException"); 
+        } catch (CloneNotSupportedException e) {           
+        }
+    }
+
+    /**
+     * Test for <code>getInstance(String algorithm)</code> method
+     * Assertions:
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is not correct;
+     * returns Mac object
+     */
+    public void testGetInstance01() throws NoSuchAlgorithmException,
+            InvalidKeyException,
+            InvalidAlgorithmParameterException {
+        try {
+            Mac.getInstance(null);
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown when algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                Mac.getInstance(invalidValues[i]);
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        Mac keyAgr;
+        for (int i = 0; i < validValues.length; i++) {
+            keyAgr = Mac.getInstance(validValues[i]);
+            assertEquals("Incorrect algorithm", keyAgr.getAlgorithm(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", keyAgr.getProvider(), mProv);
+            checkResult(keyAgr);
+        }
+    }
+    /**
+     * Test for <code>getInstance(String algorithm, String provider)</code>
+     * method
+     * Assertions: 
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is not correct;
+     * throws IllegalArgumentException when provider is null;
+     * throws NoSuchProviderException when provider is available;
+     * returns Mac object
+     */
+    public void testGetInstance02() throws NoSuchAlgorithmException,
+            NoSuchProviderException, IllegalArgumentException,
+            InvalidKeyException,
+            InvalidAlgorithmParameterException {            
+        try {
+            Mac.getInstance(null, mProv.getName());
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown when algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                Mac.getInstance(invalidValues[i], mProv
+                        .getName());
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        String prov = null;
+        for (int i = 0; i < validValues.length; i++) {
+            try {
+                Mac.getInstance(validValues[i], prov);
+                fail("IllegalArgumentException must be thrown when provider is null (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (IllegalArgumentException e) {
+            }
+        }
+        for (int i = 0; i < validValues.length; i++) {
+            for (int j = 1; j < invalidValues.length; j++) {
+                try {
+                    Mac.getInstance(validValues[i],
+                            invalidValues[j]);
+                    fail("NoSuchProviderException must be thrown (algorithm: "
+                            .concat(invalidValues[i]).concat(" provider: ")
+                            .concat(invalidValues[j]).concat(")"));
+                } catch (NoSuchProviderException e) {
+                }
+            }
+        }
+        Mac keyAgr;
+        for (int i = 0; i < validValues.length; i++) {
+            keyAgr = Mac.getInstance(validValues[i], mProv
+                    .getName());
+            assertEquals("Incorrect algorithm", keyAgr.getAlgorithm(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", keyAgr.getProvider().getName(),
+                    mProv.getName());
+            checkResult(keyAgr);
+        }
+    }
+
+    /**
+     * Test for <code>getInstance(String algorithm, Provider provider)</code>
+     * method
+     * Assertions:
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is not correct;
+     * throws IllegalArgumentException when provider is null;
+     * returns Mac object
+     */
+    public void testGetInstance03() throws NoSuchAlgorithmException,
+            IllegalArgumentException,
+            InvalidKeyException,
+            InvalidAlgorithmParameterException {
+        try {
+            Mac.getInstance(null, mProv);
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown when algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                Mac.getInstance(invalidValues[i], mProv);
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        Provider prov = null;
+        for (int i = 0; i < validValues.length; i++) {
+            try {
+                Mac.getInstance(validValues[i], prov);
+                fail("IllegalArgumentException must be thrown when provider is null (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (IllegalArgumentException e) {
+            }
+        }
+        Mac keyAgr;
+        for (int i = 0; i < validValues.length; i++) {
+            keyAgr = Mac.getInstance(validValues[i], mProv);
+            assertEquals("Incorrect algorithm", keyAgr.getAlgorithm(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", keyAgr.getProvider(), mProv);
+            checkResult(keyAgr);
+       }
+    }
+    public static class AlgParSpec implements AlgorithmParameterSpec {
+        
+    }
+    public static class tmpKey implements Key {
+        public tmpKey() {
+            
+        }
+        public String getAlgorithm() {
+            return "Test";
+        }
+        public String getFormat() {
+            return "Format";
+        }
+        public byte[] getEncoded() {
+            return null;
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/SecretKeyFactory_ImplTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/SecretKeyFactory_ImplTest.java?rev=407748&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/SecretKeyFactory_ImplTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/SecretKeyFactory_ImplTest.java Fri May 19 01:44:59 2006
@@ -0,0 +1,239 @@
+/*
+ *  Copyright 2005 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.
+ */
+
+/**
+* @author Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package javax.crypto;
+
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.Security;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.KeySpec;
+
+import org.apache.harmony.security.SpiEngUtils;
+import junit.framework.TestCase;
+
+
+/**
+ * Tests for <code>SecretKeyFactory</code> class constructors and methods
+ * 
+ */
+
+public class SecretKeyFactory_ImplTest extends TestCase {
+    
+    private static final String srvSecretKeyFactory = "SecretKeyFactory";
+    private static final String defaultAlg = "MySecretKey";
+    private static final String SecretKeyFactoryProviderClass = "org.apache.harmony.crypto.tests.support.MySecretKeyFactorySpi";
+
+    private static final String[] invalidValues = SpiEngUtils.invalidValues;
+
+    private static final String[] validValues;
+
+    static {
+        validValues = new String[4];
+        validValues[0] = defaultAlg;
+        validValues[1] = defaultAlg.toLowerCase();
+        validValues[2] = "mySECRETkey";
+        validValues[3] = "MYSECretkey";
+    }
+
+    Provider mProv;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        mProv = (new SpiEngUtils()).new MyProvider("MySKFProvider", "Testing provider", 
+                srvSecretKeyFactory.concat(".").concat(defaultAlg), 
+                SecretKeyFactoryProviderClass);
+        Security.insertProviderAt(mProv, 2);
+    }
+    
+    /*
+     * @see TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        Security.removeProvider(mProv.getName());
+    }
+
+    /**
+     * Constructor for SecurityManagerFactoryTest2.
+     * 
+     * @param arg0
+     */
+    public SecretKeyFactory_ImplTest(String arg0) {
+        super(arg0);
+    }
+
+    private void checkResult(SecretKeyFactory skf) throws InvalidKeyException,
+            InvalidKeySpecException {
+        SecretKey sk;
+        KeySpec keySpec;        
+        sk = skf.generateSecret(null);
+        assertNull("generateSecret method must return null", sk);
+        sk = skf.translateKey(null);
+        assertNull("translateKey method must return null", sk);
+        keySpec = skf.getKeySpec(null, null);
+        assertNull("getKeySpec method must return null", keySpec);
+    }
+    /**
+     * Test for <code>getInstance(String algorithm)</code> method
+     * Assertions:
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is incorrect;
+     * returns SecretKeyFactory object
+     */
+    public void testGetInstance01() throws NoSuchAlgorithmException,
+            InvalidKeySpecException, InvalidKeyException {
+        try {
+            SecretKeyFactory.getInstance(null);
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                SecretKeyFactory.getInstance(invalidValues[i]);
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        SecretKeyFactory skf;
+        for (int i = 0; i < validValues.length; i++) {
+            skf = SecretKeyFactory.getInstance(validValues[i]);
+            assertEquals("Incorrect algorithm", skf.getAlgorithm(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", skf.getProvider(), mProv);
+            checkResult(skf);
+        }
+    }
+
+    /**
+     * Test for <code>getInstance(String algorithm, String provider)</code>
+     * method
+     * Assertions: 
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is null or incorrect;
+     * throws IllegalArgumentException when provider is null or empty;
+     * throws NoSuchProviderException when provider is available;
+     * returns SecretKeyFactory object
+     */
+    public void testGetInstance02() throws NoSuchAlgorithmException,
+            NoSuchProviderException, IllegalArgumentException,
+            InvalidKeySpecException, InvalidKeyException {            
+        try {
+            SecretKeyFactory.getInstance(null, mProv.getName());
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                SecretKeyFactory.getInstance(invalidValues[i], mProv
+                        .getName());
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        String prov = null;
+        for (int i = 0; i < validValues.length; i++) {
+            try {
+                SecretKeyFactory.getInstance(validValues[i], prov);
+                fail("IllegalArgumentException must be thrown when provider is null (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (IllegalArgumentException e) {
+            }
+            try {
+                SecretKeyFactory.getInstance(validValues[i], "");
+                fail("IllegalArgumentException must be thrown when provider is empty (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (IllegalArgumentException e) {
+            }
+            for (int j = 1; j < invalidValues.length; j++) {
+                try {
+                    SecretKeyFactory.getInstance(validValues[i],
+                            invalidValues[j]);
+                    fail("NoSuchProviderException must be thrown (algorithm: "
+                            .concat(invalidValues[i]).concat(" provider: ")
+                            .concat(invalidValues[j]).concat(")"));
+                } catch (NoSuchProviderException e) {
+                }
+            }
+        }
+        SecretKeyFactory skf;
+        for (int i = 0; i < validValues.length; i++) {
+            skf = SecretKeyFactory.getInstance(validValues[i], mProv
+                    .getName());
+            assertEquals("Incorrect algorithm", skf.getAlgorithm(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", skf.getProvider().getName(),
+                    mProv.getName());
+            checkResult(skf);
+        }
+    }
+
+    /**
+     * Test for <code>getInstance(String algorithm, Provider provider)</code>
+     * method
+     * Assertions:
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is null or incorrect;
+     * throws IllegalArgumentException when provider is null;
+     * returns SecretKeyFactory object
+     */
+    public void testGetInstance03() throws NoSuchAlgorithmException,
+            IllegalArgumentException,
+            InvalidKeySpecException, InvalidKeyException {
+        try {
+            SecretKeyFactory.getInstance(null, mProv);
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                SecretKeyFactory.getInstance(invalidValues[i], mProv);
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        Provider prov = null;
+        for (int i = 0; i < validValues.length; i++) {
+            try {
+                SecretKeyFactory.getInstance(validValues[i], prov);
+                fail("IllegalArgumentException must be thrown when provider is null (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (IllegalArgumentException e) {
+            }
+        }
+        SecretKeyFactory skf;
+        for (int i = 0; i < validValues.length; i++) {
+            skf = SecretKeyFactory.getInstance(validValues[i], mProv);
+            assertEquals("Incorrect algorithm", skf.getAlgorithm(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", skf.getProvider(), mProv);
+            checkResult(skf);
+        }
+    }
+}

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyCipher.java (from r407735, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyCipher.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyCipher.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyCipher.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyCipher.java&r1=407735&r2=407748&rev=407748&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyCipher.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyCipher.java Fri May 19 01:44:59 2006
@@ -18,7 +18,7 @@
 * @version $Revision$
 */
 
-package javax.crypto;
+package org.apache.harmony.crypto.tests.support;
 
 import java.security.AlgorithmParameters;
 import java.security.InvalidAlgorithmParameterException;
@@ -27,6 +27,12 @@
 import java.security.NoSuchAlgorithmException;
 import java.security.SecureRandom;
 import java.security.spec.AlgorithmParameterSpec;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.CipherSpi;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.ShortBufferException;
 
 /**
  *

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyExemptionMechanismSpi.java (from r407735, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyExemptionMechanismSpi.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyExemptionMechanismSpi.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyExemptionMechanismSpi.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyExemptionMechanismSpi.java&r1=407735&r2=407748&rev=407748&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyExemptionMechanismSpi.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyExemptionMechanismSpi.java Fri May 19 01:44:59 2006
@@ -19,13 +19,17 @@
 * @version $Revision$
 */
 
-package javax.crypto;
+package org.apache.harmony.crypto.tests.support;
 
 import java.security.AlgorithmParameters;
 import java.security.InvalidAlgorithmParameterException;
 import java.security.InvalidKeyException;
 import java.security.Key;
 import java.security.spec.AlgorithmParameterSpec;
+
+import javax.crypto.ExemptionMechanismException;
+import javax.crypto.ExemptionMechanismSpi;
+import javax.crypto.ShortBufferException;
 
 /**
  * Additional class for verification ExemptionMechanismSpi 

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyKeyAgreementSpi.java (from r407735, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyKeyAgreementSpi.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyKeyAgreementSpi.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyKeyAgreementSpi.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyKeyAgreementSpi.java&r1=407735&r2=407748&rev=407748&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyKeyAgreementSpi.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyKeyAgreementSpi.java Fri May 19 01:44:59 2006
@@ -19,7 +19,7 @@
 * @version $Revision$
 */
 
-package javax.crypto;
+package org.apache.harmony.crypto.tests.support;
 
 import java.security.InvalidAlgorithmParameterException;
 import java.security.InvalidKeyException;
@@ -27,6 +27,10 @@
 import java.security.NoSuchAlgorithmException;
 import java.security.SecureRandom;
 import java.security.spec.AlgorithmParameterSpec;
+
+import javax.crypto.KeyAgreementSpi;
+import javax.crypto.SecretKey;
+import javax.crypto.ShortBufferException;
 
 /**
  * Additional class for verification of KeyAgreementSpi

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyKeyGeneratorSpi.java (from r407735, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyKeyGeneratorSpi.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyKeyGeneratorSpi.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyKeyGeneratorSpi.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyKeyGeneratorSpi.java&r1=407735&r2=407748&rev=407748&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyKeyGeneratorSpi.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyKeyGeneratorSpi.java Fri May 19 01:44:59 2006
@@ -19,11 +19,14 @@
 * @version $Revision$
 */
 
-package javax.crypto;
+package org.apache.harmony.crypto.tests.support;
 
 import java.security.InvalidAlgorithmParameterException;
 import java.security.SecureRandom;
 import java.security.spec.AlgorithmParameterSpec;
+
+import javax.crypto.KeyGeneratorSpi;
+import javax.crypto.SecretKey;
 
 /**
  * Additional class for verification of 

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyMacSpi.java (from r407735, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyMacSpi.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyMacSpi.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyMacSpi.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyMacSpi.java&r1=407735&r2=407748&rev=407748&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MyMacSpi.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MyMacSpi.java Fri May 19 01:44:59 2006
@@ -19,12 +19,14 @@
 * @version $Revision$
 */
 
-package javax.crypto;
+package org.apache.harmony.crypto.tests.support;
 
 import java.security.InvalidAlgorithmParameterException;
 import java.security.InvalidKeyException;
 import java.security.Key;
 import java.security.spec.AlgorithmParameterSpec;
+
+import javax.crypto.MacSpi;
 import javax.crypto.spec.SecretKeySpec;
 
 /**

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MySecretKeyFactorySpi.java (from r407735, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MySecretKeyFactorySpi.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MySecretKeyFactorySpi.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MySecretKeyFactorySpi.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MySecretKeyFactorySpi.java&r1=407735&r2=407748&rev=407748&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/java/javax/crypto/MySecretKeyFactorySpi.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/support/common/java/org/apache/harmony/crypto/tests/support/MySecretKeyFactorySpi.java Fri May 19 01:44:59 2006
@@ -19,11 +19,14 @@
 * @version $Revision$
 */
 
-package javax.crypto;
+package org.apache.harmony.crypto.tests.support;
 
 import java.security.InvalidKeyException;
 import java.security.spec.InvalidKeySpecException;
 import java.security.spec.KeySpec;
+
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactorySpi;
 
 /**
  * Additional class for verification of SecretKeyFactorySpi 



Mime
View raw message