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 test.javafx.css;
  27 
  28 import com.sun.javafx.css.ParsedValueImpl;
  29 import javafx.css.StylesheetShim;
  30 import javafx.css.StyleConverter.StringStore;
  31 
  32 import java.io.DataInputStream;
  33 import java.io.DataOutputStream;
  34 import java.util.ArrayList;
  35 import java.util.Collections;
  36 import java.util.List;
  37 import javafx.css.Declaration;
  38 import javafx.css.DeclarationShim;
  39 import javafx.css.Rule;
  40 import javafx.css.RuleShim;
  41 import javafx.css.Selector;
  42 import javafx.css.StyleOrigin;
  43 import javafx.css.Stylesheet;
  44 import javafx.css.StylesheetShim;
  45 import javafx.scene.Node;
  46 import org.junit.AfterClass;
  47 import org.junit.Test;
  48 import static org.junit.Assert.*;
  49 import org.junit.BeforeClass;
  50 import org.junit.Ignore;
  51 
  52 
  53 public class RuleTest {
  54     
  55     public RuleTest() {
  56     }
  57 
  58     @BeforeClass
  59     public static void setUpClass() throws Exception {
  60     }
  61 
  62     @AfterClass
  63     public static void tearDownClass() throws Exception {
  64     }
  65 
  66     @Test
  67     public void testGetUnobservedSelectorList() {
  68         List<Selector> expResult = new ArrayList<Selector>();
  69         expResult.add(Selector.createSelector("One.two#three"));
  70         expResult.add(Selector.createSelector("Four.five#six"));
  71         Rule instance = RuleShim.getRule(expResult, Collections.EMPTY_LIST);
  72         List result = RuleShim.getUnobservedSelectorList(instance);
  73         assertEquals(expResult, result);
  74     }
  75 
  76     @Test
  77     public void testGetUnobservedDeclarationList() {
  78         List<Declaration> expResult = new ArrayList<Declaration>();
  79         expResult.add(DeclarationShim.getDeclaration("one", new ParsedValueImpl<String,String>("one", null), false));
  80         expResult.add(DeclarationShim.getDeclaration("two", new ParsedValueImpl<String,String>("two", null), false));
  81         expResult.add(DeclarationShim.getDeclaration("three", new ParsedValueImpl<String,String>("three", null), false));
  82         Rule instance = RuleShim.getRule(Collections.EMPTY_LIST, expResult);
  83         List result = RuleShim.getUnobservedDeclarationList(instance);
  84         assertEquals(expResult, result);
  85     }
  86 
  87     @Test
  88     public void testGetSelectors() {
  89         List<Selector> expResult = new ArrayList<Selector>();
  90         expResult.add(Selector.createSelector("One.two#three"));
  91         expResult.add(Selector.createSelector("Four.five#six"));
  92         Rule instance = RuleShim.getRule(expResult, Collections.EMPTY_LIST);
  93         List result = instance.getSelectors();
  94         assertEquals(expResult, result);
  95     }
  96 
  97     @Test
  98     public void testGetDeclarations() {
  99         List<Declaration> expResult = new ArrayList<Declaration>();
 100         expResult.add(DeclarationShim.getDeclaration("one", new ParsedValueImpl<String,String>("one", null), false));
 101         expResult.add(DeclarationShim.getDeclaration("two", new ParsedValueImpl<String,String>("two", null), false));
 102         expResult.add(DeclarationShim.getDeclaration("three", new ParsedValueImpl<String,String>("three", null), false));
 103         Rule instance = RuleShim.getRule(Collections.EMPTY_LIST, expResult);
 104         List result = instance.getDeclarations();
 105         assertEquals(expResult, result);
 106     }
 107 
 108     @Test
 109     public void testGetStylesheet() {
 110         Rule instance = RuleShim.getRule(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
 111         Stylesheet expResult = new StylesheetShim();
 112         expResult.getRules().add(instance);
 113         Stylesheet result = instance.getStylesheet();
 114         assertEquals(expResult, result);
 115     }
 116 
 117     @Test
 118     public void testGetOriginAfterSettingOriginAfterAddingRuleToStylesheet() {
 119         Rule instance = RuleShim.getRule(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
 120         Stylesheet stylesheet = new StylesheetShim();
 121         stylesheet.getRules().add(instance);
 122         stylesheet.setOrigin(StyleOrigin.INLINE);
 123         StyleOrigin expResult = StyleOrigin.INLINE;
 124         StyleOrigin result = instance.getOrigin();
 125         assertEquals(expResult, result);
 126     }
 127 
 128     @Test
 129     public void testGetOriginAfterSettingOriginBeforeAddingRuleToStylesheet() {
 130         Rule instance = RuleShim.getRule(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
 131         Stylesheet stylesheet = new StylesheetShim();
 132         stylesheet.setOrigin(StyleOrigin.INLINE);
 133         stylesheet.getRules().add(instance);
 134         StyleOrigin expResult = StyleOrigin.INLINE;
 135         StyleOrigin result = instance.getOrigin();
 136         assertEquals(expResult, result);
 137     }
 138     
 139     @Test
 140     public void testGetOriginWithoutAddingRuleToStylesheet() {
 141         Rule instance = RuleShim.getRule(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
 142         StyleOrigin result = instance.getOrigin();
 143         assertNull(result);
 144     }
 145 
 146     @Test
 147     public void testGetOriginAfterRemovingRuleFromStylesheet() {
 148         Rule instance = RuleShim.getRule(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
 149         Stylesheet stylesheet = new StylesheetShim();
 150         stylesheet.getRules().add(instance);
 151         stylesheet.setOrigin(StyleOrigin.INLINE);
 152         stylesheet.getRules().remove(instance);        
 153         StyleOrigin result = instance.getOrigin();
 154         assertNull(result);
 155     }
 156 
 157     @Ignore @Test
 158     public void testApplies() {
 159         System.out.println("applies");
 160         Node node = null;
 161         Rule instance = null;
 162         long expResult = 0l;
 163         long result = RuleShim.applies(instance, node, null);
 164         assertEquals(expResult, result);
 165         fail("The test case is a prototype.");
 166     }
 167 
 168     @Ignore @Test
 169     public void testToString() {
 170         System.out.println("toString");
 171         Rule instance = null;
 172         String expResult = "";
 173         String result = instance.toString();
 174         assertEquals(expResult, result);
 175         fail("The test case is a prototype.");
 176     }
 177 
 178     @Ignore @Test
 179     public void testWriteBinary() throws Exception {
 180         System.out.println("writeBinary");
 181         DataOutputStream os = null;
 182         StringStore stringStore = null;
 183         Rule instance = null;
 184         RuleShim.writeBinary(instance, os, stringStore);
 185         fail("The test case is a prototype.");
 186     }
 187 
 188     @Ignore @Test
 189     public void testReadBinary() throws Exception {
 190         System.out.println("readBinary");
 191         DataInputStream is = null;
 192         String[] strings = null;
 193         Rule expResult = null;
 194         Rule result = RuleShim.readBinary(StylesheetShim.BINARY_CSS_VERSION, is, strings);
 195         assertEquals(expResult, result);
 196         fail("The test case is a prototype.");
 197     }
 198 }