Path: blob/master/test/jdk/java/io/Reader/ReadIntoZeroLengthArray.java
41149 views
/*1* Copyright (c) 2020, 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*/2223import java.io.CharArrayReader;24import java.io.File;25import java.io.FileReader;26import java.io.IOException;27import java.io.LineNumberReader;28import java.io.PushbackReader;29import java.io.Reader;30import java.io.StringReader;31import org.testng.Assert;32import org.testng.annotations.AfterTest;33import org.testng.annotations.BeforeTest;34import org.testng.annotations.DataProvider;35import org.testng.annotations.Test;3637/*38* @test39* @bug 824838340* @summary Ensure that zero is returned for read into zero length array41* @run testng ReadIntoZeroLengthArray42*/43public class ReadIntoZeroLengthArray {44private File file;4546private char[] cbuf0;47private char[] cbuf1;4849@BeforeTest50public void setup() throws IOException {51file = File.createTempFile("foo", "bar", new File("."));52cbuf0 = new char[0];53cbuf1 = new char[1];54}5556@AfterTest57public void teardown() throws IOException {58file.delete();59}6061@DataProvider(name = "readers")62public Object[][] getReaders() throws IOException {63Reader fileReader = new FileReader(file);64return new Object[][] {65{new LineNumberReader(fileReader)},66{new CharArrayReader(new char[] {27})},67{new PushbackReader(fileReader)},68{fileReader},69{new StringReader(new String(new byte[] {(byte)42}))}70};71}7273@Test(dataProvider = "readers")74void test0(Reader r) throws IOException {75Assert.assertEquals(r.read(cbuf0), 0);76}7778@Test(dataProvider = "readers")79void test1(Reader r) throws IOException {80Assert.assertEquals(r.read(cbuf1, 0, 0), 0);81}82}838485