Ignore:
Timestamp:
2017-03-05T15:52:54+01:00 (7 years ago)
Author:
michael2402
Message:

See #13999: Use MapCSS test only for OpenJDK

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/MapCSSRendererTest.java

    r11449 r11691  
    55import static org.junit.Assert.fail;
    66
     7import java.awt.Graphics2D;
    78import java.awt.Point;
     9import java.awt.RenderingHints;
    810import java.awt.image.BufferedImage;
    911import java.io.File;
     
    1113import java.io.FileNotFoundException;
    1214import java.io.IOException;
     15import java.text.MessageFormat;
     16import java.util.ArrayList;
    1317import java.util.Arrays;
    1418import java.util.Collection;
     
    1822import javax.imageio.ImageIO;
    1923
    20 import org.junit.Ignore;
     24import org.junit.Assume;
     25import org.junit.Before;
    2126import org.junit.Rule;
    2227import org.junit.Test;
     
    6570     * @return The parameters.
    6671     */
    67     @Parameters
     72    @Parameters(name="{1}")
    6873    public static Collection<Object[]> runs() {
    6974        return Stream.of(
     
    7479                new TestConfig("way-width", AREA_DEFAULT)
    7580
    76                 ).map(e -> new Object[] {e})
     81                ).map(e -> new Object[] {e, e.testDirectory})
    7782                .collect(Collectors.toList());
    7883    }
     
    8085    /**
    8186     * @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) {
    8490        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"));
    85102    }
    86103
     
    90107     */
    91108    @Test
    92     @Ignore("not ready")
    93109    public void testRender() throws Exception {
    94110        // load the data
     
    131147        nc.zoomTo(testConfig.testArea);
    132148        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);
    134161
    135162        BufferedImage reference = testConfig.getReference();
     
    140167
    141168        StringBuilder differences = new StringBuilder();
     169        ArrayList<Point> differencePoints = new ArrayList<>();
    142170
    143171        for (int y = 0; y < reference.getHeight(); y++) {
     
    145173                int expected = reference.getRGB(x, y);
    146174                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                    }
    156187                }
    157188            }
    158189        }
    159190
    160         if (differences.length() > 0) {
     191        if (differencePoints.size() > 0) {
    161192            // You can use this to debug:
    162193            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;
    164219        }
    165220    }
Note: See TracChangeset for help on using the changeset viewer.