From aac8bbc0aa0ab1bd663c21dd5993d193ed6cec2a Mon Sep 17 00:00:00 2001 From: Alexander Kuechler Date: Thu, 14 Mar 2024 15:57:24 +0100 Subject: [PATCH] Coverage++ --- .../aisec/cpg/graph/ExpressionBuilderTest.kt | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/graph/ExpressionBuilderTest.kt diff --git a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/graph/ExpressionBuilderTest.kt b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/graph/ExpressionBuilderTest.kt new file mode 100644 index 0000000000..03298eb79f --- /dev/null +++ b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/graph/ExpressionBuilderTest.kt @@ -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() + 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(node1, clone), node2.nextDFG) + } + + @Test + fun testDuplicateWithDFGProperties2() { + val node1 = Literal() + 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(node1, clone), node2.prevDFG) + } +}