-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathTestOracleUtils.java
More file actions
55 lines (48 loc) · 2.05 KB
/
TestOracleUtils.java
File metadata and controls
55 lines (48 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package sqlancer.common.oracle;
import sqlancer.IgnoreMeException;
import sqlancer.Randomly;
import sqlancer.common.ast.newast.Expression;
import sqlancer.common.gen.PartitionGenerator;
import sqlancer.common.schema.AbstractSchema;
import sqlancer.common.schema.AbstractTable;
import sqlancer.common.schema.AbstractTableColumn;
import sqlancer.common.schema.AbstractTables;
public final class TestOracleUtils {
private TestOracleUtils() {
}
public static final class PredicateVariants<E extends Expression<C>, C extends AbstractTableColumn<?, ?>> {
public E predicate;
public E negatedPredicate;
public E isNullPredicate;
PredicateVariants(E predicate, E negatedPredicate, E isNullPredicate) {
this.predicate = predicate;
this.negatedPredicate = negatedPredicate;
this.isNullPredicate = isNullPredicate;
}
}
public static <T extends AbstractTable<C, ?, ?>, C extends AbstractTableColumn<?, ?>> AbstractTables<T, C> getRandomTableNonEmptyTables(
AbstractSchema<?, T> schema) {
if (schema.getDatabaseTables().isEmpty()) {
throw new IgnoreMeException();
}
return new AbstractTables<>(Randomly.nonEmptySubset(schema.getDatabaseTables()));
}
public static <E extends Expression<C>, T extends AbstractTable<C, ?, ?>, C extends AbstractTableColumn<?, ?>> PredicateVariants<E, C> initializeTernaryPredicateVariants(
PartitionGenerator<E, C> gen, E predicate) {
if (gen == null) {
throw new IllegalStateException();
}
if (predicate == null) {
throw new IllegalStateException();
}
E negatedPredicate = gen.negatePredicate(predicate);
if (negatedPredicate == null) {
throw new IllegalStateException();
}
E isNullPredicate = gen.isNull(predicate);
if (isNullPredicate == null) {
throw new IllegalStateException();
}
return new PredicateVariants<>(predicate, negatedPredicate, isNullPredicate);
}
}