1 /* 2 * Copyright (c) 2011, 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 javafx.scene.transform; 27 28 import static javafx.scene.transform.TransformTest.assertTx; 29 30 import com.sun.javafx.FXUnit; 31 import javafx.scene.shape.Rectangle; 32 33 import org.junit.Assert; 34 import org.junit.Rule; 35 import org.junit.Test; 36 import static org.junit.Assert.*; 37 38 import com.sun.javafx.test.TransformHelper; 39 import com.sun.javafx.geom.transform.BaseTransform; 40 41 42 public class TranslateTest { 43 44 @Rule 45 public FXUnit fx = new FXUnit(); 46 47 @Test 48 public void testTranslate() { 49 final Translate trans = new Translate() {{ 50 setX(25); 51 setY(52); 52 }}; 53 final Rectangle n = new Rectangle(); 54 n.getTransforms().add(trans); 55 56 assertTx(n, BaseTransform.getTranslateInstance(25, 52)); 57 TransformHelper.assertMatrix(trans, 58 1, 0, 0, 25, 59 0, 1, 0, 52, 60 0, 0, 1, 0); 61 62 trans.setX(34); 63 Assert.assertEquals(34, trans.getX(), 1e-100); 64 assertTx(n, BaseTransform.getTranslateInstance(34, 52)); 65 TransformHelper.assertMatrix(trans, 66 1, 0, 0, 34, 67 0, 1, 0, 52, 68 0, 0, 1, 0); 69 70 71 trans.setY(67); 72 assertTx(n, BaseTransform.getTranslateInstance(34, 67)); 73 TransformHelper.assertMatrix(trans, 74 1, 0, 0, 34, 75 0, 1, 0, 67, 76 0, 0, 1, 0); 77 78 trans.setZ(33); 79 TransformHelper.assertMatrix(trans, 80 1, 0, 0, 34, 81 0, 1, 0, 67, 82 0, 0, 1, 33); 83 } 84 85 @Test 86 public void testCopying() { 87 final Translate trans = new Translate(34, 67, 33); 88 89 Transform copy = trans.clone(); 90 91 TransformHelper.assertMatrix(copy, 92 1, 0, 0, 34, 93 0, 1, 0, 67, 94 0, 0, 1, 33); 95 } 96 97 @Test public void testToString() { 98 final Translate trans = new Translate(8, 15); 99 100 String s = trans.toString(); 101 102 assertNotNull(s); 103 assertFalse(s.isEmpty()); 104 } 105 106 @Test public void testBoundPropertySynced_X() throws Exception { 107 TransformTest.checkDoublePropertySynced(new Translate(3, 3, 0), "x", 22.0); 108 } 109 110 @Test public void testBoundPropertySynced_Y() throws Exception { 111 TransformTest.checkDoublePropertySynced(new Translate(3, 3, 0), "y", 33.0); 112 } 113 114 @Test public void testBoundPropertySynced_Z() throws Exception { 115 TransformTest.checkDoublePropertySynced(new Translate(3, 3, 0), "z", 44.0); 116 } 117 }