tests/java/src/stx/libjava/tests/vm/ANEWARRAY.java
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 24 Jun 2015 06:16:28 +0100
changeset 3464 d90e187e80fd
permissions -rw-r--r--
Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions ...especially to test that PC is properly set when an exception occur.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3464
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     1
package stx.libjava.tests.vm;
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     2
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     3
import static org.junit.Assert.*;
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     4
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     5
import org.junit.Test;
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     6
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     7
public class ANEWARRAY {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     8
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     9
	@Test
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    10
	public void test_bounds_01() {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    11
		Object[] arr;
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    12
		Object o;		
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    13
		arr = new Object[10];
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
		
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
		try {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
			o = arr[-1];
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
			fail();
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    18
		} catch (ArrayIndexOutOfBoundsException abe) {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    19
			// OK
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    20
		} catch (Exception e) {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    21
			fail();
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    22
		}
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    23
		
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    24
		arr = new Object[10];
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    25
		try {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    26
			arr[-1] = new Object();
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    27
			fail();
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    28
		} catch (ArrayIndexOutOfBoundsException abe) {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    29
			// OK
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    30
		} catch (Exception e) {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    31
			fail();
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    32
		}
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    33
		
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    34
		try {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    35
			o = arr[11];
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    36
			fail();
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    37
		} catch (ArrayIndexOutOfBoundsException abe) {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    38
			// OK
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    39
		} catch (Exception e) {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    40
			fail();
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    41
		}
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    42
		
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    43
		arr = new Object[10];
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    44
		try {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    45
			arr[11] = new Object();
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    46
			fail();
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    47
		} catch (ArrayIndexOutOfBoundsException abe) {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    48
			// OK
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    49
		} catch (Exception e) {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    50
			fail();
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    51
		}
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    52
	}
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    53
	
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    54
	@Test
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    55
	public void test_negative_size_01() {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    56
		Object[] arr;
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    57
		try {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    58
			arr = new Object[-1];
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    59
		} catch (NegativeArraySizeException nase) {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    60
			// OK
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    61
		} catch (Exception e) {
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    62
			fail();
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    63
		}
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    64
	}
d90e187e80fd Added more tests for NEWARRAY, ANEWARRAY and ARRAYLENGTH instructions
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    65
}