Path: blob/master/test/jdk/java/io/StringReader/Skip.java
41152 views
/*1* Copyright (c) 2003, 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/* @test24* @bug 417531225* @summary Test StringReader.skip with negative param26*/2728import java.io.*;2930public class Skip {31public static void main( String argv[] ) throws Exception {32StringReader in = new StringReader("1234567");3334// Skip forward and read35if (in.skip(3) != 3)36throw new RuntimeException("skip(3) failed");37if (in.read() != '4')38throw new RuntimeException("post skip read failure");3940// Skip backward and read41if (in.skip(-2) != -2)42throw new RuntimeException("skip(-2) failed");43if (in.read() != '3')44throw new RuntimeException("read failed after negative skip");4546// Attempt to skip backward past the beginning and read47if (in.skip(-6) != -3)48throw new RuntimeException("skip(-6) failed");49if (in.read() != '1')50throw new RuntimeException("read after skip past beginning failed");5152// Skip beyond the end53if (in.skip(30) != 6)54throw new RuntimeException("skip(30) failed");55if (in.read() != -1)56throw new RuntimeException("read at EOF failed");5758// Test after reaching end of string59if (in.skip(30) != 0)60throw new RuntimeException("skip(30) failed");61if (in.skip(-30) != 0)62throw new RuntimeException("skip(30) failed");63}64}656667