Changeset 16978 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2020-08-30T09:46:47+02:00 (4 years ago)
Author:
simon04
Message:

fix #19706, fix #19725 - Do not upscale images when using ImageResizeMode.BOUNDED

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/tools/ImageResizeModeTest.java

    r16946 r16978  
    1414import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1515
     16/**
     17 * Unit tests of {@link ImageResizeMode} class.
     18 */
    1619public class ImageResizeModeTest {
    1720
     
    2326    public JOSMTestRules test = new JOSMTestRules().preferences();
    2427
     28    final Dimension image = new Dimension(64, 48);
     29    final Dimension smallImage = new Dimension(14, 10);
     30
     31    /**
     32     * Test method for {@link ImageResizeMode#computeDimension} using {@link ImageResizeMode#AUTO}
     33     */
    2534    @Test
    26     public void testComputeDimension() {
    27         final Dimension image = new Dimension(64, 48);
     35    public void testComputeDimensionAuto() {
    2836        assertThrows(IllegalArgumentException.class, () -> ImageResizeMode.AUTO.computeDimension(new Dimension(0, 0), image));
    2937        assertEquals(new Dimension(64, 48), ImageResizeMode.AUTO.computeDimension(ImageResource.DEFAULT_DIMENSION, image));
     
    3341        assertEquals(new Dimension(21, 16), ImageResizeMode.AUTO.computeDimension(new Dimension(-1, 16), image));
    3442        assertEquals(new Dimension(24, 32), ImageResizeMode.AUTO.computeDimension(new Dimension(24, 32), image));
     43    }
     44
     45    /**
     46     * Test method for {@link ImageResizeMode#computeDimension} using {@link ImageResizeMode#BOUNDED}
     47     */
     48    @Test
     49    public void testComputeDimensionBounded() {
    3550        assertEquals(new Dimension(64, 48), ImageResizeMode.BOUNDED.computeDimension(ImageResource.DEFAULT_DIMENSION, image));
    3651        assertEquals(new Dimension(64, 48), ImageResizeMode.BOUNDED.computeDimension(new Dimension(-1, -1), image));
     
    3954        assertEquals(new Dimension(21, 16), ImageResizeMode.BOUNDED.computeDimension(new Dimension(-1, 16), image));
    4055        assertEquals(new Dimension(24, 18), ImageResizeMode.BOUNDED.computeDimension(new Dimension(24, 32), image));
     56        assertEquals(new Dimension(14, 10), ImageResizeMode.BOUNDED.computeDimension(new Dimension(64, 48), smallImage));
     57        assertEquals(new Dimension(14, 10), ImageResizeMode.BOUNDED.computeDimension(new Dimension(16, 16), smallImage));
     58        assertEquals(new Dimension(11, 8), ImageResizeMode.BOUNDED.computeDimension(new Dimension(16, 8), smallImage));
     59        assertEquals(new Dimension(12, 8), ImageResizeMode.BOUNDED.computeDimension(new Dimension(12, 12), smallImage));
     60        assertEquals(new Dimension(11, 8), ImageResizeMode.BOUNDED.computeDimension(new Dimension(12, 8), smallImage));
     61        assertEquals(new Dimension(8, 5), ImageResizeMode.BOUNDED.computeDimension(new Dimension(8, 16), smallImage));
     62        assertEquals(new Dimension(8, 5), ImageResizeMode.BOUNDED.computeDimension(new Dimension(8, 8), smallImage));
     63        assertEquals(new Dimension(8, 5), ImageResizeMode.BOUNDED.computeDimension(new Dimension(8, 8), smallImage));
     64    }
     65
     66    /**
     67     * Test method for {@link ImageResizeMode#computeDimension} using {@link ImageResizeMode#PADDED}
     68     */
     69    @Test
     70    public void testComputeDimensionPadded() {
    4171        assertThrows(IllegalArgumentException.class, () -> ImageResizeMode.PADDED.computeDimension(new Dimension(0, 0), image));
    4272        assertThrows(IllegalArgumentException.class, () -> ImageResizeMode.PADDED.computeDimension(ImageResource.DEFAULT_DIMENSION, image));
     
    4878    }
    4979
     80    /**
     81     * Test method for {@link ImageResizeMode#cacheKey}
     82     */
    5083    @Test
    5184    public void testCacheKey() {
Note: See TracChangeset for help on using the changeset viewer.