1 package org.apache.batik.test.svg; 18 19 import java.util.Vector ; 20 21 import org.apache.batik.test.TestReport; 22 23 import org.apache.batik.test.AbstractTest; 24 import org.apache.batik.test.DefaultTestSuite; 25 26 36 public class SelfContainedSVGOnLoadTestValidator extends DefaultTestSuite { 37 40 public static final String ERROR_UNEXPECTED_TEST_RESULT = 41 "SelfContainedSVGOnLoadTestValidator.error.unexpected.test.result"; 42 43 public static final String ERROR_UNEXPECTED_ERROR_CODE = 44 "SelfContainedSVGOnLoadTestValidator.error.unexpected.error.code"; 45 46 public static final String ERROR_UNEXPECTED_NUMBER_OF_DESCRIPTION_ENTRIES 47 = "SelfContainedSVGOnLoadTestValidator.error.unexpected.number.of.description.entries"; 48 49 public static final String ERROR_UNEXPECTED_TEST_FAILURE 50 = "SelfContainedSVGOnLoadTestValidator.error.unexpected.test.failure"; 51 52 public static final String ERROR_UNEXPECTED_DESCRIPTION_ENTRY 53 = "SelfContainedSVGOnLoadTestValidator.error.unexpected.description.entry"; 54 55 public static final String ENTRY_ERROR_CODE = 56 "SelfContainedSVGOnLoadTestValidator.entry.error.code"; 57 58 public static final String ENTRY_EXPECTED_ERROR_CODE = 59 "SelfContainedSVGOnLoadTestValidator.entry.expected.error.code"; 60 61 public static final String ENTRY_NUMBER_OF_DESCRIPTION = 62 "SelfContainedSVGOnLoadTestValidator.entry.number.of.description"; 63 64 public static final String ENTRY_EXPECTED_NUMBER_OF_DESCRIPTION = 65 "SelfContainedSVGOnLoadTestValidator.entry.expected.number.of.description"; 66 67 public static final String ENTRY_KEY = 68 "SelfContainedSVGOnLoadTestValidator.entry.key"; 69 70 public static final String ENTRY_EXPECTED_KEY = 71 "SelfContainedSVGOnLoadTestValidator.entry.expected.key"; 72 73 74 77 public static final String invalidURL 78 = "invalidURL"; 79 public static final String processingErrorURL 80 = "test-resources/org/apache/batik/test/svg/processingError.svg"; 81 public static final String invalidTestResultElementsNumberURL 82 = "test-resources/org/apache/batik/test/svg/invalidTestResultElementsNumber.svg"; 83 public static final String unexpectedResultValueURL 84 = "test-resources/org/apache/batik/test/svg/unexpectedResultValue.svg"; 85 public static final String missingOrEmptyErrorCodeURL 86 = "test-resources/org/apache/batik/test/svg/missingOrEmptyErrorCode.svg"; 87 public static final String errorURL 88 = "test-resources/org/apache/batik/test/svg/error.svg"; 89 public static final String errorAndEntriesURL 90 = "test-resources/org/apache/batik/test/svg/errorAndEntries.svg"; 91 public static final String successURL 92 = "test-resources/org/apache/batik/test/svg/success.svg"; 93 94 95 public SelfContainedSVGOnLoadTestValidator(){ 96 addTest(new CannotLoadSVGDocument()); 97 addTest(new ProcessingError()); 98 addTest(new InvalidTestResultElementsNumber()); 99 addTest(new UnexpectedResultValue()); 100 addTest(new MissingOrEmptyErrorCode()); 101 addTest(new ReportError()); 102 addTest(new ReportSuccess()); 103 addTest(new ReportErrorAndEntries()); 104 } 105 106 static class ReportErrorAndEntries extends DefaultErrorTest { 107 public ReportErrorAndEntries() { 108 super(errorAndEntriesURL, 109 "can.you.read.this.error.code", 110 new String [] { "can.you.read.this.first.entry", 111 "can.you.read.this.second.entry" }); 112 } 113 } 114 115 static class ReportError extends DefaultErrorTest { 116 public ReportError(){ 117 super(errorURL, 118 "can.you.read.this.error.code", 119 null); 120 } 121 } 122 123 static class ReportSuccess extends AbstractTest { 124 public TestReport rumImpl() throws Exception { 125 SelfContainedSVGOnLoadTest t = new SelfContainedSVGOnLoadTest(successURL); 126 TestReport tr = t.run(); 127 128 if (!tr.hasPassed()) { 129 return reportError(ERROR_UNEXPECTED_TEST_FAILURE); 130 } 131 132 return reportSuccess(); 133 } 134 } 135 136 static class MissingOrEmptyErrorCode extends DefaultErrorTest { 137 public MissingOrEmptyErrorCode(){ 138 super(missingOrEmptyErrorCodeURL, 139 SelfContainedSVGOnLoadTest.ERROR_MISSING_OR_EMPTY_ERROR_CODE_ON_FAILED_TEST, 140 null); 141 } 142 } 143 144 static class UnexpectedResultValue extends DefaultErrorTest{ 145 public UnexpectedResultValue(){ 146 super(unexpectedResultValueURL, 147 SelfContainedSVGOnLoadTest.ERROR_UNEXPECTED_RESULT_VALUE, 148 new String []{SelfContainedSVGOnLoadTest.ENTRY_KEY_RESULT_VALUE}); 149 } 150 } 151 152 153 static class InvalidTestResultElementsNumber extends DefaultErrorTest{ 154 public InvalidTestResultElementsNumber(){ 155 super(invalidTestResultElementsNumberURL, 156 SelfContainedSVGOnLoadTest.ERROR_UNEXPECTED_NUMBER_OF_TEST_RESULT_ELEMENTS, 157 new String []{SelfContainedSVGOnLoadTest.ENTRY_KEY_NUMBER_OF_TEST_RESULT_ELEMENTS}); 158 } 159 } 160 161 static class ProcessingError extends DefaultErrorTest{ 162 public ProcessingError(){ 163 super(processingErrorURL, 164 SelfContainedSVGOnLoadTest.ERROR_WHILE_PROCESSING_SVG_DOCUMENT, 165 new String []{SelfContainedSVGOnLoadTest.ENTRY_KEY_ERROR_DESCRIPTION}); 166 } 167 } 168 169 static class CannotLoadSVGDocument extends DefaultErrorTest { 170 public CannotLoadSVGDocument(){ 171 super(invalidURL, 172 SelfContainedSVGOnLoadTest.ERROR_CANNOT_LOAD_SVG_DOCUMENT, 173 new String [] {SelfContainedSVGOnLoadTest.ENTRY_KEY_ERROR_DESCRIPTION}); 174 } 175 } 176 177 static class DefaultErrorTest extends AbstractTest{ 178 String svgURL; 179 String expectedErrorCode; 180 String [] expectedEntryCodes; 181 182 public DefaultErrorTest(String svgURL, 183 String expectedErrorCode, 184 String [] expectedEntryCodes 185 ){ 186 this.svgURL = svgURL; 187 this.expectedErrorCode = expectedErrorCode; 188 this.expectedEntryCodes = expectedEntryCodes; 189 } 190 191 public TestReport runImpl() throws Exception { 192 SelfContainedSVGOnLoadTest t 193 = new SelfContainedSVGOnLoadTest(svgURL); 194 TestReport tr = t.run(); 195 196 if(tr.hasPassed()){ 197 return reportError(ERROR_UNEXPECTED_TEST_RESULT); 198 } 199 200 if(tr.getErrorCode() != expectedErrorCode){ 201 TestReport r = reportError(ERROR_UNEXPECTED_ERROR_CODE); 202 r.addDescriptionEntry(ENTRY_ERROR_CODE, tr.getErrorCode()); 203 r.addDescriptionEntry(ENTRY_EXPECTED_ERROR_CODE, 204 expectedErrorCode); 205 return r; 206 } 207 208 TestReport.Entry[] desc = tr.getDescription(); 210 int nDesc = 0, enDesc = 0; 211 if (desc != null){ 212 nDesc = desc.length; 213 } 214 if (expectedEntryCodes != null){ 215 enDesc = expectedEntryCodes.length; 216 } 217 218 if (nDesc != enDesc){ 219 TestReport r = reportError(ERROR_UNEXPECTED_NUMBER_OF_DESCRIPTION_ENTRIES); 220 221 r.addDescriptionEntry(ENTRY_NUMBER_OF_DESCRIPTION, 222 "" + nDesc); 223 r.addDescriptionEntry(ENTRY_EXPECTED_NUMBER_OF_DESCRIPTION, 224 "" + enDesc); 225 return r; 226 } 227 228 if (nDesc > 0){ 229 Vector veDesc = new Vector (); 230 for(int i=0; i<nDesc; i++){ 231 veDesc.add(expectedEntryCodes[i]); 232 } 233 234 for(int i=0; i<nDesc; i++){ 235 String key = desc[i].getKey(); 236 if (key == null || !veDesc.contains(key)){ 237 TestReport r = reportError(ERROR_UNEXPECTED_DESCRIPTION_ENTRY); 238 if (key != null){ 239 r.addDescriptionEntry(ENTRY_KEY, key); 240 r.addDescriptionEntry(ENTRY_EXPECTED_KEY, 241 SelfContainedSVGOnLoadTest.ENTRY_KEY_NUMBER_OF_TEST_RESULT_ELEMENTS); 242 } 243 return r; 244 } 245 } 246 } 247 248 return reportSuccess(); 249 } 250 } 251 252 } 253 254 | Popular Tags |