6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.javafx.scene.transform;
27
28 import com.sun.javafx.test.TransformHelper;
29 import javafx.scene.transform.Transform;
30 import com.sun.javafx.geom.transform.Affine3D;
31 import java.util.LinkedList;
32 import java.util.List;
33 import javafx.scene.transform.TransformOperationsTest;
34 import javafx.scene.transform.Translate;
35 import static org.junit.Assert.*;
36
37 import org.junit.Test;
38
39 public class TransformUtilsTest {
40 @Test
41 public void shouldCreateCorrectImmutableTransform() {
42 Transform t = TransformUtils.immutableTransform(
43 1, 2, 3, 4,
44 5, 6, 7, 8,
45 9, 10, 11, 12);
46
47 TransformHelper.assertMatrix(t,
48 1, 2, 3, 4,
49 5, 6, 7, 8,
50 9, 10, 11, 12);
51 }
52
53 @Test
54 public void immutableTransformShouldApplyCorrectly() {
55 Affine3D a = new Affine3D();
56 a.translate(10, 20);
57
58 Transform t = TransformUtils.immutableTransform(
59 1, 2, 3, 4,
60 5, 6, 7, 8,
61 9, 10, 11, 12);
62
63 t.impl_apply(a);
64
65 TransformHelper.assertMatrix(a,
66 1, 2, 3, 14,
67 5, 6, 7, 28,
68 9, 10, 11, 12);
69 }
70
71 @Test
72 public void immutableTransformShouldCopyCorrectly() {
73 Transform src = TransformUtils.immutableTransform(
74 1, 2, 3, 4,
75 5, 6, 7, 8,
76 9, 10, 11, 12);
77
78 Transform t = src.clone();
79
80 TransformHelper.assertMatrix(t,
81 1, 2, 3, 4,
82 5, 6, 7, 8,
83 9, 10, 11, 12);
84 }
85
86 @Test public void testImmutableTransformToString() {
87 final Transform trans = TransformUtils.immutableTransform(
88 1, 2, 3, 4,
89 5, 6, 7, 8,
90 9, 10, 11, 12);
91
92 String s = trans.toString();
93
94 assertNotNull(s);
95 assertFalse(s.isEmpty());
96 }
97
98 @Test public void testImmutableTransformState() {
99 int counter = 0;
100 for (Object o : TransformOperationsTest.getParams()) {
101 Object[] arr = (Object[]) o;
102 if (arr[0] instanceof TransformUtils.ImmutableTransform) {
103 TransformUtils.ImmutableTransform t =
104 (TransformUtils.ImmutableTransform) arr[0];
105
106 TransformHelper.assertStateOk("Checking state of transform #" +
107 (counter++) + " of TransformOperationsTest", t,
108 t.getState3d(), t.getState2d());
109 }
110 }
111 }
112
113 @Test public void testReusedImmutableTransform() {
114 int counter = 0;
115 for (Object o : TransformOperationsTest.getParams()) {
116 Object[] arr = (Object[]) o;
117 if (arr[0] instanceof TransformUtils.ImmutableTransform) {
118
119 Transform t = (Transform) arr[0];
120
121
122 // reusing
123 Transform reuse = TransformUtils.immutableTransform(
124 new Translate(10, 20));
125
126 Transform returned = TransformUtils.immutableTransform(reuse, t);
127
128 assertSame("Checking reusing immutable transform to values of #"
129 + counter + " of TransformOperationsTest", reuse, returned);
130
131 TransformHelper.assertStateOk(
132 "Checking reusing immutable transform to values of #"
133 + counter + " of TransformOperationsTest",
134 (TransformUtils.ImmutableTransform) returned,
135 ((TransformUtils.ImmutableTransform) returned).getState3d(),
136 ((TransformUtils.ImmutableTransform) returned).getState2d());
137
138 TransformHelper.assertMatrix("Checking reusing immutable "
139 + "transform to values of #" + counter
140 + " of TransformOperationsTest", returned, t);
141
142 // creating new
143 Transform returned2 = TransformUtils.immutableTransform(null, t);
144
145 assertNotSame("Checking reusing immutable transform to values of #"
146 + counter + " of TransformOperationsTest", returned2, t);
147
148 TransformHelper.assertStateOk(
149 "Checking reusing immutable transform to values of #"
150 + counter + " of TransformOperationsTest",
151 (TransformUtils.ImmutableTransform) returned2,
152 ((TransformUtils.ImmutableTransform) returned2).getState3d(),
153 ((TransformUtils.ImmutableTransform) returned2).getState2d());
154
155 TransformHelper.assertMatrix("Checking reusing immutable "
156 + "transform to values of #" + counter
157 + " of TransformOperationsTest", returned2, t);
158
159 counter++;
160 }
161 }
162 }
163
164 @Test public void testConcatenatedImmutableTransform() {
165
166 List<TransformUtils.ImmutableTransform> ts = new LinkedList<>();
167 for (Object o : TransformOperationsTest.getParams()) {
168 Object[] arr = (Object[]) o;
169 if (arr[0] instanceof TransformUtils.ImmutableTransform) {
170 ts.add((TransformUtils.ImmutableTransform) arr[0]);
171 }
172 }
173
174 int outer = 0;
175 for (TransformUtils.ImmutableTransform t1 : ts) {
176 int inner = 0;
177 for (TransformUtils.ImmutableTransform t2 : ts) {
178 int orig = 0;
179 // reusing
180 for (TransformUtils.ImmutableTransform t3 : ts) {
181 Transform clone = t3.clone();
182 Transform conc = TransformUtils.immutableTransform(
183 clone, t1, t2);
184
185 assertSame("Checking state of concatenation of "
186 + "transform #" + outer + " and #" + inner +
187 " reusing #" + orig +
188 " of TransformOperationsTest", clone, conc);
189 TransformHelper.assertStateOk(
190 "Checking state of concatenation of "
191 + "transform #" + outer + " and #" + inner +
192 " reusing #" + orig +
193 " of TransformOperationsTest",
194 (TransformUtils.ImmutableTransform) conc,
195 ((TransformUtils.ImmutableTransform) conc).getState3d(),
196 ((TransformUtils.ImmutableTransform) conc).getState2d());
197 TransformHelper.assertMatrix(
198 "Checking state of concatenation of "
199 + "transform #" + outer + " and #" + inner +
200 " reusing #" + orig +
201 " of TransformOperationsTest", conc,
202 TransformHelper.concatenate(t1, t2));
203 orig++;
204 }
205
206 // creating new
207 Transform conc2 = TransformUtils.immutableTransform(
208 null, t1, t2);
209
210 assertNotSame("Checking state of concatenation of "
211 + "transform #" + outer + " and #" + inner +
212 " of TransformOperationsTest", conc2, t1);
213 assertNotSame("Checking state of concatenation of "
214 + "transform #" + outer + " and #" + inner +
215 " of TransformOperationsTest", conc2, t2);
216 TransformHelper.assertStateOk(
217 "Checking state of concatenation of "
218 + "transform #" + outer + " and #" + inner +
219 " of TransformOperationsTest",
220 (TransformUtils.ImmutableTransform) conc2,
221 ((TransformUtils.ImmutableTransform) conc2).getState3d(),
222 ((TransformUtils.ImmutableTransform) conc2).getState2d());
223 TransformHelper.assertMatrix(
224 "Checking state of concatenation of "
225 + "transform #" + outer + " and #" + inner +
226 " of TransformOperationsTest", conc2,
227 TransformHelper.concatenate(t1, t2));
228 inner++;
229 }
230 outer++;
231 }
232 }
233 }
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package test.com.sun.javafx.scene.transform;
27
28 import test.com.sun.javafx.test.TransformHelper;
29 import javafx.scene.transform.Transform;
30 import com.sun.javafx.geom.transform.Affine3D;
31 import com.sun.javafx.scene.transform.TransformUtils;
32 import com.sun.javafx.scene.transform.TransformUtilsShim;
33 import java.util.LinkedList;
34 import java.util.List;
35 import test.javafx.scene.transform.TransformOperationsTest;
36 import javafx.scene.transform.Translate;
37 import static org.junit.Assert.*;
38
39 import org.junit.Test;
40
41 public class TransformUtilsTest {
42 @Test
43 public void shouldCreateCorrectImmutableTransform() {
44 Transform t = TransformUtilsShim.getImmutableTransform(
45 1, 2, 3, 4,
46 5, 6, 7, 8,
47 9, 10, 11, 12);
48
49 TransformHelper.assertMatrix(t,
50 1, 2, 3, 4,
51 5, 6, 7, 8,
52 9, 10, 11, 12);
53 }
54
55 @Test
56 public void immutableTransformShouldApplyCorrectly() {
57 Affine3D a = new Affine3D();
58 a.translate(10, 20);
59
60 Transform t = TransformUtilsShim.getImmutableTransform(
61 1, 2, 3, 4,
62 5, 6, 7, 8,
63 9, 10, 11, 12);
64
65 t.impl_apply(a);
66
67 TransformHelper.assertMatrix(a,
68 1, 2, 3, 14,
69 5, 6, 7, 28,
70 9, 10, 11, 12);
71 }
72
73 @Test
74 public void immutableTransformShouldCopyCorrectly() {
75 Transform src = TransformUtilsShim.getImmutableTransform(
76 1, 2, 3, 4,
77 5, 6, 7, 8,
78 9, 10, 11, 12);
79
80 Transform t = src.clone();
81
82 TransformHelper.assertMatrix(t,
83 1, 2, 3, 4,
84 5, 6, 7, 8,
85 9, 10, 11, 12);
86 }
87
88 @Test public void testImmutableTransformToString() {
89 Transform trans = TransformUtilsShim.getImmutableTransform(
90 1, 2, 3, 4,
91 5, 6, 7, 8,
92 9, 10, 11, 12);
93
94 String s = trans.toString();
95
96 assertNotNull(s);
97 assertFalse(s.isEmpty());
98 }
99
100 @Test public void testImmutableTransformState() {
101 int counter = 0;
102 for (Object o : TransformOperationsTest.getParams()) {
103 Object[] arr = (Object[]) o;
104 if (arr[0] instanceof TransformUtilsShim.ImmutableTransformShim) {
105 TransformUtilsShim.ImmutableTransformShim t =
106 (TransformUtilsShim.ImmutableTransformShim) arr[0];
107
108 TransformHelper.assertStateOk("Checking state of transform #" +
109 (counter++) + " of TransformOperationsTest", t,
110 TransformUtilsShim.getImmutableState3d(t),
111 TransformUtilsShim.getImmutableState2d(t));
112 }
113 }
114 }
115
116 @Test public void testReusedImmutableTransform() {
117 int counter = 0;
118 for (Object o : TransformOperationsTest.getParams()) {
119 Object[] arr = (Object[]) o;
120 if (arr[0] instanceof TransformUtilsShim.ImmutableTransformShim) {
121
122 Transform t = (Transform) arr[0];
123
124
125 // reusing
126 Transform reuse = TransformUtils.immutableTransform(
127 new Translate(10, 20));
128
129 Transform returned = TransformUtils.immutableTransform(reuse, t);
130
131 assertSame("Checking reusing immutable transform to values of #"
132 + counter + " of TransformOperationsTest", reuse, returned);
133
134 TransformHelper.assertStateOk(
135 "Checking reusing immutable transform to values of #"
136 + counter + " of TransformOperationsTest",
137 returned,
138 (TransformUtilsShim.getImmutableState3d(returned)),
139 (TransformUtilsShim.getImmutableState2d(returned)));
140
141 TransformHelper.assertMatrix("Checking reusing immutable "
142 + "transform to values of #" + counter
143 + " of TransformOperationsTest", returned, t);
144
145 // creating new
146 Transform returned2 = TransformUtils.immutableTransform(null, t);
147
148 assertNotSame("Checking reusing immutable transform to values of #"
149 + counter + " of TransformOperationsTest", returned2, t);
150
151 TransformHelper.assertStateOk(
152 "Checking reusing immutable transform to values of #"
153 + counter + " of TransformOperationsTest",
154 returned2,
155 TransformUtilsShim.getImmutableState3d(returned),
156 TransformUtilsShim.getImmutableState2d(returned));
157
158 TransformHelper.assertMatrix("Checking reusing immutable "
159 + "transform to values of #" + counter
160 + " of TransformOperationsTest", returned2, t);
161
162 counter++;
163 }
164 }
165 }
166
167 @Test public void testConcatenatedImmutableTransform() {
168
169 List<TransformUtilsShim.ImmutableTransformShim> ts = new LinkedList<>();
170 for (Object o : TransformOperationsTest.getParams()) {
171 Object[] arr = (Object[]) o;
172 if (arr[0] instanceof TransformUtilsShim.ImmutableTransformShim) {
173 ts.add((TransformUtilsShim.ImmutableTransformShim) arr[0]);
174 }
175 }
176
177 int outer = 0;
178 for (TransformUtilsShim.ImmutableTransformShim t1 : ts) {
179 int inner = 0;
180 for (TransformUtilsShim.ImmutableTransformShim t2 : ts) {
181 int orig = 0;
182 // reusing
183 for (TransformUtilsShim.ImmutableTransformShim t3 : ts) {
184 Transform clone = t3.clone();
185 Transform conc = TransformUtils.immutableTransform(
186 clone, t1, t2);
187
188 assertSame("Checking state of concatenation of "
189 + "transform #" + outer + " and #" + inner +
190 " reusing #" + orig +
191 " of TransformOperationsTest", clone, conc);
192 TransformHelper.assertStateOk(
193 "Checking state of concatenation of "
194 + "transform #" + outer + " and #" + inner +
195 " reusing #" + orig +
196 " of TransformOperationsTest",
197 (TransformUtilsShim.ImmutableTransformShim) conc,
198 TransformUtilsShim.getImmutableState3d(conc),
199 TransformUtilsShim.getImmutableState2d(conc));
200 TransformHelper.assertMatrix(
201 "Checking state of concatenation of "
202 + "transform #" + outer + " and #" + inner +
203 " reusing #" + orig +
204 " of TransformOperationsTest", conc,
205 TransformHelper.concatenate(t1, t2));
206 orig++;
207 }
208
209 // creating new
210 Transform conc2 = TransformUtils.immutableTransform(
211 null, t1, t2);
212
213 assertNotSame("Checking state of concatenation of "
214 + "transform #" + outer + " and #" + inner +
215 " of TransformOperationsTest", conc2, t1);
216 assertNotSame("Checking state of concatenation of "
217 + "transform #" + outer + " and #" + inner +
218 " of TransformOperationsTest", conc2, t2);
219 TransformHelper.assertStateOk(
220 "Checking state of concatenation of "
221 + "transform #" + outer + " and #" + inner +
222 " of TransformOperationsTest",
223 (TransformUtilsShim.ImmutableTransformShim) conc2,
224 TransformUtilsShim.getImmutableState3d(conc2),
225 TransformUtilsShim.getImmutableState2d(conc2));
226 TransformHelper.assertMatrix(
227 "Checking state of concatenation of "
228 + "transform #" + outer + " and #" + inner +
229 " of TransformOperationsTest", conc2,
230 TransformHelper.concatenate(t1, t2));
231 inner++;
232 }
233 outer++;
234 }
235 }
236 }
|