Skip to content

Commit

Permalink
Asserted data flow in field
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Jan 2, 2024
1 parent 42c79c2 commit 83029e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ package de.fraunhofer.aisec.cpg.frontends
import de.fraunhofer.aisec.cpg.TestUtils
import de.fraunhofer.aisec.cpg.TestUtils.assertInvokes
import de.fraunhofer.aisec.cpg.assertFullName
import de.fraunhofer.aisec.cpg.assertLiteralValue
import de.fraunhofer.aisec.cpg.assertLocalName
import de.fraunhofer.aisec.cpg.graph.*
import de.fraunhofer.aisec.cpg.graph.declarations.FieldDeclaration
import de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression
import de.fraunhofer.aisec.cpg.graph.statements.expressions.Literal
import de.fraunhofer.aisec.cpg.graph.statements.expressions.MemberCallExpression
import de.fraunhofer.aisec.cpg.graph.statements.expressions.MemberExpression
import de.fraunhofer.aisec.cpg.passes.EdgeCachePass
Expand Down Expand Up @@ -196,6 +199,19 @@ class JVMLanguageFrontendTest {
"${it.name} should not be resolved to an inferred node"
)
}

val setACall = tu.calls["setA"]
assertNotNull(setACall)

val lit10 = setACall.arguments.firstOrNull()
assertIs<Literal<Int>>(lit10)
assertLiteralValue(10, lit10)

// We should be able to follow the literal back to it's write to the field
val result =
lit10.followNextDFGEdgesUntilHit { it is FieldDeclaration && it.name.localName == "a" }
assertNotNull(result)
assertEquals(1, result.fulfilled.size)
}

@Disabled
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public void setA(int a) {
}

private void resetA() {
this.a = 10;
setA(10);
}
}

0 comments on commit 83029e4

Please sign in to comment.