mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 09:15:38 +02:00
Fixed a resource leak.
This commit is contained in:
parent
e8e43a37f8
commit
89ae641793
1 changed files with 23 additions and 25 deletions
|
@ -16,9 +16,6 @@ import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.ErrorParserManager;
|
import org.eclipse.cdt.core.ErrorParserManager;
|
||||||
import org.eclipse.cdt.core.IErrorParser;
|
import org.eclipse.cdt.core.IErrorParser;
|
||||||
|
@ -43,11 +40,13 @@ import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Alena Laskavaia
|
* @author Alena Laskavaia
|
||||||
*
|
*
|
||||||
* Tests for ErrorParser manager and different parsers
|
* Tests for ErrorParser manager and different parsers
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ErrorParserManagerTest extends TestCase {
|
public class ErrorParserManagerTest extends TestCase {
|
||||||
IWorkspace workspace;
|
IWorkspace workspace;
|
||||||
|
@ -97,7 +96,6 @@ public class ErrorParserManagerTest extends TestCase {
|
||||||
errorList = new ArrayList<ProblemMarkerInfo>();
|
errorList = new ArrayList<ProblemMarkerInfo>();
|
||||||
cProject = createProject("errorparsersanity");
|
cProject = createProject("errorparsersanity");
|
||||||
markerGenerator = new IMarkerGenerator() {
|
markerGenerator = new IMarkerGenerator() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) {
|
public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) {
|
||||||
// Obsolete
|
// Obsolete
|
||||||
|
@ -106,9 +104,7 @@ public class ErrorParserManagerTest extends TestCase {
|
||||||
@Override
|
@Override
|
||||||
public void addMarker(ProblemMarkerInfo problemMarkerInfo) {
|
public void addMarker(ProblemMarkerInfo problemMarkerInfo) {
|
||||||
errorList.add(problemMarkerInfo);
|
errorList.add(problemMarkerInfo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
String[] errorParsersIds = {
|
String[] errorParsersIds = {
|
||||||
"org.eclipse.cdt.core.CWDLocator",
|
"org.eclipse.cdt.core.CWDLocator",
|
||||||
|
@ -119,14 +115,13 @@ public class ErrorParserManagerTest extends TestCase {
|
||||||
"org.eclipse.cdt.core.GmakeErrorParser",
|
"org.eclipse.cdt.core.GmakeErrorParser",
|
||||||
};
|
};
|
||||||
epManager = new ErrorParserManager(cProject.getProject(), markerGenerator, errorParsersIds);
|
epManager = new ErrorParserManager(cProject.getProject(), markerGenerator, errorParsersIds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tears down the test fixture.
|
* Tears down the test fixture.
|
||||||
*
|
*
|
||||||
* Called after every test case method.
|
* Called after every test case method.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() {
|
protected void tearDown() {
|
||||||
// release resources here and clean-up
|
// release resources here and clean-up
|
||||||
|
@ -168,6 +163,7 @@ public class ErrorParserManagerTest extends TestCase {
|
||||||
assertEquals("no return statement in function returning non-void",problemMarkerInfo.description);
|
assertEquals("no return statement in function returning non-void",problemMarkerInfo.description);
|
||||||
assertEquals(new Path("catchpoints.cpp"),problemMarkerInfo.externalPath);
|
assertEquals(new Path("catchpoints.cpp"),problemMarkerInfo.externalPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParsersSanityTrimmed() throws CoreException, IOException {
|
public void testParsersSanityTrimmed() throws CoreException, IOException {
|
||||||
output(" catchpoints.cpp:12: warning: no return statement in function returning non-void \n");
|
output(" catchpoints.cpp:12: warning: no return statement in function returning non-void \n");
|
||||||
end();
|
end();
|
||||||
|
@ -179,22 +175,20 @@ public class ErrorParserManagerTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOutput() throws IOException {
|
public void testOutput() throws IOException {
|
||||||
FileInputStream fileInputStream = new FileInputStream(CTestPlugin.getDefault().getFileInPlugin(
|
try (FileInputStream fileInputStream = new FileInputStream(CTestPlugin.getDefault().getFileInPlugin(
|
||||||
new Path("resources/errortests/output-1")));
|
new Path("resources/errortests/output-1")))) {
|
||||||
byte b[] = new byte[1024];
|
byte b[] = new byte[1024];
|
||||||
while (true) {
|
while (true) {
|
||||||
int k = fileInputStream.read(b);
|
int k = fileInputStream.read(b);
|
||||||
if (k < 0)
|
if (k < 0)
|
||||||
break;
|
break;
|
||||||
epManager.write(b, 0, k);
|
epManager.write(b, 0, k);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
end();
|
end();
|
||||||
assertEquals(22, errorList.size());
|
assertEquals(22, errorList.size());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String addErrorParserExtension(String shortId, Class cl) {
|
private String addErrorParserExtension(String shortId, Class cl) {
|
||||||
String ext = "<plugin><extension id=\"" + shortId + "\" name=\"" + shortId
|
String ext = "<plugin><extension id=\"" + shortId + "\" name=\"" + shortId
|
||||||
+ "\" point=\"org.eclipse.cdt.core.ErrorParser\">" + "<errorparser class=\"" + cl.getName() + "\"/>"
|
+ "\" point=\"org.eclipse.cdt.core.ErrorParser\">" + "<errorparser class=\"" + cl.getName() + "\"/>"
|
||||||
|
@ -261,6 +255,7 @@ public class ErrorParserManagerTest extends TestCase {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLongLinesParser() throws IOException {
|
public void testLongLinesParser() throws IOException {
|
||||||
String id = addErrorParserExtension("test2", TestParser2.class);
|
String id = addErrorParserExtension("test2", TestParser2.class);
|
||||||
epManager = new ErrorParserManager(cProject.getProject(), markerGenerator, new String[] { id });
|
epManager = new ErrorParserManager(cProject.getProject(), markerGenerator, new String[] { id });
|
||||||
|
@ -279,6 +274,7 @@ public class ErrorParserManagerTest extends TestCase {
|
||||||
// check - line trimmed but long
|
// check - line trimmed but long
|
||||||
assertEquals("a la la 99",end);
|
assertEquals("a la la 99",end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TestParser3 implements IErrorParser2 {
|
public static class TestParser3 implements IErrorParser2 {
|
||||||
@Override
|
@Override
|
||||||
public int getProcessLineBehaviour() {
|
public int getProcessLineBehaviour() {
|
||||||
|
@ -295,6 +291,7 @@ public class ErrorParserManagerTest extends TestCase {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLongLinesUntrimmedParser() throws IOException {
|
public void testLongLinesUntrimmedParser() throws IOException {
|
||||||
String id = addErrorParserExtension("test3", TestParser3.class);
|
String id = addErrorParserExtension("test3", TestParser3.class);
|
||||||
epManager = new ErrorParserManager(cProject.getProject(), markerGenerator, new String[] { id });
|
epManager = new ErrorParserManager(cProject.getProject(), markerGenerator, new String[] { id });
|
||||||
|
@ -317,11 +314,13 @@ public class ErrorParserManagerTest extends TestCase {
|
||||||
public static class TestParser4 implements IErrorParser {
|
public static class TestParser4 implements IErrorParser {
|
||||||
@Override
|
@Override
|
||||||
public boolean processLine(String line, ErrorParserManager eoParser) {
|
public boolean processLine(String line, ErrorParserManager eoParser) {
|
||||||
ProblemMarkerInfo problemMarkerInfo = new ProblemMarkerInfo(null, 0, "Workspace level marker", IMarker.SEVERITY_INFO, null);
|
ProblemMarkerInfo problemMarkerInfo =
|
||||||
|
new ProblemMarkerInfo(null, 0, "Workspace level marker", IMarker.SEVERITY_INFO, null);
|
||||||
eoParser.addProblemMarker(problemMarkerInfo);
|
eoParser.addProblemMarker(problemMarkerInfo);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWorkspaceLevelError() throws IOException {
|
public void testWorkspaceLevelError() throws IOException {
|
||||||
String id = addErrorParserExtension("test4", TestParser4.class);
|
String id = addErrorParserExtension("test4", TestParser4.class);
|
||||||
epManager = new ErrorParserManager(null, markerGenerator, new String[] { id });
|
epManager = new ErrorParserManager(null, markerGenerator, new String[] { id });
|
||||||
|
@ -334,5 +333,4 @@ public class ErrorParserManagerTest extends TestCase {
|
||||||
assertEquals("Workspace level marker", problemMarkerInfo.description);
|
assertEquals("Workspace level marker", problemMarkerInfo.description);
|
||||||
assertTrue(problemMarkerInfo.file instanceof IWorkspaceRoot);
|
assertTrue(problemMarkerInfo.file instanceof IWorkspaceRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue