1 18 package org.apache.batik.svggen; 19 20 import java.awt.Graphics2D ; 21 import java.awt.Color ; 22 23 import java.net.URL ; 24 import java.io.File ; 25 26 import org.apache.batik.test.DefaultTestSuite; 27 import org.apache.batik.test.Test; 28 import org.apache.batik.test.TestReportValidator; 29 import org.apache.batik.test.TestReport; 30 31 37 public class SVGAccuracyTestValidator extends DefaultTestSuite { 38 46 public SVGAccuracyTestValidator(){ 47 addTest(new NullPainter()); 48 addTest(new PainterWithException()); 49 addTest(new NullReferenceURL()); 50 addTest(new InexistantReferenceURL()); 51 addTest(new DiffWithReferenceImage()); 52 addTest(new SameAsReferenceImage()); 53 } 54 55 static class NullPainter extends TestReportValidator { 56 public TestReport runImpl() throws Exception { 57 Painter painter = null; 58 URL refURL = new URL ("http", 59 "dummyHost", 60 "dummyFile.svg"); 61 62 Test t 63 = new SVGAccuracyTest(painter, refURL); 64 65 setConfig(t, 66 false, 67 SVGAccuracyTest.ERROR_CANNOT_GENERATE_SVG); 68 69 return super.runImpl(); 70 } 71 } 72 73 static class PainterWithException extends TestReportValidator 74 implements Painter { 75 76 public void paint(Graphics2D g){ 77 g.setComposite(null); g.fillRect(0, 0, 20, 20); 79 } 80 81 public TestReport runImpl() throws Exception { 82 Painter painter = this; 83 URL refURL = new URL ("http", 84 "dummyHost", 85 "dummyFile.svg"); 86 Test t = new SVGAccuracyTest(painter, refURL); 87 88 setConfig(t, 89 false, 90 SVGAccuracyTest.ERROR_CANNOT_GENERATE_SVG); 91 92 return super.runImpl(); 93 } 94 } 95 96 static class ValidPainterTest extends TestReportValidator 97 implements Painter{ 98 99 public void paint(Graphics2D g){ 100 g.setPaint(Color.red); 101 g.fillRect(0, 0, 40, 40); 102 } 103 } 104 105 static class NullReferenceURL extends ValidPainterTest { 106 public TestReport runImpl() throws Exception { 107 Test t = new SVGAccuracyTest(this, null); 108 109 setConfig(t, 110 false, 111 SVGAccuracyTest.ERROR_CANNOT_OPEN_REFERENCE_SVG_FILE); 112 113 return super.runImpl(); 114 } 115 } 116 117 static class InexistantReferenceURL extends ValidPainterTest { 118 public TestReport runImpl() throws Exception { 119 Test t = new SVGAccuracyTest(this, 120 new URL ("http", 121 "dummyHost", 122 "dummyFile.svg")); 123 124 setConfig(t, 125 false, 126 SVGAccuracyTest.ERROR_CANNOT_OPEN_REFERENCE_SVG_FILE); 127 128 return super.runImpl(); 129 } 130 } 131 132 static class DiffWithReferenceImage extends ValidPainterTest { 133 public TestReport runImpl() throws Exception { 134 File tmpFile = File.createTempFile("EmptySVGReference", 135 null); 136 tmpFile.deleteOnExit(); 137 138 Test t = new SVGAccuracyTest(this, 139 tmpFile.toURL()); 140 141 setConfig(t, 142 false, 143 SVGAccuracyTest.ERROR_GENERATED_SVG_INACCURATE); 144 145 return super.runImpl(); 146 } 147 } 148 149 static class SameAsReferenceImage extends ValidPainterTest { 150 public TestReport runImpl() throws Exception { 151 File tmpFile = File.createTempFile("SVGReference", 152 null); 153 tmpFile.deleteOnExit(); 154 155 SVGAccuracyTest t = new SVGAccuracyTest(this, 156 tmpFile.toURL()); 157 158 t.setSaveSVG(tmpFile); 159 160 setConfig(t, 161 false, 162 SVGAccuracyTest.ERROR_GENERATED_SVG_INACCURATE); 163 164 super.runImpl(); 167 168 setConfig(t, 171 true, 172 null); 173 174 return super.runImpl(); 175 } 176 } 177 178 } 179 | Popular Tags |