modules/graphics/src/test/java/test/javafx/css/SizeTest.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.css;
  27 



  28 import static org.junit.Assert.assertEquals;
  29 import javafx.scene.text.Font;
  30 
  31 import org.junit.Test;
  32 
  33 
  34 public class SizeTest {
  35 
  36     public SizeTest() {
  37     }
  38 
  39     static final private double DOTS_PER_INCH = 96.0;
  40     static final private double POINTS_PER_INCH = 72.0;
  41 
  42     /**
  43      * Test of points method, of class Size.
  44      */
  45     @Test
  46     public void testPoints() {
  47         final Font font = Font.font("Amble", 16);
  48         final double pixelSize = font.getSize();
  49         final double pointSize = pixelSize * (POINTS_PER_INCH / DOTS_PER_INCH);
  50 
  51         Size instance = new Size(12.0, SizeUnits.PX);
  52         double expResult = 12.0  * (POINTS_PER_INCH/DOTS_PER_INCH);
  53         double result = instance.points(font);
  54         assertEquals("px", expResult, result, 0.01);
  55 
  56         instance = new Size(12.0, SizeUnits.PT);
  57         expResult = 12.0; // PT is absolute
  58         result = instance.points(font);
  59         assertEquals("pt", expResult, result, 0.01);
  60 
  61         instance = new Size(50.0, SizeUnits.PERCENT);
  62         expResult = 0.5 * pointSize;
  63         result = instance.points(pointSize, font);
  64         assertEquals("%", expResult, result, 0.01);
  65 
  66         instance = new Size(2, SizeUnits.EM);
  67         expResult = 2 * pointSize;
  68         result = instance.points(font);
  69         assertEquals("em", expResult, result, 0.01);
  70 
  71         instance = new Size(1.0, SizeUnits.EX);
  72         expResult = 0.5 * pointSize;
  73         result = instance.points(font);
  74         assertEquals("ex", expResult, result, 0.01);
  75 
  76 
  77         instance = new Size(1.0, SizeUnits.CM);
  78         expResult = POINTS_PER_INCH/2.54; // CM is absolute (pts per inch/cm per inch)
  79         result = instance.points(font);
  80         assertEquals("cm", expResult, result, 0.01);
  81 
  82         instance = new Size(1.0, SizeUnits.MM);
  83         expResult = POINTS_PER_INCH/25.4; // MM is absolute (pts per inch/mm per inch)
  84         result = instance.points(font);
  85         assertEquals("mm", expResult, result, 0.01);
  86 
  87         instance = new Size(1.0, SizeUnits.IN);
  88         expResult = POINTS_PER_INCH; // IN is absolute (pts per inch)
  89         result = instance.points(font);
  90         assertEquals("in", expResult, result, 0.01);
  91 
  92         instance = new Size(1.0, SizeUnits.PC);
  93         expResult = 12.0; // PC is absolute (pts per pica)
  94         result = instance.points(font);
  95         assertEquals("pc", expResult, result, 0.01);
  96 
  97     }
  98 
  99     /**
 100      * Test of pixels method, of class Size.
 101      */
 102     @Test
 103     public void testPixels() {
 104         final Font font = Font.font("Amble", 16);
 105         final double pixelSize = font.getSize();
 106         final double pointSize = pixelSize * (POINTS_PER_INCH / DOTS_PER_INCH);
 107 
 108         Size instance = new Size(12.0, SizeUnits.PX);
 109         double expResult = 12.0;
 110         double result = instance.pixels(font);
 111         assertEquals("px", expResult, result, 0.01);
 112 
 113         instance = new Size(12.0, SizeUnits.PT);
 114         expResult = 12.0 * (DOTS_PER_INCH / POINTS_PER_INCH);




   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.css;
  27 
  28 import javafx.css.Size;
  29 import javafx.css.SizeShim;
  30 import javafx.css.SizeUnits;
  31 import static org.junit.Assert.assertEquals;
  32 import javafx.scene.text.Font;
  33 
  34 import org.junit.Test;
  35 
  36 
  37 public class SizeTest {
  38 
  39     public SizeTest() {
  40     }
  41 
  42     static final private double DOTS_PER_INCH = 96.0;
  43     static final private double POINTS_PER_INCH = 72.0;
  44 
  45     /**
  46      * Test of points method, of class Size.
  47      */
  48     @Test
  49     public void testPoints() {
  50         final Font font = Font.font("Amble", 16);
  51         final double pixelSize = font.getSize();
  52         final double pointSize = pixelSize * (POINTS_PER_INCH / DOTS_PER_INCH);
  53 
  54         Size instance = new Size(12.0, SizeUnits.PX);
  55         double expResult = 12.0  * (POINTS_PER_INCH/DOTS_PER_INCH);
  56         double result = SizeShim.points(instance, font);
  57         assertEquals("px", expResult, result, 0.01);
  58 
  59         instance = new Size(12.0, SizeUnits.PT);
  60         expResult = 12.0; // PT is absolute
  61         result = SizeShim.points(instance, font);
  62         assertEquals("pt", expResult, result, 0.01);
  63 
  64         instance = new Size(50.0, SizeUnits.PERCENT);
  65         expResult = 0.5 * pointSize;
  66         result = SizeShim.points(instance, pointSize, font);
  67         assertEquals("%", expResult, result, 0.01);
  68 
  69         instance = new Size(2, SizeUnits.EM);
  70         expResult = 2 * pointSize;
  71         result = SizeShim.points(instance, font);
  72         assertEquals("em", expResult, result, 0.01);
  73 
  74         instance = new Size(1.0, SizeUnits.EX);
  75         expResult = 0.5 * pointSize;
  76         result = SizeShim.points(instance, font);
  77         assertEquals("ex", expResult, result, 0.01);
  78 
  79 
  80         instance = new Size(1.0, SizeUnits.CM);
  81         expResult = POINTS_PER_INCH/2.54; // CM is absolute (pts per inch/cm per inch)
  82         result = SizeShim.points(instance, font);
  83         assertEquals("cm", expResult, result, 0.01);
  84 
  85         instance = new Size(1.0, SizeUnits.MM);
  86         expResult = POINTS_PER_INCH/25.4; // MM is absolute (pts per inch/mm per inch)
  87         result = SizeShim.points(instance, font);
  88         assertEquals("mm", expResult, result, 0.01);
  89 
  90         instance = new Size(1.0, SizeUnits.IN);
  91         expResult = POINTS_PER_INCH; // IN is absolute (pts per inch)
  92         result = SizeShim.points(instance, font);
  93         assertEquals("in", expResult, result, 0.01);
  94 
  95         instance = new Size(1.0, SizeUnits.PC);
  96         expResult = 12.0; // PC is absolute (pts per pica)
  97         result = SizeShim.points(instance, font);
  98         assertEquals("pc", expResult, result, 0.01);
  99 
 100     }
 101 
 102     /**
 103      * Test of pixels method, of class Size.
 104      */
 105     @Test
 106     public void testPixels() {
 107         final Font font = Font.font("Amble", 16);
 108         final double pixelSize = font.getSize();
 109         final double pointSize = pixelSize * (POINTS_PER_INCH / DOTS_PER_INCH);
 110 
 111         Size instance = new Size(12.0, SizeUnits.PX);
 112         double expResult = 12.0;
 113         double result = instance.pixels(font);
 114         assertEquals("px", expResult, result, 0.01);
 115 
 116         instance = new Size(12.0, SizeUnits.PT);
 117         expResult = 12.0 * (DOTS_PER_INCH / POINTS_PER_INCH);