2
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.carbide.cpp.codescanner.tests;
|
|
19 |
|
|
20 |
import java.io.*;
|
|
21 |
|
|
22 |
import com.nokia.carbide.cpp.internal.codescanner.error.parsers.*;
|
|
23 |
import com.nokia.carbide.cpp.project.core.ProjectCorePlugin;
|
|
24 |
import org.eclipse.cdt.core.ErrorParserManager;
|
|
25 |
import org.eclipse.cdt.core.IMarkerGenerator;
|
|
26 |
import org.eclipse.cdt.core.ProblemMarkerInfo;
|
|
27 |
import org.eclipse.core.resources.IProject;
|
|
28 |
import org.eclipse.core.resources.IResource;
|
|
29 |
import org.eclipse.core.runtime.CoreException;
|
|
30 |
import org.eclipse.core.runtime.IPath;
|
|
31 |
import org.eclipse.core.runtime.NullProgressMonitor;
|
|
32 |
|
|
33 |
import junit.framework.TestCase;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* Test cases for class CSErrorParser.
|
|
37 |
*
|
|
38 |
*/
|
|
39 |
public class CSErrorParserTest extends TestCase {
|
|
40 |
|
|
41 |
private class testMarkerGenerator implements IMarkerGenerator {
|
|
42 |
public void addMarker(ProblemMarkerInfo problemMarkerInfo) {
|
|
43 |
}
|
|
44 |
public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) {
|
|
45 |
}
|
|
46 |
}
|
|
47 |
|
|
48 |
@Override
|
|
49 |
protected void setUp() throws Exception {
|
|
50 |
super.setUp();
|
|
51 |
}
|
|
52 |
|
|
53 |
@Override
|
|
54 |
protected void tearDown() throws Exception {
|
|
55 |
super.tearDown();
|
|
56 |
}
|
|
57 |
|
|
58 |
public void testProcessLine() {
|
|
59 |
|
|
60 |
try {
|
|
61 |
IProject project = ProjectCorePlugin.createProject("codescanner_test1", null);
|
|
62 |
assertNotNull(project);
|
|
63 |
IPath workingDir = project.getLocation();
|
|
64 |
IPath filePath = workingDir.append("MyTest.cpp");
|
|
65 |
testMarkerGenerator markGen = new testMarkerGenerator();
|
|
66 |
NullProgressMonitor monitor = new NullProgressMonitor();
|
|
67 |
String[] errorParserIds = new String[0];
|
|
68 |
ErrorParserManager errorParserManager = new ErrorParserManager(project, workingDir, markGen, errorParserIds);
|
|
69 |
CSErrorParser errorParser = new CSErrorParser();
|
|
70 |
|
|
71 |
createTestFile(filePath);
|
|
72 |
|
|
73 |
// test with different messages
|
|
74 |
String msg = filePath.toString() + "(1) : warning: this is a warning message";
|
|
75 |
assertTrue(errorParser.processLine(msg, errorParserManager));
|
|
76 |
msg = filePath.toString() + "(2) : error: this is an error message";
|
|
77 |
assertTrue(errorParser.processLine(msg, errorParserManager));
|
|
78 |
assertFalse(errorParser.processLine("the system cannot find the path specified", errorParserManager));
|
|
79 |
assertFalse(errorParser.processLine("a random message", errorParserManager));
|
|
80 |
|
|
81 |
project.delete(true, true, monitor);
|
|
82 |
} catch (CoreException e) {
|
|
83 |
fail();
|
|
84 |
}
|
|
85 |
}
|
|
86 |
|
|
87 |
private void createTestFile(IPath filePath) {
|
|
88 |
try {
|
|
89 |
FileOutputStream fout = new FileOutputStream (filePath.toOSString());
|
|
90 |
new PrintStream(fout).println ("This is only a test.");
|
|
91 |
new PrintStream(fout).println ("There is no need to panic.");
|
|
92 |
fout.close();
|
|
93 |
}
|
|
94 |
catch (IOException e) {
|
|
95 |
fail();
|
|
96 |
}
|
|
97 |
}
|
|
98 |
}
|