-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Call Site and Call Graph Tests (#56)
* Call site and call graph test * Set correct CPG version * 🐛 Fixed incorrect call edge source bug on assignment vertex and created naive call edges if no call edge was produced by Soot * 🎨 Cleaned up code a bit Co-authored-by: David Baker Effendi <[email protected]>
- Loading branch information
1 parent
3764888
commit 2b4a848
Showing
6 changed files
with
121 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
testing/src/test/scala/io/github/plume/oss/querying/CallTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.github.plume.oss.querying | ||
|
||
import io.github.plume.oss.PlumeCodeToCpgSuite | ||
import io.shiftleft.codepropertygraph.generated.{Operators, nodes} | ||
import io.shiftleft.semanticcpg.language.NoResolve | ||
import io.shiftleft.semanticcpg.language._ | ||
|
||
class CallTests extends PlumeCodeToCpgSuite { | ||
|
||
implicit val resolver = NoResolve | ||
|
||
override val code = """ | ||
class Foo { | ||
int add(int x, int y) { | ||
return x + y; | ||
} | ||
int main(int argc, char argv) { | ||
return add(argc, 3); | ||
} | ||
} | ||
""" | ||
|
||
"should contain a call node for `add` with correct fields" in { | ||
val List(x) = cpg.call("add").l | ||
x.code shouldBe "add(argc, 3)" | ||
x.name shouldBe "add" | ||
x.order shouldBe 1 | ||
x.methodInstFullName shouldBe None // Deprecated | ||
x.methodFullName shouldBe "Foo: int add(int,int)" | ||
x.argumentIndex shouldBe 1 | ||
// TODO x.signature | ||
// x.typeFullName : deprecated | ||
x.lineNumber shouldBe Some(8) | ||
} | ||
|
||
"should allow traversing from call to arguments" in { | ||
cpg.call("add").argument.size shouldBe 2 | ||
|
||
val List(arg1) = cpg.call("add").argument(1).l | ||
arg1.isInstanceOf[nodes.Identifier] shouldBe true | ||
arg1.asInstanceOf[nodes.Identifier].name shouldBe "argc" | ||
arg1.code shouldBe "argc" | ||
arg1.order shouldBe 1 | ||
arg1.argumentIndex shouldBe 1 | ||
|
||
val List(arg2) = cpg.call("add").argument(2).l | ||
arg2.isInstanceOf[nodes.Literal] shouldBe true | ||
arg2.asInstanceOf[nodes.Literal].code shouldBe "3" | ||
arg2.code shouldBe "3" | ||
arg2.order shouldBe 2 | ||
arg2.argumentIndex shouldBe 2 | ||
} | ||
|
||
"should allow traversing from call to surrounding method" in { | ||
val List(x) = cpg.call("add").method.l | ||
x.name shouldBe "main" | ||
} | ||
|
||
"should allow traversing from call to callee method" in { | ||
val List(x) = cpg.call("add").callee.l | ||
x.name shouldBe "add" | ||
} | ||
|
||
"should allow traversing from argument to parameter" in { | ||
val List(x) = cpg.call("add").argument(1).parameter.l | ||
x.name shouldBe "x" | ||
} | ||
|
||
} |