Skip to content

Commit

Permalink
Add test case for inference test of parent class
Browse files Browse the repository at this point in the history
  • Loading branch information
peckto committed Dec 12, 2024
1 parent cc094be commit dedce78
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ import de.fraunhofer.aisec.cpg.graph.scopes.GlobalScope
import de.fraunhofer.aisec.cpg.graph.types.BooleanType
import de.fraunhofer.aisec.cpg.test.*
import java.io.File
import kotlin.test.Test
import kotlin.test.assertContains
import kotlin.test.assertEquals
import kotlin.test.assertIs
import kotlin.test.assertIsNot
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlin.test.*

class CXXInferenceTest {
@Test
Expand Down Expand Up @@ -199,4 +193,32 @@ class CXXInferenceTest {
assertEquals(pairType, pair.returnTypes.singleOrNull())
}
}

@Test
fun testInferParentClassInNamespace() {
val file = File("src/test/resources/cxx/inference/parent_inference.cpp")
val tu =
analyzeAndGetFirstTU(listOf(file), file.parentFile.toPath(), true) {
it.registerLanguage<CPPLanguage>()
it.loadIncludes(false)
it.addIncludesToGraph(false)
}
assertNotNull(tu)

val util = tu.namespaces["ABC"]
assertNotNull(util)

val recordABCA = util.records["A"]
assertNotNull(recordABCA)
assertTrue(recordABCA.isInferred)

val recordA = tu.records["A"]
assertNotNull(recordA)
val funcFoo = recordA.functions["foo"]
assertNotNull(funcFoo)
assertTrue(funcFoo.isInferred)
val funcBar = recordA.functions["bar"]
assertNotNull(funcBar)
assertFalse(funcBar.isInferred)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
namespace ABC {
struct A {
A();
void foo();
};
}
*/

struct A : ABC::A {
A() {
foo();
bar();
}
void bar() {

}
};

0 comments on commit dedce78

Please sign in to comment.