|
25 | 25 | */
|
26 | 26 | package de.fraunhofer.aisec.cpg.graph
|
27 | 27 |
|
| 28 | +import de.fraunhofer.aisec.cpg.frontends.TestLanguageFrontend |
28 | 29 | import de.fraunhofer.aisec.cpg.graph.builder.plus
|
29 | 30 | import de.fraunhofer.aisec.cpg.graph.declarations.FieldDeclaration
|
30 | 31 | import de.fraunhofer.aisec.cpg.graph.edges.flows.CallingContextIn
|
31 | 32 | import de.fraunhofer.aisec.cpg.graph.edges.flows.ContextSensitiveDataflow
|
32 | 33 | import de.fraunhofer.aisec.cpg.graph.edges.flows.PartialDataflowGranularity
|
33 | 34 | import de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression
|
34 |
| -import de.fraunhofer.aisec.cpg.graph.statements.expressions.Literal |
35 |
| -import de.fraunhofer.aisec.cpg.graph.statements.expressions.Reference |
36 | 35 | import kotlin.test.Test
|
37 | 36 | import kotlin.test.assertEquals
|
38 | 37 | import kotlin.test.assertTrue
|
39 | 38 |
|
40 | 39 | class ExpressionBuilderTest {
|
41 | 40 | @Test
|
42 | 41 | fun testDuplicateWithDFGProperties() {
|
43 |
| - val node1 = Literal<Int>() |
44 |
| - val node2 = Reference() |
45 |
| - val granularity = PartialDataflowGranularity(FieldDeclaration()) |
46 |
| - val callingContextIn = CallingContextIn(CallExpression()) |
47 |
| - node1.prevDFGEdges.addContextSensitive(node2, granularity, callingContextIn) |
| 42 | + with(TestLanguageFrontend()) { |
| 43 | + val node1 = newLiteral(42) |
| 44 | + val node2 = newReference("foo") |
| 45 | + val granularity = PartialDataflowGranularity(FieldDeclaration()) |
| 46 | + val callingContextIn = CallingContextIn(CallExpression()) |
| 47 | + node1.prevDFGEdges.addContextSensitive(node2, granularity, callingContextIn) |
48 | 48 |
|
49 |
| - val clone = node1.duplicate(false) |
50 |
| - val clonedPrevDFG = clone.prevDFGEdges.single() |
51 |
| - assertTrue(clonedPrevDFG is ContextSensitiveDataflow) |
52 |
| - assertEquals(callingContextIn, clonedPrevDFG.callingContext) |
53 |
| - assertEquals(granularity, clonedPrevDFG.granularity) |
| 49 | + val clone = node1.duplicate(false) |
| 50 | + val clonedPrevDFG = clone.prevDFGEdges.single() |
| 51 | + assertTrue(clonedPrevDFG is ContextSensitiveDataflow) |
| 52 | + assertEquals(callingContextIn, clonedPrevDFG.callingContext) |
| 53 | + assertEquals(granularity, clonedPrevDFG.granularity) |
54 | 54 |
|
55 |
| - assertEquals(setOf<Node>(node1, clone), node2.nextDFG) |
| 55 | + assertEquals(setOf<Node>(node1, clone), node2.nextDFG) |
| 56 | + } |
56 | 57 | }
|
57 | 58 |
|
58 | 59 | @Test
|
59 | 60 | fun testDuplicateWithDFGProperties2() {
|
60 |
| - val node1 = Literal<Int>() |
61 |
| - val node2 = Reference() |
62 |
| - val granularity = PartialDataflowGranularity(FieldDeclaration()) |
63 |
| - val callingContextIn = CallingContextIn(CallExpression()) |
64 |
| - node1.nextDFGEdges.addContextSensitive(node2, granularity, callingContextIn) |
| 61 | + with(TestLanguageFrontend()) { |
| 62 | + val node1 = newLiteral(42) |
| 63 | + val node2 = newReference("foo") |
| 64 | + val granularity = PartialDataflowGranularity(FieldDeclaration()) |
| 65 | + val callingContextIn = CallingContextIn(CallExpression()) |
| 66 | + node1.nextDFGEdges.addContextSensitive(node2, granularity, callingContextIn) |
65 | 67 |
|
66 |
| - val clone = node1.duplicate(false) |
67 |
| - val clonedPrevDFG = clone.nextDFGEdges.single() |
68 |
| - assertTrue(clonedPrevDFG is ContextSensitiveDataflow) |
69 |
| - assertEquals(callingContextIn, clonedPrevDFG.callingContext) |
70 |
| - assertEquals(granularity, clonedPrevDFG.granularity) |
| 68 | + val clone = node1.duplicate(false) |
| 69 | + val clonedPrevDFG = clone.nextDFGEdges.single() |
| 70 | + assertTrue(clonedPrevDFG is ContextSensitiveDataflow) |
| 71 | + assertEquals(callingContextIn, clonedPrevDFG.callingContext) |
| 72 | + assertEquals(granularity, clonedPrevDFG.granularity) |
71 | 73 |
|
72 |
| - assertEquals(setOf<Node>(node1, clone), node2.prevDFG) |
| 74 | + assertEquals(setOf<Node>(node1, clone), node2.prevDFG) |
| 75 | + } |
73 | 76 | }
|
74 | 77 | }
|
0 commit comments