annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22432
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
1 /*
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
4 *
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
8 *
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
13 * accompanied this code).
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
14 *
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
18 *
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
21 * questions.
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
22 */
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
23 package com.oracle.truffle.api;
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
24
22490
fa86f9f3848d change FrameDescriptor#copy to also copy info
Andreas Woess <andreas.woess@oracle.com>
parents: 22435
diff changeset
25 import static org.junit.Assert.assertEquals;
22492
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
26 import static org.junit.Assert.assertFalse;
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
27 import static org.junit.Assert.assertNull;
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
28 import static org.junit.Assert.assertSame;
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
29 import static org.junit.Assert.assertTrue;
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
30 import static org.junit.Assert.fail;
22490
fa86f9f3848d change FrameDescriptor#copy to also copy info
Andreas Woess <andreas.woess@oracle.com>
parents: 22435
diff changeset
31
fa86f9f3848d change FrameDescriptor#copy to also copy info
Andreas Woess <andreas.woess@oracle.com>
parents: 22435
diff changeset
32 import org.junit.Test;
fa86f9f3848d change FrameDescriptor#copy to also copy info
Andreas Woess <andreas.woess@oracle.com>
parents: 22435
diff changeset
33
22432
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
34 import com.oracle.truffle.api.frame.Frame;
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
35 import com.oracle.truffle.api.frame.FrameDescriptor;
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
36 import com.oracle.truffle.api.frame.FrameSlot;
22434
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
37 import com.oracle.truffle.api.frame.FrameSlotKind;
22432
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
38 import com.oracle.truffle.api.frame.FrameSlotTypeException;
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
39 import com.oracle.truffle.api.frame.VirtualFrame;
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
40
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
41 public class FrameDescriptorTest {
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
42
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
43 private FrameSlot s1;
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
44 private FrameSlot s2;
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
45 private FrameSlot s3;
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
46
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
47 @Test
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
48 public void localsDefaultValue() throws Exception {
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
49 Object defaultValue = "default";
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
50 FrameDescriptor d = new FrameDescriptor(defaultValue);
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
51 s1 = d.addFrameSlot("v1");
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
52 s2 = d.addFrameSlot("v2");
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
53 s3 = d.addFrameSlot("v3");
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
54 VirtualFrame f = Truffle.getRuntime().createVirtualFrame(new Object[]{1, 2}, d);
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
55
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
56 assertFrame(f, d);
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
57 assertFrame(f.materialize(), d);
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
58 }
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
59
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
60 private void assertFrame(Frame f, FrameDescriptor d) throws FrameSlotTypeException {
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
61 assertEquals("Three slots", 3, d.getSize());
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
62 assertEquals("Three slots list", 3, d.getSlots().size());
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
63 assertEquals("1st slot", d.getSlots().get(0), s1);
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
64 assertEquals("2nd slot", d.getSlots().get(1), s2);
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
65 assertEquals("3rd slot", d.getSlots().get(2), s3);
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
66 assertEquals("default", f.getObject(s1));
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
67 assertEquals("default", f.getObject(s2));
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
68 f.setInt(s3, (int) f.getArguments()[0]);
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
69 assertEquals(1, f.getInt(s3));
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
70 }
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
71
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
72 @Test
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
73 public void nullDefaultValue() {
22492
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
74 assertNull(new FrameDescriptor().getDefaultValue());
22432
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
75 }
22434
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
76
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
77 @Test
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
78 public void copy() throws Exception {
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
79 Object defaultValue = "default";
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
80 FrameDescriptor d = new FrameDescriptor(defaultValue);
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
81 s1 = d.addFrameSlot("v1", "i1", FrameSlotKind.Boolean);
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
82 s2 = d.addFrameSlot("v2", "i2", FrameSlotKind.Float);
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
83
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
84 assertEquals(2, d.getSize());
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
85 assertEquals(d.getSlots().get(1).getInfo(), "i2");
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
86 assertEquals(d.getSlots().get(1).getKind(), FrameSlotKind.Float);
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
87 assertEquals(d.getSlots().get(1).getIndex(), 1);
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
88
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
89 FrameDescriptor copy = d.copy();
22490
fa86f9f3848d change FrameDescriptor#copy to also copy info
Andreas Woess <andreas.woess@oracle.com>
parents: 22435
diff changeset
90 assertEquals(2, copy.getSize());
fa86f9f3848d change FrameDescriptor#copy to also copy info
Andreas Woess <andreas.woess@oracle.com>
parents: 22435
diff changeset
91 assertEquals(1, copy.getSlots().get(1).getIndex());
fa86f9f3848d change FrameDescriptor#copy to also copy info
Andreas Woess <andreas.woess@oracle.com>
parents: 22435
diff changeset
92 assertEquals("Info is copied", "i2", copy.getSlots().get(1).getInfo());
fa86f9f3848d change FrameDescriptor#copy to also copy info
Andreas Woess <andreas.woess@oracle.com>
parents: 22435
diff changeset
93 assertEquals("Kind isn't copied", FrameSlotKind.Illegal, copy.getSlots().get(1).getKind());
22434
c11ce7d2e2c3 Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22432
diff changeset
94 }
22435
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
95
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
96 @Test
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
97 public void shallowCopy() {
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
98 Object defaultValue = "default";
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
99 FrameDescriptor d = new FrameDescriptor(defaultValue);
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
100 s1 = d.addFrameSlot("v1", "i1", FrameSlotKind.Boolean);
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
101 s2 = d.addFrameSlot("v2", "i2", FrameSlotKind.Float);
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
102
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
103 assertEquals(2, d.getSize());
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
104 final FrameSlot first = d.getSlots().get(1);
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
105 assertEquals(first.getInfo(), "i2");
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
106 assertEquals(first.getKind(), FrameSlotKind.Float);
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
107 assertEquals(first.getIndex(), 1);
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
108
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
109 FrameDescriptor copy = d.shallowCopy();
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
110
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
111 assertEquals(2, copy.getSize());
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
112 final FrameSlot firstCopy = copy.getSlots().get(1);
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
113 assertEquals("Info is copied", firstCopy.getInfo(), "i2");
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
114 assertEquals("Kind is copied", firstCopy.getKind(), FrameSlotKind.Float);
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
115 assertEquals(firstCopy.getIndex(), 1);
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
116
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
117 firstCopy.setKind(FrameSlotKind.Int);
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
118 assertEquals("Kind is changed", firstCopy.getKind(), FrameSlotKind.Int);
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
119 assertEquals("Kind is changed in original too!", first.getKind(), FrameSlotKind.Int);
dc2bfc816011 Documenting and testing behavior of FrameDescriptor#shallowCopy
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22434
diff changeset
120 }
22492
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
121
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
122 @Test
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
123 public void version() {
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
124 FrameDescriptor d = new FrameDescriptor();
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
125 s1 = d.addFrameSlot("v1", "i1", FrameSlotKind.Boolean);
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
126 s2 = d.addFrameSlot("v2", "i2", FrameSlotKind.Float);
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
127
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
128 Assumption version;
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
129 version = d.getVersion();
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
130 assertTrue(version.isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
131 // add slot
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
132 s3 = d.addFrameSlot("v3", "i3", FrameSlotKind.Int);
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
133 assertEquals(3, d.getSize());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
134 assertFalse(version.isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
135 version = d.getVersion();
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
136 assertTrue(version.isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
137 assertSame("1st slot", s1, d.getSlots().get(0));
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
138 assertSame("2nd slot", s2, d.getSlots().get(1));
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
139 assertSame("3rd slot", s3, d.getSlots().get(2));
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
140
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
141 // change kind
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
142 s3.setKind(FrameSlotKind.Object);
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
143 assertFalse(version.isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
144 version = d.getVersion();
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
145 assertTrue(version.isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
146
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
147 // remove slot
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
148 d.removeFrameSlot("v3");
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
149 assertEquals(2, d.getSize());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
150 assertFalse(version.isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
151 version = d.getVersion();
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
152 assertTrue(version.isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
153 }
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
154
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
155 @Test
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
156 public void notInFrameAssumption() {
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
157 FrameDescriptor d = new FrameDescriptor();
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
158 Assumption[] ass = new Assumption[]{d.getNotInFrameAssumption("v1"), d.getNotInFrameAssumption("v2"), d.getNotInFrameAssumption("v3")};
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
159 assertTrue(ass[0].isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
160 assertTrue(ass[1].isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
161 assertTrue(ass[2].isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
162 s1 = d.addFrameSlot("v1", "i1", FrameSlotKind.Boolean);
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
163 assertFalse(ass[0].isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
164 assertTrue(ass[1].isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
165 assertTrue(ass[2].isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
166 s2 = d.addFrameSlot("v2", "i2", FrameSlotKind.Float);
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
167 assertFalse(ass[0].isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
168 assertFalse(ass[1].isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
169 assertTrue(ass[2].isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
170 s3 = d.addFrameSlot("v3", "i3", FrameSlotKind.Int);
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
171 assertFalse(ass[0].isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
172 assertFalse(ass[1].isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
173 assertFalse(ass[2].isValid());
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
174
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
175 for (String identifier : new String[]{"v1", "v2", "v3"}) {
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
176 try {
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
177 d.getNotInFrameAssumption(identifier);
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
178 fail("expected IllegalArgumentException");
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
179 } catch (IllegalArgumentException e) {
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
180 // expected
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
181 }
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
182 }
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
183 d.getNotInFrameAssumption("v4");
bc3303fb3888 add more FrameDescriptor tests
Andreas Woess <andreas.woess@oracle.com>
parents: 22490
diff changeset
184 }
22432
079cd9183128 Documenting and testing some aspects of FrameDescriptor behavior
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
185 }