modules/graphics/src/test/java/test/javafx/scene/transform/TransformOperationsTest.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 java.util.Arrays;
  29 import java.util.Collection;
  30 import javafx.beans.InvalidationListener;
  31 import javafx.beans.Observable;
  32 import javafx.beans.value.ChangeListener;
  33 import javafx.beans.value.ObservableValue;
  34 import javafx.event.EventHandler;
  35 import javafx.geometry.BoundingBox;
  36 import javafx.geometry.Bounds;
  37 import javafx.geometry.Point2D;
  38 import javafx.geometry.Point3D;
  39 import com.sun.javafx.scene.transform.TransformUtils;
  40 import com.sun.javafx.test.TransformHelper;










  41 import org.junit.Test;
  42 import org.junit.runner.RunWith;
  43 import org.junit.runners.Parameterized;
  44 import org.junit.runners.Parameterized.Parameters;
  45 
  46 import static org.junit.Assert.*;
  47 
  48 @RunWith(Parameterized.class)
  49 public class TransformOperationsTest {
  50     private static final Affine affine_identity = new Affine();
  51     private static final Affine affine_translate_only = new Affine(0, 0, 2,
  52                                                                    0, 0, 3);
  53     private static final Affine affine_translate = new Affine(1, 0, 2,
  54                                                               0, 1, 3);
  55     private static final Affine affine_scale = new Affine(4, 0, 0,
  56                                                           0, 5, 0);
  57     private static final Affine affine_sc_tr = new Affine(6, 0, 8,
  58                                                           0, 7, 9);
  59     private static final Affine affine_shear = new Affine( 0, 10, 0,
  60                                                           11,  0, 0);


 605         try {
 606             res = ct.createInverse();
 607         } catch(NonInvertibleTransformException e) {
 608             if (canInvert) {
 609                 e.printStackTrace();
 610                 fail("NonInvertibleTransformException thrown for invertible transform");
 611             } else {
 612                 // ok
 613                 return;
 614             }
 615         }
 616 
 617         if (!isInvertible) {
 618             fail("Should have thrown NonInvertibleTransformException");
 619         }
 620 
 621         assertNotNull(res);
 622         TransformHelper.assertMatrix(res, inv);
 623 
 624         // emulate garbage collection of the cache to check it's renewed
 625         ct.clearInverseCache();
 626 
 627         try {
 628             res = ct.createInverse();
 629         } catch(NonInvertibleTransformException e) {
 630             if (canInvert) {
 631                 e.printStackTrace();
 632                 fail("NonInvertibleTransformException thrown for invertible transform");
 633             } else {
 634                 // ok
 635                 return;
 636             }
 637         }
 638 
 639         if (!isInvertible) {
 640             fail("Should have thrown NonInvertibleTransformException");
 641         }
 642 
 643         assertNotNull(res);
 644         TransformHelper.assertMatrix(res, inv);
 645     }




   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 java.util.Arrays;
  29 import java.util.Collection;
  30 import javafx.beans.InvalidationListener;
  31 import javafx.beans.Observable;
  32 import javafx.beans.value.ChangeListener;
  33 import javafx.beans.value.ObservableValue;
  34 import javafx.event.EventHandler;
  35 import javafx.geometry.BoundingBox;
  36 import javafx.geometry.Bounds;
  37 import javafx.geometry.Point2D;
  38 import javafx.geometry.Point3D;
  39 import com.sun.javafx.scene.transform.TransformUtils;
  40 import javafx.scene.transform.Affine;
  41 import javafx.scene.transform.MatrixType;
  42 import javafx.scene.transform.NonInvertibleTransformException;
  43 import javafx.scene.transform.Rotate;
  44 import javafx.scene.transform.Scale;
  45 import javafx.scene.transform.Shear;
  46 import javafx.scene.transform.Transform;
  47 import javafx.scene.transform.TransformChangedEvent;
  48 import javafx.scene.transform.TransformShim;
  49 import javafx.scene.transform.Translate;
  50 import test.com.sun.javafx.test.TransformHelper;
  51 import org.junit.Test;
  52 import org.junit.runner.RunWith;
  53 import org.junit.runners.Parameterized;
  54 import org.junit.runners.Parameterized.Parameters;
  55 
  56 import static org.junit.Assert.*;
  57 
  58 @RunWith(Parameterized.class)
  59 public class TransformOperationsTest {
  60     private static final Affine affine_identity = new Affine();
  61     private static final Affine affine_translate_only = new Affine(0, 0, 2,
  62                                                                    0, 0, 3);
  63     private static final Affine affine_translate = new Affine(1, 0, 2,
  64                                                               0, 1, 3);
  65     private static final Affine affine_scale = new Affine(4, 0, 0,
  66                                                           0, 5, 0);
  67     private static final Affine affine_sc_tr = new Affine(6, 0, 8,
  68                                                           0, 7, 9);
  69     private static final Affine affine_shear = new Affine( 0, 10, 0,
  70                                                           11,  0, 0);


 615         try {
 616             res = ct.createInverse();
 617         } catch(NonInvertibleTransformException e) {
 618             if (canInvert) {
 619                 e.printStackTrace();
 620                 fail("NonInvertibleTransformException thrown for invertible transform");
 621             } else {
 622                 // ok
 623                 return;
 624             }
 625         }
 626 
 627         if (!isInvertible) {
 628             fail("Should have thrown NonInvertibleTransformException");
 629         }
 630 
 631         assertNotNull(res);
 632         TransformHelper.assertMatrix(res, inv);
 633 
 634         // emulate garbage collection of the cache to check it's renewed
 635         TransformShim.clearInverseCache(ct);
 636 
 637         try {
 638             res = ct.createInverse();
 639         } catch(NonInvertibleTransformException e) {
 640             if (canInvert) {
 641                 e.printStackTrace();
 642                 fail("NonInvertibleTransformException thrown for invertible transform");
 643             } else {
 644                 // ok
 645                 return;
 646             }
 647         }
 648 
 649         if (!isInvertible) {
 650             fail("Should have thrown NonInvertibleTransformException");
 651         }
 652 
 653         assertNotNull(res);
 654         TransformHelper.assertMatrix(res, inv);
 655     }