1 /* 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 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 }