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.com.sun.prism.impl.shape; 27 28 import com.sun.javafx.geom.PathIterator; 29 import com.sun.prism.BasicStroke; 30 import com.sun.prism.impl.shape.NativePiscesRasterizerShim; 31 import org.junit.Test; 32 33 public class NativePiscesRasterizerTest { 34 static final int JOIN_BEVEL = BasicStroke.JOIN_BEVEL; 35 static final int JOIN_MITER = BasicStroke.JOIN_MITER; 36 static final int JOIN_ROUND = BasicStroke.JOIN_ROUND; 37 38 static final int CAP_SQUARE = BasicStroke.CAP_SQUARE; 39 static final int CAP_ROUND = BasicStroke.CAP_ROUND; 40 static final int CAP_BUTT = BasicStroke.CAP_BUTT; 41 42 static final byte SEG_MOVETO = PathIterator.SEG_MOVETO; 43 static final byte SEG_LINETO = PathIterator.SEG_LINETO; 44 static final byte SEG_QUADTO = PathIterator.SEG_QUADTO; 45 static final byte SEG_CUBICTO = PathIterator.SEG_CUBICTO; 46 static final byte SEG_CLOSE = PathIterator.SEG_CLOSE; 47 48 static final float coords6[] = new float[6]; 49 static final float coords1[] = new float[1]; 50 static final float coords3[] = new float[3]; 51 static final float coords5[] = new float[5]; 52 static final float coords7[] = new float[7]; 53 static final byte move_arr[] = { SEG_MOVETO }; 54 static final byte moveline_arr[] = { SEG_MOVETO, SEG_LINETO }; 55 static final byte movequad_arr[] = { SEG_MOVETO, SEG_QUADTO }; 56 static final byte movecubic_arr[] = { SEG_MOVETO, SEG_CUBICTO }; 57 static final int bounds10[] = { 0, 0, 10, 10 }; 58 static final byte mask1k[] = new byte[1024]; 59 60 @Test(expected=java.lang.NullPointerException.class) 61 public void FillNullCoords() { 62 NativePiscesRasterizerShim.produceFillAlphas(null, move_arr, 1, true, 63 1, 0, 0, 0, 1, 0, 64 bounds10, mask1k); 65 } 66 67 @Test(expected=java.lang.NullPointerException.class) 68 public void FillNullCommands() { 69 NativePiscesRasterizerShim.produceFillAlphas(coords6, null, 1, true, 70 1, 0, 0, 0, 1, 0, 71 bounds10, mask1k); 72 } 73 74 @Test(expected=java.lang.NullPointerException.class) 75 public void FillNullBounds() { 76 NativePiscesRasterizerShim.produceFillAlphas(coords6, move_arr, 1, true, 77 1, 0, 0, 0, 1, 0, 78 null, mask1k); 79 } 80 81 @Test(expected=java.lang.NullPointerException.class) 82 public void FillNullMask() { 83 NativePiscesRasterizerShim.produceFillAlphas(coords6, move_arr, 1, true, 84 1, 0, 0, 0, 1, 0, 85 bounds10, null); 86 } 87 88 @Test(expected=java.lang.ArrayIndexOutOfBoundsException.class) 89 public void FillShortBounds() { 90 NativePiscesRasterizerShim.produceFillAlphas(coords6, move_arr, 1, true, 91 1, 0, 0, 0, 1, 0, 92 new int[3], mask1k); 93 } 94 95 @Test(expected=java.lang.ArrayIndexOutOfBoundsException.class) 96 public void FillShortCommands() { 97 NativePiscesRasterizerShim.produceFillAlphas(coords6, move_arr, 2, true, 98 1, 0, 0, 0, 1, 0, 99 bounds10, mask1k); 100 } 101 102 @Test 103 public void FillBadCommands() { 104 byte badcmd_arr[] = new byte[2]; 105 badcmd_arr[0] = SEG_MOVETO; 106 for (int i = 0; i < 256; i++) { 107 switch (i) { 108 case SEG_MOVETO: 109 case SEG_LINETO: 110 case SEG_QUADTO: 111 case SEG_CUBICTO: 112 case SEG_CLOSE: 113 continue; 114 default: 115 badcmd_arr[1] = (byte) i; 116 try { 117 NativePiscesRasterizerShim.produceFillAlphas(coords6, badcmd_arr, 2, true, 118 1, 0, 0, 0, 1, 0, 119 bounds10, mask1k); 120 throw new RuntimeException("allowed bad command: "+i); 121 } catch (InternalError e) { 122 } 123 break; 124 } 125 } 126 } 127 128 @Test(expected=java.lang.ArrayIndexOutOfBoundsException.class) 129 public void FillShortMoveCoords() { 130 NativePiscesRasterizerShim.produceFillAlphas(coords1, move_arr, 1, true, 131 1, 0, 0, 0, 1, 0, 132 bounds10, mask1k); 133 } 134 135 @Test(expected=java.lang.ArrayIndexOutOfBoundsException.class) 136 public void FillShortLineCoords() { 137 NativePiscesRasterizerShim.produceFillAlphas(coords3, moveline_arr, 2, true, 138 1, 0, 0, 0, 1, 0, 139 bounds10, mask1k); 140 } 141 142 @Test(expected=java.lang.ArrayIndexOutOfBoundsException.class) 143 public void FillShortQuadCoords() { 144 NativePiscesRasterizerShim.produceFillAlphas(coords5, movequad_arr, 2, true, 145 1, 0, 0, 0, 1, 0, 146 bounds10, mask1k); 147 } 148 149 @Test(expected=java.lang.ArrayIndexOutOfBoundsException.class) 150 public void FillShortCubicCoords() { 151 NativePiscesRasterizerShim.produceFillAlphas(coords7, movecubic_arr, 2, true, 152 1, 0, 0, 0, 1, 0, 153 bounds10, mask1k); 154 } 155 156 @Test(expected=java.lang.NullPointerException.class) 157 public void StrokeNullCoords() { 158 NativePiscesRasterizerShim.produceStrokeAlphas(null, move_arr, 1, 159 10, CAP_ROUND, JOIN_ROUND, 10, null, 0, 160 1, 0, 0, 0, 1, 0, 161 bounds10, mask1k); 162 } 163 164 @Test(expected=java.lang.NullPointerException.class) 165 public void StrokeNullCommands() { 166 NativePiscesRasterizerShim.produceStrokeAlphas(coords6, null, 1, 167 10, CAP_ROUND, JOIN_ROUND, 10, null, 0, 168 1, 0, 0, 0, 1, 0, 169 bounds10, mask1k); 170 } 171 172 @Test(expected=java.lang.NullPointerException.class) 173 public void StrokeNullBounds() { 174 NativePiscesRasterizerShim.produceStrokeAlphas(coords6, move_arr, 1, 175 10, CAP_ROUND, JOIN_ROUND, 10, null, 0, 176 1, 0, 0, 0, 1, 0, 177 null, mask1k); 178 } 179 180 @Test(expected=java.lang.NullPointerException.class) 181 public void StrokeNullMask() { 182 NativePiscesRasterizerShim.produceStrokeAlphas(coords6, move_arr, 1, 183 10, CAP_ROUND, JOIN_ROUND, 10, null, 0, 184 1, 0, 0, 0, 1, 0, 185 bounds10, null); 186 } 187 188 @Test(expected=java.lang.ArrayIndexOutOfBoundsException.class) 189 public void StrokeShortBounds() { 190 NativePiscesRasterizerShim.produceStrokeAlphas(coords6, move_arr, 1, 191 10, CAP_ROUND, JOIN_ROUND, 10, null, 0, 192 1, 0, 0, 0, 1, 0, 193 new int[3], mask1k); 194 } 195 196 @Test(expected=java.lang.ArrayIndexOutOfBoundsException.class) 197 public void StrokeShortCommands() { 198 NativePiscesRasterizerShim.produceStrokeAlphas(coords6, move_arr, 2, 199 10, CAP_ROUND, JOIN_ROUND, 10, null, 0, 200 1, 0, 0, 0, 1, 0, 201 bounds10, mask1k); 202 } 203 204 @Test 205 public void StrokeBadCommands() { 206 byte badcmd_arr[] = new byte[2]; 207 badcmd_arr[0] = SEG_MOVETO; 208 for (int i = 0; i < 256; i++) { 209 switch (i) { 210 case SEG_MOVETO: 211 case SEG_LINETO: 212 case SEG_QUADTO: 213 case SEG_CUBICTO: 214 case SEG_CLOSE: 215 continue; 216 default: 217 badcmd_arr[1] = (byte) i; 218 try { 219 NativePiscesRasterizerShim.produceStrokeAlphas(coords6, badcmd_arr, 2, 220 10, CAP_ROUND, JOIN_ROUND, 10, null, 0, 221 1, 0, 0, 0, 1, 0, 222 bounds10, mask1k); 223 throw new RuntimeException("allowed bad command: "+i); 224 } catch (InternalError e) { 225 } 226 break; 227 } 228 } 229 } 230 231 @Test(expected=java.lang.ArrayIndexOutOfBoundsException.class) 232 public void StrokeShortMoveCoords() { 233 NativePiscesRasterizerShim.produceStrokeAlphas(coords1, move_arr, 1, 234 10, CAP_ROUND, JOIN_ROUND, 10, null, 0, 235 1, 0, 0, 0, 1, 0, 236 bounds10, mask1k); 237 } 238 239 @Test(expected=java.lang.ArrayIndexOutOfBoundsException.class) 240 public void StrokeShortLineCoords() { 241 NativePiscesRasterizerShim.produceStrokeAlphas(coords3, moveline_arr, 2, 242 10, CAP_ROUND, JOIN_ROUND, 10, null, 0, 243 1, 0, 0, 0, 1, 0, 244 bounds10, mask1k); 245 } 246 247 @Test(expected=java.lang.ArrayIndexOutOfBoundsException.class) 248 public void StrokeShortQuadCoords() { 249 NativePiscesRasterizerShim.produceStrokeAlphas(coords5, movequad_arr, 2, 250 10, CAP_ROUND, JOIN_ROUND, 10, null, 0, 251 1, 0, 0, 0, 1, 0, 252 bounds10, mask1k); 253 } 254 255 @Test(expected=java.lang.ArrayIndexOutOfBoundsException.class) 256 public void StrokeShortCubicCoords() { 257 NativePiscesRasterizerShim.produceStrokeAlphas(coords7, movecubic_arr, 2, 258 10, CAP_ROUND, JOIN_ROUND, 10, null, 0, 259 1, 0, 0, 0, 1, 0, 260 bounds10, mask1k); 261 } 262 }