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 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); 89 // result = StyleConverter.POINTS.convert(value, font); 90 // assertEquals(expResult, result, 0.01); 91 // 92 // size = new ParsedValueImpl<Size,Size>(new Size(12.0f, SizeUnits.PT), null); 93 // value = new ParsedValueImpl<Value<?,Size>,Double>(size, StyleConverter.POINTS); 94 // expResult = SizeUnits.PT.points(12, 1, font); 95 // result = StyleConverter.POINTS.convert(value, font); 96 // assertEquals(expResult, result, 0.01); 97 // 98 // size = new ParsedValueImpl<Size,Size>(new Size(12.0f, SizeUnits.PX), null); 99 // value = new ParsedValueImpl<Value<?,Size>,Double>(size, StyleConverter.POINTS); 100 // expResult = SizeUnits.PX.points(12, 1, font); 101 // result = StyleConverter.POINTS.convert(value, font); 102 // assertEquals(expResult, result, 0.01); 103 // 104 // } 105 106 }