Changeset 12996 in josm for trunk/test/functional/org/openstreetmap/josm/gui/mappaint
- Timestamp:
- 2017-10-14T20:01:24+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/functional/org/openstreetmap/josm/gui/mappaint/MapCSSRendererTest.java
r12995 r12996 5 5 import static org.junit.Assert.fail; 6 6 7 import java.awt.Color; 7 8 import java.awt.GraphicsEnvironment; 8 9 import java.awt.Point; … … 82 83 83 84 /** Text for nodes */ 84 new TestConfig("node-text", AREA_DEFAULT).usesFont("DejaVu Sans"), 85 new TestConfig("node-text", AREA_DEFAULT).usesFont("DejaVu Sans") 86 .setThresholdPixels(100).setThresholdTotalColorDiff(100), 85 87 86 88 /** Tests that StyledMapRenderer#drawWay respects width */ … … 103 105 104 106 /** Tests area label drawing/placement */ 105 new TestConfig("area-text", AREA_DEFAULT) ,107 new TestConfig("area-text", AREA_DEFAULT).setThresholdPixels(50).setThresholdTotalColorDiff(50), 106 108 107 109 /** Tests area icon drawing/placement */ … … 117 119 118 120 /** Tests text along a way */ 119 new TestConfig("way-text", AREA_DEFAULT) ,121 new TestConfig("way-text", AREA_DEFAULT).setThresholdPixels(20).setThresholdTotalColorDiff(40), 120 122 121 123 /** Another test for node shapes */ … … 128 130 new TestConfig("way-dashes2"), 129 131 /** Tests node text placement */ 130 new TestConfig("node-text2") ,132 new TestConfig("node-text2").setThresholdPixels(30).setThresholdTotalColorDiff(50), 131 133 /** Tests relation link selector */ 132 134 new TestConfig("relation-linkselector"), … … 135 137 136 138 /** Tests evaluation of expressions */ 137 new TestConfig("eval").setImageWidth(600) 139 new TestConfig("eval").setImageWidth(600).setThresholdPixels(100).setThresholdTotalColorDiff(100) 138 140 139 141 ).map(e -> new Object[] {e, e.testDirectory}) … … 204 206 StringBuilder differences = new StringBuilder(); 205 207 ArrayList<Point> differencePoints = new ArrayList<>(); 208 int colorDiffSum = 0; 206 209 207 210 for (int y = 0; y < reference.getHeight(); y++) { … … 211 214 if (!colorsAreSame(expected, result)) { 212 215 differencePoints.add(new Point(x, y)); 216 int colorDiff = colorDiff(new Color(expected, true), new Color(result, true)); 213 217 if (differences.length() < 500) { 214 218 differences.append("\nDifference at ") … … 219 223 .append(Integer.toHexString(expected)) 220 224 .append(" but got ") 221 .append(Integer.toHexString(result)); 225 .append(Integer.toHexString(result)) 226 .append(" (color diff is ") 227 .append(colorDiff) 228 .append(")"); 222 229 } 230 colorDiffSum += colorDiff; 223 231 } 224 232 } 225 233 } 226 234 227 if (differencePoints.size() > 0) {235 if (differencePoints.size() > testConfig.thresholdPixels || colorDiffSum > testConfig.thresholdTotalColorDiff) { 228 236 // You can use this to debug: 229 237 ImageIO.write(image, "png", new File(testConfig.getTestDirectory() + "/test-output.png")); … … 236 244 ImageIO.write(diffImage, "png", new File(testConfig.getTestDirectory() + "/test-differences.png")); 237 245 238 fail(MessageFormat.format("Images for test {0} differ at {1} points: {2}", 239 testConfig.testDirectory, differencePoints.size(), differences.toString())); 246 if (differencePoints.size() > testConfig.thresholdPixels) { 247 fail(MessageFormat.format("Images for test {0} differ at {1} points, threshold is {2}: {3}", 248 testConfig.testDirectory, differencePoints.size(), testConfig.thresholdPixels, differences.toString())); 249 } else { 250 fail(MessageFormat.format("Images for test {0} differ too much in color, value is {1}, permitted threshold is {2}: {3}", 251 testConfig.testDirectory, colorDiffSum, testConfig.thresholdTotalColorDiff, differences.toString())); 252 } 240 253 } 241 254 } … … 246 259 n.setDisabledState(false); 247 260 } 261 } 262 263 private int colorDiff(Color c1, Color c2) { 264 return Math.abs(c1.getAlpha() - c2.getAlpha()) + Math.abs(c1.getRed() - c2.getRed()) 265 + Math.abs(c1.getGreen() - c2.getGreen()) + Math.abs(c1.getBlue() - c2.getBlue()); 248 266 } 249 267 … … 269 287 private DataSet ds; 270 288 private int imageWidth = IMAGE_SIZE; 289 private int thresholdPixels; 290 private int thresholdTotalColorDiff; 271 291 272 292 TestConfig(String testDirectory, Bounds testArea) { … … 284 304 } 285 305 306 /** 307 * Set the number of pixels that can differ. 308 * 309 * Needed due to somewhat platform dependent font rendering. 310 * @param thresholdPixels the number of pixels that can differ 311 * @return this object, for convenience 312 */ 313 public TestConfig setThresholdPixels(int thresholdPixels) { 314 this.thresholdPixels = thresholdPixels; 315 return this; 316 } 317 318 /** 319 * Set the threshold for total color difference. 320 * Every difference in any color component (and alpha) will be added up and must not exceed this threshold. 321 * Needed due to somewhat platform dependent font rendering. 322 * @param thresholdTotalColorDiff he threshold for total color difference 323 * @return this object, for convenience 324 */ 325 public TestConfig setThresholdTotalColorDiff(int thresholdTotalColorDiff) { 326 this.thresholdTotalColorDiff = thresholdTotalColorDiff; 327 return this; 328 } 329 286 330 public TestConfig usesFont(String string) { 287 331 this.fonts.add(string);
Note:
See TracChangeset
for help on using the changeset viewer.