1 /* 2 * Copyright (c) 2015, 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 package java.awt.geom; 26 27 /** 28 * Using the java.awt.geom package is not allowed by jtreg but there is no 29 * practical mean to access Path2D fields (arrays) to check them. 30 * Run this test manually 31 * 32 * @summary Check Path2D copy constructor modified to trim arrays 33 * @run main Path2DTrimCopy 34 */ 35 public class Path2DTrimCopy { 36 37 private static final int LEN = 87; 38 39 private static final int GROWTH_LEN = 128; 40 41 public static void main(String[] args) { 42 testPath2D_Float(); 43 testPath2D_Float_empty(); 44 45 testPath2D_Double(); 46 testPath2D_Double_empty(); 47 } 48 49 public static void testPath2D_Float() { 50 System.out.println("testPath2D_Float()"); 51 Path2D.Float cf; 52 53 // Fill new path: 54 final Path2D.Float pf = new Path2D.Float(); 55 fillPath(pf, LEN); 56 57 System.out.println("numTypes: " + pf.numTypes); 58 System.out.println("pointTypes.length: " + pf.pointTypes.length); 59 System.out.println("numCoords: " + pf.numCoords); 60 System.out.println("floatCoords.length: " + pf.floatCoords.length); 61 62 // Test cloned path: 63 cf = new Path2D.Float(pf); 64 System.out.println("cloned pointTypes.length: " 65 + cf.pointTypes.length); 66 System.out.println("cloned floatCoords.length: " 67 + cf.floatCoords.length); 68 69 if (cf.numTypes != pf.numTypes) { 70 fail("Invalid cloned numTypes: " 71 + cf.numTypes + " != " + pf.numTypes); 72 } 73 if (cf.pointTypes.length != cf.numTypes) { 74 fail("Invalid cloned pointTypes: " 75 + cf.pointTypes.length + " != " + cf.numTypes); 76 } 77 if (cf.numCoords != pf.numCoords) { 78 fail("Invalid cloned numCoords: " 79 + cf.numCoords + " != " + pf.numCoords); 80 } 81 if (cf.floatCoords.length != cf.numCoords) { 82 fail("Invalid cloned floatCoords: " 83 + cf.floatCoords.length + " != " + cf.numCoords); 84 } 85 } 86 87 public static void testPath2D_Float_empty() { 88 System.out.println("testPath2D_Float_empty()"); 89 Path2D.Float cf; 90 91 { 92 // Create empty path: 93 Path2D.Float pf = new Path2D.Float(); 94 95 System.out.println("numTypes: " + pf.numTypes); 96 System.out.println("pointTypes.length: " + pf.pointTypes.length); 97 System.out.println("numCoords: " + pf.numCoords); 98 System.out.println("floatCoords.length: " + pf.floatCoords.length); 99 100 // Test cloned path: 101 cf = new Path2D.Float(pf); 102 System.out.println("cloned pointTypes.length: " 103 + cf.pointTypes.length); 104 System.out.println("cloned floatCoords.length: " 105 + cf.floatCoords.length); 106 107 if (cf.numTypes != pf.numTypes) { 108 fail("Invalid cloned numTypes: " 109 + cf.numTypes + " != " + pf.numTypes); 110 } 111 if (cf.pointTypes.length != cf.numTypes) { 112 fail("Invalid cloned pointTypes: " 113 + cf.pointTypes.length + " != " + cf.numTypes); 114 } 115 if (cf.numCoords != pf.numCoords) { 116 fail("Invalid cloned numCoords: " 117 + cf.numCoords + " != " + pf.numCoords); 118 } 119 if (cf.floatCoords.length != cf.numCoords) { 120 fail("Invalid cloned floatCoords: " 121 + cf.floatCoords.length + " != " + cf.numCoords); 122 } 123 } 124 125 // Fill path: 126 fillPath(cf, LEN); 127 128 System.out.println("numTypes: " + cf.numTypes); 129 System.out.println("pointTypes.length: " + cf.pointTypes.length); 130 System.out.println("numCoords: " + cf.numCoords); 131 System.out.println("floatCoords.length: " + cf.floatCoords.length); 132 133 final int n = LEN + 1; 134 135 if (cf.numTypes != n) { 136 fail("Invalid cloned numTypes: " 137 + cf.numTypes + " != " + n); 138 } 139 if (cf.pointTypes.length != GROWTH_LEN) { 140 fail("Invalid cloned pointTypes: " 141 + cf.pointTypes.length + " != " + GROWTH_LEN); 142 } 143 if (cf.numCoords != n * 2) { 144 fail("Invalid cloned numCoords: " 145 + cf.numCoords + " != " + (n * 2)); 146 } 147 if (cf.floatCoords.length != 2 * GROWTH_LEN) { 148 fail("Invalid cloned floatCoords: " 149 + cf.floatCoords.length + " != " + (2 * GROWTH_LEN)); 150 } 151 } 152 153 public static void testPath2D_Double() { 154 System.out.println("testPath2D_Double()"); 155 Path2D.Double cd; 156 157 // Fill new path: 158 final Path2D.Double pd = new Path2D.Double(); 159 fillPath(pd, LEN); 160 161 System.out.println("numTypes: " + pd.numTypes); 162 System.out.println("pointTypes.length: " + pd.pointTypes.length); 163 System.out.println("numCoords: " + pd.numCoords); 164 System.out.println("doubleCoords.length: " + pd.doubleCoords.length); 165 166 // Test cloned path: 167 cd = new Path2D.Double(pd); 168 System.out.println("cloned pointTypes.length: " 169 + cd.pointTypes.length); 170 System.out.println("cloned doubleCoords.length: " 171 + cd.doubleCoords.length); 172 173 if (cd.numTypes != pd.numTypes) { 174 fail("Invalid cloned numTypes: " 175 + cd.numTypes + " != " + pd.numTypes); 176 } 177 if (cd.pointTypes.length != cd.numTypes) { 178 fail("Invalid cloned pointTypes: " 179 + cd.pointTypes.length + " != " + cd.numTypes); 180 } 181 if (cd.numCoords != pd.numCoords) { 182 fail("Invalid cloned numCoords: " 183 + cd.numCoords + " != " + pd.numCoords); 184 } 185 if (cd.doubleCoords.length != cd.numCoords) { 186 fail("Invalid cloned doubleCoords: " 187 + cd.doubleCoords.length + " != " + cd.numCoords); 188 } 189 } 190 191 public static void testPath2D_Double_empty() { 192 System.out.println("testPath2D_Double_empty()"); 193 194 Path2D.Double cf; 195 196 { 197 // Create empty path: 198 Path2D.Double pf = new Path2D.Double(); 199 200 System.out.println("numTypes: " + pf.numTypes); 201 System.out.println("pointTypes.length: " + pf.pointTypes.length); 202 System.out.println("numCoords: " + pf.numCoords); 203 System.out.println("floatCoords.length: " + pf.doubleCoords.length); 204 205 // Test cloned path: 206 cf = new Path2D.Double(pf); 207 System.out.println("cloned pointTypes.length: " 208 + cf.pointTypes.length); 209 System.out.println("cloned doubleCoords.length: " 210 + cf.doubleCoords.length); 211 212 if (cf.numTypes != pf.numTypes) { 213 fail("Invalid cloned numTypes: " 214 + cf.numTypes + " != " + pf.numTypes); 215 } 216 if (cf.pointTypes.length != cf.numTypes) { 217 fail("Invalid cloned pointTypes: " 218 + cf.pointTypes.length + " != " + cf.numTypes); 219 } 220 if (cf.numCoords != pf.numCoords) { 221 fail("Invalid cloned numCoords: " 222 + cf.numCoords + " != " + pf.numCoords); 223 } 224 if (cf.doubleCoords.length != cf.numCoords) { 225 fail("Invalid cloned doubleCoords: " 226 + cf.doubleCoords.length + " != " + cf.numCoords); 227 } 228 } 229 230 // Fill path: 231 fillPath(cf, LEN); 232 233 System.out.println("numTypes: " + cf.numTypes); 234 System.out.println("pointTypes.length: " + cf.pointTypes.length); 235 System.out.println("numCoords: " + cf.numCoords); 236 System.out.println("doubleCoords.length: " + cf.doubleCoords.length); 237 238 final int n = LEN + 1; 239 240 if (cf.numTypes != n) { 241 fail("Invalid cloned numTypes: " 242 + cf.numTypes + " != " + n); 243 } 244 if (cf.pointTypes.length != GROWTH_LEN) { 245 fail("Invalid cloned pointTypes: " 246 + cf.pointTypes.length + " != " + GROWTH_LEN); 247 } 248 if (cf.numCoords != n * 2) { 249 fail("Invalid cloned numCoords: " 250 + cf.numCoords + " != " + (n * 2)); 251 } 252 if (cf.doubleCoords.length != 2 * GROWTH_LEN) { 253 fail("Invalid cloned doubleCoords: " 254 + cf.doubleCoords.length + " != " + (2 * GROWTH_LEN)); 255 } 256 } 257 258 private static void fillPath(Path2D p, int len) { 259 p.moveTo(0, 0); 260 for (int i = 0; i < len; i++) { 261 p.lineTo(i, i); 262 } 263 } 264 265 private static void fail(String msg) { 266 System.out.println("Test Failed"); 267 throw new RuntimeException(msg); 268 } 269 }