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