001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.drlvm.tests.regression.h1788;
019:
020: import junit.framework.TestCase;
021:
022: public class abcdTest extends TestCase {
023:
024: public void test2141() {
025: System.out.println("Start test2141 ...");
026: int i = 0;
027: int arr[] = new int[300000];
028: try {
029: for (i = 0; i < 100000; i++) {
030: while (i < 3) {
031: arr[i - 1] = 1;
032: i++;
033: }
034: }
035: fail("TEST 1 FAILED: ArrayIndexOutOfBoundsException wasn't thrown");
036: } catch (ArrayIndexOutOfBoundsException ae) {
037: System.out.println("TEST 1 PASSED");
038: }
039:
040: i = 0;
041: try {
042: for (i = 0; i < 100000; i++) {
043: if (i > 5) {
044: arr[i - 100] = 1;
045: i++;
046: }
047: }
048: fail("TEST 2 FAILED: ArrayIndexOutOfBoundsException wasn't thrown");
049: } catch (ArrayIndexOutOfBoundsException ae) {
050: System.out.println("TEST 2 PASSED");
051: }
052: }
053:
054: public void test2144() {
055: final int limit = 10000;
056: System.out.println("Start test2144 ...");
057: int arr[] = new int[limit];
058: int j = 1;
059: try {
060: for (int k = 2; k < limit; k = 1 + k + k * j) {
061: if (k < 0)
062: System.out.println("---Overflow---");
063: System.out.println("k=" + k + ": arr[" + (k - 2)
064: + "] will be called");
065: arr[k] = arr[k - 2];
066: j = k * k;
067: }
068: } catch (ArrayIndexOutOfBoundsException e) {
069: System.out
070: .println("TEST PASSED ArrayIndexOutOfBoundsException was thrown");
071: return;
072: } catch (Exception e) {
073: e.printStackTrace();
074: fail("TEST FAILED: unexpected exception was thrown");
075: }
076: fail("TEST FAILED: ArrayIndexOutOfBoundsException wasn't thrown");
077: }
078:
079: public void test2147_1() {
080: final int limit = 1000;
081: System.out.println("Start test2147_1 ...");
082: int arr[] = new int[limit];
083: try {
084: for (int k = 1; k < limit;) {
085: System.out.println("k=" + k + ": arr[" + (k - 1)
086: + "] will be called");
087: k = arr[k - 1];
088: }
089: } catch (ArrayIndexOutOfBoundsException e) {
090: System.out
091: .println("TEST PASSED: ArrayIndexOutOfBoundsException was thrown");
092: return;
093: }
094: fail("TEST FAILED: ArrayIndexOutOfBoundsException wasn't thrown");
095: }
096:
097: static int num = 0;
098:
099: public void test2147_2() {
100: System.out.println("Start test2147_2: LowBoundCheck Test ...");
101: try {
102: int[] arr = new int[5];
103: int limit = arr.length - 1;
104: for (int j = limit; j > 0; j--) {
105: System.out.println("Call arr[" + (j - 3) + "]");
106: num = arr[j - 3];
107: }
108: fail("TEST FAILED: ArrayIndexOutOfBoundsException wasn't thrown");
109: } catch (ArrayIndexOutOfBoundsException ae) {
110: System.out.println("TEST PASSED");
111: }
112: }
113:
114: }
|