1 /* 2 * Copyright (c) 2012, 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.parser.CSSParser; 29 import java.util.ArrayList; 30 import java.util.Arrays; 31 import java.util.Collection; 32 import java.util.List; 33 import org.junit.Test; 34 import static org.junit.Assert.*; 35 36 import org.junit.runner.RunWith; 37 import org.junit.runners.Parameterized; 38 import org.junit.runners.Parameterized.Parameters; 39 40 @RunWith(Parameterized.class) 41 public class StyleTest { 42 43 private static class Data { 44 private final String s1, s2; 45 private final boolean expected; 46 Data(String s1, String s2, boolean expected){ 47 this.s1 = s1; 48 this.s2 = s2; 49 this.expected = expected; 50 } 51 52 @Override public String toString() { 53 return "\"" + s1 + "\" " + (expected ? "==" : "!=") + " \"" + s2 + "\""; 54 } 55 } 56 57 public StyleTest(Data data) { 58 this.data = data; 59 } 60 private final Data data; 61 62 private static Style createStyle(String stylesheetText) { 63 64 Stylesheet stylesheet = CSSParser.getInstance().parse(stylesheetText); 65 Rule rule = stylesheet.getRules().get(0); 66 Selector sel = rule.getUnobservedSelectorList().get(0); 67 Declaration decl = rule.getUnobservedDeclarationList().get(0); 68 return new Style(sel, decl); 69 } 70 71 @Parameters 72 public static Collection data() { 73 74 return Arrays.asList(new Object[] { 75 new Object[] { new Data("*.style { -fx-fill: red; }", 76 "*.style { -fx-fill: red; }", true) }, 77 new Object[] { new Data("*.style { -fx-fill: red; }", 78 "*.bad { -fx-fill: red; }", false) }, 79 new Object[] { new Data("*.style:p { -fx-fill: red; }", 80 "*.style:p { -fx-fill: red; }", true) }, 81 new Object[] { new Data("*.style:p { -fx-fill: red; }", 82 "*.style:q { -fx-fill: red; }", false) }, 83 new Object[] { new Data("*.style:p { -fx-fill: red; }", 84 "*.bad:p { -fx-fill: red; }", false) }, 85 new Object[] { new Data("*.style#c { -fx-fill: red; }", 86 "*.style#c { -fx-fill: red; }", true) }, 87 new Object[] { new Data("*.style#c { -fx-fill: red; }", 88 "*.style#d { -fx-fill: red; }", false) }, 89 new Object[] { new Data("*.style#c:p { -fx-fill: red; }", 90 "*.style#c:p { -fx-fill: red; }", true) }, 91 new Object[] { new Data("*.style#c:p { -fx-fill: red; }", 92 "*.style#c:q { -fx-fill: red; }", false) }, 93 new Object[] { new Data("*.style { -fx-fill: red; }", 94 "*.style { -fx-fill: green; }", false) }, 95 new Object[] { new Data("*.style { -fx-border-color: red; }", 96 "*.style { -fx-fill: red; }", false) }, 97 }); 98 } 99 100 @Test 101 public void testEquals() { 102 103 Style instance = createStyle(data.s1); 104 Style obj = createStyle(data.s2); 105 boolean expected = data.expected; 106 boolean actual = instance.equals(obj); 107 assertTrue(data.toString(), expected == actual); 108 109 } 110 111 }