Skip to content

Commit

Permalink
Coverage++
Browse files Browse the repository at this point in the history
  • Loading branch information
KuechA committed Mar 14, 2024
1 parent bc4b101 commit aac8bbc
Showing 1 changed file with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $$$$$$\ $$$$$$$\ $$$$$$\
* $$ __$$\ $$ __$$\ $$ __$$\
* $$ / \__|$$ | $$ |$$ / \__|
* $$ | $$$$$$$ |$$ |$$$$\
* $$ | $$ ____/ $$ |\_$$ |
* $$ | $$\ $$ | $$ | $$ |
* \$$$$$ |$$ | \$$$$$ |
* \______/ \__| \______/
*
*/
package de.fraunhofer.aisec.cpg.graph

import de.fraunhofer.aisec.cpg.graph.declarations.FieldDeclaration
import de.fraunhofer.aisec.cpg.graph.edge.CallingContextIn
import de.fraunhofer.aisec.cpg.graph.edge.ContextsensitiveDataflow
import de.fraunhofer.aisec.cpg.graph.edge.PartialDataflowGranularity
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.Reference
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class ExpressionBuilderTest {
@Test
fun testDuplicateWithDFGProperties() {
val node1 = Literal<Int>()
val node2 = Reference()
val granularity = PartialDataflowGranularity(FieldDeclaration())
val callingContextIn = CallingContextIn(CallExpression())
node1.addPrevDFGContext(node2, callingContextIn, granularity)

val clone = node1.duplicate(false)
val clonedPrevDFG = clone.prevDFGEdges.single()
assertTrue(clonedPrevDFG is ContextsensitiveDataflow)
assertEquals(callingContextIn, clonedPrevDFG.callingContext)
assertEquals(granularity, clonedPrevDFG.granularity)

assertEquals(setOf<Node>(node1, clone), node2.nextDFG)
}

@Test
fun testDuplicateWithDFGProperties2() {
val node1 = Literal<Int>()
val node2 = Reference()
val granularity = PartialDataflowGranularity(FieldDeclaration())
val callingContextIn = CallingContextIn(CallExpression())
node1.addNextDFGContext(node2, callingContextIn, granularity)

val clone = node1.duplicate(false)
val clonedPrevDFG = clone.nextDFGEdges.single()
assertTrue(clonedPrevDFG is ContextsensitiveDataflow)
assertEquals(callingContextIn, clonedPrevDFG.callingContext)
assertEquals(granularity, clonedPrevDFG.granularity)

assertEquals(setOf<Node>(node1, clone), node2.prevDFG)
}
}

0 comments on commit aac8bbc

Please sign in to comment.