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());
}
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());
}
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()));
}
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());
}
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);
}
Aggregations