@@ -125,6 +125,45 @@ public void testConsume() throws NoSuchMethodException {
125125 23 , // remaining bytes
126126 "foo\n bar" ));
127127
128+ // Test for multi-dimensional array codegen
129+ // (https://github.com/CodeIntelligenceTesting/jazzer/issues/1026)
130+ consumeTestCase (
131+ int [][].class ,
132+ new int [][] {{1 , 2 }, {3 }},
133+ "new int[][]{new int[]{1, 2}, new int[]{3}}" ,
134+ Arrays .asList (
135+ (byte ) 1 , // do not return null for the outer array
136+ 100 , // remainingBytes before first element creation
137+ (byte ) 1 , // do not return null for first int[]
138+ 50 , // remainingBytes for consumeArrayLength inside first consumeInts
139+ new int [] {1 , 2 }, // consumeInts returns first int[]
140+ 40 , // remainingBytes after first element creation
141+ // sizeOfElementEstimate = 100 - 40 = 60
142+ // consumeArrayLength(data, 60) = remainingBytes / 2 / 60
143+ // need this to return 2: 240 / 2 / 60 = 2
144+ 240 , // remainingBytes for outer consumeArrayLength
145+ (byte ) 1 , // do not return null for second int[]
146+ 50 , // remainingBytes for consumeArrayLength inside second consumeInts
147+ new int [] {3 })); // consumeInts returns second int[]
148+
149+ // Test that inner class arrays use getCanonicalName() (dot-separated) not getTypeName() which
150+ // would produce '$'-separated names that are not valid Java source.
151+ consumeTestCase (
152+ TestEnum [].class ,
153+ new TestEnum [] {TestEnum .BAR },
154+ "new com.code_intelligence.jazzer.autofuzz.MetaTest.TestEnum[]{"
155+ + "com.code_intelligence.jazzer.autofuzz.MetaTest.TestEnum.BAR}" ,
156+ Arrays .asList (
157+ (byte ) 1 , // do not return null for the array
158+ 100 , // remainingBytes before first element creation
159+ (byte ) 1 , // do not return null for the enum value
160+ 1 , // pickValue index (BAR)
161+ 90 , // remainingBytes after first element creation
162+ // sizeOfElementEstimate = 100 - 90 = 10
163+ // consumeArrayLength(data, 10) = remainingBytes / 2 / 10
164+ // need this to return 1: 20 / 2 / 10 = 1
165+ 20 )); // remainingBytes for outer consumeArrayLength
166+
128167 byte [] testInputStreamBytes = new byte [] {(byte ) 1 , (byte ) 2 , (byte ) 3 };
129168 consumeTestCase (
130169 new ByteArrayInputStream (testInputStreamBytes ),
@@ -136,7 +175,7 @@ public void testConsume() throws NoSuchMethodException {
136175
137176 consumeTestCase (
138177 TestEnum .BAR ,
139- String .format ("%s.%s" , TestEnum .class .getName (), TestEnum .BAR .name ()),
178+ String .format ("%s.%s" , TestEnum .class .getCanonicalName (), TestEnum .BAR .name ()),
140179 Arrays .asList (
141180 (byte ) 1 , // do not return null for the enum value
142181 1 /* second value */ ));
0 commit comments