modules/graphics/src/test/java/javafx/css/InsetsTypeTest.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 static org.junit.Assert.assertEquals;
  29 import static org.junit.Assert.fail;
  30 
  31 import java.io.IOException;
  32 import javafx.css.ParsedValue;
  33 import javafx.geometry.Insets;
  34 import javafx.scene.text.Font;
  35 
  36 import org.junit.Before;
  37 import org.junit.Test;
  38 
  39 import com.sun.javafx.css.parser.CSSParser;
  40 
  41 
  42 public class InsetsTypeTest {
  43 
  44     String[] css;
  45 
  46     Insets[][] expResults;
  47 
  48     // values for top, right, bottom, left
  49     final float[][][] fvals = new float[][][] {
  50         { {1.0f} },
  51         { {-1.0f, 0.0f, 1.0f, 2.0f} },
  52         { {1.0f}, {2.0f}, {3.0f}, {4.0f} },
  53         { {1.0f, 0.0f, 1.0f, 2.0f},
  54           {2.0f, 0.0f, 1.0f, 2.0f},
  55           {3.0f, 0.0f, 1.0f, 2.0f},
  56           {4.0f, 0.0f, 1.0f, 2.0f} },
  57         { {1.0f},
  58           {2.0f, -1.0f},
  59           {3.0f, 0.0f, 1.0f, 2.0f},


  90         float top =  (vals.length > 0) ? vals[0] : 0.0f;
  91         float right = (vals.length > 1) ? vals[1] : top;
  92         float bottom = (vals.length > 2) ? vals[2] : top;
  93         float left = (vals.length > 3) ? vals[3] : right;
  94         return new Insets(top, right, bottom, left);
  95     }
  96 
  97     void checkInsets(String msg, Insets expResult, Insets result) {
  98         assertEquals(msg + "top", expResult.getTop(), result.getTop(), 0.01);
  99         assertEquals(msg + "right", expResult.getRight(), result.getRight(), 0.01);
 100         assertEquals(msg + "bottom", expResult.getBottom(), result.getBottom(), 0.01);
 101         assertEquals(msg + "left", expResult.getLeft(), result.getLeft(), 0.01);
 102     }
 103 
 104     @Test
 105     public void testConvert() {
 106 
 107         for (int i=0; i<css.length; i++) {
 108 
 109             Stylesheet stylesheet =
 110                 CSSParser.getInstance().parse("* { -fx-border-insets: " + css[i] + "; }");
 111 
 112             ParsedValue value =
 113                     TypeTest.getValueFor(stylesheet, "-fx-border-insets");
 114 
 115             Insets[] insets = (Insets[]) value.convert(Font.getDefault());
 116 
 117             //assertEquals(expResults[i].length,insets.length);
 118 
 119             for(int j=0; j<insets.length; j++) {
 120                 String msg = Integer.toString(i) + "." + Integer.toString(j);
 121                 checkInsets(msg, expResults[i][j], insets[j]);
 122             }
 123         }
 124     }
 125 }


   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 static org.junit.Assert.assertEquals;
  29 import static org.junit.Assert.fail;
  30 
  31 import java.io.IOException;

  32 import javafx.geometry.Insets;
  33 import javafx.scene.text.Font;
  34 
  35 import org.junit.Before;
  36 import org.junit.Test;
  37 
  38 import javafx.css.CssParser;
  39 
  40 
  41 public class InsetsTypeTest {
  42 
  43     String[] css;
  44 
  45     Insets[][] expResults;
  46 
  47     // values for top, right, bottom, left
  48     final float[][][] fvals = new float[][][] {
  49         { {1.0f} },
  50         { {-1.0f, 0.0f, 1.0f, 2.0f} },
  51         { {1.0f}, {2.0f}, {3.0f}, {4.0f} },
  52         { {1.0f, 0.0f, 1.0f, 2.0f},
  53           {2.0f, 0.0f, 1.0f, 2.0f},
  54           {3.0f, 0.0f, 1.0f, 2.0f},
  55           {4.0f, 0.0f, 1.0f, 2.0f} },
  56         { {1.0f},
  57           {2.0f, -1.0f},
  58           {3.0f, 0.0f, 1.0f, 2.0f},


  89         float top =  (vals.length > 0) ? vals[0] : 0.0f;
  90         float right = (vals.length > 1) ? vals[1] : top;
  91         float bottom = (vals.length > 2) ? vals[2] : top;
  92         float left = (vals.length > 3) ? vals[3] : right;
  93         return new Insets(top, right, bottom, left);
  94     }
  95 
  96     void checkInsets(String msg, Insets expResult, Insets result) {
  97         assertEquals(msg + "top", expResult.getTop(), result.getTop(), 0.01);
  98         assertEquals(msg + "right", expResult.getRight(), result.getRight(), 0.01);
  99         assertEquals(msg + "bottom", expResult.getBottom(), result.getBottom(), 0.01);
 100         assertEquals(msg + "left", expResult.getLeft(), result.getLeft(), 0.01);
 101     }
 102 
 103     @Test
 104     public void testConvert() {
 105 
 106         for (int i=0; i<css.length; i++) {
 107 
 108             Stylesheet stylesheet =
 109                 new CssParser().parse("* { -fx-border-insets: " + css[i] + "; }");
 110 
 111             ParsedValue value =
 112                     TypeTest.getValueFor(stylesheet, "-fx-border-insets");
 113 
 114             Insets[] insets = (Insets[]) value.convert(Font.getDefault());
 115 
 116             //assertEquals(expResults[i].length,insets.length);
 117 
 118             for(int j=0; j<insets.length; j++) {
 119                 String msg = Integer.toString(i) + "." + Integer.toString(j);
 120                 checkInsets(msg, expResults[i][j], insets[j]);
 121             }
 122         }
 123     }
 124 }