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.h5094;
019:
020: import junit.framework.TestCase;
021:
022: public class InlinedStackTest extends TestCase {
023:
024: private static void a() throws Exception {
025: smth();
026: b();
027: }
028:
029: private static void b() throws Exception {
030: c();
031: }
032:
033: static void c() throws Exception {
034: smth();
035: d();
036: }
037:
038: static void d() throws Exception {
039: smth();
040: smth();
041: throw new RuntimeException();
042: }
043:
044: static int i = 0;
045:
046: static void smth() {
047: i++;
048: }
049:
050: public static void assertStackFrame(String clsname,
051: String methname, int ln, StackTraceElement stf) {
052: assertEquals(clsname, stf.getClassName());
053: assertEquals(methname, stf.getMethodName());
054: assertEquals(ln, stf.getLineNumber());
055: }
056:
057: public void test1() throws Exception {
058: try {
059: a();
060: } catch (Throwable t) {
061: t.printStackTrace();
062: StackTraceElement[] st = t.getStackTrace();
063: assertTrue("trace is not deep enough: " + st.length,
064: st.length >= 6);
065: assertStackFrame(this .getClass().getName(), "d", 39, st[0]);
066: assertStackFrame(this .getClass().getName(), "c", 34, st[1]);
067: assertStackFrame(this .getClass().getName(), "b", 29, st[2]);
068: assertStackFrame(this .getClass().getName(), "a", 26, st[3]);
069: assertStackFrame(this .getClass().getName(), "test1", 55,
070: st[4]);
071: }
072: }
073:
074: public void test2() throws Exception {
075: try {
076: Q.a();
077: } catch (Throwable t) {
078: t.printStackTrace();
079: StackTraceElement[] st = t.getStackTrace();
080: assertTrue("trace is not deep enough: " + st.length,
081: st.length >= 6);
082: assertStackFrame(this .getClass().getName(), "d", 39, st[0]);
083: assertStackFrame(Q.class.getName(), "c", 108, st[1]);
084: assertStackFrame(Q.class.getName(), "b", 104, st[2]);
085: assertStackFrame(Q.class.getName(), "a", 100, st[3]);
086: //assertStackFrame(this.getClass().getName(), "test2", 70, st[4]); //OPT to be fixed yet
087: }
088: }
089:
090: public void test3() throws Exception {
091: try {
092: Q.a2();
093: } catch (Throwable t) {
094: t.printStackTrace();
095: StackTraceElement[] st = t.getStackTrace();
096: assertTrue("trace is not deep enough: " + st.length,
097: st.length >= 5);
098: assertStackFrame(this .getClass().getName(), "d", 39, st[0]);
099: assertStackFrame(this .getClass().getName(), "c", 34, st[1]);
100: assertStackFrame(Q.class.getName(), "a2", 112, st[2]);
101: assertStackFrame(this .getClass().getName(), "test3", 85,
102: st[3]);
103: }
104: }
105: }
106:
107: class Q {
108: static void a() throws Exception {
109: b();
110: }
111:
112: private static void b() throws Exception {
113: InlinedStackTest.smth();
114: c();
115: }
116:
117: private static void c() throws Exception {
118: InlinedStackTest.d();
119: }
120:
121: static void a2() throws Exception {
122: InlinedStackTest.c();
123: }
124: }
|