use of de.fraunhofer.aisec.cpg.graph.statements.IfStatement in project cpg by Fraunhofer-AISEC.
the class CXXLanguageFrontendTest method testIf.
@Test
void testIf() throws Exception {
File file = new File("src/test/resources/if.cpp");
TranslationUnitDeclaration declaration = TestUtils.analyzeAndGetFirstTU(List.of(file), file.getParentFile().toPath(), true);
List<Statement> statements = getStatementsOfFunction(declaration.getDeclarationAs(0, FunctionDeclaration.class));
IfStatement ifStatement = (IfStatement) statements.get(0);
assertNotNull(ifStatement);
assertNotNull(ifStatement.getCondition());
assertEquals("bool", ifStatement.getCondition().getType().getTypeName());
assertEquals(true, ((Literal) ifStatement.getCondition()).getValue());
assertTrue(((CompoundStatement) ifStatement.getThenStatement()).getStatements().get(0) instanceof ReturnStatement);
assertTrue(((CompoundStatement) ifStatement.getElseStatement()).getStatements().get(0) instanceof ReturnStatement);
}
Aggregations