Search in sources :

Example 1 with ValueDeclaration

use of de.fraunhofer.aisec.cpg.graph.declarations.ValueDeclaration in project cpg by Fraunhofer-AISEC.

the class TypedefTest method testMultiple.

@Test
void testMultiple() throws Exception {
    List<TranslationUnitDeclaration> result = TestUtils.analyze("cpp", topLevel, true);
    List<ValueDeclaration> variables = TestUtils.subnodesOfType(result, ValueDeclaration.class);
    // simple type
    ValueDeclaration i1 = TestUtils.findByUniqueName(variables, "i1");
    ValueDeclaration i2 = TestUtils.findByUniqueName(variables, "i2");
    assertEquals(i1.getType(), i2.getType());
    // array
    ValueDeclaration a1 = TestUtils.findByUniqueName(variables, "a1");
    ValueDeclaration a2 = TestUtils.findByUniqueName(variables, "a2");
    assertEquals(a1.getType(), a2.getType());
    // pointer
    ValueDeclaration intPtr1 = TestUtils.findByUniqueName(variables, "intPtr1");
    ValueDeclaration intPtr2 = TestUtils.findByUniqueName(variables, "intPtr2");
    assertEquals(intPtr1.getType(), intPtr2.getType());
    // function pointer
    ValueDeclaration fPtr1 = TestUtils.findByUniqueName(variables, "intFptr1");
    ValueDeclaration fPtr2 = TestUtils.findByUniqueName(variables, "intFptr2");
    assertEquals(fPtr1.getType(), fPtr2.getType());
}
Also used : ValueDeclaration(de.fraunhofer.aisec.cpg.graph.declarations.ValueDeclaration) TranslationUnitDeclaration(de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration) Test(org.junit.jupiter.api.Test) BaseTest(de.fraunhofer.aisec.cpg.BaseTest)

Example 2 with ValueDeclaration

use of de.fraunhofer.aisec.cpg.graph.declarations.ValueDeclaration in project cpg by Fraunhofer-AISEC.

the class TypedefTest method testMemberTypeDef.

@Test
void testMemberTypeDef() throws Exception {
    List<TranslationUnitDeclaration> result = TestUtils.analyze("cpp", topLevel, true);
    List<ValueDeclaration> variables = TestUtils.subnodesOfType(result, ValueDeclaration.class);
    List<RecordDeclaration> records = TestUtils.subnodesOfType(result, RecordDeclaration.class);
    RecordDeclaration addConst = TestUtils.findByUniqueName(records, "add_const");
    ValueDeclaration typeMember1 = TestUtils.findByUniqueName(addConst.getFields(), "typeMember1");
    ValueDeclaration typeMember2 = TestUtils.findByUniqueName(addConst.getFields(), "typeMember2");
    assertEquals(typeMember1.getType(), typeMember2.getType());
    ValueDeclaration typeMemberOutside = TestUtils.findByUniqueName(variables, "typeMemberOutside");
    assertNotEquals(typeMemberOutside.getType(), typeMember2.getType());
    ValueDeclaration cptr1 = TestUtils.findByUniqueName(variables, "cptr1");
    ValueDeclaration cptr2 = TestUtils.findByUniqueName(variables, "cptr2");
    assertEquals(cptr1.getType(), cptr2.getType());
    assertNotEquals(typeMemberOutside.getType(), cptr2.getType());
}
Also used : RecordDeclaration(de.fraunhofer.aisec.cpg.graph.declarations.RecordDeclaration) ValueDeclaration(de.fraunhofer.aisec.cpg.graph.declarations.ValueDeclaration) TranslationUnitDeclaration(de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration) Test(org.junit.jupiter.api.Test) BaseTest(de.fraunhofer.aisec.cpg.BaseTest)

Example 3 with ValueDeclaration

use of de.fraunhofer.aisec.cpg.graph.declarations.ValueDeclaration in project cpg by Fraunhofer-AISEC.

the class TypedefTest method testWithModifier.

