Path: blob/master/test/jdk/javax/imageio/plugins/gif/EndWriteSequenceTest.java
41154 views
/*1* Copyright (c) 2005, 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 6275366 627536926* @summary Verifies that behaviour of GIFImageWriter.endWriteSequence() is27* consistent with specification28*/2930import java.io.ByteArrayOutputStream;31import java.io.IOException;3233import javax.imageio.ImageIO;34import javax.imageio.ImageWriter;35import javax.imageio.stream.ImageOutputStream;3637public class EndWriteSequenceTest {38public static void main(String[] args) throws IOException {39ImageWriter w =40ImageIO.getImageWritersByFormatName("GIF").next();4142boolean gotCorrectException = false;4344/**45* check statement: "Throws: IllegalStateException -46* if the output has not been set ...."47*/48try {49w.reset(); // to be shure that output is null50w.endWriteSequence();51} catch (IllegalStateException e) {52gotCorrectException = true;53} catch (Throwable e) {54throw new RuntimeException("Test failed.", e);55}56if (!gotCorrectException) {57throw new RuntimeException("Test failed.");58}5960/**61* set up output stream62*/63ByteArrayOutputStream baos =64new ByteArrayOutputStream();6566ImageOutputStream ios =67ImageIO.createImageOutputStream(baos);6869w.setOutput(ios);7071/**72* check statement: "Throws: IllegalStateException -73* if .... prepareWriteSequence has not been called.74*/75gotCorrectException = false;76try {77w.endWriteSequence();78} catch (IllegalStateException e) {79gotCorrectException = true;80} catch (Throwable e) {81throw new RuntimeException("Test failed.", e);82}83if (!gotCorrectException) {84throw new RuntimeException("Test failed.");85}8687System.out.println("Test passed.");88}89}909192