Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/FrameDescriptorTest.java @ 22492:bc3303fb3888
add more FrameDescriptor tests
author | Andreas Woess <andreas.woess@oracle.com> |
---|---|
date | Thu, 10 Dec 2015 18:39:47 +0100 |
parents | fa86f9f3848d |
children |
comparison
equal
deleted
inserted
replaced
22491:a73f1d7a5a3e | 22492:bc3303fb3888 |
---|---|
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.truffle.api; | 23 package com.oracle.truffle.api; |
24 | 24 |
25 import static org.junit.Assert.assertEquals; | 25 import static org.junit.Assert.assertEquals; |
26 import static org.junit.Assert.assertFalse; | |
27 import static org.junit.Assert.assertNull; | |
28 import static org.junit.Assert.assertSame; | |
29 import static org.junit.Assert.assertTrue; | |
30 import static org.junit.Assert.fail; | |
26 | 31 |
27 import org.junit.Assert; | |
28 import org.junit.Test; | 32 import org.junit.Test; |
29 | 33 |
30 import com.oracle.truffle.api.frame.Frame; | 34 import com.oracle.truffle.api.frame.Frame; |
31 import com.oracle.truffle.api.frame.FrameDescriptor; | 35 import com.oracle.truffle.api.frame.FrameDescriptor; |
32 import com.oracle.truffle.api.frame.FrameSlot; | 36 import com.oracle.truffle.api.frame.FrameSlot; |
65 assertEquals(1, f.getInt(s3)); | 69 assertEquals(1, f.getInt(s3)); |
66 } | 70 } |
67 | 71 |
68 @Test | 72 @Test |
69 public void nullDefaultValue() { | 73 public void nullDefaultValue() { |
70 Assert.assertNull(new FrameDescriptor().getDefaultValue()); | 74 assertNull(new FrameDescriptor().getDefaultValue()); |
71 } | 75 } |
72 | 76 |
73 @Test | 77 @Test |
74 public void copy() throws Exception { | 78 public void copy() throws Exception { |
75 Object defaultValue = "default"; | 79 Object defaultValue = "default"; |
112 | 116 |
113 firstCopy.setKind(FrameSlotKind.Int); | 117 firstCopy.setKind(FrameSlotKind.Int); |
114 assertEquals("Kind is changed", firstCopy.getKind(), FrameSlotKind.Int); | 118 assertEquals("Kind is changed", firstCopy.getKind(), FrameSlotKind.Int); |
115 assertEquals("Kind is changed in original too!", first.getKind(), FrameSlotKind.Int); | 119 assertEquals("Kind is changed in original too!", first.getKind(), FrameSlotKind.Int); |
116 } | 120 } |
121 | |
122 @Test | |
123 public void version() { | |
124 FrameDescriptor d = new FrameDescriptor(); | |
125 s1 = d.addFrameSlot("v1", "i1", FrameSlotKind.Boolean); | |
126 s2 = d.addFrameSlot("v2", "i2", FrameSlotKind.Float); | |
127 | |
128 Assumption version; | |
129 version = d.getVersion(); | |
130 assertTrue(version.isValid()); | |
131 // add slot | |
132 s3 = d.addFrameSlot("v3", "i3", FrameSlotKind.Int); | |
133 assertEquals(3, d.getSize()); | |
134 assertFalse(version.isValid()); | |
135 version = d.getVersion(); | |
136 assertTrue(version.isValid()); | |
137 assertSame("1st slot", s1, d.getSlots().get(0)); | |
138 assertSame("2nd slot", s2, d.getSlots().get(1)); | |
139 assertSame("3rd slot", s3, d.getSlots().get(2)); | |
140 | |
141 // change kind | |
142 s3.setKind(FrameSlotKind.Object); | |
143 assertFalse(version.isValid()); | |
144 version = d.getVersion(); | |
145 assertTrue(version.isValid()); | |
146 | |
147 // remove slot | |
148 d.removeFrameSlot("v3"); | |
149 assertEquals(2, d.getSize()); | |
150 assertFalse(version.isValid()); | |
151 version = d.getVersion(); | |
152 assertTrue(version.isValid()); | |
153 } | |
154 | |
155 @Test | |
156 public void notInFrameAssumption() { | |
157 FrameDescriptor d = new FrameDescriptor(); | |
158 Assumption[] ass = new Assumption[]{d.getNotInFrameAssumption("v1"), d.getNotInFrameAssumption("v2"), d.getNotInFrameAssumption("v3")}; | |
159 assertTrue(ass[0].isValid()); | |
160 assertTrue(ass[1].isValid()); | |
161 assertTrue(ass[2].isValid()); | |
162 s1 = d.addFrameSlot("v1", "i1", FrameSlotKind.Boolean); | |
163 assertFalse(ass[0].isValid()); | |
164 assertTrue(ass[1].isValid()); | |
165 assertTrue(ass[2].isValid()); | |
166 s2 = d.addFrameSlot("v2", "i2", FrameSlotKind.Float); | |
167 assertFalse(ass[0].isValid()); | |
168 assertFalse(ass[1].isValid()); | |
169 assertTrue(ass[2].isValid()); | |
170 s3 = d.addFrameSlot("v3", "i3", FrameSlotKind.Int); | |
171 assertFalse(ass[0].isValid()); | |
172 assertFalse(ass[1].isValid()); | |
173 assertFalse(ass[2].isValid()); | |
174 | |
175 for (String identifier : new String[]{"v1", "v2", "v3"}) { | |
176 try { | |
177 d.getNotInFrameAssumption(identifier); | |
178 fail("expected IllegalArgumentException"); | |
179 } catch (IllegalArgumentException e) { | |
180 // expected | |
181 } | |
182 } | |
183 d.getNotInFrameAssumption("v4"); | |
184 } | |
117 } | 185 } |