summaryrefslogtreecommitdiffstats
path: root/support
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:03:55 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:03:55 -0800
commitdd828f42a5c83b4270d4fbf6fce2da1878f1e84a (patch)
treefdd4b68fa1020f2b6426034c94823419a7236200 /support
parentfdb2704414a9ed92394ada0d1395e4db86889465 (diff)
downloadlibcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.zip
libcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.tar.gz
libcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.tar.bz2
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'support')
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MySSLContextSpi.java145
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyTrustManagerFactorySpi.java71
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/Support_Configuration.java475
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPath.java47
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertStoreSpi.java6
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificate.java40
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificateFactorySpi.java2
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/resource/Support_Resources.java177
-rw-r--r--support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java3
-rw-r--r--support/src/test/java/tests/support/Support_CollectionTest.java6
-rw-r--r--support/src/test/java/tests/support/Support_GetResource.java25
-rw-r--r--support/src/test/java/tests/support/Support_ListTest.java3
-rw-r--r--support/src/test/java/tests/support/Support_SetTest.java3
-rw-r--r--support/src/test/java/tests/support/Support_UnmodifiableCollectionTest.java3
-rw-r--r--support/src/test/java/tests/support/Support_UnmodifiableMapTest.java3
15 files changed, 999 insertions, 10 deletions
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MySSLContextSpi.java b/support/src/test/java/org/apache/harmony/security/tests/support/MySSLContextSpi.java
new file mode 100644
index 0000000..c503675
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MySSLContextSpi.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.security.tests.support;
+
+import java.nio.ByteBuffer;
+import java.security.KeyManagementException;
+import java.security.SecureRandom;
+
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.SSLContextSpi;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLEngineResult;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSessionContext;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+
+/**
+ * Additional class for verification of SSLContextSpi and SSLContext
+ * functionality
+ *
+ */
+
+public class MySSLContextSpi extends SSLContextSpi {
+ private boolean init = false;
+ protected void engineInit(KeyManager[] km, TrustManager[] tm,
+ SecureRandom sr) throws KeyManagementException {
+ if (sr == null) {
+ throw new KeyManagementException(
+ "secureRandom is null");
+ }
+ init = true;
+ }
+
+ protected SSLSocketFactory engineGetSocketFactory() {
+ if (!init) {
+ throw new RuntimeException("Not initialiazed");
+ };
+ return null;
+ }
+
+ protected SSLServerSocketFactory engineGetServerSocketFactory() {
+ if (!init) {
+ throw new RuntimeException("Not initialiazed");
+ }
+ return null;
+ }
+
+ protected SSLSessionContext engineGetServerSessionContext() {
+ if (!init) {
+ throw new RuntimeException("Not initialiazed");
+ }
+ return null;
+ }
+
+ protected SSLSessionContext engineGetClientSessionContext() {
+ if (!init) {
+ throw new RuntimeException("Not initialiazed");
+ }
+ return null;
+ }
+
+ /*
+ * FIXME: add these methods
+ */
+ protected SSLEngine engineCreateSSLEngine(String host, int port) {
+ if (!init) {
+ throw new RuntimeException("Not initialiazed");
+ }
+ return new tmpSSLEngine(host, port);
+ }
+
+ protected SSLEngine engineCreateSSLEngine() {
+ if (!init) {
+ throw new RuntimeException("Not initialiazed");
+ }
+ return new tmpSSLEngine();
+ }
+
+ public class tmpSSLEngine extends SSLEngine {
+ String tmpHost;
+ int tmpPort;
+ public tmpSSLEngine() {
+ tmpHost = null;
+ tmpPort = 0;
+ }
+ public tmpSSLEngine(String host, int port) {
+ tmpHost = host;
+ tmpPort = port;
+ }
+ public String getPeerHost() {
+ return tmpHost;
+ }
+ public int getPeerPort() {
+ return tmpPort;
+ }
+ public void beginHandshake() throws SSLException { }
+ public void closeInbound() throws SSLException { }
+ public void closeOutbound() {}
+ public Runnable getDelegatedTask() { return null; }
+ public String[] getEnabledCipherSuites() { return null; }
+ public String[] getEnabledProtocols() {return null; }
+ public boolean getEnableSessionCreation() { return true; }
+ public SSLEngineResult.HandshakeStatus getHandshakeStatus() { return null; };
+ public boolean getNeedClientAuth() { return true; }
+ public SSLSession getSession() { return null; }
+ public String[] getSupportedCipherSuites() { return null; }
+ public String[] getSupportedProtocols() { return null; }
+ public boolean getUseClientMode() { return true; }
+ public boolean getWantClientAuth() { return true; }
+ public boolean isInboundDone() { return true; }
+ public boolean isOutboundDone() { return true; }
+ public void setEnabledCipherSuites(String[] suites) { }
+ public void setEnabledProtocols(String[] protocols) { }
+ public void setEnableSessionCreation(boolean flag) { }
+ public void setNeedClientAuth(boolean need) { }
+ public void setUseClientMode(boolean mode) { }
+ public void setWantClientAuth(boolean want) { }
+ public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts,
+ int offset, int length) throws SSLException {
+ return null;
+ }
+ public SSLEngineResult wrap(ByteBuffer[] srcs, int offset,
+ int length, ByteBuffer dst) throws SSLException {
+ return null;
+ }
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyTrustManagerFactorySpi.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyTrustManagerFactorySpi.java
new file mode 100644
index 0000000..4c2ea8e
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyTrustManagerFactorySpi.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.security.tests.support;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+
+import javax.net.ssl.ManagerFactoryParameters;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactorySpi;
+
+/**
+ * Class for vertifying TrustManagerFactorySpi and TrustManagerFactory
+ * functionality
+ *
+ */
+
+public class MyTrustManagerFactorySpi extends TrustManagerFactorySpi {
+ protected void engineInit(KeyStore ks) throws KeyStoreException {
+ if (ks == null) {
+ throw new KeyStoreException("Not supported operation for null KeyStore");
+ }
+ }
+
+ protected void engineInit(ManagerFactoryParameters spec)
+ throws InvalidAlgorithmParameterException {
+ if (spec == null) {
+ throw new InvalidAlgorithmParameterException("Null parameter");
+ }
+ if (spec instanceof Parameters) {
+ try {
+ engineInit(((Parameters)spec).getKeyStore());
+ } catch (KeyStoreException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ throw new InvalidAlgorithmParameterException("Invalid parameter");
+ }
+ }
+
+ protected TrustManager[] engineGetTrustManagers() {
+ return null;
+ }
+
+
+ public static class Parameters implements ManagerFactoryParameters {
+ private KeyStore keyStore;
+ public Parameters (KeyStore ks) {
+ this.keyStore = ks;
+ }
+ public KeyStore getKeyStore() {
+ return keyStore;
+ }
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/Support_Configuration.java b/support/src/test/java/org/apache/harmony/security/tests/support/Support_Configuration.java
new file mode 100644
index 0000000..51bb892
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/Support_Configuration.java
@@ -0,0 +1,475 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.security.tests.support;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Hashtable;
+
+/**
+ * This class is responsible for providing the dynamic names and addresses for
+ * the java.net classes. There are two directories which need to be placed on an
+ * ftp server and an http server which should accompany this source. The
+ * ftp-files have to be placed on an ftp server and have to be the root of a
+ * user jcltest with password jclpass. The testres files must be available on an
+ * HTTP server and the name and location can be configured below.
+ */
+public class Support_Configuration {
+
+ public static String DomainAddress = "apache.org";
+
+ public static String WebName = "jcltest.";
+
+ public static final String HomeAddress;
+
+ public static String TestResourcesDir = "/testres231";
+
+ public static final String TestResources;
+
+ public static String HomeAddressResponse = "HTTP/1.1 200 OK";
+
+ public static String HomeAddressSoftware = "Jetty(6.0.x)";
+
+ public static String ProxyServerTestHost = "jcltest.apache.org";
+
+ public static String SocksServerTestHost = "jcltest.apache.org";
+
+ public static int SocksServerTestPort = 1080;
+
+ // Need an IP address that does not resolve to a host name
+ public static String UnresolvedIP = "192.168.99.99";
+
+ // the bytes for an address which represents an address which is not
+ // one of the addresses for any of our machines on which tests will run
+ // it is used to verify we get the expected error when we try to bind
+ // to an address that is not one of the machines local addresses
+ public static byte nonLocalAddressBytes[] = { 1, 0, 0, 0 };
+
+ public static String InetTestAddress = "localhost";
+
+ public static String InetTestIP = "127.0.0.1";
+
+ public static String InetTestAddress2 = "localhost";
+
+ public static String InetTestIP2 = "127.0.0.1";
+
+ public static byte[] InetTestCaddr = { 9, 26, -56, -111 };
+
+ public static int InetTestHashcode = 2130706433;
+
+ public static final String HomeAddress6 = "jcltest6.apache.org";
+
+ public static String IPv6GlobalAddressJcl4 = "FE80:0000:0000:0000:020D:60FF:FE0F:A776%4"; // this
+
+ public static String ProxyServerTestHostIPv6 = "jcltest6.apache.org";
+
+ public static String InetTestIP6 = "fe80::20d:60ff:fe24:7410";
+
+ public static String InetTestIP6LO = "::1";
+
+ // ip address that resolves to a host that is not present on the local
+ // network
+ // this allows us to check the timeouts for connect
+ public static String ResolvedNotExistingHost = "9.26.194.72";
+
+ /**
+ * You can compute the hash code with the following code: try { String name =
+ * "whatever.xxx.com";
+ * System.out.println(InetAddress.getByName(name).hashCode()); } catch
+ * (UnknownHostException e) {}
+ */
+
+ /**
+ * An address that resolves to more than one IP address so that the
+ * getAllByName test has something to test.
+ */
+ public static String SpecialInetTestAddress = "jcltestmultiple.apache.org";
+
+ public static int SpecialInetTestAddressNumber = 4;
+
+ /**
+ * InetAlias1 and InetAlias2 must be different host names that resolve to
+ * the same IP address.
+ */
+ public static String InetAlias1 = "alias1.apache.org";
+
+ public static String InetAlias2 = "alias2.apache.org";
+
+ public static String FTPTestAddress = "jcltest:jclpass@localhost";
+
+ public static String URLConnectionLastModifiedString = "Mon, 14 Jun 1999 21:06:22 GMT";
+
+ public static long URLConnectionLastModified = 929394382000L;
+
+ public static long URLConnectionDate = 929106872000L;
+
+ public static boolean RunCommTests = false;
+
+ public static String Port1 = "COM1";
+
+ public static String Port2 = "COM2";
+
+ static Hashtable<String, String> props = null;
+ static {
+ loadProperties();
+ HomeAddress = WebName + DomainAddress;
+ TestResources = HomeAddress + TestResourcesDir;
+ }
+
+ static void loadProperties() {
+ InputStream in = null;
+ Hashtable<String, String> props = new Hashtable<String, String>();
+
+ String iniName = System.getProperty("test.ini.file", "JCLAuto.ini");
+ if (System.getProperty("test.comm") != null) {
+ RunCommTests = true;
+ }
+
+ try {
+ in = new FileInputStream(iniName);
+ } catch (IOException e) {
+ } catch (Exception e) {
+ System.out.println("SupportConfiguration.loadProperties()");
+ System.out.println(e);
+ e.printStackTrace();
+ }
+ if (in == null) {
+ try {
+ Class<?> cl = Class
+ .forName("com.ibm.support.Support_Configuration");
+ in = cl.getResourceAsStream(iniName);
+ } catch (ClassNotFoundException e) {
+ }
+ }
+ try {
+ if (in != null) {
+ load(in, props);
+ }
+ } catch (IOException e) {
+ }
+ if (props.size() == 0) {
+ return;
+ }
+ String value;
+
+ value = props.get("DomainAddress");
+ if (value != null) {
+ DomainAddress = value;
+ }
+
+ value = props.get("WebName");
+ if (value != null) {
+ WebName = value;
+ }
+
+ value = props.get("TestResourcesDir");
+ if (value != null) {
+ TestResourcesDir = value;
+ }
+ value = props.get("HomeAddressResponse");
+ if (value != null) {
+ HomeAddressResponse = value;
+ }
+
+ value = props.get("HomeAddressSoftware");
+ if (value != null) {
+ HomeAddressSoftware = value;
+ }
+
+ value = props.get("ProxyServerTestHost");
+ if (value != null) {
+ ProxyServerTestHost = value;
+ }
+
+ value = props.get("SocksServerTestHost");
+ if (value != null) {
+ SocksServerTestHost = value;
+ }
+
+ value = props.get("SocksServerTestPort");
+ if (value != null) {
+ SocksServerTestPort = Integer.parseInt(value);
+ }
+
+ value = props.get("UnresolvedIP");
+ if (value != null) {
+ UnresolvedIP = value;
+ }
+
+ value = props.get("InetTestAddress");
+ if (value != null) {
+ InetTestAddress = value;
+ }
+
+ value = props.get("InetTestIP");
+ if (value != null) {
+ InetTestIP = value;
+ byte[] addr = new byte[4];
+ int last = 0;
+ try {
+ for (int i = 0; i < 3; i++) {
+ int dot = InetTestIP.indexOf('.', last);
+ addr[i] = (byte) Integer.parseInt(InetTestIP.substring(
+ last, dot));
+ last = dot + 1;
+ }
+ addr[3] = (byte) Integer.parseInt(InetTestIP.substring(last));
+ InetTestCaddr = addr;
+ } catch (RuntimeException e) {
+ System.out.println("Error parsing InetTestIP (" + InetTestIP
+ + ")");
+ System.out.println(e);
+ }
+ }
+
+ value = props.get("NonLocalAddressBytes");
+ if (value != null) {
+ String nonLocalAddressBytesString = value;
+ byte[] addr = new byte[4];
+ int last = 0;
+ try {
+ for (int i = 0; i < 3; i++) {
+ int dot = nonLocalAddressBytesString.indexOf('.', last);
+ addr[i] = (byte) Integer
+ .parseInt(nonLocalAddressBytesString.substring(
+ last, dot));
+ last = dot + 1;
+ }
+ addr[3] = (byte) Integer.parseInt(nonLocalAddressBytesString
+ .substring(last));
+ nonLocalAddressBytes = addr;
+ } catch (RuntimeException e) {
+ System.out.println("Error parsing NonLocalAddressBytes ("
+ + nonLocalAddressBytesString + ")");
+ System.out.println(e);
+ }
+ }
+
+ value = props.get("InetTestAddress2");
+ if (value != null) {
+ InetTestAddress2 = value;
+ }
+
+ value = props.get("InetTestIP2");
+ if (value != null) {
+ InetTestIP2 = value;
+ }
+
+ value = props.get("InetTestHashcode");
+ if (value != null) {
+ InetTestHashcode = Integer.parseInt(value);
+ }
+
+ value = props.get("SpecialInetTestAddress");
+ if (value != null) {
+ SpecialInetTestAddress = value;
+ }
+
+ value = props.get("SpecialInetTestAddressNumber");
+ if (value != null) {
+ SpecialInetTestAddressNumber = Integer.parseInt(value);
+ }
+
+ value = props.get("FTPTestAddress");
+ if (value != null) {
+ FTPTestAddress = value;
+ }
+
+ value = props.get("URLConnectionLastModifiedString");
+ if (value != null) {
+ URLConnectionLastModifiedString = value;
+ }
+
+ value = props.get("URLConnectionLastModified");
+ if (value != null) {
+ URLConnectionLastModified = Long.parseLong(value);
+ }
+
+ value = props.get("URLConnectionDate");
+ if (value != null) {
+ URLConnectionDate = Long.parseLong(value);
+ }
+
+ value = props.get("Port1");
+ if (value != null) {
+ Port1 = value;
+ }
+
+ value = props.get("Port2");
+ if (value != null) {
+ Port2 = value;
+ }
+
+ value = props.get("InetTestIP6");
+ if (value != null) {
+ InetTestIP6 = value;
+ }
+
+ value = props.get("InetTestIP6LO");
+ if (value != null) {
+ InetTestIP6LO = value;
+ }
+
+ value = props.get("ProxyServerTestHostIPv6");
+ if (value != null) {
+ ProxyServerTestHostIPv6 = value;
+ }
+
+ value = props.get("ResolvedNotExistingHost");
+ if (value != null) {
+ ResolvedNotExistingHost = value;
+ }
+
+ value = props.get("InetAlias1");
+ if (value != null) {
+ InetAlias1 = value;
+ }
+
+ value = props.get("InetAlias2");
+ if (value != null) {
+ InetAlias2 = value;
+ }
+
+ value = props.get("IPv6GlobalAddressJcl4");
+ if (value != null) {
+ IPv6GlobalAddressJcl4 = value;
+ }
+
+ }
+
+ static void load(InputStream in, Hashtable<String, String> result) throws IOException {
+ int NONE = 0, SLASH = 1, UNICODE = 2, CONTINUE = 3, DONE = 4, IGNORE = 5;
+ int mode = NONE, unicode = 0, count = 0, nextChar;
+ StringBuffer key = new StringBuffer(), value = new StringBuffer(), buffer = key;
+ boolean firstChar = true;
+
+ while ((nextChar = in.read()) != -1) {
+ if (mode == UNICODE) {
+ int digit = Character.digit((char) nextChar, 16);
+ if (digit >= 0) {
+ unicode = (unicode << 4) + digit;
+ if (++count < 4) {
+ continue;
+ }
+ }
+ mode = NONE;
+ buffer.append((char) unicode);
+ if (nextChar != '\n') {
+ continue;
+ }
+ }
+ if (mode == SLASH) {
+ mode = NONE;
+ switch (nextChar) {
+ case '\r':
+ mode = CONTINUE; // Look for a following \n
+ continue;
+ case '\n':
+ mode = IGNORE; // Ignore whitespace on the next line
+ continue;
+ case 'b':
+ nextChar = '\b';
+ break;
+ case 'f':
+ nextChar = '\f';
+ break;
+ case 'n':
+ nextChar = '\n';
+ break;
+ case 'r':
+ nextChar = '\r';
+ break;
+ case 't':
+ nextChar = '\t';
+ break;
+ case 'u':
+ mode = UNICODE;
+ unicode = count = 0;
+ continue;
+ }
+ } else {
+ switch (nextChar) {
+ case '#':
+ case '!':
+ if (firstChar) {
+ while ((nextChar = in.read()) != -1) {
+ if (nextChar == '\r' || nextChar == '\n') {
+ break;
+ }
+ }
+ continue;
+ }
+ break;
+ case '\n':
+ if (mode == CONTINUE) { // Part of a \r\n sequence
+ mode = IGNORE; // Ignore whitespace on the next line
+ continue;
+ }
+ // fall into the next case
+ case '\r':
+ mode = NONE;
+ firstChar = true;
+ if (key.length() > 0 || buffer == value) {
+ result.put(key.toString(), value.toString());
+ }
+ key.setLength(0);
+ value.setLength(0);
+ buffer = key;
+ continue;
+ case '\\':
+ mode = SLASH;
+ continue;
+ case ':':
+ case '=':
+ if (buffer == key) {
+ buffer = value;
+ continue;
+ }
+ break;
+ }
+ char c = (char) nextChar;
+ if ((c >= 0x1c && c <= 0x20) || (c >= 0x9 && c <= 0xd)) {
+ if (mode == CONTINUE) {
+ mode = IGNORE;
+ }
+ if (buffer.length() == 0 || mode == IGNORE) {
+ continue;
+ }
+ if (buffer == key) {
+ mode = DONE;
+ continue;
+ }
+ }
+ if (mode == IGNORE || mode == CONTINUE) {
+ mode = NONE;
+ }
+ }
+ firstChar = false;
+ if (mode == DONE) {
+ buffer = value;
+ mode = NONE;
+ }
+ buffer.append((char) nextChar);
+ }
+ if (key.length() > 0 || buffer == value) {
+ result.put(key.toString(), value.toString());
+ }
+ }
+
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPath.java b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPath.java
index ccdb216..06c2716 100644
--- a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPath.java
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPath.java
@@ -22,8 +22,8 @@
package org.apache.harmony.security.tests.support.cert;
+import java.io.ObjectStreamException;
import java.security.cert.CertPath;
-import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.util.Collections;
import java.util.Iterator;
@@ -36,10 +36,12 @@ import java.util.Vector;
*
*/
public class MyCertPath extends CertPath {
+ private static final long serialVersionUID = 7444835599161870893L;
/**
* my certificates list
*/
- private final Vector<Certificate> certificates;
+ private final Vector<MyCertificate> certificates;
+
/**
* List of encodings supported
*/
@@ -58,7 +60,7 @@ public class MyCertPath extends CertPath {
public MyCertPath(byte[] encoding) {
super("MyEncoding");
this.encoding = encoding;
- certificates = new Vector<Certificate>();
+ certificates = new Vector<MyCertificate>();
certificates.add(new MyCertificate("MyEncoding", encoding));
encodingNames = new Vector<String>();
encodingNames.add("MyEncoding");
@@ -68,7 +70,7 @@ public class MyCertPath extends CertPath {
* @return certificates list
* @see java.security.cert.CertPath#getCertificates()
*/
- public List<Certificate> getCertificates() {
+ public List<MyCertificate> getCertificates() {
return Collections.unmodifiableList(certificates);
}
@@ -83,8 +85,8 @@ public class MyCertPath extends CertPath {
/**
* @return encoded form of this cert path as specified by
* <code>encoding</code> parameter
- * @throws CertificateEncodingException if <code>encoding</code>
- * not equals "MyEncoding"
+ * @throws CertificateEncodingException
+ * if <code>encoding</code> not equals "MyEncoding"
* @see java.security.cert.CertPath#getEncoded(java.lang.String)
*/
public byte[] getEncoded(String encoding)
@@ -104,4 +106,37 @@ public class MyCertPath extends CertPath {
return Collections.unmodifiableCollection(encodingNames).iterator();
}
+ /**
+ * @return the CertPathRep to be serialized
+ * @see java.security.cert.CertPath#writeReplace()
+ */
+ public Object writeReplace() throws ObjectStreamException {
+ return super.writeReplace();
+ }
+
+ public class MyCertPathRep extends CertPath.CertPathRep {
+
+ private static final long serialVersionUID = 1609000085450479173L;
+
+ private String type;
+ private byte[] data;
+
+ public MyCertPathRep(String type, byte[] data) {
+ super(type, data);
+ this.data = data;
+ this.type = type;
+ }
+
+ public Object readResolve() throws ObjectStreamException {
+ return super.readResolve();
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+ }
}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertStoreSpi.java b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertStoreSpi.java
index fd6505c..fe3002e 100644
--- a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertStoreSpi.java
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertStoreSpi.java
@@ -23,11 +23,13 @@
package org.apache.harmony.security.tests.support.cert;
import java.security.InvalidAlgorithmParameterException;
+import java.security.cert.CRL;
import java.security.cert.CRLSelector;
import java.security.cert.CertSelector;
import java.security.cert.CertStoreException;
import java.security.cert.CertStoreParameters;
import java.security.cert.CertStoreSpi;
+import java.security.cert.Certificate;
import java.util.Collection;
/**
@@ -46,7 +48,7 @@ public class MyCertStoreSpi extends CertStoreSpi {
}
}
- public Collection engineGetCertificates(CertSelector selector)
+ public Collection<Certificate> engineGetCertificates(CertSelector selector)
throws CertStoreException {
if (selector == null) {
throw new CertStoreException("Parameter is null");
@@ -54,7 +56,7 @@ public class MyCertStoreSpi extends CertStoreSpi {
return null;
}
- public Collection engineGetCRLs(CRLSelector selector)
+ public Collection<CRL> engineGetCRLs(CRLSelector selector)
throws CertStoreException {
if (selector == null) {
throw new CertStoreException("Parameter is null");
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificate.java b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificate.java
index f06ed1d..e6d6034 100644
--- a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificate.java
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificate.java
@@ -22,6 +22,7 @@
package org.apache.harmony.security.tests.support.cert;
+import java.io.ObjectStreamException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
@@ -36,9 +37,12 @@ import java.security.cert.CertificateException;
*/
public class MyCertificate extends Certificate {
+ private static final long serialVersionUID = -1835303280727190066L;
// MyCertificate encoding
private final byte[] encoding;
+ public CertificateRep rep;
+
/**
* Constructs new object of class <code>MyCertificate</code>
*
@@ -83,11 +87,16 @@ public class MyCertificate extends Certificate {
return "[My test Certificate, type: " + getType() + "]";
}
+ public Object writeReplace() throws ObjectStreamException {
+ return super.writeReplace();
+ }
+
/**
* Returns public key (stub) from <code>MyCertificate</code> object
*/
public PublicKey getPublicKey() {
return new PublicKey() {
+ private static final long serialVersionUID = 788077928335589816L;
public String getAlgorithm() {
return "TEST";
}
@@ -100,4 +109,35 @@ public class MyCertificate extends Certificate {
};
}
+ public Certificate.CertificateRep getCertificateRep()
+ throws ObjectStreamException {
+ Object obj = super.writeReplace();
+ return (MyCertificateRep) obj;
+ }
+
+ public class MyCertificateRep extends Certificate.CertificateRep {
+
+ private static final long serialVersionUID = -3474284043994635553L;
+
+ private String type;
+ private byte[] data;
+
+ public MyCertificateRep(String type, byte[] data) {
+ super(type, data);
+ this.data = data;
+ this.type = type;
+ }
+
+ public Object readResolve() throws ObjectStreamException {
+ return super.readResolve();
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+ }
}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificateFactorySpi.java b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificateFactorySpi.java
index 8a94a6c..ea38e72 100644
--- a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificateFactorySpi.java
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificateFactorySpi.java
@@ -71,6 +71,7 @@ public class MyCertificateFactorySpi extends CertificateFactorySpi {
return null;
}
+ @SuppressWarnings("unchecked")
public Collection engineGenerateCertificates(InputStream inStream)
throws CertificateException {
if (!(inStream instanceof DataInputStream)) {
@@ -86,6 +87,7 @@ public class MyCertificateFactorySpi extends CertificateFactorySpi {
return null;
}
+ @SuppressWarnings("unchecked")
public Collection engineGenerateCRLs(InputStream inStream)
throws CRLException {
if (!(inStream instanceof DataInputStream)) {
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/resource/Support_Resources.java b/support/src/test/java/org/apache/harmony/security/tests/support/resource/Support_Resources.java
new file mode 100644
index 0000000..112b9e9
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/resource/Support_Resources.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.security.tests.support.resource;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.apache.harmony.security.tests.support.Support_Configuration;
+
+public class Support_Resources {
+
+ public static final String RESOURCE_PACKAGE = "/tests/resources/";
+
+ public static final String RESOURCE_PACKAGE_NAME = "tests.resources";
+
+ public static InputStream getStream(String name) {
+ return Support_Resources.class.getResourceAsStream(RESOURCE_PACKAGE
+ + name);
+ }
+
+ public static String getURL(String name) {
+ String folder = null;
+ String fileName = name;
+ File resources = createTempFolder();
+ int index = name.lastIndexOf("/");
+ if (index != -1) {
+ folder = name.substring(0, index);
+ name = name.substring(index + 1);
+ }
+ copyFile(resources, folder, name);
+ URL url = null;
+ String resPath = resources.toString();
+ if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\') {
+ resPath = resPath.substring(1);
+ }
+ try {
+ url = new URL("file:/" + resPath + "/" + fileName);
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return url.toString();
+ }
+
+ public static File createTempFolder() {
+
+ File folder = null;
+ try {
+ folder = File.createTempFile("hyts_resources", "", null);
+ folder.delete();
+ folder.mkdirs();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ folder.deleteOnExit();
+ return folder;
+ }
+
+ public static void copyFile(File root, String folder, String file) {
+ File f;
+ if (folder != null) {
+ f = new File(root.toString() + "/" + folder);
+ if (!f.exists()) {
+ f.mkdirs();
+ f.deleteOnExit();
+ }
+ } else {
+ f = root;
+ }
+
+ File dest = new File(f.toString() + "/" + file);
+
+ InputStream in = Support_Resources.getStream(folder == null ? file
+ : folder + "/" + file);
+ try {
+ copyLocalFileto(dest, in);
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public static File createTempFile(String suffix) throws IOException {
+ return File.createTempFile("hyts_", suffix, null);
+ }
+
+ public static void copyLocalFileto(File dest, InputStream in)
+ throws FileNotFoundException, IOException {
+ if (!dest.exists()) {
+ FileOutputStream out = new FileOutputStream(dest);
+ int result;
+ byte[] buf = new byte[4096];
+ while ((result = in.read(buf)) != -1) {
+ out.write(buf, 0, result);
+ }
+ in.close();
+ out.close();
+ dest.deleteOnExit();
+ }
+ }
+
+ public static File getExternalLocalFile(String url) throws IOException,
+ MalformedURLException {
+ File resources = createTempFolder();
+ InputStream in = new URL(url).openStream();
+ File temp = new File(resources.toString() + "/local.tmp");
+ copyLocalFileto(temp, in);
+ return temp;
+ }
+
+ public static String getResourceURL(String resource) {
+ return "http://" + Support_Configuration.TestResources + resource;
+ }
+
+ /**
+ * Util method to load resource files
+ *
+ * @param name - name of resource file
+ * @return - resource input stream
+ */
+ public static InputStream getResourceStream(String name) {
+
+ InputStream is = ClassLoader.getSystemClassLoader()
+ .getResourceAsStream(name);
+
+ if (is == null) {
+ throw new RuntimeException("Failed to load resource: " + name);
+ }
+
+ return is;
+ }
+
+ /**
+ * Util method to get absolute path to resource file
+ *
+ * @param name - name of resource file
+ * @return - path to resource
+ */
+ public static String getAbsoluteResourcePath(String name) {
+
+ URL url = ClassLoader.getSystemClassLoader().getResource(name);
+ if (url == null) {
+ throw new RuntimeException("Failed to load resource: " + name);
+ }
+
+ try {
+ return new File(url.toURI()).getAbsolutePath();
+ } catch (URISyntaxException e) {
+ throw new RuntimeException("Failed to load resource: " + name);
+ }
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java b/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java
index c783c6d..7e4797d 100644
--- a/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java
+++ b/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java
@@ -22,6 +22,8 @@
package org.apache.harmony.testframework.serialization;
+import dalvik.annotation.TestTargetClass;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -61,6 +63,7 @@ import junit.framework.TestCase;
* <b>&quot;RESOURCE_DIR&quot; </b> system property.
*
*/
+@TestTargetClass(Serializable.class)
public abstract class SerializationTest extends TestCase {
/**
diff --git a/support/src/test/java/tests/support/Support_CollectionTest.java b/support/src/test/java/tests/support/Support_CollectionTest.java
index 791222d..824768a 100644
--- a/support/src/test/java/tests/support/Support_CollectionTest.java
+++ b/support/src/test/java/tests/support/Support_CollectionTest.java
@@ -17,14 +17,16 @@
package tests.support;
+import dalvik.annotation.TestTargetClass;
+
import java.util.Collection;
import java.util.TreeSet;
/**
* @tests java.util.Collection
*/
-public class Support_CollectionTest extends junit.framework.TestCase {
-
+@TestTargetClass(java.util.Collection.class)
+public class Support_CollectionTest extends junit.framework.TestCase {
Collection<Integer> col; // must contain the Integers 0 to 99
public Support_CollectionTest(String p1) {
diff --git a/support/src/test/java/tests/support/Support_GetResource.java b/support/src/test/java/tests/support/Support_GetResource.java
new file mode 100644
index 0000000..cef4f8e
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_GetResource.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 tests.support;
+
+public class Support_GetResource {
+
+ public static String getResourceURL(String resource) {
+ return "http://" + Support_Configuration.TestResources + resource;
+ }
+}
diff --git a/support/src/test/java/tests/support/Support_ListTest.java b/support/src/test/java/tests/support/Support_ListTest.java
index 6e9160b..645a564 100644
--- a/support/src/test/java/tests/support/Support_ListTest.java
+++ b/support/src/test/java/tests/support/Support_ListTest.java
@@ -17,11 +17,14 @@
package tests.support;
+import dalvik.annotation.TestTargetClass;
+
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
+@TestTargetClass(List.class)
public class Support_ListTest extends junit.framework.TestCase {
List<Integer> list; // must contain the Integers 0 to 99 in order
diff --git a/support/src/test/java/tests/support/Support_SetTest.java b/support/src/test/java/tests/support/Support_SetTest.java
index 51ac1c4..4325e19 100644
--- a/support/src/test/java/tests/support/Support_SetTest.java
+++ b/support/src/test/java/tests/support/Support_SetTest.java
@@ -17,8 +17,11 @@
package tests.support;
+import dalvik.annotation.TestTargetClass;
+
import java.util.Set;
+@TestTargetClass(Set.class)
public class Support_SetTest extends junit.framework.TestCase {
Set<Integer> set; // must contain only the Integers 0 to 99
diff --git a/support/src/test/java/tests/support/Support_UnmodifiableCollectionTest.java b/support/src/test/java/tests/support/Support_UnmodifiableCollectionTest.java
index 96619bd..0100c01 100644
--- a/support/src/test/java/tests/support/Support_UnmodifiableCollectionTest.java
+++ b/support/src/test/java/tests/support/Support_UnmodifiableCollectionTest.java
@@ -17,6 +17,8 @@
package tests.support;
+import dalvik.annotation.TestTargetClass;
+
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
@@ -24,6 +26,7 @@ import java.util.SortedSet;
import java.util.TreeSet;
import junit.framework.TestCase;
+@TestTargetClass(Collection.class)
public class Support_UnmodifiableCollectionTest extends TestCase {
Collection<Integer> col;
diff --git a/support/src/test/java/tests/support/Support_UnmodifiableMapTest.java b/support/src/test/java/tests/support/Support_UnmodifiableMapTest.java
index 9648074..6405701 100644
--- a/support/src/test/java/tests/support/Support_UnmodifiableMapTest.java
+++ b/support/src/test/java/tests/support/Support_UnmodifiableMapTest.java
@@ -17,12 +17,15 @@
package tests.support;
+import dalvik.annotation.TestTargetClass;
+
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import junit.framework.TestCase;
+@TestTargetClass(Map.class)
public class Support_UnmodifiableMapTest extends TestCase {
Map<String, Integer> map;