01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.drlvm.tests.regression.h4514;
19:
20: import junit.framework.*;
21:
22: public class Test extends TestCase {
23:
24: public void testTrace1() {
25: //some useless code
26: int i = 0;
27: int j = 1;
28: try {
29: assertEquals(0, 1); //the number of this line must be in tracktracelement
30: } catch (Throwable e) {
31: StackTraceElement this Frame = findThisFrame(e);
32: assertEquals(27, this Frame.getLineNumber());
33: }
34: }
35:
36: public void testTrace2() {
37: //some useless code
38: int i = 0;
39: int j = 1;
40: try {
41: fail();//the number of this line must be in tracktracelement
42: } catch (Throwable e) {
43: StackTraceElement this Frame = findThisFrame(e);
44: assertEquals(39, this Frame.getLineNumber());
45: }
46: }
47:
48: public void testTrace3() {
49: //some useless code
50: int i = 0;
51: int j = 1;
52: try {
53: assertEquals(true, false);//the number of this line must be in tracktracelement
54: } catch (Throwable e) {
55: StackTraceElement this Frame = findThisFrame(e);
56: assertEquals(51, this Frame.getLineNumber());
57: }
58:
59: }
60:
61: public void testTrace4() {
62: //some useless code
63: int i = 0;
64: int j = 1;
65: try {
66: assertNotNull(null);//the number of this line must be in tracktracelement
67: } catch (Throwable e) {
68: StackTraceElement this Frame = findThisFrame(e);
69: assertEquals(64, this Frame.getLineNumber());
70: }
71:
72: }
73:
74: public void testTrace5() {
75: //some useless code
76: int i = 0;
77: int j = 1;
78: try {
79: assertEquals("", "fail");//the number of this line must be in tracktracelement
80: } catch (Throwable e) {
81: StackTraceElement this Frame = findThisFrame(e);
82: assertEquals(77, this Frame.getLineNumber());
83: }
84:
85: }
86:
87: static StackTraceElement findThisFrame(Throwable e) {
88: StackTraceElement[] frames = e.getStackTrace();
89: for (StackTraceElement frame : frames) {
90: if (frame.getClassName().equals(Test.class.getName())) {
91: return frame;
92: }
93: }
94: return null;
95: }
96: }
|