- Timestamp:
- 2017-03-05T15:52:54+01:00 (8 years ago)
- Location:
- trunk/test
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/MapCSSRendererTest.java
r11449 r11691 5 5 import static org.junit.Assert.fail; 6 6 7 import java.awt.Graphics2D; 7 8 import java.awt.Point; 9 import java.awt.RenderingHints; 8 10 import java.awt.image.BufferedImage; 9 11 import java.io.File; … … 11 13 import java.io.FileNotFoundException; 12 14 import java.io.IOException; 15 import java.text.MessageFormat; 16 import java.util.ArrayList; 13 17 import java.util.Arrays; 14 18 import java.util.Collection; … … 18 22 import javax.imageio.ImageIO; 19 23 20 import org.junit.Ignore; 24 import org.junit.Assume; 25 import org.junit.Before; 21 26 import org.junit.Rule; 22 27 import org.junit.Test; … … 65 70 * @return The parameters. 66 71 */ 67 @Parameters 72 @Parameters(name="{1}") 68 73 public static Collection<Object[]> runs() { 69 74 return Stream.of( … … 74 79 new TestConfig("way-width", AREA_DEFAULT) 75 80 76 ).map(e -> new Object[] {e })81 ).map(e -> new Object[] {e, e.testDirectory}) 77 82 .collect(Collectors.toList()); 78 83 } … … 80 85 /** 81 86 * @param testConfig The config to use for this test. 82 */ 83 public MapCSSRendererTest(TestConfig testConfig) { 87 * @param ignored The name to print it nicely 88 */ 89 public MapCSSRendererTest(TestConfig testConfig, String ignored) { 84 90 this.testConfig = testConfig; 91 } 92 93 /** 94 * This test only runs on OpenJDK. 95 * It is ignored for other Java versions since they differ slightly in their rendering engine. 96 * @since 11691 97 */ 98 @Before 99 public void testForOpenJDK() { 100 String javaHome = System.getProperty("java.home"); 101 Assume.assumeTrue(javaHome != null && javaHome.contains("openjdk")); 85 102 } 86 103 … … 90 107 */ 91 108 @Test 92 @Ignore("not ready")93 109 public void testRender() throws Exception { 94 110 // load the data … … 131 147 nc.zoomTo(testConfig.testArea); 132 148 dataSet.allPrimitives().stream().forEach(n -> n.setHighlighted(n.isKeyTrue("highlight"))); 133 new StyledMapRenderer(image.createGraphics(), nc, false).render(dataSet, false, testConfig.testArea); 149 Graphics2D g = image.createGraphics(); 150 // Force all render hints to be defaults - do not use platform values 151 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 152 g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); 153 g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); 154 g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); 155 g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); 156 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 157 g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); 158 g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); 159 g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 160 new StyledMapRenderer(g, nc, false).render(dataSet, false, testConfig.testArea); 134 161 135 162 BufferedImage reference = testConfig.getReference(); … … 140 167 141 168 StringBuilder differences = new StringBuilder(); 169 ArrayList<Point> differencePoints = new ArrayList<>(); 142 170 143 171 for (int y = 0; y < reference.getHeight(); y++) { … … 145 173 int expected = reference.getRGB(x, y); 146 174 int result = image.getRGB(x, y); 147 if (expected != result && differences.length() < 500) { 148 differences.append("\nDifference at ") 149 .append(x) 150 .append(",") 151 .append(y) 152 .append(": Expected ") 153 .append(Integer.toHexString(expected)) 154 .append(" but got ") 155 .append(Integer.toHexString(result)); 175 if (!colorsAreSame(expected, result)) { 176 differencePoints.add(new Point(x, y)); 177 if (differences.length() < 500) { 178 differences.append("\nDifference at ") 179 .append(x) 180 .append(",") 181 .append(y) 182 .append(": Expected ") 183 .append(Integer.toHexString(expected)) 184 .append(" but got ") 185 .append(Integer.toHexString(result)); 186 } 156 187 } 157 188 } 158 189 } 159 190 160 if (difference s.length() > 0) {191 if (differencePoints.size() > 0) { 161 192 // You can use this to debug: 162 193 ImageIO.write(image, "png", new File(testConfig.getTestDirectory() + "/test-output.png")); 163 fail("Images for test " + testConfig.testDirectory + " differ: " + differences.toString()); 194 195 // Add a nice image that highlights the differences: 196 BufferedImage diffImage = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_ARGB); 197 for (Point p : differencePoints) { 198 diffImage.setRGB(p.x, p.y, 0xffff0000); 199 } 200 ImageIO.write(diffImage, "png", new File(testConfig.getTestDirectory() + "/test-differences.png")); 201 202 fail(MessageFormat.format("Images for test {1} differ at {2} points: {3}", 203 testConfig.testDirectory, differencePoints.size(), differences.toString())); 204 } 205 } 206 207 /** 208 * Check if two colors differ 209 * @param expected 210 * @param result 211 * @return <code>true</code> if they differ. 212 */ 213 private boolean colorsAreSame(int expected, int result) { 214 int expectedAlpha = expected >> 24; 215 if (expectedAlpha == 0) { 216 return (result & 0xff000000) == 0; 217 } else { 218 return expected == result; 164 219 } 165 220 }
Note:
See TracChangeset
for help on using the changeset viewer.