test/jdk/javax/imageio/ImageReadParamPasses.java
author erikj
Fri, 06 Apr 2018 02:52:24 +0200
changeset 49540 9704789737c1
parent 47216 71c04702a3d5
permissions -rw-r--r--
8201222: JDK-8199539 broke the OpenJDK build Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45351
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
     1
/*
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
     2
 * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
     4
 *
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
     8
 *
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    13
 * accompanied this code).
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    14
 *
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    18
 *
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    21
 * questions.
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    22
 */
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    23
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    24
/*
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    25
 * @test
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    26
 * @bug 4429365
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    27
 * @summary Checks that ImageReadParam.setSourceProgressivePasses handles
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    28
 *          overflow correctly
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    29
 */
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    30
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    31
import javax.imageio.ImageReadParam;
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    32
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    33
public class ImageReadParamPasses {
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    34
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    35
    private static final int maxint = Integer.MAX_VALUE;
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    36
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    37
    private static void expect(int i, int j) {
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    38
        if (i != j) {
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    39
            throw new RuntimeException("Expected " + i + ", got " + j);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    40
        }
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    41
    }
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    42
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    43
    private static void checkForIAE(int minPass, int numPasses) {
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    44
        ImageReadParam param = new ImageReadParam();
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    45
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    46
        boolean gotIAE = false;
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    47
        try {
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    48
            param.setSourceProgressivePasses(minPass, numPasses);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    49
        } catch (IllegalArgumentException iae) {
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    50
            gotIAE = true;
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    51
        }
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    52
        if (!gotIAE) {
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    53
            throw new RuntimeException("Failed to get IAE for wraparound!");
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    54
        }
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    55
    }
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    56
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    57
    private static void test(int minPass, int numPasses) {
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    58
        ImageReadParam param = new ImageReadParam();
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    59
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    60
        param.setSourceProgressivePasses(minPass, numPasses);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    61
        expect(param.getSourceMinProgressivePass(), minPass);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    62
        expect(param.getSourceNumProgressivePasses(), numPasses);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    63
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    64
        int maxPass = numPasses == maxint ? maxint : minPass + numPasses - 1;
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    65
        expect(param.getSourceMaxProgressivePass(), maxPass);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    66
    }
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    67
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    68
    public static void main(String[] args) {
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    69
        // Typical case
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    70
        test(17, 30);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    71
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    72
        // Read all passes
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    73
        test(0, maxint);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    74
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    75
        // Start at pass 17, continue indefinitely
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    76
        test(17, maxint);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    77
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    78
        // Start at pass maxint - 10, continue indefinitely
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    79
        test(maxint - 10, maxint);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    80
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    81
        // Start at pass maxint - 10, go up to maxint - 1
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    82
        test(maxint - 10, 10);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    83
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    84
        // Start at pass maxint - 10, go up to maxint
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    85
        test(maxint - 10, 11);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    86
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    87
        // Start at maxint, continue indefinitely :-)
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    88
        test(maxint, maxint);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    89
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    90
        // Start at maxint, go up to maxint
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    91
        test(maxint, 1);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    92
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    93
        // Check that an IllegalArgumentException is thrown if
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    94
        // wraparound occurs
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    95
        checkForIAE(maxint, 2);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    96
        checkForIAE(maxint - 5, 10);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    97
        checkForIAE(10, maxint - 5);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    98
        checkForIAE(maxint - 1000, maxint - 1000);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
    99
        checkForIAE(maxint - 1, maxint - 1);
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
   100
    }
f7f615a3aaff 8177628: Opensource unit/regression tests for ImageIO
serb
parents:
diff changeset
   101
}