1 16 17 package org.apache.batik.css.engine.value; 18 19 import java.util.StringTokenizer ; 20 21 import org.w3c.css.sac.LexicalUnit; 22 23 import org.apache.batik.css.engine.value.svg.MarkerManager; 24 import org.apache.batik.css.engine.value.svg.OpacityManager; 25 import org.apache.batik.css.engine.value.svg.SVGColorManager; 26 import org.apache.batik.css.engine.value.svg.SVGPaintManager; 27 import org.apache.batik.css.engine.value.svg.SpacingManager; 28 import org.apache.batik.css.parser.Parser; 29 import org.apache.batik.test.AbstractTest; 30 import org.apache.batik.test.DefaultTestReport; 31 import org.apache.batik.test.TestReport; 32 import org.apache.batik.util.CSSConstants; 33 34 40 public class PropertyManagerTest extends AbstractTest { 41 42 45 public static final String ERROR_IS_INHERITED = 46 "PropertyManagerTest.error.inherited"; 47 48 51 public static final String ERROR_INHERIT_VALUE = 52 "PropertyManagerTest.error.inherit.value"; 53 54 57 public static final String ERROR_INVALID_DEFAULT_VALUE = 58 "PropertyManagerTest.error.invalid.default.value"; 59 60 63 public static final String ERROR_INVALID_VALUE = 64 "PropertyManagerTest.error.invalid.value"; 65 66 69 public static final String ERROR_INSTANTIATION = 70 "PropertyManagerTest.error.instantiation"; 71 72 75 protected String managerClassName; 76 77 80 protected Boolean isInherited; 81 82 85 protected String [] identValues; 86 87 90 protected String defaultValue; 91 92 100 public PropertyManagerTest(String managerClassName, 101 Boolean isInherited, 102 String defaultValue, 103 String identValueList) { 104 this.managerClassName = managerClassName; 105 this.isInherited = isInherited; 106 this.defaultValue = defaultValue; 107 StringTokenizer tokens = new StringTokenizer (identValueList, "|"); 108 int nbIdentValue = tokens.countTokens(); 109 if (nbIdentValue > 0) { 110 identValues = new String [nbIdentValue]; 111 for (int i=0; tokens.hasMoreTokens(); ++i) { 112 identValues[i] = tokens.nextToken().trim(); 113 } 114 } 115 } 116 117 120 protected ValueManager createValueManager() throws Exception { 121 return (ValueManager)Class.forName(managerClassName).newInstance(); 122 } 123 124 128 public TestReport runImpl() throws Exception { 129 DefaultTestReport report = new DefaultTestReport(this); 130 131 ValueManager manager; 132 try { 133 manager = createValueManager(); 134 } catch (Exception ex) { 135 report.setErrorCode(ERROR_INSTANTIATION); 136 report.setPassed(false); 137 report.addDescriptionEntry(ERROR_INSTANTIATION, ex.getMessage()); 138 return report; 139 } 140 141 if (!defaultValue.equals("__USER_AGENT__")) { 143 String s = manager.getDefaultValue().getCssText(); 144 if (!defaultValue.equalsIgnoreCase(s)) { 145 report.setErrorCode(ERROR_INVALID_DEFAULT_VALUE); 146 report.setPassed(false); 147 report.addDescriptionEntry(ERROR_INVALID_DEFAULT_VALUE, 148 "should be: "+defaultValue); 149 } 150 } 151 152 if (isInherited.booleanValue() != manager.isInheritedProperty()) { 154 report.setErrorCode(ERROR_IS_INHERITED); 155 report.setPassed(false); 156 report.addDescriptionEntry(ERROR_IS_INHERITED, ""); 157 } 158 159 Parser cssParser = new Parser(); 160 try { 162 LexicalUnit lu = cssParser.parsePropertyValue("inherit"); 163 Value v = manager.createValue(lu, null); 164 String s = v.getCssText(); 165 if (!"inherit".equalsIgnoreCase(s)) { 166 report.setErrorCode(ERROR_INHERIT_VALUE); 167 report.setPassed(false); 168 report.addDescriptionEntry(ERROR_INHERIT_VALUE, "inherit"); 169 } 170 } catch (Exception ex) { 171 report.setErrorCode(ERROR_INHERIT_VALUE); 172 report.setPassed(false); 173 report.addDescriptionEntry(ERROR_INHERIT_VALUE, ex.getMessage()); 174 } 175 176 if (identValues != null) { 178 try { 179 for (int i=0; i < identValues.length; ++i) { 180 LexicalUnit lu = cssParser.parsePropertyValue(identValues[i]); 181 Value v = manager.createValue(lu, null); 182 String s = v.getCssText(); 183 if (!identValues[i].equalsIgnoreCase(s)) { 184 report.setErrorCode(ERROR_INVALID_VALUE); 185 report.setPassed(false); 186 report.addDescriptionEntry(ERROR_INVALID_VALUE, 187 identValues[i]+"/"+s); 188 } 189 } 190 } catch (Exception ex) { 191 report.setErrorCode(ERROR_INVALID_VALUE); 192 report.setPassed(false); 193 report.addDescriptionEntry(ERROR_INVALID_VALUE, 194 ex.getMessage()); 195 } 196 } 197 return report; 198 } 199 200 203 public static class FillManager extends SVGPaintManager { 204 public FillManager() { 205 super(CSSConstants.CSS_FILL_PROPERTY); 206 } 207 } 208 209 212 public static class FillOpacityManager extends OpacityManager { 213 public FillOpacityManager() { 214 super(CSSConstants.CSS_FILL_OPACITY_PROPERTY, true); 215 } 216 } 217 218 221 public static class FloodColorManager extends SVGColorManager { 222 public FloodColorManager() { 223 super(CSSConstants.CSS_FLOOD_COLOR_PROPERTY); 224 } 225 } 226 227 230 public static class FloodOpacityManager extends OpacityManager { 231 public FloodOpacityManager() { 232 super(CSSConstants.CSS_FLOOD_OPACITY_PROPERTY, false); 233 } 234 } 235 236 239 public static class LetterSpacingManager extends SpacingManager { 240 public LetterSpacingManager() { 241 super(CSSConstants.CSS_LETTER_SPACING_PROPERTY); 242 } 243 } 244 245 248 public static class LightingColorManager extends SVGColorManager { 249 public LightingColorManager() { 250 super(CSSConstants.CSS_LIGHTING_COLOR_PROPERTY, ValueConstants.WHITE_RGB_VALUE); 251 } 252 } 253 254 257 public static class MarkerEndManager extends MarkerManager { 258 public MarkerEndManager() { 259 super(CSSConstants.CSS_MARKER_END_PROPERTY); 260 } 261 } 262 263 266 public static class MarkerMidManager extends MarkerManager { 267 public MarkerMidManager() { 268 super(CSSConstants.CSS_MARKER_MID_PROPERTY); 269 } 270 } 271 272 275 public static class MarkerStartManager extends MarkerManager { 276 public MarkerStartManager() { 277 super(CSSConstants.CSS_MARKER_START_PROPERTY); 278 } 279 } 280 281 284 public static class DefaultOpacityManager extends OpacityManager { 285 public DefaultOpacityManager() { 286 super(CSSConstants.CSS_OPACITY_PROPERTY, false); 287 } 288 } 289 290 293 public static class StopColorManager extends SVGColorManager { 294 public StopColorManager() { 295 super(CSSConstants.CSS_STOP_COLOR_PROPERTY); 296 } 297 } 298 299 302 public static class StopOpacityManager extends OpacityManager { 303 public StopOpacityManager() { 304 super(CSSConstants.CSS_STOP_OPACITY_PROPERTY, false); 305 } 306 } 307 308 311 public static class StrokeManager extends SVGPaintManager { 312 public StrokeManager() { 313 super(CSSConstants.CSS_STROKE_PROPERTY, ValueConstants.NONE_VALUE); 314 } 315 } 316 317 320 public static class StrokeOpacityManager extends OpacityManager { 321 public StrokeOpacityManager() { 322 super(CSSConstants.CSS_STROKE_OPACITY_PROPERTY, true); 323 } 324 } 325 326 329 public static class WordSpacingManager extends SpacingManager { 330 public WordSpacingManager() { 331 super(CSSConstants.CSS_WORD_SPACING_PROPERTY); 332 } 333 } 334 } 335 | Popular Tags |