mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
Replace get and newWith methods with real implementations
This commit is contained in:
@@ -2,19 +2,47 @@ package generatedtest;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
// Test case generated by GenerateFlowTestCase.ql
|
||||
public class Test {
|
||||
|
||||
Object getMapKey(Object container) { return null; }
|
||||
Object getMapValue(Object container) { return null; }
|
||||
Object newWithElement(Object element) { return null; }
|
||||
Object newWithMapKey(Object element) { return null; }
|
||||
Object newWithMapValue(Object element) { return null; }
|
||||
Object source() { return null; }
|
||||
<K,V> K getMapKey(Map<K,V> container) { return container.keySet().iterator().next(); }
|
||||
<K,V> K getMapKey(Cache<K,V> container) { return getMapKey(container.asMap()); }
|
||||
<K,V> V getMapValue(Map<K,V> container) { return container.values().iterator().next(); }
|
||||
<K,V> V getMapValue(Cache<K,V> container) { return getMapValue(container.asMap()); }
|
||||
<T> Iterable<T> newWithElement(T element) {
|
||||
List<T> l = new ArrayList();
|
||||
l.add(element);
|
||||
return l;
|
||||
}
|
||||
<K,V> Map<K,V> newMapWithMapKey(K element) {
|
||||
Map<K,V> m = new HashMap<K,V>();
|
||||
m.put(element, null);
|
||||
return m;
|
||||
}
|
||||
<K,V> LoadingCache<K,V> newCacheWithMapKey(K element) {
|
||||
LoadingCache<K,V> lc = CacheBuilder.newBuilder().build(null);
|
||||
lc.put(element, null);
|
||||
return lc;
|
||||
}
|
||||
<K,V> Map<K,V> newMapWithMapValue(V element) {
|
||||
Map<K,V> m = new HashMap<K,V>();
|
||||
m.put(null, element);
|
||||
return m;
|
||||
}
|
||||
<K,V> LoadingCache<K,V> newCacheWithMapValue(V element) {
|
||||
LoadingCache<K,V> lc = CacheBuilder.newBuilder().build(null);
|
||||
lc.put(null, element);
|
||||
return lc;
|
||||
}
|
||||
<T> T source() { return null; }
|
||||
void sink(Object o) { }
|
||||
|
||||
public void test() throws Exception {
|
||||
@@ -22,98 +50,98 @@ public class Test {
|
||||
{
|
||||
// "com.google.common.cache;Cache;true;asMap;();;MapKey of Argument[-1];MapKey of ReturnValue;value"
|
||||
ConcurrentMap out = null;
|
||||
LoadingCache in = (LoadingCache)newWithMapKey(source());
|
||||
LoadingCache in = newCacheWithMapKey(source());
|
||||
out = in.asMap();
|
||||
sink(getMapKey(out)); // $ hasValueFlow
|
||||
}
|
||||
{
|
||||
// "com.google.common.cache;Cache;true;asMap;();;MapKey of Argument[-1];MapKey of ReturnValue;value"
|
||||
ConcurrentMap out = null;
|
||||
Cache in = (Cache)newWithMapKey(source());
|
||||
Cache in = newCacheWithMapKey(source());
|
||||
out = in.asMap();
|
||||
sink(getMapKey(out)); // $ hasValueFlow
|
||||
}
|
||||
{
|
||||
// "com.google.common.cache;Cache;true;asMap;();;MapValue of Argument[-1];MapValue of ReturnValue;value"
|
||||
ConcurrentMap out = null;
|
||||
LoadingCache in = (LoadingCache)newWithMapValue(source());
|
||||
LoadingCache in = newCacheWithMapValue(source());
|
||||
out = in.asMap();
|
||||
sink(getMapValue(out)); // $ hasValueFlow
|
||||
}
|
||||
{
|
||||
// "com.google.common.cache;Cache;true;asMap;();;MapValue of Argument[-1];MapValue of ReturnValue;value"
|
||||
ConcurrentMap out = null;
|
||||
Cache in = (Cache)newWithMapValue(source());
|
||||
Cache in = newCacheWithMapValue(source());
|
||||
out = in.asMap();
|
||||
sink(getMapValue(out)); // $ hasValueFlow
|
||||
}
|
||||
{
|
||||
// "com.google.common.cache;Cache;true;get;(Object,Callable);;MapValue of Argument[-1];ReturnValue;value"
|
||||
Object out = null;
|
||||
Cache in = (Cache)newWithMapValue(source());
|
||||
Cache in = newCacheWithMapValue(source());
|
||||
out = in.get(null, null);
|
||||
sink(out); // $ hasValueFlow
|
||||
}
|
||||
{
|
||||
// "com.google.common.cache;Cache;true;getAllPresent;(Iterable);;MapValue of Argument[-1];MapValue of ReturnValue;value"
|
||||
ImmutableMap out = null;
|
||||
Cache in = (Cache)newWithMapValue(source());
|
||||
Cache in = newCacheWithMapValue(source());
|
||||
out = in.getAllPresent(null);
|
||||
sink(getMapValue(out)); // $ hasValueFlow
|
||||
}
|
||||
{
|
||||
// "com.google.common.cache;Cache;true;getIfPresent;(Object);;MapValue of Argument[-1];ReturnValue;value"
|
||||
// "com.google.common.cache;Cache;true;getIfPresent;;;MapValue of Argument[-1];ReturnValue;value"
|
||||
Object out = null;
|
||||
Cache in = (Cache)newWithMapValue(source());
|
||||
Cache in = newCacheWithMapValue(source());
|
||||
out = in.getIfPresent(null);
|
||||
sink(out); // $ hasValueFlow
|
||||
}
|
||||
{
|
||||
// "com.google.common.cache;Cache;true;put;(Object,Object);;Argument[0];MapKey of Argument[-1];value"
|
||||
Cache out = null;
|
||||
Object in = (Object)source();
|
||||
Object in = source();
|
||||
out.put(in, null);
|
||||
sink(getMapKey(out)); // $ hasValueFlow
|
||||
}
|
||||
{
|
||||
// "com.google.common.cache;Cache;true;put;(Object,Object);;Argument[1];MapValue of Argument[-1];value"
|
||||
Cache out = null;
|
||||
Object in = (Object)source();
|
||||
Object in = source();
|
||||
out.put(null, in);
|
||||
sink(getMapValue(out)); // $ hasValueFlow
|
||||
}
|
||||
{
|
||||
// "com.google.common.cache;Cache;true;putAll;(Map);;MapKey of Argument[0];MapKey of Argument[-1];value"
|
||||
Cache out = null;
|
||||
Map in = (Map)newWithMapKey(source());
|
||||
Map in = newMapWithMapKey(source());
|
||||
out.putAll(in);
|
||||
sink(getMapKey(out)); // $ hasValueFlow
|
||||
}
|
||||
{
|
||||
// "com.google.common.cache;Cache;true;putAll;(Map);;MapValue of Argument[0];MapValue of Argument[-1];value"
|
||||
Cache out = null;
|
||||
Map in = (Map)newWithMapValue(source());
|
||||
Map in = newMapWithMapValue(source());
|
||||
out.putAll(in);
|
||||
sink(getMapValue(out)); // $ hasValueFlow
|
||||
}
|
||||
{
|
||||
// "com.google.common.cache;LoadingCache;true;apply;(Object);;MapValue of Argument[-1];ReturnValue;value"
|
||||
// "com.google.common.cache;LoadingCache;true;apply;;;MapValue of Argument[-1];ReturnValue;value"
|
||||
Object out = null;
|
||||
LoadingCache in = (LoadingCache)newWithMapValue(source());
|
||||
LoadingCache in = newCacheWithMapValue(source());
|
||||
out = in.apply(null);
|
||||
sink(out); // $ hasValueFlow
|
||||
}
|
||||
{
|
||||
// "com.google.common.cache;LoadingCache;true;get;(Object);;MapValue of Argument[-1];ReturnValue;value"
|
||||
// "com.google.common.cache;LoadingCache;true;get;;;MapValue of Argument[-1];ReturnValue;value"
|
||||
Object out = null;
|
||||
LoadingCache in = (LoadingCache)newWithMapValue(source());
|
||||
LoadingCache in = newCacheWithMapValue(source());
|
||||
out = in.get(null);
|
||||
sink(out); // $ hasValueFlow
|
||||
}
|
||||
{
|
||||
// "com.google.common.cache;LoadingCache;true;getAll;(Iterable);;Element of Argument[0];MapKey of ReturnValue;value"
|
||||
ImmutableMap out = null;
|
||||
Iterable in = (Iterable)newWithElement(source());
|
||||
Iterable in = newWithElement(source());
|
||||
LoadingCache instance = null;
|
||||
out = instance.getAll(in);
|
||||
sink(getMapKey(out)); // $ hasValueFlow
|
||||
@@ -121,14 +149,14 @@ public class Test {
|
||||
{
|
||||
// "com.google.common.cache;LoadingCache;true;getAll;(Iterable);;MapValue of Argument[-1];MapValue of ReturnValue;value"
|
||||
ImmutableMap out = null;
|
||||
LoadingCache in = (LoadingCache)newWithMapValue(source());
|
||||
LoadingCache in = newCacheWithMapValue(source());
|
||||
out = in.getAll(null);
|
||||
sink(getMapValue(out)); // $ hasValueFlow
|
||||
}
|
||||
{
|
||||
// "com.google.common.cache;LoadingCache;true;getUnchecked;(Object);;MapValue of Argument[-1];ReturnValue;value"
|
||||
// "com.google.common.cache;LoadingCache;true;getUnchecked;;;MapValue of Argument[-1];ReturnValue;value"
|
||||
Object out = null;
|
||||
LoadingCache in = (LoadingCache)newWithMapValue(source());
|
||||
LoadingCache in = newCacheWithMapValue(source());
|
||||
out = in.getUnchecked(null);
|
||||
sink(out); // $ hasValueFlow
|
||||
}
|
||||
|
||||
@@ -4,20 +4,6 @@ import semmle.code.java.dataflow.ExternalFlow
|
||||
import semmle.code.java.dataflow.TaintTracking
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
|
||||
class SummaryModelTest extends SummaryModelCsv {
|
||||
override predicate row(string row) {
|
||||
row =
|
||||
[
|
||||
//"package;type;overrides;name;signature;ext;inputspec;outputspec;kind",
|
||||
"generatedtest;Test;false;newWithElement;;;Argument[0];Element of ReturnValue;value",
|
||||
"generatedtest;Test;false;getMapKey;;;MapKey of Argument[0];ReturnValue;value",
|
||||
"generatedtest;Test;false;newWithMapKey;;;Argument[0];MapKey of ReturnValue;value",
|
||||
"generatedtest;Test;false;getMapValue;;;MapValue of Argument[0];ReturnValue;value",
|
||||
"generatedtest;Test;false;newWithMapValue;;;Argument[0];MapValue of ReturnValue;value"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
class ValueFlowConf extends DataFlow::Configuration {
|
||||
ValueFlowConf() { this = "qltest:valueFlowConf" }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user