Skip to main content
summaryrefslogtreecommitdiffstats
blob: 13ecd379d8b855321ccb97e982b423a5c1e8ea76 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/
////Created on Oct 12, 2004
package org.eclipse.mylar.tests.misc;

import java.io.File;
import java.io.FileReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;

import org.eclipse.core.runtime.Path;
import org.eclipse.mylar.bugs.search.BugzillaMylarSearchOperation;
import org.eclipse.mylar.bugzilla.core.internal.BugParser;
import org.eclipse.mylar.bugzilla.core.search.BugzillaSearchHit;
import org.eclipse.mylar.bugzilla.tests.BugzillaTestPlugin;
import org.eclipse.mylar.bugzilla.ui.tasklist.BugzillaReportNode;
import org.eclipse.mylar.bugzilla.ui.tasklist.StackTrace;
import org.eclipse.mylar.tests.core.support.FileTool;

/**
 * Class to test the Bridge methods that do not require server queries
 * 
 * @author Shawn Minto
 */
public class BugzillaStackTraceTest extends TestCase {

	private static final String TEST_FILE_LOC = "testdata/reports-stacktrace/";

	private static final String BUGZILLA_SERVER_NAME = "https://bugs.eclipse.org/bugs";

	/**
	 * Test that the regular expression escaping mechanism works properly
	 */
	public void testREGEX() {
		String r = ".*+(){}[]^$|?/\\";
		String r2 = StackTrace.escapeForRegex(r);
		String ans = "\\.\\*\\+\\(\\)\\{\\}\\[\\]\\^\\$\\|\\?\\/\\\\";
		String msg = "Regular Expression matching wrong:\nwas: " + r2 + "\nshould be:" + ans;
		assertTrue(msg, r2.equals(ans));
	}

	// /**
	// * Test parsing the bug for multiple stacks in in
	// */
	// public void testMultipleStacksDiffComments(){
	// // BUG 4862 - 2 stack traces - 1 in description, 1 in comment - text
	// before and after
	// performParse(4862, "4862.html", 2, false);
	// }

	// /**
	// * Test parsing the bug for a single stack in the description with some
	// * text before it
	// */
	// public void testSingleStackCodeBeforeInDescription(){
	// // BUG 76388 - 1 stack trace - description - text before and formatted
	// ugly
	// performParse(76388, "76388.html", 1, false);
	// }

	/**
	 * Test parsing the bug for a single stack trace in the description with
	 * text before and after it
	 */
	public void testSingleStackCodeBeforeAndAfterInDescription() {

		// BUG 76146 - 1 stack trace - description - text before and code after
		performParse(76146, "76146.html", 1, false);
	}

	/**
	 * Test parsing a bug that has 1 stack trace in the description with no
	 * extra text, but has lines in it that span 3 lines
	 */
	public void testSingleStackPoorFormatInDescription() {
		// BUG 67395 - 1 stack trace - description - no extra text, 1 at line
		// spans 3 lines
		performParse(67395, "67395.html", 1, false);
	}

	/**
	 * Test parsing a bug with no stack traces and no qualified exception names
	 */
	public void testNoStackNoQualified() {
		// BUG 4548 - no stack traces, no qualified reference to an exception
		performParse(4548, "4548.html", 0, false);
	}

	/**
	 * Test parsing a bug with no stack traces, but a qualified reference to an
	 * exception
	 */
	public void testNoStackQual() {
		// BUG 1 - no stack traces, qualified reference to exception - made up
		// bug
		performParse(1, "1.html", 0, false);
	}

	/**
	 * Test parsing of a bug with 1 stack trace and multiple qualified
	 * references
	 */
	public void testSingleStackQual() {
		// BUG 2 - 1 stack trace- 2 qual ref, stack trace, 1 qual ref - made up
		// bug
		performParse(2, "2.html", 1, false);
	}

	/**
	 * Test parsing of a bug with many stacks traces in a single comment
	 */
	public void testMultipleStackSingleComment() {
		// BUG 40152 - 1 stack trace- 2 qual ref, stack trace, 1 qual ref - made
		// up bug
		performParse(40152, "40152.html", 33, false);
	}

	/**
	 * Print out the stack traces
	 * 
	 * @param l
	 *            List of stack traces
	 */
	private void printStackTraces(List<StackTrace> l) {
		System.out.println("\n\n");
		for (int i = 0; i < l.size(); i++) {
			StackTrace trace = l.get(i);
			System.out.println("*****************?????????????????*****************\n");
			System.out.println("OFFSET: " + trace.getOffset() + " LENGTH: " + trace.getLength());
			System.out.println(trace.getStackTrace());
			System.out.println("*****************?????????????????*****************\n\n");
		}
	}

	private void performParse(int bugNumber, String bugFileName, int numTracesExpected, boolean printStackTraces) {

		BugzillaSearchHit hit = new BugzillaSearchHit("<TEST-SERVER>", bugNumber, "", "", "", "", "", "", "", ""); // stack
																													// trace
																													// in
																													// desc
																													// and
																													// com

		// create a new doi info
		BugzillaReportNode doi = new BugzillaReportNode(0, hit, false);
		try {

			// read the bug in from a file
			File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path(TEST_FILE_LOC + bugFileName)); // used
																														// if
																														// run
																														// as a
																														// plugin
																														// test
			// File f = new File(TEST_FILE_LOC+bugFileName); // used if run as a
			// standalone test
			Reader reader = new FileReader(f);
			doi.setBug(BugParser.parseBug(reader, hit.getId(), BUGZILLA_SERVER_NAME, true, null, null, null));
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

		// do a second pass parse on the bug
		List<BugzillaReportNode> l = new ArrayList<BugzillaReportNode>();
		l.add(doi);
		BugzillaMylarSearchOperation.secondPassBugzillaParser(l);

		// make sure that we received the right number of stack traces back
		// System.out.println("*** BUG " + hit.getId() + " ***");
		// System.out.println("NumStackTraces = " +
		// doi.getStackTraces().size());
		assertEquals("Wrong Number stack traces", numTracesExpected, doi.getStackTraces().size());
		if (printStackTraces)
			printStackTraces(doi.getStackTraces());
	}
}

Back to the top