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

  28 import javafx.css.converter.SizeConverter;
  29 import javafx.css.ParsedValue;
  30 import javafx.css.Size;
  31 import javafx.css.SizeUnits;

  32 import javafx.scene.text.Font;
  33 import static org.junit.Assert.assertEquals;
  34 import org.junit.Test;
  35 
  36 
  37 public class FontSizeTypeTest {
  38 
  39     public FontSizeTypeTest() {
  40     }
  41 
  42     /**
  43      * Test of convert method, of class FontSizeType.
  44      */
  45     @Test
  46     public void testConvertToPixels() {
  47         ParsedValue<Size,Size> size = new ParsedValueImpl<Size,Size>(new Size(2.0f, SizeUnits.EM), null);
  48         ParsedValue<ParsedValue<?,Size>,Number> value = new ParsedValueImpl<ParsedValue<?,Size>,Number>(size, SizeConverter.getInstance());
  49         Font font = Font.getDefault();
  50         double expResult = SizeUnits.EM.pixels(2, 1, font);
  51         double result = SizeConverter.getInstance().convert(value, font).doubleValue();
  52         assertEquals(expResult, result, 0.01);
  53 
  54         size = new ParsedValueImpl<Size,Size>(new Size(120.0f, SizeUnits.PERCENT), null);
  55         value = new ParsedValueImpl<ParsedValue<?,Size>,Number>(size, SizeConverter.getInstance());
  56         expResult = SizeUnits.PERCENT.pixels(120, 1, font);
  57         result = SizeConverter.getInstance().convert(value, font).doubleValue();
  58         assertEquals(expResult, result, 0.01);
  59 
  60         size = new ParsedValueImpl<Size,Size>(new Size(12.0f, SizeUnits.PT), null);
  61         value = new ParsedValueImpl<ParsedValue<?,Size>,Number>(size, SizeConverter.getInstance());
  62         expResult = SizeUnits.PT.pixels(12, 1, font);
  63         result = SizeConverter.getInstance().convert(value, font).doubleValue();
  64         assertEquals(expResult, result, 0.01);
  65 
  66         size = new ParsedValueImpl<Size,Size>(new Size(12.0f, SizeUnits.PX), null);
  67         value = new ParsedValueImpl<ParsedValue<?,Size>,Number>(size, SizeConverter.getInstance());
  68         expResult = SizeUnits.PX.pixels(12, 1, font);
  69         result = SizeConverter.getInstance().convert(value, font).doubleValue();
  70         assertEquals(expResult, result, 0.01);
  71     }
  72 
  73 //    @Test
  74 //    public void testConvertToPoints() {
  75 //
  76 //        Font font = Font.getDefault();
  77 //        // font size is in pixels. convert to points
  78 //        double pointSize = font.getSize() / javafx.stage.Screen.getPrimary().getDpi() * 72;
  79 //
  80 //        ParsedValue<Size,Size> size = new ParsedValueImpl<Size,Size>(new Size(2.0f, SizeUnits.EM), null);
  81 //        ParsedValue<Value<?,Size>,Double> value = new ParsedValueImpl<Value<?,Size>,Double>(size, StyleConverter.POINTS);
  82 //        double expResult = SizeUnits.EM.points(2, 1, font);
  83 //        double result = StyleConverter.POINTS.convert(value, font);
  84 //        assertEquals(expResult, result, 0.01);
  85 //
  86 //        size = new ParsedValueImpl<Size,Size>(new Size(120.0f, SizeUnits.PERCENT), null);
  87 //        value = new ParsedValueImpl<Value<?,Size>,Double>(size, StyleConverter.POINTS);
  88 //        expResult = SizeUnits.PERCENT.points(120, 1, font);


   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.com.sun.javafx.css;
  27 
  28 import com.sun.javafx.css.ParsedValueImpl;
  29 import javafx.css.converter.SizeConverter;
  30 import javafx.css.ParsedValue;
  31 import javafx.css.Size;
  32 import javafx.css.SizeUnits;
  33 import javafx.css.SizeUnitsShim;
  34 import javafx.scene.text.Font;
  35 import static org.junit.Assert.assertEquals;
  36 import org.junit.Test;
  37 
  38 
  39 public class FontSizeTypeTest {
  40 
  41     public FontSizeTypeTest() {
  42     }
  43 
  44     /**
  45      * Test of convert method, of class FontSizeType.
  46      */
  47     @Test
  48     public void testConvertToPixels() {
  49         ParsedValue<Size,Size> size = new ParsedValueImpl<Size,Size>(new Size(2.0f, SizeUnits.EM), null);
  50         ParsedValue<ParsedValue<?,Size>,Number> value = new ParsedValueImpl<ParsedValue<?,Size>,Number>(size, SizeConverter.getInstance());
  51         Font font = Font.getDefault();
  52         double expResult = SizeUnitsShim.pixels(SizeUnits.EM, 2, 1, font);
  53         double result = SizeConverter.getInstance().convert(value, font).doubleValue();
  54         assertEquals(expResult, result, 0.01);
  55 
  56         size = new ParsedValueImpl<Size,Size>(new Size(120.0f, SizeUnits.PERCENT), null);
  57         value = new ParsedValueImpl<ParsedValue<?,Size>,Number>(size, SizeConverter.getInstance());
  58         expResult = SizeUnitsShim.pixels(SizeUnits.PERCENT, 120, 1, font);
  59         result = SizeConverter.getInstance().convert(value, font).doubleValue();
  60         assertEquals(expResult, result, 0.01);
  61 
  62         size = new ParsedValueImpl<Size,Size>(new Size(12.0f, SizeUnits.PT), null);
  63         value = new ParsedValueImpl<ParsedValue<?,Size>,Number>(size, SizeConverter.getInstance());
  64         expResult = SizeUnitsShim.pixels(SizeUnits.PT, 12, 1, font);
  65         result = SizeConverter.getInstance().convert(value, font).doubleValue();
  66         assertEquals(expResult, result, 0.01);
  67 
  68         size = new ParsedValueImpl<Size,Size>(new Size(12.0f, SizeUnits.PX), null);
  69         value = new ParsedValueImpl<ParsedValue<?,Size>,Number>(size, SizeConverter.getInstance());
  70         expResult = SizeUnitsShim.pixels(SizeUnits.PX, 12, 1, font);
  71         result = SizeConverter.getInstance().convert(value, font).doubleValue();
  72         assertEquals(expResult, result, 0.01);
  73     }
  74 
  75 //    @Test
  76 //    public void testConvertToPoints() {
  77 //
  78 //        Font font = Font.getDefault();
  79 //        // font size is in pixels. convert to points
  80 //        double pointSize = font.getSize() / javafx.stage.Screen.getPrimary().getDpi() * 72;
  81 //
  82 //        ParsedValue<Size,Size> size = new ParsedValueImpl<Size,Size>(new Size(2.0f, SizeUnits.EM), null);
  83 //        ParsedValue<Value<?,Size>,Double> value = new ParsedValueImpl<Value<?,Size>,Double>(size, StyleConverter.POINTS);
  84 //        double expResult = SizeUnits.EM.points(2, 1, font);
  85 //        double result = StyleConverter.POINTS.convert(value, font);
  86 //        assertEquals(expResult, result, 0.01);
  87 //
  88 //        size = new ParsedValueImpl<Size,Size>(new Size(120.0f, SizeUnits.PERCENT), null);
  89 //        value = new ParsedValueImpl<Value<?,Size>,Double>(size, StyleConverter.POINTS);
  90 //        expResult = SizeUnits.PERCENT.points(120, 1, font);