use of de.fraunhofer.aisec.cpg.graph.statements.CaseStatement in project cpg by Fraunhofer-AISEC.
the class CXXLanguageFrontendTest method testSwitch.
@Test
void testSwitch() throws Exception {
File file = new File("src/test/resources/cfg/switch.cpp");
TranslationUnitDeclaration declaration = TestUtils.analyzeAndGetFirstTU(List.of(file), file.getParentFile().toPath(), true);
List<Node> graphNodes = SubgraphWalker.flattenAST(declaration);
graphNodes.sort(new NodeComparator());
assertTrue(graphNodes.size() != 0);
List<SwitchStatement> switchStatements = Util.filterCast(graphNodes, SwitchStatement.class);
assertTrue(switchStatements.size() == 3);
SwitchStatement switchStatement = switchStatements.get(0);
assertTrue(((CompoundStatement) switchStatement.getStatement()).getStatements().size() == 11);
List<CaseStatement> caseStatements = Util.filterCast(SubgraphWalker.flattenAST(switchStatement), CaseStatement.class);
assertTrue(caseStatements.size() == 4);
List<DefaultStatement> defaultStatements = Util.filterCast(SubgraphWalker.flattenAST(switchStatement), DefaultStatement.class);
assertTrue(defaultStatements.size() == 1);
}
Aggregations