Ignore:
Timestamp:
2020-04-06T00:29:19+02:00 (4 years ago)
Author:
Don-vip
Message:

see #19017 - more lenient test, allow major differences

File:
1 edited

Legend:

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

    r16224 r16235  
    8282        return Stream.of(
    8383                /** Tests for StyledMapRenderer#drawNodeSymbol */
    84                 new TestConfig("node-shapes", AREA_DEFAULT),
     84                new TestConfig("node-shapes", AREA_DEFAULT)
     85                        .setThresholdPixels(100).setThresholdTotalColorDiff(2_110),
    8586
    8687                /** Text for nodes */
    8788                new TestConfig("node-text", AREA_DEFAULT).usesFont("DejaVu Sans")
    88                         .setThresholdPixels(100).setThresholdTotalColorDiff(100),
     89                        .setThresholdPixels(530).setThresholdTotalColorDiff(23_800),
    8990
    9091                /** Tests that StyledMapRenderer#drawWay respects width */
    91                 new TestConfig("way-width", AREA_DEFAULT),
     92                new TestConfig("way-width", AREA_DEFAULT)
     93                        .setThresholdPixels(280).setThresholdTotalColorDiff(22_500),
    9294
    9395                /** Tests the way color property, including alpha */
    94                 new TestConfig("way-color", AREA_DEFAULT),
     96                new TestConfig("way-color", AREA_DEFAULT)
     97                        .setThresholdPixels(100).setThresholdTotalColorDiff(3_400),
    9598
    9699                /** Tests dashed ways. */
    97                 new TestConfig("way-dashes", AREA_DEFAULT),
     100                new TestConfig("way-dashes", AREA_DEFAULT)
     101                        .setThresholdPixels(460).setThresholdTotalColorDiff(12_100),
    98102
    99103                /** Tests dashed way clamping algorithm */
    100                 new TestConfig("way-dashes-clamp", AREA_DEFAULT),
     104                new TestConfig("way-dashes-clamp", AREA_DEFAULT)
     105                        .setThresholdPixels(200).setThresholdTotalColorDiff(6_800),
    101106
    102107                /** Tests fill-color property */
     
    104109
    105110                /** Tests the fill-image property. */
    106                 new TestConfig("area-fill-image", AREA_DEFAULT),
     111                new TestConfig("area-fill-image", AREA_DEFAULT)
     112                        .setThresholdPixels(420).setThresholdTotalColorDiff(11_200),
    107113
    108114                /** Tests area label drawing/placement */
    109                 new TestConfig("area-text", AREA_DEFAULT).setThresholdPixels(50).setThresholdTotalColorDiff(50),
     115                new TestConfig("area-text", AREA_DEFAULT)
     116                        .setThresholdPixels(550).setThresholdTotalColorDiff(17_400),
    110117
    111118                /** Tests area icon drawing/placement */
    112                 new TestConfig("area-icon", AREA_DEFAULT),
     119                new TestConfig("area-icon", AREA_DEFAULT)
     120                        .setThresholdPixels(680).setThresholdTotalColorDiff(23_000),
    113121
    114122                /** Tests if all styles are sorted correctly. Tests {@link StyleRecord#compareTo(StyleRecord)} */
    115                 new TestConfig("order", AREA_DEFAULT),
     123                new TestConfig("order", AREA_DEFAULT)
     124                        .setThresholdPixels(2050).setThresholdTotalColorDiff(101_800),
    116125
    117126                /** Tests repeat-image feature for ways */
    118                 new TestConfig("way-repeat-image", AREA_DEFAULT),
     127                new TestConfig("way-repeat-image", AREA_DEFAULT)
     128                        .setThresholdPixels(2100).setThresholdTotalColorDiff(93_000),
    119129                /** Tests the clamping for repeat-images and repeat-image-phase */
    120                 new TestConfig("way-repeat-image-clamp", AREA_DEFAULT),
     130                new TestConfig("way-repeat-image-clamp", AREA_DEFAULT)
     131                        .setThresholdPixels(80).setThresholdTotalColorDiff(2_300),
    121132
    122133                /** Tests text along a way */
    123                 new TestConfig("way-text", AREA_DEFAULT).setThresholdPixels(20).setThresholdTotalColorDiff(40),
     134                new TestConfig("way-text", AREA_DEFAULT)
     135                        .setThresholdPixels(3400).setThresholdTotalColorDiff(122_700),
    124136
    125137                /** Another test for node shapes */
    126                 new TestConfig("node-shapes2").setImageWidth(600),
     138                new TestConfig("node-shapes2").setImageWidth(600)
     139                        .setThresholdPixels(1230).setThresholdTotalColorDiff(43_700),
    127140                /** Tests default values for node shapes */
    128                 new TestConfig("node-shapes-default"),
     141                new TestConfig("node-shapes-default")
     142                        .setThresholdPixels(10).setThresholdTotalColorDiff(270),
    129143                /** Tests node shapes with both fill and stroke combined */
    130                 new TestConfig("node-shapes-combined"),
     144                new TestConfig("node-shapes-combined")
     145                        .setThresholdPixels(360).setThresholdTotalColorDiff(9_200),
    131146                /** Another test for dashed ways */
    132                 new TestConfig("way-dashes2"),
     147                new TestConfig("way-dashes2")
     148                        .setThresholdPixels(340).setThresholdTotalColorDiff(16_100),
    133149                /** Tests node text placement */
    134                 new TestConfig("node-text2").setThresholdPixels(30).setThresholdTotalColorDiff(50),
     150                new TestConfig("node-text2")
     151                        .setThresholdPixels(1020).setThresholdTotalColorDiff(345_000),
    135152                /** Tests relation link selector */
    136                 new TestConfig("relation-linkselector"),
     153                new TestConfig("relation-linkselector")
     154                        .setThresholdPixels(430).setThresholdTotalColorDiff(13_000),
    137155                /** Tests parent selector on relation */
    138                 new TestConfig("relation-parentselector"),
     156                new TestConfig("relation-parentselector")
     157                        .setThresholdPixels(310).setThresholdTotalColorDiff(8_200),
    139158
    140159                /** Tests evaluation of expressions */
    141                 new TestConfig("eval").setImageWidth(600).setThresholdPixels(100).setThresholdTotalColorDiff(100)
     160                new TestConfig("eval").setImageWidth(600)
     161                        .setThresholdPixels(6610).setThresholdTotalColorDiff(3_304_000)
    142162
    143163                ).map(e -> new Object[] {e, e.testDirectory})
     
    217237                int result = image.getRGB(x, y);
    218238                if (!colorsAreSame(expected, result)) {
    219                     differencePoints.add(new Point(x, y));
    220239                    Color expectedColor = new Color(expected, true);
    221240                    Color resultColor = new Color(result, true);
     
    224243                            + Math.abs(expectedColor.getBlue() - resultColor.getBlue());
    225244                    int alphaDiff = Math.abs(expectedColor.getAlpha() - resultColor.getAlpha());
    226                     if (differences.length() < 500) {
    227                         differences.append("\nDifference at ")
    228                         .append(x)
    229                         .append(",")
    230                         .append(y)
    231                         .append(": Expected ")
    232                         .append(ColorHelper.color2html(expectedColor))
    233                         .append(" but got ")
    234                         .append(ColorHelper.color2html(resultColor))
    235                         .append(" (color diff is ")
    236                         .append(colorDiff)
    237                         .append(", alpha diff is ")
    238                         .append(alphaDiff)
    239                         .append(")");
     245                    // Ignore small alpha differences due to Java versions, rendering libraries and so on
     246                    if (alphaDiff <= 20) {
     247                        alphaDiff = 0;
     248                    }
     249                    // Ignore small color differences for the same reasons, but also completely for almost-transparent pixels
     250                    if (colorDiff <= 15 || resultColor.getAlpha() <= 20) {
     251                        colorDiff = 0;
     252                    }
     253                    if (colorDiff + alphaDiff > 0) {
     254                        differencePoints.add(new Point(x, y));
     255                        if (differences.length() < 2000) {
     256                            differences.append("\nDifference at ")
     257                            .append(x)
     258                            .append(",")
     259                            .append(y)
     260                            .append(": Expected ")
     261                            .append(ColorHelper.color2html(expectedColor))
     262                            .append(" but got ")
     263                            .append(ColorHelper.color2html(resultColor))
     264                            .append(" (color diff is ")
     265                            .append(colorDiff)
     266                            .append(", alpha diff is ")
     267                            .append(alphaDiff)
     268                            .append(")");
     269                        }
    240270                    }
    241271                    colorDiffSum += colorDiff + alphaDiff;
Note: See TracChangeset for help on using the changeset viewer.