Path: blob/master/test/jdk/javax/imageio/ImageReadParamPasses.java
41144 views
/*1* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 442936526* @summary Checks that ImageReadParam.setSourceProgressivePasses handles27* overflow correctly28*/2930import javax.imageio.ImageReadParam;3132public class ImageReadParamPasses {3334private static final int maxint = Integer.MAX_VALUE;3536private static void expect(int i, int j) {37if (i != j) {38throw new RuntimeException("Expected " + i + ", got " + j);39}40}4142private static void checkForIAE(int minPass, int numPasses) {43ImageReadParam param = new ImageReadParam();4445boolean gotIAE = false;46try {47param.setSourceProgressivePasses(minPass, numPasses);48} catch (IllegalArgumentException iae) {49gotIAE = true;50}51if (!gotIAE) {52throw new RuntimeException("Failed to get IAE for wraparound!");53}54}5556private static void test(int minPass, int numPasses) {57ImageReadParam param = new ImageReadParam();5859param.setSourceProgressivePasses(minPass, numPasses);60expect(param.getSourceMinProgressivePass(), minPass);61expect(param.getSourceNumProgressivePasses(), numPasses);6263int maxPass = numPasses == maxint ? maxint : minPass + numPasses - 1;64expect(param.getSourceMaxProgressivePass(), maxPass);65}6667public static void main(String[] args) {68// Typical case69test(17, 30);7071// Read all passes72test(0, maxint);7374// Start at pass 17, continue indefinitely75test(17, maxint);7677// Start at pass maxint - 10, continue indefinitely78test(maxint - 10, maxint);7980// Start at pass maxint - 10, go up to maxint - 181test(maxint - 10, 10);8283// Start at pass maxint - 10, go up to maxint84test(maxint - 10, 11);8586// Start at maxint, continue indefinitely :-)87test(maxint, maxint);8889// Start at maxint, go up to maxint90test(maxint, 1);9192// Check that an IllegalArgumentException is thrown if93// wraparound occurs94checkForIAE(maxint, 2);95checkForIAE(maxint - 5, 10);96checkForIAE(10, maxint - 5);97checkForIAE(maxint - 1000, maxint - 1000);98checkForIAE(maxint - 1, maxint - 1);99}100}101102103