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