diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-01-09 17:50:54 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-01-09 17:50:54 -0800 |
commit | a0881d052ee72e3f7e773374e9b1aa75fbd6be4c (patch) | |
tree | 8a9462436077d0d906368cb21f521f1bf8a25500 /crypto | |
parent | dd828f42a5c83b4270d4fbf6fce2da1878f1e84a (diff) | |
download | libcore-a0881d052ee72e3f7e773374e9b1aa75fbd6be4c.zip libcore-a0881d052ee72e3f7e773374e9b1aa75fbd6be4c.tar.gz libcore-a0881d052ee72e3f7e773374e9b1aa75fbd6be4c.tar.bz2 |
auto import from //branches/cupcake/...@125939
Diffstat (limited to 'crypto')
82 files changed, 6163 insertions, 2472 deletions
diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/AllTests.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/AllTests.java index e00c935..5050fc8 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/AllTests.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/AllTests.java @@ -30,7 +30,7 @@ public class AllTests { } public static Test suite() { - TestSuite suite = new TestSuite("All tests for package org.apache.harmony.crypto.tests.javax.crypto;"); + TestSuite suite = tests.TestSuiteFactory.createTestSuite("All tests for package org.apache.harmony.crypto.tests.javax.crypto;"); // $JUnit-BEGIN$ suite.addTestSuite(BadPaddingExceptionTest.class); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/BadPaddingExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/BadPaddingExceptionTest.java index d8721e5..4dcc314 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/BadPaddingExceptionTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/BadPaddingExceptionTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import javax.crypto.BadPaddingException; @@ -62,15 +62,12 @@ public class BadPaddingExceptionTest extends TestCase { * Test for <code>BadPaddingException()</code> constructor Assertion: * constructs BadPaddingException with no detail message */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "BadPaddingException", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "BadPaddingException", + args = {} + ) public void testBadPaddingException01() { BadPaddingException tE = new BadPaddingException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -82,15 +79,12 @@ public class BadPaddingExceptionTest extends TestCase { * Assertion: constructs BadPaddingException with detail message msg. * Parameter <code>msg</code> is not null. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "BadPaddingException", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "BadPaddingException", + args = {java.lang.String.class} + ) public void testBadPaddingException02() { BadPaddingException tE; for (int i = 0; i < msgs.length; i++) { @@ -105,15 +99,12 @@ public class BadPaddingExceptionTest extends TestCase { * Test for <code>BadPaddingException(String)</code> constructor * Assertion: constructs BadPaddingException when <code>msg</code> is null */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "BadPaddingException", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "BadPaddingException", + args = {java.lang.String.class} + ) public void testBadPaddingException03() { String msg = null; BadPaddingException tE = new BadPaddingException(msg); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherInputStream1Test.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherInputStream1Test.java index baa80d30..98ea555 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherInputStream1Test.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherInputStream1Test.java @@ -23,11 +23,19 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.io.ByteArrayInputStream; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.NoSuchPaddingException; import javax.crypto.NullCipher; import javax.crypto.CipherInputStream; @@ -60,15 +68,12 @@ public class CipherInputStream1Test extends TestCase { * CipherInputStream uses NullCipher if Cipher is not specified * in the constructor. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "CipherInputStream", - methodArgs = {java.io.InputStream.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "CipherInputStream", + args = {java.io.InputStream.class} + ) public void testCipherInputStream() throws Exception { byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; TestInputStream tis = new TestInputStream(data); @@ -89,15 +94,12 @@ public class CipherInputStream1Test extends TestCase { * read() method testing. Tests that method returns the correct value * (related to the InputStream) and that it returns -1 at the end of stream. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IOException checking missed.", - targets = { - @TestTarget( - methodName = "read", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Can not check IOException.", + method = "read", + args = {} + ) public void testRead1() throws Exception { byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; TestInputStream tis = new TestInputStream(data); @@ -119,15 +121,12 @@ public class CipherInputStream1Test extends TestCase { * value (related to the InputStream) and that it returns -1 at the end of * stream. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IOException checking missed.", - targets = { - @TestTarget( - methodName = "read", - methodArgs = {byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Can not check IOException.", + method = "read", + args = {byte[].class} + ) public void testRead2() throws Exception { byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; TestInputStream tis = new TestInputStream(data); @@ -166,15 +165,12 @@ public class CipherInputStream1Test extends TestCase { * bytes in the case of null buffer, and that it returns -1 at the end of * stream. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IOException checking missed.", - targets = { - @TestTarget( - methodName = "read", - methodArgs = {byte[].class, int.class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Can not check IOException.", + method = "read", + args = {byte[].class, int.class, int.class} + ) public void testRead3() throws Exception { byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; TestInputStream tis = new TestInputStream(data); @@ -213,15 +209,12 @@ public class CipherInputStream1Test extends TestCase { * skip(long n) method testing. Tests that the method correctly skips the * bytes. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IOException checking missed.", - targets = { - @TestTarget( - methodName = "skip", - methodArgs = {long.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Can not check IOException.", + method = "skip", + args = {long.class} + ) public void testSkip() throws Exception { byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; TestInputStream tis = new TestInputStream(data); @@ -260,15 +253,12 @@ public class CipherInputStream1Test extends TestCase { /** * available() method testing. Tests that the method always return 0. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IOException checking missed.", - targets = { - @TestTarget( - methodName = "available", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Can not check IOException.", + method = "available", + args = {} + ) public void testAvailable() throws Exception { byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; TestInputStream tis = new TestInputStream(data); @@ -281,15 +271,12 @@ public class CipherInputStream1Test extends TestCase { * close() method testing. Tests that the method calls the close() * method of the underlying input stream. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IOException checking missed.", - targets = { - @TestTarget( - methodName = "close", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Can not check IOException.", + method = "close", + args = {} + ) public void testClose() throws Exception { byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; TestInputStream tis = new TestInputStream(data); @@ -302,15 +289,12 @@ public class CipherInputStream1Test extends TestCase { /** * markSupported() method testing. Tests that mark is not supported. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "available", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "markSupported", + args = {} + ) public void testMarkSupported() { byte[] data = new byte[] {-127, -100, -50, -10, -1, 0, 1, 10, 50, 127}; TestInputStream tis = new TestInputStream(data); @@ -319,5 +303,27 @@ public class CipherInputStream1Test extends TestCase { + "should be false.", cis.markSupported()); } + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "CipherInputStream", + args = {java.io.InputStream.class, javax.crypto.Cipher.class} + ) + public void test_ConstructorLjava_io_InputStreamLjavax_crypto_Cipher () throws + NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException { + ByteArrayInputStream bais = new ByteArrayInputStream(new byte[100]); + + KeyGenerator kg = KeyGenerator.getInstance("DES"); + kg.init(56, new SecureRandom()); + Key key = kg.generateKey(); + + Cipher c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, key); + + CipherInputStream cis = new CipherInputStream(bais, c); + + assertNotNull(cis); + } + } diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherInputStreamTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherInputStreamTest.java index 2c2b4b8..64562bb 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherInputStreamTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherInputStreamTest.java @@ -18,9 +18,9 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; @@ -38,15 +38,12 @@ public class CipherInputStreamTest extends TestCase { /** * @tests javax.crypto.CipherInputStream#read(byte[] b, int off, int len) */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Regression test. Checks NullPointerException", - targets = { - @TestTarget( - methodName = "read", - methodArgs = {byte[].class, int.class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Regression test. Checks NullPointerException", + method = "read", + args = {byte[].class, int.class, int.class} + ) public void testReadBII() throws Exception { // Regression for HARMONY-1080 CipherInputStream stream = new CipherInputStream(null, new NullCipher()); @@ -61,15 +58,12 @@ public class CipherInputStreamTest extends TestCase { /** * @tests javax.crypto.CipherInputStream#close() */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Regression test. Checks IllegalStateException", - targets = { - @TestTarget( - methodName = "close", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Regression test. Checks IllegalStateException", + method = "close", + args = {} + ) public void testClose() throws Exception { // Regression for HARMONY-1087 try { diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherOutputStream1Test.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherOutputStream1Test.java index 7311b9e..237af28 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherOutputStream1Test.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherOutputStream1Test.java @@ -23,14 +23,22 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.OutputStream; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.Arrays; + +import javax.crypto.KeyGenerator; +import javax.crypto.NoSuchPaddingException; import javax.crypto.NullCipher; import javax.crypto.CipherOutputStream; import javax.crypto.Cipher; @@ -60,15 +68,12 @@ public class CipherOutputStream1Test extends TestCase { * CipherOutputStream uses NullCipher if Cipher is not specified * in the constructor. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "CipherOutputStream", - methodArgs = {java.io.OutputStream.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "CipherOutputStream", + args = {java.io.OutputStream.class} + ) public void testCipherOutputStream() throws Exception { byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; TestOutputStream tos = new TestOutputStream(); @@ -85,15 +90,12 @@ public class CipherOutputStream1Test extends TestCase { * write(int b) method testing. Tests that method writes correct values to * the underlying output stream. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IOException checking missed.", - targets = { - @TestTarget( - methodName = "write", - methodArgs = {int.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Can not check IOException.", + method = "write", + args = {int.class} + ) public void testWrite1() throws Exception { byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; TestOutputStream tos = new TestOutputStream(); @@ -112,15 +114,12 @@ public class CipherOutputStream1Test extends TestCase { * write(byte[] b) method testing. Tests that method writes correct values * to the underlying output stream. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "NullPointerException & IOException checking missed.", - targets = { - @TestTarget( - methodName = "write", - methodArgs = {byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Can not check IOException.", + method = "write", + args = {byte[].class} + ) public void testWrite2() throws Exception { byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; TestOutputStream tos = new TestOutputStream(); @@ -131,20 +130,24 @@ public class CipherOutputStream1Test extends TestCase { if (!Arrays.equals(result, data)) { fail("CipherOutputStream wrote incorrect data."); } + + try { + cos.write(null); + fail("NullPointerException expected"); + } catch (NullPointerException e) { + //expected + } } /** * write(byte[] b, int off, int len) method testing. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IOException checking missed.", - targets = { - @TestTarget( - methodName = "write", - methodArgs = {byte[].class, int.class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Can not check IOException.", + method = "write", + args = {byte[].class, int.class, int.class} + ) public void testWrite3() throws Exception { byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; TestOutputStream tos = new TestOutputStream(); @@ -162,15 +165,12 @@ public class CipherOutputStream1Test extends TestCase { /** * @tests write(byte[] b, int off, int len) */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Regression test. IllegalArgumentException checked.", - targets = { - @TestTarget( - methodName = "write", - methodArgs = {byte[].class, int.class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Regression test. IllegalArgumentException checked.", + method = "write", + args = {byte[].class, int.class, int.class} + ) public void testWrite4() throws Exception { //Regression for HARMONY-758 try { @@ -182,15 +182,12 @@ public class CipherOutputStream1Test extends TestCase { /** * @tests write(byte[] b, int off, int len) */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Regression test. Functional.", - targets = { - @TestTarget( - methodName = "write", - methodArgs = {byte[].class, int.class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Can not check IOException.", + method = "write", + args = {byte[].class, int.class, int.class} + ) public void testWrite5() throws Exception { //Regression for HARMONY-758 Cipher cf = Cipher.getInstance("DES/CBC/PKCS5Padding"); @@ -206,15 +203,12 @@ public class CipherOutputStream1Test extends TestCase { * flush() method testing. Tests that method flushes the data to the * underlying output stream. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IOException checking missed.", - targets = { - @TestTarget( - methodName = "flush", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Can not check IOException.", + method = "flush", + args = {} + ) public void testFlush() throws Exception { byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; TestOutputStream tos = new TestOutputStream(); @@ -231,15 +225,12 @@ public class CipherOutputStream1Test extends TestCase { * close() method testing. Tests that the method calls the close() method of * the underlying input stream. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IOException checking missed.", - targets = { - @TestTarget( - methodName = "close", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Can not check IOException.", + method = "close", + args = {} + ) public void testClose() throws Exception { byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 }; TestOutputStream tos = new TestOutputStream(); @@ -253,5 +244,27 @@ public class CipherOutputStream1Test extends TestCase { assertTrue("The close() method should call the close() method " + "of its underlying output stream.", tos.wasClosed()); } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "CipherOutputStream", + args = {java.io.OutputStream.class, javax.crypto.Cipher.class} + ) + public void test_ConstructorLjava_io_OutputStreamLjavax_crypto_Cipher() throws + NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + KeyGenerator kg = KeyGenerator.getInstance("DES"); + kg.init(56, new SecureRandom()); + Key key = kg.generateKey(); + + Cipher c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, key); + + CipherOutputStream cos = new CipherOutputStream(baos, c); + + assertNotNull(cos); + } } diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherOutputStreamTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherOutputStreamTest.java index d4db40d..aadad1a 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherOutputStreamTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherOutputStreamTest.java @@ -18,9 +18,9 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.io.OutputStream; import javax.crypto.Cipher; @@ -32,15 +32,12 @@ public class CipherOutputStreamTest extends junit.framework.TestCase { /** * @tests javax.crypto.CipherOutputStream#close() */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Regression test. Checks IllegalStateException.", - targets = { - @TestTarget( - methodName = "close", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Regression test. Checks IllegalStateException.", + method = "close", + args = {} + ) public void test_close() throws Exception { // regression test for HARMONY-1139 try { diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherSpiTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherSpiTest.java index 219be74..72d7c81 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherSpiTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherSpiTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.security.spec.AlgorithmParameterSpec; import java.security.InvalidAlgorithmParameterException; @@ -146,15 +146,12 @@ public class CipherSpiTest extends TestCase { * Test for <code>CipherSpi</code> constructor * Assertion: constructs CipherSpi */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "CipherSpi", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "CipherSpi", + args = {} + ) public void testCipherSpiTests01() throws IllegalBlockSizeException, BadPaddingException, ShortBufferException { @@ -184,15 +181,11 @@ public class CipherSpiTest extends TestCase { * Test for <code>engineGetKeySize(Key)</code> method * Assertion: It throws UnsupportedOperationException if it is not overridden */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Functionality not tested.", - targets = { - @TestTarget( - methodName = "engineGetKeySize", - methodArgs = {java.security.Key.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + method = "engineGetKeySize", + args = {java.security.Key.class} + ) public void testCipherSpi02() throws Exception { Mock_CipherSpi cSpi = new Mock_CipherSpi(); try { @@ -206,15 +199,12 @@ public class CipherSpiTest extends TestCase { * Test for <code>engineWrap(Key)</code> method * Assertion: It throws UnsupportedOperationException if it is not overridden */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Functionality not tested.", - targets = { - @TestTarget( - methodName = "engineWrap", - methodArgs = {java.security.Key.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Functionality not tested.", + method = "engineWrap", + args = {java.security.Key.class} + ) public void testCipherSpi03() throws Exception { Mock_CipherSpi cSpi = new Mock_CipherSpi(); try { @@ -228,15 +218,12 @@ public class CipherSpiTest extends TestCase { * Test for <code>engineUnwrap(byte[], String, int)</code> method * Assertion: It throws UnsupportedOperationException if it is not overridden */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Functionality not tested.", - targets = { - @TestTarget( - methodName = "engineUnwrap", - methodArgs = {byte[].class, java.lang.String.class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Functionality not tested.", + method = "engineUnwrap", + args = {byte[].class, java.lang.String.class, int.class} + ) public void testCipherSpi04() throws Exception { Mock_CipherSpi cSpi = new Mock_CipherSpi(); try { @@ -252,15 +239,12 @@ public class CipherSpiTest extends TestCase { * throws NullPointerException if one of these buffers is null; * throws ShortBufferException is there is no space in output to hold result */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "engineUpdate", - methodArgs = {java.nio.ByteBuffer.class, java.nio.ByteBuffer.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "engineUpdate", + args = {java.nio.ByteBuffer.class, java.nio.ByteBuffer.class} + ) public void testCipherSpi05() throws ShortBufferException { Mock_CipherSpi cSpi = new Mock_CipherSpi(); byte[] bb = { (byte) 0, (byte) 1, (byte) 2, (byte) 3, (byte) 4, @@ -313,15 +297,12 @@ public class CipherSpiTest extends TestCase { * throws NullPointerException if one of these buffers is null; * throws ShortBufferException is there is no space in output to hold result */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "BadPaddingException & IllegalBlockSizeException checking missed.", - targets = { - @TestTarget( - methodName = "engineDoFinal", - methodArgs = {java.nio.ByteBuffer.class, java.nio.ByteBuffer.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "BadPaddingException & IllegalBlockSizeException checking missed.", + method = "engineDoFinal", + args = {java.nio.ByteBuffer.class, java.nio.ByteBuffer.class} + ) public void testCipherSpi06() throws BadPaddingException, ShortBufferException, IllegalBlockSizeException { Mock_CipherSpi cSpi = new Mock_CipherSpi(); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java index f545010..f06fa54 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java @@ -17,81 +17,139 @@ package org.apache.harmony.crypto.tests.javax.crypto; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.KnownFailure; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTargetNew; +import dalvik.annotation.TestTargets; + +import org.apache.harmony.crypto.tests.support.MyCipher; + +import tests.support.resource.Support_Resources; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.math.BigInteger; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.ByteBuffer; +import java.nio.ReadOnlyBufferException; import java.security.AlgorithmParameters; +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.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; import java.security.spec.AlgorithmParameterSpec; +import java.security.spec.RSAKeyGenParameterSpec; import java.util.Arrays; +import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.CipherSpi; +import javax.crypto.IllegalBlockSizeException; import javax.crypto.KeyGenerator; +import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKeyFactory; import javax.crypto.ShortBufferException; import javax.crypto.spec.DESedeKeySpec; import javax.crypto.spec.IvParameterSpec; -import tests.support.resource.Support_Resources; -import org.apache.harmony.crypto.tests.support.MyCipher; - @TestTargetClass(Cipher.class) public class CipherTest extends junit.framework.TestCase { static Key cipherKey; static final String algorithm = "DESede"; static final int keyLen = 168; + + static Key cipherKeyDES; + static final String algorithmDES = "DES"; + static final int keyLenDES = 56; static { try { KeyGenerator kg = KeyGenerator.getInstance(algorithm); kg.init(keyLen, new SecureRandom()); cipherKey = kg.generateKey(); + + kg = KeyGenerator.getInstance(algorithmDES); + kg.init(keyLenDES, new SecureRandom()); + cipherKeyDES = kg.generateKey(); } catch (Exception e) { fail("No key " + e); } } - /** * @tests javax.crypto.Cipher#getInstance(java.lang.String) */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getInstance", + args = {java.lang.String.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineSetMode", + args = {java.lang.String.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineSetPadding", + args = {java.lang.String.class} ) }) public void test_getInstanceLjava_lang_String() throws Exception { Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); assertNotNull("Received a null Cipher instance", cipher); + + try { + Cipher.getInstance("WrongAlgorithmName"); + fail("NoSuchAlgorithmException expected"); + } catch (NoSuchAlgorithmException e) { + //expected + } +// RI throws NoSuchAlgorithmException for wrong padding. } /** * @tests javax.crypto.Cipher#getInstance(java.lang.String, * java.lang.String) */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "NoSuchPaddingException checking missed.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.lang.String.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getInstance", + args = {java.lang.String.class, java.lang.String.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineSetMode", + args = {java.lang.String.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineSetPadding", + args = {java.lang.String.class} ) }) public void test_getInstanceLjava_lang_StringLjava_lang_String() @@ -129,19 +187,33 @@ public class CipherTest extends junit.framework.TestCase { } catch (NoSuchProviderException e) { // Expected } +// RI throws NoSuchAlgorithmException for wrong padding. } /** * @tests javax.crypto.Cipher#getInstance(java.lang.String, * java.security.Provider) */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.security.Provider.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getInstance", + args = {java.lang.String.class, java.security.Provider.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineSetMode", + args = {java.lang.String.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineSetPadding", + args = {java.lang.String.class} ) }) public void test_getInstanceLjava_lang_StringLjava_security_Provider() @@ -155,20 +227,34 @@ public class CipherTest extends junit.framework.TestCase { Cipher cipher = Cipher.getInstance("DES", providers[i]); assertNotNull("Cipher.getInstance() returned a null value", cipher); } + + // Exception case + try { + Cipher.getInstance("DES", (Provider) null); + fail("Should have thrown an IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // Expected + } + + // Exception case + try { + Cipher.getInstance("WrongAlg", providers[0]); + fail("NoSuchAlgorithmException expected"); + } catch (NoSuchAlgorithmException e) { + // Expected + } +// RI throws NoSuchAlgorithmException for wrong padding. } /** * @tests javax.crypto.Cipher#getProvider() */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getProvider", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getProvider", + args = {} + ) public void test_getProvider() throws Exception { Provider[] providers = Security.getProviders("Cipher.AES"); @@ -188,15 +274,12 @@ public class CipherTest extends junit.framework.TestCase { /** * @tests javax.crypto.Cipher#getAlgorithm() */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getAlgorithm", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getAlgorithm", + args = {} + ) public void test_getAlgorithm() throws Exception { final String algorithm = "DESede/CBC/PKCS5Padding"; @@ -208,13 +291,19 @@ public class CipherTest extends junit.framework.TestCase { /** * @tests javax.crypto.Cipher#getBlockSize() */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getBlockSize", - methodArgs = {} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getBlockSize", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineGetBlockSize", + args = {} ) }) public void test_getBlockSize() throws Exception { @@ -227,19 +316,33 @@ public class CipherTest extends junit.framework.TestCase { /** * @tests javax.crypto.Cipher#getOutputSize(int) */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IllegalStateException checking missed.", - targets = { - @TestTarget( - methodName = "getOutputSize", - methodArgs = {int.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getOutputSize", + args = {int.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineGetOutputSize", + args = {int.class} ) }) public void test_getOutputSizeI() throws Exception { SecureRandom sr = new SecureRandom(); Cipher cipher = Cipher.getInstance(algorithm + "/ECB/PKCS5Padding"); + + try { + cipher.getOutputSize(25); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + cipher.init(Cipher.ENCRYPT_MODE, cipherKey, sr); // A 25-byte input could result in at least 4 8-byte blocks @@ -254,31 +357,43 @@ public class CipherTest extends junit.framework.TestCase { /** * @tests javax.crypto.Cipher#init(int, java.security.Key) */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed.", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {int.class, java.security.Key.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {int.class, java.security.Key.class} + ) public void test_initILjava_security_Key() throws Exception { Cipher cipher = Cipher.getInstance(algorithm + "/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, cipherKey); + + + cipher = Cipher.getInstance("DES/CBC/NoPadding"); + try { + cipher.init(Cipher.ENCRYPT_MODE, cipherKey); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } } /** * @tests javax.crypto.Cipher#init(int, java.security.Key, * java.security.SecureRandom) */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed.", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {int.class, java.security.Key.class, java.security.SecureRandom.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {int.class, java.security.Key.class, java.security.SecureRandom.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineInit", + args = {int.class, java.security.Key.class, java.security.SecureRandom.class} ) }) public void test_initILjava_security_KeyLjava_security_SecureRandom() @@ -286,40 +401,63 @@ public class CipherTest extends junit.framework.TestCase { SecureRandom sr = new SecureRandom(); Cipher cipher = Cipher.getInstance(algorithm + "/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, cipherKey, sr); + + cipher = Cipher.getInstance("DES/CBC/NoPadding"); + try { + cipher.init(Cipher.ENCRYPT_MODE, cipherKey, sr); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } } /** * @tests javax.crypto.Cipher#init(int, java.security.Key, * java.security.spec.AlgorithmParameterSpec) */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed.", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {int.class, java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {int.class, java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + ) public void test_initILjava_security_KeyLjava_security_spec_AlgorithmParameterSpec() throws Exception { SecureRandom sr = new SecureRandom(); Cipher cipher = null; byte[] iv = null; - AlgorithmParameterSpec ivAVP = null; + AlgorithmParameterSpec ap = null; iv = new byte[8]; sr.nextBytes(iv); - ivAVP = new IvParameterSpec(iv); + ap = new IvParameterSpec(iv); cipher = Cipher.getInstance(algorithm + "/CBC/PKCS5Padding"); - cipher.init(Cipher.ENCRYPT_MODE, cipherKey, ivAVP); + cipher.init(Cipher.ENCRYPT_MODE, cipherKey, ap); byte[] cipherIV = cipher.getIV(); assertTrue("IVs differ", Arrays.equals(cipherIV, iv)); + + cipher = Cipher.getInstance("DES/CBC/NoPadding"); + try { + cipher.init(Cipher.ENCRYPT_MODE, cipherKey, ap); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } + + cipher = Cipher.getInstance("DES/CBC/NoPadding"); + ap = new RSAKeyGenParameterSpec(10, new BigInteger("10")); + + try { + cipher.init(Cipher.ENCRYPT_MODE, cipherKeyDES, ap); + fail("InvalidAlgorithmParameterException expected"); + } catch (InvalidAlgorithmParameterException e) { + //expected + } } /** @@ -327,13 +465,19 @@ public class CipherTest extends junit.framework.TestCase { * java.security.spec.AlgorithmParameterSpec, * java.security.SecureRandom) */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed.", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {int.class, java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {int.class, java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineInit", + args = {int.class, java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} ) }) public void test_initILjava_security_KeyLjava_security_spec_AlgorithmParameterSpecLjava_security_SecureRandom() @@ -342,34 +486,57 @@ public class CipherTest extends junit.framework.TestCase { Cipher cipher = null; byte[] iv = null; - AlgorithmParameterSpec ivAVP = null; + AlgorithmParameterSpec ap = null; iv = new byte[8]; sr.nextBytes(iv); - ivAVP = new IvParameterSpec(iv); + ap = new IvParameterSpec(iv); cipher = Cipher.getInstance(algorithm + "/CBC/PKCS5Padding"); - cipher.init(Cipher.ENCRYPT_MODE, cipherKey, ivAVP, sr); + cipher.init(Cipher.ENCRYPT_MODE, cipherKey, ap, sr); byte[] cipherIV = cipher.getIV(); assertTrue("IVs differ", Arrays.equals(cipherIV, iv)); + cipher = Cipher.getInstance("DES/CBC/NoPadding"); + try { + cipher.init(Cipher.ENCRYPT_MODE, cipherKey, ap, sr); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } + + cipher = Cipher.getInstance("DES/CBC/NoPadding"); + ap = new RSAKeyGenParameterSpec(10, new BigInteger("10")); + + try { + cipher.init(Cipher.ENCRYPT_MODE, cipherKeyDES, ap, sr); + fail("InvalidAlgorithmParameterException expected"); + } catch (InvalidAlgorithmParameterException e) { + //expected + } } /** * @tests javax.crypto.Cipher#update(byte[], int, int) */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed.", - targets = { - @TestTarget( - methodName = "update", - methodArgs = {byte[].class, int.class, int.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "update", + args = {byte[].class, int.class, int.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineUpdate", + args = {byte[].class, int.class, int.class} ) }) - public void _test_update$BII() throws Exception { + public void test_update$BII() throws Exception { for (int index = 1; index < 4; index++) { Cipher c = Cipher.getInstance("DESEDE/CBC/PKCS5Padding"); @@ -389,7 +556,9 @@ public class CipherTest extends junit.framework.TestCase { byte[] input = new byte[256]; String resPath = "hyts_" + "des-ede3-cbc.test" + index + ".ciphertext"; - InputStream is = Support_Resources.getResourceStream(resPath); + File resources = Support_Resources.createTempFolder(); + Support_Resources.copyFile(resources, null, resPath); + InputStream is = Support_Resources.getStream(resPath); int bytesRead = is.read(input, 0, 256); while (bytesRead > 0) { @@ -413,21 +582,26 @@ public class CipherTest extends junit.framework.TestCase { assertTrue("Operation produced incorrect results", Arrays.equals( plaintextBytes, decipheredCipherText)); }// end for + + Cipher cipher = Cipher.getInstance("DESEDE/CBC/PKCS5Padding"); + try { + cipher.update(new byte[64], 0, 32); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } } /** * @tests javax.crypto.Cipher#doFinal() */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed.", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {} - ) - }) - public void _test_doFinal() throws Exception { + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "doFinal", + args = {} + ) + public void test_doFinal() throws Exception { for (int index = 1; index < 4; index++) { Cipher c = Cipher.getInstance("DESEDE/CBC/PKCS5Padding"); @@ -447,7 +621,9 @@ public class CipherTest extends junit.framework.TestCase { byte[] input = new byte[256]; String resPath = "hyts_" + "des-ede3-cbc.test" + index + ".plaintext"; - InputStream is = Support_Resources.getResourceStream(resPath); + File resources = Support_Resources.createTempFolder(); + Support_Resources.copyFile(resources, null, resPath); + InputStream is = Support_Resources.getStream(resPath); int bytesRead = is.read(input, 0, 256); while (bytesRead > 0) { @@ -469,11 +645,54 @@ public class CipherTest extends junit.framework.TestCase { assertTrue("Operation produced incorrect results", Arrays.equals( encryptedPlaintext, cipherText)); }// end for + + byte[] b = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; + byte[] b1 = new byte[30]; + + Cipher c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + c.update(b, 0, 10, b1, 5); + try { + c.doFinal(); + fail("IllegalBlockSizeException expected"); + } catch (IllegalBlockSizeException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + try { + c.doFinal(); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + c.doFinal(b, 0, 16, b1, 0); + + SecureRandom sr = new SecureRandom(); + byte[] iv = new byte[8]; + sr.nextBytes(iv); + AlgorithmParameterSpec ap = new IvParameterSpec(iv); + + c = Cipher.getInstance("DES/CBC/PKCS5Padding"); + c.init(Cipher.DECRYPT_MODE, cipherKeyDES, ap); + + c.update(b1, 0, 24, b, 0); + try { + c.doFinal(); + fail("BadPaddingException expected"); + } catch (BadPaddingException e) { + //expected + } } private byte[] loadBytes(String resPath) { try { - InputStream is = Support_Resources.getResourceStream(resPath); + File resources = Support_Resources.createTempFolder(); + Support_Resources.copyFile(resources, null, resPath); + InputStream is = Support_Resources.getStream(resPath); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buff = new byte[1024]; @@ -488,13 +707,19 @@ public class CipherTest extends junit.framework.TestCase { } } -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getParameters", - methodArgs = {} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getParameters", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineGetParameters", + args = {} ) }) public void testGetParameters() throws Exception { @@ -505,61 +730,121 @@ public class CipherTest extends junit.framework.TestCase { /* * Class under test for int update(byte[], int, int, byte[], int) */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Checks ShortBufferException", - targets = { - @TestTarget( - methodName = "update", - methodArgs = {byte[].class, int.class, int.class, byte[].class, int.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "update", + args = {byte[].class, int.class, int.class, byte[].class, int.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineUpdate", + args = {byte[].class, int.class, int.class, byte[].class, int.class} ) }) public void testUpdatebyteArrayintintbyteArrayint() throws Exception { - Cipher c = Cipher.getInstance("DESede"); - c.init(Cipher.ENCRYPT_MODE, cipherKey); byte[] b = {1,2,3,4,5,6,7,8,9,10}; byte[] b1 = new byte[6]; + Cipher c = Cipher.getInstance("DESede"); + try { c.update(b, 0, 10, b1, 5); - fail("No expected ShortBufferException"); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + + c.init(Cipher.ENCRYPT_MODE, cipherKey); + try { + c.update(b, 0, 10, b1, 5); + fail("ShortBufferException expected"); } catch (ShortBufferException e) { + //expected } + + b1 = new byte[30]; + c.update(b, 0, 10, b1, 5); } /* * Class under test for int doFinal(byte[], int, int, byte[], int) */ -@TestInfo( - level = TestLevel.TODO, - purpose = "Empty test.", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class, int.class, int.class, byte[].class, int.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "doFinal", + args = {byte[].class, int.class, int.class, byte[].class, int.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineDoFinal", + args = {byte[].class, int.class, int.class, byte[].class, int.class} ) }) + @KnownFailure("Fixed in ToT") public void testDoFinalbyteArrayintintbyteArrayint() throws Exception { - Cipher c = Cipher.getInstance("DESede"); + byte[] b = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; + byte[] b1 = new byte[30]; + + Cipher c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + try { + c.doFinal(b, 0, 10, b1, 5); + fail("IllegalBlockSizeException expected"); + } catch (IllegalBlockSizeException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + try { + c.doFinal(b, 0, 10, b1, 5); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + c.doFinal(b, 0, 16, b1, 0); + + SecureRandom sr = new SecureRandom(); + byte[] iv = new byte[8]; + sr.nextBytes(iv); + AlgorithmParameterSpec ap = new IvParameterSpec(iv); + + c = Cipher.getInstance("DES/CBC/PKCS5Padding"); + c.init(Cipher.DECRYPT_MODE, cipherKeyDES, ap); + + try { + c.doFinal(b1, 0, 24, new byte[42], 0); + fail("BadPaddingException expected"); + } catch (BadPaddingException e) { + //expected + } + + b1 = new byte[6]; + c = Cipher.getInstance("DESede"); c.init(Cipher.ENCRYPT_MODE, cipherKey); - byte[] b = {1,2,3,4,5,6,7,8,9,10}; - byte[] b1 = new byte[6]; - // FIXME Failed on BC provider - // try { - // c.doFinal(b, 3, 6, b1, 5); - // fail("No expected ShortBufferException"); - // } catch (ShortBufferException e) { - // } + try { + c.doFinal(b, 3, 6, b1, 5); + fail("No expected ShortBufferException"); + } catch (ShortBufferException e) { + //expected + } } -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Exceptions checked only.", - targets = { - @TestTarget( - methodName = "getMaxAllowedKeyLength", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getMaxAllowedKeyLength", + args = {java.lang.String.class} + ) public void testGetMaxAllowedKeyLength() throws NoSuchAlgorithmException { try { Cipher.getMaxAllowedKeyLength(null); @@ -576,19 +861,17 @@ public class CipherTest extends junit.framework.TestCase { fail("No expected NoSuchAlgorithmException"); } catch (NoSuchAlgorithmException e) { } + assertTrue(Cipher.getMaxAllowedKeyLength("/DES/CBC/PKCS5Paddin") > 0); } -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Exceptions checked only.", - targets = { - @TestTarget( - methodName = "getMaxAllowedParameterSpec", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getMaxAllowedParameterSpec", + args = {java.lang.String.class} + ) public void testGetMaxAllowedParameterSpec() - throws NoSuchAlgorithmException { + throws NoSuchAlgorithmException, Exception { try { Cipher.getMaxAllowedParameterSpec(null); fail("No expected NullPointerException"); @@ -604,21 +887,20 @@ public class CipherTest extends junit.framework.TestCase { fail("No expected NoSuchAlgorithmException"); } catch (NoSuchAlgorithmException e) { } + Cipher.getMaxAllowedParameterSpec("DES/CBC/PKCS5Paddin"); + Cipher.getMaxAllowedParameterSpec("RSA"); } /** * @tests javax.crypto.Cipher#Cipher(CipherSpi cipherSpi, Provider provider, * String transformation) */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "Cipher", - methodArgs = {javax.crypto.CipherSpi.class, java.security.Provider.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "Cipher", + args = {javax.crypto.CipherSpi.class, java.security.Provider.class, java.lang.String.class} + ) public void test_Ctor() throws Exception { // Regression for Harmony-1184 try { @@ -643,6 +925,762 @@ public class CipherTest extends junit.framework.TestCase { } } + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "doFinal", + args = {java.nio.ByteBuffer.class, java.nio.ByteBuffer.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineDoFinal", + args = {java.nio.ByteBuffer.class, java.nio.ByteBuffer.class} + ) + }) + public void test_doFinalLjava_nio_ByteBufferLjava_nio_ByteBuffer () + throws NoSuchAlgorithmException, NoSuchPaddingException, + InvalidKeyException, ShortBufferException, BadPaddingException, + IllegalBlockSizeException, InvalidAlgorithmParameterException { + byte[] b = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; + ByteBuffer bInput = ByteBuffer.allocate(64); + ByteBuffer bOutput = ByteBuffer.allocate(64); + + Cipher c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + bInput.put(b, 0, 10); + try { + c.doFinal(bInput, bOutput); + fail("IllegalBlockSizeException expected"); + } catch (IllegalBlockSizeException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + try { + c.doFinal(bInput, bOutput); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + bInput = ByteBuffer.allocate(16); + bInput.put(b, 0, 16); + c.doFinal(bInput, bOutput); + + SecureRandom sr = new SecureRandom(); + byte[] iv = new byte[8]; + sr.nextBytes(iv); + AlgorithmParameterSpec ap = new IvParameterSpec(iv); + + c = Cipher.getInstance("DES/CBC/PKCS5Padding"); + c.init(Cipher.DECRYPT_MODE, cipherKeyDES, ap); + bInput = ByteBuffer.allocate(64); + + try { + c.doFinal(bOutput, bInput); + fail("BadPaddingException expected"); + } catch (BadPaddingException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + bInput.put(b, 0, 16); + try { + c.doFinal(bInput, bInput); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + bInput.put(b, 0, 16); + try { + c.doFinal(bInput, bOutput.asReadOnlyBuffer()); + fail("ReadOnlyBufferException expected"); + } catch (ReadOnlyBufferException e) { + //expected + } + + bInput.rewind(); + bInput.put(b, 0, 16); + bOutput = ByteBuffer.allocate(8); + c = Cipher.getInstance("DESede"); + c.init(Cipher.ENCRYPT_MODE, cipherKey); + try { + c.doFinal(bInput, bOutput); + fail("No expected ShortBufferException"); + } catch (ShortBufferException e) { + //expected + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {int.class, java.security.Key.class, java.security.AlgorithmParameters.class} + ) + public void test_initILjava_security_KeyLjava_security_AlgorithmParameters () + throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, + InvalidAlgorithmParameterException { + SecureRandom sr = new SecureRandom(); + byte[] iv = new byte[8]; + sr.nextBytes(iv); + AlgorithmParameterSpec ap = new IvParameterSpec(iv); + + Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding"); + c.init(Cipher.DECRYPT_MODE, cipherKeyDES, ap); + assertNotNull(c.getParameters()); + + try { + c.init(Cipher.DECRYPT_MODE, cipherKey, ap); + fail("InvalidKeyException e"); + } catch (InvalidKeyException e) { + //expected + } + + try { + c.init(Cipher.DECRYPT_MODE, cipherKeyDES, (AlgorithmParameters)null); + fail("InvalidAlgorithmParameterException e"); + } catch (InvalidAlgorithmParameterException e) { + //expected + } + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {int.class, java.security.Key.class, java.security.AlgorithmParameters.class, java.security.SecureRandom.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineInit", + args = {int.class, java.security.Key.class, java.security.AlgorithmParameters.class, java.security.SecureRandom.class} + ) + }) + public void test_initILjava_security_KeyLjava_security_AlgorithmParametersLjava_security_SecureRandom () + throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, + InvalidAlgorithmParameterException { + SecureRandom sr = new SecureRandom(); + byte[] iv = new byte[8]; + sr.nextBytes(iv); + AlgorithmParameterSpec ap = new IvParameterSpec(iv); + + Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding"); + c.init(Cipher.DECRYPT_MODE, cipherKeyDES, ap, sr); + assertNotNull(c.getParameters()); + + try { + c.init(Cipher.DECRYPT_MODE, cipherKey, ap, new SecureRandom()); + fail("InvalidKeyException e"); + } catch (InvalidKeyException e) { + //expected + } + + try { + c.init(Cipher.DECRYPT_MODE, cipherKeyDES, (AlgorithmParameters)null, sr); + fail("InvalidAlgorithmParameterException e"); + } catch (InvalidAlgorithmParameterException e) { + //expected + } + + c.init(Cipher.DECRYPT_MODE, cipherKeyDES, ap, (SecureRandom)null); + assertNotNull(c.getParameters()); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {int.class, java.security.cert.Certificate.class} + ) + public void test_initILjava_security_cert_Certificate () + throws MalformedURLException, IOException, CertificateException, + NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException { + + /* Certificate creation notes: certificate should be valid 37273 starting + * from 13 Nov 2008 + * If it brcomes invalidated regenerate it using following commands: + * 1. openssl genrsa -des3 -out test.key 1024 + * 2. openssl req -new -key test.key -out test.csr + * 3. cp test.key test.key.org + * 4. openssl rsa -in test.key.org -out test.key + * 5. openssl x509 -req -days 37273 -in test.csr -signkey test.key -out test.cert + * */ + + String certName = Support_Resources.getURL("test.cert"); + InputStream is = new URL(certName).openConnection().getInputStream(); + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + + Certificate cert = cf.generateCertificate(is); + + Cipher c = Cipher.getInstance("RSA"); + + c.init(Cipher.ENCRYPT_MODE, cert); + c = Cipher.getInstance("DES/CBC/PKCS5Padding"); + try { + c.init(Cipher.ENCRYPT_MODE, cert); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {int.class, java.security.cert.Certificate.class, java.security.SecureRandom.class} + ) + public void test_initILjava_security_cert_Certificate_java_security_SecureRandom () + throws MalformedURLException, IOException, CertificateException, + NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException { + + /* Certificate creation notes: certificate should be valid 37273 starting + * from 13 Nov 2008 + * If it brcomes invalidated regenerate it using following commands: + * 1. openssl genrsa -des3 -out test.key 1024 + * 2. openssl req -new -key test.key -out test.csr + * 3. cp test.key test.key.org + * 4. openssl rsa -in test.key.org -out test.key + * 5. openssl x509 -req -days 37273 -in test.csr -signkey test.key -out test.cert + * */ + + String certName = Support_Resources.getURL("test.cert"); + InputStream is = new URL(certName).openConnection().getInputStream(); + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + + Certificate cert = cf.generateCertificate(is); + + Cipher c = Cipher.getInstance("RSA"); + + c.init(Cipher.ENCRYPT_MODE, cert, new SecureRandom()); + c = Cipher.getInstance("DES/CBC/PKCS5Padding"); + try { + c.init(Cipher.ENCRYPT_MODE, cert, new SecureRandom()); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "unwrap", + args = {byte[].class, java.lang.String.class, int.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineUnwrap", + args = {byte[].class, java.lang.String.class, int.class} + ) + }) + @KnownFailure("Fixed in ToT") + public void test_unwrap$BLjava_lang_StringI () throws NoSuchAlgorithmException, + NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, + IllegalBlockSizeException { + SecureRandom sr = new SecureRandom(); + byte[] iv = new byte[8]; + sr.nextBytes(iv); + AlgorithmParameterSpec ap = new IvParameterSpec(iv); + + Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding"); + + c.init(Cipher.WRAP_MODE, cipherKeyDES, ap, sr); + byte[] arDES = c.wrap(cipherKeyDES); + byte[] ar = c.wrap(cipherKey); + + try { + c.unwrap(arDES, "DES", Cipher.SECRET_KEY); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + + c.init(Cipher.UNWRAP_MODE, cipherKeyDES, ap, sr); + assertTrue(cipherKeyDES.equals(c.unwrap(arDES, "DES", Cipher.SECRET_KEY))); + assertFalse(cipherKeyDES.equals(c.unwrap(ar, "DES", Cipher.SECRET_KEY))); + + try { + c.unwrap(arDES, "RSA38", Cipher.PUBLIC_KEY); + fail("NoSuchAlgorithmException expected"); + } catch (NoSuchAlgorithmException e) { + //expected + } + + c = Cipher.getInstance("DESede/CBC/PKCS5Padding"); + c.init(Cipher.UNWRAP_MODE, cipherKey, ap, sr); + try { + c.unwrap(arDES, "DESede", Cipher.SECRET_KEY); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "update", + args = {java.nio.ByteBuffer.class, java.nio.ByteBuffer.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineUpdate", + args = {java.nio.ByteBuffer.class, java.nio.ByteBuffer.class} + ) + }) + public void test_updateLjava_nio_ByteBufferLjava_nio_ByteBuffer () throws + NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, + ShortBufferException, InvalidAlgorithmParameterException { + byte[] b = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; + ByteBuffer bInput = ByteBuffer.allocate(256); + ByteBuffer bOutput = ByteBuffer.allocate(256); + + Cipher c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + bInput.put(b, 0, 10); + bInput.rewind(); + bOutput.rewind(); + c.update(bInput, bOutput); + + c = Cipher.getInstance("DES/CBC/NoPadding"); + try { + c.update(bInput, bOutput); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + bInput = ByteBuffer.allocate(16); + bInput.put(b, 0, 16); + bInput.rewind(); + bOutput.rewind(); + c.update(bInput, bOutput); + + SecureRandom sr = new SecureRandom(); + byte[] iv = new byte[8]; + sr.nextBytes(iv); + AlgorithmParameterSpec ap = new IvParameterSpec(iv); + + c = Cipher.getInstance("DES/CBC/PKCS5Padding"); + c.init(Cipher.DECRYPT_MODE, cipherKeyDES, ap); + bInput = ByteBuffer.allocate(64); + + c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + bInput.put(b, 0, 16); + bInput.rewind(); + try { + c.update(bInput, bInput); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + bInput.put(b, 0, 16); + bInput.rewind(); + bOutput.rewind(); + try { + c.update(bInput, bOutput.asReadOnlyBuffer()); + fail("ReadOnlyBufferException expected"); + } catch (ReadOnlyBufferException e) { + //expected + } + + bInput.rewind(); + bInput.put(b, 0, 16); + bInput.rewind(); + bOutput = ByteBuffer.allocate(8); + c = Cipher.getInstance("DESede"); + c.init(Cipher.ENCRYPT_MODE, cipherKey); + try { + c.update(bInput, bOutput); + fail("No expected ShortBufferException"); + } catch (ShortBufferException e) { + //expected + } + } + + class Mock_Key implements Key { + public String getAlgorithm() { + return null; + } + + public byte[] getEncoded() { + return null; + } + + public String getFormat() { + return null; + } + + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "wrap", + args = {java.security.Key.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineWrap", + args = {java.security.Key.class} + ) + }) + public void test_wrap_java_security_Key () throws NoSuchAlgorithmException, + NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, + InvalidAlgorithmParameterException, MalformedURLException, IOException, + CertificateException { + SecureRandom sr = new SecureRandom(); + byte[] iv = new byte[8]; + sr.nextBytes(iv); + AlgorithmParameterSpec ap = new IvParameterSpec(iv); + + Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding"); + + c.init(Cipher.WRAP_MODE, cipherKeyDES, ap, sr); + assertNotNull(c.wrap(cipherKeyDES)); + assertNotNull(c.wrap(cipherKey)); + String certName = Support_Resources.getURL("test.cert"); + InputStream is = new URL(certName).openConnection().getInputStream(); + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + + Certificate cert = cf.generateCertificate(is); + assertNotNull(c.wrap(cert.getPublicKey())); + + c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.WRAP_MODE, cipherKeyDES, ap, sr); + try { + assertNotNull(c.wrap(cert.getPublicKey())); + fail("IllegalBlockSizeException expected"); + } catch (IllegalBlockSizeException e) { + //expected + } + + c.init(Cipher.DECRYPT_MODE, cipherKeyDES, ap, sr); + + try { + c.wrap(cipherKeyDES); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + + c.init(Cipher.WRAP_MODE, cipherKeyDES, ap, sr); + try { + c.wrap(new Mock_Key()); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "doFinal", + args = {byte[].class, int.class} + ) + @KnownFailure("Fixed in ToT") + public void test_doFinal$BI() throws Exception { + byte[] b = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; + byte[] b1 = new byte[30]; + + Cipher c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + c.update(b, 0, 10); + try { + c.doFinal(b1, 5); + fail("IllegalBlockSizeException expected"); + } catch (IllegalBlockSizeException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + try { + c.doFinal(b1, 5); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + c.update(b, 3, 8); + c.doFinal(b1, 0); + + SecureRandom sr = new SecureRandom(); + byte[] iv = new byte[8]; + sr.nextBytes(iv); + AlgorithmParameterSpec ap = new IvParameterSpec(iv); + + c = Cipher.getInstance("DES/CBC/PKCS5Padding"); + c.init(Cipher.DECRYPT_MODE, cipherKeyDES, ap); + + c.update(b1, 0, 24); + try { + c.doFinal(b, 0); + fail("BadPaddingException expected"); + } catch (BadPaddingException e) { + //expected + } + + b1 = new byte[6]; + c = Cipher.getInstance("DESede"); + c.init(Cipher.ENCRYPT_MODE, cipherKey); + c.update(b, 3, 6); + try { + c.doFinal(b1, 5); + fail("No expected ShortBufferException"); + } catch (ShortBufferException e) { + //expected + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "doFinal", + args = {byte[].class} + ) + public void test_doFinal$B() throws Exception { + byte[] b1 = new byte[32]; + byte[] bI1 = {1,2,3,4,5,6,7,8,9,10}; + byte[] bI2 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; + byte[] bI3 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; + byte[] bI4 = {1,2,3}; + + Cipher c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + try { + c.doFinal(bI1); + fail("IllegalBlockSizeException expected"); + } catch (IllegalBlockSizeException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + try { + c.doFinal(bI1); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + c.doFinal(bI2); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + c.doFinal(bI3, 0, 16, b1, 0); + + SecureRandom sr = new SecureRandom(); + byte[] iv = new byte[8]; + sr.nextBytes(iv); + AlgorithmParameterSpec ap = new IvParameterSpec(iv); + + c = Cipher.getInstance("DES/CBC/PKCS5Padding"); + c.init(Cipher.DECRYPT_MODE, cipherKeyDES, ap); + + try { + c.doFinal(b1); + fail("BadPaddingException expected"); + } catch (BadPaddingException e) { + //expected + } + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "doFinal", + args = {byte[].class, int.class, int.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = CipherSpi.class, + method = "engineDoFinal", + args = {byte[].class, int.class, int.class} + ) + }) + public void test_doFinal$BII() throws Exception { + byte[] b = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; + byte[] b1 = new byte[30]; + + Cipher c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + try { + c.doFinal(b, 0, 10); + fail("IllegalBlockSizeException expected"); + } catch (IllegalBlockSizeException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + try { + c.doFinal(b, 0, 10); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + c.doFinal(b, 0, 16); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + c.doFinal(b, 0, 16, b1, 0); + + SecureRandom sr = new SecureRandom(); + byte[] iv = new byte[8]; + sr.nextBytes(iv); + AlgorithmParameterSpec ap = new IvParameterSpec(iv); + + c = Cipher.getInstance("DES/CBC/PKCS5Padding"); + c.init(Cipher.DECRYPT_MODE, cipherKeyDES, ap); + + try { + c.doFinal(b1, 0, 24); + fail("BadPaddingException expected"); + } catch (BadPaddingException e) { + //expected + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "doFinal", + args = {byte[].class, int.class, int.class, byte[].class} + ) + @KnownFailure("Fixed in ToT") + public void test_doFinal$BII$B() throws Exception { + byte[] b = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; + byte[] b1 = new byte[30]; + + Cipher c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + try { + c.doFinal(b, 0, 10, b1); + fail("IllegalBlockSizeException expected"); + } catch (IllegalBlockSizeException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + try { + c.doFinal(b, 0, 10, b1); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + c.doFinal(b, 0, 16, b1); + + SecureRandom sr = new SecureRandom(); + byte[] iv = new byte[8]; + sr.nextBytes(iv); + AlgorithmParameterSpec ap = new IvParameterSpec(iv); + + c = Cipher.getInstance("DES/CBC/PKCS5Padding"); + c.init(Cipher.DECRYPT_MODE, cipherKeyDES, ap); + + try { + c.doFinal(b1, 0, 24, new byte[42]); + fail("BadPaddingException expected"); + } catch (BadPaddingException e) { + //expected + } + + b1 = new byte[6]; + c = Cipher.getInstance("DESede"); + c.init(Cipher.ENCRYPT_MODE, cipherKey); + try { + c.doFinal(b, 3, 6, b1); + fail("No expected ShortBufferException"); + } catch (ShortBufferException e) { + //expected + } + } + + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks exception", + method = "update", + args = {byte[].class} + ) + public void test_update$B() throws Exception { + Cipher cipher = Cipher.getInstance("DESEDE/CBC/PKCS5Padding"); + try { + cipher.update(new byte[64]); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "update", + args = {byte[].class, int.class, int.class, byte[].class} + ) + public void test_() throws Exception { + byte[] b = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; + byte[] b1 = new byte[30]; + + Cipher c = Cipher.getInstance("DES/CBC/NoPadding"); + + try { + c.update(b, 0, 10, b1); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + + c = Cipher.getInstance("DES/CBC/NoPadding"); + c.init(Cipher.ENCRYPT_MODE, cipherKeyDES); + c.update(b, 0, 16, b1); + + b1 = new byte[3]; + + try { + c.update(b, 3, 15, b1); + fail("No expected ShortBufferException"); + } catch (ShortBufferException e) { + //expected + } + } + class testCipher extends Cipher { testCipher(CipherSpi c, Provider p, String s) { super(c, p, s); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfoTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfoTest.java index 8b0ba39..d78698c 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfoTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfoTest.java @@ -23,18 +23,20 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.io.IOException; import java.security.AlgorithmParameters; +import java.security.AlgorithmParametersSpi; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.Key; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; import java.security.Provider; import java.security.Security; import java.security.spec.InvalidKeySpecException; @@ -74,7 +76,7 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { */ private static final String[][] algName = { // AES - { "AES", null }, + { "AES", null}, // {"AES", "AES/ECB/PKCS5Padding"}, // {"AES", "AES/CBC/PKCS5Padding"}, // {"AES", "AES/OFB/PKCS5Padding"}, @@ -135,8 +137,8 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { { "PBEWithMD5AndTripleDES", null }, // {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-5(5) // pbeWithMD5AndDES-CBC(3)} - { "PBEWithMD5AndDES", "PBEWithMD5AndDES/CBC/PKCS5Padding" }, - { "PBEWithMD5AndDES", null }, { "PBEWithHmacSHA1AndDESede", null }, + { "PBEWithMD5AndDES", "PBEWithMD5AndDES/CBC/PKCS5Padding", "PBEWithMD5AndDES"}, + { "PBEWithMD5AndDES", null, "PBEWithMD5AndDES"}, { "PBEWithHmacSHA1AndDESede", null }, // more oids: // {iso(1) member-body(2) us(840) nortelnetworks(113533) entrust(7) // algorithms(66) pbeWithMD5AndCAST5-CBC(12)} @@ -166,8 +168,8 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { // {"1.2.840.113549.1.12.1.1",null}, // {"1.2.840.113549.1.12.1.2",null}, - { "1.2.840.113549.1.12.1.3", null }, - { "PBEWithSHA1AndDESede", null }, + { "1.2.840.113549.1.12.1.3", null, "PBEWithSHA1AndDESede"}, + { "PBEWithSHA1AndDESede", null, "PBEWithSHA1AndDESede"}, // {"1.2.840.113549.1.12.1.4",null}, // {"1.2.840.113549.1.12.1.5",null}, // {"1.2.840.113549.1.12.1.6",null}, @@ -193,6 +195,41 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { // {"RSA",null}, // 1.2.840.113549.1.1.1 // {"1.2.840.113549.1.1.1", null}, }; + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getAlgName", + args = {} + ) + public void test_getAlgName () { + boolean performed = false; + for (int i = 0; i < algName.length; i++) { + try { + // generate test data + TestDataGenerator g = new TestDataGenerator(algName[i][0], + algName[i][1], privateKeyInfoDamaged, null); + + // create test object + EncryptedPrivateKeyInfo epki; + if (g.ap() == null) { + epki = new EncryptedPrivateKeyInfo(algName[i][0], g.ct()); + } else { + epki = new EncryptedPrivateKeyInfo(g.ap(), g.ct()); + } + + // call methods under test + if (algName[i].length == 3) { + assertTrue(epki.getAlgName().compareTo(algName[i][2]) == 0); + } + + performed = true; + } catch (TestDataGenerator.AllowedFailure allowedFailure) { + } catch (NoSuchAlgorithmException allowedFailure) { + } + } + assertTrue("Test not performed", performed); + } /** * Test #1 for <code>EncryptedPrivateKeyInfo(byte[])</code> constructor @@ -204,15 +241,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * @throws IOException * @throws NoSuchAlgorithmException */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", + method = "EncryptedPrivateKeyInfo", + args = {byte[].class} + ) public final void testEncryptedPrivateKeyInfobyteArray1() throws Exception { new EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfoData .getValidEncryptedPrivateKeyInfoEncoding("DH")); @@ -228,15 +262,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", + method = "EncryptedPrivateKeyInfo", + args = {byte[].class} + ) public final void testEncryptedPrivateKeyInfobyteArray2() throws IOException { try { @@ -253,15 +284,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * Test preconditions: wrong encoding passed as a parameter <br> * Expected: <code>IOException</code> */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", + method = "EncryptedPrivateKeyInfo", + args = {byte[].class} + ) public final void testEncryptedPrivateKeyInfobyteArray3() { try { new EncryptedPrivateKeyInfo(new byte[0]); @@ -277,15 +305,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * Test preconditions: wrong encoding passed as a parameter <br> * Expected: <code>IOException</code> */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", + method = "EncryptedPrivateKeyInfo", + args = {byte[].class} + ) public final void testEncryptedPrivateKeyInfobyteArray4() { try { new EncryptedPrivateKeyInfo(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, @@ -302,15 +327,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * Test preconditions: wrong encoding passed as a parameter <br> * Expected: <code>IOException</code> */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", + method = "EncryptedPrivateKeyInfo", + args = {byte[].class} + ) public final void testEncryptedPrivateKeyInfobyteArray5() throws Exception { byte[] enc = null; try { @@ -402,15 +424,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.", + method = "EncryptedPrivateKeyInfo", + args = {byte[].class} + ) public final void testEncryptedPrivateKeyInfobyteArray6() throws Exception { byte[] encoded = EncryptedPrivateKeyInfoData .getValidEncryptedPrivateKeyInfoEncoding("DSA"); @@ -430,15 +449,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * Test preconditions: valid parameters passed <br> * Expected: must pass without any exceptions */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {java.lang.String.class, byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", + method = "EncryptedPrivateKeyInfo", + args = {java.lang.String.class, byte[].class} + ) public final void testEncryptedPrivateKeyInfoStringbyteArray1() { boolean performed = false; @@ -463,15 +479,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * Test preconditions: pass nonexistent algorithm name <br> * Expected: <code>NoSuchAlgorithmException</code> */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {java.lang.String.class, byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", + method = "EncryptedPrivateKeyInfo", + args = {java.lang.String.class, byte[].class} + ) public final void testEncryptedPrivateKeyInfoStringbyteArray2() { try { new EncryptedPrivateKeyInfo("bla-bla", @@ -499,15 +512,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws NoSuchAlgorithmException */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {java.lang.String.class, byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", + method = "EncryptedPrivateKeyInfo", + args = {java.lang.String.class, byte[].class} + ) public final void testEncryptedPrivateKeyInfoStringbyteArray3() throws NoSuchAlgorithmException { // pass null as name @@ -534,15 +544,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * Test preconditions: pass empty encrypted data <br> * Expected: <code>IllegalArgumentException</code> */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {java.lang.String.class, byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", + method = "EncryptedPrivateKeyInfo", + args = {java.lang.String.class, byte[].class} + ) public final void testEncryptedPrivateKeyInfoStringbyteArray4() throws Exception { try { @@ -562,15 +569,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {java.lang.String.class, byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", + method = "EncryptedPrivateKeyInfo", + args = {java.lang.String.class, byte[].class} + ) public final void testEncryptedPrivateKeyInfoStringbyteArray5() throws Exception { byte[] encryptedDataCopy = EncryptedPrivateKeyInfoData.encryptedData @@ -589,15 +593,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * @tests javax/crypto/EncryptedPrivateKeyInfo(String, byte[]) * Checks exception order */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {java.lang.String.class, byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.", + method = "EncryptedPrivateKeyInfo", + args = {java.lang.String.class, byte[].class} + ) public final void testEncryptedPrivateKeyInfoStringbyteArray6() { //Regression for HARMONY-768 try { @@ -608,7 +609,13 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { } } - /** + class Mock_AlgorithmParameters extends AlgorithmParameters { + protected Mock_AlgorithmParameters(AlgorithmParametersSpi paramSpi, Provider provider, String algorithm) { + super(paramSpi, provider, algorithm); + } + } + +/** * Test #1 for * <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[]) * </code> @@ -618,23 +625,22 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * Expected: must pass without any exceptions * * @throws IOException + * @throws NoSuchAlgorithmException */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Functionality checked. NoSuchAlgorithmException should be tested for complete tests subset.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {java.security.AlgorithmParameters.class, byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Functionality checked. NoSuchAlgorithmException should be tested for complete tests subset.", + method = "EncryptedPrivateKeyInfo", + args = {java.security.AlgorithmParameters.class, byte[].class} + ) public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray1() - throws IOException { + throws IOException, NoSuchAlgorithmException { + AlgorithmParameters ap = null; boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { try { - AlgorithmParameters ap = AlgorithmParameters + ap = AlgorithmParameters .getInstance(EncryptedPrivateKeyInfoData.algName0[i][0]); // use pregenerated AlgorithmParameters encodings ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding( @@ -648,6 +654,16 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { } } assertTrue("Test not performed", performed); + + ap = new Mock_AlgorithmParameters(null, null, "Wrong alg name"); + + try { + new EncryptedPrivateKeyInfo(ap, + EncryptedPrivateKeyInfoData.encryptedData); + fail("NoSuchAlgorithmException expected"); + } catch (NoSuchAlgorithmException e) { + //expected + } } /** @@ -664,15 +680,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * @throws NoSuchAlgorithmException * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "NullPointerException checked.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {java.security.AlgorithmParameters.class, byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "NullPointerException checked.", + method = "EncryptedPrivateKeyInfo", + args = {java.security.AlgorithmParameters.class, byte[].class} + ) public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray2() throws NoSuchAlgorithmException, IOException { // 1: pass null as AlgorithmParameters @@ -707,15 +720,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * @throws NoSuchAlgorithmException * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IllegalArgumentException checked.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {java.security.AlgorithmParameters.class, byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "IllegalArgumentException checked.", + method = "EncryptedPrivateKeyInfo", + args = {java.security.AlgorithmParameters.class, byte[].class} + ) public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray3() throws Exception { try { @@ -742,15 +752,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Functionality checked.", - targets = { - @TestTarget( - methodName = "EncryptedPrivateKeyInfo", - methodArgs = {java.security.AlgorithmParameters.class, byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Functionality checked.", + method = "EncryptedPrivateKeyInfo", + args = {java.security.AlgorithmParameters.class, byte[].class} + ) public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray4() throws Exception { AlgorithmParameters ap = AlgorithmParameters.getInstance("DSA"); @@ -780,15 +787,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getAlgParameters method.", - targets = { - @TestTarget( - methodName = "getAlgParameters", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getAlgParameters method.", + method = "getAlgParameters", + args = {} + ) public final void testGetAlgParameters01() throws IOException { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -817,15 +821,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { assertTrue("Test not performed", performed); } -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getAlgParameters method.", - targets = { - @TestTarget( - methodName = "getAlgParameters", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getAlgParameters method.", + method = "getAlgParameters", + args = {} + ) public final void testGetAlgParameters01_01() throws Exception { byte[] validEncodingWithUnknownAlgOID = EncryptedPrivateKeyInfoData .getValidEncryptedPrivateKeyInfoEncoding("DH"); @@ -847,15 +848,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getAlgParameters method.", - targets = { - @TestTarget( - methodName = "getAlgParameters", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getAlgParameters method.", + method = "getAlgParameters", + args = {} + ) public final void testGetAlgParameters02() throws IOException { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -889,15 +887,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getAlgParameters method.", - targets = { - @TestTarget( - methodName = "getAlgParameters", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getAlgParameters method.", + method = "getAlgParameters", + args = {} + ) public final void testGetAlgParameters03() throws IOException { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -927,15 +922,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getAlgParameters method.", - targets = { - @TestTarget( - methodName = "getAlgParameters", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getAlgParameters method.", + method = "getAlgParameters", + args = {} + ) public final void testGetAlgParameters04() throws IOException { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -972,15 +964,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getEncryptedData method.", - targets = { - @TestTarget( - methodName = "getEncryptedData", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getEncryptedData method.", + method = "getEncryptedData", + args = {} + ) public final void testGetEncryptedData01() throws IOException { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -1010,15 +999,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * name and encrypted data as a parameters <br> * Expected: the equivalent encrypted data must be returned */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getEncryptedData method.", - targets = { - @TestTarget( - methodName = "getEncryptedData", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getEncryptedData method.", + method = "getEncryptedData", + args = {} + ) public final void testGetEncryptedData02() { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -1049,15 +1035,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getEncryptedData method.", - targets = { - @TestTarget( - methodName = "getEncryptedData", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getEncryptedData method.", + method = "getEncryptedData", + args = {} + ) public final void testGetEncryptedData03() throws IOException { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -1092,15 +1075,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * Expected: refs to encrypted data byte array passed to the ctor and * returned by the method under test must be different */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getEncryptedData method.", - targets = { - @TestTarget( - methodName = "getEncryptedData", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getEncryptedData method.", + method = "getEncryptedData", + args = {} + ) public final void testGetEncryptedData04() { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -1133,15 +1113,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IOException checking missed.", - targets = { - @TestTarget( - methodName = "getEncoded", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Can not check IOException", + method = "getEncoded", + args = {} + ) public final void testGetEncoded01() throws IOException { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -1171,15 +1148,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IOException checking missed.", - targets = { - @TestTarget( - methodName = "getEncoded", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Can not check IOException", + method = "getEncoded", + args = {} + ) public final void testGetEncoded02() throws IOException { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -1215,15 +1189,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IOException checking missed.", - targets = { - @TestTarget( - methodName = "getEncoded", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Can not check IOException", + method = "getEncoded", + args = {} + ) public final void testGetEncoded03() throws IOException { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -1262,15 +1233,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { * * @throws IOException */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IOException checking missed.", - targets = { - @TestTarget( - methodName = "getEncoded", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Can not check IOException", + method = "getEncoded", + args = {} + ) public final void testGetEncoded04() throws IOException { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -1295,15 +1263,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { assertTrue("Test not performed", performed); } -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getKeySpec method.", - targets = { - @TestTarget( - methodName = "getKeySpec", - methodArgs = {javax.crypto.Cipher.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getKeySpec method.", + method = "getKeySpec", + args = {javax.crypto.Cipher.class} + ) public final void testGetKeySpecCipher01() { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -1333,15 +1298,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { /** * Encrypted data contains valid PKCS8 key info encoding */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getKeySpec method.", - targets = { - @TestTarget( - methodName = "getKeySpec", - methodArgs = {javax.crypto.Cipher.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getKeySpec method.", + method = "getKeySpec", + args = {javax.crypto.Cipher.class} + ) public final void test_ROUNDTRIP_GetKeySpecCipher01() { boolean performed = false; @@ -1382,15 +1344,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { /** * Encrypted data contains invalid PKCS8 key info encoding */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getKeySpec method.", - targets = { - @TestTarget( - methodName = "getKeySpec", - methodArgs = {javax.crypto.Cipher.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getKeySpec method.", + method = "getKeySpec", + args = {javax.crypto.Cipher.class} + ) public final void test_ROUNDTRIP_GetKeySpecCipher02() { boolean performed = false; for (int i = 0; i < algName.length; i++) { @@ -1425,15 +1384,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { assertTrue("Test not performed", performed); } -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Subset does not checks NoSuchAlgorithmException", - targets = { - @TestTarget( - methodName = "getKeySpec", - methodArgs = {java.security.Key.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Can not check NoSuchAlgorithmException", + method = "getKeySpec", + args = {java.security.Key.class} + ) public final void testGetKeySpecKey01() { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -1463,15 +1419,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { /** * Encrypted data contains valid PKCS8 key info encoding */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Subset does not checks NoSuchAlgorithmException", - targets = { - @TestTarget( - methodName = "getKeySpec", - methodArgs = {java.security.Key.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Can not check NoSuchAlgorithmException", + method = "getKeySpec", + args = {java.security.Key.class} + ) public final void test_ROUNDTRIP_GetKeySpecKey01() { boolean performed = false; for (int i = 0; i < algName.length; i++) { @@ -1510,15 +1463,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { /** * Encrypted data contains invalid PKCS8 key info encoding */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Subset does not checks NoSuchAlgorithmException", - targets = { - @TestTarget( - methodName = "getKeySpec", - methodArgs = {java.security.Key.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Can not check NoSuchAlgorithmException", + method = "getKeySpec", + args = {java.security.Key.class} + ) public final void test_ROUNDTRIP_GetKeySpecKey02() { boolean performed = false; for (int i = 0; i < algName.length; i++) { @@ -1549,15 +1499,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { assertTrue("Test not performed", performed); } -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "In subset missed NoSuchProviderException & NoSuchAlgorithmException checking", - targets = { - @TestTarget( - methodName = "getKeySpec", - methodArgs = {java.security.Key.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "NoSuchAlgorithmException can not be checking", + method = "getKeySpec", + args = {java.security.Key.class, java.lang.String.class} + ) public final void testGetKeySpecKeyString01() throws Exception { boolean performed = false; for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) { @@ -1567,7 +1514,6 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { EncryptedPrivateKeyInfoData.encryptedData); try { - // check that method under test throws NPE epki.getKeySpec((Key) null, "SomeProviderName"); fail(getName() + "NullPointerException has not been thrown"); @@ -1576,6 +1522,25 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { } try { + epki.getKeySpec(new Key() { + public String getAlgorithm() { + return "alg"; + } + + public String getFormat() { + return "fmt"; + } + + public byte[] getEncoded() { + return new byte[] {}; + } + }, "StrangeProviderName"); + fail(getName() + "NoSuchProviderException has not been thrown"); + } catch (NoSuchProviderException ok) { + //expected + } + + try { // check that method under test throws NPE epki.getKeySpec(new Key() { @@ -1607,15 +1572,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { /** * Encrypted data contains valid PKCS8 key info encoding */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "In subset missed NoSuchProviderException & NoSuchAlgorithmException checking", - targets = { - @TestTarget( - methodName = "getKeySpec", - methodArgs = {java.security.Key.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "In subset missed NoSuchProviderException & NoSuchAlgorithmException checking", + method = "getKeySpec", + args = {java.security.Key.class, java.lang.String.class} + ) public final void test_ROUNDTRIP_GetKeySpecKeyString01() throws Exception { boolean performed = false; for (int i = 0; i < algName.length; i++) { @@ -1665,15 +1627,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { /** * Encrypted data contains invalid PKCS8 key info encoding */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "In subset missed NoSuchProviderException & NoSuchAlgorithmException checking", - targets = { - @TestTarget( - methodName = "getKeySpec", - methodArgs = {java.security.Key.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "In subset missed NoSuchProviderException & NoSuchAlgorithmException checking", + method = "getKeySpec", + args = {java.security.Key.class, java.lang.String.class} + ) public final void test_ROUNDTRIP_GetKeySpecKeyString02() throws Exception { boolean performed = false; for (int i = 0; i < algName.length; i++) { @@ -1718,15 +1677,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { assertTrue("Test not performed", performed); } -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "In subset missed NoSuchAlgorithmException checking", - targets = { - @TestTarget( - methodName = "getKeySpec", - methodArgs = {java.security.Key.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Can not check NoSuchAlgorithmException", + method = "getKeySpec", + args = {java.security.Key.class, java.security.Provider.class} + ) public final void testGetKeySpecKeyProvider01() throws Exception { boolean performed = false; @@ -1775,15 +1731,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { /** * Encrypted data contains valid PKCS8 key info encoding */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "In subset missed NoSuchAlgorithmException checking", - targets = { - @TestTarget( - methodName = "getKeySpec", - methodArgs = {java.security.Key.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Can not check NoSuchAlgorithmException", + method = "getKeySpec", + args = {java.security.Key.class, java.security.Provider.class} + ) public final void test_ROUNDTRIP_GetKeySpecKeyProvider01() { boolean performed = false; @@ -1833,15 +1786,12 @@ public class EncryptedPrivateKeyInfoTest extends TestCase { /** * Encrypted data contains invalid PKCS8 key info encoding */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "In subset missed NoSuchAlgorithmException checking", - targets = { - @TestTarget( - methodName = "getKeySpec", - methodArgs = {java.security.Key.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Can not check NoSuchAlgorithmException", + method = "getKeySpec", + args = {java.security.Key.class, java.security.Provider.class} + ) public final void test_ROUNDTRIP_GetKeySpecKeyProvider02() { boolean performed = false; diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismExceptionTest.java index 0f8a372..99901ac 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismExceptionTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismExceptionTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import javax.crypto.ExemptionMechanismException; @@ -68,15 +68,12 @@ public class ExemptionMechanismExceptionTest extends TestCase { * Test for <code>ExemptionMechanismException()</code> constructor * Assertion: constructs ExemptionMechanismException with no detail message */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "ExemptionMechanismException", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "ExemptionMechanismException", + args = {} + ) public void testExemptionMechanismException01() { ExemptionMechanismException tE = new ExemptionMechanismException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -93,15 +90,12 @@ public class ExemptionMechanismExceptionTest extends TestCase { * Assertion: constructs ExemptionMechanismException with detail message * msg. Parameter <code>msg</code> is not null. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "ExemptionMechanismException", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "ExemptionMechanismException", + args = {java.lang.String.class} + ) public void testExemptionMechanismException02() { ExemptionMechanismException tE; for (int i = 0; i < msgs.length; i++) { @@ -122,15 +116,12 @@ public class ExemptionMechanismExceptionTest extends TestCase { * Assertion: constructs ExemptionMechanismException when <code>msg</code> * is null */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "ExemptionMechanismException", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "ExemptionMechanismException", + args = {java.lang.String.class} + ) public void testExemptionMechanismException03() { String msg = null; ExemptionMechanismException tE = new ExemptionMechanismException(msg); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismSpiTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismSpiTest.java index e528258..e694e55 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismSpiTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismSpiTest.java @@ -23,15 +23,19 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; +import java.math.BigInteger; import java.security.AlgorithmParameters; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.Key; +import java.security.NoSuchAlgorithmException; import java.security.spec.AlgorithmParameterSpec; +import java.security.spec.RSAKeyGenParameterSpec; + import javax.crypto.ExemptionMechanismException; import javax.crypto.ShortBufferException; import javax.crypto.ExemptionMechanismSpi; @@ -96,20 +100,15 @@ class Mock_ExemptionMechanismSpi extends MyExemptionMechanismSpi{ /** * Test for <code>ExemptionMechanismSpi</code> constructor Assertion: * constructs ExemptionMechanismSpi + * @throws Exception */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "ExemptionMechanismSpi", - methodArgs = {} - ) - }) - public void testExemptionMechanismSpi01() - throws ExemptionMechanismException, - ShortBufferException, InvalidKeyException, - InvalidAlgorithmParameterException { + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "ExemptionMechanismSpi", + args = {} + ) + public void testExemptionMechanismSpi01() throws Exception { Mock_ExemptionMechanismSpi emSpi = new Mock_ExemptionMechanismSpi(){}; int len = MyExemptionMechanismSpi.getLength(); byte [] bbRes = emSpi.engineGenExemptionBlob(); @@ -153,8 +152,8 @@ class Mock_ExemptionMechanismSpi extends MyExemptionMechanismSpi{ } key = ((MyExemptionMechanismSpi)emSpi).new tmpKey("Proba", new byte[0]); emSpi.engineInit(key); - emSpi.engineInit(key, params); - emSpi.engineInit(key, parSpec); + emSpi.engineInit(key, AlgorithmParameters.getInstance("DH")); + emSpi.engineInit(key, new RSAKeyGenParameterSpec(10, new BigInteger ("10"))); assertEquals("Incorrect result", 10, emSpi.engineGetOutputSize(100)); } diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java index 4c36900..eb2920e 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java @@ -18,17 +18,28 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; +import java.math.BigInteger; +import java.security.AlgorithmParameters; +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.spec.AlgorithmParameterSpec; +import java.security.spec.RSAKeyGenParameterSpec; +import java.util.Vector; import javax.crypto.ExemptionMechanism; +import javax.crypto.ExemptionMechanismException; import javax.crypto.ExemptionMechanismSpi; +import javax.crypto.KeyGenerator; +import javax.crypto.ShortBufferException; import org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi; import org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey; @@ -54,15 +65,12 @@ public class ExemptionMechanismTest extends TestCase { * Test for <code>ExemptionMechanism</code> constructor * Assertion: creates new object using provider and mechanism name */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "ExemptionMechanism", - methodArgs = {javax.crypto.ExemptionMechanismSpi.class, java.security.Provider.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "ExemptionMechanism", + args = {javax.crypto.ExemptionMechanismSpi.class, java.security.Provider.class, java.lang.String.class} + ) public void testExemptionMechanism() throws Exception { Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", @@ -102,15 +110,12 @@ public class ExemptionMechanismTest extends TestCase { * @tests javax/crypto/ExemptionMechanism#getInstance(String algorithm, String provider) * Checks exception order */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Regression test.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getInstance", + args = {java.lang.String.class, java.lang.String.class} + ) public void testGetInstance() throws Exception { //Regression for HARMONY-762 try { @@ -119,20 +124,23 @@ public class ExemptionMechanismTest extends TestCase { } catch (NoSuchProviderException pe) { //expected } + try { + ExemptionMechanism.getInstance("AlgName", (String)null); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException e) { + //expected + } } /** * Test for <code>isCryptoAllowed(Key key)</code> method */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Regression test.", - targets = { - @TestTarget( - methodName = "isCryptoAllowed", - methodArgs = {java.security.Key.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "isCryptoAllowed", + args = {java.security.Key.class} + ) public void testIsCryptoAllowed() throws Exception { //Regression for HARMONY-1029 @@ -166,17 +174,13 @@ public class ExemptionMechanismTest extends TestCase { /** * Test for <code>genExemptionBlob((byte[] output, int outputOffset)</code> method */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Regression test", - targets = { - @TestTarget( - methodName = "genExemptionBlob", - methodArgs = {byte[].class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Regression test", + method = "genExemptionBlob", + args = {byte[].class, int.class} + ) public void testGenExemptionBlob() throws Exception { - //Regression for HARMONY-1029 Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", @@ -195,7 +199,536 @@ public class ExemptionMechanismTest extends TestCase { em.genExemptionBlob(null, 0); em.genExemptionBlob(new byte[0], 0); em.genExemptionBlob(new byte[10], -5); + } + + static boolean flag = false; + + class Mock_ExemptionMechanism extends ExemptionMechanism { + protected Mock_ExemptionMechanism(ExemptionMechanismSpi exmechSpi, Provider provider, String mechanism) { + super(exmechSpi, provider, mechanism); + } + + @Override + protected void finalize() { + flag = true; + super.finalize(); + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "finalize", + args = {} + ) + public void test_finalize () { + Mock_ExemptionMechanism mem = new Mock_ExemptionMechanism(null, null, "Name"); + assertNotNull(mem); + mem = null; + assertFalse(flag); + Vector v = new Vector(); + int capacity; + try { + while(true) { + v.add(this); + } + } catch (OutOfMemoryError e) { + capacity = v.size(); + v = null; + } + + v = new Vector(); + for (int i = 0; i < capacity/2; i++) { + v.add(this); + } + v = null; + assertTrue(flag); + } + + class Mock_ExemptionMechanismSpi extends MyExemptionMechanismSpi { + @Override + protected byte[] engineGenExemptionBlob() + throws ExemptionMechanismException { + throw new ExemptionMechanismException(); + } + + @Override + protected int engineGenExemptionBlob(byte[] output, int outputOffset) + throws ShortBufferException, ExemptionMechanismException { + if (output.length - outputOffset < + super.engineGenExemptionBlob(output, outputOffset)) { + throw new ShortBufferException(); + } + if (output[outputOffset + 3] == 33) { + throw new ExemptionMechanismException(); + } + return super.engineGenExemptionBlob(output, outputOffset); + } + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "genExemptionBlob", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = ExemptionMechanismSpi.class, + method = "engineGenExemptionBlob", + args = {} + ) + }) + public void test_genExemptionBlob() throws InvalidKeyException, + ExemptionMechanismException { + Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", + "Provider for ExemptionMechanism testing", + srvExemptionMechanism.concat(".").concat(defaultAlg), + ExemptionMechanismProviderClass); + + ExemptionMechanism em = new ExemptionMechanism( + new MyExemptionMechanismSpi(), mProv, defaultAlg) { + }; + + Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]); + + try { + em.genExemptionBlob(); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //failed + } + em.init(key); + + assertNotNull(em.genExemptionBlob()); + + em = new ExemptionMechanism( + new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) { + }; + key = new Mock_ExemptionMechanismSpi().new tmpKey("Proba", new byte[0]); + em.init(key); + + try { + em.genExemptionBlob(); + fail("ExemptionMechanismException expected"); + } catch (ExemptionMechanismException e) { + //failed + } } + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "genExemptionBlob", + args = {byte[].class} + ) + public void test_genExemptionBlob$B() throws InvalidKeyException, + ExemptionMechanismException, ShortBufferException { + Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", + "Provider for ExemptionMechanism testing", + srvExemptionMechanism.concat(".").concat(defaultAlg), + ExemptionMechanismProviderClass); + + ExemptionMechanism em = new ExemptionMechanism( + new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) { + }; + + Key key = new Mock_ExemptionMechanismSpi().new tmpKey("Proba", new byte[0]); + + try { + em.genExemptionBlob(new byte[10]); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //failed + } + + em.init(key); + + assertEquals(5, (em.genExemptionBlob(new byte[10]))); + + try { + em.genExemptionBlob(new byte[2]); + fail("ShortBufferException expected"); + } catch (ShortBufferException e) { + //failed + } + byte[] b = new byte[] {0,0,0,33,0}; + + try { + em.genExemptionBlob(b); + fail("ExemptionMechanismException expected"); + } catch (ExemptionMechanismException e) { + //failed + } + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "genExemptionBlob", + args = {byte[].class, int.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = ExemptionMechanismSpi.class, + method = "engineGenExemptionBlob", + args = {byte[].class, int.class} + ) + }) + public void test_genExemptionBlob$BI() throws InvalidKeyException, + ExemptionMechanismException, ShortBufferException { + Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", + "Provider for ExemptionMechanism testing", + srvExemptionMechanism.concat(".").concat(defaultAlg), + ExemptionMechanismProviderClass); + + ExemptionMechanism em = new ExemptionMechanism( + new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) { + }; + + Key key = new Mock_ExemptionMechanismSpi().new tmpKey("Proba", new byte[0]); + + try { + em.genExemptionBlob(new byte[10], 2); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //failed + } + + em.init(key); + + assertEquals(5, (em.genExemptionBlob(new byte[10], 5))); + + try { + em.genExemptionBlob(new byte[7], 3); + fail("ShortBufferException expected"); + } catch (ShortBufferException e) { + //failed + } + byte[] b = new byte[] {0, 0, 0, 1, 2, 3, 33, 0}; + + try { + em.genExemptionBlob(b, 3); + fail("ExemptionMechanismException expected"); + } catch (ExemptionMechanismException e) { + //failed + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Tests Exceptions", + method = "getInstance", + args = {java.lang.String.class} + ) + public void test_getInstanceLjava_lang_String() throws Exception { + try { + ExemptionMechanism.getInstance((String) null); + fail("NullPointerException expected"); + } catch (NullPointerException e) { + //expected + } + + Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", + "Provider for ExemptionMechanism testing", + srvExemptionMechanism.concat(".").concat(defaultAlg), + ExemptionMechanismProviderClass); + + ExemptionMechanism em = new ExemptionMechanism( + new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) { + }; + + try { + em.getInstance("WrongAlgName"); + fail("NoSuchAlgorithmException expected"); + } catch (NoSuchAlgorithmException e) { + //expected + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Tests Exceptions", + method = "getInstance", + args = {java.lang.String.class, java.security.Provider.class} + ) + public void test_getInstanceLjava_lang_StringLjava_security_Provider() + throws Exception { + Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", + "Provider for ExemptionMechanism testing", + srvExemptionMechanism.concat(".").concat(defaultAlg), + ExemptionMechanismProviderClass); + + try { + ExemptionMechanism.getInstance((String) null, mProv); + fail("NullPointerException expected"); + } catch (NullPointerException e) { + //expected + } + + ExemptionMechanism em = new ExemptionMechanism( + new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) { + }; + + try { + em.getInstance("WrongAlgName", mProv); + fail("NoSuchAlgorithmException expected"); + } catch (NoSuchAlgorithmException e) { + //expected + } + + try { + em.getInstance("WrongAlgName", (Provider)null); + fail("IllegalArgumentException expected"); + } catch (IllegalArgumentException e) { + //expected + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getName", + args = {} + ) + public void test_getName() throws Exception { + Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", + "Provider for ExemptionMechanism testing", + srvExemptionMechanism.concat(".").concat(defaultAlg), + ExemptionMechanismProviderClass); + + ExemptionMechanism em = new ExemptionMechanism( + new MyExemptionMechanismSpi(), mProv, defaultAlg) { + }; + + Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]); + + assertEquals(defaultAlg, em.getName()); + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getOutputSize", + args = {int.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = ExemptionMechanismSpi.class, + method = "engineGetOutputSize", + args = {int.class} + ) + }) + public void test_getOutputSizeI() throws Exception { + Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", + "Provider for ExemptionMechanism testing", + srvExemptionMechanism.concat(".").concat(defaultAlg), + ExemptionMechanismProviderClass); + + ExemptionMechanism em = new ExemptionMechanism( + new MyExemptionMechanismSpi(), mProv, defaultAlg) { + }; + + Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]); + + try { + em.getOutputSize(10); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //failed + } + + em.init(key); + assertEquals(10, em.getOutputSize(10)); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getProvider", + args = {} + ) + public void test_getProvider() throws Exception { + Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", + "Provider for ExemptionMechanism testing", + srvExemptionMechanism.concat(".").concat(defaultAlg), + ExemptionMechanismProviderClass); + + ExemptionMechanism em = new ExemptionMechanism( + new MyExemptionMechanismSpi(), mProv, defaultAlg) { + }; + + Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]); + + assertEquals(mProv, em.getProvider()); + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {java.security.Key.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = ExemptionMechanismSpi.class, + method = "engineInit", + args = {java.security.Key.class} + ) + }) + public void test_initLjava_security_Key() throws Exception { + Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", + "Provider for ExemptionMechanism testing", + srvExemptionMechanism.concat(".").concat(defaultAlg), + ExemptionMechanismProviderClass); + + ExemptionMechanism em = new ExemptionMechanism( + new MyExemptionMechanismSpi(), mProv, defaultAlg) { + }; + + Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]); + + em.init(key); + + KeyGenerator kg = KeyGenerator.getInstance("DES"); + kg.init(56, new SecureRandom()); + key = kg.generateKey(); + + try { + em.init(null); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } + + try { + em.init(key); + fail("ExemptionMechanismException expected"); + } catch (ExemptionMechanismException e) { + //expected + } + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {java.security.Key.class, java.security.AlgorithmParameters.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = ExemptionMechanismSpi.class, + method = "engineInit", + args = {java.security.Key.class, java.security.AlgorithmParameters.class} + ) + }) + public void test_initLjava_security_KeyLjava_security_AlgorithmParameters() + throws Exception { + Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", + "Provider for ExemptionMechanism testing", + srvExemptionMechanism.concat(".").concat(defaultAlg), + ExemptionMechanismProviderClass); + + ExemptionMechanism em = new ExemptionMechanism( + new MyExemptionMechanismSpi(), mProv, defaultAlg) { + }; + + Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]); + + em.init(key, AlgorithmParameters.getInstance("DES")); + + try { + em.init(key, (AlgorithmParameters)null); + fail("InvalidAlgorithmParameterException expected"); + } catch (InvalidAlgorithmParameterException e) { + //expected + } + + KeyGenerator kg = KeyGenerator.getInstance("DES"); + kg.init(56, new SecureRandom()); + key = kg.generateKey(); + + try { + em.init(null, AlgorithmParameters.getInstance("DES")); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } + + try { + em.init(key, AlgorithmParameters.getInstance("DES")); + fail("ExemptionMechanismException expected"); + } catch (ExemptionMechanismException e) { + //expected + } + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = ExemptionMechanismSpi.class, + method = "engineInit", + args = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + ) + }) + public void test_initLjava_security_KeyLjava_security_spec_AlgorithmParameterSpec() + throws Exception{ + Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", + "Provider for ExemptionMechanism testing", + srvExemptionMechanism.concat(".").concat(defaultAlg), + ExemptionMechanismProviderClass); + + ExemptionMechanism em = new ExemptionMechanism( + new MyExemptionMechanismSpi(), mProv, defaultAlg) { + }; + + Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]); + + em.init(key, new RSAKeyGenParameterSpec(10, new BigInteger("10"))); + + try { + em.init(key, (AlgorithmParameterSpec)null); + fail("InvalidAlgorithmParameterException expected"); + } catch (InvalidAlgorithmParameterException e) { + //expected + } + + KeyGenerator kg = KeyGenerator.getInstance("DES"); + kg.init(56, new SecureRandom()); + key = kg.generateKey(); + + try { + em.init(null, new RSAKeyGenParameterSpec(10, new BigInteger("10"))); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } + + try { + em.init(key, new RSAKeyGenParameterSpec(10, new BigInteger("10"))); + fail("ExemptionMechanismException expected"); + } catch (ExemptionMechanismException e) { + //expected + } + } } + + diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/IllegalBlockSizeExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/IllegalBlockSizeExceptionTest.java index 5ec8321..d99e003 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/IllegalBlockSizeExceptionTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/IllegalBlockSizeExceptionTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import javax.crypto.IllegalBlockSizeException; @@ -63,15 +63,12 @@ public class IllegalBlockSizeExceptionTest extends TestCase { * Test for <code>IllegalBlockSizeException()</code> constructor * Assertion: constructs IllegalBlockSizeException with no detail message */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "IllegalBlockSizeException", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "IllegalBlockSizeException", + args = {} + ) public void testIllegalBlockSizeException01() { IllegalBlockSizeException tE = new IllegalBlockSizeException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -83,15 +80,12 @@ public class IllegalBlockSizeExceptionTest extends TestCase { * Assertion: constructs IllegalBlockSizeException with detail message msg. * Parameter <code>msg</code> is not null. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "IllegalBlockSizeException", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "IllegalBlockSizeException", + args = {java.lang.String.class} + ) public void testIllegalBlockSizeException02() { IllegalBlockSizeException tE; for (int i = 0; i < msgs.length; i++) { @@ -107,15 +101,12 @@ public class IllegalBlockSizeExceptionTest extends TestCase { * Assertion: constructs IllegalBlockSizeException when <code>msg</code> * is null */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "IllegalBlockSizeException", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "IllegalBlockSizeException", + args = {java.lang.String.class} + ) public void testIllegalBlockSizeException03() { String msg = null; IllegalBlockSizeException tE = new IllegalBlockSizeException(msg); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementSpiTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementSpiTest.java index cc34674..6617ea1 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementSpiTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementSpiTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; @@ -95,15 +95,12 @@ public class KeyAgreementSpiTest extends TestCase { * Test for <code>KeyAgreementSpi</code> constructor Assertion: constructs * KeyAgreementSpi */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "KeyAgreementSpi", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "KeyAgreementSpi", + args = {} + ) public void testKeyAgreementSpi01() throws InvalidKeyException, ShortBufferException, NoSuchAlgorithmException, InvalidAlgorithmParameterException { diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementTest.java index baed6e8..ed57596 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.math.BigInteger; import java.security.InvalidAlgorithmParameterException; @@ -38,9 +38,11 @@ import java.security.PublicKey; import java.security.SecureRandom; import java.security.spec.AlgorithmParameterSpec; import java.security.spec.DSAParameterSpec; +import java.security.spec.RSAKeyGenParameterSpec; import javax.crypto.KeyAgreement; import javax.crypto.KeyAgreementSpi; +import javax.crypto.ShortBufferException; import javax.crypto.interfaces.DHPrivateKey; import javax.crypto.spec.DHParameterSpec; @@ -121,15 +123,12 @@ public class KeyAgreementTest extends TestCase { * throws NullPointerException when algorithm is null throws * NoSuchAlgorithmException when algorithm isnot available */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class} + ) public void testGetInstanceString01() throws NoSuchAlgorithmException { try { KeyAgreement.getInstance(null); @@ -150,15 +149,12 @@ public class KeyAgreementTest extends TestCase { * Test for <code> getInstance(String algorithm) </code> method Assertions: * returns KeyAgreement object */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class} + ) public void testGetInstanceString02() throws NoSuchAlgorithmException { if (!DEFSupported) { fail(NotSupportMsg); @@ -177,15 +173,12 @@ public class KeyAgreementTest extends TestCase { * method Assertions: throws NullPointerException when algorithm is null * throws NoSuchAlgorithmException when algorithm is not available */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.lang.String.class} + ) public void testGetInstanceStringString01() throws NoSuchAlgorithmException, IllegalArgumentException, NoSuchProviderException { @@ -214,15 +207,12 @@ public class KeyAgreementTest extends TestCase { * or empty throws NoSuchProviderException when provider has not be * configured */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.lang.String.class} + ) public void testGetInstanceStringString02() throws IllegalArgumentException, NoSuchAlgorithmException, NoSuchProviderException { @@ -258,15 +248,12 @@ public class KeyAgreementTest extends TestCase { * Test for <code> getInstance(String algorithm, String provider)</code> * method Assertions: returns KeyAgreement object */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.lang.String.class} + ) public void testGetInstanceStringString03() throws IllegalArgumentException, NoSuchAlgorithmException, NoSuchProviderException { @@ -290,15 +277,12 @@ public class KeyAgreementTest extends TestCase { * method Assertions: throws NullPointerException when algorithm is null * throws NoSuchAlgorithmException when algorithm isnot available */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.security.Provider.class} + ) public void testGetInstanceStringProvider01() throws NoSuchAlgorithmException, IllegalArgumentException { if (!DEFSupported) { @@ -324,15 +308,12 @@ public class KeyAgreementTest extends TestCase { * Test for <code> getInstance(String algorithm, Provider provider)</code> * method Assertions: throws IllegalArgumentException when provider is null */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.security.Provider.class} + ) public void testGetInstanceStringProvider02() throws NoSuchAlgorithmException, IllegalArgumentException { if (!DEFSupported) { @@ -353,15 +334,12 @@ public class KeyAgreementTest extends TestCase { * Test for <code> getInstance(String algorithm, Provider provider)</code> * method Assertions: returns KeyAgreement object */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.security.Provider.class} + ) public void testGetInstanceStringProvider03() throws IllegalArgumentException, NoSuchAlgorithmException { if (!DEFSupported) { @@ -387,22 +365,51 @@ public class KeyAgreementTest extends TestCase { * sharedsecret in buffer and return numbers of bytes; returns SecretKey * object */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "Checks functionality only.", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {java.security.Key.class} - ), @TestTarget( - methodName = "generateSecret", - methodArgs = {} - ), @TestTarget( - methodName = "generateSecret", - methodArgs = {byte[].class, int.class} - ), @TestTarget( - methodName = "generateSecret", - methodArgs = {java.lang.String.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality only.", + method = "init", + args = {java.security.Key.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality only.", + method = "generateSecret", + args = {} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality only.", + method = "generateSecret", + args = {byte[].class, int.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality only.", + method = "generateSecret", + args = {java.lang.String.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality only.", + clazz = KeyAgreementSpi.class, + method = "engineGenerateSecret", + args = {} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality only.", + clazz = KeyAgreementSpi.class, + method = "engineGenerateSecret", + args = {byte[].class, int.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality only.", + clazz = KeyAgreementSpi.class, + method = "engineGenerateSecret", + args = {java.lang.String.class} ) }) public void testGenerateSecret03() throws Exception { @@ -433,13 +440,19 @@ public class KeyAgreementTest extends TestCase { * Test for <code>doPhase(Key key, boolean lastPhase)</code> method * Assertion: throws InvalidKeyException if key is not appropriate */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Checks InvalidKeyException.", - targets = { - @TestTarget( - methodName = "doPhase", - methodArgs = {java.security.Key.class, boolean.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "doPhase", + args = {java.security.Key.class, boolean.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = KeyAgreementSpi.class, + method = "engineDoPhase", + args = {java.security.Key.class, boolean.class} ) }) public void testDoPhase() throws Exception { @@ -449,9 +462,20 @@ public class KeyAgreementTest extends TestCase { } createKeys(); KeyAgreement[] kAgs = createKAs(); + DHParameterSpec dhPs = ((DHPrivateKey) privKey).getParams(); + SecureRandom randomNull = null; + SecureRandom random = new SecureRandom(); for (int i = 0; i < kAgs.length; i++) { + try { + kAgs[i].doPhase(publKey, true); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + kAgs[i].init(privKey); + try { kAgs[i].doPhase(privKey, false); fail("InvalidKeyException must be throw"); @@ -463,6 +487,11 @@ public class KeyAgreementTest extends TestCase { fail("InvalidKeyException must be throw"); } catch (InvalidKeyException e) { } + + kAgs[i].init(privKey, dhPs); + kAgs[i].doPhase(publKey, true); + kAgs[i].init(privKey, dhPs, random); + kAgs[i].doPhase(publKey, true); } } @@ -473,22 +502,32 @@ public class KeyAgreementTest extends TestCase { * <code>init(Key key, AlgorithmParameterSpec params, SecureRandom random)</code> * Assertion: throws InvalidKeyException when key is inappropriate */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "Checks InvalidKeyException.", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {java.security.Key.class} - ), @TestTarget( - methodName = "init", - methodArgs = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} - ), @TestTarget( - methodName = "init", - methodArgs = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} - ), @TestTarget( - methodName = "init", - methodArgs = {java.security.Key.class, java.security.SecureRandom.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks InvalidKeyException.", + method = "init", + args = {java.security.Key.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks InvalidKeyException.", + method = "init", + args = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks InvalidKeyException.", + clazz = KeyAgreementSpi.class, + method = "engineInit", + args = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks InvalidKeyException.", + clazz = KeyAgreementSpi.class, + method = "engineInit", + args = {java.security.Key.class, java.security.SecureRandom.class} ) }) public void testInit01() throws Exception { @@ -544,19 +583,21 @@ public class KeyAgreementTest extends TestCase { * Assertion: throws AlgorithmParameterException when params are * inappropriate */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "Checks InvalidAlgorithmParameterException." + - "This is a complete subset of tests for exceptions checking for init methods group", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} - ), @TestTarget( - methodName = "init", - methodArgs = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} - ) - }) + @TestTargets({ + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks InvalidAlgorithmParameterException.This is a complete subset of tests for exceptions checking for init methods group", + method = "init", + args = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks InvalidAlgorithmParameterException.This is a complete subset of tests for exceptions checking for init methods group", + clazz = KeyAgreementSpi.class, + method = "engineInit", + args = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} + ) + }) public void testInit02() throws Exception { if (!DEFSupported) { fail(NotSupportMsg); @@ -596,21 +637,47 @@ public class KeyAgreementTest extends TestCase { * <code>generateSecret()</code> * Assertions: initializes KeyAgreement and returns byte array */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "Checks functionality.", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {java.security.Key.class} - ), @TestTarget( - methodName = "init", - methodArgs = {java.security.Key.class, java.security.SecureRandom.class} - ), @TestTarget( - methodName = "generateSecret", - methodArgs = {} + @TestTargets({ + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality.", + method = "init", + args = {java.security.Key.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality.", + method = "init", + args = {java.security.Key.class, java.security.SecureRandom.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality.", + method = "generateSecret", + args = {} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality.", + clazz = KeyAgreementSpi.class, + method = "engineInit", + args = {java.security.Key.class, java.security.SecureRandom.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality.", + clazz = KeyAgreementSpi.class, + method = "engineInit", + args = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality.", + clazz = KeyAgreementSpi.class, + method = "engineGenerateSecret", + args = {} ) - }) + }) public void testInit03() throws Exception { if (!DEFSupported) { fail(NotSupportMsg); @@ -656,21 +723,47 @@ public class KeyAgreementTest extends TestCase { * <code>generateSecret()</code> * Assertions: initializes KeyAgreement and returns byte array */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Checks functionality.", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} - ), @TestTarget( - methodName = "init", - methodArgs = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} - ), @TestTarget( - methodName = "generateSecret", - methodArgs = {} + @TestTargets({ + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Checks functionality.", + method = "init", + args = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks functionality.", + method = "init", + args = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Checks functionality.", + method = "generateSecret", + args = {} + ), + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Checks functionality.", + clazz = KeyAgreementSpi.class, + method = "engineInit", + args = {java.security.Key.class, SecureRandom.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Checks functionality.", + clazz = KeyAgreementSpi.class, + method = "engineInit", + args = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Checks functionality.", + clazz = KeyAgreementSpi.class, + method = "engineGenerateSecret", + args = {} ) -}) + }) public void testInit04() throws Exception, InvalidAlgorithmParameterException { if (!DEFSupported) { @@ -681,6 +774,7 @@ public class KeyAgreementTest extends TestCase { KeyAgreement[] kAgs = createKAs(); DHParameterSpec dhPs = ((DHPrivateKey) privKey).getParams(); + AlgorithmParameterSpec aps = new RSAKeyGenParameterSpec(10, new BigInteger("10")); byte[] bbRes1; byte[] bbRes2; @@ -709,7 +803,171 @@ public class KeyAgreementTest extends TestCase { assertEquals("Incorrect byte (index: ".concat( Integer.toString(i)).concat(")"), bbRes1[j], bbRes3[j]); } + + try { + kAgs[i].init(publKey, dhPs, random); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } + try { + kAgs[i].init(privKey, aps, random); + fail("InvalidAlgorithmParameterException expected"); + } catch (InvalidAlgorithmParameterException e) { + //expected + } } } + class Mock_KeyAgreement extends KeyAgreement { + protected Mock_KeyAgreement(KeyAgreementSpi arg0, Provider arg1, String arg2) { + super(arg0, arg1, arg2); + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "KeyAgreement", + args = {javax.crypto.KeyAgreementSpi.class, java.security.Provider.class, java.lang.String.class} + ) + public void test_constructor() { + assertNotNull(new Mock_KeyAgreement(null, null, null)); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getAlgorithm", + args = {} + ) + public void test_getAlgorithm() throws NoSuchAlgorithmException { + Mock_KeyAgreement mka = new Mock_KeyAgreement(null, null, null); + assertNull(mka.getAlgorithm()); + + KeyAgreement keyA; + for (int i = 0; i < validValues.length; i++) { + keyA = KeyAgreement.getInstance(validValues[i]); + assertEquals("Incorrect algorithm", keyA.getAlgorithm(), + validValues[i]); + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getProvider", + args = {} + ) + public void test_getProvider() throws NoSuchAlgorithmException { + KeyAgreement keyA; + for (int i = 0; i < validValues.length; i++) { + keyA = KeyAgreement.getInstance(validValues[i]); + assertNotNull(keyA.getProvider()); + } + } + +@TestTargets({ + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "", + method = "generateSecret", + args = {byte[].class, int.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "", + clazz = KeyAgreementSpi.class, + method = "engineGenerateSecret", + args = {byte[].class, int.class} + )}) + public void test_generateSecret$BI() throws Exception { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + createKeys(); + KeyAgreement[] kAgs = createKAs(); + KeyAgreement ka = KeyAgreement.getInstance("DH"); + + byte[] bb1 = new byte[1]; + try { + ka.generateSecret(bb1, 0); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + ka.init(privKey); + ka.doPhase(publKey, true); + try { + ka.generateSecret(bb1, 0); + fail("ShortBufferException expected"); + } catch (ShortBufferException e) { + //expected + } + } + +@TestTargets({ + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "", + method = "generateSecret", + args = {java.lang.String.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "", + clazz = KeyAgreementSpi.class, + method = "engineGenerateSecret", + args = {java.lang.String.class} + )}) + public void test_generateSecretLjava_lang_String() throws Exception { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + createKeys(); + KeyAgreement[] kAgs = createKAs(); + KeyAgreement ka = KeyAgreement.getInstance("DH"); + + byte[] bb1 = new byte[1]; + try { + ka.generateSecret("dh"); + fail("IllegalStateException expected"); + } catch (IllegalStateException e) { + //expected + } + ka.init(privKey); + ka.doPhase(publKey, true); + try { + ka.generateSecret("Wrong alg name"); + fail("NoSuchAlgorithmException expected"); + } catch (NoSuchAlgorithmException e) { + //expected + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {java.security.Key.class, java.security.SecureRandom.class} + ) + public void test_initLjava_security_KeyLjava_security_SecureRandom() throws Exception { + if (!DEFSupported) { + fail(NotSupportMsg); + return; + } + createKeys(); + KeyAgreement[] kAgs = createKAs(); + KeyAgreement ka = KeyAgreement.getInstance("DH"); + + ka.init(privKey, new SecureRandom()); + try { + ka.init(publKey, new SecureRandom()); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } + } } diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorSpiTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorSpiTest.java index f5c3f23..bcf2635 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorSpiTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorSpiTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.security.InvalidAlgorithmParameterException; import java.security.SecureRandom; @@ -80,15 +80,12 @@ class Mock_KeyGeneratorSpi extends MyKeyGeneratorSpi { * Test for <code>KeyGeneratorSpi</code> constructor Assertion: constructs * KeyGeneratorSpi */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "KeyGeneratorSpi", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "KeyGeneratorSpi", + args = {} + ) public void testKeyGeneratorSpi01() throws InvalidAlgorithmParameterException { Mock_KeyGeneratorSpi kgSpi = new Mock_KeyGeneratorSpi(); assertNull("Not null result", kgSpi.engineGenerateKey()); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorTest.java index e7b1985..8451979 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorTest.java @@ -23,10 +23,11 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; +import java.math.BigInteger; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidParameterException; import java.security.NoSuchAlgorithmException; @@ -34,10 +35,14 @@ import java.security.NoSuchProviderException; import java.security.Provider; import java.security.SecureRandom; import java.security.spec.AlgorithmParameterSpec; +import java.security.spec.DSAParameterSpec; +import java.security.spec.RSAKeyGenParameterSpec; +import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.KeyGeneratorSpi; import javax.crypto.SecretKey; +import javax.crypto.spec.IvParameterSpec; import org.apache.harmony.crypto.tests.support.MyKeyGeneratorSpi; import org.apache.harmony.security.tests.support.SpiEngUtils; @@ -56,9 +61,9 @@ public class KeyGeneratorTest extends TestCase { public static final String srvKeyGenerator = "KeyGenerator"; public static final String validAlgorithmsKeyGenerator [] = - {"DESede", "DES", "Blowfish", "AES", "HmacMD5"}; + {"DESede", "DES", "AES", "HmacMD5"}; - private static final int [] validKeySizes = { 168, 56, 56, 256, 56}; + private static final int [] validKeySizes = { 168, 56, 256, 56}; private static int defaultKeySize = -1; @@ -110,15 +115,12 @@ public class KeyGeneratorTest extends TestCase { * Test for <code>KeyGenerator</code> constructor Assertion: returns * KeyGenerator object */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "KeyGenerator", - methodArgs = {javax.crypto.KeyGeneratorSpi.class, java.security.Provider.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "KeyGenerator", + args = {javax.crypto.KeyGeneratorSpi.class, java.security.Provider.class, java.lang.String.class} + ) public void testKeyGenerator() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { if (!DEFSupported) { @@ -165,15 +167,12 @@ public class KeyGeneratorTest extends TestCase { * throws NullPointerException when algorithm is null throws * NoSuchAlgorithmException when algorithm isnot available */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class} + ) public void testGetInstanceString01() throws NoSuchAlgorithmException { try { KeyGenerator.getInstance(null); @@ -194,15 +193,12 @@ public class KeyGeneratorTest extends TestCase { * Test for <code> getInstance(String algorithm) </code> method * Assertions: returns KeyGenerator object */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class} + ) public void testGetInstanceString02() throws NoSuchAlgorithmException { if (!DEFSupported) { fail(NotSupportMsg); @@ -221,15 +217,12 @@ public class KeyGeneratorTest extends TestCase { * throws NullPointerException when algorithm is null * throws NoSuchAlgorithmException when algorithm isnot available */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.lang.String.class} + ) public void testGetInstanceStringString01() throws NoSuchAlgorithmException, IllegalArgumentException, NoSuchProviderException { @@ -258,15 +251,12 @@ public class KeyGeneratorTest extends TestCase { * throws IllegalArgumentException when provider is null or empty * throws NoSuchProviderException when provider has not be configured */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.lang.String.class} + ) public void testGetInstanceStringString02() throws IllegalArgumentException, NoSuchAlgorithmException, NoSuchProviderException { if (!DEFSupported) { @@ -301,15 +291,12 @@ public class KeyGeneratorTest extends TestCase { * Test for <code> getInstance(String algorithm, String provider)</code> method * Assertions: returns KeyGenerator object */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.lang.String.class} + ) public void testGetInstanceStringString03() throws IllegalArgumentException, NoSuchAlgorithmException, NoSuchProviderException { if (!DEFSupported) { @@ -330,15 +317,12 @@ public class KeyGeneratorTest extends TestCase { * throws NullPointerException when algorithm is null * throws NoSuchAlgorithmException when algorithm isnot available */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.security.Provider.class} + ) public void testGetInstanceStringProvider01() throws NoSuchAlgorithmException, IllegalArgumentException { if (!DEFSupported) { @@ -364,15 +348,12 @@ public class KeyGeneratorTest extends TestCase { * Assertions: * throws IllegalArgumentException when provider is null */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.security.Provider.class} + ) public void testGetInstanceStringProvider02() throws NoSuchAlgorithmException, IllegalArgumentException { if (!DEFSupported) { @@ -393,15 +374,12 @@ public class KeyGeneratorTest extends TestCase { * Test for <code> getInstance(String algorithm, Provider provider)</code> method * Assertions: returns KeyGenerator object */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.security.Provider.class} + ) public void testGetInstanceStringProvider03() throws IllegalArgumentException, NoSuchAlgorithmException { if (!DEFSupported) { @@ -422,19 +400,20 @@ public class KeyGeneratorTest extends TestCase { * Assertion: throws InvalidParameterException if keysize is wrong * */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Checks exceptions only", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {int.class} - ),@TestTarget( - methodName = "init", - methodArgs = {int.class, java.security.SecureRandom.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + method = "init", + args = {int.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + method = "init", + args = {int.class, java.security.SecureRandom.class} ) }) public void testInitKey() throws Exception { + byte flag = 0xF; if (!DEFSupported) { fail(NotSupportMsg); return; @@ -443,7 +422,7 @@ public class KeyGeneratorTest extends TestCase { .equals(validAlgorithmsKeyGenerator[validAlgorithmsKeyGenerator.length - 1])) { return; } - int[] size = { Integer.MIN_VALUE, -1, 0, Integer.MAX_VALUE }; + int[] size = { Integer.MIN_VALUE, -1, 0, 112, 168, Integer.MAX_VALUE }; KeyGenerator[] kgs = createKGs(); SecureRandom random = new SecureRandom(); @@ -451,15 +430,20 @@ public class KeyGeneratorTest extends TestCase { for (int j = 0; j < size.length; j++) { try { kgs[i].init(size[j]); + flag &= 0xE; } catch (InvalidParameterException ignore) { + flag &= 0xD; } try { kgs[i].init(size[j], random); - } catch (InvalidParameterException ignore) { + flag &= 0xB; + } catch (InvalidParameterException ignore) { + flag &= 0x7; } } } + assertTrue(flag == 0); } /* @@ -467,16 +451,25 @@ public class KeyGeneratorTest extends TestCase { * <code>init(AlgorithmParameterSpec params, SecureRandom random)</code> methods * Assertion: throws InvalidAlgorithmParameterException when params is null */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Checks exceptions only", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {java.security.spec.AlgorithmParameterSpec.class} - ), @TestTarget( - methodName = "init", - methodArgs = {java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks exceptions only", + method = "init", + args = {java.security.spec.AlgorithmParameterSpec.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks exceptions only", + method = "init", + args = {java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks exceptions only", + clazz = KeyGeneratorSpi.class, + method = "engineInit", + args = {java.security.spec.AlgorithmParameterSpec.class, java.security.SecureRandom.class} ) }) public void testInitParams() throws Exception { @@ -513,13 +506,19 @@ public class KeyGeneratorTest extends TestCase { * returns SecretKey object * */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "generateKey", - methodArgs = {} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "generateKey", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = KeyGeneratorSpi.class, + method = "engineGenerateKey", + args = {} ) }) public void testGenerateKey() throws Exception { @@ -551,6 +550,132 @@ public class KeyGeneratorTest extends TestCase { } } + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getAlgorithm", + args = {} + ) + public void test_getAlgorithm() throws NoSuchAlgorithmException { + KeyGenerator kg = null; + + for (int i = 0; i < validAlgorithmsKeyGenerator.length; i++) { + kg = KeyGenerator.getInstance(validAlgorithmsKeyGenerator[i]); + assertEquals(validAlgorithmsKeyGenerator[i], kg.getAlgorithm()); + } + + kg = new myKeyGenerator(null, null, null); + assertNull(kg.getAlgorithm()); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getProvider", + args = {} + ) + public void test_getProvider () throws NoSuchAlgorithmException { + KeyGenerator kg = null; + + for (int i = 0; i < validAlgorithmsKeyGenerator.length; i++) { + kg = KeyGenerator.getInstance(validAlgorithmsKeyGenerator[i]); + assertNotNull(kg.getProvider()); + } + + kg = new myKeyGenerator(null, null, null); + assertNull(kg.getProvider()); + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {int.class, java.security.SecureRandom.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = KeyGeneratorSpi.class, + method = "engineInit", + args = {int.class, java.security.SecureRandom.class} + ) + }) + public void test_initILjava_security_SecureRandom() throws NoSuchAlgorithmException { + SecureRandom random = null; + KeyGenerator kg = null; + + for (int i = 0; i < validAlgorithmsKeyGenerator.length; i++) { + kg = KeyGenerator.getInstance(validAlgorithmsKeyGenerator[i]); + random = new SecureRandom(); + kg.init(validKeySizes[i], random); + assertNotNull(kg.getProvider()); + } + + kg = KeyGenerator.getInstance(validAlgorithmsKeyGenerator[0]); + + try { + kg.init(5, random); + fail("InvalidParameterException expected"); + } catch (InvalidParameterException e) { + //expected + } + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {java.security.SecureRandom.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = KeyGeneratorSpi.class, + method = "engineInit", + args = {java.security.SecureRandom.class} + ) + }) + public void test_Ljava_security_SecureRandom() throws NoSuchAlgorithmException { + SecureRandom random = null; + KeyGenerator kg = null; + + for (int i = 0; i < validAlgorithmsKeyGenerator.length; i++) { + kg = KeyGenerator.getInstance(validAlgorithmsKeyGenerator[i]); + random = new SecureRandom(); + kg.init(random); + assertNotNull(kg.getProvider()); + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "init", + args = {java.security.spec.AlgorithmParameterSpec.class} + ) + public void test_initLjava_security_spec_AlgorithmParameterSpec () + throws Exception { + KeyGenerator kg = null; + + IvParameterSpec aps = null; + SecureRandom sr = new SecureRandom(); + + byte[] iv = null; + iv = new byte[8]; + sr.nextBytes(iv); + aps = new IvParameterSpec(iv); + + for (int i = 0; i < validAlgorithmsKeyGenerator.length; i++) { + kg = KeyGenerator.getInstance(validAlgorithmsKeyGenerator[i]); + try { + kg.init(aps); + } catch (InvalidAlgorithmParameterException e) { + } + assertNotNull(kg.getProvider()); + } + } } /** diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/MacSpiTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/MacSpiTest.java index f5ecfdf..d7a2ec1 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/MacSpiTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/MacSpiTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.nio.ByteBuffer; import java.security.InvalidAlgorithmParameterException; @@ -173,19 +173,24 @@ class Mock_MacSpi2 extends MyMacSpi2 { * Test for <code>MacSpi</code> constructor * Assertion: constructs MacSpi */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "All others methods are abstract.", - targets = { - @TestTarget( - methodName = "MacSpi", - methodArgs = {} - ), @TestTarget( - methodName = "engineUpdate", - methodArgs = {java.nio.ByteBuffer.class} - ), @TestTarget( - methodName = "clone", - methodArgs = {} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All others methods are abstract.", + method = "MacSpi", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All others methods are abstract.", + method = "engineUpdate", + args = {java.nio.ByteBuffer.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All others methods are abstract.", + method = "clone", + args = {} ) }) public void testMacSpiTests01() throws Exception { diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/MacTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/MacTest.java index 84f663c..750342c 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/MacTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/MacTest.java @@ -23,16 +23,19 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; +import java.math.BigInteger; import java.nio.ByteBuffer; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.Provider; +import java.security.spec.DSAParameterSpec; +import java.security.spec.PSSParameterSpec; import javax.crypto.Mac; import javax.crypto.MacSpi; @@ -115,15 +118,12 @@ public class MacTest extends TestCase { * throws NullPointerException when algorithm is null * throws NoSuchAlgorithmException when algorithm is not available */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class} + ) public void testMac01() { try { Mac.getInstance(null); @@ -145,15 +145,12 @@ public class MacTest extends TestCase { * Test for <code>getInstance(String algorithm)</code> method * Assertion: returns Mac object */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class} + ) public void testMac02() throws NoSuchAlgorithmException { if (!DEFSupported) { fail(NotSupportedMsg); @@ -171,15 +168,12 @@ public class MacTest extends TestCase { * throws IllegalArgumentException when provider is null or empty * throws NoSuchProviderException when provider is not available */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.lang.String.class} + ) public void testMac03() throws NoSuchAlgorithmException, NoSuchProviderException { if (!DEFSupported) { fail(NotSupportedMsg); @@ -215,15 +209,12 @@ public class MacTest extends TestCase { * throws NullPointerException when algorithm is null * throws NoSuchAlgorithmException when algorithm is not available */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.lang.String.class} + ) public void testMac04() throws NoSuchAlgorithmException, IllegalArgumentException, NoSuchProviderException { if (!DEFSupported) { @@ -249,15 +240,12 @@ public class MacTest extends TestCase { * Test for <code>getInstance(String algorithm, String provider)</code> method * Assertion: returns Mac object */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.lang.String.class} + ) public void testMac05() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException { if (!DEFSupported) { @@ -277,15 +265,12 @@ public class MacTest extends TestCase { * Test for <code>getInstance(String algorithm, Provider provider)</code> method * Assertion: throws IllegalArgumentException when provider is null */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.security.Provider.class} + ) public void testMac06() throws NoSuchAlgorithmException, NoSuchProviderException { if (!DEFSupported) { fail(NotSupportedMsg); @@ -306,15 +291,12 @@ public class MacTest extends TestCase { * throws NullPointerException when algorithm is null * throws NoSuchAlgorithmException when algorithm is not available */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.security.Provider.class} + ) public void testMac07() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException { if (!DEFSupported) { @@ -341,15 +323,12 @@ public class MacTest extends TestCase { * Test for <code>getInstance(String algorithm, Provider provider)</code> method * Assertion: returns Mac object */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.security.Provider.class} + ) public void testMac08() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException { if (!DEFSupported) { @@ -366,36 +345,74 @@ public class MacTest extends TestCase { /** * Test for <code>update</code> and <code>doFinal</code> methods * Assertion: throws IllegalStateException when Mac is not initialized + * @throws Exception */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Checks IllegalStateException only but for all methods." + - " Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {} - ),@TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class} - ),@TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class, int.class} - ),@TestTarget( - methodName = "update", - methodArgs = {byte.class} - ),@TestTarget( - methodName = "update", - methodArgs = {byte[].class} - ),@TestTarget( - methodName = "update", - methodArgs = {byte[].class, int.class, int.class} - ),@TestTarget( - methodName = "update", - methodArgs = {java.nio.ByteBuffer.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + method = "doFinal", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + clazz = MacSpi.class, + method = "engineDoFinal", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + method = "doFinal", + args = {byte[].class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + method = "doFinal", + args = {byte[].class, int.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + method = "update", + args = {byte.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + clazz = MacSpi.class, + method = "engineUpdate", + args = {byte.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + method = "update", + args = {byte[].class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + method = "update", + args = {byte[].class, int.class, int.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + clazz = MacSpi.class, + method = "engineUpdate", + args = {byte[].class, int.class, int.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + method = "update", + args = {java.nio.ByteBuffer.class} ) }) - public void testMac09() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException, ShortBufferException { + public void testMac09() throws Exception { if (!DEFSupported) { fail(NotSupportedMsg); return; @@ -404,6 +421,8 @@ public class MacTest extends TestCase { assertNotNull("Mac objects were not created", macs); byte [] buf = new byte[10]; ByteBuffer bBuf = ByteBuffer.wrap(buf, 0, 10); + byte [] bb = {(byte)1, (byte)2, (byte)3, (byte)4, (byte)5}; + SecretKeySpec sks = new SecretKeySpec(bb, "SHA1"); for (int i = 0; i < macs.length; i++) { try { macs[i].update((byte)0); @@ -440,6 +459,14 @@ public class MacTest extends TestCase { fail("IllegalStateException must be thrown"); } catch (IllegalStateException e) { } + + macs[i].init(sks); + try { + macs[i].doFinal(new byte[1], 0); + fail("ShortBufferException expected"); + } catch (ShortBufferException e) { + //expected + } } } /** @@ -448,15 +475,12 @@ public class MacTest extends TestCase { * throws ShotBufferException when outOffset is negative or * outOffset >= output.length or when given buffer is small */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Checks ShortBufferException", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks ShortBufferException", + method = "doFinal", + args = {byte[].class, int.class} + ) public void testMac10() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException, IllegalStateException, InvalidKeyException { @@ -505,16 +529,25 @@ public class MacTest extends TestCase { * <code>doFinal()</code> methods Assertion: Mac result is stored in * output buffer */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Checks functionality.", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {} - ),@TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class, int.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality.", + method = "doFinal", + args = {} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + clazz = MacSpi.class, + method = "engineDoFinal", + args = {} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality.", + method = "doFinal", + args = {byte[].class, int.class} ) }) public void testMac11() throws NoSuchAlgorithmException, NoSuchProviderException, @@ -543,16 +576,25 @@ public class MacTest extends TestCase { * Test for <code>doFinal(byte[] input)</code> method * Assertion: update Mac and returns result */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Checks functionality.", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {} - ), @TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality.", + method = "doFinal", + args = {} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + clazz = MacSpi.class, + method = "engineDoFinal", + args = {} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality.", + method = "doFinal", + args = {byte[].class} ) }) public void testMac12() throws NoSuchAlgorithmException, NoSuchProviderException, @@ -590,13 +632,19 @@ public class MacTest extends TestCase { * Assertion: throws IllegalArgumentException when offset or len is negative, * offset + len >= input.length */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Checks IllegalArgumentException", - targets = { - @TestTarget( - methodName = "update", - methodArgs = {byte[].class, int.class, int.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks IllegalArgumentException", + method = "update", + args = {byte[].class, int.class, int.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + clazz = MacSpi.class, + method = "engineUpdate", + args = {byte[].class, int.class, int.class} ) }) public void testMac13() throws NoSuchAlgorithmException, @@ -640,16 +688,32 @@ public class MacTest extends TestCase { * methods * Assertion: updates Mac */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Checks functionality.", - targets = { - @TestTarget( - methodName = "update", - methodArgs = {byte.class} - ),@TestTarget( - methodName = "update", - methodArgs = {byte[].class, int.class, int.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality.", + method = "update", + args = {byte.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + clazz = MacSpi.class, + method = "engineUpdate", + args = {byte.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality.", + method = "update", + args = {byte[].class, int.class, int.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + clazz = MacSpi.class, + method = "engineUpdate", + args = {byte[].class, int.class, int.class} ) }) public void testMac14() throws NoSuchAlgorithmException, @@ -694,15 +758,12 @@ public class MacTest extends TestCase { * Test for <code>clone()</code> method * Assertion: returns Mac object or throws CloneNotSupportedException */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "clone", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "clone", + args = {} + ) public void testMacClone() throws NoSuchAlgorithmException, CloneNotSupportedException { if (!DEFSupported) { fail(NotSupportedMsg); @@ -728,16 +789,25 @@ public class MacTest extends TestCase { * Assertion: throws InvalidKeyException and InvalidAlgorithmParameterException * when parameters are not appropriate */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Checks exceptions", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {java.security.Key.class} - ),@TestTarget( - methodName = "init", - methodArgs = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks exceptions", + method = "init", + args = {java.security.Key.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks exceptions", + method = "init", + args = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks exceptions", + clazz = MacSpi.class, + method = "engineInit", + args = {java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} ) }) public void testInit() throws NoSuchAlgorithmException, NoSuchProviderException, @@ -752,8 +822,16 @@ public class MacTest extends TestCase { byte [] b = {(byte)1, (byte)2, (byte)3, (byte)4, (byte)5}; SecretKeySpec sks = new SecretKeySpec(b, "SHA1"); DHGenParameterSpec algPS = new DHGenParameterSpec(1, 2); - + PSSParameterSpec algPSS = new PSSParameterSpec(20); + SecretKeySpec sks1 = new SecretKeySpec(b, "RSA"); + for (int i = 0; i < macs.length; i++) { + macs[i].init(sks); + try { + macs[i].init(sks1, algPSS); + fail("init(..) accepts incorrect AlgorithmParameterSpec parameter"); + } catch (InvalidAlgorithmParameterException e) { + } try { macs[i].init(sks, algPS); fail("init(..) accepts incorrect AlgorithmParameterSpec parameter"); @@ -771,6 +849,7 @@ public class MacTest extends TestCase { fail("InvalidKeyException must be thrown"); } catch (InvalidKeyException e) { } +// macs[i].init(sks, null); } } @@ -780,16 +859,25 @@ public class MacTest extends TestCase { * methods * Assertion: processes Mac; if input is null then do nothing */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Checks functionality", - targets = { - @TestTarget( - methodName = "update", - methodArgs = {byte[].class, int.class, int.class} - ),@TestTarget( - methodName = "update", - methodArgs = {java.nio.ByteBuffer.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality", + method = "update", + args = {byte[].class, int.class, int.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + clazz = MacSpi.class, + method = "engineUpdate", + args = {byte[].class, int.class, int.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality", + method = "update", + args = {java.nio.ByteBuffer.class} ) }) public void testUpdateByteBuffer01() throws NoSuchAlgorithmException, NoSuchProviderException, @@ -835,16 +923,25 @@ public class MacTest extends TestCase { * methods * Assertion: processes Mac */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Checks functionality", - targets = { - @TestTarget( - methodName = "update", - methodArgs = {java.nio.ByteBuffer.class} - ),@TestTarget( - methodName = "update", - methodArgs = {byte[].class, int.class, int.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality", + method = "update", + args = {java.nio.ByteBuffer.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks functionality", + method = "update", + args = {byte[].class, int.class, int.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException", + clazz = MacSpi.class, + method = "engineUpdate", + args = {byte[].class, int.class, int.class} ) }) public void testUpdateByteBuffer02() throws NoSuchAlgorithmException, NoSuchProviderException, @@ -882,15 +979,12 @@ public class MacTest extends TestCase { * Test for <code>clone()</code> method * Assertion: clone if provider is clo */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "clone", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "clone", + args = {} + ) public void testClone() { if (!DEFSupported) { fail(NotSupportedMsg); @@ -912,13 +1006,19 @@ public class MacTest extends TestCase { * Test for <code>getMacLength()</code> method * Assertion: return Mac length */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getMacLength", - methodArgs = {} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getMacLength", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = MacSpi.class, + method = "engineGetMacLength", + args = {} ) }) public void testGetMacLength() { @@ -937,13 +1037,19 @@ public class MacTest extends TestCase { * Test for <code>reset()</code> method * Assertion: return Mac length */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "reset", - methodArgs = {} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "reset", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = MacSpi.class, + method = "engineReset", + args = {} ) }) public void testReset() throws InvalidKeyException { @@ -983,15 +1089,12 @@ public class MacTest extends TestCase { * Test for <code>Mac</code> constructor * Assertion: returns Mac object */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "Mac", - methodArgs = {javax.crypto.MacSpi.class, java.security.Provider.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "Mac", + args = {javax.crypto.MacSpi.class, java.security.Provider.class, java.lang.String.class} + ) public void testMacConstructor() throws NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException { if (!DEFSupported) { @@ -1024,6 +1127,46 @@ public class MacTest extends TestCase { } catch (NullPointerException e) { } } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getAlgorithm", + args = {} + ) + public void test_getAlgorithm() throws NoSuchAlgorithmException { + Mac mac; + for (int i = 0; i < validValues.length; i++) { + mac = Mac.getInstance(validValues[i]); + assertEquals("Incorrect algorithm", mac.getAlgorithm(), validValues[i]); + } + + mac = new Mock_Mac(null, null, null); + assertNull(mac.getAlgorithm()); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getProvider", + args = {} + ) + public void test_getProvider() throws NoSuchAlgorithmException { + Mac mac; + for (int i = 0; i < validValues.length; i++) { + mac = Mac.getInstance(validValues[i]); + assertNotNull(mac.getProvider()); + } + + mac = new Mock_Mac(null, null, null); + assertNull(mac.getProvider()); + } + + class Mock_Mac extends Mac { + protected Mock_Mac(MacSpi arg0, Provider arg1, String arg2) { + super(arg0, arg1, arg2); + } + } public static Test suite() { return new TestSuite(MacTest.class); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/NoSuchPaddingExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/NoSuchPaddingExceptionTest.java index 88b1bda..01418c8 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/NoSuchPaddingExceptionTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/NoSuchPaddingExceptionTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import javax.crypto.NoSuchPaddingException; @@ -63,15 +63,12 @@ public class NoSuchPaddingExceptionTest extends TestCase { * Test for <code>NoSuchPaddingException()</code> constructor Assertion: * constructs NoSuchPaddingException with no detail message */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "NoSuchPaddingException", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "NoSuchPaddingException", + args = {} + ) public void testNoSuchPaddingException01() { NoSuchPaddingException tE = new NoSuchPaddingException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -83,15 +80,12 @@ public class NoSuchPaddingExceptionTest extends TestCase { * Assertion: constructs NoSuchPaddingException with detail message msg. * Parameter <code>msg</code> is not null. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "NoSuchPaddingException", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "NoSuchPaddingException", + args = {java.lang.String.class} + ) public void testNoSuchPaddingException02() { NoSuchPaddingException tE; for (int i = 0; i < msgs.length; i++) { @@ -107,15 +101,12 @@ public class NoSuchPaddingExceptionTest extends TestCase { * Assertion: constructs NoSuchPaddingException when <code>msg</code> is * null */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "NoSuchPaddingException", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "NoSuchPaddingException", + args = {java.lang.String.class} + ) public void testNoSuchPaddingException03() { String msg = null; NoSuchPaddingException tE = new NoSuchPaddingException(msg); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java index aea4b3f..f521690 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java @@ -23,14 +23,15 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.security.SecureRandom; import java.util.Arrays; import javax.crypto.Cipher; +import javax.crypto.CipherSpi; import javax.crypto.NullCipher; import javax.crypto.spec.SecretKeySpec; @@ -50,80 +51,79 @@ public class NullCipherTest extends TestCase { c = new NullCipher(); } -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "Class checks inherited methods.", - targets = { - @TestTarget( - methodName = "getAlgorithm", - methodArgs = {} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Class checks inherited methods.", + method = "getAlgorithm", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Class checks inherited methods.", + method = "NullCipher", + args = {} ) }) public void testGetAlgorithm() { c.getAlgorithm(); } -@TestInfo( + @TestTargetNew( level = TestLevel.COMPLETE, - purpose = "Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "getBlockSize", - methodArgs = {} - ) - }) + notes = "Checks inherited method from Cipher.", + method = "getBlockSize", + args = {} + ) public void testGetBlockSize() { assertEquals("Incorrect BlockSize", 1, c.getBlockSize()); } -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "IllegalStateException checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "getOutputSize", - methodArgs = {int.class} - ) - }) + notes = "IllegalStateException checking missed. Checks inherited method from Cipher.", + method = "getOutputSize", + args = {int.class} + ) public void testGetOutputSize() { assertEquals("Incorrect OutputSize", 111, c.getOutputSize(111)); } -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "getIV", - methodArgs = {} - ) - }) + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks inherited method from Cipher.", + method = "getIV", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks inherited method from Cipher.", + clazz = CipherSpi.class, + method = "engineGetIV", + args = {} + ) + }) public void testGetIV() { assertTrue("Incorrect IV", Arrays.equals(c.getIV(), new byte[8])); } -@TestInfo( + @TestTargetNew( level = TestLevel.COMPLETE, - purpose = "Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "getParameters", - methodArgs = {} - ) - }) + notes = "Checks inherited method from Cipher.", + method = "getParameters", + args = {} + ) public void testGetParameters() { assertNull("Incorrect Parameters", c.getParameters()); } -@TestInfo( + @TestTargetNew( level = TestLevel.COMPLETE, - purpose = "Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "getExemptionMechanism", - methodArgs = {} - ) - }) + notes = "Checks inherited method from Cipher.", + method = "getExemptionMechanism", + args = {} + ) public void testGetExemptionMechanism() { assertNull("Incorrect ExemptionMechanism", c.getExemptionMechanism()); } @@ -131,15 +131,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for void init(int, Key) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "InvalidKeyException checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {int.class, java.security.Key.class} - ) - }) + notes = "InvalidKeyException checking missed. Checks inherited method from Cipher.", + method = "init", + args = {int.class, java.security.Key.class} + ) public void testInitintKey() throws Exception { c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(new byte[1], "algorithm")); @@ -148,15 +145,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for void init(int, Key, SecureRandom) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "InvalidKeyException checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {int.class, java.security.Key.class, java.security.SecureRandom.class} - ) - }) + notes = "InvalidKeyException checking missed. Checks inherited method from Cipher.", + method = "init", + args = {int.class, java.security.Key.class, java.security.SecureRandom.class} + ) public void testInitintKeySecureRandom() throws Exception { c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(new byte[1], "algorithm"), new SecureRandom()); @@ -165,15 +159,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for void init(int, Key, AlgorithmParameterSpec) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "init", - methodArgs = {int.class, java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} - ) - }) + notes = "Exceptions checking missed. Checks inherited method from Cipher.", + method = "init", + args = {int.class, java.security.Key.class, java.security.spec.AlgorithmParameterSpec.class} + ) public void testInitintKeyAlgorithmParameterSpec() throws Exception { class myAlgorithmParameterSpec implements java.security.spec.AlgorithmParameterSpec {} c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(new byte[1], @@ -183,15 +174,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for byte[] update(byte[]) */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "IllegalStateException checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "update", - methodArgs = {byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "IllegalStateException checking missed. Checks inherited method from Cipher.", + method = "update", + args = {byte[].class} + ) public void testUpdatebyteArray() throws Exception { byte [] b = {1, 2, 3, 4, 5}; byte [] r = c.update(b); @@ -202,15 +190,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for byte[] update(byte[], int, int) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "IllegalStateException checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "update", - methodArgs = {byte[].class, int.class, int.class} - ) - }) + notes = "IllegalStateException checking missed. Checks inherited method from Cipher.", + method = "update", + args = {byte[].class, int.class, int.class} + ) public void testUpdatebyteArrayintint() throws Exception { byte [] b = {1, 2, 3, 4, 5}; byte [] r = c.update(b, 0, 5); @@ -227,15 +212,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for int update(byte[], int, int, byte[]) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "update", - methodArgs = {byte[].class, int.class, int.class, byte[].class} - ) - }) + notes = "Exceptions checking missed. Checks inherited method from Cipher.", + method = "update", + args = {byte[].class, int.class, int.class, byte[].class} + ) public void testUpdatebyteArrayintintbyteArray() throws Exception { byte [] b = {1, 2, 3, 4, 5}; byte [] r = new byte[5]; @@ -246,15 +228,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for int update(byte[], int, int, byte[], int) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "update", - methodArgs = {byte[].class, int.class, int.class, byte[].class, int.class} - ) - }) + notes = "Exceptions checking missed. Checks inherited method from Cipher.", + method = "update", + args = {byte[].class, int.class, int.class, byte[].class, int.class} + ) public void testUpdatebyteArrayintintbyteArrayint() throws Exception { byte [] b = {1, 2, 3, 4, 5}; byte [] r = new byte[5]; @@ -265,15 +244,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for byte[] doFinal() */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Exceptions checking missed. Checks inherited method from Cipher.", + method = "doFinal", + args = {} + ) public void testDoFinal() throws Exception { assertNull("doFinal failed", c.doFinal()); } @@ -281,15 +257,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for int doFinal(byte[], int) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class, int.class} - ) - }) + notes = "Exceptions checking missed. Checks inherited method from Cipher.", + method = "doFinal", + args = {byte[].class, int.class} + ) public void testDoFinalbyteArrayint() throws Exception { byte [] r = new byte[5]; assertEquals("doFinal failed", 0, c.doFinal(r, 0)); @@ -298,15 +271,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for byte[] doFinal(byte[]) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class} - ) - }) + notes = "Exceptions checking missed. Checks inherited method from Cipher.", + method = "doFinal", + args = {byte[].class} + ) public void testDoFinalbyteArray() throws Exception { byte [] b = {1, 2, 3, 4, 5}; byte [] r = null; @@ -318,15 +288,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for byte[] doFinal(byte[], int, int) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class, int.class, int.class} - ) - }) + notes = "Exceptions checking missed. Checks inherited method from Cipher.", + method = "doFinal", + args = {byte[].class, int.class, int.class} + ) public void testDoFinalbyteArrayintint() throws Exception { byte [] b = {1, 2, 3, 4, 5}; byte [] r = null; @@ -344,15 +311,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for byte[] update(byte[], int, int) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "update", - methodArgs = {byte[].class, int.class, int.class} - ) - }) + notes = "Exceptions checking missed. Checks inherited method from Cipher.", + method = "update", + args = {byte[].class, int.class, int.class} + ) public void testUpdatebyteArrayintint2() { //Regression for HARMONY-758 try { @@ -365,15 +329,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for int doFinal(byte[], int, int, byte[]) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class, int.class, int.class, byte[].class} - ) - }) + notes = "Exceptions checking missed. Checks inherited method from Cipher.", + method = "doFinal", + args = {byte[].class, int.class, int.class, byte[].class} + ) public void testDoFinalbyteArrayintintbyteArray() throws Exception { byte [] b = {1, 2, 3, 4, 5}; byte [] r = new byte[5]; @@ -384,15 +345,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for int doFinal(byte[], int, int, byte[]) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class, int.class, int.class, byte[].class} - ) - }) + notes = "Exceptions checking missed. Checks inherited method from Cipher.", + method = "doFinal", + args = {byte[].class, int.class, int.class, byte[].class} + ) public void testDoFinalbyteArrayintintbyteArray2() throws Exception { //Regression for HARMONY-758 try { @@ -406,36 +364,30 @@ public class NullCipherTest extends TestCase { /* * Class under test for int doFinal(byte[], int, int, byte[]) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class, int.class, int.class, byte[].class} - ) - }) - public void _testDoFinalbyteArrayintintbyteArray3() throws Exception { + notes = "Exceptions checking missed. Checks inherited method from Cipher.", + method = "doFinal", + args = {byte[].class, int.class, int.class, byte[].class} + ) + public void testDoFinalbyteArrayintintbyteArray3() throws Exception { //Regression for HARMONY-758 try { new NullCipher().update(new byte[1], 0, 1, new byte[0]); - fail("Expected ArrayIndexOutOfBoundsException was not thrown"); - } catch (ArrayIndexOutOfBoundsException e) { + fail("Expected IndexOutOfBoundsException was not thrown"); + } catch (IndexOutOfBoundsException e) { } } /* * Class under test for int doFinal(byte[], int, int, byte[], int) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class, int.class, int.class, byte[].class, int.class} - ) - }) + notes = "Exceptions checking missed. Checks inherited method from Cipher.", + method = "doFinal", + args = {byte[].class, int.class, int.class, byte[].class, int.class} + ) public void testDoFinalbyteArrayintintbyteArrayint() throws Exception { byte [] b = {1, 2, 3, 4, 5}; byte [] r = new byte[5]; @@ -446,15 +398,12 @@ public class NullCipherTest extends TestCase { /* * Class under test for int doFinal(byte[], int, int, byte[], int) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class, int.class, int.class, byte[].class, int.class} - ) - }) + notes = "Exceptions checking missed. Checks inherited method from Cipher.", + method = "doFinal", + args = {byte[].class, int.class, int.class, byte[].class, int.class} + ) public void testDoFinalbyteArrayintintbyteArrayint2() throws Exception { //Regression for HARMONY-758 try { @@ -468,22 +417,19 @@ public class NullCipherTest extends TestCase { /* * Class under test for int doFinal(byte[], int, int, byte[], int) */ -@TestInfo( + @TestTargetNew( level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed. Checks inherited method from Cipher.", - targets = { - @TestTarget( - methodName = "doFinal", - methodArgs = {byte[].class, int.class, int.class, byte[].class, int.class} - ) - }) - public void _testDoFinalbyteArrayintintbyteArrayint3() throws Exception { + notes = "Exceptions checking missed. Checks inherited method from Cipher.", + method = "doFinal", + args = {byte[].class, int.class, int.class, byte[].class, int.class} + ) + public void testDoFinalbyteArrayintintbyteArrayint3() throws Exception { //Regression for HARMONY-758 try { new NullCipher().update(new byte[1], 0, 1, new byte[0], 0); - fail("Expected ArrayIndexOutOfBoundsException was not thrown"); - } catch (ArrayIndexOutOfBoundsException e) { + fail("Expected IndexOutOfBoundsException was not thrown"); + } catch (IndexOutOfBoundsException e) { } } } diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SealedObjectTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SealedObjectTest.java index 67dcc23..5fb0245 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SealedObjectTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SealedObjectTest.java @@ -22,10 +22,11 @@ package org.apache.harmony.crypto.tests.javax.crypto; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTargetNew; + +import junit.framework.TestCase; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -33,8 +34,11 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.security.InvalidKeyException; import java.security.Key; +import java.security.NoSuchProviderException; import java.util.Arrays; + import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.KeyGenerator; @@ -43,8 +47,6 @@ import javax.crypto.SealedObject; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; -import junit.framework.TestCase; - @TestTargetClass(SealedObject.class) /** */ @@ -67,15 +69,12 @@ public class SealedObjectTest extends TestCase { * deserialized, the content od deserialized object equals to the content of * initial object. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "!Serialization", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "!Serialization", + args = {} + ) public void testReadObject() throws Exception { String secret = "secret string"; SealedObject so = new SealedObject(secret, new NullCipher()); @@ -100,15 +99,11 @@ public class SealedObjectTest extends TestCase { * SealedObject(Serializable object, Cipher c) method testing. Tests if the * NullPointerException is thrown in the case of null cipher. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Functionality checked in testSealedObject2, missed IOException & IllegalBlockSizeException checking", - targets = { - @TestTarget( - methodName = "SealedObject", - methodArgs = {java.io.Serializable.class, javax.crypto.Cipher.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + method = "SealedObject", + args = {java.io.Serializable.class, javax.crypto.Cipher.class} + ) public void testSealedObject1() throws Exception { String secret = "secret string"; try { @@ -117,21 +112,39 @@ public class SealedObjectTest extends TestCase { + "of null cipher."); } catch (NullPointerException e) { } + + KeyGenerator kg = KeyGenerator.getInstance("DES"); + Key key = kg.generateKey(); + + IvParameterSpec ips = new IvParameterSpec(new byte[] { + 1, 2, 3, 4, 5, 6, 7, 8}); + + Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, key, ips); + + SealedObject so = new SealedObject(secret, cipher); + + cipher = Cipher.getInstance("DES/CBC/NoPadding"); + cipher.init(Cipher.ENCRYPT_MODE, key, ips); + + try { + new SealedObject(secret, cipher); + fail("IllegalBlockSizeException expected"); + } catch (IllegalBlockSizeException e) { + //expected + } } /** * SealedObject(SealedObject so) method testing. Tests if the * NullPointerException is thrown in the case of null SealedObject. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "SealedObject", - methodArgs = {javax.crypto.SealedObject.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "SealedObject", + args = {javax.crypto.SealedObject.class} + ) public void testSealedObject2() throws Exception { try { new SealedObject(null) {}; @@ -157,15 +170,12 @@ public class SealedObjectTest extends TestCase { * getAlgorithm() method testing. Tests if the returned value equals to the * corresponding value of Cipher object. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getAlgorithm", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getAlgorithm", + args = {} + ) public void testGetAlgorithm() throws Exception { String secret = "secret string"; String algorithm = "DES"; @@ -185,15 +195,12 @@ public class SealedObjectTest extends TestCase { * encryption algorithm and specified parameters can be retrieved by * specifying the cryptographic key. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed.", - targets = { - @TestTarget( - methodName = "getObject", - methodArgs = {java.security.Key.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Not all exceptions can be checked.", + method = "getObject", + args = {java.security.Key.class} + ) public void testGetObject1() throws Exception { KeyGenerator kg = KeyGenerator.getInstance("DES"); Key key = kg.generateKey(); @@ -214,6 +221,14 @@ public class SealedObjectTest extends TestCase { + "should contain the encoded algorithm parameters.", Arrays .equals(so.get_encodedParams(), cipher.getParameters() .getEncoded())); + try { + so.getObject((Key)null); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } catch (NullPointerException e) { + //also ok + } } /** @@ -222,15 +237,12 @@ public class SealedObjectTest extends TestCase { * with encryption algorithm and specified parameters can be retrieved by * specifying the initialized Cipher object. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed.", - targets = { - @TestTarget( - methodName = "getObject", - methodArgs = {javax.crypto.Cipher.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Not all exceptions can be checked.", + method = "getObject", + args = {javax.crypto.Cipher.class} + ) public void testGetObject2() throws Exception { try { new SealedObject("secret string", new NullCipher()) @@ -255,6 +267,13 @@ public class SealedObjectTest extends TestCase { cipher.init(Cipher.DECRYPT_MODE, key, ips); assertEquals("The returned object does not equals to the " + "original object.", secret, so.getObject(cipher)); + + try { + so.getObject((Cipher)null); + fail("NullPointerException expected"); + } catch (NullPointerException e) { + //expected + } } /** @@ -263,15 +282,12 @@ public class SealedObjectTest extends TestCase { * object sealed with encryption algorithm can be retrieved by specifying * the cryptographic key and provider name. */ -@TestInfo( - level = TestLevel.PARTIAL, - purpose = "Exceptions checking missed.", - targets = { - @TestTarget( - methodName = "getObject", - methodArgs = {java.security.Key.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Not all exceptions can be checked.", + method = "getObject", + args = {java.security.Key.class, java.lang.String.class} + ) public void testGetObject3() throws Exception { try { new SealedObject("secret string", new NullCipher()).getObject( @@ -302,6 +318,23 @@ public class SealedObjectTest extends TestCase { cipher.init(Cipher.DECRYPT_MODE, key); assertEquals("The returned object does not equals to the " + "original object.", secret, so.getObject(key, provider)); + + kg = KeyGenerator.getInstance("DESede"); + key = kg.generateKey(); + + try { + so.getObject(key, provider); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } + + try { + so.getObject(key, "Wrong provider name"); + fail("NoSuchProviderException expected"); + } catch (NoSuchProviderException e) { + //expected + } } } diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactorySpiTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactorySpiTest.java index 5a2ae23..4b383d7 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactorySpiTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactorySpiTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.security.InvalidKeyException; import java.security.spec.InvalidKeySpecException; @@ -77,15 +77,12 @@ public class SecretKeyFactorySpiTest extends TestCase { * Test for <code>SecretKeyFactorySpi</code> constructor Assertion: * constructs SecretKeyFactorySpi */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "SecretKeyFactorySpi", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "SecretKeyFactorySpi", + args = {} + ) public void testSecretKeyFactorySpi01() throws InvalidKeyException, InvalidKeySpecException { Mock_SecretKeyFactorySpi skfSpi = new Mock_SecretKeyFactorySpi(); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactoryTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactoryTest.java index f3b8d31..6526239 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactoryTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactoryTest.java @@ -23,17 +23,20 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; 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.spec.InvalidKeySpecException; import java.security.spec.KeySpec; +import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.SecretKeyFactorySpi; @@ -121,15 +124,12 @@ public class SecretKeyFactoryTest extends TestCase { * Test for <code>SecretKeyFactory</code> constructor * Assertion: returns SecretKeyFactory object */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "SecretKeyFactory", - methodArgs = {javax.crypto.SecretKeyFactorySpi.class, java.security.Provider.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "SecretKeyFactory", + args = {javax.crypto.SecretKeyFactorySpi.class, java.security.Provider.class, java.lang.String.class} + ) public void testSecretKeyFactory01() throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException { if (!DEFSupported) { @@ -161,15 +161,12 @@ public class SecretKeyFactoryTest extends TestCase { * throws NullPointerException when algorithm is null; * throws NoSuchAlgorithmException when algorithm has invalid value */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class} + ) public void testSecretKeyFactory02() throws NoSuchAlgorithmException { try { SecretKeyFactory.getInstance(null); @@ -190,15 +187,12 @@ public class SecretKeyFactoryTest extends TestCase { * Test for <code>getInstance(String algorithm)</code> method * Assertion: returns SecretKeyObject */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class} + ) public void testSecretKeyFactory03() throws NoSuchAlgorithmException { if (!DEFSupported) { fail(NotSupportMsg); @@ -219,15 +213,12 @@ public class SecretKeyFactoryTest extends TestCase { * throws NullPointerException when algorithm is null; * throws NoSuchAlgorithmException when algorithm is invalid */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.lang.String.class} + ) public void testSecretKeyFactory04() throws NoSuchAlgorithmException, NoSuchProviderException { if (!DEFSupported) { @@ -258,15 +249,12 @@ public class SecretKeyFactoryTest extends TestCase { * throws IllegalArgumentException when provider is null or empty; * throws NoSuchProviderException when provider has invalid value */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.lang.String.class} + ) public void testSecretKeyFactory05() throws NoSuchAlgorithmException, NoSuchProviderException { if (!DEFSupported) { @@ -305,15 +293,12 @@ public class SecretKeyFactoryTest extends TestCase { * method * Assertion: returns SecretKeyFactory object */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.lang.String.class} + ) public void testSecretKeyFactory06() throws NoSuchProviderException, NoSuchAlgorithmException { if (!DEFSupported) { @@ -336,15 +321,12 @@ public class SecretKeyFactoryTest extends TestCase { * Assertion: throws NullPointerException when algorithm is null; * throws NoSuchAlgorithmException when algorithm is invalid */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.security.Provider.class} + ) public void testSecretKeyFactory07() throws NoSuchAlgorithmException { if (!DEFSupported) { fail(NotSupportMsg); @@ -371,15 +353,12 @@ public class SecretKeyFactoryTest extends TestCase { * method * Assertion: throws IllegalArgumentException when provider is null */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.security.Provider.class} + ) public void testSecretKeyFactory08() throws NoSuchAlgorithmException { if (!DEFSupported) { fail(NotSupportMsg); @@ -401,15 +380,12 @@ public class SecretKeyFactoryTest extends TestCase { * method * Assertion: returns SecretKeyFactory object */ -@TestInfo( - level = TestLevel.PARTIAL_OK, - purpose = "This is a complete subset of tests for getInstance method.", - targets = { - @TestTarget( - methodName = "getInstance", - methodArgs = {java.lang.String.class, java.security.Provider.class} - ) - }) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "This is a complete subset of tests for getInstance method.", + method = "getInstance", + args = {java.lang.String.class, java.security.Provider.class} + ) public void testSecretKeyFactory09() throws NoSuchAlgorithmException { if (!DEFSupported) { fail(NotSupportMsg); @@ -432,16 +408,32 @@ public class SecretKeyFactoryTest extends TestCase { * Assertion: * throw InvalidKeySpecException if parameter is inappropriate */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "Tis test is checking two methods.", - targets = { - @TestTarget( - methodName = "generateSecret", - methodArgs = {java.security.spec.KeySpec.class} - ), @TestTarget( - methodName = "getKeySpec", - methodArgs = {javax.crypto.SecretKey.class, java.lang.Class.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Tis test is checking two methods.", + method = "generateSecret", + args = {java.security.spec.KeySpec.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Tis test is checking two methods.", + clazz = SecretKeyFactorySpi.class, + method = "engineGenerateSecret", + args = {java.security.spec.KeySpec.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Tis test is checking two methods.", + method = "getKeySpec", + args = {javax.crypto.SecretKey.class, java.lang.Class.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Tis test is checking two methods.", + clazz = SecretKeyFactorySpi.class, + method = "engineGetKeySpec", + args = {javax.crypto.SecretKey.class, java.lang.Class.class} ) }) public void testSecretKeyFactory10() throws InvalidKeyException, @@ -515,6 +507,86 @@ public class SecretKeyFactoryTest extends TestCase { } } } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getAlgorithm", + args = {} + ) + public void test_getAlgorithm() throws NoSuchAlgorithmException { + for (int i = 0; i < validValues.length; i++) { + SecretKeyFactory secKF = SecretKeyFactory + .getInstance(validValues[i]); + assertEquals("Incorrect algorithm", secKF.getAlgorithm(), + validValues[i]); + } + + Mock_SecretKeyFactory msf = new Mock_SecretKeyFactory(null, null, null); + assertNull(msf.getAlgorithm()); + } + + class Mock_SecretKeyFactory extends SecretKeyFactory{ + protected Mock_SecretKeyFactory(SecretKeyFactorySpi arg0, Provider arg1, String arg2) { + super(arg0, arg1, arg2); + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getProvider", + args = {} + ) + public void test_getProvider() throws NoSuchAlgorithmException { + for (int i = 0; i < validValues.length; i++) { + SecretKeyFactory secKF = SecretKeyFactory + .getInstance(validValues[i]); + assertNotNull(secKF.getProvider()); + } + + Mock_SecretKeyFactory msf = new Mock_SecretKeyFactory(null, null, null); + assertNull(msf.getProvider()); + } + + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "translateKey", + args = {javax.crypto.SecretKey.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = SecretKeyFactorySpi.class, + method = "engineTranslateKey", + args = {javax.crypto.SecretKey.class} + ) + }) + public void test_translateKeyLjavax_crypto_SecretKey() + throws NoSuchAlgorithmException, InvalidKeyException { + KeyGenerator kg = null; + Key key = null; + SecretKeyFactory secKF = null; + + for (int i = 0; i < validValues.length; i++) { + secKF = SecretKeyFactory + .getInstance(validValues[i]); + assertNotNull(secKF.getProvider()); + kg = KeyGenerator.getInstance(secKF.getAlgorithm()); + kg.init(new SecureRandom()); + key = kg.generateKey(); + + secKF.translateKey((SecretKey) key); + } + try { + secKF.translateKey(null); + fail("InvalidKeyException expected"); + } catch (InvalidKeyException e) { + //expected + } + } } class mySecretKeyFactory extends SecretKeyFactory { diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyTest.java index 638c6f9..7941972 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import javax.crypto.SecretKey; @@ -51,15 +51,12 @@ public class SecretKeyTest extends TestCase { /** * Test for <code>serialVersionUID</code> field */ - @TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "!Constants", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "!Constants", + args = {} + ) public void testField() { checkSecretKey sk = new checkSecretKey(); assertEquals("Incorrect serialVersionUID", diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ShortBufferExceptionTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ShortBufferExceptionTest.java index 35ba2c5..9121275 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ShortBufferExceptionTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/ShortBufferExceptionTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import javax.crypto.ShortBufferException; @@ -61,15 +61,12 @@ public class ShortBufferExceptionTest extends TestCase { * Test for <code>ShortBufferException()</code> constructor Assertion: * constructs ShortBufferException with no detail message */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "ShortBufferException", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "ShortBufferException", + args = {} + ) public void testShortBufferException01() { ShortBufferException tE = new ShortBufferException(); assertNull("getMessage() must return null.", tE.getMessage()); @@ -81,15 +78,12 @@ public class ShortBufferExceptionTest extends TestCase { * Assertion: constructs ShortBufferException with detail message msg. * Parameter <code>msg</code> is not null. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "ShortBufferException", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "ShortBufferException", + args = {java.lang.String.class} + ) public void testShortBufferException02() { ShortBufferException tE; for (int i = 0; i < msgs.length; i++) { @@ -105,15 +99,12 @@ public class ShortBufferExceptionTest extends TestCase { * Assertion: constructs ShortBufferException when <code>msg</code> is * null */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "ShortBufferException", - methodArgs = {java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "ShortBufferException", + args = {java.lang.String.class} + ) public void testShortBufferException03() { String msg = null; ShortBufferException tE = new ShortBufferException(msg); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/AllTests.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/AllTests.java new file mode 100644 index 0000000..1ba0d00 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/AllTests.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * This is autogenerated source file. Includes tests for package org.apache.harmony.crypto.tests.javax.crypto; + */ + +public class AllTests { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTests.suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite("All tests for package org.apache.harmony.crypto.tests.javax.crypto.func;"); + // $JUnit-BEGIN$ + + suite.addTestSuite(CipherDesTest.class); + suite.addTestSuite(CipherAesTest.class); + suite.addTestSuite(CipherAesWrapTest.class); + suite.addTestSuite(CipherDESedeTest.class); + suite.addTestSuite(CipherDESedeWrapTest.class); + suite.addTestSuite(CipherSymmetricKeyThread.class); + suite.addTestSuite(CipherPBETest.class); + suite.addTestSuite(CipherRSATest.class); + suite.addTestSuite(KeyGeneratorFunctionalTest.class); + suite.addTestSuite(KeyAgreementFunctionalTest.class); + suite.addTestSuite(MacFunctionalTest.class); + suite.addTestSuite(SecretKeyFactoryFunctionalTest.class); + + // $JUnit-END$ + return suite; + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherAesTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherAesTest.java new file mode 100644 index 0000000..446ade3 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherAesTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTargetNew; + +import junit.framework.TestCase; + + +import targets.Cipher; + +@TestTargetClass(Cipher.AES.class) +public class CipherAesTest extends TestCase { +// 76 cases checked + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void test_AesNoISO() { + CipherSymmetricKeyThread aesNoISO = new CipherSymmetricKeyThread("AES", + new int[]{128},//Keysize must be equal to 128, 192, or 256. + new String[] {"ECB", "CBC", "CTR", "CTS", "CFB", "CFB8", + "CFB16", "CFB24", "CFB32", "CFB40", "CFB48", "CFB56", "CFB64", + "CFB72", "CFB80", "CFB88", "CFB96", "CFB104", "CFB112", "CFB120", + "CFB128", "OFB", "OFB8", "OFB16", "OFB24", "OFB32", "OFB40", + "OFB48", "OFB56", "OFB64", "OFB72", "OFB80", "OFB88", "OFB96", + "OFB104", "OFB112", "OFB120", "OFB128"}, + new String[]{"NoPadding", "PKCS5Padding"}); + + aesNoISO.launcher(); + + assertEquals(aesNoISO.getFailureMessages(), 0, aesNoISO.getTotalFailuresNumber()); + } + +// 36 cases checked + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void test_AesISO() { + CipherSymmetricKeyThread aesISO = new CipherSymmetricKeyThread("AES", + new int[]{128},//Keysize must be equal to 128, 192, or 256. + new String[] {"ECB", "CBC", "CFB", "CFB8", + "CFB16", "CFB24", "CFB32", "CFB40", "CFB48", "CFB56", "CFB64", + "CFB72", "CFB80", "CFB88", "CFB96", "CFB104", "CFB112", "CFB120", + "CFB128", "OFB", "OFB8", "OFB16", "OFB24", "OFB32", "OFB40", + "OFB48", "OFB56", "OFB64", "OFB72", "OFB80", "OFB88", "OFB96", + "OFB104", "OFB112", "OFB120", "OFB128"}, + new String[] {"ISO10126PADDING"}); + + aesISO.launcher(); + + assertEquals(aesISO.getFailureMessages(), 0, aesISO.getTotalFailuresNumber()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherAesWrapTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherAesWrapTest.java new file mode 100644 index 0000000..0e7e7e1 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherAesWrapTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTargetNew; + +import junit.framework.TestCase; + + +import targets.Cipher; + +@TestTargetClass(Cipher.AESWrap.class) +public class CipherAesWrapTest extends TestCase { +// one case checked. Mode "ECB" not supported. + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void _test_AesWrap() { + CipherWrapThread aesWrap = new CipherWrapThread("AESWrap", + new int[]{128}, + new String[] {"ECB"}, + new String[] {"NoPadding"}); + + aesWrap.launcher(); + + assertEquals(aesWrap.getFailureMessages(), 0, aesWrap.getTotalFailuresNumber()); + } + + public void test_AesWrap1() { + CipherWrapThread aesWrap = new CipherWrapThread("AES", + new int[]{128}, + new String[] {"ECB"}, + new String[] {"NoPadding"}); + + aesWrap.launcher(); + + assertEquals(aesWrap.getFailureMessages(), 0, aesWrap.getTotalFailuresNumber()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherDESedeTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherDESedeTest.java new file mode 100644 index 0000000..27113c6 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherDESedeTest.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTargetNew; + +import junit.framework.TestCase; + + +import targets.Cipher; + +@TestTargetClass(Cipher.DESede.class) +public class CipherDESedeTest extends TestCase { +// 88 cases checked + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void test_DESedeNoISO() { + CipherSymmetricKeyThread DESedeNoISO = new CipherSymmetricKeyThread("DESede", + new int[]{112, 168},//Keysize must be equal to 112 or 168. + new String[] {"ECB", "CBC", "CTR", "CTS", "CFB", "CFB8", "CFB16", + "CFB24", "CFB32", "CFB40", "CFB48", "CFB56", "CFB64", "OFB", + "OFB8", "OFB16", "OFB24", "OFB32","OFB40", "OFB48", "OFB56", + "OFB64"}, + new String[]{"NoPadding", "PKCS5Padding"}); + + DESedeNoISO.launcher(); + + assertEquals(DESedeNoISO.getFailureMessages(), 0, DESedeNoISO.getTotalFailuresNumber()); + } + +// 40 cases checked + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void test_DESedeISO() { + CipherSymmetricKeyThread DESedeISO = new CipherSymmetricKeyThread("DESede", + new int[]{112, 168},//Keysize must be equal to 112 or 168. + new String[] {"ECB", "CBC", "CFB", "CFB8", "CFB16", "CFB24", + "CFB32", "CFB40", "CFB48", "CFB56", "CFB64", "OFB", + "OFB8", "OFB16", "OFB24", "OFB32","OFB40", "OFB48", + "OFB56", "OFB64"}, + new String[]{"ISO10126PADDING"}); + + DESedeISO.launcher(); + + assertEquals(DESedeISO.getFailureMessages(), 0, DESedeISO.getTotalFailuresNumber()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherDESedeWrapTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherDESedeWrapTest.java new file mode 100644 index 0000000..05eed26 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherDESedeWrapTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetNew; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + + +import targets.Cipher; + +@TestTargetClass(Cipher.DESedeWrap.class) +public class CipherDESedeWrapTest extends TestCase { +// 2 cases checked. Mode "CBC" not supported. + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void _test_DESedeWrap() { + CipherWrapThread DESedeWrap = new CipherWrapThread("DESedeWrap", + new int[]{112, 168}, + new String[] {"CBC"}, + new String[]{"NoPadding"}); + + DESedeWrap.launcher(); + + assertEquals(DESedeWrap.getFailureMessages(), 0, DESedeWrap.getTotalFailuresNumber()); + } + + public void test_DESede() { + CipherWrapThread DESedeWrap = new CipherWrapThread("DESede", + new int[]{112, 168}, + new String[] {"CBC"}, + new String[]{"NoPadding"}); + + DESedeWrap.launcher(); + + assertEquals(DESedeWrap.getFailureMessages(), 0, DESedeWrap.getTotalFailuresNumber()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherDesTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherDesTest.java new file mode 100644 index 0000000..3417d92 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherDesTest.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTargetNew; + +import junit.framework.TestCase; + + +import targets.Cipher; + +@TestTargetClass(Cipher.DES.class) +public class CipherDesTest extends TestCase { +// 44 cases checked + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void test_DesNoISO() { + CipherSymmetricKeyThread desNoISO = new CipherSymmetricKeyThread("DES", + new int[]{56},//Keysize must be equal to 56. + new String[] {"ECB", "CBC", "CTR", "CTS", "CFB", "CFB8", + "CFB16", "CFB24", "CFB32", "CFB40", "CFB48", "CFB56", + "CFB64", "OFB", "OFB8", "OFB16", "OFB24", "OFB32", + "OFB40", "OFB48", "OFB56", "OFB64"}, + new String[]{"NoPadding", "PKCS5Padding"}); + + desNoISO.launcher(); + + assertEquals(desNoISO.getFailureMessages(), 0, desNoISO.getTotalFailuresNumber()); + } + +// 20 cases checked + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void test_DesISO() { + CipherSymmetricKeyThread desISO = new CipherSymmetricKeyThread("DES", + new int[]{56},//Keysize must be equal to 56. + new String[] {"ECB", "CBC", "CFB", "CFB8", + "CFB16", "CFB24", "CFB32", "CFB40", "CFB48", "CFB56", + "CFB64", "OFB", "OFB8", "OFB16", "OFB24", "OFB32", + "OFB40", "OFB48", "OFB56", "OFB64"}, + new String[]{"ISO10126PADDING"}); + + desISO.launcher(); + + assertEquals(desISO.getFailureMessages(), 0, desISO.getTotalFailuresNumber()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherPBETest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherPBETest.java new file mode 100644 index 0000000..5f97064 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherPBETest.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTargetNew; + +import junit.framework.TestCase; + + +import targets.Cipher; + +import java.security.NoSuchAlgorithmException; + +import javax.crypto.SecretKeyFactory; + +@TestTargetClass(Cipher.PBE.class) +public class CipherPBETest extends TestCase { +// 2 cases checked + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void test_PBEWithMD5AndDES() throws Exception { + CipherPBEThread PBEWithMD5AndDES = new CipherPBEThread("PBEWithMD5AndDES", + new int[]{40, 128}, + new String[] {"CBC"}, + new String[]{"PKCS5Padding"}); + + PBEWithMD5AndDES.launcher(); + + assertEquals(PBEWithMD5AndDES.getFailureMessages(), 0, PBEWithMD5AndDES.getTotalFailuresNumber()); + } + +// 2 cases checked. Not supported on Android. + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void _test_PBEWithSHA1AndDESede() throws Exception { + CipherPBEThread PBEWithSHA1AndDESede = new CipherPBEThread("PBEWithSHA1AndDESede", + new int[]{40, 128}, + new String[] {"CBC"}, + new String[]{"PKCS5Padding"}); + + PBEWithSHA1AndDESede.launcher(); + + assertEquals(PBEWithSHA1AndDESede.getFailureMessages(), 0, PBEWithSHA1AndDESede.getTotalFailuresNumber()); + } + +// 2 cases checked. Not supported on Android. + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void _test_PBEWithSHA1AndRC2_40() throws Exception { + CipherPBEThread PBEWithSHA1AndRC2_40 = new CipherPBEThread("PBEWithSHA1AndRC2_40", + new int[]{40, 128}, + new String[] {"CBC"}, + new String[]{"PKCS5Padding"}); + + PBEWithSHA1AndRC2_40.launcher(); + + assertEquals(PBEWithSHA1AndRC2_40.getFailureMessages(), 0, PBEWithSHA1AndRC2_40.getTotalFailuresNumber()); + } + +// Key factory does not supported. + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void _test_PBEWITHSHAAND3() throws Exception { + CipherPBEThread PBEWithSHA1AndRC2_40 = new CipherPBEThread("PBEWITHSHAAND3", + new int[]{40, 128}, + new String[] {"CBC"}, + new String[]{"NoPadding", "PKCS5Padding", "ISO10126PADDING"}); + + PBEWithSHA1AndRC2_40.launcher(); + + assertEquals(PBEWithSHA1AndRC2_40.getFailureMessages(), 0, PBEWithSHA1AndRC2_40.getTotalFailuresNumber()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherPBEThread.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherPBEThread.java new file mode 100644 index 0000000..0e8dc4d --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherPBEThread.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + + +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; + +import javax.crypto.Cipher; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.PBEKeySpec; +import javax.crypto.spec.PBEParameterSpec; + +public class CipherPBEThread extends CipherThread { + + CipherPBEThread(String name, int[] keys, String[] modes, String[] paddings) { + super(name, keys, modes, paddings); + } + + @Override + public void crypt() throws Exception { + byte[] output = new byte[128]; + byte[] decrypted = new byte[128]; + byte[] input = getData().getBytes(); + byte[] salt = new byte[8]; + SecureRandom sr = new SecureRandom(); + + PBEKeySpec keySpec = new PBEKeySpec("top sicret password".toCharArray()); + SecretKeyFactory skf = SecretKeyFactory.getInstance(getAlgName()); + SecretKey key = skf.generateSecret(keySpec); + + Cipher cip = Cipher.getInstance(getAlgName() + "/" + getMode() + "/" + + getPadding()); + + sr.nextBytes(salt); + PBEParameterSpec parSpec = new PBEParameterSpec(salt, getKeyLength()); + + cip.init(Cipher.ENCRYPT_MODE, key, parSpec); + cip.doFinal(input, 0, input.length, output); + int outputSize = cip.getOutputSize(input.length); + cip.init(Cipher.DECRYPT_MODE, key, parSpec); + cip.doFinal(output, 0, outputSize, decrypted); + + checkEncodedData(getData().getBytes(), decrypted); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherRSATest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherRSATest.java new file mode 100644 index 0000000..3071287 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherRSATest.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTargetNew; + +import junit.framework.TestCase; + + +import targets.Cipher; + +@TestTargetClass(Cipher.RSA.class) +public class CipherRSATest extends TestCase { +// 3 cases checked + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void test_RSAShortKey() { + CipherRSAThread rsa = new CipherRSAThread("RSA", + new int[]{512}, + new String[] {"ECB"}, + new String[]{"PKCS1Padding", + "OAEPWITHMD5ANDMGF1Padding", "OAEPWITHSHA1ANDMGF1Padding"}); + + rsa.launcher(); + + assertEquals(rsa.getFailureMessages(), 0, rsa.getTotalFailuresNumber()); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void _test_RSALongKey() { + CipherRSAThread rsa = new CipherRSAThread("RSA", + new int[]{1024}, + new String[] {"ECB"}, + new String[]{"OAEPWITHSHA-384ANDMGF1Padding"}); + + rsa.launcher(); + + assertEquals(rsa.getFailureMessages(), 0, rsa.getTotalFailuresNumber()); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void _test_RSAXXXLKey() { + CipherRSAThread rsa = new CipherRSAThread("RSA", + new int[]{2048}, + new String[] {"ECB"}, + new String[]{"OAEPWITHSHA-512ANDMGF1Padding"}); + + rsa.launcher(); + + assertEquals(rsa.getFailureMessages(), 0, rsa.getTotalFailuresNumber()); + } + +// 2 cases checked + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ) + public void test_RSANoPadding() { + CipherRSAThread rsa = new CipherRSAThread("RSA", + new int[]{512}, + new String[] {"ECB"}, + new String[]{"NoPadding", "ISO9796-1PADDING"}); + + rsa.launcher(); + + assertEquals(rsa.getFailureMessages(), 0, rsa.getTotalFailuresNumber()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherRSAThread.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherRSAThread.java new file mode 100644 index 0000000..8efc0f6 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherRSAThread.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + + +import java.security.KeyPair; +import java.security.KeyPairGenerator; + +import javax.crypto.Cipher; + +public class CipherRSAThread extends CipherThread { + + CipherRSAThread(String name, int[] keys, String[] modes, String[] paddings) { + super(name, keys, modes, paddings); + } + + @Override + public void crypt() throws Exception { + byte[] output = new byte[256]; + byte[] decrypted = new byte[256]; + int dataBlock = 20; + byte[] input = getData().substring(0, dataBlock).getBytes(); + KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); + kpg.initialize(getKeyLength()); + KeyPair kp = kpg.generateKeyPair(); + + Cipher cip = Cipher.getInstance(getAlgName() + "/" + getMode() + "/" + + getPadding()); + cip.init(Cipher.ENCRYPT_MODE, kp.getPublic()); + cip.doFinal(input, 0, input.length, output); + int outputSize = cip.getOutputSize(input.length); + cip.init(Cipher.DECRYPT_MODE, kp.getPrivate()); + cip.doFinal(output, 0, outputSize, decrypted); + + checkEncodedData(input, decrypted); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherSymmetricKeyThread.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherSymmetricKeyThread.java new file mode 100644 index 0000000..63faada --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherSymmetricKeyThread.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + + +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.spec.IvParameterSpec; + +public class CipherSymmetricKeyThread extends CipherThread { + CipherSymmetricKeyThread(String name, int[] keys, String[] modes, String[] paddings) { + super(name, keys, modes, paddings); + } + + + @Override + public void crypt() throws Exception { + byte[] output = new byte[128]; + byte[] decrypted = new byte[128]; + byte[] input = getData().getBytes(); + SecureRandom sr = new SecureRandom(); + byte[] iv = null;//new byte[16]; + int outputSize = 0; + + KeyGenerator kg = KeyGenerator.getInstance(getAlgName()); + kg.init(getKeyLength(), new SecureRandom()); + Key key = kg.generateKey(); + + Cipher cip = Cipher.getInstance(getAlgName() + "/" + getMode() + "/" + + getPadding()); + if (getAlgName() != "AES") { + iv = new byte[8]; + } else { + iv = new byte[16]; + } + sr.nextBytes(iv); + IvParameterSpec ivspec = new IvParameterSpec(iv); + if (getMode() != "ECB") { + cip.init(Cipher.ENCRYPT_MODE, key, ivspec); + cip.doFinal(input, 0, input.length, output); + outputSize = cip.getOutputSize(input.length); + iv = cip.getIV(); + ivspec = new IvParameterSpec(iv); + cip.init(Cipher.DECRYPT_MODE, key, ivspec); + cip.doFinal(output, 0, outputSize, decrypted); + } else { + cip.init(Cipher.ENCRYPT_MODE, key); + cip.doFinal(input, 0, input.length, output); + outputSize = cip.getOutputSize(input.length); + cip.init(Cipher.DECRYPT_MODE, key); + cip.doFinal(output, 0, outputSize, decrypted); + } + + checkEncodedData(getData().getBytes(), decrypted); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherThread.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherThread.java new file mode 100644 index 0000000..25d51c4 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherThread.java @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import javax.crypto.Cipher; + +public abstract class CipherThread implements Runnable { + private int[] keyLengthAr = null; + private String[] modeAr = null; + private String[] paddingModeAr = null; + private int kCounter = 0; + private int mCounter = 0; + private int pCounter = 0; + private StringBuffer errorSB = null; + + private boolean flagTestResult = false; + private String data = " Albert Einstein was a German-born " + + "theoretical physicist. "; + private String algName = null; + private int keyLength = 0; + private String mode = null; + private String paddingMode = null; + private int fails = 0; + + abstract public void crypt() throws Exception; + + CipherThread(String name, int[] keys, String[] modes, String[] paddings) { + algName = name; + keyLengthAr = keys; + modeAr = modes; + paddingModeAr = paddings; + kCounter = 0; + mCounter = 0; + pCounter = 0; + } + + public void checkEncodedData(byte[] original, byte[] encoded) + throws Exception { + for(int i = 0; i < original.length; i++) { + if (original[i] != encoded[i]) { + throw new Exception("Source and encoded data not match " + + getCipherParameters()); + } + } + } + + public void launcher() { + Thread thread = null; + + do { + keyLength = getNextKey(); + do { + mode = getNextMode(); + do { + paddingMode = getNextPadding(); + thread = new Thread(this); + thread.start(); + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } while (hasNextPadding()); + } while (hasNextMode()); + } while (hasNextKey()); + } + + public void run() { + try { + crypt(); + } catch (Exception e) { + if(errorSB == null) { + errorSB = new StringBuffer(); + } + errorSB.append(e.getMessage()); + errorSB.append("\n"); + errorSB.append(getCipherParameters()); + errorSB.append("\n"); + StackTraceElement[] st = e.getStackTrace(); + for (int i = 0; i < st.length; i++) { + errorSB.append(st[i].toString()); + errorSB.append("\n"); + } + fails++; + return; + } + flagTestResult = true; + } + + public String getAlgName() { + return algName; + } + + public int getKeyLength() { + return keyLength; + } + + public String getData() { + return data; + } + + public String getPadding() { + return paddingMode; + } + + public String getMode() { + return mode; + } + + public String getCipherParameters() { + return "Alg name:" + algName + " Key:" + keyLength + " Mode:" + mode + + " Padding:" + paddingMode; + } + + public boolean getTestStatus() { + return flagTestResult; + } + + public String getAlgorithmName() { + return algName; + } + + public boolean hasNextKey() { + return (kCounter < keyLengthAr.length); + } + + public boolean hasNextMode() { + return (mCounter < modeAr.length); + } + + public boolean hasNextPadding() { + return (pCounter < paddingModeAr.length); + } + + public int getNextKey() { + kCounter = (hasNextKey()) ? kCounter : 0; + return keyLengthAr[kCounter++]; + } + + public String getNextMode() { + mCounter = (hasNextMode()) ? mCounter : 0; + return modeAr[mCounter++]; + } + + public String getNextPadding() { + pCounter = (hasNextPadding()) ? pCounter : 0; + return paddingModeAr[pCounter++]; + } + + public long getTotalCasesNumber() { + return keyLengthAr.length * modeAr.length * paddingModeAr.length; + } + + public long getTotalFailuresNumber() { + return fails; + } + + public String getFailureMessages() { + return (errorSB == null) ? "" : new String(errorSB); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherWrapThread.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherWrapThread.java new file mode 100644 index 0000000..2b34c1c --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherWrapThread.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + + +import java.security.Key; +import java.security.SecureRandom; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; + +public class CipherWrapThread extends CipherThread { + CipherWrapThread(String name, int[] keys, String[] modes, String[] paddings) { + super(name, keys, modes, paddings); + } + + @Override + public void crypt() throws Exception { + KeyGenerator kg = KeyGenerator.getInstance(getAlgName().replace("Wrap", "")); + kg.init(getKeyLength(), new SecureRandom()); + Key key = kg.generateKey(); + + Cipher cip = Cipher.getInstance(getAlgName() + "/" + getMode() + "/" + + getPadding()); + + cip.init(Cipher.WRAP_MODE, key); + byte[] output = cip.wrap(key); + cip.init(Cipher.UNWRAP_MODE, key); + Key decrypted = cip.unwrap(output, getAlgName(), Cipher.SECRET_KEY); + + checkEncodedData(key.getFormat().getBytes(), decrypted.getFormat().getBytes()); + checkEncodedData(key.getEncoded(), decrypted.getEncoded()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyAgreementFunctionalTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyAgreementFunctionalTest.java new file mode 100644 index 0000000..fbb5f64 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyAgreementFunctionalTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import junit.framework.TestCase; + + +import java.math.BigInteger; +import java.security.AlgorithmParameterGenerator; +import java.security.AlgorithmParameters; +import java.security.Key; +import java.security.KeyFactory; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.SecureRandom; +import java.security.spec.X509EncodedKeySpec; +import java.util.Formatter; + +import javax.crypto.KeyAgreement; +import javax.crypto.SecretKey; +import javax.crypto.spec.DHParameterSpec; + +public class KeyAgreementFunctionalTest extends TestCase { + public void test_() throws Exception { + String[] algArray = {"DES", "DESede"}; + + KeyAgreementThread kat = new KeyAgreementThread(algArray); + kat.launcher(); + + assertEquals(kat.getFailureMessages(), 0, kat.getTotalFailuresNumber()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyAgreementThread.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyAgreementThread.java new file mode 100644 index 0000000..51c9fb7 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyAgreementThread.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import java.security.AlgorithmParameterGenerator; +import java.security.AlgorithmParameters; +import java.security.KeyFactory; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.SecureRandom; +import java.security.spec.X509EncodedKeySpec; + +import javax.crypto.KeyAgreement; +import javax.crypto.SecretKey; +import javax.crypto.spec.DHParameterSpec; + +public class KeyAgreementThread extends TestThread { + class KeyAgreementGen { + private PrivateKey privateKey = null; + private byte[] publicKeyBytes = null; + + KeyAgreementGen(DHParameterSpec parameterSpec) + throws Exception { + KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH"); + keyGen.initialize(parameterSpec); + KeyPair keypair = keyGen.generateKeyPair(); + + privateKey = keypair.getPrivate(); + publicKeyBytes = keypair.getPublic().getEncoded(); + } + + public byte[] getPublicKeyBytes () { + return publicKeyBytes; + } + + public SecretKey getSecretKey(String alg, byte[] publicKey) throws Exception { + X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(publicKey); + KeyFactory keyFact = KeyFactory.getInstance("DH"); + PublicKey pubKey = keyFact.generatePublic(x509KeySpec); + + KeyAgreement ka = KeyAgreement.getInstance("DH"); + ka.init(privateKey); + ka.doPhase(pubKey, true); + + return ka.generateSecret(alg); + } + } + + public KeyAgreementThread(String[] names) { + super(names); + } + + @Override + public void test() throws Exception { + AlgorithmParameterGenerator apg = AlgorithmParameterGenerator.getInstance("DH"); + apg.init(1024, new SecureRandom()); + AlgorithmParameters ap = apg.generateParameters(); + DHParameterSpec ps = ap.getParameterSpec(DHParameterSpec.class); + + KeyAgreementGen kag1 = new KeyAgreementGen(ps); + KeyAgreementGen kag2 = new KeyAgreementGen(ps); + + byte[] bArray1 = kag1.getPublicKeyBytes(); + byte[] bArray2 = kag2.getPublicKeyBytes(); + + SecretKey sk1 = kag1.getSecretKey(algName, bArray2); + SecretKey sk2 = kag2.getSecretKey(algName, bArray1); + + if (sk1.equals(sk2) == false) { + throw new Exception ("Generated keys are not the same"); + } + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyGeneratorFunctionalTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyGeneratorFunctionalTest.java new file mode 100644 index 0000000..87546a9 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyGeneratorFunctionalTest.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTargetNew; +import dalvik.annotation.TestTargets; + +import junit.framework.TestCase; + + +import targets.KeyGenerator; + +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +@TestTargetClass(KeyGenerator.AES.class) +public class KeyGeneratorFunctionalTest extends TestCase { +@TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "method", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = KeyGenerator.DES.class, + method = "method", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = KeyGenerator.DESede.class, + method = "method", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = KeyGenerator.HMACMD5.class, + method = "method", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = KeyGenerator.HMACSHA1.class, + method = "method", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = KeyGenerator.HMACSHA256.class, + method = "method", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = KeyGenerator.HMACSHA384.class, + method = "method", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = KeyGenerator.HMACSHA512.class, + method = "method", + args = {} + )}) + public void test_() throws Exception { + String[] algArray = {/*"DH",*/ "AES", "DES", "DESEDE", "DESede", + "HMACMD5", "HmacMD5", "HMACSHA1", "HmacSHA1", "HMACSHA256", + "HmacSHA256", "HMACSHA384", "HmacSHA384", "HMACSHA512", + "HmacSHA512"}; + + KeyGeneratorThread kgt = new KeyGeneratorThread(algArray); + kgt.launcher(); + + assertEquals(kgt.getFailureMessages(), 0, kgt.getTotalFailuresNumber()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyGeneratorThread.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyGeneratorThread.java new file mode 100644 index 0000000..52a7b5d --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyGeneratorThread.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + + +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +import javax.crypto.KeyGenerator; + +public class KeyGeneratorThread extends TestThread { + KeyGeneratorThread(String[] names) { + super(names); + } + + public void test() throws Exception { + KeyGenerator kg = KeyGenerator.getInstance(algName); + Key k = kg.generateKey(); + if(kg.getAlgorithm().toLowerCase().equals(k.getAlgorithm().toLowerCase()) != true) { + throw new Exception ("Algorithm names not matched for KeyGenerator" + + " and for Key objects"); + } + if(kg.getAlgorithm().toLowerCase().equals(algName.toLowerCase()) != true) { + throw new Exception ("Algorithm names not matched for KeyGenerator" + + " and for Key objects"); + } + byte[] array1 = k.getEncoded(); + k = kg.generateKey(); + byte[] array2 = k.getEncoded(); + int matches = 0; + for (int i = 0; i < array1.length; i++) { + if (array1[i] == array2[i]) { + matches++; + } + } + if (matches > array1.length / 2) { + throw new Exception("Generated keys are simular"); + } + SecureRandom random = new SecureRandom(); + kg.init(random); + matches = 0; + k = kg.generateKey(); + array1 = k.getEncoded(); + random = new SecureRandom(); + kg.init(random); + k = kg.generateKey(); + array2 = k.getEncoded(); + for (int i = 0; i < array1.length; i++) { + if (array1[i] == array2[i]) { + matches++; + } + } + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/MacFunctionalTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/MacFunctionalTest.java new file mode 100644 index 0000000..0736c3d --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/MacFunctionalTest.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import junit.framework.TestCase; + + +import java.security.NoSuchAlgorithmException; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; + +public class MacFunctionalTest extends TestCase { + public void test_() throws Exception { + String[] algArray = {"HMACSHA1", "HMACSHA256", "HMACSHA384", + "HMACSHA512", "HMACMD5"}; + + MacThread mt = new MacThread(algArray); + mt.launcher(); + + assertEquals(mt.getFailureMessages(), 0, mt.getTotalFailuresNumber()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/MacThread.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/MacThread.java new file mode 100644 index 0000000..de519d7 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/MacThread.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; + +public class MacThread extends TestThread { + MacThread(String[] names) { + super(names); + } + + @Override + public void test() throws Exception { + int size = 256; + byte[] src1 = new byte[size]; + byte[] src2 = new byte[size]; + byte[] src3 = new byte[size]; + int i; + + for (i = 0; i < size; i++) { + src1[i] = (byte)i; + src2[i] = (byte)i; + src3[i] = (byte)(size - i - 1); + } + Mac m = Mac.getInstance(algName); + byte[] b = {(byte)0, (byte)0, (byte)0, (byte)0, (byte)0}; + SecretKeySpec sks = new SecretKeySpec(b, "SHA1"); + m.init(sks); + + byte[] res = m.doFinal(src1); + String sign1 = new String(res); + m.init(sks); + res = m.doFinal(src2); + String sign2 = new String(res); + m.init(sks); + res = m.doFinal(src3); + String sign3 = new String(res); + if (sign1.compareTo(sign2) != 0 || sign1.compareTo(sign3) == 0 || + sign2.compareTo(sign3) == 0) { + throw new Exception ("Signature is not correct for algorithm " + algName); + } + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/SecretKeyFactoryFunctionalTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/SecretKeyFactoryFunctionalTest.java new file mode 100644 index 0000000..e2ec4bc --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/SecretKeyFactoryFunctionalTest.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import junit.framework.TestCase; + + +import java.security.NoSuchAlgorithmException; +import java.security.spec.KeySpec; + +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.DESKeySpec; +import javax.crypto.spec.DESedeKeySpec; +import javax.crypto.spec.PBEKeySpec; + +public class SecretKeyFactoryFunctionalTest extends TestCase { + + public void test_() throws Exception { + String[] algArray = {"DES", "DESede", "PBEWITHMD5ANDDES", + "PBEWithSHA1AndDESede", "PBEWithSHA1AndRC2_40"}; + + SecretKeyFactoryThread skft = new SecretKeyFactoryThread(algArray); + skft.launcher(); + + assertEquals(skft.getFailureMessages(), 0, skft.getTotalFailuresNumber()); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/SecretKeyFactoryThread.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/SecretKeyFactoryThread.java new file mode 100644 index 0000000..d426939 --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/SecretKeyFactoryThread.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +import java.security.spec.KeySpec; + +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.DESKeySpec; +import javax.crypto.spec.DESedeKeySpec; +import javax.crypto.spec.PBEKeySpec; + +public class SecretKeyFactoryThread extends TestThread { + SecretKeyFactoryThread(String[] names) { + super(names); + } + + @Override + public void test() throws Exception { + SecretKeyFactory skf = SecretKeyFactory.getInstance(algName); + byte[] b = new byte[24]; + KeySpec ks = (KeySpec) ((algName == "DES") ? new DESKeySpec(b) : + (algName == "DESede") ? new DESedeKeySpec(b) : + new PBEKeySpec("passw".toCharArray())); + skf.generateSecret(ks); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/TestThread.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/TestThread.java new file mode 100644 index 0000000..f970b1a --- /dev/null +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/TestThread.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * 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.crypto.tests.javax.crypto.func; + +public abstract class TestThread implements Runnable { + public String[] algNamesArray = null; + public int aCounter = 0; + public String algName = null; + public StringBuffer errorSB = null; + public int fails = 0; + public boolean flagTestResult = false; + + TestThread(String[] names) { + algNamesArray = names; + aCounter = 0; + } + + public abstract void test() throws Exception; + + public void launcher() { + Thread thread = null; + + do { + algName = getNextAlgorithmName(); + thread = new Thread(this); + thread.start(); + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } while (hasAlgorithmName()); + } + + public void run() { + try { + test(); + } catch (Exception e) { + if(errorSB == null) { + errorSB = new StringBuffer(); + } + errorSB.append(e.getMessage()); + errorSB.append("\n"); + errorSB.append(getAlgorithmName()); + errorSB.append("\n"); + StackTraceElement[] st = e.getStackTrace(); + for (int i = 0; i < st.length; i++) { + errorSB.append(st[i].toString()); + errorSB.append("\n"); + } + fails++; + return; + } + flagTestResult = true; + } + + public String getAlgorithmName() { + return algName; + } + + public boolean hasAlgorithmName() { + return (aCounter < algNamesArray.length); + } + + public String getNextAlgorithmName() { + aCounter = (hasAlgorithmName()) ? aCounter : 0; + return algNamesArray[aCounter++]; + } + + public long getTotalFailuresNumber() { + return fails; + } + + public String getFailureMessages() { + return (errorSB == null) ? "" : new String(errorSB); + } +} diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/AllTests.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/AllTests.java index bca63e6..b66a384 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/AllTests.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/AllTests.java @@ -30,7 +30,7 @@ public class AllTests { } public static Test suite() { - TestSuite suite = new TestSuite("All tests for package org.apache.harmony.crypto.tests.javax.crypto.interfaces;"); + TestSuite suite = tests.TestSuiteFactory.createTestSuite("All tests for package org.apache.harmony.crypto.tests.javax.crypto.interfaces;"); // $JUnit-BEGIN$ suite.addTestSuite(DHPrivateKeyTest.class); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/DHPrivateKeyTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/DHPrivateKeyTest.java index 3c65d24..9ab8d02 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/DHPrivateKeyTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/DHPrivateKeyTest.java @@ -22,20 +22,29 @@ package org.apache.harmony.crypto.tests.javax.crypto.interfaces; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTargetNew; +import dalvik.annotation.TestTargets; + +import javax.crypto.interfaces.DHKey; import javax.crypto.interfaces.DHPrivateKey; import javax.crypto.spec.DHParameterSpec; import junit.framework.TestCase; import java.math.BigInteger; +import java.security.KeyPair; +import java.security.KeyPairGenerator; /** * Tests for <code>DHPrivateKey</code> class field * */ +@TestTargetClass(DHPrivateKey.class) public class DHPrivateKeyTest extends TestCase { - + /** * Constructor for DHPrivateKey. * @@ -47,7 +56,12 @@ public class DHPrivateKeyTest extends TestCase { /** * Test for <code>serialVersionUID</code> field - */ + */ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "tests serialVersionUID for a fixed value", + method = "!field:serialVersionUID" + ) public void testField() { checkDHPrivateKey key = new checkDHPrivateKey(); assertEquals("Incorrect serialVersionUID", @@ -55,6 +69,33 @@ public class DHPrivateKeyTest extends TestCase { 2211791113380396553L); } +@TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + method = "getX", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + clazz = DHKey.class, + method = "getParams", + args = {} + ) + }) + public void test_getParams() throws Exception { + KeyPairGenerator kg = KeyPairGenerator.getInstance("DH"); + kg.initialize(512); + KeyPair kp1 = kg.genKeyPair(); + KeyPair kp2 = kg.genKeyPair(); + DHPrivateKey pk1 = (DHPrivateKey) kp1.getPrivate(); + DHPrivateKey pk2 = (DHPrivateKey) kp2.getPrivate(); + + assertTrue(pk1.getX().getClass().getCanonicalName().equals("java.math.BigInteger")); + assertTrue(pk1.getParams().getClass().getCanonicalName().equals("javax.crypto.spec.DHParameterSpec")); + assertFalse(pk1.getX().equals(pk2.getX())); + assertTrue(pk1.getX().equals(pk1.getX())); + } + public class checkDHPrivateKey implements DHPrivateKey { public String getAlgorithm() { return "SecretKey"; diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/DHPublicKeyTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/DHPublicKeyTest.java index b5121ee..274a221 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/DHPublicKeyTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/DHPublicKeyTest.java @@ -22,23 +22,29 @@ package org.apache.harmony.crypto.tests.javax.crypto.interfaces; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTargetNew; +import dalvik.annotation.TestTargets; + +import junit.framework.TestCase; + import java.math.BigInteger; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import javax.crypto.interfaces.DHKey; import javax.crypto.interfaces.DHPublicKey; import javax.crypto.spec.DHParameterSpec; -import junit.framework.TestCase; - /** * Tests for <code>DHPublicKey</code> class field * */ +@TestTargetClass(DHPublicKey.class) public class DHPublicKeyTest extends TestCase { - public static void main(String[] args) { - } - /** * Constructor for DHPublicKey. * @@ -51,12 +57,45 @@ public class DHPublicKeyTest extends TestCase { /** * Test for <code>serialVersionUID</code> field */ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "tests serialVersionUID for a fixed value", + method = "!field:serialVersionUID" + ) public void testField() { checkDHPublicKey key = new checkDHPublicKey(); assertEquals("Incorrect serialVersionUID", key.getSerVerUID(), //DHPublicKey.serialVersionUID -6628103563352519193L); } + +@TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + method = "getY", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + clazz = DHKey.class, + method = "getParams", + args = {} + ) + }) + public void test_getParams() throws Exception { + KeyPairGenerator kg = KeyPairGenerator.getInstance("DH"); + kg.initialize(512); + KeyPair kp1 = kg.genKeyPair(); + KeyPair kp2 = kg.genKeyPair(); + DHPublicKey pk1 = (DHPublicKey) kp1.getPublic(); + DHPublicKey pk2 = (DHPublicKey) kp2.getPublic(); + + assertTrue(pk1.getY().getClass().getCanonicalName().equals("java.math.BigInteger")); + assertTrue(pk2.getParams().getClass().getCanonicalName().equals("javax.crypto.spec.DHParameterSpec")); + assertFalse(pk1.getY().equals(pk2.getY())); + assertTrue(pk1.getY().equals(pk1.getY())); + } + public class checkDHPublicKey implements DHPublicKey { public String getAlgorithm() { return "SecretKey"; diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/PBEKeyTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/PBEKeyTest.java index 5e0c21c..cee9634 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/PBEKeyTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/interfaces/PBEKeyTest.java @@ -22,17 +22,22 @@ package org.apache.harmony.crypto.tests.javax.crypto.interfaces; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTargetNew; + +import junit.framework.TestCase; + import java.math.BigInteger; import javax.crypto.interfaces.PBEKey; -import junit.framework.TestCase; - /** * Tests for <code>PBEKey</code> class field * */ +@TestTargetClass(PBEKey.class) public class PBEKeyTest extends TestCase { @@ -48,12 +53,51 @@ public class PBEKeyTest extends TestCase { /** * Test for <code>serialVersionUID</code> field */ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "tests serialVersionUID for a fixed value", + method = "!field:serialVersionUID" + ) public void testField() { checkPBEKey key = new checkPBEKey(); assertEquals("Incorrect serialVersionUID", key.getSerVerUID(), //PBEKey.serialVersionUID -1430015993304333921L); } + +@TestTargetNew( + level = TestLevel.COMPLETE, + method = "getIterationCount", + args = {} + ) + public void test_getIterationCount() throws Exception { + checkPBEKey key = new checkPBEKey(); + + key.getIterationCount(); + } + +@TestTargetNew( + level = TestLevel.COMPLETE, + method = "getPassword", + args = {} + ) + public void test_getPassword() throws Exception { + checkPBEKey key = new checkPBEKey(); + + key.getPassword(); + } + +@TestTargetNew( + level = TestLevel.COMPLETE, + method = "getSalt", + args = {} + ) + public void test_getSalt() throws Exception { + checkPBEKey key = new checkPBEKey(); + + key.getSalt(); + } + public class checkPBEKey implements PBEKey { public String getAlgorithm() { return "SecretKey"; diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/AllTests.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/AllTests.java index 5bfa13f..0be596e 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/AllTests.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/serialization/AllTests.java @@ -30,7 +30,7 @@ public class AllTests { } public static Test suite() { - TestSuite suite = new TestSuite("All tests for package org.apache.harmony.crypto.tests.javax.crypto.serialization;"); + TestSuite suite = tests.TestSuiteFactory.createTestSuite("All tests for package org.apache.harmony.crypto.tests.javax.crypto.serialization;"); // $JUnit-BEGIN$ suite.addTestSuite(BadPaddingExceptionTest.class); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/AllTests.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/AllTests.java index 1afd486..d31dc54 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/AllTests.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/AllTests.java @@ -30,7 +30,7 @@ public class AllTests { } public static Test suite() { - TestSuite suite = new TestSuite("All tests for package org.apache.harmony.crypto.tests.javax.crypto.spec;"); + TestSuite suite = tests.TestSuiteFactory.createTestSuite("All tests for package org.apache.harmony.crypto.tests.javax.crypto.spec;"); // $JUnit-BEGIN$ suite.addTestSuite(DESKeySpecTest.class); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESKeySpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESKeySpecTest.java index 706104f..9904eed 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESKeySpecTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESKeySpecTest.java @@ -22,9 +22,9 @@ package org.apache.harmony.crypto.tests.javax.crypto.spec; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.lang.NullPointerException; import java.security.InvalidKeyException; @@ -110,16 +110,18 @@ public class DESKeySpecTest extends TestCase { * Constructors testing. Tests behavior of each of two constructors * in the cases of: null array, short array, normal array. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "Checks both constructors.", - targets = { - @TestTarget( - methodName = "DESKeySpec", - methodArgs = {byte[].class} - ), @TestTarget( - methodName = "DESKeySpec", - methodArgs = {byte[].class, int.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks both constructors.", + method = "DESKeySpec", + args = {byte[].class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks both constructors.", + method = "DESKeySpec", + args = {byte[].class, int.class} ) }) public void testDESKeySpec() { @@ -177,15 +179,12 @@ public class DESKeySpecTest extends TestCase { * the key with the key specified in the constructor. The object under * the test is created by different constructors. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getKey", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getKey", + args = {} + ) public void testGetKey() { byte[] key = {1, 2, 3, 4, 5, 6, 7, 8}; DESKeySpec ks; @@ -224,15 +223,12 @@ public class DESKeySpecTest extends TestCase { * it returns false on the key which is not parity adjusted, and if * it returns true on parity adjusted key. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "isParityAdjusted", - methodArgs = {byte[].class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "isParityAdjusted", + args = {byte[].class, int.class} + ) public void testIsParityAdjusted() { try { DESKeySpec.isParityAdjusted(null, 1); @@ -281,15 +277,12 @@ public class DESKeySpecTest extends TestCase { * it returns true on weak or semi-weak keys, and if it returns * false on other keys. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "isWeak", - methodArgs = {byte[].class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "isWeak", + args = {byte[].class, int.class} + ) public void testIsWeak() { try { DESKeySpec.isWeak(null, 1); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESedeKeySpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESedeKeySpecTest.java index 038e3fc..5c312a4 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESedeKeySpecTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESedeKeySpecTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto.spec; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.lang.NullPointerException; import java.security.InvalidKeyException; @@ -47,16 +47,18 @@ public class DESedeKeySpecTest extends TestCase { * Constructors testing. Tests behavior of each of two constructors * in the cases of: null array, short array, normal array. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "Checks both constructors.", - targets = { - @TestTarget( - methodName = "DESedeKeySpec", - methodArgs = {byte[].class} - ), @TestTarget( - methodName = "DESedeKeySpec", - methodArgs = {byte[].class, int.class} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks both constructors.", + method = "DESedeKeySpec", + args = {byte[].class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Checks both constructors.", + method = "DESedeKeySpec", + args = {byte[].class, int.class} ) }) public void testDESedeKeySpec() { @@ -120,15 +122,12 @@ public class DESedeKeySpecTest extends TestCase { * the key with the key specified in the constructor. The object under * the test is created by different constructors. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getKey", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getKey", + args = {} + ) public void testGetKey() { byte[] key = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2}; @@ -169,15 +168,12 @@ public class DESedeKeySpecTest extends TestCase { * it returns false on the key which is not parity adjusted, and if * it returns true on parity adjusted key. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "isParityAdjusted", - methodArgs = {byte[].class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "isParityAdjusted", + args = {byte[].class, int.class} + ) public void testIsParityAdjusted() { try { DESedeKeySpec.isParityAdjusted(null, 1); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHGenParameterSpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHGenParameterSpecTest.java index 2f379c3..7b09cb6 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHGenParameterSpecTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHGenParameterSpecTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto.spec; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.lang.Integer; @@ -46,19 +46,24 @@ public class DHGenParameterSpecTest extends TestCase { * parameters specified in the constructor with the values returned * by getters. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "All functionality tested in one method. Probably it should be divided into several tests.", - targets = { - @TestTarget( - methodName = "DHGenParameterSpec", - methodArgs = {int.class, int.class} - ), @TestTarget( - methodName = "getExponentSize", - methodArgs = {} - ), @TestTarget( - methodName = "getPrimeSize", - methodArgs = {} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "DHGenParameterSpec", + args = {int.class, int.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "getExponentSize", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "getPrimeSize", + args = {} ) }) public void testDHGenParameterSpec() { diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHParameterSpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHParameterSpecTest.java index 0ffd340..0c0ac3b 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHParameterSpecTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHParameterSpecTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto.spec; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.lang.Integer; import java.math.BigInteger; @@ -47,25 +47,36 @@ public class DHParameterSpecTest extends TestCase { * specified in the constructor with the values returned by getters. * The tested object is created by different constructors. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "All functionality tested in one method. Probably it should be divided into several tests.", - targets = { - @TestTarget( - methodName = "DHParameterSpec", - methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class} - ), @TestTarget( - methodName = "DHParameterSpec", - methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, int.class} - ), @TestTarget( - methodName = "getG", - methodArgs = {} - ), @TestTarget( - methodName = "getL", - methodArgs = {} - ), @TestTarget( - methodName = "getP", - methodArgs = {} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "DHParameterSpec", + args = {java.math.BigInteger.class, java.math.BigInteger.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "DHParameterSpec", + args = {java.math.BigInteger.class, java.math.BigInteger.class, int.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "getG", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "getL", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "getP", + args = {} ) }) public void testDHParameterSpec() { diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHPrivateKeySpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHPrivateKeySpecTest.java index 783032e..7181623 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHPrivateKeySpecTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHPrivateKeySpecTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto.spec; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.math.BigInteger; @@ -45,22 +45,30 @@ public class DHPrivateKeySpecTest extends TestCase { * DHPrivateKeySpec class testing. Tests the equivalence of parameters * specified in the constructor with the values returned by getters. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "All functionality tested in one method. Probably it should be divided into several tests.", - targets = { - @TestTarget( - methodName = "DHPrivateKeySpec", - methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class} - ), @TestTarget( - methodName = "getG", - methodArgs = {} - ), @TestTarget( - methodName = "getP", - methodArgs = {} - ), @TestTarget( - methodName = "getX", - methodArgs = {} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "DHPrivateKeySpec", + args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "getG", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "getP", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "getX", + args = {} ) }) public void testDHPrivateKeySpec() { diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHPublicKeySpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHPublicKeySpecTest.java index 24b4cdc..064c713 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHPublicKeySpecTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DHPublicKeySpecTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto.spec; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.math.BigInteger; @@ -45,22 +45,30 @@ public class DHPublicKeySpecTest extends TestCase { * DHPublicKeySpec class testing. Tests the equivalence of parameters * specified in the constructor with the values returned by getters. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "All functionality tested in one method. Probably it should be divided into several tests.", - targets = { - @TestTarget( - methodName = "DHPublicKeySpec", - methodArgs = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class} - ), @TestTarget( - methodName = "getG", - methodArgs = {} - ), @TestTarget( - methodName = "getP", - methodArgs = {} - ), @TestTarget( - methodName = "getY", - methodArgs = {} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "DHPublicKeySpec", + args = {java.math.BigInteger.class, java.math.BigInteger.class, java.math.BigInteger.class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "getG", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "getP", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "All functionality tested in one method. Probably it should be divided into several tests.", + method = "getY", + args = {} ) }) public void testDHPrivateKeySpec() { diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/IvParameterSpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/IvParameterSpecTest.java index 4d5be6b..fda566a 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/IvParameterSpecTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/IvParameterSpecTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto.spec; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.lang.NullPointerException; import java.lang.IllegalArgumentException; @@ -48,15 +48,12 @@ public class IvParameterSpecTest extends TestCase { * NullPointerException is thrown in the case of null input * array and that input array is copied during initialization. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "IvParameterSpec", - methodArgs = {byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "IvParameterSpec", + args = {byte[].class} + ) public void testIvParameterSpec1() { try { new IvParameterSpec(null); @@ -77,15 +74,12 @@ public class IvParameterSpecTest extends TestCase { * NullPointerException is thrown in the case of null input * array and that input array is copied during initialization. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "IvParameterSpec", - methodArgs = {byte[].class, int.class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "IvParameterSpec", + args = {byte[].class, int.class, int.class} + ) public void testIvParameterSpec2() { try { new IvParameterSpec(null, 1, 1); @@ -148,15 +142,12 @@ public class IvParameterSpecTest extends TestCase { } } -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getIV", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getIV", + args = {} + ) public void testGetIV() { byte[] iv = new byte[] {1, 2, 3, 4, 5}; IvParameterSpec ivps = new IvParameterSpec(iv); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/OAEPParameterSpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/OAEPParameterSpecTest.java index 43e38c6..6b2c673 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/OAEPParameterSpecTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/OAEPParameterSpecTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto.spec; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.security.spec.MGF1ParameterSpec; import java.security.spec.AlgorithmParameterSpec; @@ -49,15 +49,12 @@ public class OAEPParameterSpecTest extends TestCase { * is thrown in the case of inappropriate constructor parameters and checks * the value of DEFAULT field. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "OAEPParameterSpec", - methodArgs = {java.lang.String.class, java.lang.String.class, java.security.spec.AlgorithmParameterSpec.class, javax.crypto.spec.PSource.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "OAEPParameterSpec", + args = {java.lang.String.class, java.lang.String.class, java.security.spec.AlgorithmParameterSpec.class, javax.crypto.spec.PSource.class} + ) public void testOAEPParameterSpec() { // using init values for OAEPParameterSpec.DEFAULT String mdName = "SHA-1"; @@ -109,15 +106,12 @@ public class OAEPParameterSpecTest extends TestCase { /** * getDigestAlgorithm() method testing. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getDigestAlgorithm", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getDigestAlgorithm", + args = {} + ) public void testGetDigestAlgorithm() { String mdName = "SHA-1"; String mgfName = "MGF1"; @@ -134,15 +128,12 @@ public class OAEPParameterSpecTest extends TestCase { /** * getMGFAlgorithm() method testing. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getMGFAlgorithm", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getMGFAlgorithm", + args = {} + ) public void testGetMGFAlgorithm() { String mdName = "SHA-1"; String mgfName = "MGF1"; @@ -159,15 +150,12 @@ public class OAEPParameterSpecTest extends TestCase { /** * getMGFParameters() method testing. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getMGFParameters", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getMGFParameters", + args = {} + ) public void testGetMGFParameters() { String mdName = "SHA-1"; String mgfName = "MGF1"; @@ -184,15 +172,12 @@ public class OAEPParameterSpecTest extends TestCase { /** * getPSource() method testing. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getPSource", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getPSource", + args = {} + ) public void testGetPSource() { String mdName = "SHA-1"; String mgfName = "MGF1"; diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PBEKeySpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PBEKeySpecTest.java index 7aba77f..1cb017e 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PBEKeySpecTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PBEKeySpecTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto.spec; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.util.Arrays; @@ -46,15 +46,12 @@ public class PBEKeySpecTest extends TestCase { * the method in the case of null input char array and tests that input * array is copied during the object initialization. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "PBEKeySpec", - methodArgs = {char[].class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "PBEKeySpec", + args = {char[].class} + ) public void testPBEKeySpec1() { try { PBEKeySpec pbeks = new PBEKeySpec(null); @@ -78,15 +75,12 @@ public class PBEKeySpecTest extends TestCase { * of inappropriate parameters and checks that array objects specified as * a parameters are copied during the object initialization. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "PBEKeySpec", - methodArgs = {char[].class, byte[].class, int.class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "PBEKeySpec", + args = {char[].class, byte[].class, int.class, int.class} + ) public void testPBEKeySpec2() { char[] password = new char[] {'1', '2', '3', '4', '5'}; byte[] salt = new byte[] {1, 2, 3, 4, 5}; @@ -166,15 +160,12 @@ public class PBEKeySpecTest extends TestCase { * of inappropriate parameters and checks that array objects specified as * a parameters are copied during the object initialization. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "PBEKeySpec", - methodArgs = {char[].class, byte[].class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "PBEKeySpec", + args = {char[].class, byte[].class, int.class} + ) public void testPBEKeySpec3() { char[] password = new char[] {'1', '2', '3', '4', '5'}; byte[] salt = new byte[] {1, 2, 3, 4, 5}; @@ -236,15 +227,12 @@ public class PBEKeySpecTest extends TestCase { * clearPassword() method testing. Tests that internal copy of password * is cleared after the method call. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "clearPassword", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "clearPassword", + args = {} + ) public void testClearPassword() { char[] password = new char[] {'1', '2', '3', '4', '5'}; PBEKeySpec pbeks = new PBEKeySpec(password); @@ -262,15 +250,12 @@ public class PBEKeySpecTest extends TestCase { * to the password specified in the constructor and that the change of * returned array does not cause the change of internal array. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "Exception was checked in testClearPassword() method.", - targets = { - @TestTarget( - methodName = "getPassword", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Exception was checked in testClearPassword() method.", + method = "getPassword", + args = {} + ) public void testGetPassword() { char[] password = new char[] {'1', '2', '3', '4', '5'}; PBEKeySpec pbeks = new PBEKeySpec(password); @@ -292,15 +277,12 @@ public class PBEKeySpecTest extends TestCase { * Also it checks that the method returns null if salt is not * specified. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getSalt", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getSalt", + args = {} + ) public void testGetSalt() { char[] password = new char[] {'1', '2', '3', '4', '5'}; byte[] salt = new byte[] {1, 2, 3, 4, 5}; @@ -326,15 +308,12 @@ public class PBEKeySpecTest extends TestCase { * Also it checks that the method returns 0 if iterationCount is not * specified. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getIterationCount", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getIterationCount", + args = {} + ) public void testGetIterationCount() { char[] password = new char[] {'1', '2', '3', '4', '5'}; byte[] salt = new byte[] {1, 2, 3, 4, 5}; @@ -352,15 +331,12 @@ public class PBEKeySpecTest extends TestCase { /** * getKeyLength() method testing. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getKeyLength", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getKeyLength", + args = {} + ) public void testGetKeyLength() { char[] password = new char[] {'1', '2', '3', '4', '5'}; byte[] salt = new byte[] {1, 2, 3, 4, 5}; diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PBEParameterSpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PBEParameterSpecTest.java index d627d12..b294995 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PBEParameterSpecTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PBEParameterSpecTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto.spec; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.util.Arrays; @@ -46,15 +46,12 @@ public class PBEParameterSpecTest extends TestCase { * Tests the behavior of the method in the case of null input array * and tests that input array is copied during the object initialization. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "PBEParameterSpec", - methodArgs = {byte[].class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "PBEParameterSpec", + args = {byte[].class, int.class} + ) public void testPBEParameterSpec() { byte[] salt = {1, 2, 3, 4, 5}; int iterationCount = 10; @@ -78,15 +75,12 @@ public class PBEParameterSpecTest extends TestCase { * to the salt specified in the constructor and that the change of * returned array does not cause the change of internal array. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getSalt", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getSalt", + args = {} + ) public void testGetSalt() { byte[] salt = new byte[] {1, 2, 3, 4, 5}; int iterationCount = 10; @@ -106,15 +100,12 @@ public class PBEParameterSpecTest extends TestCase { * getIterationCount() method testing. Tests that returned value is equal * to the value specified in the constructor. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getIterationCount", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getIterationCount", + args = {} + ) public void testGetIterationCount() { byte[] salt = new byte[] {1, 2, 3, 4, 5}; int iterationCount = 10; diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PSourceTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PSourceTest.java index 6c13cfd..08e8acd 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PSourceTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/PSourceTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto.spec; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.util.Arrays; import javax.crypto.spec.PSource; @@ -45,15 +45,13 @@ public class PSourceTest extends TestCase { * DEFAULT field, and that input p array is copied to protect against * subsequent modification. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "Nested class.", - targets = { - @TestTarget( - methodName = "PSource.PSpecified", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Nested class.", + clazz = PSource.PSpecified.class, + method = "PSpecified", + args = { byte[].class } + ) public void testPSpecified() { try { new PSource.PSpecified(null); @@ -78,13 +76,20 @@ public class PSourceTest extends TestCase { * array specified in the constructor. Checks that modification * of returned array does not affect the internal array. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "!Constants", - methodArgs = {} + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = PSource.PSpecified.class, + method = "PSpecified", + args = {byte[].class} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + clazz = PSource.PSpecified.class, + method = "getValue", + args = {} ) }) public void testGetValue() { @@ -107,7 +112,12 @@ public class PSourceTest extends TestCase { * PSource(String pSrcName) method testing. Tests that returned value is * equal to the value specified in the constructor. */ - @TestInfo(level = TestLevel.PARTIAL_OK, purpose = "Checks NullPointerException", targets = {@TestTarget(methodName = "PSource", methodArgs = {java.lang.String.class})}) + @TestTargetNew( + level = TestLevel.PARTIAL_COMPLETE, + notes = "Checks NullPointerException", + method = "PSource", + args = {java.lang.String.class} + ) public void testPSource() { try { new PSource(null) {}; @@ -121,9 +131,20 @@ public class PSourceTest extends TestCase { * getAlgorithm() method testing. Tests that returned value is * equal to the value specified in the constructor. */ - @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { - @TestTarget(methodName = "getAlgorithm", methodArgs = {}), - @TestTarget(methodName = "PSource", methodArgs = {java.lang.String.class})}) + @TestTargets({ + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getAlgorithm", + args = {} + ), + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "PSource", + args = {java.lang.String.class} + ) + }) public void testGetAlgorithm() { String pSrcName = "pSrcName"; PSource ps = new PSource(pSrcName) {}; diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/RC2ParameterSpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/RC2ParameterSpecTest.java index 38b11b0..cf72d23 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/RC2ParameterSpecTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/RC2ParameterSpecTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto.spec; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.lang.IllegalArgumentException; import java.util.Arrays; @@ -48,15 +48,12 @@ public class RC2ParameterSpecTest extends TestCase { * inappropriate constructor parameters and that input iv array is * copied to protect against subsequent modification. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "RC2ParameterSpec", - methodArgs = {int.class, byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "RC2ParameterSpec", + args = {int.class, byte[].class} + ) public void testRC2ParameterSpec1() { int effectiveKeyBits = 10; byte[] iv = {1, 2, 3, 4, 5, 6, 7, 8}; @@ -88,15 +85,12 @@ public class RC2ParameterSpecTest extends TestCase { * inappropriate constructor parameters and that input iv array is * copied to protect against subsequent modification. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "RC2ParameterSpec", - methodArgs = {int.class, byte[].class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "RC2ParameterSpec", + args = {int.class, byte[].class, int.class} + ) public void testRC2ParameterSpec2() { int effectiveKeyBits = 10; byte[] iv = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; @@ -127,15 +121,12 @@ public class RC2ParameterSpecTest extends TestCase { * getEffectiveKeyBits() method testing. Tests that returned value is * equal to the value specified in the constructor. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getEffectiveKeyBits", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getEffectiveKeyBits", + args = {} + ) public void testGetEffectiveKeyBits() { int effectiveKeyBits = 10; byte[] iv = {1, 2, 3, 4, 5, 6, 7, 8}; @@ -152,15 +143,12 @@ public class RC2ParameterSpecTest extends TestCase { * of returned array does not affect the internal array. Also it checks * that getIV() method returns null if iv is not specified. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getIV", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getIV", + args = {} + ) public void testGetIV() { int effectiveKeyBits = 10; byte[] iv = new byte[] {1, 2, 3, 4, 5, 6, 7, 8}; @@ -185,15 +173,12 @@ public class RC2ParameterSpecTest extends TestCase { * operation: it should be reflexive, symmetric, transitive, consistent * and should be false on null object. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "equals", - methodArgs = {java.lang.Object.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "equals", + args = {java.lang.Object.class} + ) public void testEquals() { int effectiveKeyBits = 10; byte[] iv = new byte[] {1, 2, 3, 4, 5, 6, 7, 8}; @@ -234,15 +219,12 @@ public class RC2ParameterSpecTest extends TestCase { * hashCode() method testing. Tests that for equal objects hash codes * are equal. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "hashCode", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "hashCode", + args = {} + ) public void testHashCode() { int effectiveKeyBits = 0; byte[] iv = new byte[] {1, 2, 3, 4, 5, 6, 7, 8}; @@ -253,6 +235,21 @@ public class RC2ParameterSpecTest extends TestCase { assertTrue("Equal objects should have the same hash codes.", ps1.hashCode() == ps2.hashCode()); } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "RC2ParameterSpec", + args = {int.class} + ) + public void test_constructorI() { + int effectiveKeyBits = 0; + + RC2ParameterSpec ps1 = new RC2ParameterSpec(effectiveKeyBits); + RC2ParameterSpec ps2 = new RC2ParameterSpec(effectiveKeyBits); + + assertTrue(ps1.equals(ps2)); + } public static Test suite() { return new TestSuite(RC2ParameterSpecTest.class); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/RC5ParameterSpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/RC5ParameterSpecTest.java index caf047f..6182615 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/RC5ParameterSpecTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/RC5ParameterSpecTest.java @@ -23,9 +23,9 @@ package org.apache.harmony.crypto.tests.javax.crypto.spec; import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetNew; import java.util.Arrays; @@ -47,15 +47,12 @@ public class RC5ParameterSpecTest extends TestCase { * inappropriate constructor parameters and that input iv array is * copied to protect against subsequent modification. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "RC5ParameterSpec", - methodArgs = {int.class, int.class, int.class, byte[].class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "RC5ParameterSpec", + args = {int.class, int.class, int.class, byte[].class} + ) public void testRC5ParameterSpec1() { int version = 1; int rounds = 5; @@ -97,15 +94,12 @@ public class RC5ParameterSpecTest extends TestCase { * the case of inappropriate constructor parameters and that input iv array * is copied to protect against subsequent modification. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "RC5ParameterSpec", - methodArgs = {int.class, int.class, int.class, byte[].class, int.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "RC5ParameterSpec", + args = {int.class, int.class, int.class, byte[].class, int.class} + ) public void testRC5ParameterSpec2() { int version = 1; int rounds = 5; @@ -162,15 +156,12 @@ public class RC5ParameterSpecTest extends TestCase { * getVersion() method testing. Tests that returned value is * equal to the value specified in the constructor. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getVersion", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getVersion", + args = {} + ) public void testGetVersion() { int version = 1; int rounds = 5; @@ -186,15 +177,12 @@ public class RC5ParameterSpecTest extends TestCase { * getRounds() method testing. Tests that returned value is * equal to the value specified in the constructor. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getRounds", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getRounds", + args = {} + ) public void testGetRounds() { int version = 1; int rounds = 5; @@ -210,15 +198,12 @@ public class RC5ParameterSpecTest extends TestCase { * getWordSize() method testing. Tests that returned value is * equal to the value specified in the constructor. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getWordSize", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getWordSize", + args = {} + ) public void testGetWordSize() { int version = 1; int rounds = 5; @@ -236,15 +221,12 @@ public class RC5ParameterSpecTest extends TestCase { * of returned array does not affect the internal array. Also it checks * that getIV() method returns null if iv is not specified. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getIV", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getIV", + args = {} + ) public void testGetIV() { int version = 1; int rounds = 5; @@ -272,15 +254,12 @@ public class RC5ParameterSpecTest extends TestCase { * operation: it should be reflexive, symmetric, transitive, consistent * and should be false on null object. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "equals", - methodArgs = {java.lang.Object.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "equals", + args = {java.lang.Object.class} + ) public void testEquals() { int version = 1; int rounds = 5; @@ -331,15 +310,12 @@ public class RC5ParameterSpecTest extends TestCase { * hashCode() method testing. Tests that for equal objects hash codes * are equal. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "hashCode", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "hashCode", + args = {} + ) public void testHashCode() { int version = 1; int rounds = 5; @@ -353,6 +329,23 @@ public class RC5ParameterSpecTest extends TestCase { assertTrue("Equal objects should have the same hash codes.", ps1.hashCode() == ps2.hashCode()); } + + @TestTargetNew( + level = TestLevel.COMPLETE, + method = "RC5ParameterSpec", + args = {int.class, int.class, int.class} + ) + public void test_constructorIII() { + int version = 1; + int rounds = 5; + int wordSize = 16; + RC5ParameterSpec ps1 = new RC5ParameterSpec(version, rounds, wordSize); + RC5ParameterSpec ps2 = new RC5ParameterSpec(version, rounds, wordSize); + RC5ParameterSpec ps3 = new RC5ParameterSpec(version, rounds, wordSize + 1); + + assertTrue(ps1.equals(ps2)); + assertFalse(ps1.equals(ps3)); + } public static Test suite() { return new TestSuite(RC5ParameterSpecTest.class); diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/SecretKeySpecTest.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/SecretKeySpecTest.java index 61371aa..f7a762f 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/SecretKeySpecTest.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/spec/SecretKeySpecTest.java @@ -22,19 +22,19 @@ package org.apache.harmony.crypto.tests.javax.crypto.spec; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestInfo; +import dalvik.annotation.KnownFailure; import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTarget; - -import java.util.Arrays; - -import javax.crypto.spec.SecretKeySpec; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTargetNew; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; +import java.util.Arrays; + +import javax.crypto.spec.SecretKeySpec; + @TestTargetClass(SecretKeySpec.class) /** */ @@ -47,15 +47,12 @@ public class SecretKeySpecTest extends TestCase { * constructor parameters and that input iv array is * copied to protect against subsequent modification. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "SecretKeySpec", - methodArgs = {byte[].class, java.lang.String.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "SecretKeySpec", + args = {byte[].class, java.lang.String.class} + ) public void testSecretKeySpec1() { byte[] key = new byte[] {1, 2, 3, 4, 5}; String algorithm = "Algorithm"; @@ -94,16 +91,13 @@ public class SecretKeySpecTest extends TestCase { * the case of inappropriate constructor parameters and that input iv array * is copied to protect against subsequent modification. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "SecretKeySpec", - methodArgs = {byte[].class, int.class, int.class, java.lang.String.class} - ) - }) - public void _testSecretKeySpec2() { + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "SecretKeySpec", + args = {byte[].class, int.class, int.class, java.lang.String.class} + ) + public void testSecretKeySpec2() { byte[] key = new byte[] {1, 2, 3, 4, 5}; int offset = 1; int len = 4; @@ -138,21 +132,14 @@ public class SecretKeySpecTest extends TestCase { } try { - new SecretKeySpec(key, -1, key.length, algorithm); - fail("An IllegalArgumentException should be thrown " - + "in the case of null key."); + new SecretKeySpec(key, 0, -1, algorithm); + fail("An ArrayIndexOutOfBoundsException should be thrown " + + "in the case of illegal length."); } catch (IllegalArgumentException e) { fail("Not expected IllegalArgumentException was thrown."); } catch (ArrayIndexOutOfBoundsException e) { } - try { - new SecretKeySpec(key, offset, len, null); - fail("An IllegalArgumentException should be thrown " - + "in the case of null algorithm."); - } catch (IllegalArgumentException e) { - } - SecretKeySpec ks = new SecretKeySpec(key, algorithm); key[offset] ++; assertFalse("The change of key specified in the constructor " @@ -167,20 +154,40 @@ public class SecretKeySpecTest extends TestCase { //expected } } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "SecretKeySpec", + args = {byte[].class, int.class, int.class, java.lang.String.class} + ) + @KnownFailure("Constructor does not check if offset is negative") + public void testSecretKeySpec3() { + byte[] key = new byte[] {1, 2, 3, 4, 5}; + int offset = 1; + int len = 4; + String algorithm = "Algorithm"; + + try { + new SecretKeySpec(key, -1, key.length, algorithm); + fail("An ArrayIndexOutOfBoundsException should be thrown " + + "in the case of illegal offset."); + } catch (IllegalArgumentException e) { + fail("Not expected IllegalArgumentException was thrown."); + } catch (ArrayIndexOutOfBoundsException e) { + } + } /** * getAlgorithm() method testing. Tests that returned value is * equal to the value specified in the constructor. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getAlgorithm", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getAlgorithm", + args = {} + ) public void testGetAlgorithm() { byte[] key = new byte[] {1, 2, 3, 4, 5}; String algorithm = "Algorithm"; @@ -194,15 +201,12 @@ public class SecretKeySpecTest extends TestCase { /** * getFormat() method testing. Tests that returned value is "RAW". */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getFormat", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getFormat", + args = {} + ) public void testGetFormat() { byte[] key = new byte[] {1, 2, 3, 4, 5}; String algorithm = "Algorithm"; @@ -217,15 +221,12 @@ public class SecretKeySpecTest extends TestCase { * array specified in the constructor. Checks that modification * of returned array does not affect the internal array. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "getEncoded", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getEncoded", + args = {} + ) public void testGetEncoded() { byte[] key = new byte[] {1, 2, 3, 4, 5}; String algorithm = "Algorithm"; @@ -252,15 +253,12 @@ public class SecretKeySpecTest extends TestCase { * hashCode() method testing. Tests that for equal objects hash codes * are equal. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "hashCode", - methodArgs = {} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "hashCode", + args = {} + ) public void testHashCode() { byte[] key = new byte[] {1, 2, 3, 4, 5}; String algorithm = "Algorithm"; @@ -276,15 +274,12 @@ public class SecretKeySpecTest extends TestCase { * operation: it should be reflexive, symmetric, transitive, consistent * and should be false on null object. */ -@TestInfo( - level = TestLevel.COMPLETE, - purpose = "", - targets = { - @TestTarget( - methodName = "equals", - methodArgs = {java.lang.Object.class} - ) - }) + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "equals", + args = {java.lang.Object.class} + ) public void testEquals() { byte[] key = new byte[] {1, 2, 3, 4, 5}; String algorithm = "Algorithm"; diff --git a/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyExemptionMechanismSpi.java b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyExemptionMechanismSpi.java index 750765e..ddd6f26 100644 --- a/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyExemptionMechanismSpi.java +++ b/crypto/src/test/java/org/apache/harmony/crypto/tests/support/MyExemptionMechanismSpi.java @@ -83,6 +83,9 @@ public class MyExemptionMechanismSpi extends ExemptionMechanismSpi { if (!(key instanceof tmpKey)) { throw new ExemptionMechanismException("Incorrect key"); } + if (params == null) { + throw new InvalidAlgorithmParameterException("params is null"); + } } @Override @@ -95,6 +98,9 @@ public class MyExemptionMechanismSpi extends ExemptionMechanismSpi { if (!(key instanceof tmpKey)) { throw new ExemptionMechanismException("Incorrect key"); } + if (params == null) { + throw new InvalidAlgorithmParameterException("params is null"); + } } @SuppressWarnings("serial") diff --git a/crypto/src/test/java/tests/crypto/AllTests.java b/crypto/src/test/java/tests/crypto/AllTests.java index 8079d3e..795d0a9 100644 --- a/crypto/src/test/java/tests/crypto/AllTests.java +++ b/crypto/src/test/java/tests/crypto/AllTests.java @@ -30,11 +30,12 @@ public class AllTests { } public static Test suite() { - TestSuite suite = new TestSuite("All crypto test suites"); + TestSuite suite = tests.TestSuiteFactory.createTestSuite("All crypto test suites"); // $JUnit-BEGIN$ suite.addTest(org.apache.harmony.crypto.tests.javax.crypto.interfaces.AllTests.suite()); suite.addTest(org.apache.harmony.crypto.tests.javax.crypto.serialization.AllTests.suite()); suite.addTest(org.apache.harmony.crypto.tests.javax.crypto.spec.AllTests.suite()); + suite.addTest(org.apache.harmony.crypto.tests.javax.crypto.func.AllTests.suite()); suite.addTest(org.apache.harmony.crypto.tests.javax.crypto.AllTests.suite()); // $JUnit-END$ return suite; diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.ciphertext b/crypto/src/test/resources/hyts_des-ede3-cbc.test1.ciphertext index 2d7b94b..2d7b94b 100644 --- a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.ciphertext +++ b/crypto/src/test/resources/hyts_des-ede3-cbc.test1.ciphertext diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.iv b/crypto/src/test/resources/hyts_des-ede3-cbc.test1.iv index 401f335..401f335 100644 --- a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.iv +++ b/crypto/src/test/resources/hyts_des-ede3-cbc.test1.iv diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.key b/crypto/src/test/resources/hyts_des-ede3-cbc.test1.key index 2ffb5ea..2ffb5ea 100644 --- a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.key +++ b/crypto/src/test/resources/hyts_des-ede3-cbc.test1.key diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.plaintext b/crypto/src/test/resources/hyts_des-ede3-cbc.test1.plaintext index 9787ee2..9787ee2 100644 --- a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test1.plaintext +++ b/crypto/src/test/resources/hyts_des-ede3-cbc.test1.plaintext diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.ciphertext b/crypto/src/test/resources/hyts_des-ede3-cbc.test2.ciphertext Binary files differindex 1ae3f96..1ae3f96 100644 --- a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.ciphertext +++ b/crypto/src/test/resources/hyts_des-ede3-cbc.test2.ciphertext diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.iv b/crypto/src/test/resources/hyts_des-ede3-cbc.test2.iv index 72660fc..72660fc 100644 --- a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.iv +++ b/crypto/src/test/resources/hyts_des-ede3-cbc.test2.iv diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.key b/crypto/src/test/resources/hyts_des-ede3-cbc.test2.key index 9876f3f..9876f3f 100644 --- a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.key +++ b/crypto/src/test/resources/hyts_des-ede3-cbc.test2.key diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.plaintext b/crypto/src/test/resources/hyts_des-ede3-cbc.test2.plaintext Binary files differindex 1b5ef4a..1b5ef4a 100644 --- a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test2.plaintext +++ b/crypto/src/test/resources/hyts_des-ede3-cbc.test2.plaintext diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.ciphertext b/crypto/src/test/resources/hyts_des-ede3-cbc.test3.ciphertext Binary files differindex b9dd600..b9dd600 100644 --- a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.ciphertext +++ b/crypto/src/test/resources/hyts_des-ede3-cbc.test3.ciphertext diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.iv b/crypto/src/test/resources/hyts_des-ede3-cbc.test3.iv index 7a6ded5..7a6ded5 100644 --- a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.iv +++ b/crypto/src/test/resources/hyts_des-ede3-cbc.test3.iv diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.key b/crypto/src/test/resources/hyts_des-ede3-cbc.test3.key index e18fd89..e18fd89 100644 --- a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.key +++ b/crypto/src/test/resources/hyts_des-ede3-cbc.test3.key diff --git a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.plaintext b/crypto/src/test/resources/hyts_des-ede3-cbc.test3.plaintext Binary files differindex f45bd88..f45bd88 100644 --- a/crypto/src/test/java/resources/hyts_des-ede3-cbc.test3.plaintext +++ b/crypto/src/test/resources/hyts_des-ede3-cbc.test3.plaintext |