You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sm...@apache.org on 2006/12/15 11:40:22 UTC
svn commit: r487513 - in
/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security:
AlgorithmParameters2Test.java AlgorithmParametersTest.java
Author: smishura
Date: Fri Dec 15 02:40:18 2006
New Revision: 487513
URL: http://svn.apache.org/viewvc?view=rev&rev=487513
Log:
Merging and refactoring tests for:
- AlgorithmParameters.getEncoded()
- AlgorithmParameters.getEncoded(String format)
Modified:
harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParameters2Test.java
harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java
Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParameters2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParameters2Test.java?view=diff&rev=487513&r1=487512&r2=487513
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParameters2Test.java (original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParameters2Test.java Fri Dec 15 02:40:18 2006
@@ -26,50 +26,6 @@
public class AlgorithmParameters2Test extends junit.framework.TestCase {
/**
- * @tests java.security.AlgorithmParameters#getEncoded()
- */
- public void test_getEncoded() throws Exception {
- // Test for method byte []
- // java.security.AlgorithmParameters.getEncoded()
- AlgorithmParameters params = AlgorithmParameters.getInstance("DSA");
-
- byte[] enc = null;
- try {
- enc = params.getEncoded();
- fail("should not get encoded from un-initialized instance");
- } catch (IOException e) {
- // expected
- }
-
- params.init(new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE,
- BigInteger.ONE));
- enc = params.getEncoded();
- assertNotNull("encoded is null", enc);
- }
-
- /**
- * @tests java.security.AlgorithmParameters#getEncoded(java.lang.String)
- */
- public void test_getEncodedLjava_lang_String() throws Exception {
- // Test for method byte []
- // java.security.AlgorithmParameters.getEncoded(java.lang.String)
- AlgorithmParameters params = AlgorithmParameters.getInstance("DSA");
-
- params.init(new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE,
- BigInteger.ONE));
-
- // getEncoded behavior is not specified for unknown 'format'
- // different providers work in different manner:
- // 1.5 RI provider uses primary encoding format,
- // but BC provider returns null.
- // As it is provider specific behavior - it is not tested.
- //byte[] enc = params.getEncoded("JUNK");
-
- byte[] enc = params.getEncoded("ASN.1");
- assertNotNull("ANS.1 should be supported", enc);
- }
-
- /**
* @tests java.security.AlgorithmParameters#getParameterSpec(java.lang.Class)
*/
public void test_getParameterSpecLjava_lang_Class() throws Exception {
Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java?view=diff&rev=487513&r1=487512&r2=487513
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/AlgorithmParametersTest.java Fri Dec 15 02:40:18 2006
@@ -23,11 +23,13 @@
package org.apache.harmony.security.tests.java.security;
import java.io.IOException;
+import java.math.BigInteger;
import java.security.AlgorithmParameters;
import java.security.AlgorithmParametersSpi;
import java.security.Provider;
import java.security.Security;
import java.security.spec.AlgorithmParameterSpec;
+import java.security.spec.DSAParameterSpec;
import java.security.spec.InvalidParameterSpecException;
import junit.framework.TestCase;
@@ -75,6 +77,75 @@
assertEquals("AAA", ap.getAlgorithm());
}
+ /**
+ * @tests java.security.AlgorithmParameters#getEncoded()
+ */
+ public void test_getEncoded() throws Exception {
+
+ final byte[] enc = new byte[] { 0x02, 0x01, 0x03 };
+
+ MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {
+ protected byte[] engineGetEncoded() throws IOException {
+ return enc;
+ }
+ };
+
+ AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p,
+ "algorithm");
+
+ //
+ // test: IOException if not initialized
+ //
+ try {
+ params.getEncoded();
+ fail("should not get encoded from un-initialized instance");
+ } catch (IOException e) {
+ // expected
+ }
+
+ //
+ // test: corresponding spi method is invoked
+ //
+ params.init(new MyAlgorithmParameterSpec());
+ assertSame(enc, params.getEncoded());
+ }
+
+ /**
+ * @tests java.security.AlgorithmParameters#getEncoded(String)
+ */
+ public void test_getEncodedLjava_lang_String() throws Exception {
+
+ final byte[] enc = new byte[] { 0x02, 0x01, 0x03 };
+
+ final String strFormatParam = "format";
+
+ MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {
+ protected byte[] engineGetEncoded(String format) throws IOException {
+ assertEquals(strFormatParam, format);
+ return enc;
+ }
+ };
+
+ AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p,
+ "algorithm");
+
+ //
+ // test: IOException if not initialized
+ //
+ try {
+ params.getEncoded(strFormatParam);
+ fail("should not get encoded from un-initialized instance");
+ } catch (IOException e) {
+ // expected
+ }
+
+ //
+ // test: corresponding spi method is invoked
+ //
+ params.init(new MyAlgorithmParameterSpec());
+ assertSame(enc, params.getEncoded(strFormatParam));
+ }
+
/**
* @tests java.security.AlgorithmParameters#getInstance(String)
*/
@@ -170,18 +241,6 @@
private void checkUnititialized(AlgorithmParameters ap) {
try {
- ap.getEncoded();
- fail("getEncoded(): No expected IOException");
- } catch (java.io.IOException e) {
- }
-
- try {
- ap.getEncoded("aaa");
- fail("getEncoded(format): No expected IOException");
- } catch (java.io.IOException e) {
- }
-
- try {
//make it compilable on 1.5
ap.getParameterSpec((Class<AlgorithmParameterSpec>)new Object().getClass());
fail("getParameterSpec(): No expected InvalidParameterSpecException");
@@ -196,14 +255,6 @@
assertSame("getProvider() failed", p, ap.getProvider());
assertEquals("getAlgorithm() failed", "ABC", ap.getAlgorithm());
- ap.getEncoded();
- assertTrue("getEncoded() failed",
- MyAlgorithmParameters.runEngineGetEncoded1);
-
- ap.getEncoded("aaa");
- assertTrue("getEncoded(format) failed",
- MyAlgorithmParameters.runEngineGetEncoded2);
-
//make it compilable on 1.5
ap.getParameterSpec((Class<AlgorithmParameterSpec>) new Object()
.getClass());
@@ -245,10 +296,6 @@
public static boolean runEngineGetParameterSpec = false;
- public static boolean runEngineGetEncoded1 = false;
-
- public static boolean runEngineGetEncoded2 = false;
-
public static boolean runEngineToString = false;
protected void engineInit(AlgorithmParameterSpec paramSpec)
@@ -272,12 +319,10 @@
}
protected byte[] engineGetEncoded() throws IOException {
- runEngineGetEncoded1 = true;
return null;
}
protected byte[] engineGetEncoded(String format) throws IOException {
- runEngineGetEncoded2 = true;
return null;
}