Skip to content

Commit 54a0d0f

Browse files
committed
test: use shadowed annotations; assert that max length is respected
1 parent fccc5be commit 54a0d0f

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

selffuzz/src/test/java/com/code_intelligence/selffuzz/mutation/ArgumentsMutatorFuzzTest.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020

2121
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
2222
import com.code_intelligence.jazzer.junit.FuzzTest;
23-
import com.code_intelligence.jazzer.mutation.annotation.WithSize;
24-
import com.code_intelligence.jazzer.mutation.annotation.WithUtf8Length;
2523
import com.code_intelligence.jazzer.protobuf.Proto2;
2624
import com.code_intelligence.jazzer.protobuf.Proto3;
2725
import com.code_intelligence.selffuzz.jazzer.mutation.ArgumentsMutator;
2826
import com.code_intelligence.selffuzz.jazzer.mutation.annotation.NotNull;
2927
import com.code_intelligence.selffuzz.jazzer.mutation.annotation.WithLength;
28+
import com.code_intelligence.selffuzz.jazzer.mutation.annotation.WithSize;
29+
import com.code_intelligence.selffuzz.jazzer.mutation.annotation.WithUtf8Length;
3030
import com.code_intelligence.selffuzz.jazzer.mutation.mutator.Mutators;
3131
import java.io.ByteArrayInputStream;
3232
import java.io.ByteArrayOutputStream;
@@ -102,21 +102,32 @@ void fuzzStrings(
102102
@NotNull String s1,
103103
@NotNull @WithUtf8Length(min = 10, max = 20) String s2) {}
104104

105-
@SelfFuzzTest // BUG: null pointer exception
106-
void fuzzListOfMaps(Map<String, Integer> nullableMap) {}
105+
@SelfFuzzTest
106+
void fuzzListOfMaps(@WithSize(max = 4) Map<String, Integer> nullableMap) {
107+
if (nullableMap != null) {
108+
assertThat(nullableMap.size()).isAtMost(4);
109+
}
110+
}
107111

108112
@SelfFuzzTest
109113
void fuzzListOfLists(List<@NotNull List<String>> nullableMap, List<List<Integer>> nullableList) {}
110114

111115
@SelfFuzzTest
112-
void fuzzPPrimitiveArrays(
113-
int @WithLength(max = 10) [] a0, boolean[] a2, int @WithLength(max = 8193) [] a3) {}
116+
void fuzzPrimitiveArrays(
117+
int @WithLength(max = 10) [] a0, boolean[] a2, int @WithLength(max = 8193) [] a3) {
118+
if (a0 != null) assertThat(a0.length).isAtMost(10);
119+
if (a3 != null) assertThat(a3.length).isAtMost(8193);
120+
}
114121

115122
@SelfFuzzTest
116123
void fuzzBean(@NotNull ConstructorPropertiesAnnotatedBean bean, BeanWithParent beanWithParent) {}
117124

118125
@SelfFuzzTest
119-
void fuzzListOfBeans(@WithSize(max = 4) List<BeanWithParent> beanWithParent) {}
126+
void fuzzListOfBeans(@WithSize(max = 4) List<BeanWithParent> beanWithParent) {
127+
if (beanWithParent != null) {
128+
assertThat(beanWithParent.size()).isAtMost(4);
129+
}
130+
}
120131

121132
@SelfFuzzTest
122133
void fuzzListOfListOfBeans(
@@ -189,7 +200,15 @@ void fuzzPrimitiveArrays(
189200
Byte @WithLength(max = 3) [] by0,
190201
byte[] by1,
191202
Short @WithLength(max = 3) [] s0,
192-
short[] s1) {}
203+
short[] s1) {
204+
if (i0 != null) assertThat(i0.length).isAtMost(3);
205+
if (b0 != null) assertThat(b0.length).isAtMost(3);
206+
if (d0 != null) assertThat(d0.length).isAtMost(3);
207+
if (f0 != null) assertThat(f0.length).isAtMost(3);
208+
if (l0 != null) assertThat(l0.length).isAtMost(3);
209+
if (by0 != null) assertThat(by0.length).isAtMost(3);
210+
if (s0 != null) assertThat(s0.length).isAtMost(3);
211+
}
193212

194213
enum MyEnum {
195214
A,

0 commit comments

Comments
 (0)