mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
- added test check
This commit is contained in:
parent
506daf12cd
commit
6d33ab23a6
1 changed files with 37 additions and 2 deletions
|
@ -10,9 +10,13 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.cfg;
|
package org.eclipse.cdt.codan.core.cfg;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.cxx.internal.model.cfg.ControlFlowGraphBuilder;
|
import org.eclipse.cdt.codan.core.cxx.internal.model.cfg.ControlFlowGraphBuilder;
|
||||||
import org.eclipse.cdt.codan.core.test.CodanTestCase;
|
import org.eclipse.cdt.codan.core.test.CodanTestCase;
|
||||||
import org.eclipse.cdt.codan.internal.core.cfg.ControlFlowGraph;
|
import org.eclipse.cdt.codan.internal.core.cfg.ControlFlowGraph;
|
||||||
|
import org.eclipse.cdt.codan.provisional.core.model.cfg.IBasicBlock;
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
|
@ -25,7 +29,6 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.Path;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: add description
|
* TODO: add description
|
||||||
|
@ -73,7 +76,7 @@ public class ControlFlowGraphTest extends CodanTestCase {
|
||||||
}
|
}
|
||||||
void buildCfg() {
|
void buildCfg() {
|
||||||
try {
|
try {
|
||||||
Path path = new Path(currentFile.toString());
|
|
||||||
IResource el = cproject.getProject().findMember(currentFile.getName());
|
IResource el = cproject.getProject().findMember(currentFile.getName());
|
||||||
processFile((IFile) el);
|
processFile((IFile) el);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -88,8 +91,40 @@ public class ControlFlowGraphTest extends CodanTestCase {
|
||||||
private void checkCfg() {
|
private void checkCfg() {
|
||||||
assertNotNull(graph);
|
assertNotNull(graph);
|
||||||
assertNotNull(graph.getStartNode());
|
assertNotNull(graph.getStartNode());
|
||||||
|
Collection<IBasicBlock> nodes = graph.getNodes();
|
||||||
|
for (Iterator<IBasicBlock> iterator = nodes.iterator(); iterator.hasNext();) {
|
||||||
|
IBasicBlock node = iterator.next();
|
||||||
|
checkNode(node);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param node
|
||||||
|
*/
|
||||||
|
private void checkNode(IBasicBlock node) {
|
||||||
|
for (Iterator<IBasicBlock> iterator = node.getIncomingIterator(); iterator.hasNext();) {
|
||||||
|
IBasicBlock b = iterator.next();
|
||||||
|
if (!contains(node, b.getOutgoingIterator()))
|
||||||
|
fail("Block "+node+" inc "+b);
|
||||||
|
}
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param node
|
||||||
|
* @param outgoingIterator
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean contains(IBasicBlock node,
|
||||||
|
Iterator<IBasicBlock> iterator) {
|
||||||
|
for (; iterator.hasNext();) {
|
||||||
|
IBasicBlock b = iterator.next();
|
||||||
|
if (b.equals(node)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
<code file="test1.c">
|
<code file="test1.c">
|
||||||
main() {
|
main() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue