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.h4265;
019:
020: import junit.framework.*;
021:
022: public class Test extends TestCase {
023:
024: //1
025: void _testRec1() {
026: _testRec1();
027: }
028:
029: public void testRec1() {
030: try {
031: _testRec1();
032: } catch (StackOverflowError e) {
033: return;
034: }
035: fail("No SOE was thrown!");
036: }
037:
038: //2
039: Object lock2 = new Object();
040:
041: void _testSyncRec1() {
042: synchronized (lock2) {
043: _testSyncRec1();
044: }
045: }
046:
047: public void testSyncRec1() {
048: try {
049: _testSyncRec1();
050: } catch (StackOverflowError e) {
051: return;
052: }
053: fail("No SOE was thrown!");
054: }
055:
056: //3
057: Object lock3 = new Object();
058:
059: void _testSyncRec2() {
060: try {
061: synchronized (lock3) {
062: _testSyncRec2();
063: }
064: } catch (Error r) {
065: //ignore
066: }
067: }
068:
069: public void testSyncRec2() throws Exception {
070: Thread t1 = new Thread(new Runnable() {
071: public void run() {
072: _testSyncRec2();
073: }
074: });
075: t1.start();
076: t1.join();
077:
078: Thread t2 = new Thread(new Runnable() {
079: public void run() {
080: _testSyncRec2();
081: }
082: });
083: t2.start();
084: t2.join();
085: //pass if no hang
086: }
087:
088: //4
089: int i1 = 0;
090:
091: void _testRec2() {
092: try {
093: i1++;
094: _testRec2();
095: } finally {
096: i1--;
097: }
098: }
099:
100: public void testRec2() {
101: i1 = 0;
102: try {
103: _testRec2();
104: } catch (StackOverflowError e) {
105: assertEquals(0, i1);
106: return;
107: }
108: fail("No SOE was thrown!");
109:
110: }
111:
112: //5
113: public void testRec3() {
114: i1 = 0;
115: try {
116: _testRec2();
117: } catch (Throwable e) {
118: assertEquals(0, i1);
119: return;
120: }
121: fail("No Throwable was thrown!");
122:
123: }
124:
125: //6
126: public void testRec4() {
127: i1 = 0;
128: try {
129: _testRec2();
130: } catch (Error e) {
131: assertEquals(0, i1);
132: return;
133: }
134: fail("No Error was thrown!");
135:
136: }
137:
138: }
|