Skip to content

Commit 096509b

Browse files
Generate tests and stubs
1 parent 3bcb46f commit 096509b

23 files changed

+860
-792
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package generatedtest;
2+
3+
import com.google.common.cache.Cache;
4+
import com.google.common.cache.LoadingCache;
5+
import com.google.common.collect.ImmutableMap;
6+
import java.util.Map;
7+
import java.util.concurrent.ConcurrentMap;
8+
9+
// Test case generated by GenerateFlowTestCase.ql
10+
public class Test {
11+
12+
Object getMapKey(Object container) { return null; }
13+
Object getMapValue(Object container) { return null; }
14+
Object newWithElement(Object element) { return null; }
15+
Object newWithMapKey(Object element) { return null; }
16+
Object newWithMapValue(Object element) { return null; }
17+
Object source() { return null; }
18+
void sink(Object o) { }
19+
20+
public void test() throws Exception {
21+
22+
{
23+
// "com.google.common.cache;Cache;true;asMap;();;MapKey of Argument[-1];MapKey of ReturnValue;value"
24+
ConcurrentMap out = null;
25+
LoadingCache in = (LoadingCache)newWithMapKey(source());
26+
out = in.asMap();
27+
sink(getMapKey(out)); // $ hasValueFlow
28+
}
29+
{
30+
// "com.google.common.cache;Cache;true;asMap;();;MapKey of Argument[-1];MapKey of ReturnValue;value"
31+
ConcurrentMap out = null;
32+
Cache in = (Cache)newWithMapKey(source());
33+
out = in.asMap();
34+
sink(getMapKey(out)); // $ hasValueFlow
35+
}
36+
{
37+
// "com.google.common.cache;Cache;true;asMap;();;MapValue of Argument[-1];MapValue of ReturnValue;value"
38+
ConcurrentMap out = null;
39+
LoadingCache in = (LoadingCache)newWithMapValue(source());
40+
out = in.asMap();
41+
sink(getMapValue(out)); // $ hasValueFlow
42+
}
43+
{
44+
// "com.google.common.cache;Cache;true;asMap;();;MapValue of Argument[-1];MapValue of ReturnValue;value"
45+
ConcurrentMap out = null;
46+
Cache in = (Cache)newWithMapValue(source());
47+
out = in.asMap();
48+
sink(getMapValue(out)); // $ hasValueFlow
49+
}
50+
{
51+
// "com.google.common.cache;Cache;true;get;(Object,Callable);;MapValue of Argument[-1];ReturnValue;value"
52+
Object out = null;
53+
Cache in = (Cache)newWithMapValue(source());
54+
out = in.get(null, null);
55+
sink(out); // $ hasValueFlow
56+
}
57+
{
58+
// "com.google.common.cache;Cache;true;getAllPresent;(Iterable);;MapValue of Argument[-1];MapValue of ReturnValue;value"
59+
ImmutableMap out = null;
60+
Cache in = (Cache)newWithMapValue(source());
61+
out = in.getAllPresent(null);
62+
sink(getMapValue(out)); // $ hasValueFlow
63+
}
64+
{
65+
// "com.google.common.cache;Cache;true;getIfPresent;(Object);;MapValue of Argument[-1];ReturnValue;value"
66+
Object out = null;
67+
Cache in = (Cache)newWithMapValue(source());
68+
out = in.getIfPresent(null);
69+
sink(out); // $ hasValueFlow
70+
}
71+
{
72+
// "com.google.common.cache;Cache;true;put;(Object,Object);;Argument[0];MapKey of Argument[-1];value"
73+
Cache out = null;
74+
Object in = (Object)source();
75+
out.put(in, null);
76+
sink(getMapKey(out)); // $ hasValueFlow
77+
}
78+
{
79+
// "com.google.common.cache;Cache;true;put;(Object,Object);;Argument[1];MapValue of Argument[-1];value"
80+
Cache out = null;
81+
Object in = (Object)source();
82+
out.put(null, in);
83+
sink(getMapValue(out)); // $ hasValueFlow
84+
}
85+
{
86+
// "com.google.common.cache;Cache;true;putAll;(Map);;MapKey of Argument[0];MapKey of Argument[-1];value"
87+
Cache out = null;
88+
Map in = (Map)newWithMapKey(source());
89+
out.putAll(in);
90+
sink(getMapKey(out)); // $ hasValueFlow
91+
}
92+
{
93+
// "com.google.common.cache;Cache;true;putAll;(Map);;MapValue of Argument[0];MapValue of Argument[-1];value"
94+
Cache out = null;
95+
Map in = (Map)newWithMapValue(source());
96+
out.putAll(in);
97+
sink(getMapValue(out)); // $ hasValueFlow
98+
}
99+
{
100+
// "com.google.common.cache;LoadingCache;true;apply;(Object);;MapValue of Argument[-1];ReturnValue;value"
101+
Object out = null;
102+
LoadingCache in = (LoadingCache)newWithMapValue(source());
103+
out = in.apply(null);
104+
sink(out); // $ hasValueFlow
105+
}
106+
{
107+
// "com.google.common.cache;LoadingCache;true;get;(Object);;MapValue of Argument[-1];ReturnValue;value"
108+
Object out = null;
109+
LoadingCache in = (LoadingCache)newWithMapValue(source());
110+
out = in.get(null);
111+
sink(out); // $ hasValueFlow
112+
}
113+
{
114+
// "com.google.common.cache;LoadingCache;true;getAll;(Iterable);;Element of Argument[0];MapKey of ReturnValue;value"
115+
ImmutableMap out = null;
116+
Iterable in = (Iterable)newWithElement(source());
117+
LoadingCache instance = null;
118+
out = instance.getAll(in);
119+
sink(getMapKey(out)); // $ hasValueFlow
120+
}
121+
{
122+
// "com.google.common.cache;LoadingCache;true;getAll;(Iterable);;MapValue of Argument[-1];MapValue of ReturnValue;value"
123+
ImmutableMap out = null;
124+
LoadingCache in = (LoadingCache)newWithMapValue(source());
125+
out = in.getAll(null);
126+
sink(getMapValue(out)); // $ hasValueFlow
127+
}
128+
{
129+
// "com.google.common.cache;LoadingCache;true;getUnchecked;(Object);;MapValue of Argument[-1];ReturnValue;value"
130+
Object out = null;
131+
LoadingCache in = (LoadingCache)newWithMapValue(source());
132+
out = in.getUnchecked(null);
133+
sink(out); // $ hasValueFlow
134+
}
135+
136+
}
137+
138+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../../../stubs/guava-30.0

java/ql/test/library-tests/frameworks/guava/generated/cache/test.expected

Whitespace-only changes.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import java
2+
import semmle.code.java.dataflow.DataFlow
3+
import semmle.code.java.dataflow.ExternalFlow
4+
import semmle.code.java.dataflow.TaintTracking
5+
import TestUtilities.InlineExpectationsTest
6+
7+
class SummaryModelTest extends SummaryModelCsv {
8+
override predicate row(string row) {
9+
row =
10+
[
11+
//"package;type;overrides;name;signature;ext;inputspec;outputspec;kind",
12+
"generatedtest;Test;false;newWithElement;;;Argument[0];Element of ReturnValue;value",
13+
"generatedtest;Test;false;getMapKey;;;MapKey of Argument[0];ReturnValue;value",
14+
"generatedtest;Test;false;newWithMapKey;;;Argument[0];MapKey of ReturnValue;value",
15+
"generatedtest;Test;false;getMapValue;;;MapValue of Argument[0];ReturnValue;value",
16+
"generatedtest;Test;false;newWithMapValue;;;Argument[0];MapValue of ReturnValue;value"
17+
]
18+
}
19+
}
20+
21+
class ValueFlowConf extends DataFlow::Configuration {
22+
ValueFlowConf() { this = "qltest:valueFlowConf" }
23+
24+
override predicate isSource(DataFlow::Node n) {
25+
n.asExpr().(MethodAccess).getMethod().hasName("source")
26+
}
27+
28+
override predicate isSink(DataFlow::Node n) {
29+
n.asExpr().(Argument).getCall().getCallee().hasName("sink")
30+
}
31+
}
32+
33+
class TaintFlowConf extends TaintTracking::Configuration {
34+
TaintFlowConf() { this = "qltest:taintFlowConf" }
35+
36+
override predicate isSource(DataFlow::Node n) {
37+
n.asExpr().(MethodAccess).getMethod().hasName("source")
38+
}
39+
40+
override predicate isSink(DataFlow::Node n) {
41+
n.asExpr().(Argument).getCall().getCallee().hasName("sink")
42+
}
43+
}
44+
45+
class HasFlowTest extends InlineExpectationsTest {
46+
HasFlowTest() { this = "HasFlowTest" }
47+
48+
override string getARelevantTag() { result = ["hasValueFlow", "hasTaintFlow"] }
49+
50+
override predicate hasActualResult(Location location, string element, string tag, string value) {
51+
tag = "hasValueFlow" and
52+
exists(DataFlow::Node src, DataFlow::Node sink, ValueFlowConf conf | conf.hasFlow(src, sink) |
53+
sink.getLocation() = location and
54+
element = sink.toString() and
55+
value = ""
56+
)
57+
or
58+
tag = "hasTaintFlow" and
59+
exists(DataFlow::Node src, DataFlow::Node sink, TaintFlowConf conf |
60+
conf.hasFlow(src, sink) and not any(ValueFlowConf c).hasFlow(src, sink)
61+
|
62+
sink.getLocation() = location and
63+
element = sink.toString() and
64+
value = ""
65+
)
66+
}
67+
}
Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
1-
/*
2-
* Copyright (C) 2007 The Guava Authors
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5-
* in compliance with the License. You may obtain a copy of the License at
6-
*
7-
* http://www.apache.org/licenses/LICENSE-2.0
8-
*
9-
* Unless required by applicable law or agreed to in writing, software distributed under the License
10-
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11-
* or implied. See the License for the specific language governing permissions and limitations under
12-
* the License.
13-
*/
1+
// Generated automatically from com.google.common.base.Function for testing purposes, and adjusted manually
142

153
package com.google.common.base;
16-
import org.checkerframework.checker.nullness.qual.Nullable;
17-
18-
public interface Function<F, T> extends java.util.function.Function<F, T> {
19-
@Override
20-
T apply(@Nullable F input);
21-
22-
@Override
23-
boolean equals(@Nullable Object object);
244

5+
public interface Function<F, T> extends java.util.function.Function<F, T>
6+
{
7+
T apply(F p0);
8+
boolean equals(Object p0);
259
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Generated automatically from com.google.common.cache.Cache for testing purposes
2+
3+
package com.google.common.cache;
4+
5+
import com.google.common.cache.CacheStats;
6+
import com.google.common.collect.ImmutableMap;
7+
import java.util.Map;
8+
import java.util.concurrent.Callable;
9+
import java.util.concurrent.ConcurrentMap;
10+
11+
public interface Cache<K, V>
12+
{
13+
CacheStats stats();
14+
ConcurrentMap<K, V> asMap();
15+
ImmutableMap<K, V> getAllPresent(Iterable<? extends Object> p0);
16+
V get(K p0, Callable<? extends V> p1);
17+
V getIfPresent(Object p0);
18+
long size();
19+
void cleanUp();
20+
void invalidate(Object p0);
21+
void invalidateAll();
22+
void invalidateAll(Iterable<? extends Object> p0);
23+
void put(K p0, V p1);
24+
void putAll(Map<? extends K, ? extends V> p0);
25+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Generated automatically from com.google.common.cache.CacheStats for testing purposes
2+
3+
package com.google.common.cache;
4+
5+
6+
public class CacheStats
7+
{
8+
protected CacheStats() {}
9+
public CacheStats minus(CacheStats p0){ return null; }
10+
public CacheStats plus(CacheStats p0){ return null; }
11+
public CacheStats(long p0, long p1, long p2, long p3, long p4, long p5){}
12+
public String toString(){ return null; }
13+
public boolean equals(Object p0){ return false; }
14+
public double averageLoadPenalty(){ return 0; }
15+
public double hitRate(){ return 0; }
16+
public double loadExceptionRate(){ return 0; }
17+
public double missRate(){ return 0; }
18+
public int hashCode(){ return 0; }
19+
public long evictionCount(){ return 0; }
20+
public long hitCount(){ return 0; }
21+
public long loadCount(){ return 0; }
22+
public long loadExceptionCount(){ return 0; }
23+
public long loadSuccessCount(){ return 0; }
24+
public long missCount(){ return 0; }
25+
public long requestCount(){ return 0; }
26+
public long totalLoadTime(){ return 0; }
27+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Generated automatically from com.google.common.cache.LoadingCache for testing purposes
2+
3+
package com.google.common.cache;
4+
5+
import com.google.common.base.Function;
6+
import com.google.common.cache.Cache;
7+
import com.google.common.collect.ImmutableMap;
8+
import java.util.concurrent.ConcurrentMap;
9+
10+
public interface LoadingCache<K, V> extends Cache<K, V>, Function<K, V>
11+
{
12+
ConcurrentMap<K, V> asMap();
13+
ImmutableMap<K, V> getAll(Iterable<? extends K> p0);
14+
V apply(K p0);
15+
V get(K p0);
16+
V getUnchecked(K p0);
17+
void refresh(K p0);
18+
}

0 commit comments

Comments
 (0)