modules/graphics/src/test/java/test/javafx/scene/transform/TransformTest.java

Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:


   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 com.sun.javafx.geom.transform.Affine2D;
  29 import com.sun.javafx.geom.transform.Affine3D;
  30 import com.sun.javafx.geom.transform.BaseTransform;
  31 import com.sun.javafx.scene.transform.TransformUtils;
  32 import com.sun.javafx.test.TransformHelper;
  33 import javafx.beans.property.DoubleProperty;
  34 import javafx.beans.property.SimpleDoubleProperty;
  35 import javafx.geometry.BoundingBox;
  36 import javafx.geometry.Point3D;
  37 import javafx.scene.Group;
  38 import javafx.scene.Node;
  39 import javafx.scene.NodeTest;
  40 import javafx.scene.Scene;
  41 import javafx.scene.shape.Rectangle;
  42 import javafx.scene.shape.RectangleTest;
  43 import org.junit.Assert;
  44 import org.junit.Test;
  45 
  46 import java.lang.reflect.Method;




  47 
  48 import static org.junit.Assert.*;
  49 
  50 
  51 public class TransformTest {
  52 
  53     static void assertTx(Node n, BaseTransform trans) {
  54         Assert.assertEquals(trans, n.impl_getLeafTransform());
  55     }
  56 
  57 
  58     @Test
  59     public void testTranslate() {
  60         Transform tx = Transform.translate(25, 52);
  61         final Rectangle n = new Rectangle();
  62         n.getTransforms().add(tx);
  63 
  64         assertTx(n, BaseTransform.getTranslateInstance(25, 52));
  65     }
  66 
  67 
  68     @Test
  69     public void testScale1() {
  70         Transform tx = Transform.scale(25, 52);
  71         final Rectangle n = new Rectangle();
  72         n.getTransforms().add(tx);
  73 


 197         assertFalse(t1.similarTo(t2, new BoundingBox(0, -1, 0, 1, 0, 1), limit));
 198         assertFalse(t1.similarTo(t2, new BoundingBox(-1, 0, 0, 0, 1, 1), limit));
 199         assertFalse(t1.similarTo(t2, new BoundingBox(0, 0, 0, 1, 1, 1), limit));
 200     }
 201 
 202     @Test
 203     public void eachCornerShouldBeConsideredBySimilarTo2D() {
 204         final Transform t1 = new Affine();
 205         final Transform t2 = new Scale(11, 11);
 206         final double limit = Math.sqrt(200) - 1;
 207 
 208         assertTrue(t1.similarTo(t2, new BoundingBox(0, 0, 0, 0, 0, 0), limit));
 209         assertTrue(t1.similarTo(t2, new BoundingBox(0, 0, 0, 0.1, 0.1, 0.1), limit));
 210         assertFalse(t1.similarTo(t2, new BoundingBox(-1, -1, 0, 0, 0, 0), limit));
 211         assertFalse(t1.similarTo(t2, new BoundingBox(0, -1, 0, 1, 0, 0), limit));
 212         assertFalse(t1.similarTo(t2, new BoundingBox(-1, 0, 0, 0, 1, 0), limit));
 213         assertFalse(t1.similarTo(t2, new BoundingBox(0, 0, 0, 1, 1, 0), limit));
 214     }
 215 
 216 
 217     static void checkDoublePropertySynced(Transform tr, String propertyName, double val)
 218         throws Exception {
 219 
 220         final Rectangle r = new RectangleTest.StubRectangle(200, 200, 200, 200);
 221 
 222         DoubleProperty v = new SimpleDoubleProperty(0.0);
 223         Method m = tr.getClass().getMethod(propertyName + "Property", new Class[] {});
 224         ((DoubleProperty)m.invoke(tr)).bind(v);
 225 
 226         r.getTransforms().add(tr);
 227         ((Group)new Scene(new Group()).getRoot()).getChildren().add(r);
 228 
 229         v.set(val);
 230         NodeTest.syncNode(r);
 231 
 232         //check
 233         RectangleTest.StubNGRectangle pgR = r.impl_getPeer();
 234         assertTx(r, pgR.getTransformMatrix());
 235     }
 236 }


   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 com.sun.javafx.geom.transform.Affine2D;
  29 import com.sun.javafx.geom.transform.Affine3D;
  30 import com.sun.javafx.geom.transform.BaseTransform;
  31 import com.sun.javafx.scene.transform.TransformUtils;
  32 import test.com.sun.javafx.test.TransformHelper;
  33 import javafx.beans.property.DoubleProperty;
  34 import javafx.beans.property.SimpleDoubleProperty;
  35 import javafx.geometry.BoundingBox;
  36 import javafx.geometry.Point3D;
  37 import javafx.scene.Group;
  38 import javafx.scene.Node;
  39 import test.javafx.scene.NodeTest;
  40 import javafx.scene.Scene;
  41 import javafx.scene.shape.Rectangle;
  42 import test.javafx.scene.shape.RectangleTest;
  43 import org.junit.Assert;
  44 import org.junit.Test;
  45 
  46 import java.lang.reflect.Method;
  47 import javafx.scene.transform.Affine;
  48 import javafx.scene.transform.Rotate;
  49 import javafx.scene.transform.Scale;
  50 import javafx.scene.transform.Transform;
  51 
  52 import static org.junit.Assert.*;
  53 
  54 
  55 public class TransformTest {
  56 
  57     public static void assertTx(Node n, BaseTransform trans) {
  58         Assert.assertEquals(trans, n.impl_getLeafTransform());
  59     }
  60 
  61 
  62     @Test
  63     public void testTranslate() {
  64         Transform tx = Transform.translate(25, 52);
  65         final Rectangle n = new Rectangle();
  66         n.getTransforms().add(tx);
  67 
  68         assertTx(n, BaseTransform.getTranslateInstance(25, 52));
  69     }
  70 
  71 
  72     @Test
  73     public void testScale1() {
  74         Transform tx = Transform.scale(25, 52);
  75         final Rectangle n = new Rectangle();
  76         n.getTransforms().add(tx);
  77 


 201         assertFalse(t1.similarTo(t2, new BoundingBox(0, -1, 0, 1, 0, 1), limit));
 202         assertFalse(t1.similarTo(t2, new BoundingBox(-1, 0, 0, 0, 1, 1), limit));
 203         assertFalse(t1.similarTo(t2, new BoundingBox(0, 0, 0, 1, 1, 1), limit));
 204     }
 205 
 206     @Test
 207     public void eachCornerShouldBeConsideredBySimilarTo2D() {
 208         final Transform t1 = new Affine();
 209         final Transform t2 = new Scale(11, 11);
 210         final double limit = Math.sqrt(200) - 1;
 211 
 212         assertTrue(t1.similarTo(t2, new BoundingBox(0, 0, 0, 0, 0, 0), limit));
 213         assertTrue(t1.similarTo(t2, new BoundingBox(0, 0, 0, 0.1, 0.1, 0.1), limit));
 214         assertFalse(t1.similarTo(t2, new BoundingBox(-1, -1, 0, 0, 0, 0), limit));
 215         assertFalse(t1.similarTo(t2, new BoundingBox(0, -1, 0, 1, 0, 0), limit));
 216         assertFalse(t1.similarTo(t2, new BoundingBox(-1, 0, 0, 0, 1, 0), limit));
 217         assertFalse(t1.similarTo(t2, new BoundingBox(0, 0, 0, 1, 1, 0), limit));
 218     }
 219 
 220 
 221     public static void checkDoublePropertySynced(Transform tr, String propertyName, double val)
 222         throws Exception {
 223 
 224         final Rectangle r = new RectangleTest.StubRectangle(200, 200, 200, 200);
 225 
 226         DoubleProperty v = new SimpleDoubleProperty(0.0);
 227         Method m = tr.getClass().getMethod(propertyName + "Property", new Class[] {});
 228         ((DoubleProperty)m.invoke(tr)).bind(v);
 229 
 230         r.getTransforms().add(tr);
 231         ((Group)new Scene(new Group()).getRoot()).getChildren().add(r);
 232 
 233         v.set(val);
 234         NodeTest.syncNode(r);
 235 
 236         //check
 237         RectangleTest.StubNGRectangle pgR = r.impl_getPeer();
 238         assertTx(r, pgR.getTransformMatrix());
 239     }
 240 }