Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/ExactClassValueProfileTest.java @ 22064:02015aac6be9
Removing IdentityValueProfile and ExactClassValueProfile classes from the API
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 05 Aug 2015 16:47:04 +0200 |
parents | 9c8c0937da41 |
children | dc83cc1f94f2 |
comparison
equal
deleted
inserted
replaced
22063:b960accdd9b5 | 22064:02015aac6be9 |
---|---|
28 import org.junit.*; | 28 import org.junit.*; |
29 import org.junit.experimental.theories.*; | 29 import org.junit.experimental.theories.*; |
30 import org.junit.runner.*; | 30 import org.junit.runner.*; |
31 | 31 |
32 import com.oracle.truffle.api.utilities.*; | 32 import com.oracle.truffle.api.utilities.*; |
33 import java.lang.reflect.Method; | |
33 | 34 |
34 @RunWith(Theories.class) | 35 @RunWith(Theories.class) |
35 public class ExactClassValueProfileTest { | 36 public class ExactClassValueProfileTest { |
36 | 37 |
37 @DataPoint public static final String O1 = new String(); | 38 @DataPoint public static final String O1 = new String(); |
38 @DataPoint public static final String O2 = new String(); | 39 @DataPoint public static final String O2 = new String(); |
39 @DataPoint public static final Object O3 = new Object(); | 40 @DataPoint public static final Object O3 = new Object(); |
40 @DataPoint public static final Integer O4 = new Integer(1); | 41 @DataPoint public static final Integer O4 = new Integer(1); |
41 @DataPoint public static final Integer O5 = null; | 42 @DataPoint public static final Integer O5 = null; |
42 | 43 |
43 private ExactClassValueProfile profile; | 44 private ValueProfile profile; |
44 | 45 |
45 @Before | 46 @Before |
46 public void create() { | 47 public void create() { |
47 profile = (ExactClassValueProfile) ValueProfile.createClassProfile(); | 48 profile = ValueProfile.createClassProfile(); |
48 } | 49 } |
49 | 50 |
50 @Test | 51 @Test |
51 public void testInitial() { | 52 public void testInitial() throws Exception { |
52 assertThat(profile.isGeneric(), is(false)); | 53 assertThat(isGeneric(profile), is(false)); |
53 assertThat(profile.isUninitialized(), is(true)); | 54 assertThat(isUninitialized(profile), is(true)); |
54 assertNull(profile.getCachedClass()); | 55 assertNull(getCachedClass(profile)); |
55 profile.toString(); // test that it is not crashing | 56 profile.toString(); // test that it is not crashing |
56 } | 57 } |
57 | 58 |
58 @Theory | 59 @Theory |
59 public void testProfileOne(Object value) { | 60 public void testProfileOne(Object value) throws Exception { |
60 Object result = profile.profile(value); | 61 Object result = profile.profile(value); |
61 | 62 |
62 assertThat(result, is(value)); | 63 assertThat(result, is(value)); |
63 assertEquals(profile.getCachedClass(), expectedClass(value)); | 64 assertEquals(getCachedClass(profile), expectedClass(value)); |
64 assertThat(profile.isUninitialized(), is(false)); | 65 assertThat(isUninitialized(profile), is(false)); |
65 profile.toString(); // test that it is not crashing | 66 profile.toString(); // test that it is not crashing |
66 } | 67 } |
67 | 68 |
68 @Theory | 69 @Theory |
69 public void testProfileTwo(Object value0, Object value1) { | 70 public void testProfileTwo(Object value0, Object value1) throws Exception { |
70 Object result0 = profile.profile(value0); | 71 Object result0 = profile.profile(value0); |
71 Object result1 = profile.profile(value1); | 72 Object result1 = profile.profile(value1); |
72 | 73 |
73 assertThat(result0, is(value0)); | 74 assertThat(result0, is(value0)); |
74 assertThat(result1, is(value1)); | 75 assertThat(result1, is(value1)); |
75 | 76 |
76 Object expectedClass = expectedClass(value0) == expectedClass(value1) ? expectedClass(value0) : Object.class; | 77 Object expectedClass = expectedClass(value0) == expectedClass(value1) ? expectedClass(value0) : Object.class; |
77 | 78 |
78 assertEquals(profile.getCachedClass(), expectedClass); | 79 assertEquals(getCachedClass(profile), expectedClass); |
79 assertThat(profile.isUninitialized(), is(false)); | 80 assertThat(isUninitialized(profile), is(false)); |
80 assertThat(profile.isGeneric(), is(expectedClass == Object.class)); | 81 assertThat(isGeneric(profile), is(expectedClass == Object.class)); |
81 profile.toString(); // test that it is not crashing | 82 profile.toString(); // test that it is not crashing |
82 } | 83 } |
83 | 84 |
84 @Theory | 85 @Theory |
85 public void testProfileThree(Object value0, Object value1, Object value2) { | 86 public void testProfileThree(Object value0, Object value1, Object value2) throws Exception { |
86 Object result0 = profile.profile(value0); | 87 Object result0 = profile.profile(value0); |
87 Object result1 = profile.profile(value1); | 88 Object result1 = profile.profile(value1); |
88 Object result2 = profile.profile(value2); | 89 Object result2 = profile.profile(value2); |
89 | 90 |
90 assertThat(result0, is(value0)); | 91 assertThat(result0, is(value0)); |
91 assertThat(result1, is(value1)); | 92 assertThat(result1, is(value1)); |
92 assertThat(result2, is(value2)); | 93 assertThat(result2, is(value2)); |
93 | 94 |
94 Object expectedClass = expectedClass(value0) == expectedClass(value1) && expectedClass(value1) == expectedClass(value2) ? expectedClass(value0) : Object.class; | 95 Object expectedClass = expectedClass(value0) == expectedClass(value1) && expectedClass(value1) == expectedClass(value2) ? expectedClass(value0) : Object.class; |
95 | 96 |
96 assertEquals(profile.getCachedClass(), expectedClass); | 97 assertEquals(getCachedClass(profile), expectedClass); |
97 assertThat(profile.isUninitialized(), is(false)); | 98 assertThat(isUninitialized(profile), is(false)); |
98 assertThat(profile.isGeneric(), is(expectedClass == Object.class)); | 99 assertThat(isGeneric(profile), is(expectedClass == Object.class)); |
99 profile.toString(); // test that it is not crashing | 100 profile.toString(); // test that it is not crashing |
100 } | 101 } |
101 | 102 |
102 private static Class<?> expectedClass(Object value) { | 103 private static Class<?> expectedClass(Object value) { |
103 return value == null ? Object.class : value.getClass(); | 104 return value == null ? Object.class : value.getClass(); |
104 } | 105 } |
105 | 106 |
107 private static Object get(String name, ValueProfile profile) throws Exception { | |
108 final Method m = profile.getClass().getDeclaredMethod(name); | |
109 m.setAccessible(true); | |
110 return m.invoke(profile); | |
111 } | |
112 | |
113 private static Object getCachedClass(ValueProfile profile) throws Exception { | |
114 return get("getCachedClass", profile); | |
115 } | |
116 | |
117 private static boolean isUninitialized(ValueProfile profile) throws Exception { | |
118 return (Boolean) get("isUninitialized", profile); | |
119 } | |
120 | |
121 private static boolean isGeneric(ValueProfile profile) throws Exception { | |
122 return (Boolean) get("isGeneric", profile); | |
123 } | |
106 } | 124 } |