summaryrefslogtreecommitdiffstats
path: root/support
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-02-10 15:43:57 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-02-10 15:43:57 -0800
commitb7926325a1c1a370c84c81db80372f59af240a53 (patch)
treeb1d0214be443ea674d0ded8c502a8e074e50bdd2 /support
parent687f18b91f4a0a728a027579110953ee729adcb8 (diff)
downloadlibcore-b7926325a1c1a370c84c81db80372f59af240a53.zip
libcore-b7926325a1c1a370c84c81db80372f59af240a53.tar.gz
libcore-b7926325a1c1a370c84c81db80372f59af240a53.tar.bz2
auto import from //branches/cupcake/...@130745
Diffstat (limited to 'support')
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MySignature1.java7
-rw-r--r--support/src/test/java/targets/KeyAgreement.java36
-rw-r--r--support/src/test/java/targets/Mac.java56
-rw-r--r--support/src/test/java/targets/SecretKeyFactory.java46
-rw-r--r--support/src/test/java/tests/resources/Package/hyts_all_attributes_dex.jarbin0 -> 701 bytes
-rw-r--r--support/src/test/java/tests/resources/Package/hyts_c_dex.jarbin0 -> 704 bytes
-rw-r--r--support/src/test/java/tests/resources/Package/hyts_no_attributes_dex.jarbin0 -> 663 bytes
-rw-r--r--support/src/test/java/tests/resources/Package/hyts_no_entry_dex.jarbin0 -> 654 bytes
-rw-r--r--support/src/test/java/tests/resources/Package/hyts_package_dex.jarbin0 -> 1564 bytes
-rw-r--r--support/src/test/java/tests/resources/Package/hyts_pq_dex.jarbin0 -> 710 bytes
-rw-r--r--support/src/test/java/tests/resources/Package/hyts_some_attributes_dex.jarbin0 -> 692 bytes
-rw-r--r--support/src/test/java/tests/resources/cts_dalvikExecTest.jarbin0 -> 1698 bytes
-rw-r--r--support/src/test/java/tests/resources/cts_dalvikExecTest_classes.dexbin0 -> 2108 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_signed_inc.jarbin0 -> 2392 bytes
-rw-r--r--support/src/test/java/tests/support/Support_Exec.java33
-rw-r--r--support/src/test/java/tests/support/resource/Support_Resources.java53
16 files changed, 219 insertions, 12 deletions
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MySignature1.java b/support/src/test/java/org/apache/harmony/security/tests/support/MySignature1.java
index 48c3d31..2703b0f 100644
--- a/support/src/test/java/org/apache/harmony/security/tests/support/MySignature1.java
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MySignature1.java
@@ -79,6 +79,13 @@ public class MySignature1 extends Signature {
protected void engineUpdate(byte[] b, int off, int len)
throws SignatureException {
+ if (b == null) throw new NullPointerException();
+ if (off < 0 || off > b.length || off > len) {
+ throw new IllegalArgumentException("incorrect parameter off");
+ }
+ if (len < 0 || len > b.length) {
+ throw new IllegalArgumentException("incorrect parameter len");
+ }
runEngineUpdate2 = true;
}
diff --git a/support/src/test/java/targets/KeyAgreement.java b/support/src/test/java/targets/KeyAgreement.java
new file mode 100644
index 0000000..48bd7d9
--- /dev/null
+++ b/support/src/test/java/targets/KeyAgreement.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 targets;
+
+import dalvik.annotation.VirtualTestTarget;
+
+/**
+ * @hide
+ */
+public interface KeyAgreement {
+ /**
+ * @hide
+ */
+ abstract class Internal {
+ protected Internal() {
+ }
+ }
+
+ @VirtualTestTarget
+ static abstract class DH extends Internal {
+ protected abstract void method();
+ }
+}
diff --git a/support/src/test/java/targets/Mac.java b/support/src/test/java/targets/Mac.java
new file mode 100644
index 0000000..d1ec21a
--- /dev/null
+++ b/support/src/test/java/targets/Mac.java
@@ -0,0 +1,56 @@
+/*
+ * 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 targets;
+
+import dalvik.annotation.VirtualTestTarget;
+
+/**
+ * @hide
+ */
+public interface Mac {
+ /**
+ * @hide
+ */
+ abstract class Internal {
+ protected Internal() {
+ }
+ }
+
+ @VirtualTestTarget
+ static abstract class HMACMD5 extends Internal {
+ protected abstract void method();
+ }
+
+ @VirtualTestTarget
+ static abstract class HMACSHA1 extends Internal {
+ protected abstract void method();
+ }
+
+ @VirtualTestTarget
+ static abstract class HMACSHA256 extends Internal {
+ protected abstract void method();
+ }
+
+ @VirtualTestTarget
+ static abstract class HMACSHA384 extends Internal {
+ protected abstract void method();
+ }
+
+ @VirtualTestTarget
+ static abstract class HMACSHA512 extends Internal {
+ protected abstract void method();
+ }
+}
diff --git a/support/src/test/java/targets/SecretKeyFactory.java b/support/src/test/java/targets/SecretKeyFactory.java
new file mode 100644
index 0000000..133b3e3
--- /dev/null
+++ b/support/src/test/java/targets/SecretKeyFactory.java
@@ -0,0 +1,46 @@
+/*
+ * 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 targets;
+
+import dalvik.annotation.VirtualTestTarget;
+
+/**
+ * @hide
+ */
+public interface SecretKeyFactory {
+ /**
+ * @hide
+ */
+ abstract class Internal {
+ protected Internal() {
+ }
+ }
+
+ @VirtualTestTarget
+ static abstract class DES extends Internal {
+ protected abstract void method();
+ }
+
+ @VirtualTestTarget
+ static abstract class DESede extends Internal {
+ protected abstract void method();
+ }
+
+ @VirtualTestTarget
+ static abstract class PBEWITHMD5ANDDES extends Internal {
+ protected abstract void method();
+ }
+}
diff --git a/support/src/test/java/tests/resources/Package/hyts_all_attributes_dex.jar b/support/src/test/java/tests/resources/Package/hyts_all_attributes_dex.jar
new file mode 100644
index 0000000..b9da43f
--- /dev/null
+++ b/support/src/test/java/tests/resources/Package/hyts_all_attributes_dex.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Package/hyts_c_dex.jar b/support/src/test/java/tests/resources/Package/hyts_c_dex.jar
new file mode 100644
index 0000000..cc2ba1b
--- /dev/null
+++ b/support/src/test/java/tests/resources/Package/hyts_c_dex.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Package/hyts_no_attributes_dex.jar b/support/src/test/java/tests/resources/Package/hyts_no_attributes_dex.jar
new file mode 100644
index 0000000..b3c61ef
--- /dev/null
+++ b/support/src/test/java/tests/resources/Package/hyts_no_attributes_dex.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Package/hyts_no_entry_dex.jar b/support/src/test/java/tests/resources/Package/hyts_no_entry_dex.jar
new file mode 100644
index 0000000..76777f6
--- /dev/null
+++ b/support/src/test/java/tests/resources/Package/hyts_no_entry_dex.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Package/hyts_package_dex.jar b/support/src/test/java/tests/resources/Package/hyts_package_dex.jar
new file mode 100644
index 0000000..837ad0d
--- /dev/null
+++ b/support/src/test/java/tests/resources/Package/hyts_package_dex.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Package/hyts_pq_dex.jar b/support/src/test/java/tests/resources/Package/hyts_pq_dex.jar
new file mode 100644
index 0000000..cc45dc9
--- /dev/null
+++ b/support/src/test/java/tests/resources/Package/hyts_pq_dex.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Package/hyts_some_attributes_dex.jar b/support/src/test/java/tests/resources/Package/hyts_some_attributes_dex.jar
new file mode 100644
index 0000000..46ab8b9
--- /dev/null
+++ b/support/src/test/java/tests/resources/Package/hyts_some_attributes_dex.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/cts_dalvikExecTest.jar b/support/src/test/java/tests/resources/cts_dalvikExecTest.jar
new file mode 100644
index 0000000..b6af791
--- /dev/null
+++ b/support/src/test/java/tests/resources/cts_dalvikExecTest.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/cts_dalvikExecTest_classes.dex b/support/src/test/java/tests/resources/cts_dalvikExecTest_classes.dex
new file mode 100644
index 0000000..415c50a
--- /dev/null
+++ b/support/src/test/java/tests/resources/cts_dalvikExecTest_classes.dex
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_signed_inc.jar b/support/src/test/java/tests/resources/hyts_signed_inc.jar
new file mode 100644
index 0000000..d75ce08
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_signed_inc.jar
Binary files differ
diff --git a/support/src/test/java/tests/support/Support_Exec.java b/support/src/test/java/tests/support/Support_Exec.java
index cec7934..eb55d67 100644
--- a/support/src/test/java/tests/support/Support_Exec.java
+++ b/support/src/test/java/tests/support/Support_Exec.java
@@ -29,6 +29,12 @@ import junit.framework.TestCase;
public class Support_Exec extends TestCase {
+ static final boolean againstDalvik;
+ static {
+ String platform = System.getProperty("java.vendor");
+ againstDalvik = (platform.contains("Android"));
+ }
+
/**
* This function returns the output of the process as a string
*/
@@ -51,7 +57,7 @@ public class Support_Exec extends TestCase {
return getProcessOutput(arr, displayOutput);
}
- private static String getProcessOutput(Object[] arr, boolean displayOutput)
+ public static String getProcessOutput(Object[] arr, boolean displayOutput)
throws IOException, InterruptedException {
Process proc = (Process) arr[0];
StringBuilder output = new StringBuilder();
@@ -109,7 +115,11 @@ public class Support_Exec extends TestCase {
executable += File.separator;
}
executable += "bin" + File.separator;
- execArgs.add(executable + "dalvikvm");
+ if (againstDalvik) {
+ execArgs.add(executable + "dalvikvm");
+ } else {
+ execArgs.add(executable + "java");
+ }
// add classpath string
if (classpath != null) {
@@ -156,9 +166,24 @@ public class Support_Exec extends TestCase {
}
// execute java process
- final Process proc = Runtime.getRuntime().exec(
- execArgs.toArray(new String[execArgs.size()]), envp);
+ return execAndDigestOutput(execArgs.toArray(new String[execArgs.size()]), envp);
+ }
+
+ //
+ // mc: This looks like functionaly worth publicity:
+ //
+ public static Object[] execAndDigestOutput (String[] cmdLine, String[] envp)
+ throws IOException, InterruptedException {
+
+// System.out.println("Commandline BEGIN");
+// for (int i = 0; i < cmdLine.length; i++) {
+// System.out.println(cmdLine[i]);
+// }
+// System.out.println("END");
+
+ final Process proc = Runtime.getRuntime().exec(cmdLine, envp);
final StringBuilder errBuf = new StringBuilder();
+
Thread errThread = new Thread(new Runnable() {
public void run() {
synchronized (errBuf) {
diff --git a/support/src/test/java/tests/support/resource/Support_Resources.java b/support/src/test/java/tests/support/resource/Support_Resources.java
index b1e63f6..f15f618 100644
--- a/support/src/test/java/tests/support/resource/Support_Resources.java
+++ b/support/src/test/java/tests/support/resource/Support_Resources.java
@@ -17,17 +17,18 @@
package tests.support.resource;
+import tests.support.Support_Configuration;
+
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
-import tests.support.Support_Configuration;
-
public class Support_Resources {
public static final String RESOURCE_PACKAGE = "/tests/resources/";
@@ -78,7 +79,7 @@ public class Support_Resources {
return folder;
}
- public static void copyFile(File root, String folder, String file) {
+ public static File copyFile(File root, String folder, String file) {
File f;
if (folder != null) {
f = new File(root.toString() + "/" + folder);
@@ -103,6 +104,8 @@ public class Support_Resources {
// TODO Auto-generated catch block
e.printStackTrace();
}
+
+ return dest;
}
public static File createTempFile(String suffix) throws IOException {
@@ -144,17 +147,51 @@ public class Support_Resources {
* @return - resource input stream
*/
public static InputStream getResourceStream(String name) {
-
- InputStream is = ClassLoader.getSystemClassLoader()
- .getResourceAsStream(name);
+//ATTENTION:
+// Against class.getResourceStream(name) the name can start with a "/".
+// Against classLoader.getResourceStream NOT!
+
+ InputStream is;
+// is = Support_Resources.class.getClassLoader().getResourceAsStream(name); This would work without leading "/"
+ is = Support_Resources.class.getResourceAsStream(name);
+// is = ClassLoader.getSystemClassLoader().getResourceAsStream(name); This would work without leading "/"
if (is == null) {
- throw new RuntimeException("Failed to load resource: " + name);
+ name = "/tests/resources/" + name;
+ is = Support_Resources.class.getResourceAsStream(name);
+ if (is == null) {
+ throw new RuntimeException("Failed to load resource: " + name);
+ }
}
return is;
}
-
+
+ /**
+ * Util method to write resource files directly to an OutputStream.
+ *
+ * @param name - name of resource file.
+ * @param out - OutputStream to write to.
+ * @return - number of bytes written to out.
+ */
+ public static int writeResourceToStream(String name, OutputStream out) {
+ InputStream input = getResourceStream(name);
+ byte[] buffer = new byte[512];
+ int total = 0;
+ int count;
+ try {
+ count = input.read(buffer);
+ while (count != -1) {
+ out.write(buffer, 0, count);
+ total = total + count;
+ count = input.read(buffer);
+ }
+ return total;
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to write to passed stream.", e);
+ }
+ }
+
/**
* Util method to get absolute path to resource file
*