Java: convert test to inline expectation

This commit is contained in:
Anders Schack-Mulligen
2022-09-14 10:17:31 +02:00
parent 83e7bf71d7
commit 9f200633ca
3 changed files with 16 additions and 44 deletions

View File

@@ -1,7 +1,7 @@
public class A {
static void sink(Object x) { }
static Object source() { return null; }
static Object source(String srctag) { return null; }
static class C1 {
C1() { }
@@ -20,7 +20,7 @@ public class A {
void foo(Object x) {
Object c1 = x;
sink(c1);
sink(c1); // $ hasValueFlow=c.1 hasValueFlow=c.2 hasValueFlow=c.3 hasValueFlow=C1 hasValueFlow=C1.1 hasValueFlow=C1.2 hasValueFlow=C1.3
}
}
@@ -33,11 +33,11 @@ public class A {
void foo(Object x) {
Object c2 = x;
sink(c2);
sink(c2); // $ hasValueFlow=2 hasValueFlow=c.1 hasValueFlow=c.2 hasValueFlow=c.3 hasValueFlow=C2 hasValueFlow=C2.1 hasValueFlow=C2.2 hasValueFlow=C2.3
}
void callWrapFoo2() {
wrapFoo2(source());
wrapFoo2(source("2"));
}
}
@@ -46,18 +46,18 @@ public class A {
}
void test(C1 c) {
c.wrapFoo1(source());
c.wrapFoo2(source());
wrapFoo3(c, source());
c.wrapFoo1(source("c.1"));
c.wrapFoo2(source("c.2"));
wrapFoo3(c, source("c.3"));
new C1(source());
new C1().wrapFoo1(source());
new C1().wrapFoo2(source());
wrapFoo3(new C1(), source());
new C1(source("C1"));
new C1().wrapFoo1(source("C1.1"));
new C1().wrapFoo2(source("C1.2"));
wrapFoo3(new C1(), source("C1.3"));
new C2(source());
new C2().wrapFoo1(source());
new C2().wrapFoo2(source());
wrapFoo3(new C2(), source());
new C2(source("C2"));
new C2().wrapFoo1(source("C2.1"));
new C2().wrapFoo2(source("C2.2"));
wrapFoo3(new C2(), source("C2.3"));
}
}

View File

@@ -1,15 +0,0 @@
| A.java:40:16:40:23 | source(...) | A.java:36:12:36:13 | c2 |
| A.java:49:16:49:23 | source(...) | A.java:23:12:23:13 | c1 |
| A.java:49:16:49:23 | source(...) | A.java:36:12:36:13 | c2 |
| A.java:50:16:50:23 | source(...) | A.java:23:12:23:13 | c1 |
| A.java:50:16:50:23 | source(...) | A.java:36:12:36:13 | c2 |
| A.java:51:17:51:24 | source(...) | A.java:23:12:23:13 | c1 |
| A.java:51:17:51:24 | source(...) | A.java:36:12:36:13 | c2 |
| A.java:53:12:53:19 | source(...) | A.java:23:12:23:13 | c1 |
| A.java:54:23:54:30 | source(...) | A.java:23:12:23:13 | c1 |
| A.java:55:23:55:30 | source(...) | A.java:23:12:23:13 | c1 |
| A.java:56:24:56:31 | source(...) | A.java:23:12:23:13 | c1 |
| A.java:58:12:58:19 | source(...) | A.java:36:12:36:13 | c2 |
| A.java:59:23:59:30 | source(...) | A.java:36:12:36:13 | c2 |
| A.java:60:23:60:30 | source(...) | A.java:36:12:36:13 | c2 |
| A.java:61:24:61:31 | source(...) | A.java:36:12:36:13 | c2 |

View File

@@ -1,15 +1,2 @@
import java
import semmle.code.java.dataflow.DataFlow
import DataFlow
class Conf extends Configuration {
Conf() { this = "qqconf" }
override predicate isSource(Node n) { n.asExpr().(MethodAccess).getMethod().hasName("source") }
override predicate isSink(Node n) { n.asExpr().(Argument).getCall().getCallee().hasName("sink") }
}
from Node src, Node sink, Conf c
where c.hasFlow(src, sink)
select src, sink
import TestUtilities.InlineFlowTest