--- old/modules/graphics/src/test/java/com/sun/javafx/css/CssMetaDataTest.java 2015-09-03 15:35:27.320670400 -0700 +++ /dev/null 2015-09-03 15:35:28.000000000 -0700 @@ -1,1290 +0,0 @@ -/* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.css; - -import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import com.sun.javafx.sg.prism.NGNode; -import javafx.beans.value.WritableValue; -import javafx.css.CssMetaData; -import javafx.css.FontCssMetaData; -import javafx.css.PseudoClass; -import javafx.css.StyleConverter; -import javafx.css.StyleOrigin; -import javafx.css.Styleable; -import javafx.css.StyleableProperty; -import javafx.scene.Group; -import javafx.scene.Node; -import javafx.scene.Scene; -import javafx.scene.paint.Color; -import javafx.scene.shape.Rectangle; -import javafx.scene.text.Font; -import javafx.scene.text.Text; -import javafx.stage.Stage; -import com.sun.javafx.css.converters.BooleanConverter; -import com.sun.javafx.css.parser.CSSParser; -import com.sun.javafx.geom.BaseBounds; -import com.sun.javafx.geom.transform.BaseTransform; -import com.sun.javafx.jmx.MXNodeAlgorithm; -import com.sun.javafx.jmx.MXNodeAlgorithmContext; -import org.junit.Test; - -import static org.junit.Assert.*; - - -public class CssMetaDataTest { - - public CssMetaDataTest() { - } - - private static CssMetaData get(List> list, String prop) { - for (CssMetaData styleable : list) { - if (prop.equals(styleable.getProperty())) return styleable; - } - return null; - } - - /** - * Test of getCssMetaData method of class Styleable. - */ - @Test - public void testGetCssMetaData_Styleable() { - Styleable styleable = new TestNode(); - List> expResult = TestNode.getClassCssMetaData(); - List result = styleable.getCssMetaData(); - assertEquals(expResult, result); - } - - @Test - public void testGetJavafxBeansProperty() { - TestNode testNode = new TestNode(); - WritableValue prop = TestNodeBase.StyleableProperties.TEST.getStyleableProperty(testNode); - assert(prop != null); - CssMetaData result = ((StyleableProperty)prop).getCssMetaData(); - assert(result == TestNodeBase.StyleableProperties.TEST); - } - - /** - * Test of getProperty method, of class CssMetaData. - */ - @Test - public void testGetProperty() { - - String expResult = "-fx-test"; - String result = TestNodeBase.StyleableProperties.TEST.getProperty(); - assertEquals(expResult, result); - } - - /** - * Test of getConverter method, of class CssMetaData. - */ - @Test - public void testGetConverter() { - - StyleConverter expResult = BooleanConverter.getInstance(); - StyleConverter result = TestNodeBase.StyleableProperties.TEST.getConverter(); - assertEquals(expResult, result); - } - - /** - * Test of getInitialValue method, of class CssMetaData. - */ - @Test - public void testGetInitialValue() { - - TestNode testNode = new TestNode(); - Double expResult = testNode.getXyzzy(); - Double result = (Double)TestNode.StyleableProperties.XYZZY.getInitialValue(testNode); - assertEquals(expResult, result); - - } - - /** - * Test of getSubProperties method, of class CssMetaData. - */ - @Test - public void testGetSubProperties() { - - CssMetaData fontProp = - new FontCssMetaData("-fx-font", Font.getDefault()) { - - @Override - public boolean isSettable(TestNode n) { - return true; - } - - @Override - public StyleableProperty getStyleableProperty(TestNode n) { - return null; - } - }; - - List> list = fontProp.getSubProperties(); - assertNotNull(list); - - } - - /** - * Test of isInherits method, of class CssMetaData. - */ - @Test - public void testIsInherits() { - - boolean expResult = false; - boolean result = TestNode.StyleableProperties.XYZZY.isInherits(); - assertEquals(expResult, result); - - } - - /** - * Test of toString method, of class CssMetaData. - */ - @Test - public void testToString() { - - CssMetaData fontProp = - new FontCssMetaData("-fx-font", Font.getDefault()) { - - @Override - public boolean isSettable(TestNode n) { - return true; - } - - @Override - public StyleableProperty getStyleableProperty(TestNode n) { - return null; - } - }; - - String string = fontProp.toString(); - assertNotNull(string); - - } - - /** - * Test of equals method, of class CssMetaData. - */ - @Test - public void testEquals() { - TestNode testNode = new TestNode(); - Node node = new Node() { - - @Override - protected NGNode impl_createPeer() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public BaseBounds impl_computeGeomBounds(BaseBounds bb, BaseTransform bt) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - protected boolean impl_computeContains(double d, double d1) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public Object impl_processMXNode(MXNodeAlgorithm mxna, MXNodeAlgorithmContext mxnac) { - throw new UnsupportedOperationException("Not supported yet."); - } - }; - - CssMetaData testNodeOpacity = get(TestNode.getClassCssMetaData(), "-fx-opacity"); - CssMetaData nodeOpacity = get(Node.getClassCssMetaData(), "-fx-opacity"); - - assertTrue(testNodeOpacity.equals(nodeOpacity)); - } - - static int ord = 0; - static CascadingStyle createCascadingStyle(Selector selector, Declaration declaration) { - - Set pseudoClasses = null; - if (selector instanceof SimpleSelector) { - - pseudoClasses = ((SimpleSelector)selector).getPseudoClassStates(); - } else { - - pseudoClasses = new PseudoClassState(); - for (SimpleSelector sel : ((CompoundSelector)selector).getSelectors()) { - - Set selectorPseudoClasses = sel.getPseudoClassStates(); - pseudoClasses.addAll(selectorPseudoClasses); - } - } - - return new CascadingStyle( - new Style(selector, declaration), - pseudoClasses, - 0, - ord++ - ); - } - - @Test @org.junit.Ignore - public void testGetMatchingStyles() { - - - final Stylesheet stylesheet = new Stylesheet(); - stylesheet.setOrigin(StyleOrigin.USER_AGENT); - StyleManager.getInstance().getInstance().setDefaultUserAgentStylesheet(stylesheet); - - final List rules = stylesheet.getRules(); - - // - // .root { -fx-base: red; -fx-color: -fx-base; } - // - List rootStyleClass = new ArrayList(); - rootStyleClass.add("root"); - - Selector root = new SimpleSelector("*", rootStyleClass, null, null); - - ParsedValueImpl fxBaseValue = CSSParser.getInstance().parseExpr("-fx-base", "red"); - Declaration fxBase = new Declaration("-fx-base", fxBaseValue, false); - - ParsedValueImpl fxColorValue = new ParsedValueImpl(fxBase.getProperty(), null, true); - Declaration fxColor = new Declaration("-fx-color", fxColorValue, false); - - List selectors = new ArrayList(); - Collections.addAll(selectors, root); - - List declarations = new ArrayList(); - Collections.addAll(declarations, fxBase, fxColor); - - Rule baseRule = new Rule(selectors, declarations); - rules.add(baseRule); - - // - // .rect { -fx-fill: -fx-color; } - // - List rectStyleClass = new ArrayList(); - rectStyleClass.add("rect"); - - Selector rect = new SimpleSelector("*", rectStyleClass, null, null); - - ParsedValueImpl fxFillValue = CSSParser.getInstance().parseExpr("-fx-fill", "-fx-color"); - Declaration fxFill = new Declaration("-fx-fill", fxFillValue, false); - - selectors = new ArrayList(); - Collections.addAll(selectors, rect); - - declarations = new ArrayList(); - Collections.addAll(declarations, fxFill); - - Rule rectRule = new Rule(selectors, declarations); - rules.add(rectRule); - - // .rect:hover { -fx-fill: yellow; } - List pseudoclasses = new ArrayList(); - pseudoclasses.add("hover"); - - Selector rectHover = new SimpleSelector("*", rectStyleClass, pseudoclasses, null); - - ParsedValueImpl fxFillHoverValue = new ParsedValueImpl(Color.YELLOW, null); - Declaration fxFillHover = new Declaration("-fx-fill", fxFillHoverValue, false); - - selectors = new ArrayList(); - Collections.addAll(selectors, rectHover); - - declarations = new ArrayList(); - Collections.addAll(declarations, fxFillHover); - - Rule rectHoverRule = new Rule(selectors, declarations); - rules.add(rectHoverRule); - - List