Index: modules/awt/src/test/api/java/common/java/awt/PolygonTest.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/PolygonTest.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/PolygonTest.java (working copy) @@ -30,10 +30,13 @@ public class PolygonTest extends ShapeTestCase { + { + SERIALIZATION_TEST = true; + } + public PolygonTest(String name) { super(name); - filterImage = createFilter("^(polygon).*([.]ico)$", "(.*)((affine)|(flat)|(bounds))(.*)"); - serializePath = getSerializePath(Polygon.class); +// filterImage = createFilter("^(polygon).*([.]ico)$", "(.*)((affine)|(flat)|(bounds))(.*)"); } protected void setUp() throws Exception { @@ -304,24 +307,30 @@ return obj.getClass().getName() + "[" + data + "]"; } - public void _testSerializeRead() { - assertTrue(checkRead(new Polygon())); - assertTrue(checkRead(new Polygon(new int[]{1, 2, 3}, new int[]{4, 5, 6}, 3))); + public void testSerializeRead1() { + checkRead(new Polygon()); } - public void _testSerializeWrite() { - assertTrue(checkWrite(new Polygon())); - assertTrue(checkWrite(new Polygon(new int[]{1, 2, 3}, new int[]{4, 5, 6}, 3))); + public void testSerializeRead2() { + checkRead(new Polygon(new int[]{1, 2, 3}, new int[]{4, 5, 6}, 3)); } + + public void testSerializeWrite1() { + checkWrite(new Polygon()); + } + public void testSerializeWrite2() { + checkWrite(new Polygon(new int[]{1, 2, 3}, new int[]{4, 5, 6}, 3)); + } + public void createSerializeTemplates() { saveSerialized(new Polygon()); saveSerialized(new Polygon(new int[]{1, 2, 3}, new int[]{4, 5, 6}, 3)); } public static void main(String[] args) { -// junit.textui.TestRunner.run(PolygonTest.class); - new PolygonTest("").createSerializeTemplates(); +// new PolygonTest("").createSerializeTemplates(); + junit.textui.TestRunner.run(PolygonTest.class); } } Index: modules/awt/src/test/api/java/common/java/awt/Tools.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/Tools.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/Tools.java (working copy) @@ -14,36 +14,36 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ package java.awt; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.awt.geom.AffineTransform; import java.awt.geom.CubicCurve2D; import java.awt.geom.GeneralPath; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.awt.geom.QuadCurve2D; +import java.awt.image.BufferedImage; +import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.Reader; import java.io.StreamTokenizer; import java.io.Writer; +import java.util.Arrays; +//import javax.imageio.ImageIO; + import org.apache.harmony.awt.gl.MultiRectAreaOp; -//import com.sun.image.codec.jpeg.JPEGCodec; -//import com.sun.image.codec.jpeg.JPEGEncodeParam; -//import com.sun.image.codec.jpeg.JPEGImageDecoder; -//import com.sun.image.codec.jpeg.JPEGImageEncoder; - import junit.framework.Assert; public abstract class Tools { + static String typeName[] = {"move", "line", "quad", "cubic", "close"}; + static int findString(String buf[], String value) { for(int i = 0; i < buf.length; i++) { if (buf[i].equals(value)) { @@ -53,6 +53,12 @@ Assert.fail("Unknown value " + value); return -1; } + + public static String getClasstPath(Class clazz) { + String name = clazz.getName(); + name = name.substring(0, name.lastIndexOf('.')); + return name.replace('.', java.io.File.separator.charAt(0)) + java.io.File.separator; + } public static class Shape { @@ -69,8 +75,41 @@ static final double IMAGE_MAX_BORDER = 100.0; static final Color backColor = Color.white; - static String typeName[] = {"move", "line", "quad", "cubic", "close"}; + public static Frame show(final java.awt.Shape shape) { + Frame f = new Frame("Shape") { + + public void paint(Graphics g) { + // Background + g.setColor(Color.white); + g.fillRect(0, 0, getWidth(), getHeight()); + // Fill shape + g.setColor(Color.lightGray); + ((Graphics2D)g).fill(shape); + + // Draw shape + g.setColor(Color.black); + ((Graphics2D)g).draw(shape); + +// java.awt.image.BufferedImage img = Shape.createImage(shape, null, Color.gray, Color.lightGray); +// g.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), null); + } + + }; + + f.addWindowListener( + new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + } + ); + + f.setSize(600, 400); + f.show(); + return f; + } + public static void save(java.awt.Shape s, String fileName) { try { FileWriter f = new FileWriter(fileName); @@ -95,7 +134,6 @@ StreamTokenizer t = new StreamTokenizer(f); int count = 0; int type = 0; - Point2D lp = null; float coords[] = new float[6]; while(t.nextToken() != StreamTokenizer.TT_EOF) { switch(t.ttype) { @@ -144,10 +182,10 @@ return s; } - public static java.awt.image.BufferedImage createImage(java.awt.Shape src, AffineTransform t, Color draw, Color fill) { + public static java.awt.image.BufferedImage createImage(java.awt.Shape shape, AffineTransform t, Color draw, Color fill) { // Calculate image border - Rectangle r = src.getBounds(); + Rectangle r = shape.getBounds(); double border = r.getWidth() * IMAGE_REL_BORDER; border = Math.min(IMAGE_MAX_BORDER, border); border = Math.max(IMAGE_MIN_BORDER, border); @@ -159,7 +197,7 @@ t.setToTranslation(- r.getX() + border, - r.getY() + border); } java.awt.geom.GeneralPath dst = new java.awt.geom.GeneralPath(); - dst.append(src.getPathIterator(t), false); + dst.append(shape.getPathIterator(t), false); java.awt.image.BufferedImage img = new java.awt.image.BufferedImage( @@ -192,15 +230,15 @@ return PathIterator.equals(s1.getPathIterator(null), s2.getPathIterator(null), delta); } - public static java.awt.Shape scale(java.awt.Shape src, double k) { - java.awt.geom.PathIterator path = src.getPathIterator(AffineTransform.getScaleInstance(k, k)); + public static java.awt.Shape scale(java.awt.Shape shape, double k) { + java.awt.geom.PathIterator path = shape.getPathIterator(AffineTransform.getScaleInstance(k, k)); java.awt.geom.GeneralPath dst = new java.awt.geom.GeneralPath(path.getWindingRule()); dst.append(path, false); return dst; } - public static java.awt.Shape flip(java.awt.Shape src) { - java.awt.geom.PathIterator path = src.getPathIterator(new AffineTransform(0, 1, 1, 0, 0, 0)); + public static java.awt.Shape flip(java.awt.Shape shape) { + java.awt.geom.PathIterator path = shape.getPathIterator(new AffineTransform(0, 1, 1, 0, 0, 0)); java.awt.geom.GeneralPath dst = new java.awt.geom.GeneralPath(path.getWindingRule()); dst.append(path, false); return dst; @@ -354,33 +392,7 @@ } public static class BufferedImage { -/* - public static java.awt.image.BufferedImage load(String filename) { - java.awt.image.BufferedImage img = null; - try { - FileInputStream in = new FileInputStream(filename); - JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in); - img = decoder.decodeAsBufferedImage(); - in.close(); - } catch (Exception e) { - Assert.fail("Can't open file: " + filename); - } - return img; - } - public static void save(java.awt.image.BufferedImage img, String filename) { - try { - FileOutputStream out = new FileOutputStream(filename); - JPEGEncodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(img); - param.setQuality(1.0f, false); - JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out, param); - encoder.encode(img); - out.close(); - } catch (Exception e) { - Assert.fail("Can't save file: " + filename); - } - } -*/ public static java.awt.image.BufferedImage load(String filename) { java.awt.image.BufferedImage img = null; try { @@ -449,6 +461,8 @@ public static class PathIterator { + public static String equalsError = ""; + static boolean coordsEquals(double coords1[], double coords2[], int count, double delta) { for(int i = 0; i < count; i++) { if (Math.abs(coords1[i] - coords2[i]) > delta) { @@ -468,21 +482,27 @@ } public static boolean equals(java.awt.geom.PathIterator p1, java.awt.geom.PathIterator p2, double delta) { + equalsError = ""; if (p1.getWindingRule() != p2.getWindingRule()) { + equalsError = "WindingRule expected " + p1.getWindingRule() + " but was " + p2.getWindingRule(); return false; } + int count = 0; double coords1[] = new double[6]; double coords2[] = new double[6]; while(!p1.isDone() && !p2.isDone()) { int type1 = p1.currentSegment(coords1); int type2 = p2.currentSegment(coords2); if (type1 != type2 || !coordsEquals(coords1, coords2, Shape.pointCount[type1], delta)) { + equalsError = "Expected #" + count + " segment "+ typeName[type1] + Arrays.toString(coords1) + " but was " + typeName[type2] + Arrays.toString(coords2); return false; } p1.next(); p2.next(); + count++; } if (p1.isDone() != p2.isDone()) { + equalsError = "Expected #" + count + " isDone " + p1.isDone() + " but was " + p2.isDone(); return false; } return true; @@ -532,6 +552,7 @@ } path.next(); } + out += "done\n"; return out; } } Index: modules/awt/src/test/api/java/common/java/awt/RectangleTest.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/RectangleTest.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/RectangleTest.java (working copy) @@ -27,11 +27,14 @@ public class RectangleTest extends SerializeTestCase { + { + SERIALIZATION_TEST = true; + } + Rectangle r; public RectangleTest(String name) { super(name); - serializePath = getSerializePath(Rectangle.class); } protected void setUp() throws Exception { @@ -338,18 +341,30 @@ assertEquals(new Rectangle2D.Double(0, 0, 5, 6), r.createUnion(new Rectangle2D.Double(0, 0, 5, 6))); // Cover } - public void testSerializeRead() { - assertTrue(checkRead(new Rectangle())); - assertTrue(checkRead(new Rectangle(1, 2))); - assertTrue(checkRead(new Rectangle(1, 2, 3, 4))); + public void testSerializeRead1() { + checkRead(new Rectangle()); } - public void testSerializeWrite() { - assertTrue(checkWrite(new Rectangle())); - assertTrue(checkWrite(new Rectangle(1, 2))); - assertTrue(checkWrite(new Rectangle(1, 2, 3, 4))); + public void testSerializeRead2() { + checkRead(new Rectangle(1, 2)); } + public void testSerializeRead3() { + checkRead(new Rectangle(1, 2, 3, 4)); + } + + public void testSerializeWrite1() { + checkWrite(new Rectangle()); + } + + public void testSerializeWrite2() { + checkWrite(new Rectangle(1, 2)); + } + + public void testSerializeWrite3() { + checkWrite(new Rectangle(1, 2, 3, 4)); + } + public void createSerializeTemplates() { saveSerialized(new Rectangle()); saveSerialized(new Rectangle(1, 2)); @@ -357,8 +372,8 @@ } public static void main(String[] args) { -// junit.textui.TestRunner.run(RectangleTest.class); - new RectangleTest("").createSerializeTemplates(); +// new RectangleTest("").createSerializeTemplates(); + junit.textui.TestRunner.run(RectangleTest.class); } } Index: modules/awt/src/test/api/java/common/java/awt/SerializeTestCase.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/SerializeTestCase.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/SerializeTestCase.java (working copy) @@ -14,10 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ package java.awt; import java.io.File; @@ -26,84 +22,82 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.net.URL; import junit.framework.TestCase; - public class SerializeTestCase extends TestCase { - static final String POSTFIX = ".actual"; - static final String FOLDER = "serialization"; - + public static boolean SERIALIZATION_TEST = false; + public String serializePath = null; - + public SerializeTestCase(String name) { super(name); - } - - public static String getSerializePath(Class serializeClass) { - String path = System.getProperty("TEST_SRC_DIR"); - assertNotNull("Variable TEST_SRC_DIR not defined", path); - if (!path.endsWith(File.separator)) { - path += File.separator; + if (SERIALIZATION_TEST) { + String classPath = "serialization/" + Tools.getClasstPath(this.getClass()); + URL url = ClassLoader.getSystemClassLoader().getResource(classPath); + assertNotNull("Path not found " + classPath, url); + serializePath = url.getPath(); } - String name = serializeClass.getName(); - name = name.substring(0, name.lastIndexOf('.')); - path += name.replace('.', File.separator.charAt(0)) + File.separator + FOLDER + File.separator; - new File(path).mkdirs(); - return path; } public String objToStr(Object obj) { return obj.toString(); } - public boolean checkRead(Object obj) { - assertNotNull("Serialize path not defined"); + public void checkRead(Object obj) { + String file = serializePath + objToStr(obj) + ".ser"; + Object golden = loadSerialized(file); + assertTrue("Non equals objects " + file, objToStr(golden).equals(objToStr(obj))); + } + + public void checkWrite(Object obj) { + String name = objToStr(obj); + String expected = serializePath + name + ".ser"; + File actual = null; try { - Object template = loadSerialized(serializePath + objToStr(obj)); - return objToStr(template).equals(objToStr(obj)); + actual = File.createTempFile(name, ".actual", new File(serializePath)); + actual.deleteOnExit(); } catch (IOException e) { - } catch (ClassNotFoundException e) { + fail("Can't create temp file"); } - return false; + saveSerialized(obj, actual.getPath()); + assertTrue("Non equals files " + expected, compare(expected, actual.getPath())); } - public boolean checkWrite(Object obj) { - assertNotNull("Serialize path not defined"); - String file = serializePath + objToStr(obj); - saveSerialized(obj, file + POSTFIX); - return compare(file, file + POSTFIX); + public Object loadSerialized(String file) { + try { + //System.out.println("load " + file); + FileInputStream fs = new FileInputStream(file); + ObjectInputStream os = new ObjectInputStream(fs); + Object obj = os.readObject(); + os.close(); + fs.close(); + return obj; + } catch (Exception e) { + fail("Can''t read object from file " + file); + } + return null; } public void saveSerialized(Object obj) { - assertNotNull("Serialize path not defined"); saveSerialized(obj, serializePath + objToStr(obj)); } public void saveSerialized(Object obj, String file) { try { +// System.out.println("save " + file); FileOutputStream fs = new FileOutputStream(file); ObjectOutputStream os = new ObjectOutputStream(fs); os.writeObject(obj); os.close(); fs.close(); - System.out.println("Write " + file); } catch (Exception e) { - System.out.println("Can''t write object to file " + file); + fail("Can''t write object to file " + file); } } - public Object loadSerialized(String file) throws IOException, ClassNotFoundException { - FileInputStream fs = new FileInputStream(file); - ObjectInputStream os = new ObjectInputStream(fs); - Object obj = os.readObject(); - os.close(); - fs.close(); - System.out.println("Read " + file); - return obj; - } - boolean compare(String file1, String file2) { boolean cmp = false; try { @@ -136,7 +130,7 @@ fs1.close(); fs2.close(); } catch (Exception e) { - System.out.println("Can''t compare files " + file1 + " and " + file2); + fail("Can''t compare files " + file1 + " and " + file2); } return cmp; } Index: modules/awt/src/test/api/java/common/java/awt/DimensionTest.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/DimensionTest.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/DimensionTest.java (working copy) @@ -25,11 +25,14 @@ public class DimensionTest extends SerializeTestCase { + { + SERIALIZATION_TEST = true; + } + Dimension d; public DimensionTest(String name) { super(name); - serializePath = getSerializePath(Dimension.class); } protected void setUp() throws Exception { @@ -103,24 +106,30 @@ assertEquals(d.toString(), "java.awt.Dimension[width=2,height=3]"); } - public void testSerializeRead() { - assertTrue(checkRead(new Dimension())); - assertTrue(checkRead(new Dimension(1, 2))); + public void testSerializeRead1() { + checkRead(new Dimension()); } - public void testSerializeWrite() { - assertTrue(checkWrite(new Dimension())); - assertTrue(checkWrite(new Dimension(1, 2))); + public void testSerializeRead2() { + checkRead(new Dimension(1, 2)); } + public void testSerializeWrite1() { + checkWrite(new Dimension()); + } + + public void testSerializeWrite2() { + checkWrite(new Dimension(1, 2)); + } + public void createSerializeTemplates() { saveSerialized(new Dimension()); saveSerialized(new Dimension(1, 2)); } public static void main(String[] args) { -// junit.textui.TestRunner.run(DimensionTest.class); - new DimensionTest("").createSerializeTemplates(); +// new DimensionTest("").createSerializeTemplates(); + junit.textui.TestRunner.run(DimensionTest.class); } } Index: modules/awt/src/test/api/java/common/java/awt/PointTest.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/PointTest.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/PointTest.java (working copy) @@ -24,9 +24,12 @@ public class PointTest extends SerializeTestCase { + { + SERIALIZATION_TEST = true; + } + public PointTest(String name) { super(name); - serializePath = getSerializePath(Point.class); } protected void setUp() throws Exception { @@ -102,24 +105,30 @@ assertFalse(new Point(3, 3).equals(new Point(1, 2))); } - public void testSerializeRead() { - assertTrue(checkRead(new Point())); - assertTrue(checkRead(new Point(1, 2))); + public void testSerializeRead1() { + checkRead(new Point()); } - public void testSerializeWrite() { - assertTrue(checkWrite(new Point())); - assertTrue(checkWrite(new Point(1, 2))); + public void testSerializeRead2() { + checkRead(new Point(1, 2)); } + public void testSerializeWrite1() { + checkWrite(new Point()); + } + + public void testSerializeWrite2() { + checkWrite(new Point(1, 2)); + } + public void createSerializeTemplates() { saveSerialized(new Point()); saveSerialized(new Point(1, 2)); } public static void main(String[] args) { -// junit.textui.TestRunner.run(PointTest.class); - new PointTest("").createSerializeTemplates(); +// new PointTest("").createSerializeTemplates(); + junit.textui.TestRunner.run(PointTest.class); } } Index: modules/awt/src/test/api/java/common/java/awt/geom/RoundRectangle2DTest.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/geom/RoundRectangle2DTest.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/geom/RoundRectangle2DTest.java (working copy) @@ -14,10 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ package java.awt.geom; import java.awt.geom.ShapeTestCase; @@ -26,7 +22,7 @@ public RoundRectangle2DTest(String name) { super(name); - filterImage = createFilter("^(round).*([.]ico)$", "(.*)((affine)|(flat)|(bounds))(.*)"); +// filterImage = createFilter("^(round).*([.]ico)$", "(.*)((affine)|(flat)|(bounds))(.*)"); filterShape = createFilter("^(round).*([.]shape)$", null); } Index: modules/awt/src/test/api/java/common/java/awt/geom/Ellipse2DTest.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/geom/Ellipse2DTest.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/geom/Ellipse2DTest.java (working copy) @@ -14,17 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ package java.awt.geom; public class Ellipse2DTest extends ShapeTestCase { public Ellipse2DTest(String name) { super(name); - filterImage = createFilter("^(ellipse).*([.]ico)$", "(.*)((affine)|(flat)|(bounds))(.*)"); +// filterImage = createFilter("^(ellipse).*([.]ico)$", "(.*)((affine)|(flat)|(bounds))(.*)"); filterShape = createFilter("^(ellipse).*([.]shape)$", null); } Index: modules/awt/src/test/api/java/common/java/awt/geom/GeomTestCase.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/geom/GeomTestCase.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/geom/GeomTestCase.java (working copy) @@ -14,14 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ package java.awt.geom; import java.awt.SerializeTestCase; import java.awt.Tools; +import java.util.Arrays; public class GeomTestCase extends SerializeTestCase { @@ -142,7 +139,9 @@ fail(concat(msg, "Wrong array length " + a2.length + ", needed at least " + length)); } for(int i = 0; i < length; i++) { - assertEquals(concat(msg, "Element " + i), a1[i], a2[i], delta); + if (a1[i] != a2[i]) { + fail(msg, Arrays.toString(a1), Arrays.toString(a2)); + } } } @@ -158,7 +157,9 @@ fail(concat(msg, "Wrong array length " + a2.length + ", needed at least " + length)); } for(int i = 0; i < length; i++) { - assertEquals(concat(msg, "Element " + i), a1[i], a2[i], delta); + if (a1[i] != a2[i]) { + fail(msg, Arrays.toString(a1), Arrays.toString(a2)); + } } } @@ -174,7 +175,9 @@ fail(concat(msg, "Wrong array length " + a2.length + ", needed at least " + length)); } for(int i = 0; i < length; i++) { - assertEquals(concat(msg, "Element " + i), a1[i], a2[i]); + if (a1[i] != a2[i]) { + fail(msg, Arrays.toString(a1), Arrays.toString(a2)); + } } } Index: modules/awt/src/test/api/java/common/java/awt/geom/QuadCurve2DTest.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/geom/QuadCurve2DTest.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/geom/QuadCurve2DTest.java (working copy) @@ -14,10 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ package java.awt.geom; import java.awt.Point; @@ -68,9 +64,8 @@ QuadCurve2D q; public QuadCurve2DTest(String name) { - super(name); - filterImage = createFilter("^(quad).*([.]ico)$", "(.*)((affine)|(flat)|(bounds))(.*)"); -// filterShape = createFilter("^(quad).*([.]shape)$", null); + super(name); +// filterImage = createFilter("^(quad).*([.]ico)$", "(.*)((affine)|(flat)|(bounds))(.*)"); } protected void setUp() throws Exception { Index: modules/awt/src/test/api/java/common/java/awt/geom/Rectangle2DTest.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/geom/Rectangle2DTest.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/geom/Rectangle2DTest.java (working copy) @@ -14,10 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ package java.awt.geom; import java.awt.Point; @@ -114,8 +110,7 @@ public Rectangle2DTest(String name) { super(name); - filterImage = createFilter("^(rect).*([.]ico)$", "(.*)((affine)|(flat)|(bounds))(.*)"); -// filterShape = createFilter("^(rect).*([.]shape)$", null); +// filterImage = createFilter("^(rect).*([.]ico)$", "(.*)((affine)|(flat)|(bounds))(.*)"); } protected void setUp() throws Exception { Index: modules/awt/src/test/api/java/common/java/awt/geom/GeneralPathTest.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/geom/GeneralPathTest.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/geom/GeneralPathTest.java (working copy) @@ -24,7 +24,7 @@ import java.awt.Shape; import java.awt.Tools; -public class GeneralPathTest extends PathIteratorTestCase { +public class GeneralPathTest extends ShapeTestCase { // Test append float[][][][] shapes1 = new float[][][][] { Index: modules/awt/src/test/api/java/common/java/awt/geom/Arc2DTest.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/geom/Arc2DTest.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/geom/Arc2DTest.java (working copy) @@ -168,9 +168,8 @@ public Arc2DTest(String name) { super(name); - filterImage = createFilter("^(arc).*([.]ico)$", "(.*)((affine)|(flat)|(bounds))(.*)"); +// filterImage = createFilter("^(arc).*([.]ico)$", "(.*)((affine)|(flat)|(bounds))(.*)"); filterShape = createFilter("^(arc).*([.]shape)$", null); -// filterBounds = createFilter("^(arc).*(bounds).*([.]ico)$", null); } protected void setUp() throws Exception { Index: modules/awt/src/test/api/java/common/java/awt/geom/ShapeTestCase.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/geom/ShapeTestCase.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/geom/ShapeTestCase.java (working copy) @@ -14,10 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ package java.awt.geom; import java.io.File; @@ -25,7 +21,8 @@ import java.io.IOException; import java.io.StreamTokenizer; import java.io.StringReader; -import java.lang.reflect.Method; +import java.net.URL; +import java.util.HashMap; import java.util.Random; import java.util.regex.Pattern; import java.awt.Color; @@ -42,9 +39,8 @@ public abstract class ShapeTestCase extends PathIteratorTestCase { - final static String SHAPE_PATH = "java/awt/geom/shapes/"; - final static String OUTPUT_PATH = "java/awt/geom/shapes/output/"; - final boolean OUTPUT = System.getProperty("TEST_OUTPUT") != null; + final static boolean OUTPUT = System.getProperty("OUTPUT") != null; + final static double SHAPE_DELTA = 0.01; final static int RECT_WIDTH = 46; final static int RECT_HEIGHT = 34; @@ -65,748 +61,510 @@ final static Color errorColor = Color.red; final static Color successColor = Color.green; - String shapePath, outputPath; - String tests[]; + final static HashMap arcTypes = new HashMap(); + static { + arcTypes.put("PIE", Arc2D.PIE); + arcTypes.put("CHORD", Arc2D.CHORD); + arcTypes.put("OPEN", Arc2D.OPEN); + } + + static String shapePath = null; + static String outputPath = null; + protected FilenameFilter filterImage, filterShape; - int[] prevRect; - int[] count; - int countGoldenFiles = 0; + abstract static class Runner { - class TextTokenizer { + class TextTokenizer { - StreamTokenizer t; - String buf; + StreamTokenizer t; + String buf; - TextTokenizer(String text) { - t = new StreamTokenizer(new StringReader(text)); - buf = text; - } - - double getDouble() throws IOException { - while (t.nextToken() != StreamTokenizer.TT_EOF) { - if (t.ttype == StreamTokenizer.TT_NUMBER) { - return t.nval; - } + TextTokenizer(String text) { + t = new StreamTokenizer(new StringReader(text)); + buf = text; } - throw new IOException("Double not found"); - } - String getString() throws IOException { - while (t.nextToken() != StreamTokenizer.TT_EOF) { - if (t.ttype == StreamTokenizer.TT_WORD) { - return t.sval; + double getDouble() throws IOException { + while (t.nextToken() != StreamTokenizer.TT_EOF) { + if (t.ttype == StreamTokenizer.TT_NUMBER) { + return t.nval; + } } + throw new IOException("Double not found"); } - throw new IOException("String not found"); - } - boolean findString(String substr) { - int pos = buf.indexOf(substr); - if (pos != -1) { - t = new StreamTokenizer(new StringReader(buf.substring(pos + substr.length()))); - } - return pos != -1; - } - - } - - public ShapeTestCase(String name) { - super(name); - String basePath = System.getProperty("TEST_SRC_DIR"); - assertNotNull(basePath, "Parameter TEST_SRC_DIR not defined"); - if (!basePath.endsWith(File.separator)) { - basePath += File.separator; - } - - shapePath = basePath + SHAPE_PATH; - outputPath = basePath + OUTPUT_PATH; - - if (OUTPUT) { - new File(outputPath).mkdirs(); - } - } - - protected void setUp() throws Exception { - super.setUp(); - countGoldenFiles = 0; - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - public FilenameFilter createFilter(final String include, final String exclude) { - return new FilenameFilter() { - public boolean accept(File dir, String name) { - return - (include == null || Pattern.matches(include, name)) && - (exclude == null || !Pattern.matches(exclude, name)); - } - }; - } - - BufferedImage createImage(Shape shape, AffineTransform t) { - return Tools.Shape.createImage(shape, t, colorShape, colorInside); - } - - String [] getTestList(String path, FilenameFilter filter) { - File folder = new File(path); - String list[] = folder.list(filter); - if (list != null) { - for(int i = 0; i < list.length; i++) { - list[i] = folder.getAbsolutePath() + File.separator + list[i]; - } - } - assertTrue("Shapes weren't found in " + folder.getAbsolutePath(), list != null && list.length > 0); -// System.out.println("Found " + list.length + " shape(s) " + shapePath); - return list; - } - - double StrToDouble(String value) { - return new Double(value).doubleValue(); - } - - int StrToArcType(String value) { - if (value.equals("PIE")) { - return Arc2D.PIE; - } - if (value.equals("CHORD")) { - return Arc2D.CHORD; - } - if (value.equals("OPEN")) { - return Arc2D.OPEN; - } - fail("Unknown Arc2D type " + value); - return -1; - } - - double getFlatness(String fileName) { - try { - TextTokenizer t = new TextTokenizer(Tools.File.extractFileName(fileName)); - if (t.findString("flat(")) { - return t.getDouble(); - } - } catch(IOException e) { - fail("Cann't read flatness " + fileName); - } - return -1.0; - } -/* - Polygon makePolygon(PathIterator p) { - Polygon pg = new Polygon(); - double[] coords = new double[2]; - while(!p.isDone()) { - switch(p.currentSegment(coords)) { - case PathIterator.SEG_MOVETO: - case PathIterator.SEG_LINETO: - pg.addPoint((int)coords[0], (int)coords[1]); - break; - default: - fail("Wrong segment type"); - } - } - return pg; - } -*/ - Shape createShape(String fileName) { - Shape shape = null; - try { - String fname = Tools.File.extractFileName(fileName); - TextTokenizer t = new TextTokenizer(fname); - - int type = 0; - if (t.findString("rect(")) { - shape = new Rectangle2D.Double( - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble()); - } else - if (t.findString("ellipse(")) { - shape = new Ellipse2D.Double( - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble()); - } else - if (t.findString("round(")) { - shape = new RoundRectangle2D.Double( - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble()); - } else - if (t.findString("arc(")) { - shape = new Arc2D.Double( - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble(), - StrToArcType(t.getString())); - } else - if (t.findString("line(")) { - shape = new Line2D.Double( - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble()); - } else - if (t.findString("quad(")) { - shape = new QuadCurve2D.Double( - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble()); - } else - if (t.findString("cubic(")) { - shape = new CubicCurve2D.Double( - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble()); - } else - if (t.findString("polygon(")) { - shape = new Polygon(); - try { - while(true) { - ((Polygon)shape).addPoint((int)t.getDouble(), (int)t.getDouble()); + String getString() throws IOException { + while (t.nextToken() != StreamTokenizer.TT_EOF) { + if (t.ttype == StreamTokenizer.TT_WORD) { + return t.sval; } - } catch(IOException e) { } - } else { - // GeneralPath - shape = Tools.Shape.load(Tools.File.changeExt(fileName, ".shape")); + throw new IOException("String not found"); } - } catch (IOException e) { - fail("Cann't read shape " + fileName); - } - return shape; - } - - AffineTransform createTransform(String fileName) { - AffineTransform at = null; - try { - String fname = Tools.File.extractFileName(fileName); - TextTokenizer t = new TextTokenizer(fname); - - - if (t.findString("affine(")) { -/* - String ttype = t.getString(); - if (ttype.equals("M")) { - at.setTransform(AffineTransform.getTranslateInstance(t.getDouble(), t.getDouble())); - } else - if (ttype.equals("R")) { - at.setTransform(AffineTransform.getRotateInstance(t.getDouble())); - } else - if (ttype.equals("SC")) { - at.setTransform(AffineTransform.getScaleInstance(t.getDouble(), t.getDouble())); - } else - if (ttype.equals("SH")) { - at.setTransform(AffineTransform.getShearInstance(t.getDouble(), t.getDouble())); - } else - if (ttype.equals("F")) { - at.setTransform(AffineTransform.getShearInstance(t.getDouble(), t.getDouble())); + boolean findString(String substr) { + int pos = buf.indexOf(substr); + if (pos != -1) { + t = new StreamTokenizer(new StringReader(buf.substring(pos + substr.length()))); } -*/ - at = new AffineTransform( - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble()); + return pos != -1; } - } catch (IOException e) { - fail("Cann't read transform " + fileName); } - return at; - } - Rectangle2D createBounds2D(String fileName) { - try { - TextTokenizer t = new TextTokenizer(Tools.File.extractFileName(fileName)); - if (t.findString("bounds(")) { - return new Rectangle2D.Double( - t.getDouble(), - t.getDouble(), - t.getDouble(), - t.getDouble()); + abstract static class Rectangle extends Runner { + + static String outputPrefix = "undefined"; + + static class Contains extends Rectangle { + + static { + outputPrefix = "cr_"; + } + + static boolean[] result = new boolean[] {false, false, true, false}; + + boolean execute(Shape shape, int x, int y, int width, int height, int expected) { + return result[expected] == shape.contains(x, y, width, height); + } + } - } catch(IOException e) { - fail("Cann't read bounds " + fileName); - } - return null; - } - - int[][] createImageBuffer(BufferedImage img) { - int buf[][] = new int[img.getWidth()][img.getHeight()]; - for(int x = 0; x < img.getWidth(); x++) - for(int y = 0; y < img.getHeight(); y++) { - buf[x][y] = img.getRGB(x, y); + + static class Intersects extends Rectangle { + + static { + outputPrefix = "ir_"; + } + + static boolean[] result = new boolean[] {false, false, true, true}; + + boolean execute(Shape shape, int x, int y, int width, int height, int expected) { + return result[expected] == shape.intersects(x, y, width, height); + } + } - return buf; - } + + int[] prevRect; + int[] count; + + abstract boolean execute(Shape shape, int x, int y, int width, int height, int expected); + + public boolean run(String fileName) { + boolean error = false; + try { + Shape shape = createShape(fileName); + BufferedImage img = Tools.BufferedImage.loadIcon(fileName); + int buf[][] = createImageBuffer(img); + Graphics g = img.getGraphics(); + g.setColor(errorColor); - int getColor(int color) { - if (color == cInside || color == cOutside || color == cShape) { - return color; - } - int xored = (color ^ cGrid ^ 0xFF808080); - if (xored == cInside || xored == cOutside || xored == cShape) { - return xored; - } - return color; - } + count = new int[]{0, 0, 0}; + prevRect = null; - void countRect(int[][] buf, int[] r1, int[] r2, int[] count) { - if (r1 != null && (r1[0] > r2[2] || r1[2] < r2[0] || r1[1] > r2[3] || r1[3] < r2[1])) { - count[0] = count[1] = count[2] = 0; - countRect(buf, null, r2, count); - return; - } + for(int x = 0; x < img.getWidth() - RECT_WIDTH; x++) + for(int y = 0; y < img.getHeight() - RECT_HEIGHT; y++) { + int rectType = getRectType(null, buf, x, y, RECT_WIDTH, RECT_HEIGHT, true); + if (rectType == 0) { + // Invalid rectangle + continue; + } + if (!execute(shape, x, y, RECT_WIDTH, RECT_HEIGHT, rectType)) { + g.drawRect(x, y, RECT_WIDTH, RECT_HEIGHT); + error = true; + } + } - int x1, y1, x2, y2; - if (r1 == null) { - x1 = r2[0]; - y1 = r2[1]; - x2 = r2[2]; - y2 = r2[3]; - } else { - x1 = Math.min(r1[0], r2[0]); - y1 = Math.min(r1[1], r2[1]); - x2 = Math.max(r1[2], r2[2]); - y2 = Math.max(r1[3], r2[3]); - } - for(int x = x1; x <= x2; x++) - for(int y = y1; y <= y2; y++) { - boolean inside1 = r1 != null && r1[0] <= x && x <= r1[2] && r1[1] <= y && y <= r1[3]; - boolean inside2 = r2 != null && r2[0] <= x && x <= r2[2] && r2[1] <= y && y <= r2[3]; + int errCount = 0; + Random rnd = new Random(); + for(int i = 0; i < 1000; i ++) { + int rx = (int)(rnd.nextDouble() * (img.getWidth() - RECT_WIDTH)); + int ry = (int)(rnd.nextDouble() * (img.getHeight() - RECT_HEIGHT)); + int rw = (int)(rnd.nextDouble() * (img.getWidth() - rx - 1)) + 1; + int rh = (int)(rnd.nextDouble() * (img.getHeight() - ry - 1)) + 1; - if (inside1 ^ inside2) { - int index = 3; - int color = getColor(buf[x][y]); - if (color == colorOutside.getRGB()) { - index = 0; - } else - if (color == colorInside.getRGB()) { - index = 1; - } else - if (color == colorShape.getRGB()) { - index = 2; + int rectType = getRectType(img, buf, rx, ry, rw, rh, false); + if (rectType == 0) { + // Invalid rectangle + continue; + } + if (!execute(shape, rx, ry, rw, rh, rectType)) { + g.drawRect(rx, ry, rw, rh); + error = true; + errCount++; + } + if (errCount > ERROR_MAX_COUNT) { + break; + } } - if (inside1) { - count[index]--; - } else { - count[index]++; + + if (OUTPUT) { + Tools.BufferedImage.saveIcon(img, outputPath + outputPrefix + Tools.File.extractFileName(fileName)); } + } catch(Exception e) { + e.printStackTrace(); + fail(e.toString()); } + return !error; } - } + + int getRectType(BufferedImage img, int buf[][], int rx, int ry, int rw, int rh, boolean usePrev) { - int getRectType(BufferedImage img, int buf[][], int rx, int ry, int rw, int rh, boolean usePrev) { + if ((rx + ry) % 2 == 0) { + return 0; + } - if ((rx + ry) % 2 == 0) { - return 0; - } + if (!usePrev) { + prevRect = null; + count = new int[3]; + } - if (!usePrev) { - prevRect = null; - count = new int[3]; - } + int[] newRect = new int[]{rx, ry, rx + rw, ry + rh}; + countRect(buf, prevRect, newRect, count); + prevRect = newRect; - int[] newRect = new int[]{rx, ry, rx + rw, ry + rh}; - countRect(buf, prevRect, newRect, count); - prevRect = newRect; + if (count[0] > POINT_MIN_COUNT && count[1] == 0 && count[2] == 0) { + return 1; // Outside + } + if (count[1] > POINT_MIN_COUNT && count[0] == 0 && count[2] == 0) { + return 2; // Inside + } + if (count[0] > POINT_MIN_COUNT && count[1] > POINT_MIN_COUNT) { + return 3; // Both + } + return 0; // Invalid rectangle + } + + void countRect(int[][] buf, int[] r1, int[] r2, int[] count) { + if (r1 != null && (r1[0] > r2[2] || r1[2] < r2[0] || r1[1] > r2[3] || r1[3] < r2[1])) { + count[0] = count[1] = count[2] = 0; + countRect(buf, null, r2, count); + return; + } - if (count[0] > POINT_MIN_COUNT && count[1] == 0 && count[2] == 0) { - return 1; // Outside - } - if (count[1] > POINT_MIN_COUNT && count[0] == 0 && count[2] == 0) { - return 2; // Inside - } - if (count[0] > POINT_MIN_COUNT && count[1] > POINT_MIN_COUNT) { - return 3; // Both - } - return 0; // Invalid rectangle - } + int x1, y1, x2, y2; + if (r1 == null) { + x1 = r2[0]; + y1 = r2[1]; + x2 = r2[2]; + y2 = r2[3]; + } else { + x1 = Math.min(r1[0], r2[0]); + y1 = Math.min(r1[1], r2[1]); + x2 = Math.max(r1[2], r2[2]); + y2 = Math.max(r1[3], r2[3]); + } + for(int x = x1; x <= x2; x++) + for(int y = y1; y <= y2; y++) { + boolean inside1 = r1 != null && r1[0] <= x && x <= r1[2] && r1[1] <= y && y <= r1[3]; + boolean inside2 = r2 != null && r2[0] <= x && x <= r2[2] && r2[1] <= y && y <= r2[3]; - int getRectType_(BufferedImage img, int buf[][], int rx, int ry, int rw, int rh) { - - if ((rx + ry) % 2 == 0) { - return 0; + if (inside1 ^ inside2) { + int index = 3; + int color = getColor(buf[x][y]); + if (color == colorOutside.getRGB()) { + index = 0; + } else + if (color == colorInside.getRGB()) { + index = 1; + } else + if (color == colorShape.getRGB()) { + index = 2; + } + if (inside1) { + count[index]--; + } else { + count[index]++; + } + } + } + } + } + + static class Point extends Runner { - int countOutside = 0; - int countInside = 0; - int countShape = 0; - - for(int x = rx; x <= rx + rw; x++) { - for(int y = ry; y <= ry + rh; y++) { - if (x == rx || x == rx + rw || - y == ry || y == ry + rh || - (x + y) % CHECK_STEP == 0 || (x - y) % CHECK_STEP == 0) - { - if (img != null) { -// img.setRGB(x, y, Color.blue.getRGB()); + public boolean run(String fileName) { + boolean error = false; + Shape shape = createShape(fileName); + BufferedImage img = Tools.BufferedImage.loadIcon(fileName); + for(int x = 0; x < img.getWidth(); x++) + for(int y = 0; y < img.getHeight(); y++) { + int color = getColor(img.getRGB(x, y)); + boolean res = shape.contains(x, y); + if ((color == colorInside.getRGB() && !res) || + (color == colorOutside.getRGB() && res)) + { + img.setRGB(x, y, errorColor.getRGB()); + error = true; + } } - int color = getColor(buf[x][y]); - if (color == colorOutside.getRGB()) { - countOutside++; - } else - if (color == colorInside.getRGB()) { - countInside++; - } else - if (color == colorShape.getRGB()) { - countShape++; - } + if (OUTPUT) { + Tools.BufferedImage.saveIcon(img, outputPath + "cp_" + Tools.File.extractFileName(fileName)); } + return !error; } + } + + static class PathIterator extends Runner { - if (countInside == 0 && countOutside > POINT_MIN_COUNT && countShape == 0) { - return 1; // Outside - } - if (countOutside == 0 && countInside > POINT_MIN_COUNT && countShape == 0) { - return 2; // Inside - } - if (countInside > POINT_MIN_COUNT && countOutside > POINT_MIN_COUNT) { - return 3; // Both - } - return 0; // Invalid rectangle - } - - void checkRunner(String name, FilenameFilter filter, String methodName, Object[] params) { - if (filter == null) { - return; // skip test - } - tests = getTestList(shapePath, filter); - int countErr = 0; - try { - Method method = this.getClass().getMethod(methodName, new Class[] {String.class, Object[].class}); - for(int i = 0; i < tests.length; i++) { - Object res = method.invoke(this, new Object[] {tests[i], params}); - if (!((Boolean)res).booleanValue()) { - if (countErr == 0) { - System.out.println(name); + public boolean run(String fileName) { + double flatness = getFlatness(fileName); + AffineTransform at = createTransform(fileName); + Shape shape1 = createShape(fileName); + Shape shape2 = Tools.Shape.load(fileName); + GeneralPath path = new GeneralPath(); + path.append(flatness < 0.0 ? shape1.getPathIterator(at) : shape1.getPathIterator(at, flatness), false); + if (OUTPUT) { + Tools.Shape.save(path, outputPath + (at == null ? "pi_" : "pia_") + Tools.File.extractFileName(fileName)); + } + return Tools.PathIterator.equals( + path.getPathIterator(null), + shape2.getPathIterator(null), + SHAPE_DELTA); + } + + double getFlatness(String fileName) { + try { + TextTokenizer t = new TextTokenizer(Tools.File.extractFileName(fileName)); + if (t.findString("flat(")) { + return t.getDouble(); } - countErr++; - System.out.println("Failed " + tests[i]); - } else { - System.out.println(" " + tests[i]); + } catch(IOException e) { + fail("Can't read flatness " + fileName); } + return -1.0; } - } catch(Exception e) { - e.printStackTrace(); - fail(e.toString()); - } - if (countErr == 0 && countGoldenFiles != 0) { - System.out.println("Checked " + countGoldenFiles + " golden file(s) " + name); - } - assertTrue("Failed " + countErr + "/" + tests.length + " test(s)", countErr == 0); - } + + AffineTransform createTransform(String fileName) { + AffineTransform at = null; + try { + String fname = Tools.File.extractFileName(fileName); + TextTokenizer t = new TextTokenizer(fname); - public boolean checkRect1(String fileName, Object[] params) { - countGoldenFiles++; - boolean error = false; - try { - String methodName = (String)params[0]; - String prefix = (String)params[1]; - boolean[] expected = (boolean[])params[2]; - Method method = Shape.class.getMethod(methodName, new Class[]{double.class, double.class, double.class, double.class}); - Shape shape = createShape(fileName); - BufferedImage img = Tools.BufferedImage.loadIcon(fileName); - int buf[][] = createImageBuffer(img); - Graphics g = img.getGraphics(); - g.setColor(errorColor); - - count = new int[]{0, 0, 0}; - prevRect = null; - - for(int x = 0; x < img.getWidth() - RECT_WIDTH; x++) - for(int y = 0; y < img.getHeight() - RECT_HEIGHT; y++) { - int rectType = getRectType(null, buf, x, y, RECT_WIDTH, RECT_HEIGHT, true); - if (rectType == 0) { - // Invalid rectangle - continue; + if (t.findString("affine(")) { + /* + String ttype = t.getString(); + if (ttype.equals("M")) { + at.setTransform(AffineTransform.getTranslateInstance(t.getDouble(), t.getDouble())); + } else + if (ttype.equals("R")) { + at.setTransform(AffineTransform.getRotateInstance(t.getDouble())); + } else + if (ttype.equals("SC")) { + at.setTransform(AffineTransform.getScaleInstance(t.getDouble(), t.getDouble())); + } else + if (ttype.equals("SH")) { + at.setTransform(AffineTransform.getShearInstance(t.getDouble(), t.getDouble())); + } else + if (ttype.equals("F")) { + at.setTransform(AffineTransform.getShearInstance(t.getDouble(), t.getDouble())); + } + */ + at = new AffineTransform( + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble()); } - Object res = method.invoke(shape, new Object[]{ - new Double(x), - new Double(y), - new Double(RECT_WIDTH), - new Double(RECT_HEIGHT)}); - if (expected[rectType] != ((Boolean)res).booleanValue()) { - g.drawRect(x, y, RECT_WIDTH, RECT_HEIGHT); - error = true; - } - } - int errCount = 0; - Random rnd = new Random(); - for(int i = 0; i < 1000; i ++) { - int rx = (int)(rnd.nextDouble() * (img.getWidth() - RECT_WIDTH)); - int ry = (int)(rnd.nextDouble() * (img.getHeight() - RECT_HEIGHT)); - int rw = (int)(rnd.nextDouble() * (img.getWidth() - rx - 1)) + 1; - int rh = (int)(rnd.nextDouble() * (img.getHeight() - ry - 1)) + 1; - - int rectType = getRectType(img, buf, rx, ry, rw, rh, false); - if (rectType == 0) { - // Invalid rectangle - continue; + } catch (IOException e) { + fail("Can't read transform " + fileName); } + return at; + } - Object res = method.invoke(shape, new Object[]{ - new Double(rx), - new Double(ry), - new Double(rw), - new Double(rh)}); - - if (expected[rectType] != ((Boolean)res).booleanValue()) { - g.drawRect(rx, ry, rw, rh); - error = true; - errCount++; + } + + abstract boolean run(String fileName); + + Shape createShape(String fileName) { + Shape shape = null; + try { + String fname = Tools.File.extractFileName(fileName); + TextTokenizer t = new TextTokenizer(fname); + if (t.findString("rect(")) { + shape = new Rectangle2D.Double( + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble()); + } else + if (t.findString("ellipse(")) { + shape = new Ellipse2D.Double( + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble()); + } else + if (t.findString("round(")) { + shape = new RoundRectangle2D.Double( + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble()); + } else + if (t.findString("arc(")) { + shape = new Arc2D.Double( + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble(), + arcTypes.get(t.getString())); + } else + if (t.findString("line(")) { + shape = new Line2D.Double( + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble()); + } else + if (t.findString("quad(")) { + shape = new QuadCurve2D.Double( + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble()); + } else + if (t.findString("cubic(")) { + shape = new CubicCurve2D.Double( + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble(), + t.getDouble()); + } else + if (t.findString("polygon(")) { + shape = new Polygon(); + try { + while(true) { + ((Polygon)shape).addPoint((int)t.getDouble(), (int)t.getDouble()); + } + } catch(IOException e) { + } + } else { + // GeneralPath + shape = Tools.Shape.load(Tools.File.changeExt(fileName, ".shape")); } - if (errCount > ERROR_MAX_COUNT) { - break; - } - } - if (OUTPUT) { - Tools.BufferedImage.saveIcon(img, outputPath + prefix + Tools.File.extractFileName(fileName)); + } catch (IOException e) { + fail("Can't read shape " + fileName); } - } catch(Exception e) { - e.printStackTrace(); - fail(e.toString()); + return shape; } - return !error; - } - public boolean checkRect2(String fileName, Object[] params) { - boolean error = false; - try { - String methodName = (String)params[0]; - String prefix = (String)params[1]; - - Method method1 = Shape.class.getMethod(methodName, new Class[]{double.class, double.class, double.class, double.class}); - Method method2 = Shape.class.getMethod(methodName, new Class[]{Rectangle2D.class}); - Shape shape = createShape(fileName); - BufferedImage img = Tools.BufferedImage.loadIcon(fileName); - int buf[][] = createImageBuffer(img); - Graphics g = img.getGraphics(); - g.setColor(errorColor); - - Random rnd = new Random(); - for(int i = 0; i < 100; i ++) { - int rx = (int)(rnd.nextDouble() * (img.getWidth() - RECT_WIDTH)); - int ry = (int)(rnd.nextDouble() * (img.getHeight() - RECT_HEIGHT)); - int rw = (int)(rnd.nextDouble() * (img.getWidth() - rx - 1)) + 1; - int rh = (int)(rnd.nextDouble() * (img.getHeight() - ry - 1)) + 1; - - Object res1 = method1.invoke(shape, new Object[]{ - new Double(rx), - new Double(ry), - new Double(rw), - new Double(rh)}); - - Object res2 = method2.invoke(shape, new Object[]{new Rectangle2D.Double(rx, ry, rw, rh)}); - - if (!res1.equals(res2)) { - g.drawRect(rx, ry, rw, rh); - error = true; + int[][] createImageBuffer(BufferedImage img) { + int buf[][] = new int[img.getWidth()][img.getHeight()]; + for(int x = 0; x < img.getWidth(); x++) + for(int y = 0; y < img.getHeight(); y++) { + buf[x][y] = img.getRGB(x, y); } - } + return buf; + } - if (OUTPUT) { - Tools.BufferedImage.saveIcon(img, outputPath + prefix + Tools.File.extractFileName(fileName)); + static int getColor(int color) { + if (color == cInside || color == cOutside || color == cShape) { + return color; } - } catch(Exception e) { - e.printStackTrace(); - fail(e.toString()); + int xored = (color ^ cGrid ^ 0xFF808080); + if (xored == cInside || xored == cOutside || xored == cShape) { + return xored; + } + return color; } - return !error; + } + + public ShapeTestCase(String name) { + super(name); + String classPath = "shapes/" + Tools.getClasstPath(this.getClass()); + URL url = ClassLoader.getSystemClassLoader().getResource(classPath); + assertNotNull("Path not found " + classPath, url); + shapePath = url.getPath(); + outputPath = shapePath + "output/"; + } - public boolean checkContainsPoint1(String fileName, Object[] params) { - countGoldenFiles++; - boolean error = false; - Shape shape = createShape(fileName); - BufferedImage img = Tools.BufferedImage.loadIcon(fileName); - for(int x = 0; x < img.getWidth(); x++) - for(int y = 0; y < img.getHeight(); y++) { - int color = getColor(img.getRGB(x, y)); - boolean res = shape.contains(x, y); - if ((color == colorInside.getRGB() && !res) || - (color == colorOutside.getRGB() && res)) - { - img.setRGB(x, y, errorColor.getRGB()); - error = true; - } - } + void print(String text) { if (OUTPUT) { - Tools.BufferedImage.saveIcon(img, outputPath + "cp_" + Tools.File.extractFileName(fileName)); + System.out.println(text); } - return !error; } + + public FilenameFilter createFilter(final String include, final String exclude) { + return new FilenameFilter() { + public boolean accept(File dir, String name) { + return + (include == null || Pattern.matches(include, name)) && + (exclude == null || !Pattern.matches(exclude, name)); + } + }; + } - public boolean checkContainsPoint2(String fileName, Object[] params) { - boolean error = false; - Shape shape = createShape(fileName); - BufferedImage img = Tools.BufferedImage.loadIcon(fileName); - Random rnd = new Random(); - for(int i = 0; i < 100; i++) { - int x = (int)(rnd.nextDouble() * img.getWidth()); - int y = (int)(rnd.nextDouble() * img.getHeight()); - if (shape.contains(x, y) != shape.contains(new Point2D.Double(x, y))) { - img.setRGB(x, y, errorColor.getRGB()); - error = true; - } + String [] getTestList(String path, FilenameFilter filter) { + File folder = new File(path); + String list[] = folder.list(filter); + if (list != null) { + for(int i = 0; i < list.length; i++) { + list[i] = folder.getAbsolutePath() + File.separator + list[i]; + } + } + return list; + } + + void interator(String name, FilenameFilter filter, Runner runner) { + if (filter == null) { + return; // skip test } if (OUTPUT) { - Tools.BufferedImage.saveIcon(img, outputPath + "cp2_" + Tools.File.extractFileName(fileName)); + new File(outputPath).mkdirs(); } - return !error; + String tests[] = getTestList(shapePath, filter); + assertTrue("Shapes not found " + shapePath, tests != null && tests.length > 0); + for(int i = 0; i < tests.length; i++) { + boolean result = runner.run(tests[i]); + assertTrue(tests[i] + " " + Tools.PathIterator.equalsError, result); + } } - public boolean checkPathIterator(String fileName, Object[] params) { - countGoldenFiles++; - boolean error = false; - double flatness = getFlatness(fileName); - AffineTransform at = createTransform(fileName); - Shape shape1 = createShape(fileName); - Shape shape2 = Tools.Shape.load(fileName); - String name = at == null ? "pi_" : "pia_"; - GeneralPath path = new GeneralPath(); - path.append(flatness < 0.0 ? shape1.getPathIterator(at) : shape1.getPathIterator(at, flatness), false); - if (OUTPUT) { - Tools.Shape.save(path, outputPath + name + Tools.File.extractFileName(fileName)); - } - return Tools.PathIterator.equals( - path.getPathIterator(null), - shape2.getPathIterator(null), - SHAPE_DELTA); + public void testGetPathIterator() { + interator( + "getPathIterator()", + filterShape, + new Runner.PathIterator()); } - public void _testContainsPoint1() { - checkRunner( + public void testContainsPoint() { + interator( "contains(double,double)", filterImage, - "checkContainsPoint1", - null); + new Runner.Point()); } - public void _testContainsPoint2() { - checkRunner( - "contains(Point2D)", - filterImage, - "checkContainsPoint2", - null); - } - - public void _testContainsRect1() { - checkRunner( + public void testContainsRect() { + interator( "contains(double,double,double,double)", filterImage, - "checkRect1", - new Object[]{"contains", "cr_", new boolean[] {false, false, true, false}}); + new Runner.Rectangle.Contains()); } - public void _testContainsRect2() { - checkRunner( - "contains(Rectangle2D)", - filterImage, - "checkRect2", - new Object[]{"contains", "cr2_"}); - } - - public void _testIntersectsRect1() { - checkRunner( + public void testIntersectsRect() { + interator( "intersects(double,double,double,double)", filterImage, - "checkRect1", - new Object[]{"intersects", "ir_", new boolean[] {false, false, true, true}}); + new Runner.Rectangle.Intersects()); } - public void _testIntersectsRect2() { - checkRunner( - "contains(Rectangle2D)", - filterImage, - "checkRect2", - new Object[]{"intersects", "ir2_"}); - } - - public void testGetPathIterator() { - checkRunner( - "getPathIterator()", - filterShape, - "checkPathIterator", - null); - } - - - /* - public boolean checkBounds(String fileName) { - boolean error = false; - Shape shape = createShape(fileName); - Rectangle2D expectBounds = createBounds2D(fileName); - Rectangle2D actualBounds = bounds2D ? shape.getBounds2D() : shape.getBounds(); - BufferedImage img = Tools.BufferedImage.loadIcon(fileName); - Graphics g = img.getGraphics(); - g.setColor(Color.red); - ((Graphics2D)g).draw(actualBounds); - String name = bounds2D ? "bounds2D_" : "bounds_"; - if (OUTPUT) { - Tools.BufferedImage.saveIcon(img, outputPath + name + Tools.File.extractFileName(fileName)); - } - return !equalRects(expectBounds, actualBounds, SHAPE_DELTA); - } - - - public void testGetBounds2D() { - System.out.println("testdsfsd"); - if (filterBounds == null) { - return; // skip test - } - tests = getTestList(shapePath, filterBounds); - System.out.println("test"); - int countErr = 0; - for(int i = 0; i < tests.length; i++) { - if (checkBounds(tests[i], true)) { - countErr++; - System.out.println("Failed " + tests[i]); - } - } - assertTrue("Failed " + countErr + " test(s)", countErr == 0); - } -*/ -/* - public void testGetBounds() { - if (filterBounds == null) { - return; // skip test - } - tests = getTestList(shapePath, filterBounds); - int countErr = 0; - for(int i = 0; i < tests.length; i++) { - if (checkBounds(tests[i], false)) { - countErr++; - System.out.println("Failed " + tests[i]); - } - } - assertTrue("Failed " + countErr + " test(s)", countErr == 0); - } -*/ -} - +} \ No newline at end of file Index: modules/awt/src/test/api/java/common/java/awt/geom/CubicCurve2DTest.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/geom/CubicCurve2DTest.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/geom/CubicCurve2DTest.java (working copy) @@ -14,10 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ package java.awt.geom; import java.awt.Point; @@ -68,8 +64,7 @@ public CubicCurve2DTest(String name) { super(name); - filterImage = createFilter("^(cubic).*([.]ico)$", "(.*)((affine)|(flat)|(bounds))(.*)"); -// filterShape = createFilter("^(quad).*([.]shape)$", null); +// filterImage = createFilter("^(cubic).*([.]ico)$", "(.*)((affine)|(flat)|(bounds))(.*)"); } protected void setUp() throws Exception { Index: modules/awt/src/test/api/java/common/java/awt/geom/AffineTransformTest.java =================================================================== --- modules/awt/src/test/api/java/common/java/awt/geom/AffineTransformTest.java (revision 454346) +++ modules/awt/src/test/api/java/common/java/awt/geom/AffineTransformTest.java (working copy) @@ -14,10 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Denis M. Kishenko - * @version $Revision$ - */ package java.awt.geom; import java.awt.Shape; @@ -27,6 +23,10 @@ public class AffineTransformTest extends GeomTestCase { + { + SERIALIZATION_TEST = true; + } + final static double ROTATION_DELTA = 1E-5; double[][] type = new double[][]{ @@ -102,7 +102,6 @@ public AffineTransformTest(String name) { super(name); - serializePath = getSerializePath(AffineTransform.class); } protected void setUp() throws Exception { @@ -223,8 +222,6 @@ s += Integer.toString(type & ~all) + ","; } } -// System.out.println(s); -// return s; return Integer.toString(type); } @@ -491,7 +488,6 @@ t.translate(8, 9); assertEquals( AffineTransform.TYPE_GENERAL_TRANSFORM, -// new double[]{2, 3, 4, 5, 14, 16}, new double[]{2, 3, 4, 5, 58, 76}, 0.0, t); @@ -507,7 +503,6 @@ t.scale(2, 3); assertEquals( AffineTransform.TYPE_GENERAL_TRANSFORM, -// new double[]{4, 9, 8, 15, 12, 21}, new double[]{4, 6, 12, 15, 6, 7}, 0.0, t); @@ -524,7 +519,6 @@ assertEquals( AffineTransform.TYPE_GENERAL_TRANSFORM, new double[]{10, 13, 10, 14, 6, 7}, -// new double[]{11, 7, 19, 13, 27, 19}, 0.0, t); } @@ -546,7 +540,6 @@ assertEquals( AffineTransform.TYPE_GENERAL_TRANSFORM, new double[]{4, 5, -2, -3, 6, 7}, -// new double[]{-3, 2, -5, 4, -7, 6}, 0.0, t); } @@ -613,7 +606,7 @@ } } - public void testTransform1() { + public void testTransformPoint() { for(int i = 0; i < points.length; i++) { AffineTransform at = new AffineTransform(points[i][0]); for(int j = 1; j < points[i].length; j++) { @@ -640,7 +633,7 @@ } } - public void testTransform2() { + public void testTransformArray1() { AffineTransform at = new AffineTransform(0, 1, -2, 0, 3, 4); Point2D[] src = new Point2D[]{ null, @@ -653,7 +646,7 @@ assertEquals(new Point2D.Float(1, 5), dst[3]); } - public void testTransform3() { + public void testTransformArray2() { AffineTransform at = new AffineTransform(0, 1, -2, 0, 3, 4); double[] src = new double[]{0, 0, 0, 0, 0, 0, 1, 1, 0, 0}; double[] dst = new double[6]; @@ -661,8 +654,8 @@ at.transform(src, 4, dst, 2, 2); assertEquals(expected, dst, 6, 0.0); } - - public void testTransform4() { + + public void testTransformArray3() { AffineTransform at = new AffineTransform(0, 1, -2, 0, 3, 4); float[] src = new float[]{0, 0, 0, 0, 0, 0, 1, 1, 0, 0}; float[] dst = new float[6]; @@ -671,7 +664,7 @@ assertEquals(expected, dst, 6, 0.0f); } - public void testTransform5() { + public void testTransformArray4() { AffineTransform at = new AffineTransform(0, 1, -2, 0, 3, 4); float[] src = new float[]{0, 0, 0, 0, 0, 0, 1, 1, 0, 0}; double[] dst = new double[6]; @@ -680,7 +673,7 @@ assertEquals(expected, dst, 6, 0.0); } - public void testTransform6() { + public void testTransformArray5() { AffineTransform at = new AffineTransform(0, 1, -2, 0, 3, 4); double[] src = new double[]{0, 0, 0, 0, 0, 0, 1, 1, 0, 0}; float[] dst = new float[6]; @@ -688,7 +681,7 @@ at.transform(src, 4, dst, 2, 2); assertEquals(expected, dst, 6, 0.0f); } - + public void testDeltaTransform1() { for(int i = 0; i < points.length; i++) { AffineTransform at = new AffineTransform(points[i][0]); @@ -822,33 +815,30 @@ t.toString()); } - public String objToStr(Object obj) { - double[] m = new double[6]; - ((AffineTransform)obj).getMatrix(m); - return - obj.getClass().getName() + "[[" + - m[0] + ", " + m[2] + ", " + m[4] + "], [" + - m[1] + ", " + m[3] + ", " + m[5] + "]]"; + public void testSerializeRead1() { + checkRead(new AffineTransform()); } - public void testSerializeRead() { - assertTrue(checkRead(new AffineTransform())); - assertTrue(checkRead(new AffineTransform(1, 2, 3, 4, 5, 6))); + public void testSerializeRead2() { + checkRead(new AffineTransform(1, 2, 3, 4, 5, 6)); } - public void testSerializeWrite() { - assertTrue(checkWrite(new AffineTransform())); - assertTrue(checkWrite(new AffineTransform(1, 2, 3, 4, 5, 6))); + public void testSerializeWrite1() { + checkWrite(new AffineTransform()); } + public void testSerializeWrite2() { + checkWrite(new AffineTransform(1, 2, 3, 4, 5, 6)); + } + public void createSerializeTemplates() { saveSerialized(new AffineTransform()); saveSerialized(new AffineTransform(1, 2, 3, 4, 5, 6)); } public static void main(String[] args) { -// junit.textui.TestRunner.run(AffineTransformTest.class); - new AffineTransformTest("").createSerializeTemplates(); +// new AffineTransformTest("").createSerializeTemplates(); + junit.textui.TestRunner.run(AffineTransformTest.class); } } Index: modules/awt/build.xml =================================================================== --- modules/awt/build.xml (revision 454346) +++ modules/awt/build.xml (working copy) @@ -52,7 +52,7 @@ - + @@ -220,29 +220,9 @@ - - - - - - - - - - - - - - - - - - - - - + @@ -272,11 +252,6 @@ - - - - - @@ -327,6 +302,12 @@ + + + + + + @@ -350,4 +331,13 @@ append="true">awt${line.separator} + + + + + + + + +