@Test
void testWithModifier() throws Exception {
    List<TranslationUnitDeclaration> result = TestUtils.analyze("cpp", topLevel, true);
    List<ValueDeclaration> variables = TestUtils.subnodesOfType(result, ValueDeclaration.class);
    // pointer
    ValueDeclaration l1ptr = TestUtils.findByUniqueName(variables, "l1ptr");
    ValueDeclaration l2ptr = TestUtils.findByUniqueName(variables, "l2ptr");
    ValueDeclaration l3ptr = TestUtils.findByUniqueName(variables, "l3ptr");
    ValueDeclaration l4ptr = TestUtils.findByUniqueName(variables, "l4ptr");
    assertEquals(l1ptr.getType(), l2ptr.getType());
    assertEquals(l1ptr.getType(), l3ptr.getType());
    assertEquals(l1ptr.getType(), l4ptr.getType());
    // arrays
    ValueDeclaration l1arr = TestUtils.findByUniqueName(variables, "l1arr");
    ValueDeclaration l2arr = TestUtils.findByUniqueName(variables, "l2arr");
    ValueDeclaration l3arr = TestUtils.findByUniqueName(variables, "l3arr");
    ValueDeclaration l4arr = TestUtils.findByUniqueName(variables, "l4arr");
    assertTrue(TypeManager.getInstance().checkArrayAndPointer(l1arr.getType(), l2arr.getType()));
    assertTrue(TypeManager.getInstance().checkArrayAndPointer(l1arr.getType(), l3arr.getType()));
    assertTrue(TypeManager.getInstance().checkArrayAndPointer(l1arr.getType(), l4arr.getType()));
}
Also used : ValueDeclaration(de.fraunhofer.aisec.cpg.graph.declarations.ValueDeclaration) TranslationUnitDeclaration(de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration) Test(org.junit.jupiter.api.Test) BaseTest(de.fraunhofer.aisec.cpg.BaseTest)

Example 4 with ValueDeclaration

use of de.fraunhofer.aisec.cpg.graph.declarations.ValueDeclaration in project cpg by Fraunhofer-AISEC.

the class TypedefTest method testStructs.

@Test
void testStructs() throws Exception {
    List<TranslationUnitDeclaration> result = TestUtils.analyze("cpp", topLevel, true);
    List<ValueDeclaration> variables = TestUtils.subnodesOfType(result, ValueDeclaration.class);
    ValueDeclaration ps1 = TestUtils.findByUniqueName(variables, "ps1");
    ValueDeclaration ps2 = TestUtils.findByUniqueName(variables, "ps2");
    assertEquals(ps1.getType(), ps2.getType());
}
Also used : ValueDeclaration(de.fraunhofer.aisec.cpg.graph.declarations.ValueDeclaration) TranslationUnitDeclaration(de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration) Test(org.junit.jupiter.api.Test) BaseTest(de.fraunhofer.aisec.cpg.BaseTest)

Example 5 with ValueDeclaration

use of de.fraunhofer.aisec.cpg.graph.declarations.ValueDeclaration in project cpg by Fraunhofer-AISEC.

the class VariableResolverJavaTest method testReferenceToParameter.

@Test
void testReferenceToParameter() {
    ValueDeclaration param = TestUtils.getSubnodeOfTypeWithName(outerFunction2, ParamVariableDeclaration.class, "varName");
    VRUtil.assertUsageOf(callParamMap.get("func2_param_varName"), param);
}
Also used : ValueDeclaration(de.fraunhofer.aisec.cpg.graph.declarations.ValueDeclaration) BaseTest(de.fraunhofer.aisec.cpg.BaseTest) Test(org.junit.jupiter.api.Test)

Aggregations

BaseTest (de.fraunhofer.aisec.cpg.BaseTest)8 ValueDeclaration (de.fraunhofer.aisec.cpg.graph.declarations.ValueDeclaration)8 Test (org.junit.jupiter.api.Test)8 TranslationUnitDeclaration (de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration)7 RecordDeclaration (de.fraunhofer.aisec.cpg.graph.declarations.RecordDeclaration)1