1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.bcel.verifier;
21
22 import java.io.IOException;
23
24 import org.apache.bcel.verifier.tests.TestArrayAccess02Creator;
25 import org.apache.bcel.verifier.tests.TestArrayAccess03Creator;
26 import org.apache.bcel.verifier.tests.TestArrayAccess04DoubleCreator;
27 import org.apache.bcel.verifier.tests.TestArrayAccess04FloatCreator;
28 import org.apache.bcel.verifier.tests.TestArrayAccess04IntCreator;
29 import org.apache.bcel.verifier.tests.TestArrayAccess04LongCreator;
30 import org.apache.bcel.verifier.tests.TestArrayAccess04ShortCreator;
31 import org.apache.bcel.verifier.tests.TestArrayAccess04UnknownCreator;
32 import org.junit.jupiter.api.Assertions;
33 import org.junit.jupiter.api.Test;
34
35 class VerifierArrayAccessTest extends AbstractVerifierTest {
36
37 @Test
38 void testInvalidArrayAccess() throws IOException, ClassNotFoundException {
39 new TestArrayAccess03Creator().create();
40 assertVerifyRejected("TestArrayAccess03", "Verification of an arraystore instruction on an object must fail.");
41 new TestArrayAccess04IntCreator().create();
42 assertVerifyRejected("TestArrayAccess04Int", "Verification of an arraystore instruction of an int on an array of references must fail.");
43 new TestArrayAccess04FloatCreator().create();
44 assertVerifyRejected("TestArrayAccess04Float", "Verification of an arraystore instruction of a float on an array of references must fail.");
45 new TestArrayAccess04DoubleCreator().create();
46 assertVerifyRejected("TestArrayAccess04Double", "Verification of an arraystore instruction of a double on an array of references must fail.");
47 new TestArrayAccess04LongCreator().create();
48 assertVerifyRejected("TestArrayAccess04Long", "Verification of an arraystore instruction of a long on an array of references must fail.");
49 new TestArrayAccess04ShortCreator().create();
50 assertVerifyRejected("TestArrayAccess04Short", "Verification of an arraystore instruction of a short on an array of references must fail.");
51 final TestArrayAccess04UnknownCreator testArrayAccess04UnknownCreator = new TestArrayAccess04UnknownCreator();
52 Assertions.assertThrowsExactly(IllegalArgumentException.class, testArrayAccess04UnknownCreator::create, "Invalid type <unknown object>");
53 }
54
55 @Test
56 void testValidArrayAccess() throws IOException, ClassNotFoundException {
57 assertVerifyOK("TestArrayAccess01", "Verification of an arraystore instruction on an array that is not compatible with the stored element must pass.");
58 new TestArrayAccess02Creator().create();
59 assertVerifyOK("TestArrayAccess02", "Verification of an arraystore instruction on an array that is not compatible with the stored element must pass.");
60 }
61
62 }