summaryrefslogtreecommitdiffstats
path: root/tests/CoreTests/android/core
diff options
context:
space:
mode:
authorBrett Chabot <brettchabot@android.com>2010-04-01 21:45:41 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-04-01 21:45:41 -0700
commitc162668e870cda9d336741f24c177cd925fef8e0 (patch)
tree479d06830326708e659887c6291254e53f4a1a76 /tests/CoreTests/android/core
parent87e72cd3b327fefc39030a628e9e9b7141791d39 (diff)
parent0dc59e78e18493aecd37427531d093e800846c3e (diff)
downloadframeworks_base-c162668e870cda9d336741f24c177cd925fef8e0.zip
frameworks_base-c162668e870cda9d336741f24c177cd925fef8e0.tar.gz
frameworks_base-c162668e870cda9d336741f24c177cd925fef8e0.tar.bz2
Merge "More framework tests cleanup." into froyo
Diffstat (limited to 'tests/CoreTests/android/core')
-rw-r--r--tests/CoreTests/android/core/AndroidPerformanceTests.java35
-rw-r--r--tests/CoreTests/android/core/ArrayListPerformanceTest.java327
-rw-r--r--tests/CoreTests/android/core/HashMapPerformanceTest.java185
-rw-r--r--tests/CoreTests/android/core/HashSetTest.java207
-rw-r--r--tests/CoreTests/android/core/HashtableTest.java357
-rw-r--r--tests/CoreTests/android/core/HeapTest.java633
-rw-r--r--tests/CoreTests/android/core/InstanceofTest.java141
-rw-r--r--tests/CoreTests/android/core/JavaPerformanceTests.java38
-rw-r--r--tests/CoreTests/android/core/JniLibTest.java59
-rw-r--r--tests/CoreTests/android/core/LinkedListTest.java529
-rw-r--r--tests/CoreTests/android/core/MathPerformanceTest.java380
-rw-r--r--tests/CoreTests/android/core/MonitorTest.java469
-rw-r--r--tests/CoreTests/android/core/PerformanceTests.java1224
-rw-r--r--tests/CoreTests/android/core/SerializationTest.java47
-rw-r--r--tests/CoreTests/android/core/StringTest.java951
-rw-r--r--tests/CoreTests/android/core/TestHttpClient.java116
-rw-r--r--tests/CoreTests/android/core/TreeMapPerformanceTest.java281
-rw-r--r--tests/CoreTests/android/core/TreeSetTest.java349
-rw-r--r--tests/CoreTests/android/core/VectorTest.java555
19 files changed, 6883 insertions, 0 deletions
diff --git a/tests/CoreTests/android/core/AndroidPerformanceTests.java b/tests/CoreTests/android/core/AndroidPerformanceTests.java
new file mode 100644
index 0000000..e604d59
--- /dev/null
+++ b/tests/CoreTests/android/core/AndroidPerformanceTests.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+import android.test.TestListActivity;
+
+public class AndroidPerformanceTests extends TestListActivity {
+ @Override
+ public String getTestSuite() {
+ return "com.android.unit_tests.AndroidPerformanceTests$Suite";
+ }
+
+ public static class Suite {
+ public static String[] children() {
+ return new String[] {
+ JavaPerformanceTests.class.getName(),
+ PerformanceTests.class.getName(),
+ };
+ }
+ }
+}
diff --git a/tests/CoreTests/android/core/ArrayListPerformanceTest.java b/tests/CoreTests/android/core/ArrayListPerformanceTest.java
new file mode 100644
index 0000000..6130e83
--- /dev/null
+++ b/tests/CoreTests/android/core/ArrayListPerformanceTest.java
@@ -0,0 +1,327 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+import java.util.ArrayList;
+import android.test.PerformanceTestBase;
+
+public class ArrayListPerformanceTest extends PerformanceTestBase {
+
+ private ArrayList<Integer> mList;
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ mList = new ArrayList();
+ mList.add(0);
+ mList.add(1);
+ mList.add(2);
+ mList.add(3);
+ mList.add(4);
+ mList.add(5);
+ mList.add(6);
+ mList.add(7);
+ mList.add(8);
+ mList.add(9);
+ }
+
+ public void testArrayListAdd() {
+ int i = 0;
+ for (; i < 10; i++) {
+ mList.add(i);
+ mList.add(i);
+ mList.add(i);
+ mList.add(i);
+ mList.add(i);
+ mList.add(i);
+ mList.add(i);
+ mList.add(i);
+ mList.add(i);
+ mList.add(i);
+ }
+ }
+
+ public void testArrayListAdd1() {
+ int i = 0;
+ for (; i < 10; i++) {
+ mList.add(7, i);
+ mList.add(7, i);
+ mList.add(7, i);
+ mList.add(7, i);
+ mList.add(7, i);
+ mList.add(7, i);
+ mList.add(7, i);
+ mList.add(7, i);
+ mList.add(7, i);
+ mList.add(7, i);
+ }
+ }
+
+ public void testArrayListToArray() {
+ Object rArray;
+ int i = 0;
+ for (; i < 100; i++) {
+ rArray = mList.toArray();
+ rArray = mList.toArray();
+ rArray = mList.toArray();
+ rArray = mList.toArray();
+ rArray = mList.toArray();
+ rArray = mList.toArray();
+ rArray = mList.toArray();
+ rArray = mList.toArray();
+ rArray = mList.toArray();
+ rArray = mList.toArray();
+ }
+ }
+
+ public void testArrayListSize() {
+ int i = 0, len;
+ for (; i < 100; i++) {
+ len = mList.size();
+ len = mList.size();
+ len = mList.size();
+ len = mList.size();
+ len = mList.size();
+ len = mList.size();
+ len = mList.size();
+ len = mList.size();
+ len = mList.size();
+ len = mList.size();
+ }
+ }
+
+ public void testArrayListGet() {
+ int i = 0, value;
+ int len = mList.size();
+ for (; i < len; i++) {
+ value = mList.get(i);
+ value = mList.get(i);
+ value = mList.get(i);
+ value = mList.get(i);
+ value = mList.get(i);
+ value = mList.get(i);
+ value = mList.get(i);
+ value = mList.get(i);
+ value = mList.get(i);
+ value = mList.get(i);
+ }
+ }
+
+ public void testArrayListContains() {
+ boolean flag;
+ int i = 0;
+
+ for (; i < 100; i++) {
+ flag = mList.contains(i);
+ flag = mList.contains(i);
+ flag = mList.contains(i);
+ flag = mList.contains(i);
+ flag = mList.contains(i);
+ flag = mList.contains(i);
+ flag = mList.contains(i);
+ flag = mList.contains(i);
+ flag = mList.contains(i);
+ flag = mList.contains(i);
+
+ }
+ }
+
+ public void testArrayListToArray1() {
+ Integer[] rArray = new Integer[10];
+
+ Integer[] mArray;
+ int i = 0;
+ for (; i < 100; i++) {
+ mArray = mList.toArray(rArray);
+ mArray = mList.toArray(rArray);
+ mArray = mList.toArray(rArray);
+ mArray = mList.toArray(rArray);
+ mArray = mList.toArray(rArray);
+ mArray = mList.toArray(rArray);
+ mArray = mList.toArray(rArray);
+ mArray = mList.toArray(rArray);
+ mArray = mList.toArray(rArray);
+ mArray = mList.toArray(rArray);
+ }
+ }
+
+ public void testArrayListSet() {
+ int i = 0;
+ for (; i < 10; i++) {
+ mList.set(5, 0);
+ mList.set(5, 0);
+ mList.set(5, 0);
+ mList.set(5, 0);
+ mList.set(5, 0);
+ mList.set(5, 0);
+ mList.set(5, 0);
+ mList.set(5, 0);
+ mList.set(5, 0);
+ mList.set(5, 0);
+ }
+ }
+
+ public void testArrayListIndexOf() {
+ int i = 0, index;
+
+ for (; i < 100; i++) {
+ index = mList.indexOf(0);
+ index = mList.indexOf(0);
+ index = mList.indexOf(0);
+ index = mList.indexOf(0);
+ index = mList.indexOf(0);
+ index = mList.indexOf(0);
+ index = mList.indexOf(0);
+ index = mList.indexOf(0);
+ index = mList.indexOf(0);
+ index = mList.indexOf(0);
+ }
+ }
+
+ public void testArrayListLastIndexOf() {
+ int i = 0, index;
+
+ for (; i < 100; i++) {
+ index = mList.lastIndexOf(0);
+ index = mList.lastIndexOf(0);
+ index = mList.lastIndexOf(0);
+ index = mList.lastIndexOf(0);
+ index = mList.lastIndexOf(0);
+ index = mList.lastIndexOf(0);
+ index = mList.lastIndexOf(0);
+ index = mList.lastIndexOf(0);
+ index = mList.lastIndexOf(0);
+ index = mList.lastIndexOf(0);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testArrayListRemove() {
+ ArrayList<Integer> aList;
+ aList = new ArrayList();
+ for (int j = 0; j < 10000; j++) {
+ aList.add(0);
+ }
+
+ int i = 0, index;
+
+ for (; i < 10; i++) {
+ index = aList.remove(0);
+ index = aList.remove(0);
+ index = aList.remove(0);
+ index = aList.remove(0);
+ index = aList.remove(0);
+ index = aList.remove(0);
+ index = aList.remove(0);
+ index = aList.remove(0);
+ index = aList.remove(0);
+ index = aList.remove(0);
+
+
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testArrayListAddAll() {
+ ArrayList<Integer> aList = new ArrayList();
+
+ int i = 0;
+ boolean b;
+ for (; i < 10; i++) {
+ b = aList.addAll(mList);
+ b = aList.addAll(mList);
+ b = aList.addAll(mList);
+ b = aList.addAll(mList);
+ b = aList.addAll(mList);
+ b = aList.addAll(mList);
+ b = aList.addAll(mList);
+ b = aList.addAll(mList);
+ b = aList.addAll(mList);
+ b = aList.addAll(mList);
+
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testArrayListRemove1() {
+ ArrayList<String> aList;
+ String s;
+
+ aList = new ArrayList();
+ for (int j = 0; j < 100; j++) {
+ aList.add("a");
+ aList.add("b");
+ }
+ s = new String("a");
+
+ int i = 0;
+ boolean b;
+ for (; i < 10; i++) {
+ b = aList.remove(s);
+ b = aList.remove(s);
+ b = aList.remove(s);
+ b = aList.remove(s);
+ b = aList.remove(s);
+ b = aList.remove(s);
+ b = aList.remove(s);
+ b = aList.remove(s);
+ b = aList.remove(s);
+ b = aList.remove(s);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testArrayListAddAll1() {
+ ArrayList<Integer> aList = new ArrayList();
+
+ int i = 0;
+ boolean b;
+
+ for (; i < 10; i++) {
+ b = aList.addAll(0, mList);
+ b = aList.addAll(0, mList);
+ b = aList.addAll(0, mList);
+ b = aList.addAll(0, mList);
+ b = aList.addAll(0, mList);
+ b = aList.addAll(0, mList);
+ b = aList.addAll(0, mList);
+ b = aList.addAll(0, mList);
+ b = aList.addAll(0, mList);
+ b = aList.addAll(0, mList);
+ }
+ }
+
+ public void testArrayListClone() {
+ Object rObj;
+ int i = 0;
+
+ for (; i < 100; i++) {
+ rObj = mList.clone();
+ rObj = mList.clone();
+ rObj = mList.clone();
+ rObj = mList.clone();
+ rObj = mList.clone();
+ rObj = mList.clone();
+ rObj = mList.clone();
+ rObj = mList.clone();
+ rObj = mList.clone();
+ rObj = mList.clone();
+ }
+ }
+}
diff --git a/tests/CoreTests/android/core/HashMapPerformanceTest.java b/tests/CoreTests/android/core/HashMapPerformanceTest.java
new file mode 100644
index 0000000..82727bb
--- /dev/null
+++ b/tests/CoreTests/android/core/HashMapPerformanceTest.java
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Set;
+
+import android.test.PerformanceTestBase;
+import android.test.PerformanceTestCase;
+
+public class HashMapPerformanceTest extends PerformanceTestBase {
+ public static final int ITERATIONS = 1000;
+ public HashMap mMap;
+ public String[] mKeys;
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ mMap = new HashMap();
+ mKeys = new String[ITERATIONS];
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ mKeys[i] = Integer.toString(i, 16);
+ mMap.put(mKeys[i], i);
+ }
+ }
+
+ @Override
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ public void testHashMapGet() {
+ int num;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ num = (Integer) mMap.get(mKeys[i]);
+ num = (Integer) mMap.get(mKeys[i]);
+ num = (Integer) mMap.get(mKeys[i]);
+ num = (Integer) mMap.get(mKeys[i]);
+ num = (Integer) mMap.get(mKeys[i]);
+ num = (Integer) mMap.get(mKeys[i]);
+ num = (Integer) mMap.get(mKeys[i]);
+ num = (Integer) mMap.get(mKeys[i]);
+ num = (Integer) mMap.get(mKeys[i]);
+ num = (Integer) mMap.get(mKeys[i]);
+ }
+ }
+
+ public void testHashMapKeySet() {
+ Set keyset;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ keyset = mMap.keySet();
+ keyset = mMap.keySet();
+ keyset = mMap.keySet();
+ keyset = mMap.keySet();
+ keyset = mMap.keySet();
+ keyset = mMap.keySet();
+ keyset = mMap.keySet();
+ keyset = mMap.keySet();
+ keyset = mMap.keySet();
+ keyset = mMap.keySet();
+ }
+ }
+
+ public void testHashMapEntrySet() {
+ Set keyset;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ keyset = mMap.entrySet();
+ keyset = mMap.entrySet();
+ keyset = mMap.entrySet();
+ keyset = mMap.entrySet();
+ keyset = mMap.entrySet();
+ keyset = mMap.entrySet();
+ keyset = mMap.entrySet();
+ keyset = mMap.entrySet();
+ keyset = mMap.entrySet();
+ keyset = mMap.entrySet();
+
+
+ }
+ }
+
+ public void testHashMapValues() {
+ Collection c;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ c = mMap.values();
+ c = mMap.values();
+ c = mMap.values();
+ c = mMap.values();
+ c = mMap.values();
+ c = mMap.values();
+ c = mMap.values();
+ c = mMap.values();
+ c = mMap.values();
+ c = mMap.values();
+
+
+ }
+ }
+
+ public void testHashMapSize() {
+ int len;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ len = mMap.size();
+ len = mMap.size();
+ len = mMap.size();
+ len = mMap.size();
+ len = mMap.size();
+ len = mMap.size();
+ len = mMap.size();
+ len = mMap.size();
+ len = mMap.size();
+ len = mMap.size();
+
+
+ }
+ }
+
+ public void testHashMapContainsValue() {
+ boolean flag;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = mMap.containsValue(i);
+ flag = mMap.containsValue(i);
+ flag = mMap.containsValue(i);
+ flag = mMap.containsValue(i);
+ flag = mMap.containsValue(i);
+ flag = mMap.containsValue(i);
+ flag = mMap.containsValue(i);
+ flag = mMap.containsValue(i);
+ flag = mMap.containsValue(i);
+ flag = mMap.containsValue(i);
+
+
+ }
+ }
+
+ public void testHashMapRemove() {
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ mMap.remove(mKeys[i]);
+ mMap.remove(mKeys[i]);
+ mMap.remove(mKeys[i]);
+ mMap.remove(mKeys[i]);
+ mMap.remove(mKeys[i]);
+ mMap.remove(mKeys[i]);
+ mMap.remove(mKeys[i]);
+ mMap.remove(mKeys[i]);
+ mMap.remove(mKeys[i]);
+ mMap.remove(mKeys[i]);
+ }
+ }
+
+
+ public void testHashMapClone() {
+ HashMap cMap;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ cMap = (HashMap) mMap.clone();
+ cMap = (HashMap) mMap.clone();
+ cMap = (HashMap) mMap.clone();
+ cMap = (HashMap) mMap.clone();
+ cMap = (HashMap) mMap.clone();
+ cMap = (HashMap) mMap.clone();
+ cMap = (HashMap) mMap.clone();
+ cMap = (HashMap) mMap.clone();
+ cMap = (HashMap) mMap.clone();
+ cMap = (HashMap) mMap.clone();
+ }
+ }
+}
diff --git a/tests/CoreTests/android/core/HashSetTest.java b/tests/CoreTests/android/core/HashSetTest.java
new file mode 100644
index 0000000..09a711f
--- /dev/null
+++ b/tests/CoreTests/android/core/HashSetTest.java
@@ -0,0 +1,207 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+import android.test.PerformanceTestBase;
+import android.test.PerformanceTestCase;
+
+import java.util.HashSet;
+import java.util.Iterator;
+
+/**
+ * Implements basic performance test functionality for HashSets
+ */
+
+public class HashSetTest extends PerformanceTestBase {
+ public static final int ITERATIONS = 1000;
+ public static HashSet<Integer> sSet;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ sSet = new HashSet<Integer>();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ sSet.add(i);
+ }
+ }
+
+ @Override
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ /**
+ *
+ * Tests performance for the HashSet method Add(Object arg 0)
+ *
+ */
+
+ @SuppressWarnings("unchecked")
+ public void testHashSetAdd() {
+ HashSet set = new HashSet();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ }
+
+ }
+
+ /**
+ *
+ * Tests performance of HashSet method contains(Object arg 0)
+ *
+ */
+
+ public void testHashSetContains() {
+ Integer index = new Integer(500);
+ boolean flag;
+ HashSet set = sSet;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = set.contains(index);
+ flag = set.contains(index);
+ flag = set.contains(index);
+ flag = set.contains(index);
+ flag = set.contains(index);
+ flag = set.contains(index);
+ flag = set.contains(index);
+ flag = set.contains(index);
+ flag = set.contains(index);
+ }
+ }
+
+ /**
+ *
+ * Tests performance of HashSet method size()
+ *
+ */
+
+ public void testHashSetSize() {
+ int num;
+ HashSet set = sSet;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ num = set.size();
+ num = set.size();
+ num = set.size();
+ num = set.size();
+ num = set.size();
+ num = set.size();
+ num = set.size();
+ num = set.size();
+ num = set.size();
+ }
+ }
+
+ /**
+ *
+ * Tests performance of the HashSet method -iterator()
+ *
+ */
+
+ public void testHashSetIterator() {
+ Iterator iterator;
+ HashSet set = sSet;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ iterator = set.iterator();
+ iterator = set.iterator();
+ iterator = set.iterator();
+ iterator = set.iterator();
+ iterator = set.iterator();
+ iterator = set.iterator();
+ iterator = set.iterator();
+ iterator = set.iterator();
+ iterator = set.iterator();
+ }
+ }
+
+ /**
+ *
+ * Tests performance for the HashSet method Remove(Object arg 0)
+ *
+ */
+
+ @SuppressWarnings("unchecked")
+ public void testHashSetRemove() {
+ HashSet set = new HashSet(sSet);
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ }
+ }
+
+ /**
+ *
+ * Tests performance for the HashSet method isEmpty(Object arg 0)
+ *
+ */
+
+ public void testHashSetIsEmpty() {
+ HashSet set = sSet;
+ boolean flag;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = set.isEmpty();
+ flag = set.isEmpty();
+ flag = set.isEmpty();
+ flag = set.isEmpty();
+ flag = set.isEmpty();
+ flag = set.isEmpty();
+ flag = set.isEmpty();
+ flag = set.isEmpty();
+ flag = set.isEmpty();
+ flag = set.isEmpty();
+ }
+ }
+
+ /**
+ *
+ * Tests performance for the HashSet method clone()
+ *
+ */
+
+ public void testHashSetClone() {
+ HashSet hSet = sSet;
+ Object set;
+ for (int i = ITERATIONS - 1; i > 0; i--) {
+ set = hSet.clone();
+ set = hSet.clone();
+ set = hSet.clone();
+ set = hSet.clone();
+ set = hSet.clone();
+ set = hSet.clone();
+ set = hSet.clone();
+ set = hSet.clone();
+ set = hSet.clone();
+ set = hSet.clone();
+ }
+ }
+}
diff --git a/tests/CoreTests/android/core/HashtableTest.java b/tests/CoreTests/android/core/HashtableTest.java
new file mode 100644
index 0000000..6160f57
--- /dev/null
+++ b/tests/CoreTests/android/core/HashtableTest.java
@@ -0,0 +1,357 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+import android.test.PerformanceTestBase;
+import android.test.PerformanceTestCase;
+
+import java.util.Hashtable;
+import java.util.Set;
+import java.util.Enumeration;
+
+/**
+ * Implements basic performance test functionality for java.util.Hashtable
+ */
+
+public class HashtableTest extends PerformanceTestBase {
+ public static final int ITERATIONS = 1000;
+ public Hashtable<String, Integer> sTable;
+ public String[] sKeys;
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ sTable = new Hashtable();
+ sKeys = new String[ITERATIONS];
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ sKeys[i] = Integer.toString(i, 16);
+ sTable.put(sKeys[i], i);
+ }
+ }
+
+ @Override
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testHashtablePut() {
+ Hashtable hTable = new Hashtable();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ hTable.put(i, i);
+ hTable.put(i, i);
+ hTable.put(i, i);
+ hTable.put(i, i);
+ hTable.put(i, i);
+ hTable.put(i, i);
+ hTable.put(i, i);
+ hTable.put(i, i);
+ hTable.put(i, i);
+ hTable.put(i, i);
+ }
+ }
+
+ public void testHashtableGet() {
+ int value;
+ String[] keys = sKeys;
+ Hashtable<String, Integer> hTable = sTable;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ value = hTable.get(keys[i]);
+ value = hTable.get(keys[i]);
+ value = hTable.get(keys[i]);
+ value = hTable.get(keys[i]);
+ value = hTable.get(keys[i]);
+ value = hTable.get(keys[i]);
+ value = hTable.get(keys[i]);
+ value = hTable.get(keys[i]);
+ value = hTable.get(keys[i]);
+ value = hTable.get(keys[i]);
+ }
+ }
+
+ public void testHashtablekeyset() {
+ Set keyset;
+ Hashtable<String, Integer> hTable = sTable;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ keyset = hTable.keySet();
+ keyset = hTable.keySet();
+ keyset = hTable.keySet();
+ keyset = hTable.keySet();
+ keyset = hTable.keySet();
+ keyset = hTable.keySet();
+ keyset = hTable.keySet();
+ keyset = hTable.keySet();
+ keyset = hTable.keySet();
+ keyset = hTable.keySet();
+ }
+ }
+
+ /**
+ *
+ */
+
+ public void testHashtableEntrySet() {
+ Set keyset;
+ Hashtable<String, Integer> hTable = sTable;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ keyset = hTable.entrySet();
+ keyset = hTable.entrySet();
+ keyset = hTable.entrySet();
+ keyset = hTable.entrySet();
+ keyset = hTable.entrySet();
+ keyset = hTable.entrySet();
+ keyset = hTable.entrySet();
+ keyset = hTable.entrySet();
+ keyset = hTable.entrySet();
+ keyset = hTable.entrySet();
+ }
+ }
+
+ public void testHashtableSize() {
+ int len;
+ Hashtable<String, Integer> hTable = sTable;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ len = hTable.size();
+ len = hTable.size();
+ len = hTable.size();
+ len = hTable.size();
+ len = hTable.size();
+ len = hTable.size();
+ len = hTable.size();
+ len = hTable.size();
+ len = hTable.size();
+ len = hTable.size();
+ }
+ }
+
+ public void testHashtableContainsValue() {
+ boolean flag;
+ Hashtable<String, Integer> hTable = sTable;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = hTable.containsValue(i);
+ flag = hTable.containsValue(i);
+ flag = hTable.containsValue(i);
+ flag = hTable.containsValue(i);
+ flag = hTable.containsValue(i);
+ flag = hTable.containsValue(i);
+ flag = hTable.containsValue(i);
+ flag = hTable.containsValue(i);
+ flag = hTable.containsValue(i);
+ flag = hTable.containsValue(i);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testHashtableRemove() {
+ Hashtable<String, Integer> hTable = new Hashtable(sTable);
+ String[] keys = sKeys;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ hTable.remove(keys[i]);
+ hTable.remove(keys[i]);
+ hTable.remove(keys[i]);
+ hTable.remove(keys[i]);
+ hTable.remove(keys[i]);
+ hTable.remove(keys[i]);
+ hTable.remove(keys[i]);
+ hTable.remove(keys[i]);
+ hTable.remove(keys[i]);
+ hTable.remove(keys[i]);
+ }
+ }
+
+ public void testHashtableContains() {
+ Hashtable<String, Integer> hTable = sTable;
+ boolean flag;
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = hTable.contains(i);
+ flag = hTable.contains(i);
+ flag = hTable.contains(i);
+ flag = hTable.contains(i);
+ flag = hTable.contains(i);
+ flag = hTable.contains(i);
+ flag = hTable.contains(i);
+ flag = hTable.contains(i);
+ flag = hTable.contains(i);
+ flag = hTable.contains(i);
+ }
+ }
+
+ public void testHashtableContainsKey() {
+ Hashtable<String, Integer> hTable = sTable;
+ boolean flag;
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = hTable.containsKey(i);
+ flag = hTable.containsKey(i);
+ flag = hTable.containsKey(i);
+ flag = hTable.containsKey(i);
+ flag = hTable.containsKey(i);
+ flag = hTable.containsKey(i);
+ flag = hTable.containsKey(i);
+ flag = hTable.containsKey(i);
+ flag = hTable.containsKey(i);
+ flag = hTable.containsKey(i);
+ }
+ }
+
+ public void testHashtableIsEmpty() {
+ Hashtable<String, Integer> hTable = sTable;
+ boolean flag;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = hTable.isEmpty();
+ flag = hTable.isEmpty();
+ flag = hTable.isEmpty();
+ flag = hTable.isEmpty();
+ flag = hTable.isEmpty();
+ flag = hTable.isEmpty();
+ flag = hTable.isEmpty();
+ flag = hTable.isEmpty();
+ flag = hTable.isEmpty();
+ flag = hTable.isEmpty();
+ }
+ }
+
+ public void testHashtableKeys() {
+ Hashtable<String, Integer> hTable = sTable;
+ Enumeration<String> keys;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ keys = hTable.keys();
+ keys = hTable.keys();
+ keys = hTable.keys();
+ keys = hTable.keys();
+ keys = hTable.keys();
+ keys = hTable.keys();
+ keys = hTable.keys();
+ keys = hTable.keys();
+ keys = hTable.keys();
+ keys = hTable.keys();
+ }
+ }
+
+ public void testHashtableElements() {
+ Hashtable<String, Integer> hTable = sTable;
+ Enumeration<Integer> elements;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ elements = hTable.elements();
+ elements = hTable.elements();
+ elements = hTable.elements();
+ elements = hTable.elements();
+ elements = hTable.elements();
+ elements = hTable.elements();
+ elements = hTable.elements();
+ elements = hTable.elements();
+ elements = hTable.elements();
+ elements = hTable.elements();
+ }
+ }
+
+ public void testHashtableHashCode() {
+ int index;
+ Hashtable<String, Integer> hTable = sTable;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = hTable.hashCode();
+ index = hTable.hashCode();
+ index = hTable.hashCode();
+ index = hTable.hashCode();
+ index = hTable.hashCode();
+ index = hTable.hashCode();
+ index = hTable.hashCode();
+ index = hTable.hashCode();
+ index = hTable.hashCode();
+ index = hTable.hashCode();
+ }
+ }
+
+ public void testHashtableEquals() {
+ boolean flag;
+ Hashtable<String, Integer> hTable = sTable;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = hTable.equals(hTable);
+ flag = hTable.equals(hTable);
+ flag = hTable.equals(hTable);
+ flag = hTable.equals(hTable);
+ flag = hTable.equals(hTable);
+ flag = hTable.equals(hTable);
+ flag = hTable.equals(hTable);
+ flag = hTable.equals(hTable);
+ flag = hTable.equals(hTable);
+ flag = hTable.equals(hTable);
+ }
+ }
+
+ public void testHashtableToString() {
+ String str;
+ Hashtable<String, Integer> hTable = sTable;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ str = hTable.toString();
+ str = hTable.toString();
+ str = hTable.toString();
+ str = hTable.toString();
+ str = hTable.toString();
+ str = hTable.toString();
+ str = hTable.toString();
+ str = hTable.toString();
+ str = hTable.toString();
+ str = hTable.toString();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testHashtablePutAll() {
+ Hashtable<String, Integer> hTable = new Hashtable();
+ Hashtable<String, Integer> hTable1 = sTable;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ hTable.putAll(hTable1);
+ hTable.putAll(hTable1);
+ hTable.putAll(hTable1);
+ hTable.putAll(hTable1);
+ hTable.putAll(hTable1);
+ hTable.putAll(hTable1);
+ hTable.putAll(hTable1);
+ hTable.putAll(hTable1);
+ hTable.putAll(hTable1);
+ hTable.putAll(hTable1);
+ }
+ }
+
+ /**
+ *
+ * clone() returns a Hashtable .. It should return Object as per the
+ * specification.
+ *
+ */
+
+ public void testHashtableClone() {
+ Hashtable hashTable;
+ Hashtable<String, Integer> hTable = sTable;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ hashTable = (Hashtable) hTable.clone();
+ hashTable = (Hashtable) hTable.clone();
+ hashTable = (Hashtable) hTable.clone();
+ hashTable = (Hashtable) hTable.clone();
+ hashTable = (Hashtable) hTable.clone();
+ hashTable = (Hashtable) hTable.clone();
+ hashTable = (Hashtable) hTable.clone();
+ hashTable = (Hashtable) hTable.clone();
+ hashTable = (Hashtable) hTable.clone();
+ hashTable = (Hashtable) hTable.clone();
+ }
+ }
+}
diff --git a/tests/CoreTests/android/core/HeapTest.java b/tests/CoreTests/android/core/HeapTest.java
new file mode 100644
index 0000000..6116f5e
--- /dev/null
+++ b/tests/CoreTests/android/core/HeapTest.java
@@ -0,0 +1,633 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+import android.test.suitebuilder.annotation.LargeTest;
+import android.test.suitebuilder.annotation.MediumTest;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.util.Log;
+import android.test.suitebuilder.annotation.Suppress;
+import dalvik.system.VMRuntime;
+import junit.framework.TestCase;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+import java.lang.ref.WeakReference;
+import java.util.LinkedList;
+import java.util.Random;
+
+
+public class HeapTest extends TestCase {
+
+ private static final String TAG = "HeapTest";
+
+ /**
+ * Returns a WeakReference to an object that has no
+ * other references. This is done in a separate method
+ * to ensure that the Object's address isn't sitting in
+ * a stale local register.
+ */
+ private WeakReference<Object> newRef() {
+ return new WeakReference<Object>(new Object());
+ }
+
+ /**
+ * Allocates the specified number of bytes. This is done in a separate method
+ * to ensure that the Object's address isn't sitting in a stale local register.
+ */
+ private void allocateMemory(int size) {
+ byte[] b = new byte[size];
+ }
+
+ @MediumTest
+ public void testMinimumHeapSize() throws Exception {
+ VMRuntime r = VMRuntime.getRuntime();
+ final boolean RUN_FLAKY = false;
+
+ long origSize = r.getMinimumHeapSize();
+ if (RUN_FLAKY) {
+ /* Check that the default value is zero. This will break if anyone
+ * in this process sets the minimum heap size to a positive value
+ * before calling this test.
+ */
+ assertTrue(origSize == 0);
+ }
+
+ long size = 4 * 1024 * 1024;
+ long oldSize = r.setMinimumHeapSize(size);
+ assertTrue(oldSize == origSize);
+
+ long newSize = r.getMinimumHeapSize();
+ /* This will fail if the maximum heap size (-Xmx) is smaller than 4MB.
+ */
+ assertTrue(newSize == size);
+
+ /* Make sure that getting the size doesn't change anything.
+ */
+ newSize = r.getMinimumHeapSize();
+ assertTrue(newSize == size);
+
+ /* This test is flaky; if the heap is already large and fragmented,
+ * it can fail. It can also fail if another thread causes a GC
+ * at the wrong time.
+ */
+ if (RUN_FLAKY) {
+ /* Increase the minimum size, allocate a big object, and make sure that
+ * a GC didn't happen.
+ */
+ WeakReference ref = newRef();
+ assertNotNull(ref.get());
+
+ r.setMinimumHeapSize(8 * 1024 * 1024);
+ allocateMemory(4 * 1024 * 1024);
+
+ /* If a GC happened, this reference will be null.
+ */
+ assertNotNull(ref.get());
+ }
+
+ /* Restore the original setting.
+ */
+ r.setMinimumHeapSize(origSize);
+ newSize = r.getMinimumHeapSize();
+ assertTrue(newSize == origSize);
+
+ /* Clean up any large stuff we've allocated,
+ * and re-establish the normal utilization ratio.
+ */
+ Runtime.getRuntime().gc();
+ }
+
+ private static void makeRefs(Object objects[], SoftReference<Object> refs[]) {
+ for (int i = 0; i < objects.length; i++) {
+ objects[i] = (Object) new byte[8 * 1024];
+ refs[i] = new SoftReference<Object>(objects[i]);
+ }
+ }
+
+ private static <T> int checkRefs(SoftReference<T> refs[], int last) {
+ int i;
+ int numCleared = 0;
+ for (i = 0; i < refs.length; i++) {
+ Object o = refs[i].get();
+ if (o == null) {
+ numCleared++;
+ }
+ }
+ if (numCleared != last) {
+ Log.i(TAG, "****** " + numCleared + "/" + i + " cleared ******");
+ }
+ return numCleared;
+ }
+
+ private static void clearRefs(Object objects[], int skip) {
+ for (int i = 0; i < objects.length; i += skip) {
+ objects[i] = null;
+ }
+ }
+
+ private static void clearRefs(Object objects[]) {
+ clearRefs(objects, 1);
+ }
+
+ private static <T> void checkRefs(T objects[], SoftReference<T> refs[]) {
+ boolean ok = true;
+
+ for (int i = 0; i < objects.length; i++) {
+ if (refs[i].get() != objects[i]) {
+ ok = false;
+ }
+ }
+ if (!ok) {
+ throw new RuntimeException("Test failed: soft refs not cleared");
+ }
+ }
+
+ @MediumTest
+ public void testGcSoftRefs() throws Exception {
+ final int NUM_REFS = 128;
+
+ Object objects[] = new Object[NUM_REFS];
+ SoftReference<Object> refs[] = new SoftReference[objects.length];
+
+ /* Create a bunch of objects and a parallel array
+ * of SoftReferences.
+ */
+ makeRefs(objects, refs);
+ Runtime.getRuntime().gc();
+
+ /* Let go of some of the hard references to the objects so that
+ * the references can be cleared.
+ */
+ clearRefs(objects, 3);
+
+ /* Collect all softly-reachable objects.
+ */
+ VMRuntime.getRuntime().gcSoftReferences();
+ Runtime.getRuntime().runFinalization();
+
+ /* Make sure that the objects were collected.
+ */
+ checkRefs(objects, refs);
+
+ /* Remove more hard references and re-check.
+ */
+ clearRefs(objects, 2);
+ VMRuntime.getRuntime().gcSoftReferences();
+ Runtime.getRuntime().runFinalization();
+ checkRefs(objects, refs);
+
+ /* Remove the rest of the references and re-check.
+ */
+ /* Remove more hard references and re-check.
+ */
+ clearRefs(objects);
+ VMRuntime.getRuntime().gcSoftReferences();
+ Runtime.getRuntime().runFinalization();
+ checkRefs(objects, refs);
+ }
+
+ public void xxtestSoftRefPartialClean() throws Exception {
+ final int NUM_REFS = 128;
+
+ Object objects[] = new Object[NUM_REFS];
+ SoftReference<Object> refs[] = new SoftReference[objects.length];
+
+ /* Create a bunch of objects and a parallel array
+ * of SoftReferences.
+ */
+ makeRefs(objects, refs);
+ Runtime.getRuntime().gc();
+
+ /* Let go of the hard references to the objects so that
+ * the references can be cleared.
+ */
+ clearRefs(objects);
+
+ /* Start creating a bunch of temporary and permanent objects
+ * to drive GC.
+ */
+ final int NUM_OBJECTS = 64 * 1024;
+ Object junk[] = new Object[NUM_OBJECTS];
+ Random random = new Random();
+
+ int i = 0;
+ int mod = 0;
+ int totalSize = 0;
+ int cleared = -1;
+ while (i < junk.length && totalSize < 8 * 1024 * 1024) {
+ int r = random.nextInt(64 * 1024) + 128;
+ Object o = (Object) new byte[r];
+ if (++mod % 16 == 0) {
+ junk[i++] = o;
+ totalSize += r * 4;
+ }
+ cleared = checkRefs(refs, cleared);
+ }
+ }
+
+ private static void makeRefs(Object objects[], WeakReference<Object> refs[]) {
+ for (int i = 0; i < objects.length; i++) {
+ objects[i] = new Object();
+ refs[i] = new WeakReference<Object>(objects[i]);
+ }
+ }
+
+ private static <T> void checkRefs(T objects[], WeakReference<T> refs[]) {
+ boolean ok = true;
+
+ for (int i = 0; i < objects.length; i++) {
+ if (refs[i].get() != objects[i]) {
+ ok = false;
+ }
+ }
+ if (!ok) {
+ throw new RuntimeException("Test failed: " +
+ "weak refs not cleared");
+ }
+ }
+
+ @MediumTest
+ public void testWeakRefs() throws Exception {
+ final int NUM_REFS = 16;
+
+ Object objects[] = new Object[NUM_REFS];
+ WeakReference<Object> refs[] = new WeakReference[objects.length];
+
+ /* Create a bunch of objects and a parallel array
+ * of WeakReferences.
+ */
+ makeRefs(objects, refs);
+ Runtime.getRuntime().gc();
+ checkRefs(objects, refs);
+
+ /* Clear out every other strong reference.
+ */
+ for (int i = 0; i < objects.length; i += 2) {
+ objects[i] = null;
+ }
+ Runtime.getRuntime().gc();
+ checkRefs(objects, refs);
+
+ /* Clear out the rest of them.
+ */
+ for (int i = 0; i < objects.length; i++) {
+ objects[i] = null;
+ }
+ Runtime.getRuntime().gc();
+ checkRefs(objects, refs);
+ }
+
+ private static void makeRefs(Object objects[], PhantomReference<Object> refs[],
+ ReferenceQueue<Object> queue) {
+ for (int i = 0; i < objects.length; i++) {
+ objects[i] = new Object();
+ refs[i] = new PhantomReference<Object>(objects[i], queue);
+ }
+ }
+
+ static <T> void checkRefs(T objects[], PhantomReference<T> refs[],
+ ReferenceQueue<T> queue) {
+ boolean ok = true;
+
+ /* Make sure that the reference that should be on
+ * the queue are marked as enqueued. Once we
+ * pull them off the queue, they will no longer
+ * be marked as enqueued.
+ */
+ for (int i = 0; i < objects.length; i++) {
+ if (objects[i] == null && refs[i] != null) {
+ if (!refs[i].isEnqueued()) {
+ ok = false;
+ }
+ }
+ }
+ if (!ok) {
+ throw new RuntimeException("Test failed: " +
+ "phantom refs not marked as enqueued");
+ }
+
+ /* Make sure that all of the references on the queue
+ * are supposed to be there.
+ */
+ PhantomReference<T> ref;
+ while ((ref = (PhantomReference<T>) queue.poll()) != null) {
+ /* Find the list index that corresponds to this reference.
+ */
+ int i;
+ for (i = 0; i < objects.length; i++) {
+ if (refs[i] == ref) {
+ break;
+ }
+ }
+ if (i == objects.length) {
+ throw new RuntimeException("Test failed: " +
+ "unexpected ref on queue");
+ }
+ if (objects[i] != null) {
+ throw new RuntimeException("Test failed: " +
+ "reference enqueued for strongly-reachable " +
+ "object");
+ }
+ refs[i] = null;
+
+ /* TODO: clear doesn't do much, since we're losing the
+ * strong ref to the ref object anyway. move the ref
+ * into another list.
+ */
+ ref.clear();
+ }
+
+ /* We've visited all of the enqueued references.
+ * Make sure that there aren't any other references
+ * that should have been enqueued.
+ *
+ * NOTE: there is a race condition here; this assumes
+ * that the VM has serviced all outstanding reference
+ * enqueue() calls.
+ */
+ for (int i = 0; i < objects.length; i++) {
+ if (objects[i] == null && refs[i] != null) {
+// System.out.println("HeapTest/PhantomRefs: refs[" + i +
+// "] should be enqueued");
+ ok = false;
+ }
+ }
+ if (!ok) {
+ throw new RuntimeException("Test failed: " +
+ "phantom refs not enqueued");
+ }
+ }
+
+ @MediumTest
+ public void testPhantomRefs() throws Exception {
+ final int NUM_REFS = 16;
+
+ Object objects[] = new Object[NUM_REFS];
+ PhantomReference<Object> refs[] = new PhantomReference[objects.length];
+ ReferenceQueue<Object> queue = new ReferenceQueue<Object>();
+
+ /* Create a bunch of objects and a parallel array
+ * of PhantomReferences.
+ */
+ makeRefs(objects, refs, queue);
+ Runtime.getRuntime().gc();
+ checkRefs(objects, refs, queue);
+
+ /* Clear out every other strong reference.
+ */
+ for (int i = 0; i < objects.length; i += 2) {
+ objects[i] = null;
+ }
+ // System.out.println("HeapTest/PhantomRefs: cleared evens");
+ Runtime.getRuntime().gc();
+ Runtime.getRuntime().runFinalization();
+ checkRefs(objects, refs, queue);
+
+ /* Clear out the rest of them.
+ */
+ for (int i = 0; i < objects.length; i++) {
+ objects[i] = null;
+ }
+ // System.out.println("HeapTest/PhantomRefs: cleared all");
+ Runtime.getRuntime().gc();
+ Runtime.getRuntime().runFinalization();
+ checkRefs(objects, refs, queue);
+ }
+
+ private static int sNumFinalized = 0;
+ private static final Object sLock = new Object();
+
+ private static class FinalizableObject {
+ protected void finalize() {
+ // System.out.println("gc from finalize()");
+ Runtime.getRuntime().gc();
+ synchronized (sLock) {
+ sNumFinalized++;
+ }
+ }
+ }
+
+ private static void makeRefs(FinalizableObject objects[],
+ WeakReference<FinalizableObject> refs[]) {
+ for (int i = 0; i < objects.length; i++) {
+ objects[i] = new FinalizableObject();
+ refs[i] = new WeakReference<FinalizableObject>(objects[i]);
+ }
+ }
+
+ @LargeTest
+ public void testWeakRefsAndFinalizers() throws Exception {
+ final int NUM_REFS = 16;
+
+ FinalizableObject objects[] = new FinalizableObject[NUM_REFS];
+ WeakReference<FinalizableObject> refs[] = new WeakReference[objects.length];
+ int numCleared;
+
+ /* Create a bunch of objects and a parallel array
+ * of WeakReferences.
+ */
+ makeRefs(objects, refs);
+ Runtime.getRuntime().gc();
+ checkRefs(objects, refs);
+
+ /* Clear out every other strong reference.
+ */
+ sNumFinalized = 0;
+ numCleared = 0;
+ for (int i = 0; i < objects.length; i += 2) {
+ objects[i] = null;
+ numCleared++;
+ }
+ // System.out.println("HeapTest/WeakRefsAndFinalizers: cleared evens");
+ Runtime.getRuntime().gc();
+ Runtime.getRuntime().runFinalization();
+ checkRefs(objects, refs);
+ if (sNumFinalized != numCleared) {
+ throw new RuntimeException("Test failed: " +
+ "expected " + numCleared + " finalizations, saw " +
+ sNumFinalized);
+ }
+
+ /* Clear out the rest of them.
+ */
+ sNumFinalized = 0;
+ numCleared = 0;
+ for (int i = 0; i < objects.length; i++) {
+ if (objects[i] != null) {
+ objects[i] = null;
+ numCleared++;
+ }
+ }
+ // System.out.println("HeapTest/WeakRefsAndFinalizers: cleared all");
+ Runtime.getRuntime().gc();
+ Runtime.getRuntime().runFinalization();
+ checkRefs(objects, refs);
+ if (sNumFinalized != numCleared) {
+ throw new RuntimeException("Test failed: " +
+ "expected " + numCleared + " finalizations, saw " +
+ sNumFinalized);
+ }
+ }
+
+ // TODO: flaky test
+ //@MediumTest
+ public void testOomeLarge() throws Exception {
+ /* Just shy of the typical max heap size so that it will actually
+ * try to allocate it instead of short-circuiting.
+ */
+ final int SIXTEEN_MB = (16 * 1024 * 1024 - 32);
+
+ Boolean sawEx = false;
+ byte a[];
+
+ try {
+ a = new byte[SIXTEEN_MB];
+ } catch (OutOfMemoryError oom) {
+ //Log.i(TAG, "HeapTest/OomeLarge caught " + oom);
+ sawEx = true;
+ }
+
+ if (!sawEx) {
+ throw new RuntimeException("Test failed: " +
+ "OutOfMemoryError not thrown");
+ }
+ }
+
+ //See bug 1308253 for reasons.
+ @Suppress
+ public void disableTestOomeSmall() throws Exception {
+ final int SIXTEEN_MB = (16 * 1024 * 1024);
+ final int LINK_SIZE = 6 * 4; // estimated size of a LinkedList's node
+
+ Boolean sawEx = false;
+
+ LinkedList<Object> list = new LinkedList<Object>();
+
+ /* Allocate progressively smaller objects to fill up the entire heap.
+ */
+ int objSize = 1 * 1024 * 1024;
+ while (objSize >= LINK_SIZE) {
+ try {
+ for (int i = 0; i < SIXTEEN_MB / objSize; i++) {
+ list.add((Object)new byte[objSize]);
+ }
+ } catch (OutOfMemoryError oom) {
+ sawEx = true;
+ }
+
+ if (!sawEx) {
+ throw new RuntimeException("Test failed: " +
+ "OutOfMemoryError not thrown while filling heap");
+ }
+ sawEx = false;
+
+ objSize = (objSize * 4) / 5;
+ }
+ }
+
+ // TODO: flaky test
+ //@SmallTest
+ public void testExternalOomeLarge() {
+ /* Just shy of the typical max heap size so that it will actually
+ * try to allocate it instead of short-circuiting.
+ */
+ final int HUGE_SIZE = (16 * 1024 * 1024 - 32);
+
+ assertFalse(VMRuntime.getRuntime().trackExternalAllocation(HUGE_SIZE));
+ }
+
+ /**
+ * "Allocates" external memory in progressively smaller chunks until there's
+ * only roughly 16 bytes left.
+ *
+ * @return the number of bytes allocated
+ */
+ private long allocateMaxExternal() {
+ final VMRuntime runtime = VMRuntime.getRuntime();
+ final int SIXTEEN_MB = (16 * 1024 * 1024);
+ final int MIN_SIZE = 16;
+ long totalAllocated = 0;
+ boolean success;
+
+ success = false;
+ try {
+ /* "Allocate" progressively smaller chunks to "fill up" the entire heap.
+ */
+ int objSize = 1 * 1024 * 1024;
+ while (objSize >= MIN_SIZE) {
+ boolean sawFailure = false;
+ for (int i = 0; i < SIXTEEN_MB / objSize; i++) {
+ if (runtime.trackExternalAllocation(objSize)) {
+ totalAllocated += objSize;
+ } else {
+ sawFailure = true;
+ break;
+ }
+ }
+
+ if (!sawFailure) {
+ throw new RuntimeException("Test failed: " +
+ "no failure while filling heap");
+ }
+
+ objSize = (objSize * 4) / 5;
+ }
+ success = true;
+ } finally {
+ if (!success) {
+ runtime.trackExternalFree(totalAllocated);
+ totalAllocated = 0;
+ }
+ }
+ return totalAllocated;
+ }
+
+ public void xxtest00ExternalOomeSmall() {
+ VMRuntime.getRuntime().trackExternalFree(allocateMaxExternal());
+ }
+
+ /**
+ * Allocates as much external memory as possible, then allocates from the heap
+ * until an OOME is caught.
+ *
+ * It's nice to run this test while the real heap is small, hence the '00' in its
+ * name to force it to run before testOomeSmall().
+ */
+ public void xxtest00CombinedOomeSmall() {
+ long totalAllocated = 0;
+ boolean sawEx = false;
+ try {
+ totalAllocated = allocateMaxExternal();
+ LinkedList<Object> list = new LinkedList<Object>();
+ try {
+ while (true) {
+ list.add((Object)new byte[8192]);
+ }
+ /*NOTREACHED*/
+ } catch (OutOfMemoryError oom) {
+ sawEx = true;
+ }
+ } finally {
+ VMRuntime.getRuntime().trackExternalFree(totalAllocated);
+ }
+ assertTrue(sawEx);
+ }
+
+ //TODO: test external alloc debugging/inspection
+}
diff --git a/tests/CoreTests/android/core/InstanceofTest.java b/tests/CoreTests/android/core/InstanceofTest.java
new file mode 100644
index 0000000..b35ef6b
--- /dev/null
+++ b/tests/CoreTests/android/core/InstanceofTest.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2006 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 android.core;
+
+import junit.framework.TestCase;
+import android.test.suitebuilder.annotation.MediumTest;
+
+
+public class InstanceofTest extends TestCase {
+
+ protected A mA;
+ protected ChildOfAOne mOne;
+ protected ChildOfAOne mTwo;
+ protected ChildOfAOne mThree;
+ protected ChildOfAOne mFour;
+ protected ChildOfAFive mFive;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ mA = new A();
+ mOne = new ChildOfAOne();
+ mTwo = new ChildOfATwo();
+ mThree = new ChildOfAThree();
+ mFour = new ChildOfAFour();
+ mFive = new ChildOfAFive();
+ }
+
+
+ @MediumTest
+ public void testNoInterface() throws Exception {
+ A a = mA;
+ for (int i = 0; i < 100000; i++) {
+ assertFalse("m_a should not be a ChildOfAFive", a instanceof ChildOfAFive);
+ }
+ }
+
+ @MediumTest
+ public void testDerivedOne() throws Exception {
+ InterfaceOne one = mOne;
+ for (int i = 0; i < 100000; i++) {
+ assertFalse("m_one should not be a ChildOfAFive", one instanceof ChildOfAFive);
+ }
+ }
+
+ @MediumTest
+ public void testDerivedTwo() throws Exception {
+ InterfaceTwo two = mTwo;
+ for (int i = 0; i < 100000; i++) {
+ assertFalse("m_two should not be a ChildOfAFive", two instanceof ChildOfAFive);
+ }
+ }
+
+ @MediumTest
+ public void testDerivedThree() throws Exception {
+ InterfaceThree three = mThree;
+ for (int i = 0; i < 100000; i++) {
+ assertFalse("m_three should not be a ChildOfAFive", three instanceof ChildOfAFive);
+ }
+ }
+
+ @MediumTest
+ public void testDerivedFour() throws Exception {
+ InterfaceFour four = mFour;
+ for (int i = 0; i < 100000; i++) {
+ assertFalse("m_four should not be a ChildOfAFive", four instanceof ChildOfAFive);
+ }
+ }
+
+ @MediumTest
+ public void testSuccessClass() throws Exception {
+ ChildOfAOne five = mFive;
+ for (int i = 0; i < 100000; i++) {
+ assertTrue("m_five is suppose to be a ChildOfAFive", five instanceof ChildOfAFive);
+ }
+ }
+
+ @MediumTest
+ public void testSuccessInterface() throws Exception {
+ ChildOfAFive five = mFive;
+ for (int i = 0; i < 100000; i++) {
+ assertTrue("m_five is suppose to be a InterfaceFour", five instanceof InterfaceFour);
+ }
+ }
+
+ @MediumTest
+ public void testFailInterface() throws Exception {
+ InterfaceOne one = mFive;
+ for (int i = 0; i < 100000; i++) {
+ assertFalse("m_five does not implement InterfaceFive", one instanceof InterfaceFive);
+ }
+ }
+
+ private interface InterfaceOne {
+ }
+
+ private interface InterfaceTwo {
+ }
+
+ private interface InterfaceThree {
+ }
+
+ private interface InterfaceFour {
+ }
+
+ private interface InterfaceFive {
+ }
+
+ private static class A {
+ }
+
+ private static class ChildOfAOne extends A implements InterfaceOne, InterfaceTwo, InterfaceThree, InterfaceFour {
+ }
+
+ private static class ChildOfATwo extends ChildOfAOne {
+ }
+
+ private static class ChildOfAThree extends ChildOfATwo {
+ }
+
+ private static class ChildOfAFour extends ChildOfAThree {
+ }
+
+ private static class ChildOfAFive extends ChildOfAFour {
+ }
+}
diff --git a/tests/CoreTests/android/core/JavaPerformanceTests.java b/tests/CoreTests/android/core/JavaPerformanceTests.java
new file mode 100644
index 0000000..fbe70cc
--- /dev/null
+++ b/tests/CoreTests/android/core/JavaPerformanceTests.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+/**
+ *
+ */
+public class JavaPerformanceTests {
+
+ public static String[] children() {
+ return new String[] {
+ StringTest.class.getName(),
+ HashMapPerformanceTest.class.getName(),
+ ArrayListPerformanceTest.class.getName(),
+ TreeMapPerformanceTest.class.getName(),
+ TreeSetTest.class.getName(),
+ HashSetTest.class.getName(),
+ HashtableTest.class.getName(),
+ VectorTest.class.getName(),
+ LinkedListTest.class.getName(),
+ MathPerformanceTest.class.getName(),
+ };
+ }
+}
diff --git a/tests/CoreTests/android/core/JniLibTest.java b/tests/CoreTests/android/core/JniLibTest.java
new file mode 100644
index 0000000..d476072
--- /dev/null
+++ b/tests/CoreTests/android/core/JniLibTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2006 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 android.core;
+
+import android.test.suitebuilder.annotation.Suppress;
+import android.util.Log;
+import junit.framework.TestCase;
+
+
+@Suppress
+public class JniLibTest extends TestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ /*
+ * This causes the native shared library to be loaded when the
+ * class is first used. The library is only loaded once, even if
+ * multiple classes include this line.
+ *
+ * The library must be in java.library.path, which is derived from
+ * LD_LIBRARY_PATH. The actual library name searched for will be
+ * "libjni_lib_test.so" under Linux, but may be different on other
+ * platforms.
+ */
+ try {
+ System.loadLibrary("jni_lib_test");
+ } catch (UnsatisfiedLinkError ule) {
+ Log.e("JniLibTest", "WARNING: Could not load jni_lib_test natives");
+ }
+ }
+
+ private static native int nativeStaticThing(float f);
+ private native void nativeThing(int val);
+
+ public void testNativeCall() {
+ Log.i("JniLibTest", "JNI search path is "
+ + System.getProperty("java.library.path"));
+ Log.i("JniLibTest", "'jni_lib_test' becomes '"
+ + System.mapLibraryName("jni_lib_test") + "'");
+
+ int result = nativeStaticThing(1234.5f);
+ nativeThing(result);
+ }
+}
diff --git a/tests/CoreTests/android/core/LinkedListTest.java b/tests/CoreTests/android/core/LinkedListTest.java
new file mode 100644
index 0000000..8b237fd
--- /dev/null
+++ b/tests/CoreTests/android/core/LinkedListTest.java
@@ -0,0 +1,529 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+import android.test.PerformanceTestBase;
+import android.test.PerformanceTestCase;
+import java.util.LinkedList;
+import java.util.ListIterator;
+
+/**
+ * This class contains performance tests for methods in java.util.LinkedList
+ *
+ */
+@SuppressWarnings("unchecked")
+public class LinkedListTest extends PerformanceTestBase {
+ public static final int ITERATIONS = 1000;
+ LinkedList<Integer> mLinkedList;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mLinkedList = new LinkedList();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ mLinkedList.add(i);
+ }
+ }
+
+ @Override
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ public void testLinkedListAdd() {
+ LinkedList<Integer> list = new LinkedList();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ list.add(i);
+ list.add(i);
+ list.add(i);
+ list.add(i);
+ list.add(i);
+ list.add(i);
+ list.add(i);
+ list.add(i);
+ list.add(i);
+ list.add(i);
+ }
+ }
+
+ public void testLinkedListAdd1() {
+ LinkedList<Integer> list = new LinkedList();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ list.add(0, i);
+ list.add(0, i);
+ list.add(0, i);
+ list.add(0, i);
+ list.add(0, i);
+ list.add(0, i);
+ list.add(0, i);
+ list.add(0, i);
+ list.add(0, i);
+ list.add(0, i);
+ }
+ }
+
+ public void testLinkedListToArray() {
+ Object array;
+ LinkedList<Integer> list = mLinkedList;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ array = list.toArray();
+ array = list.toArray();
+ array = list.toArray();
+ array = list.toArray();
+ array = list.toArray();
+ array = list.toArray();
+ array = list.toArray();
+ array = list.toArray();
+ array = list.toArray();
+ array = list.toArray();
+ }
+ }
+
+ public void testLinkedListSize() {
+ LinkedList<Integer> list = mLinkedList;
+ int len;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ len = list.size();
+ len = list.size();
+ len = list.size();
+ len = list.size();
+ len = list.size();
+ len = list.size();
+ len = list.size();
+ len = list.size();
+ len = list.size();
+ len = list.size();
+ }
+ }
+
+ public void testLinkedListGet() {
+ int element;
+ LinkedList<Integer> list = mLinkedList;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ element = list.get(i);
+ element = list.get(i);
+ element = list.get(i);
+ element = list.get(i);
+ element = list.get(i);
+ element = list.get(i);
+ element = list.get(i);
+ element = list.get(i);
+ element = list.get(i);
+ element = list.get(i);
+ }
+ }
+
+ public void testLinkedListContains() {
+ boolean flag;
+ LinkedList<Integer> list = mLinkedList;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = list.contains(i);
+ flag = list.contains(i);
+ flag = list.contains(i);
+ flag = list.contains(i);
+ flag = list.contains(i);
+ flag = list.contains(i);
+ flag = list.contains(i);
+ flag = list.contains(i);
+ flag = list.contains(i);
+ flag = list.contains(i);
+ }
+ }
+
+ public void testLinkedListToArray1() {
+ Integer[] rArray = new Integer[100];
+ Integer[] array;
+ LinkedList<Integer> list = mLinkedList;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ array = list.toArray(rArray);
+ array = list.toArray(rArray);
+ array = list.toArray(rArray);
+ array = list.toArray(rArray);
+ array = list.toArray(rArray);
+ array = list.toArray(rArray);
+ array = list.toArray(rArray);
+ array = list.toArray(rArray);
+ array = list.toArray(rArray);
+ array = list.toArray(rArray);
+ }
+ }
+
+ public void testLinkedListSet() {
+ LinkedList<Integer> list = mLinkedList;
+ int value1 = 500, value2 = 0;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ list.set(value1, value2);
+ list.set(value1, value2);
+ list.set(value1, value2);
+ list.set(value1, value2);
+ list.set(value1, value2);
+ list.set(value1, value2);
+ list.set(value1, value2);
+ list.set(value1, value2);
+ list.set(value1, value2);
+ list.set(value1, value2);
+ }
+ }
+
+ public void testLinkedListIndexOf() {
+ int index;
+ LinkedList<Integer> list = mLinkedList;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = list.indexOf(0);
+ index = list.indexOf(0);
+ index = list.indexOf(0);
+ index = list.indexOf(0);
+ index = list.indexOf(0);
+ index = list.indexOf(0);
+ index = list.indexOf(0);
+ index = list.indexOf(0);
+ index = list.indexOf(0);
+ index = list.indexOf(0);
+
+ }
+ }
+
+ public void testLinkedListLastIndexOf() {
+ int index;
+ LinkedList<Integer> list = mLinkedList;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = list.lastIndexOf(0);
+ index = list.lastIndexOf(0);
+ index = list.lastIndexOf(0);
+ index = list.lastIndexOf(0);
+ index = list.lastIndexOf(0);
+ index = list.lastIndexOf(0);
+ index = list.lastIndexOf(0);
+ index = list.lastIndexOf(0);
+ index = list.lastIndexOf(0);
+ index = list.lastIndexOf(0);
+ }
+ }
+
+ public void testLinkedListRemove() {
+ int index;
+ LinkedList<Integer> list = new LinkedList(mLinkedList);
+ for (int i = 10; i > 0; i--) {
+ index = list.remove();
+ index = list.remove();
+ index = list.remove();
+ index = list.remove();
+ index = list.remove();
+ index = list.remove();
+ index = list.remove();
+ index = list.remove();
+ index = list.remove();
+ index = list.remove();
+ }
+ }
+
+ public void testLinkedListRemove1() {
+ int index;
+ LinkedList<Integer> list = new LinkedList(mLinkedList);
+ for (int i = 10; i > 0; i--) {
+ index = list.remove(0);
+ index = list.remove(0);
+ index = list.remove(0);
+ index = list.remove(0);
+ index = list.remove(0);
+ index = list.remove(0);
+ index = list.remove(0);
+ index = list.remove(0);
+ index = list.remove(0);
+ index = list.remove(0);
+ }
+ }
+
+ public void testLinkedListRemoveFirst() {
+ int index;
+ LinkedList<Integer> list = new LinkedList(mLinkedList);
+ for (int i = 10; i > 0; i--) {
+ index = list.removeFirst();
+ index = list.removeFirst();
+ index = list.removeFirst();
+ index = list.removeFirst();
+ index = list.removeFirst();
+ index = list.removeFirst();
+ index = list.removeFirst();
+ index = list.removeFirst();
+ index = list.removeFirst();
+ index = list.removeFirst();
+ }
+ }
+
+ public void testLinkedListRemoveLast() {
+ int index;
+ LinkedList<Integer> list = new LinkedList(mLinkedList);
+ for (int i = 10; i > 0; i--) {
+ index = list.removeLast();
+ index = list.removeLast();
+ index = list.removeLast();
+ index = list.removeLast();
+ index = list.removeLast();
+ index = list.removeLast();
+ index = list.removeLast();
+ index = list.removeLast();
+ index = list.removeLast();
+ index = list.removeLast();
+ }
+ }
+
+ public void testLinkedListAddAll() {
+ LinkedList<Integer> mList = mLinkedList;
+ boolean flag;
+ LinkedList<Integer> list = new LinkedList();
+ for (int i = 10; i > 0; i--) {
+ flag = list.addAll(mList);
+ flag = list.addAll(mList);
+ flag = list.addAll(mList);
+ flag = list.addAll(mList);
+ flag = list.addAll(mList);
+ flag = list.addAll(mList);
+ flag = list.addAll(mList);
+ flag = list.addAll(mList);
+ flag = list.addAll(mList);
+ flag = list.addAll(mList);
+ }
+ }
+
+ public void testLinkedListRemove2() {
+ LinkedList<String> list;
+ String s = new String("a");
+ list = new LinkedList();
+ for (int j = 1000; j > 0; j--) {
+ list.add("a");
+ list.add("b");
+ }
+ boolean flag;
+ for (int i = 10; i > 0; i--) {
+ flag = list.remove(s);
+ flag = list.remove(s);
+ flag = list.remove(s);
+ flag = list.remove(s);
+ flag = list.remove(s);
+ flag = list.remove(s);
+ flag = list.remove(s);
+ flag = list.remove(s);
+ flag = list.remove(s);
+ flag = list.remove(s);
+ }
+ }
+
+ public void testLinkedListAddAll1() {
+ LinkedList<Integer> mList = new LinkedList();
+ int pos = 0;
+ boolean flag;
+ LinkedList<Integer> list = mLinkedList;
+ for (int i = 0; i < 10; i++) {
+ flag = mList.addAll(pos, list);
+ flag = mList.addAll(pos, list);
+ flag = mList.addAll(pos, list);
+ flag = mList.addAll(pos, list);
+ flag = mList.addAll(pos, list);
+ flag = mList.addAll(pos, list);
+ flag = mList.addAll(pos, list);
+ flag = mList.addAll(pos, list);
+ flag = mList.addAll(pos, list);
+ flag = mList.addAll(pos, list);
+ }
+ }
+
+ public void testLinkedListClone() {
+ Object rObj;
+ LinkedList<Integer> list = mLinkedList;
+ for (int i = 100; i > 0; i--) {
+ rObj = list.clone();
+ rObj = list.clone();
+ rObj = list.clone();
+ rObj = list.clone();
+ rObj = list.clone();
+ rObj = list.clone();
+ rObj = list.clone();
+ rObj = list.clone();
+ rObj = list.clone();
+ rObj = list.clone();
+ }
+ }
+
+ public void testLinkedListHashcode() {
+ int element;
+ LinkedList<Integer> list = mLinkedList;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ element = list.hashCode();
+ element = list.hashCode();
+ element = list.hashCode();
+ element = list.hashCode();
+ element = list.hashCode();
+ element = list.hashCode();
+ element = list.hashCode();
+ element = list.hashCode();
+ element = list.hashCode();
+ element = list.hashCode();
+ }
+ }
+
+ public void testLinkedListElement() {
+ int element;
+ LinkedList<Integer> list = mLinkedList;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ element = list.element();
+ element = list.element();
+ element = list.element();
+ element = list.element();
+ element = list.element();
+ element = list.element();
+ element = list.element();
+ element = list.element();
+ element = list.element();
+ element = list.element();
+ }
+ }
+
+ public void testLinkedListToString() {
+ String str;
+ LinkedList<Integer> list = mLinkedList;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ str = list.toString();
+ str = list.toString();
+ str = list.toString();
+ str = list.toString();
+ str = list.toString();
+ str = list.toString();
+ str = list.toString();
+ str = list.toString();
+ str = list.toString();
+ str = list.toString();
+ }
+ }
+
+ public void testLinkedListIsEmpty() {
+ boolean flag;
+ LinkedList<Integer> list = mLinkedList;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = list.isEmpty();
+ flag = list.isEmpty();
+ flag = list.isEmpty();
+ flag = list.isEmpty();
+ flag = list.isEmpty();
+ flag = list.isEmpty();
+ flag = list.isEmpty();
+ flag = list.isEmpty();
+ flag = list.isEmpty();
+ flag = list.isEmpty();
+ }
+ }
+
+ public void testLinkedListOffer() {
+ LinkedList<Integer> list = new LinkedList();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ list.offer(i);
+ list.offer(i);
+ list.offer(i);
+ list.offer(i);
+ list.offer(i);
+ list.offer(i);
+ list.offer(i);
+ list.offer(i);
+ list.offer(i);
+ list.offer(i);
+ }
+ }
+
+ public void testLinkedListPeek() {
+ int element;
+ LinkedList<Integer> list = mLinkedList;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ element = list.peek();
+ element = list.peek();
+ element = list.peek();
+ element = list.peek();
+ element = list.peek();
+ element = list.peek();
+ element = list.peek();
+ element = list.peek();
+ element = list.peek();
+ element = list.peek();
+ }
+ }
+
+ public void testLinkedListPoll() {
+ int element;
+ LinkedList<Integer> list = new LinkedList(mLinkedList);
+ for (int i = 10; i > 0; i--) {
+ element = list.poll();
+ element = list.poll();
+ element = list.poll();
+ element = list.poll();
+ element = list.poll();
+ element = list.poll();
+ element = list.poll();
+ element = list.poll();
+ element = list.poll();
+ element = list.poll();
+ }
+ }
+
+ public void testLinkedListAddLast() {
+ LinkedList<Integer> list = new LinkedList();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ list.addLast(i);
+ list.addLast(i);
+ list.addLast(i);
+ list.addLast(i);
+ list.addLast(i);
+ list.addLast(i);
+ list.addLast(i);
+ list.addLast(i);
+ list.addLast(i);
+ list.addLast(i);
+ }
+ }
+
+ public void testLinkedListAddFirst() {
+ LinkedList<Integer> list = new LinkedList();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ list.addFirst(i);
+ list.addFirst(i);
+ list.addFirst(i);
+ list.addFirst(i);
+ list.addFirst(i);
+ list.addFirst(i);
+ list.addFirst(i);
+ list.addFirst(i);
+ list.addFirst(i);
+ list.addFirst(i);
+ }
+ }
+
+ public void testLinkedListIterator() {
+ ListIterator iterator;
+ LinkedList<Integer> list = mLinkedList;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ iterator = list.listIterator();
+ iterator = list.listIterator();
+ iterator = list.listIterator();
+ iterator = list.listIterator();
+ iterator = list.listIterator();
+ iterator = list.listIterator();
+ iterator = list.listIterator();
+ iterator = list.listIterator();
+ iterator = list.listIterator();
+ iterator = list.listIterator();
+ }
+ }
+}
diff --git a/tests/CoreTests/android/core/MathPerformanceTest.java b/tests/CoreTests/android/core/MathPerformanceTest.java
new file mode 100644
index 0000000..b1eb500
--- /dev/null
+++ b/tests/CoreTests/android/core/MathPerformanceTest.java
@@ -0,0 +1,380 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+import android.test.PerformanceTestBase;
+import android.test.PerformanceTestCase;
+
+/**
+ *
+ * Implements basic performance test functionality for java.lang.Math
+ *
+ */
+
+public class MathPerformanceTest extends PerformanceTestBase {
+ public static final int ITERATIONS = 1000;
+ public static final double sDouble1 = -2450.50;
+ public static final double sDouble2 = -500;
+ public static final float sFloat = 300.50f;
+ public static final int sInt = 90;
+
+ @Override
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ public void testDoubleAbs() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.abs(sDouble1);
+ result = Math.abs(sDouble1);
+ result = Math.abs(sDouble1);
+ result = Math.abs(sDouble1);
+ result = Math.abs(sDouble1);
+ result = Math.abs(sDouble1);
+ result = Math.abs(sDouble1);
+ result = Math.abs(sDouble1);
+ result = Math.abs(sDouble1);
+ result = Math.abs(sDouble1);
+ }
+ }
+
+ public void testFloatAbs() {
+ float result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.abs(sFloat);
+ result = Math.abs(sFloat);
+ result = Math.abs(sFloat);
+ result = Math.abs(sFloat);
+ result = Math.abs(sFloat);
+ result = Math.abs(sFloat);
+ result = Math.abs(sFloat);
+ result = Math.abs(sFloat);
+ result = Math.abs(sFloat);
+ result = Math.abs(sFloat);
+ }
+ }
+
+ public void testMathSin() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.sin(sDouble1);
+ result = Math.sin(sDouble1);
+ result = Math.sin(sDouble1);
+ result = Math.sin(sDouble1);
+ result = Math.sin(sDouble1);
+ result = Math.sin(sDouble1);
+ result = Math.sin(sDouble1);
+ result = Math.sin(sDouble1);
+ result = Math.sin(sDouble1);
+ result = Math.sin(sDouble1);
+ }
+ }
+
+ public void testMathCos() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.cos(sDouble1);
+ result = Math.cos(sDouble1);
+ result = Math.cos(sDouble1);
+ result = Math.cos(sDouble1);
+ result = Math.cos(sDouble1);
+ result = Math.cos(sDouble1);
+ result = Math.cos(sDouble1);
+ result = Math.cos(sDouble1);
+ result = Math.cos(sDouble1);
+ result = Math.cos(sDouble1);
+ }
+ }
+
+ public void testMathTan() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.tan(sDouble1);
+ result = Math.tan(sDouble1);
+ result = Math.tan(sDouble1);
+ result = Math.tan(sDouble1);
+ result = Math.tan(sDouble1);
+ result = Math.tan(sDouble1);
+ result = Math.tan(sDouble1);
+ result = Math.tan(sDouble1);
+ result = Math.tan(sDouble1);
+ result = Math.tan(sDouble1);
+ }
+ }
+
+ public void testMathASin() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.asin(sDouble1);
+ result = Math.asin(sDouble1);
+ result = Math.asin(sDouble1);
+ result = Math.asin(sDouble1);
+ result = Math.asin(sDouble1);
+ result = Math.asin(sDouble1);
+ result = Math.asin(sDouble1);
+ result = Math.asin(sDouble1);
+ result = Math.asin(sDouble1);
+ result = Math.asin(sDouble1);
+ }
+ }
+
+ public void testMathACos() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.acos(sDouble1);
+ result = Math.acos(sDouble1);
+ result = Math.acos(sDouble1);
+ result = Math.acos(sDouble1);
+ result = Math.acos(sDouble1);
+ result = Math.acos(sDouble1);
+ result = Math.acos(sDouble1);
+ result = Math.acos(sDouble1);
+ result = Math.acos(sDouble1);
+ result = Math.acos(sDouble1);
+ }
+ }
+
+ public void testMathATan() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.atan(sDouble1);
+ result = Math.atan(sDouble1);
+ result = Math.atan(sDouble1);
+ result = Math.atan(sDouble1);
+ result = Math.atan(sDouble1);
+ result = Math.atan(sDouble1);
+ result = Math.atan(sDouble1);
+ result = Math.atan(sDouble1);
+ result = Math.atan(sDouble1);
+ result = Math.atan(sDouble1);
+ }
+ }
+
+ public void testMathLog() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.log(sDouble1);
+ result = Math.log(sDouble1);
+ result = Math.log(sDouble1);
+ result = Math.log(sDouble1);
+ result = Math.log(sDouble1);
+ result = Math.log(sDouble1);
+ result = Math.log(sDouble1);
+ result = Math.log(sDouble1);
+ result = Math.log(sDouble1);
+ result = Math.log(sDouble1);
+ }
+ }
+
+ public void testMathSqrt() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.sqrt(sDouble1);
+ result = Math.sqrt(sDouble1);
+ result = Math.sqrt(sDouble1);
+ result = Math.sqrt(sDouble1);
+ result = Math.sqrt(sDouble1);
+ result = Math.sqrt(sDouble1);
+ result = Math.sqrt(sDouble1);
+ result = Math.sqrt(sDouble1);
+ result = Math.sqrt(sDouble1);
+ result = Math.sqrt(sDouble1);
+ }
+ }
+
+ public void testMathCeil() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.ceil(sDouble1);
+ result = Math.ceil(sDouble1);
+ result = Math.ceil(sDouble1);
+ result = Math.ceil(sDouble1);
+ result = Math.ceil(sDouble1);
+ result = Math.ceil(sDouble1);
+ result = Math.ceil(sDouble1);
+ result = Math.ceil(sDouble1);
+ result = Math.ceil(sDouble1);
+ result = Math.ceil(sDouble1);
+ }
+ }
+
+ public void testMathRound() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.round(sDouble1);
+ result = Math.round(sDouble1);
+ result = Math.round(sDouble1);
+ result = Math.round(sDouble1);
+ result = Math.round(sDouble1);
+ result = Math.round(sDouble1);
+ result = Math.round(sDouble1);
+ result = Math.round(sDouble1);
+ result = Math.round(sDouble1);
+ result = Math.round(sDouble1);
+ }
+ }
+
+ public void testMathFloor() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.floor(sDouble1);
+ result = Math.floor(sDouble1);
+ result = Math.floor(sDouble1);
+ result = Math.floor(sDouble1);
+ result = Math.floor(sDouble1);
+ result = Math.floor(sDouble1);
+ result = Math.floor(sDouble1);
+ result = Math.floor(sDouble1);
+ result = Math.floor(sDouble1);
+ result = Math.floor(sDouble1);
+ }
+ }
+
+ public void testMathExp() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.exp(sDouble1);
+ result = Math.exp(sDouble1);
+ result = Math.exp(sDouble1);
+ result = Math.exp(sDouble1);
+ result = Math.exp(sDouble1);
+ result = Math.exp(sDouble1);
+ result = Math.exp(sDouble1);
+ result = Math.exp(sDouble1);
+ result = Math.exp(sDouble1);
+ result = Math.exp(sDouble1);
+ }
+ }
+
+ /**
+ *
+ */
+
+ public void testMathPow() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.pow(sDouble1, sDouble2);
+ result = Math.pow(sDouble1, sDouble2);
+ result = Math.pow(sDouble1, sDouble2);
+ result = Math.pow(sDouble1, sDouble2);
+ result = Math.pow(sDouble1, sDouble2);
+ result = Math.pow(sDouble1, sDouble2);
+ result = Math.pow(sDouble1, sDouble2);
+ result = Math.pow(sDouble1, sDouble2);
+ result = Math.pow(sDouble1, sDouble2);
+ result = Math.pow(sDouble1, sDouble2);
+ }
+ }
+
+ public void testMathMax() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.max(sDouble1, sDouble2);
+ result = Math.max(sDouble1, sDouble2);
+ result = Math.max(sDouble1, sDouble2);
+ result = Math.max(sDouble1, sDouble2);
+ result = Math.max(sDouble1, sDouble2);
+ result = Math.max(sDouble1, sDouble2);
+ result = Math.max(sDouble1, sDouble2);
+ result = Math.max(sDouble1, sDouble2);
+ result = Math.max(sDouble1, sDouble2);
+ result = Math.max(sDouble1, sDouble2);
+ }
+ }
+
+ public void testMathMin() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.min(sDouble1, sDouble2);
+ result = Math.min(sDouble1, sDouble2);
+ result = Math.min(sDouble1, sDouble2);
+ result = Math.min(sDouble1, sDouble2);
+ result = Math.min(sDouble1, sDouble2);
+ result = Math.min(sDouble1, sDouble2);
+ result = Math.min(sDouble1, sDouble2);
+ result = Math.min(sDouble1, sDouble2);
+ result = Math.min(sDouble1, sDouble2);
+ result = Math.min(sDouble1, sDouble2);
+ }
+ }
+
+ public void testMathRandom() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.random();
+ result = Math.random();
+ result = Math.random();
+ result = Math.random();
+ result = Math.random();
+ result = Math.random();
+ result = Math.random();
+ result = Math.random();
+ result = Math.random();
+ result = Math.random();
+ }
+ }
+
+ public void testMathIEEERemainder() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.IEEEremainder(sDouble1, sDouble2);
+ result = Math.IEEEremainder(sDouble1, sDouble2);
+ result = Math.IEEEremainder(sDouble1, sDouble2);
+ result = Math.IEEEremainder(sDouble1, sDouble2);
+ result = Math.IEEEremainder(sDouble1, sDouble2);
+ result = Math.IEEEremainder(sDouble1, sDouble2);
+ result = Math.IEEEremainder(sDouble1, sDouble2);
+ result = Math.IEEEremainder(sDouble1, sDouble2);
+ result = Math.IEEEremainder(sDouble1, sDouble2);
+ result = Math.IEEEremainder(sDouble1, sDouble2);
+ }
+ }
+
+ public void testMathToDegrees() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.toDegrees(sDouble1);
+ result = Math.toDegrees(sDouble1);
+ result = Math.toDegrees(sDouble1);
+ result = Math.toDegrees(sDouble1);
+ result = Math.toDegrees(sDouble1);
+ result = Math.toDegrees(sDouble1);
+ result = Math.toDegrees(sDouble1);
+ result = Math.toDegrees(sDouble1);
+ result = Math.toDegrees(sDouble1);
+ result = Math.toDegrees(sDouble1);
+ }
+ }
+
+ public void testMathToRadians() {
+ double result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = Math.toRadians(sDouble1);
+ result = Math.toRadians(sDouble1);
+ result = Math.toRadians(sDouble1);
+ result = Math.toRadians(sDouble1);
+ result = Math.toRadians(sDouble1);
+ result = Math.toRadians(sDouble1);
+ result = Math.toRadians(sDouble1);
+ result = Math.toRadians(sDouble1);
+ result = Math.toRadians(sDouble1);
+ result = Math.toRadians(sDouble1);
+ }
+ }
+}
diff --git a/tests/CoreTests/android/core/MonitorTest.java b/tests/CoreTests/android/core/MonitorTest.java
new file mode 100644
index 0000000..73c33db
--- /dev/null
+++ b/tests/CoreTests/android/core/MonitorTest.java
@@ -0,0 +1,469 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+import junit.framework.TestCase;
+import android.test.suitebuilder.annotation.MediumTest;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.test.suitebuilder.annotation.SmallTest;
+
+public class MonitorTest extends TestCase {
+
+ @MediumTest
+ public void testWaitArgumentsTest() throws Exception {
+ /* Try some valid arguments. These should all
+ * return very quickly.
+ */
+ try {
+ synchronized (this) {
+ /* millisecond version */
+ wait(1);
+ wait(10);
+
+ /* millisecond + nanosecond version */
+ wait(0, 1);
+ wait(0, 999999);
+ wait(1, 1);
+ wait(1, 999999);
+ }
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("good Object.wait() interrupted",
+ ex);
+ } catch (Exception ex) {
+ throw new RuntimeException("Unexpected exception when calling" +
+ "Object.wait() with good arguments", ex);
+ }
+
+ /* Try some invalid arguments.
+ */
+ boolean sawException = false;
+ try {
+ synchronized (this) {
+ wait(-1);
+ }
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("bad Object.wait() interrupted", ex);
+ } catch (IllegalArgumentException ex) {
+ sawException = true;
+ } catch (Exception ex) {
+ throw new RuntimeException("Unexpected exception when calling" +
+ "Object.wait() with bad arguments", ex);
+ }
+ if (!sawException) {
+ throw new RuntimeException("bad call to Object.wait() should " +
+ "have thrown IllegalArgumentException");
+ }
+
+ sawException = false;
+ try {
+ synchronized (this) {
+ wait(0, -1);
+ }
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("bad Object.wait() interrupted", ex);
+ } catch (IllegalArgumentException ex) {
+ sawException = true;
+ } catch (Exception ex) {
+ throw new RuntimeException("Unexpected exception when calling" +
+ "Object.wait() with bad arguments", ex);
+ }
+ if (!sawException) {
+ throw new RuntimeException("bad call to Object.wait() should " +
+ "have thrown IllegalArgumentException");
+ }
+
+ sawException = false;
+ try {
+ synchronized (this) {
+ /* The legal range of nanos is 0-999999. */
+ wait(0, 1000000);
+ }
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("bad Object.wait() interrupted", ex);
+ } catch (IllegalArgumentException ex) {
+ sawException = true;
+ } catch (Exception ex) {
+ throw new RuntimeException("Unexpected exception when calling" +
+ "Object.wait() with bad arguments", ex);
+ }
+ if (!sawException) {
+ throw new RuntimeException("bad call to Object.wait() should " +
+ "have thrown IllegalArgumentException");
+ }
+ }
+
+ private class Interrupter extends Thread {
+ Waiter waiter;
+
+ Interrupter(String name, Waiter waiter) {
+ super(name);
+ this.waiter = waiter;
+ }
+
+ public void run() {
+ try {
+ run_inner();
+ } catch (Throwable t) {
+ MonitorTest.errorException = t;
+ MonitorTest.testThread.interrupt();
+ }
+ }
+
+ void run_inner() {
+ waiter.spin = true;
+ // System.out.println("InterruptTest: starting waiter");
+ waiter.start();
+
+ try {
+ Thread.currentThread().sleep(500);
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("Test sleep interrupted.", ex);
+ }
+
+ /* Waiter is spinning, and its monitor should still be thin.
+ */
+ // System.out.println("Test interrupting waiter");
+ waiter.interrupt();
+ waiter.spin = false;
+
+ for (int i = 0; i < 3; i++) {
+ /* Wait for the waiter to start waiting.
+ */
+ synchronized (waiter.interrupterLock) {
+ try {
+ waiter.interrupterLock.wait();
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("Test wait interrupted.", ex);
+ }
+ }
+
+ /* Before interrupting, grab the waiter lock, which
+ * guarantees that the waiter is already sitting in wait().
+ */
+ synchronized (waiter) {
+ //System.out.println("Test interrupting waiter (" + i + ")");
+ waiter.interrupt();
+ }
+ }
+
+ // System.out.println("Test waiting for waiter to die.");
+ try {
+ waiter.join();
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("Test join interrupted.", ex);
+ }
+ // System.out.println("InterruptTest done.");
+ }
+ }
+
+ private class Waiter extends Thread {
+ Object interrupterLock = new Object();
+ Boolean spin = false;
+
+ Waiter(String name) {
+ super(name);
+ }
+
+ public void run() {
+ try {
+ run_inner();
+ } catch (Throwable t) {
+ MonitorTest.errorException = t;
+ MonitorTest.testThread.interrupt();
+ }
+ }
+
+ void run_inner() {
+ // System.out.println("Waiter spinning");
+ while (spin) {
+ // We're going to get interrupted while we spin.
+ }
+ if (interrupted()) {
+ // System.out.println("Waiter done spinning; interrupted.");
+ } else {
+ throw new RuntimeException("Thread not interrupted " +
+ "during spin");
+ }
+
+ synchronized (this) {
+ Boolean sawEx = false;
+
+ try {
+ synchronized (interrupterLock) {
+ interrupterLock.notify();
+ }
+ // System.out.println("Waiter calling wait()");
+ this.wait();
+ } catch (InterruptedException ex) {
+ sawEx = true;
+ // System.out.println("wait(): Waiter caught " + ex);
+ }
+ // System.out.println("wait() finished");
+
+ if (!sawEx) {
+ throw new RuntimeException("Thread not interrupted " +
+ "during wait()");
+ }
+ }
+ synchronized (this) {
+ Boolean sawEx = false;
+
+ try {
+ synchronized (interrupterLock) {
+ interrupterLock.notify();
+ }
+ // System.out.println("Waiter calling wait(1000)");
+ this.wait(1000);
+ } catch (InterruptedException ex) {
+ sawEx = true;
+ // System.out.println("wait(1000): Waiter caught " + ex);
+ }
+ // System.out.println("wait(1000) finished");
+
+ if (!sawEx) {
+ throw new RuntimeException("Thread not interrupted " +
+ "during wait(1000)");
+ }
+ }
+ synchronized (this) {
+ Boolean sawEx = false;
+
+ try {
+ synchronized (interrupterLock) {
+ interrupterLock.notify();
+ }
+ // System.out.println("Waiter calling wait(1000, 5000)");
+ this.wait(1000, 5000);
+ } catch (InterruptedException ex) {
+ sawEx = true;
+ // System.out.println("wait(1000, 5000): Waiter caught " + ex);
+ }
+ // System.out.println("wait(1000, 5000) finished");
+
+ if (!sawEx) {
+ throw new RuntimeException("Thread not interrupted " +
+ "during wait(1000, 5000)");
+ }
+ }
+
+ // System.out.println("Waiter returning");
+ }
+ }
+
+ private static Throwable errorException;
+ private static Thread testThread;
+
+ // TODO: Flaky test. Add back MediumTest annotation once fixed
+ public void testInterruptTest() throws Exception {
+
+
+ testThread = Thread.currentThread();
+ errorException = null;
+
+ Waiter waiter = new Waiter("InterruptTest Waiter");
+ Interrupter interrupter =
+ new Interrupter("InterruptTest Interrupter", waiter);
+ interrupter.start();
+
+ try {
+ interrupter.join();
+ waiter.join();
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("Test join interrupted.", ex);
+ }
+
+ if (errorException != null) {
+ throw new RuntimeException("InterruptTest failed",
+ errorException);
+ }
+
+
+
+
+ }
+
+ private static void deepWait(int depth, Object lock) {
+ synchronized (lock) {
+ if (depth > 0) {
+ deepWait(depth - 1, lock);
+ } else {
+ String threadName = Thread.currentThread().getName();
+ try {
+ // System.out.println(threadName + " waiting");
+ lock.wait();
+ // System.out.println(threadName + " done waiting");
+ } catch (InterruptedException ex) {
+ // System.out.println(threadName + " interrupted.");
+ }
+ }
+ }
+ }
+
+ private class Worker extends Thread {
+ Object lock;
+ int id;
+
+ Worker(int id, Object lock) {
+ super("Worker(" + id + ")");
+ this.id = id;
+ this.lock = lock;
+ }
+
+ public void run() {
+ int iterations = 0;
+
+ while (MonitorTest.running) {
+ MonitorTest.deepWait(id, lock);
+ iterations++;
+ }
+ // System.out.println(getName() + " done after " + iterations + " iterations.");
+ }
+ }
+
+ private static Object commonLock = new Object();
+ private static Boolean running = false;
+
+
+ @LargeTest
+ public void testNestedMonitors() throws Exception {
+ final int NUM_WORKERS = 5;
+
+ Worker w[] = new Worker[NUM_WORKERS];
+ int i;
+
+ for (i = 0; i < NUM_WORKERS; i++) {
+ w[i] = new Worker(i * 2 - 1, new Object());
+ }
+
+ running = true;
+
+ // System.out.println("NestedMonitors: starting workers");
+ for (i = 0; i < NUM_WORKERS; i++) {
+ w[i].start();
+ }
+
+ try {
+ Thread.currentThread().sleep(1000);
+ } catch (InterruptedException ex) {
+ // System.out.println("Test sleep interrupted.");
+ }
+
+ for (i = 0; i < 100; i++) {
+ for (int j = 0; j < NUM_WORKERS; j++) {
+ synchronized (w[j].lock) {
+ w[j].lock.notify();
+ }
+ }
+ }
+
+ // System.out.println("NesterMonitors: stopping workers");
+ running = false;
+ for (i = 0; i < NUM_WORKERS; i++) {
+ synchronized (w[i].lock) {
+ w[i].lock.notifyAll();
+ }
+ }
+ }
+
+ private static class CompareAndExchange extends Thread {
+ static Object toggleLock = null;
+ static int toggle = -1;
+ static Boolean running = false;
+
+ public void run() {
+ toggleLock = new Object();
+ toggle = -1;
+
+ Worker w1 = new Worker(0, 1);
+ Worker w2 = new Worker(2, 3);
+ Worker w3 = new Worker(4, 5);
+ Worker w4 = new Worker(6, 7);
+
+ running = true;
+
+ // System.out.println("CompareAndExchange: starting workers");
+
+ w1.start();
+ w2.start();
+ w3.start();
+ w4.start();
+
+ try {
+ this.sleep(10000);
+ } catch (InterruptedException ex) {
+ // System.out.println(getName() + " interrupted.");
+ }
+
+ // System.out.println("MonitorTest: stopping workers");
+ running = false;
+
+ toggleLock = null;
+ }
+
+ class Worker extends Thread {
+ int i1;
+ int i2;
+
+ Worker(int i1, int i2) {
+ super("Worker(" + i1 + ", " + i2 + ")");
+ this.i1 = i1;
+ this.i2 = i2;
+ }
+
+ public void run() {
+ int iterations = 0;
+
+ /* Latch this because run() may set the static field to
+ * null at some point.
+ */
+ Object toggleLock = CompareAndExchange.toggleLock;
+
+ // System.out.println(getName() + " running");
+ try {
+ while (CompareAndExchange.running) {
+ synchronized (toggleLock) {
+ int test;
+ int check;
+
+ if (CompareAndExchange.toggle == i1) {
+ this.sleep(5 + i2);
+ CompareAndExchange.toggle = test = i2;
+ } else {
+ this.sleep(5 + i1);
+ CompareAndExchange.toggle = test = i1;
+ }
+ if ((check = CompareAndExchange.toggle) != test) {
+// System.out.println("Worker(" + i1 + ", " +
+// i2 + ") " + "test " + test +
+// " != toggle " + check);
+ throw new RuntimeException(
+ "locked value changed");
+ }
+ }
+
+ iterations++;
+ }
+ } catch (InterruptedException ex) {
+ // System.out.println(getName() + " interrupted.");
+ }
+
+// System.out.println(getName() + " done after " +
+// iterations + " iterations.");
+ }
+ }
+ }
+}
diff --git a/tests/CoreTests/android/core/PerformanceTests.java b/tests/CoreTests/android/core/PerformanceTests.java
new file mode 100644
index 0000000..faf46e6
--- /dev/null
+++ b/tests/CoreTests/android/core/PerformanceTests.java
@@ -0,0 +1,1224 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+import org.apache.harmony.dalvik.NativeTestTarget;
+
+import android.test.PerformanceTestBase;
+import android.test.PerformanceTestCase;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import junit.framework.Assert;
+
+public class PerformanceTests {
+ public static String[] children() {
+ return new String[] {
+ //StringEquals2.class.getName(),
+ //StringEquals10.class.getName(),
+ //StringEquals20.class.getName(),
+ //StringEquals200.class.getName(),
+ //StringEquals200U.class.getName(),
+ //StringCompareTo10.class.getName(),
+ //StringCompareTo200.class.getName(),
+ StringLength.class.getName(),
+ StringCrawl.class.getName(),
+ Ackermann.class.getName(),
+ AddTest.class.getName(),
+// AddMemberVariableTest.class.getName(),
+ ArrayListIterator.class.getName(),
+ BoundsCheckTest.class.getName(),
+// EmptyClassBaseTest.class.getName(),
+ EmptyJniStaticMethod0.class.getName(),
+ EmptyJniStaticMethod6.class.getName(),
+ EmptyJniStaticMethod6L.class.getName(),
+ FibonacciFast.class.getName(),
+ FibonacciSlow.class.getName(),
+// LoopTests.class.getName(),
+// HashMapTest.class.getName(),
+// InterfaceTests.class.getName(),
+ LocalVariableAccess.class.getName(),
+ MemeberVariableAccess.class.getName(),
+ NestedLoop.class.getName(),
+// StringConcatenationTests.class.getName(),
+// ArrayListBase.class.getName(),
+ SynchronizedGetAndSetInt.class.getName(),
+
+ /* this will not work on JamVM -- lacks atomic ops */
+ AtomicGetAndSetInt.class.getName(),
+ };
+ }
+
+ public static class SizeTest {
+ private int mSize;
+
+ public SizeTest(int size) {
+ mSize = size;
+ }
+
+ public int size() {
+ return mSize;
+ }
+ }
+
+ public static class LocalVariableAccess extends PerformanceTestBase {
+ private static final int ITERATIONS = 100000;
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * 20);
+ return 0;
+ }
+
+ public void testRun() {
+ boolean variable = false;
+ boolean local = true;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ local = variable;
+ local = variable;
+ local = variable;
+ local = variable;
+ local = variable; // 5
+ local = variable;
+ local = variable;
+ local = variable;
+ local = variable;
+ local = variable; // 10
+ local = variable;
+ local = variable;
+ local = variable;
+ local = variable;
+ local = variable; // 15
+ local = variable;
+ local = variable;
+ local = variable;
+ local = variable;
+ local = variable; // 20
+ }
+ }
+ }
+
+ /* This test is intentionally misspelled. Please do not rename it. Thanks! */
+ public static class MemeberVariableAccess extends PerformanceTestBase {
+ private static final int ITERATIONS = 100000;
+
+ public volatile boolean mMember = false;
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * 20);
+ return 0;
+ }
+
+ public void testRun() {
+ boolean local = true;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ local = mMember;
+ local = mMember;
+ local = mMember;
+ local = mMember;
+ local = mMember; // 5
+ local = mMember;
+ local = mMember;
+ local = mMember;
+ local = mMember;
+ local = mMember; // 10
+ local = mMember;
+ local = mMember;
+ local = mMember;
+ local = mMember;
+ local = mMember; // 15
+ local = mMember;
+ local = mMember;
+ local = mMember;
+ local = mMember;
+ local = mMember; // 20
+ }
+ }
+ }
+
+ public static class ArrayListIterator extends PerformanceTestBase {
+ private static final int ITERATIONS = 10000;
+ private ArrayList mList;
+ private String[] mKeys;
+ private Iterator mIterator;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ mList = new ArrayList();
+ mKeys = new String[ITERATIONS];
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ mKeys[i] = Integer.toString(i, 16);
+ mList.add(mKeys[i]);
+ }
+ }
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ public void testRun() {
+ mIterator = mList.iterator();
+ while (mIterator.hasNext()) {
+ mIterator.next();
+ }
+ }
+ }
+
+ public static class Ackermann extends PerformanceTestBase {
+ public static final int ITERATIONS = 100;
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ public void testRun() {
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ ackermann(3, 13);
+ }
+ }
+
+ private int ackermann(int m, int n) {
+ if (m == 0)
+ return n + 1;
+ if (n == 0)
+ return ackermann(m - 1, 1);
+ return ackermann(m, n - 1);
+ }
+ }
+
+ public static class FibonacciSlow extends PerformanceTestBase {
+ public void setUp() throws Exception {
+ super.setUp();
+ Assert.assertEquals(0, fibonacci(0));
+ Assert.assertEquals(1, fibonacci(1));
+ Assert.assertEquals(1, fibonacci(2));
+ Assert.assertEquals(2, fibonacci(3));
+ Assert.assertEquals(6765, fibonacci(20));
+ }
+
+ public void tearDown() {
+ }
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ return 0;
+ }
+
+ public void testRun() {
+ fibonacci(20);
+ }
+
+ private long fibonacci(long n) {
+ if (n == 0)
+ return 0;
+ if (n == 1)
+ return 1;
+ return fibonacci(n - 2) + fibonacci(n - 1);
+ }
+ }
+
+ public static class FibonacciFast extends PerformanceTestBase {
+ public void setUp() throws Exception {
+ super.setUp();
+ Assert.assertEquals(0, fibonacci(0));
+ Assert.assertEquals(1, fibonacci(1));
+ Assert.assertEquals(1, fibonacci(2));
+ Assert.assertEquals(2, fibonacci(3));
+ Assert.assertEquals(6765, fibonacci(20));
+ }
+
+ public void tearDown() {
+ }
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ return 0;
+ }
+
+ public void testRun() {
+ fibonacci(5000);
+ }
+
+ private long fibonacci(long n) {
+ if (n == 0)
+ return 0;
+ if (n == 1)
+ return 1;
+
+ int x = 0;
+ int y = 1;
+ for (int i = 0; i < n - 1; i++) {
+ y = y + x;
+ x = y - x;
+ }
+
+ return y;
+ }
+ }
+
+ public static class HashMapTest extends PerformanceTestBase {
+ private static final int ITERATIONS = 10000;
+ private HashMap mMap;
+ private String[] mKeys;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ mMap = new HashMap();
+ mKeys = new String[ITERATIONS];
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ mKeys[i] = Integer.toString(i, 16);
+ mMap.put(mKeys[i], i);
+ }
+ }
+
+ public void tearDown() {
+ }
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ public void testHashMapContainsKey() {
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ mMap.containsKey(mKeys[i]);
+ }
+ }
+
+ public void testHashMapIterator() {
+ Iterator iterator;
+
+ iterator = mMap.entrySet().iterator();
+ while (iterator.hasNext()) {
+ iterator.next();
+ }
+ }
+
+ public void testHashMapPut() {
+ HashMap map = new HashMap();
+ String[] keys = mKeys;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ map.put(keys[i], i);
+ }
+ }
+ }
+
+ interface IA {
+ void funcA0();
+ void funcA1();
+ void funcA2();
+ void funcA3();
+ }
+ interface IAB extends IA {
+ void funcAB0();
+ void funcAB1();
+ void funcAB2();
+ void funcAB3();
+ }
+ interface IABC extends IAB {
+ void funcABC0();
+ void funcABC1();
+ void funcABC2();
+ void funcABC3();
+ }
+ interface IB {
+ void funcB0();
+ void funcB1();
+ void funcB2();
+ void funcB3();
+ }
+ interface IC {
+ void funcC0();
+ void funcC1();
+ void funcC2();
+ void funcC3();
+ }
+
+ static class Alphabet implements Cloneable, IB, IABC, IC, Runnable {
+ public void funcA0() {
+ }
+ public void funcA1() {
+ }
+ public void funcA2() {
+ }
+ public void funcA3() {
+ }
+ public void funcAB0() {
+ }
+ public void funcAB1() {
+ }
+ public void funcAB2() {
+ }
+ public void funcAB3() {
+ }
+ public void funcABC0() {
+ }
+ public void funcABC1() {
+ }
+ public void funcABC2() {
+ }
+ public void funcABC3() {
+ }
+ public void funcB0() {
+ }
+ public void funcB1() {
+ }
+ public void funcB2() {
+ }
+ public void funcB3() {
+ }
+ public void funcC0() {
+ }
+ public void funcC1() {
+ }
+ public void funcC2() {
+ }
+ public void funcC3() {
+ }
+ public void run() {
+ }
+ };
+
+ public static class InterfaceTests extends PerformanceTestBase {
+ private static final int ITERATIONS = 10000;
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * 10);
+ return 0;
+ }
+
+ /* call method directly */
+ public void testInterfaceCalls0() {
+ Alphabet alpha = new Alphabet();
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ alpha.funcABC1();
+ alpha.funcABC1();
+ alpha.funcABC1();
+ alpha.funcABC1();
+ alpha.funcABC1();
+ alpha.funcABC1();
+ alpha.funcABC1();
+ alpha.funcABC1();
+ alpha.funcABC1();
+ alpha.funcABC1();
+ }
+ }
+
+ /* call method through interface reference */
+ public void testInterfaceCalls1() {
+ Alphabet alpha = new Alphabet();
+ IABC iabc = alpha;
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ iabc.funcABC1();
+ iabc.funcABC1();
+ iabc.funcABC1();
+ iabc.funcABC1();
+ iabc.funcABC1();
+ iabc.funcABC1();
+ iabc.funcABC1();
+ iabc.funcABC1();
+ iabc.funcABC1();
+ iabc.funcABC1();
+ }
+ }
+
+ public void testInstanceOfTrivial() {
+ Alphabet alpha = new Alphabet();
+ IABC iabc = alpha;
+ boolean val;
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ val = iabc instanceof Alphabet;
+ val = iabc instanceof Alphabet;
+ val = iabc instanceof Alphabet;
+ val = iabc instanceof Alphabet;
+ val = iabc instanceof Alphabet;
+ val = iabc instanceof Alphabet;
+ val = iabc instanceof Alphabet;
+ val = iabc instanceof Alphabet;
+ val = iabc instanceof Alphabet;
+ val = iabc instanceof Alphabet;
+ }
+ }
+
+ public void testInstanceOfInterface() {
+ Alphabet alpha = new Alphabet();
+ IABC iabc = alpha;
+ boolean val;
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ val = iabc instanceof IA;
+ val = iabc instanceof IA;
+ val = iabc instanceof IA;
+ val = iabc instanceof IA;
+ val = iabc instanceof IA;
+ val = iabc instanceof IA;
+ val = iabc instanceof IA;
+ val = iabc instanceof IA;
+ val = iabc instanceof IA;
+ val = iabc instanceof IA;
+ }
+ }
+
+ public void testInstanceOfNot() {
+ Alphabet alpha = new Alphabet();
+ IABC iabc = alpha;
+ boolean val;
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ val = iabc instanceof EmptyInterface;
+ val = iabc instanceof EmptyInterface;
+ val = iabc instanceof EmptyInterface;
+ val = iabc instanceof EmptyInterface;
+ val = iabc instanceof EmptyInterface;
+ val = iabc instanceof EmptyInterface;
+ val = iabc instanceof EmptyInterface;
+ val = iabc instanceof EmptyInterface;
+ val = iabc instanceof EmptyInterface;
+ val = iabc instanceof EmptyInterface;
+ }
+ }
+ }
+
+ public static class NestedLoop extends PerformanceTestBase {
+ private static final int ITERATIONS = 10;
+ private static final int LOOPS = 5;
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * LOOPS);
+ return 0;
+ }
+
+ public void testRun() {
+ int x = 0;
+ for (int a = 0; a < ITERATIONS; a++) {
+ for (int b = 0; b < ITERATIONS; b++) {
+ for (int c = 0; c < ITERATIONS; c++) {
+ for (int d = 0; d < ITERATIONS; d++) {
+ for (int e = 0; e < ITERATIONS; e++) {
+ x++;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public static class StringConcatenationTests extends PerformanceTestBase {
+ private static final int ITERATIONS = 1000;
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ public void testStringConcatenation1() {
+ StringBuffer buffer = new StringBuffer();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ buffer.append("Hello World!\n");
+ }
+ buffer = null;
+ }
+
+ public void testStringConcatenation2() {
+ String string = "";
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ string += "Hello World!\n";
+ }
+ string = null;
+ }
+ }
+
+ public static class StringLength extends PerformanceTestBase {
+ private static final int ITERATIONS = 10000;
+ private static final String TEST_STRING = "This is the string we use for testing..."; // 40 chars
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * 10);
+ return 0;
+ }
+
+ public void testRun() {
+ String testStr = TEST_STRING;
+ int length;
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ length = testStr.length();
+ length = testStr.length();
+ length = testStr.length();
+ length = testStr.length();
+ length = testStr.length();
+ length = testStr.length();
+ length = testStr.length();
+ length = testStr.length();
+ length = testStr.length();
+ length = testStr.length();
+ }
+ }
+ }
+
+ public static class EmptyJniStaticMethod0 extends PerformanceTestBase {
+ private static final int ITERATIONS = 10000;
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * 10);
+ return 0;
+ }
+
+ public void testRun() {
+ int a, b, c, d, e, f;
+
+ a = b = c = d = e = f = 0;
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ }
+ }
+ }
+ public static class EmptyJniStaticMethod6 extends PerformanceTestBase {
+ private static final int ITERATIONS = 10000;
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * 10);
+ return 0;
+ }
+
+ public void testRun() {
+ int a, b, c, d, e, f;
+
+ a = b = c = d = e = f = 0;
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ }
+ }
+ }
+ public static class EmptyJniStaticMethod6L extends PerformanceTestBase {
+ private static final int ITERATIONS = 10000;
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * 10);
+ return 0;
+ }
+
+ public void testRun() {
+ String a = null;
+ String[] b = null;
+ int[][] c = null;
+ Object d = null;
+ Object[] e = null;
+ Object[][][][] f = null;
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f);
+ }
+ }
+ }
+
+ public static class StringCrawl extends PerformanceTestBase {
+ private static final int ITERATIONS = 10000;
+ private static final String TEST_STRING = "This is the string we use for testing..."; // 40 chars
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * TEST_STRING.length());
+ return 0;
+ }
+
+ public void testRun() {
+ String testStr = TEST_STRING;
+ char ch;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ /* this is the wrong way to walk through a string */
+ for (int j = 0; j < testStr.length(); j++) {
+ ch = testStr.charAt(j);
+ }
+ }
+ }
+ }
+
+ public static class AddTest extends PerformanceTestBase {
+ private static final int ITERATIONS = 10000;
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * 20);
+ return 0;
+ }
+
+ public void testRun() {
+ int j = 0;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ }
+ }
+ }
+
+ public static class AddMemberVariableTest extends PerformanceTestBase {
+ private static final int ITERATIONS = 10000;
+ private int j;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ j = 0;
+ }
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * 10);
+ return 0;
+ }
+
+ public void testAddMemberVariableTest() {
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ j++;
+ }
+ }
+
+ public void testAddMemberVariableInMethodTest() {
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ add();
+ add();
+ add();
+ add();
+ add();
+ add();
+ add();
+ add();
+ add();
+ add();
+ }
+ }
+
+ public void add() {
+ j++;
+ }
+ }
+
+ private interface EmptyInterface {
+ public void emptyVirtual();
+
+ }
+
+ private static class EmptyClass implements EmptyInterface {
+ public void emptyVirtual() {
+ }
+
+ public static void emptyStatic() {
+ }
+ }
+
+ public static class EmptyClassBaseTest extends PerformanceTestBase {
+ protected EmptyInterface mEmptyInterface;
+ protected EmptyClass mEmptyClass;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ mEmptyClass = new EmptyClass();
+ mEmptyInterface = mEmptyClass;
+ }
+ private static final int ITERATIONS = 10000;
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * 10);
+ return 0;
+ }
+
+ public void testEmptyVirtualMethod() {
+ //EmptyClass emtpyClass = mEmptyClass;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ mEmptyClass.emptyVirtual();
+ mEmptyClass.emptyVirtual();
+ mEmptyClass.emptyVirtual();
+ mEmptyClass.emptyVirtual();
+ mEmptyClass.emptyVirtual();
+ mEmptyClass.emptyVirtual();
+ mEmptyClass.emptyVirtual();
+ mEmptyClass.emptyVirtual();
+ mEmptyClass.emptyVirtual();
+ mEmptyClass.emptyVirtual();
+ }
+ }
+
+ public void testEmptyVirtualMethodTestInLocal() {
+ EmptyClass empty = mEmptyClass;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ empty.emptyVirtual();
+ empty.emptyVirtual();
+ empty.emptyVirtual();
+ empty.emptyVirtual();
+ empty.emptyVirtual();
+ empty.emptyVirtual();
+ empty.emptyVirtual();
+ empty.emptyVirtual();
+ empty.emptyVirtual();
+ empty.emptyVirtual();
+ }
+ }
+
+ public void testEmptyStaticMethod () {
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ EmptyClass.emptyStatic();
+ EmptyClass.emptyStatic();
+ EmptyClass.emptyStatic();
+ EmptyClass.emptyStatic();
+ EmptyClass.emptyStatic();
+ EmptyClass.emptyStatic();
+ EmptyClass.emptyStatic();
+ EmptyClass.emptyStatic();
+ EmptyClass.emptyStatic();
+ EmptyClass.emptyStatic();
+ }
+ }
+
+ public void testEmptyJniStaticMethod0() {
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ NativeTestTarget.emptyJniStaticMethod0();
+ }
+ }
+
+ public void testEmptyJniStaticMethod6() {
+ int a, b, c, d, e, f;
+
+ a = b = c = d = e = f = 0;
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f);
+ }
+ }
+
+ public void testEmptyInternalStaticMethod() {
+ /*
+ * The method called is a VM-internal method with no extra
+ * wrapping.
+ */
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ NativeTestTarget.emptyInternalStaticMethod();
+ NativeTestTarget.emptyInternalStaticMethod();
+ NativeTestTarget.emptyInternalStaticMethod();
+ NativeTestTarget.emptyInternalStaticMethod();
+ NativeTestTarget.emptyInternalStaticMethod();
+ NativeTestTarget.emptyInternalStaticMethod();
+ NativeTestTarget.emptyInternalStaticMethod();
+ NativeTestTarget.emptyInternalStaticMethod();
+ NativeTestTarget.emptyInternalStaticMethod();
+ NativeTestTarget.emptyInternalStaticMethod();
+ }
+ }
+
+ public void testEmptyInlineStaticMethod() {
+ /*
+ * The method called is a VM-internal method that gets
+ * specially "inlined" in a bytecode transformation.
+ */
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ NativeTestTarget.emptyInlineMethod();
+ NativeTestTarget.emptyInlineMethod();
+ NativeTestTarget.emptyInlineMethod();
+ NativeTestTarget.emptyInlineMethod();
+ NativeTestTarget.emptyInlineMethod();
+ NativeTestTarget.emptyInlineMethod();
+ NativeTestTarget.emptyInlineMethod();
+ NativeTestTarget.emptyInlineMethod();
+ NativeTestTarget.emptyInlineMethod();
+ NativeTestTarget.emptyInlineMethod();
+ }
+ }
+
+ public void testEmptyInterfaceMethodTest() {
+ EmptyInterface emptyInterface = mEmptyInterface;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ emptyInterface.emptyVirtual();
+ emptyInterface.emptyVirtual();
+ emptyInterface.emptyVirtual();
+ emptyInterface.emptyVirtual();
+ emptyInterface.emptyVirtual();
+ emptyInterface.emptyVirtual();
+ emptyInterface.emptyVirtual();
+ emptyInterface.emptyVirtual();
+ emptyInterface.emptyVirtual();
+ emptyInterface.emptyVirtual();
+ }
+ }
+ }
+
+ public static class LoopTests extends PerformanceTestBase {
+ private static final int ITERATIONS = 10000;
+ private SizeTest mSizeTest = new SizeTest(ITERATIONS);
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ public void testForLoopTest() {
+ int i = 0;
+ for (; i < 10000; i++) {
+ }
+ }
+
+ public void testWhileLoopTest() {
+ int i = 0;
+
+ while (i < 10000) {
+ i++;
+ }
+ }
+
+ public void testForLoopSizeCalledInside() {
+ for (int i = 0; i < mSizeTest.size(); i++) {
+ }
+ }
+
+ public void testForLoopSizeCalledOutside() {
+ final int size = mSizeTest.size();
+ for (int i = 0; i < size; i++) {
+ }
+ }
+ }
+
+ public static class BoundsCheckTest extends PerformanceTestBase {
+ private static final int ITERATIONS = 10000;
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * 10);
+ return 0;
+ }
+
+ public void testRun() {
+ int[] data = new int[1];
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ data[0] = i;
+ data[0] = i;
+ data[0] = i;
+ data[0] = i;
+ data[0] = i;
+ data[0] = i;
+ data[0] = i;
+ data[0] = i;
+ data[0] = i;
+ data[0] = i;
+ }
+ }
+ }
+
+ public static class ArrayListBase extends PerformanceTestBase {
+ public void setUp() throws Exception {
+ super.setUp();
+ mList = new ArrayList();
+ mList.add(0);
+ mList.add(1);
+ mList.add(2);
+ mList.add(3);
+ mList.add(4);
+ mList.add(5);
+ mList.add(6);
+ mList.add(7);
+ mList.add(8);
+ mList.add(9);
+ }
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(100);
+ return 0;
+ }
+
+ ArrayList<Integer> mList;
+
+ public void testForArrayList() {
+ int i = 0;
+ int res = 0;
+ for (; i < 100; i++) {
+ for (int j = 0; j < mList.size(); j++) {
+ res += mList.get(j);
+ }
+ }
+ }
+
+ public void testForLocalArrayList() {
+ int i = 0;
+ int res = 0;
+ for (; i < 100; i++) {
+ final List<Integer> list = mList;
+ final int N = list.size();
+ for (int j = 0; j < N; j++) {
+ res += list.get(j);
+ }
+ }
+ }
+
+ public void testForEachArrayList() {
+ int i = 0;
+ int res = 0;
+ for (; i < 100; i++) {
+ for (Integer v : mList) {
+ res += v;
+ }
+ }
+ }
+ }
+
+ public static class SynchronizedGetAndSetInt extends PerformanceTestBase {
+ private static final int ITERATIONS = 100000;
+
+ public int mMember = 0;
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ public void testRun() {
+ int result = 0;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ synchronized (this) {
+ result = mMember;
+ mMember = i;
+ }
+ }
+ }
+ }
+
+ public static class AtomicGetAndSetInt extends PerformanceTestBase {
+ private static final int ITERATIONS = 100000;
+
+ public AtomicInteger mMember = new AtomicInteger(0);
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ public void testRun() {
+ int result = 0;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = mMember.getAndSet(i);
+ }
+ }
+ }
+
+ public static abstract class StringEquals extends PerformanceTestBase {
+ private static final int ITERATIONS = 10000;
+
+ protected String mString1, mString2;
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * 10);
+ return 0;
+ }
+
+ public void testRun() {
+ String string1 = mString1;
+ String string2 = mString2;
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ string1.equals(string2);
+ string1.equals(string2);
+ string1.equals(string2);
+ string1.equals(string2);
+ string1.equals(string2);
+ string1.equals(string2);
+ string1.equals(string2);
+ string1.equals(string2);
+ string1.equals(string2);
+ string1.equals(string2);
+ }
+ }
+ }
+
+ public static class StringEquals2 extends StringEquals {
+ public void setUp() throws Exception {
+ mString1 = "01";
+ mString2 = "0x";
+ }
+ }
+ public static class StringEquals10 extends StringEquals {
+ public void setUp() throws Exception {
+ mString1 = "0123456789";
+ mString2 = "012345678x";
+ }
+ }
+ public static class StringEquals20 extends StringEquals {
+ public void setUp() throws Exception {
+ mString1 = "01234567890123456789";
+ mString2 = "0123456789012345678x";
+ }
+ }
+
+ public static class StringEquals200 extends StringEquals {
+ public void setUp() throws Exception {
+ mString1 = "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789";
+ mString2 = "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "012345678901234567890123456789012345678x";
+ }
+ }
+ public static class StringEquals200U extends StringEquals {
+ /* make one of the strings non-word aligned (bad memcmp case) */
+ public void setUp() throws Exception {
+ String tmpStr;
+ mString1 = "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789";
+ tmpStr = "z0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "012345678901234567890123456789012345678x";
+ mString2 = tmpStr.substring(1);
+ }
+ }
+
+ public static abstract class StringCompareTo extends PerformanceTestBase {
+ private static final int ITERATIONS = 10000;
+
+ protected String mString1, mString2;
+
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS * 10);
+ return 0;
+ }
+
+ public void testRun() {
+ String string1 = mString1;
+ String string2 = mString2;
+
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ string1.compareTo(string2);
+ string1.compareTo(string2);
+ string1.compareTo(string2);
+ string1.compareTo(string2);
+ string1.compareTo(string2);
+ string1.compareTo(string2);
+ string1.compareTo(string2);
+ string1.compareTo(string2);
+ string1.compareTo(string2);
+ string1.compareTo(string2);
+ }
+ }
+ }
+ public static class StringCompareTo10 extends StringCompareTo {
+ public void setUp() throws Exception {
+ mString1 = "0123456789";
+ mString2 = "012345678x";
+ }
+ }
+ public static class StringCompareTo200 extends StringCompareTo {
+ public void setUp() throws Exception {
+ mString1 = "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789";
+ mString2 = "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789"
+ + "012345678901234567890123456789012345678x";
+ }
+ }
+}
+
diff --git a/tests/CoreTests/android/core/SerializationTest.java b/tests/CoreTests/android/core/SerializationTest.java
new file mode 100644
index 0000000..9644d03
--- /dev/null
+++ b/tests/CoreTests/android/core/SerializationTest.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 android.core;
+
+import junit.framework.TestCase;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import android.test.suitebuilder.annotation.SmallTest;
+
+/**
+ * Tests serialization of user-level classes.
+ */
+public class SerializationTest extends TestCase {
+
+ static class MySerializable implements Serializable {}
+
+ @SmallTest
+ public void testSerialization() throws IOException, ClassNotFoundException {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ObjectOutputStream oout = new ObjectOutputStream(bout);
+ oout.writeObject(new MySerializable());
+ oout.close();
+
+ ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
+ Object o = new ObjectInputStream(bin).readObject();
+ assertTrue(o instanceof MySerializable);
+ }
+}
diff --git a/tests/CoreTests/android/core/StringTest.java b/tests/CoreTests/android/core/StringTest.java
new file mode 100644
index 0000000..128531c
--- /dev/null
+++ b/tests/CoreTests/android/core/StringTest.java
@@ -0,0 +1,951 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+import java.util.Locale;
+
+import android.test.PerformanceTestBase;
+import android.test.PerformanceTestCase;
+
+public class StringTest extends PerformanceTestBase {
+ public static final int ITERATIONS = 1000;
+ public static final String STATIC_STRING_01 = "Hello Android";
+ public static final String STATIC_STRING_02 =
+ "Remember, today is the tomorrow you worried about yesterday";
+ public static final char[] STATIC_CHAR_ARRAY =
+ {'N', 'A', 'N', 'D', 'R', 'O', 'I', 'D'};
+ public static StringBuffer STATIC_SBUF = new StringBuffer(STATIC_STRING_02);
+
+ @Override
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ /** Create an empty String object* */
+
+ public void testStringCreate() {
+ String rString;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = new String();
+ rString = new String();
+ rString = new String();
+ rString = new String();
+ rString = new String();
+ rString = new String();
+ rString = new String();
+ rString = new String();
+ rString = new String();
+ rString = new String();
+ }
+ }
+
+ /** Create an initialised String object* */
+
+ public void testStringCreate1() {
+ String rString, str = STATIC_STRING_01;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = new String(str);
+ rString = new String(str);
+ rString = new String(str);
+ rString = new String(str);
+ rString = new String(str);
+ rString = new String(str);
+ rString = new String(str);
+ rString = new String(str);
+ rString = new String(str);
+ rString = new String(str); // 10
+ }
+ }
+
+ /** equals() with for loop* */
+ public void testStringEquals() {
+ String mString = new String(STATIC_STRING_01);
+ String str = STATIC_STRING_01;
+ boolean result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = mString.equals(str);
+ result = mString.equals(str);
+ result = mString.equals(str);
+ result = mString.equals(str);
+ result = mString.equals(str);
+ result = mString.equals(str);
+ result = mString.equals(str);
+ result = mString.equals(str);
+ result = mString.equals(str);
+ result = mString.equals(str);
+ }
+ }
+
+ /**
+ * ContentEquals- Comparing the content of a String with that of a String
+ * Buffer*
+ */
+
+ public void testStringContentEquals() {
+ StringBuffer sBuf = new StringBuffer(STATIC_STRING_01);
+ String str = STATIC_STRING_01;
+ boolean result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = str.contentEquals(sBuf);
+ result = str.contentEquals(sBuf);
+ result = str.contentEquals(sBuf);
+ result = str.contentEquals(sBuf);
+ result = str.contentEquals(sBuf);
+ result = str.contentEquals(sBuf);
+ result = str.contentEquals(sBuf);
+ result = str.contentEquals(sBuf);
+ result = str.contentEquals(sBuf);
+ result = str.contentEquals(sBuf);
+ }
+ }
+
+ /** Compare string objects lexicographically using compareTo() with for loop* */
+
+ public void testStringCompareTo() {
+ String str1 = new String(STATIC_STRING_01);
+ String str2 = STATIC_STRING_01;
+ int result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = str1.compareTo(str2);
+ result = str1.compareTo(str2);
+ result = str1.compareTo(str2);
+ result = str1.compareTo(str2);
+ result = str1.compareTo(str2);
+ result = str1.compareTo(str2);
+ result = str1.compareTo(str2);
+ result = str1.compareTo(str2);
+ result = str1.compareTo(str2);
+ result = str1.compareTo(str2);
+ }
+
+ }
+
+ /** Compare string objects using compareToIgnorecase() with for loop* */
+
+ public void testStringCompareToIgnoreCase() {
+ String mString = new String(STATIC_STRING_01);
+ String str2 = STATIC_STRING_01;
+ int result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = mString.compareToIgnoreCase(str2);
+ result = mString.compareToIgnoreCase(str2);
+ result = mString.compareToIgnoreCase(str2);
+ result = mString.compareToIgnoreCase(str2);
+ result = mString.compareToIgnoreCase(str2);
+ result = mString.compareToIgnoreCase(str2);
+ result = mString.compareToIgnoreCase(str2);
+ result = mString.compareToIgnoreCase(str2);
+ result = mString.compareToIgnoreCase(str2);
+ result = mString.compareToIgnoreCase(str2);
+ }
+ }
+
+ /** startsWith * */
+
+ public void testStringstartsWith() {
+ boolean result;
+ String str1 = STATIC_STRING_02, str2 = "Rem";
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = str1.startsWith(str2);
+ result = str1.startsWith(str2);
+ result = str1.startsWith(str2);
+ result = str1.startsWith(str2);
+ result = str1.startsWith(str2);
+ result = str1.startsWith(str2);
+ result = str1.startsWith(str2);
+ result = str1.startsWith(str2);
+ result = str1.startsWith(str2);
+ result = str1.startsWith(str2);
+ }
+ }
+
+ /** startsWith(String seq, int begin) * */
+
+ public void testStringstartsWith1() {
+ String str1 = STATIC_STRING_02, str2 = "tom";
+ int pos = 10;
+ boolean result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = str1.startsWith(str2, pos);
+ result = str1.startsWith(str2, pos);
+ result = str1.startsWith(str2, pos);
+ result = str1.startsWith(str2, pos);
+ result = str1.startsWith(str2, pos);
+ result = str1.startsWith(str2, pos);
+ result = str1.startsWith(str2, pos);
+ result = str1.startsWith(str2, pos);
+ result = str1.startsWith(str2, pos);
+ result = str1.startsWith(str2, pos);
+ }
+ }
+
+ /** endsWith * */
+
+ public void testStringendsWith() {
+ String str = STATIC_STRING_02, str1 = "day";
+ boolean result;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = str.endsWith(str1);
+ result = str.endsWith(str1);
+ result = str.endsWith(str1);
+ result = str.endsWith(str1);
+ result = str.endsWith(str1);
+ result = str.endsWith(str1);
+ result = str.endsWith(str1);
+ result = str.endsWith(str1);
+ result = str.endsWith(str1);
+ result = str.endsWith(str1);
+ }
+ }
+
+ /**
+ * indexOf to determine whether a string contains a substring
+ */
+ public void testStringindexOf() {
+ boolean result;
+ String str = STATIC_STRING_02, str1 = "tomo";
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = str.indexOf(str1) > 0;
+ result = str.indexOf(str1) > 0;
+ result = str.indexOf(str1) > 0;
+ result = str.indexOf(str1) > 0;
+ result = str.indexOf(str1) > 0;
+ result = str.indexOf(str1) > 0;
+ result = str.indexOf(str1) > 0;
+ result = str.indexOf(str1) > 0;
+ result = str.indexOf(str1) > 0;
+ result = str.indexOf(str1) > 0;
+ }
+ }
+
+ /** indexOf()* */
+
+ public void testStringindexOf1() {
+ int index;
+ String str = STATIC_STRING_02;
+ char c = 't';
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = str.indexOf(c);
+ index = str.indexOf(c);
+ index = str.indexOf(c);
+ index = str.indexOf(c);
+ index = str.indexOf(c);
+ index = str.indexOf(c);
+ index = str.indexOf(c);
+ index = str.indexOf(c);
+ index = str.indexOf(c);
+ index = str.indexOf(c);
+ }
+
+ }
+
+ /** indexOf(char c, int start)* */
+ public void testStringindexOf2() {
+ int index, pos = 12;
+ String str = STATIC_STRING_02, str1 = "tom";
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = str.indexOf(str1, pos);
+ index = str.indexOf(str1, pos);
+ index = str.indexOf(str1, pos);
+ index = str.indexOf(str1, pos);
+ index = str.indexOf(str1, pos);
+ index = str.indexOf(str1, pos);
+ index = str.indexOf(str1, pos);
+ index = str.indexOf(str1, pos);
+ index = str.indexOf(str1, pos);
+ index = str.indexOf(str1, pos);
+ }
+ }
+
+ /** lastIndexOf()* */
+
+ public void testStringlastIndexOf() {
+ int index;
+ char c = 't';
+ String str = STATIC_STRING_02;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = str.lastIndexOf(c);
+ index = str.lastIndexOf(c);
+ index = str.lastIndexOf(c);
+ index = str.lastIndexOf(c);
+ index = str.lastIndexOf(c);
+ index = str.lastIndexOf(c);
+ index = str.lastIndexOf(c);
+ index = str.lastIndexOf(c);
+ index = str.lastIndexOf(c);
+ index = str.lastIndexOf(c);
+ }
+ }
+
+ /** lastIndexOf()* */
+
+ public void testStringlastIndexOf1() {
+ int index, pos = 36;
+ String str = STATIC_STRING_02, str1 = "tom";
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = str.lastIndexOf(str1, pos);
+ index = str.lastIndexOf(str1, pos);
+ index = str.lastIndexOf(str1, pos);
+ index = str.lastIndexOf(str1, pos);
+ index = str.lastIndexOf(str1, pos);
+ index = str.lastIndexOf(str1, pos);
+ index = str.lastIndexOf(str1, pos);
+ index = str.lastIndexOf(str1, pos);
+ index = str.lastIndexOf(str1, pos);
+ index = str.lastIndexOf(str1, pos);
+ }
+ }
+
+ /**
+ * contains() to determine whether a string contains a substring
+ */
+
+ public void testStringcontains() {
+ boolean result;
+ String str = STATIC_STRING_02, str1 = "tomo";
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ result = str.contains(str1);
+ result = str.contains(str1);
+ result = str.contains(str1);
+ result = str.contains(str1);
+ result = str.contains(str1);
+ result = str.contains(str1);
+ result = str.contains(str1);
+ result = str.contains(str1);
+ result = str.contains(str1);
+ result = str.contains(str1);
+ }
+ }
+
+ /** substring(int start) */
+
+ public void testStringsubstring() {
+ String rString;
+ String str = STATIC_STRING_02;
+ int index = 10;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = str.substring(index);
+ rString = str.substring(index);
+ rString = str.substring(index);
+ rString = str.substring(index);
+ rString = str.substring(index);
+ rString = str.substring(index);
+ rString = str.substring(index);
+ rString = str.substring(index);
+ rString = str.substring(index);
+ rString = str.substring(index);
+ }
+ }
+
+ /** substring(int start, int end) in a for loop* */
+
+ public void testStringsubstring1() {
+ String rString;
+ String str = STATIC_STRING_02;
+ int start = 10, end = 48;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = str.substring(start, end);
+ rString = str.substring(start, end);
+ rString = str.substring(start, end);
+ rString = str.substring(start, end);
+ rString = str.substring(start, end);
+ rString = str.substring(start, end);
+ rString = str.substring(start, end);
+ rString = str.substring(start, end);
+ rString = str.substring(start, end);
+ rString = str.substring(start, end);
+ }
+ }
+
+ /**
+ * valueOf(char[] cArray) String representation of a character array
+ */
+ public void testStringvalueOf() {
+ String rString;
+ char[] cArray = STATIC_CHAR_ARRAY;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = String.valueOf(cArray);
+ rString = String.valueOf(cArray);
+ rString = String.valueOf(cArray);
+ rString = String.valueOf(cArray);
+ rString = String.valueOf(cArray);
+ rString = String.valueOf(cArray);
+ rString = String.valueOf(cArray);
+ rString = String.valueOf(cArray);
+ rString = String.valueOf(cArray);
+ rString = String.valueOf(cArray);
+ }
+ }
+
+ /** valueOf(char[] cArray, int offset, int count)* */
+
+ public void testStringvalueOf1() {
+ String rString;
+ char[] cArray = STATIC_CHAR_ARRAY;
+ int start = 1, end = 7;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = String.valueOf(cArray, start, end);
+ rString = String.valueOf(cArray, start, end);
+ rString = String.valueOf(cArray, start, end);
+ rString = String.valueOf(cArray, start, end);
+ rString = String.valueOf(cArray, start, end);
+ rString = String.valueOf(cArray, start, end);
+ rString = String.valueOf(cArray, start, end);
+ rString = String.valueOf(cArray, start, end);
+ rString = String.valueOf(cArray, start, end);
+ rString = String.valueOf(cArray, start, end);
+ }
+ }
+
+ /** Convert a string to a char Array* */
+
+ public void testStringtoCharArray() {
+ char[] cArray;
+ String str = STATIC_STRING_02;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ cArray = str.toCharArray();
+ cArray = str.toCharArray();
+ cArray = str.toCharArray();
+ cArray = str.toCharArray();
+ cArray = str.toCharArray();
+ cArray = str.toCharArray();
+ cArray = str.toCharArray();
+ cArray = str.toCharArray();
+ cArray = str.toCharArray();
+ cArray = str.toCharArray();
+ }
+ }
+
+ /** length()* */
+
+ public void testStringlength() {
+ int len;
+ String str = STATIC_STRING_02;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ len = str.length();
+ len = str.length();
+ len = str.length();
+ len = str.length();
+ len = str.length();
+ len = str.length();
+ len = str.length();
+ len = str.length();
+ len = str.length();
+ len = str.length();
+ }
+ }
+
+ /** hashcode()* */
+
+ public void testStringhashCode() {
+ int index;
+ String str = STATIC_STRING_02;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = str.hashCode();
+ index = str.hashCode();
+ index = str.hashCode();
+ index = str.hashCode();
+ index = str.hashCode();
+ index = str.hashCode();
+ index = str.hashCode();
+ index = str.hashCode();
+ index = str.hashCode();
+ index = str.hashCode();
+ }
+ }
+
+ /** replace()* */
+
+ public void testStringreplace() {
+ String rString;
+ String str = STATIC_STRING_02;
+ char c1 = ' ', c2 = ' ';
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = str.replace(c1, c2);
+ rString = str.replace(c1, c2);
+ rString = str.replace(c1, c2);
+ rString = str.replace(c1, c2);
+ rString = str.replace(c1, c2);
+ rString = str.replace(c1, c2);
+ rString = str.replace(c1, c2);
+ rString = str.replace(c1, c2);
+ rString = str.replace(c1, c2);
+ rString = str.replace(c1, c2);
+ }
+ }
+
+ public void testStringreplaceAll() {
+ String rString;
+ String str = STATIC_STRING_02, str1 = " ", str2 = "/";
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = str.replaceAll(str1, str2);
+ rString = str.replaceAll(str1, str2);
+ rString = str.replaceAll(str1, str2);
+ rString = str.replaceAll(str1, str2);
+ rString = str.replaceAll(str1, str2);
+ rString = str.replaceAll(str1, str2);
+ rString = str.replaceAll(str1, str2);
+ rString = str.replaceAll(str1, str2);
+ rString = str.replaceAll(str1, str2);
+ rString = str.replaceAll(str1, str2);
+ }
+ }
+
+ /** Convert a StringBuffer to a String* */
+
+ public void testStringtoString() {
+ StringBuffer sBuf = new StringBuffer(STATIC_STRING_02);
+
+ String rString;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = sBuf.toString();
+ rString = sBuf.toString();
+ rString = sBuf.toString();
+ rString = sBuf.toString();
+ rString = sBuf.toString();
+ rString = sBuf.toString();
+ rString = sBuf.toString();
+ rString = sBuf.toString();
+ rString = sBuf.toString();
+ rString = sBuf.toString();
+ }
+ }
+
+ /** Split a string into an array of strings* */
+
+ public void testStringsplit() {
+ String[] strings;
+ String str1 = STATIC_STRING_02, str = " ";
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ strings = str1.split(str);
+ strings = str1.split(str);
+ strings = str1.split(str);
+ strings = str1.split(str);
+ strings = str1.split(str);
+ strings = str1.split(str);
+ strings = str1.split(str);
+ strings = str1.split(str);
+ strings = str1.split(str);
+ strings = str1.split(str);
+
+ }
+ }
+
+ /** Split a string into an array of strings* */
+
+ public void testStringsplit1() {
+ String str = STATIC_STRING_02, str1 = " ";
+ String[] strings;
+ int pos = 8;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ strings = str.split(str1, pos);
+ strings = str.split(str1, pos);
+ strings = str.split(str1, pos);
+ strings = str.split(str1, pos);
+ strings = str.split(str1, pos);
+ strings = str.split(str1, pos);
+ strings = str.split(str1, pos);
+ strings = str.split(str1, pos);
+ strings = str.split(str1, pos);
+ strings = str.split(str1, pos);
+ }
+ }
+
+ public void testStringgetBytes() {
+ byte[] bytes;
+ String str = STATIC_STRING_02;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ bytes = str.getBytes();
+ bytes = str.getBytes();
+ bytes = str.getBytes();
+ bytes = str.getBytes();
+ bytes = str.getBytes();
+ bytes = str.getBytes();
+ bytes = str.getBytes();
+ bytes = str.getBytes();
+ bytes = str.getBytes();
+ bytes = str.getBytes();
+ }
+ }
+
+ /** copyValueOf(char[] data) * */
+
+ public void testStringcopyValueOf() {
+ String rString;
+ char[] cArray = STATIC_CHAR_ARRAY;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = String.copyValueOf(cArray);
+ rString = String.copyValueOf(cArray);
+ rString = String.copyValueOf(cArray);
+ rString = String.copyValueOf(cArray);
+ rString = String.copyValueOf(cArray);
+ rString = String.copyValueOf(cArray);
+ rString = String.copyValueOf(cArray);
+ rString = String.copyValueOf(cArray);
+ rString = String.copyValueOf(cArray);
+ rString = String.copyValueOf(cArray);
+ }
+ }
+
+ /** copyValueOf(char[] data, int index, int count)* */
+
+ public void testStringcopyValueOf1() {
+ String rString;
+ int start = 1, end = 7;
+ char[] cArray = STATIC_CHAR_ARRAY;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = String.copyValueOf(cArray, start, end);
+ rString = String.copyValueOf(cArray, start, end);
+ rString = String.copyValueOf(cArray, start, end);
+ rString = String.copyValueOf(cArray, start, end);
+ rString = String.copyValueOf(cArray, start, end);
+ rString = String.copyValueOf(cArray, start, end);
+ rString = String.copyValueOf(cArray, start, end);
+ rString = String.copyValueOf(cArray, start, end);
+ rString = String.copyValueOf(cArray, start, end);
+ rString = String.copyValueOf(cArray, start, end);
+ }
+ }
+
+ /** trim()* */
+
+ public void testStringtrim() {
+ String mString =
+ new String(
+ " HELLO ANDROID ");
+ String rString;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = mString.trim();
+ rString = mString.trim();
+ rString = mString.trim();
+ rString = mString.trim();
+ rString = mString.trim();
+ rString = mString.trim();
+ rString = mString.trim();
+ rString = mString.trim();
+ rString = mString.trim();
+ rString = mString.trim();
+ }
+ }
+
+ /** getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)* */
+
+ public void testStringgetChars() {
+ char[] cArray = STATIC_CHAR_ARRAY;
+ String str = STATIC_STRING_01;
+ int value1 = 7, value2 = 12, value3 = 1;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ str.getChars(value1, value2, cArray, value3);
+ str.getChars(value1, value2, cArray, value3);
+ str.getChars(value1, value2, cArray, value3);
+ str.getChars(value1, value2, cArray, value3);
+ str.getChars(value1, value2, cArray, value3);
+ str.getChars(value1, value2, cArray, value3);
+ str.getChars(value1, value2, cArray, value3);
+ str.getChars(value1, value2, cArray, value3);
+ str.getChars(value1, value2, cArray, value3);
+ str.getChars(value1, value2, cArray, value3);
+ }
+ }
+
+ /** toUpperCase()* */
+
+ public void testStringtoUpperCase() {
+ String rString, str = STATIC_STRING_02;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = str.toUpperCase();
+ rString = str.toUpperCase();
+ rString = str.toUpperCase();
+ rString = str.toUpperCase();
+ rString = str.toUpperCase();
+ rString = str.toUpperCase();
+ rString = str.toUpperCase();
+ rString = str.toUpperCase();
+ rString = str.toUpperCase();
+ rString = str.toUpperCase();
+ }
+ }
+
+ /** toUpperCase() with locale* */
+
+ public void testStringtoUpperCase1() {
+ Locale locale = new Locale("tr");
+ String str = STATIC_STRING_02;
+ String rString;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = str.toUpperCase(locale);
+ rString = str.toUpperCase(locale);
+ rString = str.toUpperCase(locale);
+ rString = str.toUpperCase(locale);
+ rString = str.toUpperCase(locale);
+ rString = str.toUpperCase(locale);
+ rString = str.toUpperCase(locale);
+ rString = str.toUpperCase(locale);
+ rString = str.toUpperCase(locale);
+ rString = str.toUpperCase(locale);
+ }
+ }
+
+ /** toLowerCase* */
+
+ public void StringtoLowerCase() {
+ String rString, str = STATIC_STRING_02;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = str.toLowerCase();
+ rString = str.toLowerCase();
+ rString = str.toLowerCase();
+ rString = str.toLowerCase();
+ rString = str.toLowerCase();
+ rString = str.toLowerCase();
+ rString = str.toLowerCase();
+ rString = str.toLowerCase();
+ rString = str.toLowerCase();
+ rString = str.toLowerCase();
+ }
+ }
+
+ /** toLowerCase with locale* */
+
+ public void testStringtoLowerCase1() {
+ Locale locale = new Locale("tr");
+ String rString, str = STATIC_STRING_02;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = str.toLowerCase(locale);
+ rString = str.toLowerCase(locale);
+ rString = str.toLowerCase(locale);
+ rString = str.toLowerCase(locale);
+ rString = str.toLowerCase(locale);
+ rString = str.toLowerCase(locale);
+ rString = str.toLowerCase(locale);
+ rString = str.toLowerCase(locale);
+ rString = str.toLowerCase(locale);
+ rString = str.toLowerCase(locale);
+ }
+ }
+
+ /** charAt()* */
+
+ public void testStringcharAt() {
+ String str = STATIC_STRING_02;
+ int index, pos = 21;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = str.charAt(pos);
+ index = str.charAt(pos);
+ index = str.charAt(pos);
+ index = str.charAt(pos);
+ index = str.charAt(pos);
+ index = str.charAt(pos);
+ index = str.charAt(pos);
+ index = str.charAt(pos);
+ index = str.charAt(pos);
+ index = str.charAt(pos);
+ }
+ }
+
+ public void testStringConcat() {
+ String mString, str1 = STATIC_STRING_01, str2 = STATIC_STRING_02;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ mString = str1.concat(str2);
+ mString = str1.concat(str2);
+ mString = str1.concat(str2);
+ mString = str1.concat(str2);
+ mString = str1.concat(str2);
+ mString = str1.concat(str2);
+ mString = str1.concat(str2);
+ mString = str1.concat(str2);
+ mString = str1.concat(str2);
+ mString = str1.concat(str2);
+ }
+ }
+
+ public void testStringBufferAppend() {
+ StringBuffer sBuf = new StringBuffer(" ");
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ sBuf.append(i);
+ sBuf.append(i);
+ sBuf.append(i);
+ sBuf.append(i);
+ sBuf.append(i);
+ sBuf.append(i);
+ sBuf.append(i);
+ sBuf.append(i);
+ sBuf.append(i);
+ sBuf.append(i);
+ }
+ }
+
+ public void testStringBufferInsert() {
+ StringBuffer sBuf = new StringBuffer(" ");
+ int index = sBuf.length();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ sBuf.insert(index, i);
+ sBuf.insert(index, i);
+ sBuf.insert(index, i);
+ sBuf.insert(index, i);
+ sBuf.insert(index, i);
+ sBuf.insert(index, i);
+ sBuf.insert(index, i);
+ sBuf.insert(index, i);
+ sBuf.insert(index, i);
+ sBuf.insert(index, i);
+ }
+ }
+
+ public void testStringBufferReverse() {
+ StringBuffer sBuf = STATIC_SBUF;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ sBuf.reverse();
+ sBuf.reverse();
+ sBuf.reverse();
+ sBuf.reverse();
+ sBuf.reverse();
+ sBuf.reverse();
+ sBuf.reverse();
+ sBuf.reverse();
+ sBuf.reverse();
+ sBuf.reverse();
+ }
+ }
+
+ public void testStringBufferSubstring() {
+ StringBuffer sBuf = STATIC_SBUF;
+ String rString;
+ int index = 0;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = sBuf.substring(index);
+ rString = sBuf.substring(index);
+ rString = sBuf.substring(index);
+ rString = sBuf.substring(index);
+ rString = sBuf.substring(index);
+ rString = sBuf.substring(index);
+ rString = sBuf.substring(index);
+ rString = sBuf.substring(index);
+ rString = sBuf.substring(index);
+ rString = sBuf.substring(index);
+ }
+ }
+
+ public void testStringBufferSubstring1() {
+ StringBuffer sBuf = STATIC_SBUF;
+ String rString;
+ int start = 5, end = 25;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ rString = sBuf.substring(start, end);
+ rString = sBuf.substring(start, end);
+ rString = sBuf.substring(start, end);
+ rString = sBuf.substring(start, end);
+ rString = sBuf.substring(start, end);
+ rString = sBuf.substring(start, end);
+ rString = sBuf.substring(start, end);
+ rString = sBuf.substring(start, end);
+ rString = sBuf.substring(start, end);
+ rString = sBuf.substring(start, end);
+ }
+ }
+
+ public void testStringBufferReplace() {
+ StringBuffer sBuf = STATIC_SBUF;
+ int start = 3, end = 6;
+ String str = "ind";
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ sBuf.replace(start, end, str);
+ sBuf.replace(start, end, str);
+ sBuf.replace(start, end, str);
+ sBuf.replace(start, end, str);
+ sBuf.replace(start, end, str);
+ sBuf.replace(start, end, str);
+ sBuf.replace(start, end, str);
+ sBuf.replace(start, end, str);
+ sBuf.replace(start, end, str);
+ sBuf.replace(start, end, str);
+ }
+ }
+
+ public void testStringBufferIndexOf() {
+ StringBuffer sBuf = STATIC_SBUF;
+ String str = "t";
+ int index;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = sBuf.indexOf(str);
+ index = sBuf.indexOf(str);
+ index = sBuf.indexOf(str);
+ index = sBuf.indexOf(str);
+ index = sBuf.indexOf(str);
+ index = sBuf.indexOf(str);
+ index = sBuf.indexOf(str);
+ index = sBuf.indexOf(str);
+ index = sBuf.indexOf(str);
+ index = sBuf.indexOf(str);
+ }
+ }
+
+ public void testStringBufferIndexOf1() {
+ StringBuffer sBuf = STATIC_SBUF;
+ String str = "tom";
+ int index, pos = 12;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = sBuf.indexOf(str, pos);
+ index = sBuf.indexOf(str, pos);
+ index = sBuf.indexOf(str, pos);
+ index = sBuf.indexOf(str, pos);
+ index = sBuf.indexOf(str, pos);
+ index = sBuf.indexOf(str, pos);
+ index = sBuf.indexOf(str, pos);
+ index = sBuf.indexOf(str, pos);
+ index = sBuf.indexOf(str, pos);
+ index = sBuf.indexOf(str, pos);
+ }
+
+ }
+
+ public void testStringBufferLastIndexOf() {
+ StringBuffer sBuf = STATIC_SBUF;
+ String str = "t";
+ int index;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = sBuf.lastIndexOf(str);
+ index = sBuf.lastIndexOf(str);
+ index = sBuf.lastIndexOf(str);
+ index = sBuf.lastIndexOf(str);
+ index = sBuf.lastIndexOf(str);
+ index = sBuf.lastIndexOf(str);
+ index = sBuf.lastIndexOf(str);
+ index = sBuf.lastIndexOf(str);
+ index = sBuf.lastIndexOf(str);
+ index = sBuf.lastIndexOf(str);
+ }
+ }
+
+ public void testStringBufferLastIndexOf1() {
+ StringBuffer sBuf = STATIC_SBUF;
+ int index, pos = 36;
+ String str = "tom";
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = sBuf.lastIndexOf(str, pos);
+ index = sBuf.lastIndexOf(str, pos);
+ index = sBuf.lastIndexOf(str, pos);
+ index = sBuf.lastIndexOf(str, pos);
+ index = sBuf.lastIndexOf(str, pos);
+ index = sBuf.lastIndexOf(str, pos);
+ index = sBuf.lastIndexOf(str, pos);
+ index = sBuf.lastIndexOf(str, pos);
+ index = sBuf.lastIndexOf(str, pos);
+ index = sBuf.lastIndexOf(str, pos);
+ }
+ }
+}
diff --git a/tests/CoreTests/android/core/TestHttpClient.java b/tests/CoreTests/android/core/TestHttpClient.java
new file mode 100644
index 0000000..c657f1e
--- /dev/null
+++ b/tests/CoreTests/android/core/TestHttpClient.java
@@ -0,0 +1,116 @@
+/*
+ * $HeadURL: http://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/tags/4.0-alpha6/module-main/src/test/java/org/apache/http/mockup/TestHttpClient.java $
+ * $Revision: 576077 $
+ * $Date: 2007-09-16 04:50:22 -0700 (Sun, 16 Sep 2007) $
+ *
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package android.core;
+
+import java.io.IOException;
+
+import org.apache.http.ConnectionReuseStrategy;
+import org.apache.http.HttpClientConnection;
+import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.params.DefaultedHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.protocol.BasicHttpProcessor;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpRequestExecutor;
+import org.apache.http.protocol.RequestConnControl;
+import org.apache.http.protocol.RequestContent;
+import org.apache.http.protocol.RequestExpectContinue;
+import org.apache.http.protocol.RequestTargetHost;
+import org.apache.http.protocol.RequestUserAgent;
+
+public class TestHttpClient {
+
+ private final HttpParams params;
+ private final BasicHttpProcessor httpproc;
+ private final HttpRequestExecutor httpexecutor;
+ private final ConnectionReuseStrategy connStrategy;
+ private final HttpContext context;
+
+ public TestHttpClient() {
+ super();
+ this.params = new BasicHttpParams();
+ this.params
+ .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
+ .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
+ .setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1)
+ .setParameter(CoreProtocolPNames.USER_AGENT, "TEST-CLIENT/1.1");
+
+ this.httpproc = new BasicHttpProcessor();
+ // Required protocol interceptors
+ this.httpproc.addInterceptor(new RequestContent());
+ this.httpproc.addInterceptor(new RequestTargetHost());
+ // Recommended protocol interceptors
+ this.httpproc.addInterceptor(new RequestConnControl());
+ this.httpproc.addInterceptor(new RequestUserAgent());
+ this.httpproc.addInterceptor(new RequestExpectContinue());
+
+ this.httpexecutor = new HttpRequestExecutor();
+ this.connStrategy = new DefaultConnectionReuseStrategy();
+ this.context = new BasicHttpContext(null);
+ }
+
+ public HttpParams getParams() {
+ return this.params;
+ }
+
+ public HttpResponse execute(
+ final HttpRequest request,
+ final HttpHost targetHost,
+ final HttpClientConnection conn) throws HttpException, IOException {
+ this.context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
+ this.context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, targetHost);
+ this.context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+ request.setParams(
+ new DefaultedHttpParams(request.getParams(), this.params));
+ this.httpexecutor.preProcess(request, this.httpproc, this.context);
+ HttpResponse response = this.httpexecutor.execute(request, conn, this.context);
+ response.setParams(
+ new DefaultedHttpParams(response.getParams(), this.params));
+ this.httpexecutor.postProcess(response, this.httpproc, this.context);
+ return response;
+ }
+
+ public boolean keepAlive(final HttpResponse response) {
+ return this.connStrategy.keepAlive(response, this.context);
+ }
+
+}
diff --git a/tests/CoreTests/android/core/TreeMapPerformanceTest.java b/tests/CoreTests/android/core/TreeMapPerformanceTest.java
new file mode 100644
index 0000000..3a210f4
--- /dev/null
+++ b/tests/CoreTests/android/core/TreeMapPerformanceTest.java
@@ -0,0 +1,281 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+import android.test.PerformanceTestBase;
+import android.test.PerformanceTestCase;
+
+import java.util.Collection;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * Implements basic performance test functionality for java.util.TreeMap
+ */
+
+public class TreeMapPerformanceTest extends PerformanceTestBase {
+ public static final int ITERATIONS = 1000;
+ public static TreeMap<String, Integer> sMap;
+ public static String[] sKeys;
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ sMap = new TreeMap();
+ sKeys = new String[ITERATIONS];
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ sKeys[i] = Integer.toString(i, 16);
+ sMap.put(sKeys[i], i);
+ }
+ }
+
+ @Override
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testTreeMapPut() {
+ TreeMap map = new TreeMap();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ map.put(i, i);
+ map.put(i, i);
+ map.put(i, i);
+ map.put(i, i);
+ map.put(i, i);
+ map.put(i, i);
+ map.put(i, i);
+ map.put(i, i);
+ map.put(i, i);
+ map.put(i, i);
+ }
+ }
+
+ public void testTreeMapGet() {
+ int value;
+ TreeMap<String, Integer> map = sMap;
+ String[] keys = sKeys;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ value = map.get(keys[i]);
+ value = map.get(keys[i]);
+ value = map.get(keys[i]);
+ value = map.get(keys[i]);
+ value = map.get(keys[i]);
+ value = map.get(keys[i]);
+ value = map.get(keys[i]);
+ value = map.get(keys[i]);
+ value = map.get(keys[i]);
+ value = map.get(keys[i]);
+ }
+ }
+
+ public void testTreeMapFirstKey() {
+ String key;
+ TreeMap<String, Integer> map = sMap;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ key = map.firstKey();
+ key = map.firstKey();
+ key = map.firstKey();
+ key = map.firstKey();
+ key = map.firstKey();
+ key = map.firstKey();
+ key = map.firstKey();
+ key = map.firstKey();
+ key = map.firstKey();
+ key = map.firstKey();
+ }
+ }
+
+ public void testTreeMapKeySet() {
+ Set keyset;
+ TreeMap<String, Integer> map = sMap;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ keyset = map.keySet();
+ keyset = map.keySet();
+ keyset = map.keySet();
+ keyset = map.keySet();
+ keyset = map.keySet();
+ keyset = map.keySet();
+ keyset = map.keySet();
+ keyset = map.keySet();
+ keyset = map.keySet();
+ keyset = map.keySet();
+ }
+ }
+
+ public void testTreeMapEntrySet() {
+ Set keyset;
+ TreeMap<String, Integer> map = sMap;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ keyset = map.entrySet();
+ keyset = map.entrySet();
+ keyset = map.entrySet();
+ keyset = map.entrySet();
+ keyset = map.entrySet();
+ keyset = map.entrySet();
+ keyset = map.entrySet();
+ keyset = map.entrySet();
+ keyset = map.entrySet();
+ keyset = map.entrySet();
+ }
+ }
+
+ public void testTreeMapValues() {
+ Collection collection;
+ TreeMap<String, Integer> map = sMap;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ collection = map.values();
+ collection = map.values();
+ collection = map.values();
+ collection = map.values();
+ collection = map.values();
+ collection = map.values();
+ collection = map.values();
+ collection = map.values();
+ collection = map.values();
+ collection = map.values();
+ }
+ }
+
+ public void testTreeMapSize() {
+ int len;
+ TreeMap<String, Integer> map = sMap;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ len = map.size();
+ len = map.size();
+ len = map.size();
+ len = map.size();
+ len = map.size();
+ len = map.size();
+ len = map.size();
+ len = map.size();
+ len = map.size();
+ len = map.size();
+ }
+ }
+
+ public void testTreeMapContainsKey() {
+ boolean flag;
+ String key = sKeys[525];
+ TreeMap<String, Integer> map = sMap;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = map.containsKey(key);
+ flag = map.containsKey(key);
+ flag = map.containsKey(key);
+ flag = map.containsKey(key);
+ flag = map.containsKey(key);
+ flag = map.containsKey(key);
+ flag = map.containsKey(key);
+ flag = map.containsKey(key);
+ flag = map.containsKey(key);
+ flag = map.containsKey(key);
+ }
+ }
+
+ public void testTreeMapContainsValue() {
+ boolean flag;
+ TreeMap<String, Integer> map = sMap;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = map.containsValue(i);
+ flag = map.containsValue(i);
+ flag = map.containsValue(i);
+ flag = map.containsValue(i);
+ flag = map.containsValue(i);
+ flag = map.containsValue(i);
+ flag = map.containsValue(i);
+ flag = map.containsValue(i);
+ flag = map.containsValue(i);
+ flag = map.containsValue(i);
+ }
+ }
+
+ public void testTreeMapHeadMap() {
+ SortedMap map;
+ String str = sKeys[100];
+ TreeMap<String, Integer> tMap = sMap;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ map = tMap.headMap(str);
+ map = tMap.headMap(str);
+ map = tMap.headMap(str);
+ map = tMap.headMap(str);
+ map = tMap.headMap(str);
+ map = tMap.headMap(str);
+ map = tMap.headMap(str);
+ map = tMap.headMap(str);
+ map = tMap.headMap(str);
+ map = tMap.headMap(str);
+ }
+ }
+
+ public void testTreeMapSubMap() {
+ String str1 = sKeys[400];
+ String str2 = sKeys[500];
+ SortedMap map;
+ TreeMap<String, Integer> tMap = sMap;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ map = tMap.subMap(str1, str2);
+ map = tMap.subMap(str1, str2);
+ map = tMap.subMap(str1, str2);
+ map = tMap.subMap(str1, str2);
+ map = tMap.subMap(str1, str2);
+ map = tMap.subMap(str1, str2);
+ map = tMap.subMap(str1, str2);
+ map = tMap.subMap(str1, str2);
+ map = tMap.subMap(str1, str2);
+ map = tMap.subMap(str1, str2);
+ }
+ }
+
+ public void testTreeMapTailMap() {
+ String str = sKeys[900];
+ TreeMap<String, Integer> tMap = sMap;
+ SortedMap map;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ map = tMap.tailMap(str);
+ map = tMap.tailMap(str);
+ map = tMap.tailMap(str);
+ map = tMap.tailMap(str);
+ map = tMap.tailMap(str);
+ map = tMap.tailMap(str);
+ map = tMap.tailMap(str);
+ map = tMap.tailMap(str);
+ map = tMap.tailMap(str);
+ map = tMap.tailMap(str);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testTreeMapRemove() {
+ TreeMap<String, Integer> tMap = new TreeMap(sMap);
+ String[] keys = sKeys;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ tMap.remove(keys[i]);
+ tMap.remove(keys[i]);
+ tMap.remove(keys[i]);
+ tMap.remove(keys[i]);
+ tMap.remove(keys[i]);
+ tMap.remove(keys[i]);
+ tMap.remove(keys[i]);
+ tMap.remove(keys[i]);
+ tMap.remove(keys[i]);
+ tMap.remove(keys[i]);
+ }
+ }
+}
diff --git a/tests/CoreTests/android/core/TreeSetTest.java b/tests/CoreTests/android/core/TreeSetTest.java
new file mode 100644
index 0000000..a6a3309
--- /dev/null
+++ b/tests/CoreTests/android/core/TreeSetTest.java
@@ -0,0 +1,349 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+import android.test.PerformanceTestBase;
+import android.test.PerformanceTestCase;
+
+import java.util.TreeSet;
+import java.util.SortedSet;
+import java.util.Iterator;
+import java.util.Comparator;
+
+/**
+ * Implements basic performance test functionality for java.util.TreeSet
+ */
+
+public class TreeSetTest extends PerformanceTestBase {
+ public static final int ITERATIONS = 1000;
+ public static TreeSet<Integer> sSet;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ sSet = new TreeSet<Integer>();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ sSet.add(i);
+ }
+ }
+
+ @Override
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ /**
+ *
+ * Tests performance for the java.util.TreeSet method Add(Object arg 0)
+ *
+ */
+
+ @SuppressWarnings("unchecked")
+ public void testTreeSetAdd() {
+ TreeSet<Integer> set = new TreeSet();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ set.add(i);
+ }
+ }
+
+ /**
+ *
+ * Tests performance for the java.util.TreeSet method - first()
+ *
+ */
+
+ public void testTreeSetFirst() {
+ int value;
+ TreeSet<Integer> set = sSet;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ value = set.first();
+ value = set.first();
+ value = set.first();
+ value = set.first();
+ value = set.first();
+ value = set.first();
+ value = set.first();
+ value = set.first();
+ value = set.first();
+ }
+ }
+
+ /**
+ *
+ * Tests performance for the java.util.TreeSet method - last()
+ *
+ */
+
+ public void testTreeSetLast() {
+ int value;
+ TreeSet<Integer> set = sSet;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ value = set.last();
+ value = set.last();
+ value = set.last();
+ value = set.last();
+ value = set.last();
+ value = set.last();
+ value = set.last();
+ value = set.last();
+ value = set.last();
+ }
+ }
+
+ /**
+ *
+ * Tests performance of the java.util.TreeSet method- contains(Object arg0)
+ *
+ */
+
+ public void testTreeSetContains() {
+ Integer index = new Integer(500);
+ boolean flag;
+ TreeSet<Integer> set = sSet;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = set.contains(index);
+ flag = set.contains(index);
+ flag = set.contains(index);
+ flag = set.contains(index);
+ flag = set.contains(index);
+ flag = set.contains(index);
+ flag = set.contains(index);
+ flag = set.contains(index);
+ flag = set.contains(index);
+ }
+ }
+
+ /**
+ *
+ * Tests performance for the java.util.TreeSet method - size()
+ *
+ */
+
+ public void testTreeSetSize() {
+ int value;
+ TreeSet<Integer> set = sSet;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ value = set.size();
+ value = set.size();
+ value = set.size();
+ value = set.size();
+ value = set.size();
+ value = set.size();
+ value = set.size();
+ value = set.size();
+ value = set.size();
+ }
+ }
+
+ /**
+ *
+ * Tests performance for the java.util.TreeSet method - iterator()
+ *
+ */
+
+ public void testTreeSetIterator() {
+ Iterator iterator;
+ TreeSet<Integer> set = sSet;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ iterator = set.iterator();
+ iterator = set.iterator();
+ iterator = set.iterator();
+ iterator = set.iterator();
+ iterator = set.iterator();
+ iterator = set.iterator();
+ iterator = set.iterator();
+ iterator = set.iterator();
+ iterator = set.iterator();
+ }
+ }
+
+ /**
+ *
+ * Tests performance for the java.util.TreeSet method - comparator()
+ *
+ */
+
+ public void testTreeSetComparator() {
+ Comparator comparator;
+ TreeSet<Integer> set = sSet;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ comparator = set.comparator();
+ comparator = set.comparator();
+ comparator = set.comparator();
+ comparator = set.comparator();
+ comparator = set.comparator();
+ comparator = set.comparator();
+ comparator = set.comparator();
+ comparator = set.comparator();
+ comparator = set.comparator();
+ }
+ }
+
+ /**
+ *
+ * Tests performance for the java.util.TreeSet method - clone()
+ *
+ */
+
+ public void testTreeSetClone() {
+ Object obj;
+ TreeSet<Integer> set = sSet;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ obj = set.clone();
+ obj = set.clone();
+ obj = set.clone();
+ obj = set.clone();
+ obj = set.clone();
+ obj = set.clone();
+ obj = set.clone();
+ obj = set.clone();
+ obj = set.clone();
+ obj = set.clone();
+ }
+ }
+
+ /**
+ *
+ * Tests performance of the java.util.TreeSet method - remove(Object arg0)
+ *
+ */
+
+ @SuppressWarnings("unchecked")
+ public void testTreeSetRemove() {
+ TreeSet<Integer> set = new TreeSet(sSet);
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ set.remove(i);
+ }
+ }
+
+ /**
+ *
+ * Tests performance of the java.util.TreeSet method- headSet(Integer arg0)
+ *
+ */
+
+ public void testTreeSetHeadSet() {
+ Integer value = new Integer(100);
+ SortedSet set;
+ TreeSet<Integer> tSet = sSet;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ set = tSet.headSet(value);
+ set = tSet.headSet(value);
+ set = tSet.headSet(value);
+ set = tSet.headSet(value);
+ set = tSet.headSet(value);
+ set = tSet.headSet(value);
+ set = tSet.headSet(value);
+ set = tSet.headSet(value);
+ set = tSet.headSet(value);
+ set = tSet.headSet(value);
+ }
+ }
+
+ /**
+ *
+ * Tests performance of subSet(Integer arg0, Integer arg1) - TreeSet
+ *
+ */
+
+ public void testTreeSetSubSet() {
+ Integer value = new Integer(400);
+ Integer nInt = new Integer(500);
+ SortedSet set;
+ TreeSet<Integer> tSet = sSet;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ set = tSet.subSet(value, nInt);
+ set = tSet.subSet(value, nInt);
+ set = tSet.subSet(value, nInt);
+ set = tSet.subSet(value, nInt);
+ set = tSet.subSet(value, nInt);
+ set = tSet.subSet(value, nInt);
+ set = tSet.subSet(value, nInt);
+ set = tSet.subSet(value, nInt);
+ set = tSet.subSet(value, nInt);
+ set = tSet.subSet(value, nInt);
+
+ }
+
+ }
+
+ /**
+ *
+ * Tests performance of tailSet(Integer arg0) - TreeSet
+ *
+ */
+
+ public void testTreeSetTailSet() {
+ Integer value = new Integer(900);
+ SortedSet set;
+ TreeSet<Integer> tSet = sSet;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ set = tSet.tailSet(value);
+ set = tSet.tailSet(value);
+ set = tSet.tailSet(value);
+ set = tSet.tailSet(value);
+ set = tSet.tailSet(value);
+ set = tSet.tailSet(value);
+ set = tSet.tailSet(value);
+ set = tSet.tailSet(value);
+ set = tSet.tailSet(value);
+ set = tSet.tailSet(value);
+ }
+ }
+
+ /**
+ *
+ * Tests performance for the java.util.TreeSet method - isEmpty()
+ *
+ */
+
+ public void testTreeSetIsEmpty() {
+ boolean flag;
+ TreeSet<Integer> tSet = sSet;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = tSet.isEmpty();
+ flag = tSet.isEmpty();
+ flag = tSet.isEmpty();
+ flag = tSet.isEmpty();
+ flag = tSet.isEmpty();
+ flag = tSet.isEmpty();
+ flag = tSet.isEmpty();
+ flag = tSet.isEmpty();
+ flag = tSet.isEmpty();
+ flag = tSet.isEmpty();
+ }
+ }
+}
diff --git a/tests/CoreTests/android/core/VectorTest.java b/tests/CoreTests/android/core/VectorTest.java
new file mode 100644
index 0000000..b4c84fd
--- /dev/null
+++ b/tests/CoreTests/android/core/VectorTest.java
@@ -0,0 +1,555 @@
+/*
+ * Copyright (C) 2007 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 android.core;
+
+import android.test.PerformanceTestBase;
+import android.test.PerformanceTestCase;
+
+import java.util.Vector;
+import java.util.Enumeration;
+
+/**
+ * Basic Performance Tests for java.util.Vector
+ */
+
+@SuppressWarnings("unchecked")
+public class VectorTest extends PerformanceTestBase {
+ public static final int ITERATIONS = 1000;
+ private Vector<Integer> mVector;
+ private Vector<String> mStrVector;
+ private String mTestString = "Hello Android";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mVector = new Vector();
+ mStrVector = new Vector();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ assertTrue(mVector.add(i));
+ assertTrue(mStrVector.add(Integer.toString(i)));
+ }
+ }
+
+ @Override
+ public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
+ intermediates.setInternalIterations(ITERATIONS);
+ return 0;
+ }
+
+ public void testVectorAdd() {
+ Vector<Integer> vector = new Vector();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ vector.add(i);
+ vector.add(i);
+ vector.add(i);
+ vector.add(i);
+ vector.add(i);
+ vector.add(i);
+ vector.add(i);
+ vector.add(i);
+ vector.add(i);
+ vector.add(i);
+ }
+ }
+
+ public void testVectorAdd1() {
+ Vector<Integer> vector = new Vector();
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ vector.add(0, i);
+ vector.add(0, i);
+ vector.add(0, i);
+ vector.add(0, i);
+ vector.add(0, i);
+ vector.add(0, i);
+ vector.add(0, i);
+ vector.add(0, i);
+ vector.add(0, i);
+ vector.add(0, i);
+ }
+ }
+
+ public void testVectorToArray() {
+ Object array;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ array = vector.toArray();
+ array = vector.toArray();
+ array = vector.toArray();
+ array = vector.toArray();
+ array = vector.toArray();
+ array = vector.toArray();
+ array = vector.toArray();
+ array = vector.toArray();
+ array = vector.toArray();
+ array = vector.toArray();
+ }
+ }
+
+ /**
+ *
+ */
+ public void testVectorSize() {
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ int mLen;
+ mLen = vector.size();
+ mLen = vector.size();
+ mLen = vector.size();
+ mLen = vector.size();
+ mLen = vector.size();
+ mLen = vector.size();
+ mLen = vector.size();
+ mLen = vector.size();
+ mLen = vector.size();
+ mLen = vector.size();
+ }
+ }
+
+ public void testVectorGet() {
+ int element;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ element = vector.get(i);
+ element = vector.get(i);
+ element = vector.get(i);
+ element = vector.get(i);
+ element = vector.get(i);
+ element = vector.get(i);
+ element = vector.get(i);
+ element = vector.get(i);
+ element = vector.get(i);
+ element = vector.get(i);
+ }
+
+ }
+
+ public void testVectorContains() {
+ boolean flag;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ flag = vector.contains(i);
+ flag = vector.contains(i);
+ flag = vector.contains(i);
+ flag = vector.contains(i);
+ flag = vector.contains(i);
+ flag = vector.contains(i);
+ flag = vector.contains(i);
+ flag = vector.contains(i);
+ flag = vector.contains(i);
+ flag = vector.contains(i);
+ }
+ }
+
+ public void testVectorToArray1() {
+ Integer[] rArray = new Integer[100];
+ Integer[] array;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ array = vector.toArray(rArray);
+ array = vector.toArray(rArray);
+ array = vector.toArray(rArray);
+ array = vector.toArray(rArray);
+ array = vector.toArray(rArray);
+ array = vector.toArray(rArray);
+ array = vector.toArray(rArray);
+ array = vector.toArray(rArray);
+ array = vector.toArray(rArray);
+ array = vector.toArray(rArray);
+ }
+ }
+
+ public void testVectorSet() {
+ Vector<Integer> vector = mVector;
+ int pos = 5, value = 0;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ vector.set(pos, value);
+ vector.set(pos, value);
+ vector.set(pos, value);
+ vector.set(pos, value);
+ vector.set(pos, value);
+ vector.set(pos, value);
+ vector.set(pos, value);
+ vector.set(pos, value);
+ vector.set(pos, value);
+ vector.set(pos, value);
+ }
+ }
+
+ public void testVectorIndexOf() {
+ int index, value = 0;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = vector.indexOf(value);
+ index = vector.indexOf(value);
+ index = vector.indexOf(value);
+ index = vector.indexOf(value);
+ index = vector.indexOf(value);
+ index = vector.indexOf(value);
+ index = vector.indexOf(value);
+ index = vector.indexOf(value);
+ index = vector.indexOf(value);
+ index = vector.indexOf(value);
+ }
+ }
+
+ public void testVectorLastIndexOf() {
+ int index, value = 0;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i >= 0; i--) {
+ index = vector.lastIndexOf(value);
+ index = vector.lastIndexOf(value);
+ index = vector.lastIndexOf(value);
+ index = vector.lastIndexOf(value);
+ index = vector.lastIndexOf(value);
+ index = vector.lastIndexOf(value);
+ index = vector.lastIndexOf(value);
+ index = vector.lastIndexOf(value);
+ index = vector.lastIndexOf(value);
+ index = vector.lastIndexOf(value);
+ }
+ }
+
+ public void testVectorRemove() {
+ int index, value = 0;
+ Vector<Integer> vector = new Vector(mVector);
+ for (int i = 10; i > 0; i--) {
+ index = vector.remove(value);
+ index = vector.remove(value);
+ index = vector.remove(value);
+ index = vector.remove(value);
+ index = vector.remove(value);
+ index = vector.remove(value);
+ index = vector.remove(value);
+ index = vector.remove(value);
+ index = vector.remove(value);
+ index = vector.remove(value);
+ }
+ }
+
+ public void testVectorRemoveElement() {
+ Vector<Integer> vector = new Vector(mVector);
+ for (int i = 10; i > 0; i--) {
+ vector.removeElement(i);
+ vector.removeElement(i);
+ vector.removeElement(i);
+ vector.removeElement(i);
+ vector.removeElement(i);
+ vector.removeElement(i);
+ vector.removeElement(i);
+ vector.removeElement(i);
+ vector.removeElement(i);
+ vector.removeElement(i);
+ }
+ }
+
+ public void VectorRemoveElementAt() {
+ Vector<Integer> vector = new Vector(mVector);
+ for (int i = 10; i > 0; i--) {
+ vector.removeElementAt(i);
+ vector.removeElementAt(i);
+ vector.removeElementAt(i);
+ vector.removeElementAt(i);
+ vector.removeElementAt(i);
+ vector.removeElementAt(i);
+ vector.removeElementAt(i);
+ vector.removeElementAt(i);
+ vector.removeElementAt(i);
+ vector.removeElementAt(i);
+ }
+ }
+
+ public void VectorAddAll() {
+ Vector<Integer> vector = new Vector(), vector1 = mVector;
+
+ boolean flag;
+ for (int i = 10; i > 0; i--) {
+ flag = vector.addAll(vector1);
+ flag = vector.addAll(vector1);
+ flag = vector.addAll(vector1);
+ flag = vector.addAll(vector1);
+ flag = vector.addAll(vector1);
+ flag = vector.addAll(vector1);
+ flag = vector.addAll(vector1);
+ flag = vector.addAll(vector1);
+ flag = vector.addAll(vector1);
+ flag = vector.addAll(vector1);
+ }
+ }
+
+ public void VectorRemove1() {
+ Vector<String> vector = mStrVector;
+ for (int j = 1000; j > 0; j--) {
+ vector.add("a");
+ vector.add("b");
+ }
+ String s = new String("a");
+ boolean flag;
+ for (int i = 10; i > 0; i--) {
+ flag = vector.remove(s);
+ flag = vector.remove(s);
+ flag = vector.remove(s);
+ flag = vector.remove(s);
+ flag = vector.remove(s);
+ flag = vector.remove(s);
+ flag = vector.remove(s);
+ flag = vector.remove(s);
+ flag = vector.remove(s);
+ flag = vector.remove(s);
+ }
+ }
+
+ public void testVectorAddAll1() {
+ Vector<Integer> mEmptyVector = new Vector();
+ boolean flag;
+ int pos = 0;
+ Vector<Integer> vector1 = mVector;
+ Vector<Integer> vector = mEmptyVector;
+ for (int i = 10; i > 0; i--) {
+ flag = vector.addAll(pos, vector1);
+ flag = vector.addAll(pos, vector1);
+ flag = vector.addAll(pos, vector1);
+ flag = vector.addAll(pos, vector1);
+ flag = vector.addAll(pos, vector1);
+ flag = vector.addAll(pos, vector1);
+ flag = vector.addAll(pos, vector1);
+ flag = vector.addAll(pos, vector1);
+ flag = vector.addAll(pos, vector1);
+ flag = vector.addAll(pos, vector1);
+ }
+ }
+
+ public void testVectorClone() {
+ Object obj;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i > 0; i--) {
+ obj = vector.clone();
+ obj = vector.clone();
+ obj = vector.clone();
+ obj = vector.clone();
+ obj = vector.clone();
+ obj = vector.clone();
+ obj = vector.clone();
+ obj = vector.clone();
+ obj = vector.clone();
+ obj = vector.clone();
+ }
+ }
+
+ public void testVectorCapacity() {
+ int capacity;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i > 0; i--) {
+ capacity = vector.capacity();
+ capacity = vector.capacity();
+ capacity = vector.capacity();
+ capacity = vector.capacity();
+ capacity = vector.capacity();
+ capacity = vector.capacity();
+ capacity = vector.capacity();
+ capacity = vector.capacity();
+ capacity = vector.capacity();
+ capacity = vector.capacity();
+ }
+ }
+
+ public void testVectorHashcode() {
+ int element;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i > 0; i--) {
+ element = vector.hashCode();
+ element = vector.hashCode();
+ element = vector.hashCode();
+ element = vector.hashCode();
+ element = vector.hashCode();
+ element = vector.hashCode();
+ element = vector.hashCode();
+ element = vector.hashCode();
+ element = vector.hashCode();
+ element = vector.hashCode();
+ }
+ }
+
+ public void testVectorElements() {
+ Enumeration<Integer> elements;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i > 0; i--) {
+ elements = vector.elements();
+ elements = vector.elements();
+ elements = vector.elements();
+ elements = vector.elements();
+ elements = vector.elements();
+ elements = vector.elements();
+ elements = vector.elements();
+ elements = vector.elements();
+ elements = vector.elements();
+ elements = vector.elements();
+ }
+ }
+
+ public void testVectorToString() {
+ String str;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i > 0; i--) {
+ str = vector.toString();
+ str = vector.toString();
+ str = vector.toString();
+ str = vector.toString();
+ str = vector.toString();
+ str = vector.toString();
+ str = vector.toString();
+ str = vector.toString();
+ str = vector.toString();
+ str = vector.toString();
+ }
+ }
+
+ public void testVectorElementAt() {
+ int element;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i > 0; i--) {
+ element = vector.elementAt(50);
+ element = vector.elementAt(50);
+ element = vector.elementAt(50);
+ element = vector.elementAt(50);
+ element = vector.elementAt(50);
+ element = vector.elementAt(50);
+ element = vector.elementAt(50);
+ element = vector.elementAt(50);
+ element = vector.elementAt(50);
+ element = vector.elementAt(50);
+ }
+ }
+
+ public void testVectorAddElement() {
+ int element;
+ Vector<String> vector = mStrVector;
+ for (int i = ITERATIONS - 1; i > 0; i--) {
+ vector.addElement(mTestString);
+ vector.addElement(mTestString);
+ vector.addElement(mTestString);
+ vector.addElement(mTestString);
+ vector.addElement(mTestString);
+ vector.addElement(mTestString);
+ vector.addElement(mTestString);
+ vector.addElement(mTestString);
+ vector.addElement(mTestString);
+ vector.addElement(mTestString);
+ }
+ }
+
+ public void testVectorFirstElement() {
+ int element;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i > 0; i--) {
+ element = vector.firstElement();
+ element = vector.firstElement();
+ element = vector.firstElement();
+ element = vector.firstElement();
+ element = vector.firstElement();
+ element = vector.firstElement();
+ element = vector.firstElement();
+ element = vector.firstElement();
+ element = vector.firstElement();
+ element = vector.firstElement();
+ }
+ }
+
+ public void testVectorLastElement() {
+ int element;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i > 0; i--) {
+ element = vector.lastElement();
+ element = vector.lastElement();
+ element = vector.lastElement();
+ element = vector.lastElement();
+ element = vector.lastElement();
+ element = vector.lastElement();
+ element = vector.lastElement();
+ element = vector.lastElement();
+ element = vector.lastElement();
+ element = vector.lastElement();
+ }
+ }
+
+ public void testVectorSetElementAt() {
+ Vector<Integer> vector = mVector;
+ int value1 = 500, value2 = 50;
+ for (int i = ITERATIONS - 1; i > 0; i--) {
+ vector.setElementAt(value1, value2);
+ vector.setElementAt(value1, value2);
+ vector.setElementAt(value1, value2);
+ vector.setElementAt(value1, value2);
+ vector.setElementAt(value1, value2);
+ vector.setElementAt(value1, value2);
+ vector.setElementAt(value1, value2);
+ vector.setElementAt(value1, value2);
+ vector.setElementAt(value1, value2);
+ vector.setElementAt(value1, value2);
+ }
+ }
+
+ public void testVectorIsEmpty() {
+ boolean flag;
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i > 0; i--) {
+ flag = vector.isEmpty();
+ flag = vector.isEmpty();
+ flag = vector.isEmpty();
+ flag = vector.isEmpty();
+ flag = vector.isEmpty();
+ flag = vector.isEmpty();
+ flag = vector.isEmpty();
+ flag = vector.isEmpty();
+ flag = vector.isEmpty();
+ flag = vector.isEmpty();
+ }
+ }
+
+ public void testVectorCopyInto() {
+ Integer[] rArray = new Integer[ITERATIONS];
+ Vector<Integer> vector = mVector;
+ for (int i = ITERATIONS - 1; i > 0; i--) {
+ vector.copyInto(rArray);
+ vector.copyInto(rArray);
+ vector.copyInto(rArray);
+ vector.copyInto(rArray);
+ vector.copyInto(rArray);
+ vector.copyInto(rArray);
+ vector.copyInto(rArray);
+ vector.copyInto(rArray);
+ vector.copyInto(rArray);
+ vector.copyInto(rArray);
+ }
+ }
+
+ public void testVectorInsertElementAt() {
+ Vector<String> vector = mStrVector;
+ String string = mTestString;
+ for (int i = ITERATIONS - 1; i > 0; i--) {
+ vector.insertElementAt(string, i);
+ vector.insertElementAt(string, i);
+ vector.insertElementAt(string, i);
+ vector.insertElementAt(string, i);
+ vector.insertElementAt(string, i);
+ vector.insertElementAt(string, i);
+ vector.insertElementAt(string, i);
+ vector.insertElementAt(string, i);
+ vector.insertElementAt(string, i);
+ vector.insertElementAt(string, i);
+ }
+ }
+}