Changeset 19613 in josm for trunk/test/functional


Ignore:
Timestamp:
2026-08-11T15:36:21+02:00 (34 hours ago)
Author:
Don-vip
Message:

fix #24793 - update reference images after JSVG migration (for good?)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/functional/org/openstreetmap/josm/tools/ImageProviderTest.java

    r19588 r19613  
    2121import java.util.logging.Handler;
    2222import java.util.logging.LogRecord;
     23import java.util.regex.Matcher;
     24import java.util.regex.Pattern;
    2325
    2426import javax.swing.ImageIcon;
     
    187189    }
    188190
     191    private static final Pattern JAVA_SUFFIX_PATTERN = Pattern.compile("-java(\\d+)\\.png$");
     192
     193    /**
     194     * Determine the reference image file to use for the given reference name.
     195     * <p>
     196     * Different Java versions may render SVG images slightly differently.
     197     * When this happens, an additional reference file with a {@code -javaXX} suffix
     198     * can be added next to the original reference file. This method
     199     * then picks the reference file whose suffixed Java version is the closest (but not newer) to the
     200     * Java version currently running the test, falling back to the unsuffixed file otherwise.
     201     * <p>
     202     * This way, new reference files only need to be added when a new Java version actually renders
     203     * something differently, without needing to touch this method.
     204     * @param reference the reference identifier
     205     * @return the most appropriate reference file for the current Java version
     206     */
    189207    private static File getReferenceFile(String reference) {
    190         // Java 11-17 and Java 21 render SVG images differently, thus, use separate reference files
    191         final String javaSuffix = Utils.getJavaVersion() == 21 ? "-java21" : "";
    192         return new File(TestUtils.getTestDataRoot() + "/" + ImageProviderTest.class.getSimpleName() + javaSuffix + "/" + reference + ".png");
     208        final File directory = new File(TestUtils.getTestDataRoot() + "/" + ImageProviderTest.class.getSimpleName());
     209        final int javaVersion = Utils.getJavaVersion();
     210        final File[] candidates = directory.listFiles((dir, name) -> name.startsWith(reference + "-java"));
     211        File bestFile = null;
     212        int bestVersion = -1;
     213        if (candidates != null) {
     214            for (File candidate : candidates) {
     215                Matcher matcher = JAVA_SUFFIX_PATTERN.matcher(candidate.getName());
     216                if (matcher.find()) {
     217                    int version = Integer.parseInt(matcher.group(1));
     218                    if (version <= javaVersion && version > bestVersion) {
     219                        bestVersion = version;
     220                        bestFile = candidate;
     221                    }
     222                }
     223            }
     224        }
     225        return bestFile != null ? bestFile : new File(directory, reference + ".png");
    193226    }
    194227
Note: See TracChangeset for help on using the changeset viewer.