modules/graphics/src/test/java/javafx/css/StylesheetTest.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


   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.EnumConverter;
  29 import com.sun.javafx.css.converters.StringConverter;
  30 import com.sun.javafx.css.parser.CSSParser;
  31 import javafx.css.ParsedValue;
  32 import javafx.css.StyleConverter;
  33 import javafx.css.StyleOrigin;
  34 
  35 import java.io.ByteArrayInputStream;
  36 import java.io.ByteArrayOutputStream;
  37 import java.io.DataInputStream;
  38 import java.io.DataOutputStream;
  39 import java.io.File;
  40 import java.io.FileWriter;
  41 import java.io.IOException;
  42 import java.io.OutputStreamWriter;
  43 import java.net.URISyntaxException;
  44 import java.net.URL;
  45 import java.util.Collections;
  46 import java.util.List;
  47 import java.util.Locale;
  48 import java.util.Map;
  49 
  50 import javafx.css.StyleableProperty;
  51 import javafx.geometry.NodeOrientation;
  52 import javafx.geometry.Orientation;
  53 import javafx.geometry.Pos;
  54 import javafx.geometry.VPos;
  55 import javafx.scene.Group;
  56 import javafx.scene.Scene;
  57 import javafx.scene.layout.StackPane;
  58 import javafx.scene.paint.Color;
  59 import javafx.scene.paint.LinearGradient;
  60 import javafx.scene.paint.Paint;
  61 import javafx.scene.paint.RadialGradient;
  62 import javafx.scene.shape.Rectangle;
  63 import javafx.scene.text.Font;
  64 import javafx.scene.text.FontSmoothingType;
  65 import javafx.scene.text.TextAlignment;
  66 import javafx.stage.Stage;
  67 import org.junit.*;
  68 import static org.junit.Assert.*;
  69 import static org.junit.Assert.assertEquals;
  70 
  71 
  72 public class StylesheetTest {
  73 
  74     String testURL = null;
  75     
  76     public StylesheetTest() {
  77         testURL = getClass().getResource("HonorDeveloperSettingsTest_UA.css").toExternalForm();
  78     }
  79 


 221     @Test
 222     public void testLoadBinary() {
 223         System.out.println("loadBinary");
 224         URL url = null;
 225         Stylesheet expResult = null;
 226         Stylesheet result = Stylesheet.loadBinary(url);
 227         assertEquals(expResult, result);
 228         // TODO review the generated test code and remove the default call to fail.
 229         fail("The test case is a prototype.");
 230     }
 231      */
 232     
 233     @Test public void test_RT_18126() {
 234         // CSS cannot write binary -fx-background-repeat: repeat, no-repeat;
 235         String data = "#rt18126 {"
 236                 + "-fx-background-repeat: repeat, no-repeat;"
 237                 + "-fx-border-image-repeat: repeat, no-repeat;"
 238                 + "}";
 239 
 240         try {
 241             Stylesheet stylesheet = CSSParser.getInstance().parse(data);
 242 
 243             StringStore stringStore = new StringStore();
 244             ByteArrayOutputStream baos = new ByteArrayOutputStream();
 245             DataOutputStream dos = new DataOutputStream(baos);
 246             stylesheet.writeBinary(dos, stringStore);
 247             dos.flush();
 248             dos.close();
 249 
 250             ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
 251             DataInputStream dis = new DataInputStream(bais);
 252 
 253             Stylesheet restored = new Stylesheet();
 254             restored.readBinary(Stylesheet.BINARY_CSS_VERSION, dis, stringStore.strings.toArray(new String[stringStore.strings.size()]));
 255 
 256             List<Rule> cssRules = stylesheet.getRules();
 257             List<Rule> bssRules = restored.getRules();
 258 
 259             // Rule does not have an equals method
 260             assert(cssRules.size() == bssRules.size());
 261             for (int n=0; n<cssRules.size(); n++) {


 434             // Shows value was left alone
 435             assertNull(rect.getFill());
 436 
 437         } catch (Exception e) {
 438             // The code generates an IllegalArgumentException that should never reach here
 439             fail("Exception not expected: " + e.toString());
 440         }
 441     }
 442 
 443     @Test
 444     public void testRT_30953_parse() {
 445 
 446         try {
 447             // Make sure RT-30953.css can be parsed, serialized and deserialized with the current code,
 448             // no matter the bss version
 449             URL url = StylesheetTest.class.getResource("RT-30953.css");
 450             if (url == null) {
 451                 fail("Can't find RT-30953.css");
 452             }
 453 
 454             Stylesheet ss = CSSParser.getInstance().parse(url);
 455             int nFontFaceSrcs = checkFontFace(ss);
 456             assertEquals(3, nFontFaceSrcs);
 457             checkConvert(ss);
 458 
 459         } catch (Exception e) {
 460             fail(e.toString());
 461         }
 462 
 463     }
 464 
 465     @Test public void testRT_30953_deserialize_from_v4() {
 466         // RT-30953-v4.bss was generated with version 4
 467         Stylesheet ss = deserialize("RT-30953-v4.bss");
 468         checkConvert(ss);
 469     }
 470 
 471     @Test
 472     public void testRT_30953_deserialize_from_2_2_45() {
 473 
 474         // RT-30953-2.2.4bss was generated with javafx version 2.2.45 from 7u??


 565                             if (cl != null) {
 566                                 (new EnumConverter(cl)).convert(pv, null);
 567                             }
 568                         } else {
 569                             System.out.println("No converter for " + d.toString() + ". Skipped conversion.");
 570                         }
 571                         continue;
 572                     }
 573                     Object value = converter.convert(pv, Font.getDefault());
 574                 }
 575             }
 576         } catch (Exception e) {
 577             if (decl == null) fail(e.toString());
 578             else if (converter != null) fail(decl.getProperty() + ", " + converter + ", " + e.toString());
 579             else fail(decl.getProperty() + ", " + e.toString());
 580         }
 581 
 582     }
 583 
 584     private int checkFontFace(Stylesheet stylesheet) {
 585         return com.sun.javafx.css.parser.CSSParserTest.checkFontFace(stylesheet);
 586     }
 587 
 588    @Test
 589    public void testRT_37122() {
 590        try {
 591            URL url = StylesheetTest.class.getResource("RT-37122.css");
 592            File source = new File(url.toURI());
 593            File target = File.createTempFile("RT_37122_", "bss");
 594            Stylesheet.convertToBinary(source, target);
 595            Stylesheet.convertToBinary(source, target);
 596        } catch (URISyntaxException | IOException e) {
 597            fail(e.toString());
 598        }
 599    }
 600 
 601     @Test
 602     public void testRT_37301() {
 603         try {
 604             File source = File.createTempFile("RT_37301_", "css");
 605             FileWriter writer = new FileWriter(source);




   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 javafx.css;
  27 
  28 import javafx.css.StyleConverter.StringStore;
  29 import javafx.css.converter.EnumConverter;
  30 import javafx.css.converter.StringConverter;



  31 
  32 import java.io.ByteArrayInputStream;
  33 import java.io.ByteArrayOutputStream;
  34 import java.io.DataInputStream;
  35 import java.io.DataOutputStream;
  36 import java.io.File;
  37 import java.io.FileWriter;
  38 import java.io.IOException;

  39 import java.net.URISyntaxException;
  40 import java.net.URL;
  41 import java.util.Collections;
  42 import java.util.List;
  43 import java.util.Locale;

  44 

  45 import javafx.geometry.NodeOrientation;
  46 import javafx.geometry.Orientation;
  47 import javafx.geometry.Pos;
  48 import javafx.geometry.VPos;
  49 import javafx.scene.Group;
  50 import javafx.scene.Scene;
  51 import javafx.scene.layout.StackPane;
  52 import javafx.scene.paint.Color;

  53 import javafx.scene.paint.Paint;
  54 import javafx.scene.paint.RadialGradient;
  55 import javafx.scene.shape.Rectangle;
  56 import javafx.scene.text.Font;
  57 import javafx.scene.text.FontSmoothingType;
  58 import javafx.scene.text.TextAlignment;
  59 import javafx.stage.Stage;
  60 import org.junit.*;
  61 import static org.junit.Assert.*;
  62 import static org.junit.Assert.assertEquals;
  63 
  64 
  65 public class StylesheetTest {
  66 
  67     String testURL = null;
  68     
  69     public StylesheetTest() {
  70         testURL = getClass().getResource("HonorDeveloperSettingsTest_UA.css").toExternalForm();
  71     }
  72 


 214     @Test
 215     public void testLoadBinary() {
 216         System.out.println("loadBinary");
 217         URL url = null;
 218         Stylesheet expResult = null;
 219         Stylesheet result = Stylesheet.loadBinary(url);
 220         assertEquals(expResult, result);
 221         // TODO review the generated test code and remove the default call to fail.
 222         fail("The test case is a prototype.");
 223     }
 224      */
 225     
 226     @Test public void test_RT_18126() {
 227         // CSS cannot write binary -fx-background-repeat: repeat, no-repeat;
 228         String data = "#rt18126 {"
 229                 + "-fx-background-repeat: repeat, no-repeat;"
 230                 + "-fx-border-image-repeat: repeat, no-repeat;"
 231                 + "}";
 232 
 233         try {
 234             Stylesheet stylesheet = new CssParser().parse(data);
 235 
 236             StringStore stringStore = new StringStore();
 237             ByteArrayOutputStream baos = new ByteArrayOutputStream();
 238             DataOutputStream dos = new DataOutputStream(baos);
 239             stylesheet.writeBinary(dos, stringStore);
 240             dos.flush();
 241             dos.close();
 242 
 243             ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
 244             DataInputStream dis = new DataInputStream(bais);
 245 
 246             Stylesheet restored = new Stylesheet();
 247             restored.readBinary(Stylesheet.BINARY_CSS_VERSION, dis, stringStore.strings.toArray(new String[stringStore.strings.size()]));
 248 
 249             List<Rule> cssRules = stylesheet.getRules();
 250             List<Rule> bssRules = restored.getRules();
 251 
 252             // Rule does not have an equals method
 253             assert(cssRules.size() == bssRules.size());
 254             for (int n=0; n<cssRules.size(); n++) {


 427             // Shows value was left alone
 428             assertNull(rect.getFill());
 429 
 430         } catch (Exception e) {
 431             // The code generates an IllegalArgumentException that should never reach here
 432             fail("Exception not expected: " + e.toString());
 433         }
 434     }
 435 
 436     @Test
 437     public void testRT_30953_parse() {
 438 
 439         try {
 440             // Make sure RT-30953.css can be parsed, serialized and deserialized with the current code,
 441             // no matter the bss version
 442             URL url = StylesheetTest.class.getResource("RT-30953.css");
 443             if (url == null) {
 444                 fail("Can't find RT-30953.css");
 445             }
 446 
 447             Stylesheet ss = new CssParser().parse(url);
 448             int nFontFaceSrcs = checkFontFace(ss);
 449             assertEquals(3, nFontFaceSrcs);
 450             checkConvert(ss);
 451 
 452         } catch (Exception e) {
 453             fail(e.toString());
 454         }
 455 
 456     }
 457 
 458     @Test public void testRT_30953_deserialize_from_v4() {
 459         // RT-30953-v4.bss was generated with version 4
 460         Stylesheet ss = deserialize("RT-30953-v4.bss");
 461         checkConvert(ss);
 462     }
 463 
 464     @Test
 465     public void testRT_30953_deserialize_from_2_2_45() {
 466 
 467         // RT-30953-2.2.4bss was generated with javafx version 2.2.45 from 7u??


 558                             if (cl != null) {
 559                                 (new EnumConverter(cl)).convert(pv, null);
 560                             }
 561                         } else {
 562                             System.out.println("No converter for " + d.toString() + ". Skipped conversion.");
 563                         }
 564                         continue;
 565                     }
 566                     Object value = converter.convert(pv, Font.getDefault());
 567                 }
 568             }
 569         } catch (Exception e) {
 570             if (decl == null) fail(e.toString());
 571             else if (converter != null) fail(decl.getProperty() + ", " + converter + ", " + e.toString());
 572             else fail(decl.getProperty() + ", " + e.toString());
 573         }
 574 
 575     }
 576 
 577     private int checkFontFace(Stylesheet stylesheet) {
 578         return javafx.css.CssParserTest.checkFontFace(stylesheet);
 579     }
 580 
 581    @Test
 582    public void testRT_37122() {
 583        try {
 584            URL url = StylesheetTest.class.getResource("RT-37122.css");
 585            File source = new File(url.toURI());
 586            File target = File.createTempFile("RT_37122_", "bss");
 587            Stylesheet.convertToBinary(source, target);
 588            Stylesheet.convertToBinary(source, target);
 589        } catch (URISyntaxException | IOException e) {
 590            fail(e.toString());
 591        }
 592    }
 593 
 594     @Test
 595     public void testRT_37301() {
 596         try {
 597             File source = File.createTempFile("RT_37301_", "css");
 598             FileWriter writer = new FileWriter(source);