mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Cosmetics.
This commit is contained in:
parent
82fb03e1a0
commit
db6b4cf5ac
2 changed files with 42 additions and 55 deletions
|
@ -16,14 +16,9 @@ import org.eclipse.cdt.codan.core.test.CheckerTestCase;
|
||||||
import org.eclipse.cdt.codan.internal.checkers.CaseBreakChecker;
|
import org.eclipse.cdt.codan.internal.checkers.CaseBreakChecker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link#CaseBreakChecker} class
|
* Test for {@link CaseBreakChecker} class
|
||||||
*/
|
*/
|
||||||
public class CaseBreakCheckerTest extends CheckerTestCase {
|
public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.cdt.codan.core.test.CodanTestCase#setUp()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
@ -34,7 +29,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a;
|
// int a;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
@ -45,7 +40,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a;
|
// int a;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// default:
|
// default:
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
@ -56,7 +51,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a, b;
|
// int a, b;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// b = 2;
|
// b = 2;
|
||||||
// }
|
// }
|
||||||
|
@ -68,7 +63,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a, b;
|
// int a, b;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// case 2:
|
// case 2:
|
||||||
// b = 2;
|
// b = 2;
|
||||||
|
@ -83,7 +78,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a;
|
// int a;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
|
@ -95,7 +90,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a;
|
// int a;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
@ -107,7 +102,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(int a) {
|
// void foo(int a) {
|
||||||
// while (a--)
|
// while (a--)
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// continue;
|
// continue;
|
||||||
// }
|
// }
|
||||||
|
@ -119,7 +114,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(int a) {
|
// void foo(int a) {
|
||||||
//
|
//
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// throw 1;
|
// throw 1;
|
||||||
// }
|
// }
|
||||||
|
@ -131,7 +126,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a, b;
|
// int a, b;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// b = 2;
|
// b = 2;
|
||||||
// break;
|
// break;
|
||||||
|
@ -144,7 +139,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a, b;
|
// int a, b;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// break;
|
// break;
|
||||||
// case 2:
|
// case 2:
|
||||||
|
@ -159,7 +154,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a;
|
// int a;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// /* no break */
|
// /* no break */
|
||||||
// }
|
// }
|
||||||
|
@ -170,7 +165,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// void foo(int a, int b) {
|
// void foo(int a, int b) {
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// switch (b) {
|
// switch (b) {
|
||||||
// case 2:
|
// case 2:
|
||||||
|
@ -187,7 +182,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a, b;
|
// int a, b;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// b = 2;
|
// b = 2;
|
||||||
// /* no break */
|
// /* no break */
|
||||||
|
@ -200,7 +195,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a, b;
|
// int a, b;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// /* no break */
|
// /* no break */
|
||||||
// case 2:
|
// case 2:
|
||||||
|
@ -214,7 +209,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a, b;
|
// int a, b;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// b = 2;
|
// b = 2;
|
||||||
// /* no break */
|
// /* no break */
|
||||||
|
@ -228,7 +223,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a, b;
|
// int a, b;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// b = 2;
|
// b = 2;
|
||||||
// /* no break */
|
// /* no break */
|
||||||
|
@ -259,14 +254,14 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a, b;
|
// int a, b;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1: //err
|
// case 1: //err
|
||||||
// // lolo
|
// // lolo
|
||||||
// case 2: //err
|
// case 2: //err
|
||||||
// case 3://err
|
// case 3://err
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// b = 2; // err
|
// b = 2; // err
|
||||||
// // lolo
|
// // lolo
|
||||||
|
@ -279,7 +274,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
// case 6: // err
|
// case 6: // err
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// b = 2; // err
|
// b = 2; // err
|
||||||
// // lolo
|
// // lolo
|
||||||
|
@ -301,7 +296,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
// b = 2;//err
|
// b = 2;//err
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// b = 2; // err
|
// b = 2; // err
|
||||||
// // lolo
|
// // lolo
|
||||||
|
@ -319,7 +314,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a, b;
|
// int a, b;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// b = 2;
|
// b = 2;
|
||||||
// // lolo
|
// // lolo
|
||||||
|
@ -349,7 +344,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a, b;
|
// int a, b;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 0:
|
// case 0:
|
||||||
// switch( b ) {
|
// switch( b ) {
|
||||||
// case 2: // err
|
// case 2: // err
|
||||||
|
@ -385,7 +380,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a, b;
|
// int a, b;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// b = 2;
|
// b = 2;
|
||||||
// }
|
// }
|
||||||
|
@ -399,7 +394,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a, b;
|
// int a, b;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// case 2:
|
// case 2:
|
||||||
// b = 2;
|
// b = 2;
|
||||||
|
@ -417,7 +412,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a;
|
// int a;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
@ -443,7 +438,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// void foo(int a) {
|
// void foo(int a) {
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1:
|
// case 1:
|
||||||
// while (a--)
|
// while (a--)
|
||||||
// break; // err
|
// break; // err
|
||||||
|
@ -459,7 +454,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// void foo(int a) {
|
// void foo(int a) {
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 1: {
|
// case 1: {
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
|
@ -476,7 +471,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// void foo(void) {
|
// void foo(void) {
|
||||||
// int a;
|
// int a;
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 2:
|
// case 2:
|
||||||
// break;
|
// break;
|
||||||
// case 1:
|
// case 1:
|
||||||
|
@ -494,7 +489,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// void foo(int a) {
|
// void foo(int a) {
|
||||||
// switch( a ) {
|
// switch (a) {
|
||||||
// case 2:
|
// case 2:
|
||||||
// if (a*2<10)
|
// if (a*2<10)
|
||||||
// return;
|
// return;
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class CheckerTestCase extends CodanTestCase {
|
||||||
for (Object i : errLines) {
|
for (Object i : errLines) {
|
||||||
checkErrorLine((Integer) i);
|
checkErrorLine((Integer) i);
|
||||||
}
|
}
|
||||||
assertEquals("Expected number of errors "+errLines.size(),errLines.size(), markers.length);
|
assertEquals("Expected number of errors " + errLines.size(),errLines.size(), markers.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMarker checkErrorLine(int i, String problemId) {
|
public IMarker checkErrorLine(int i, String problemId) {
|
||||||
|
@ -90,7 +90,7 @@ public class CheckerTestCase extends CodanTestCase {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertEquals("Error on line "+expectedLine+" is not found",Integer.valueOf(expectedLine), line);
|
assertEquals("Error on line " + expectedLine + " is not found", Integer.valueOf(expectedLine), line);
|
||||||
if (file != null)
|
if (file != null)
|
||||||
assertEquals(file.getName(), mfile);
|
assertEquals(file.getName(), mfile);
|
||||||
assertTrue(found);
|
assertTrue(found);
|
||||||
|
@ -120,18 +120,13 @@ public class CheckerTestCase extends CodanTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkNoErrors() {
|
public void checkNoErrors() {
|
||||||
if (markers == null || markers.length == 0) {
|
if (markers != null && markers.length > 0) {
|
||||||
// all good
|
|
||||||
} else {
|
|
||||||
IMarker m = markers[0];
|
IMarker m = markers[0];
|
||||||
fail("Found " + markers.length + " errors but should not. First " + CodanProblemMarker.getProblemId(m) + " at line "
|
fail("Found " + markers.length + " errors but should not. First " +
|
||||||
+ getLine(m));
|
CodanProblemMarker.getProblemId(m) + " at line " + getLine(m));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void runOnProject() {
|
public void runOnProject() {
|
||||||
try {
|
try {
|
||||||
indexFiles();
|
indexFiles();
|
||||||
|
@ -151,9 +146,6 @@ public class CheckerTestCase extends CodanTestCase {
|
||||||
runCodan();
|
runCodan();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
protected void runCodan() {
|
protected void runCodan() {
|
||||||
CodanRuntime.getInstance().getBuilder().processResource(cproject.getProject(), new NullProgressMonitor());
|
CodanRuntime.getInstance().getBuilder().processResource(cproject.getProject(), new NullProgressMonitor());
|
||||||
try {
|
try {
|
||||||
|
@ -169,8 +161,9 @@ public class CheckerTestCase extends CodanTestCase {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected IProblemPreference getPreference(String problemId, String paramId) {
|
protected IProblemPreference getPreference(String problemId, String paramId) {
|
||||||
IProblem problem = CodanRuntime.getInstance().getCheckersRegistry().getResourceProfile(cproject.getResource())
|
IProblemProfile resourceProfile =
|
||||||
.findProblem(problemId);
|
CodanRuntime.getInstance().getCheckersRegistry().getResourceProfile(cproject.getResource());
|
||||||
|
IProblem problem = resourceProfile.findProblem(problemId);
|
||||||
IProblemPreference pref = ((MapProblemPreference) problem.getPreference()).getChildDescriptor(paramId);
|
IProblemPreference pref = ((MapProblemPreference) problem.getPreference()).getChildDescriptor(paramId);
|
||||||
return pref;
|
return pref;
|
||||||
}
|
}
|
||||||
|
@ -219,8 +212,8 @@ public class CheckerTestCase extends CodanTestCase {
|
||||||
String pid = ids[j];
|
String pid = ids[j];
|
||||||
if (p.getId().equals(pid)) {
|
if (p.getId().equals(pid)) {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
// Force the launch mode to FULL_BUILD to make sure we can test the problem even if by default it
|
// Force the launch mode to FULL_BUILD to make sure we can test the problem even
|
||||||
// is not set to run on FULL_BUILD
|
// if by default it is not set to run on FULL_BUILD.
|
||||||
IProblemPreference preference = p.getPreference();
|
IProblemPreference preference = p.getPreference();
|
||||||
if (preference instanceof RootProblemPreference) {
|
if (preference instanceof RootProblemPreference) {
|
||||||
RootProblemPreference rootProblemPreference = (RootProblemPreference) preference;
|
RootProblemPreference rootProblemPreference = (RootProblemPreference) preference;
|
||||||
|
@ -232,6 +225,5 @@ public class CheckerTestCase extends CodanTestCase {
|
||||||
((CodanProblem) p).setEnabled(enabled);
|
((CodanProblem) p).setEnabled(enabled);
|
||||||
}
|
}
|
||||||
CodanRuntime.getInstance().getCheckersRegistry().updateProfile(cproject.getProject(), profile);
|
CodanRuntime.getInstance().getCheckersRegistry().updateProfile(cproject.getProject(), profile);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue