Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 22075 invoked from network); 31 Jan 2008 10:05:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 31 Jan 2008 10:05:27 -0000 Received: (qmail 59790 invoked by uid 500); 31 Jan 2008 10:05:18 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 59766 invoked by uid 500); 31 Jan 2008 10:05:18 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 59737 invoked by uid 99); 31 Jan 2008 10:05:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 Jan 2008 02:05:18 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 Jan 2008 10:04:55 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 08BD21A9846; Thu, 31 Jan 2008 02:04:46 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r617085 [3/14] - in /harmony/enhanced/classlib/branches/java6: depends/build/ depends/build/platform/ depends/libs/ depends/oss/ make/ make/linux.x86_64.libstdc++6/ make/windows.x86/ make/windows.x86_64/ modules/archive/META-INF/ modules/ar... Date: Thu, 31 Jan 2008 10:04:22 -0000 To: commits@harmony.apache.org From: tonywu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080131100446.08BD21A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/util/TwoKeyHashMap.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/util/TwoKeyHashMap.java?rev=617085&r1=617084&r2=617085&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/util/TwoKeyHashMap.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/util/TwoKeyHashMap.java Thu Jan 31 02:04:05 2008 @@ -29,7 +29,7 @@ import java.util.Set; /** - * + * * Reductive hash with two keys * */ @@ -37,13 +37,13 @@ static final float DEFAULT_LOAD_FACTOR = 0.75f; static final int DEFAULT_INITIAL_SIZE = 16; - + private Set> entrySet; private Collection values; private int size; private int arrSize; private int modCount; - + private Entry[] arr; private float loadFactor; @@ -55,9 +55,10 @@ public TwoKeyHashMap() { this(DEFAULT_INITIAL_SIZE, DEFAULT_LOAD_FACTOR); } - + /** * Constructs an empty HashMap + * * @param initialCapacity */ public TwoKeyHashMap(int initialCapacity) { @@ -65,17 +66,19 @@ } /** - * Constructs an empty HashMap + * Constructs an empty HashMap + * * @param initialCapacity * @param initialLoadFactor */ @SuppressWarnings("unchecked") public TwoKeyHashMap(int initialCapacity, float initialLoadFactor) { - if (initialCapacity < 0) { + if (initialCapacity < 0) { throw new IllegalArgumentException("initialCapacity should be >= 0"); } if (initialLoadFactor <= 0) { - throw new IllegalArgumentException("initialLoadFactor should be > 0"); + throw new IllegalArgumentException( + "initialLoadFactor should be > 0"); } loadFactor = initialLoadFactor; if (initialCapacity == Integer.MAX_VALUE) { @@ -85,9 +88,9 @@ threshold = (int) (arrSize * loadFactor); arr = new Entry[arrSize + 1]; } - + /** - * Returns a collection view of the values + * Returns a collection view of the values */ public Collection values() { if (values == null) { @@ -95,9 +98,9 @@ } return values; } - + /** - * Returns a collection view of the mappings + * Returns a collection view of the mappings */ public Set> entrySet() { if (entrySet == null) { @@ -105,7 +108,7 @@ } return entrySet; } - + /** * Clears the map */ @@ -117,6 +120,7 @@ /** * Removes the mapping for the keys + * * @param key1 * @param key2 * @return @@ -125,9 +129,10 @@ Entry e = removeEntry(key1, key2); return null != e ? e.value : null; } - + /** * Associates the specified value with the specified keys in this map + * * @param key1 * @param key2 * @param value @@ -153,7 +158,8 @@ Entry e = arr[index]; while (e != null) { - if (hash == e.hash && key1.equals(e.getKey1()) && key2.equals(e.getKey2())) { + if (hash == e.hash && key1.equals(e.getKey1()) + && key2.equals(e.getKey2())) { V oldValue = e.value; e.value = value; return oldValue; @@ -173,7 +179,7 @@ /** * Rehash the map - * + * */ @SuppressWarnings("unchecked") void rehash() { @@ -208,10 +214,12 @@ } /** - * Returns true if this map contains a mapping for the specified keys - * @param key1 - * @param key2 - * @return + * Answers whether this map contains a mapping for the specified keys. + * + * @param key1 first key + * @param key2 second key + * @return true if this map contains a mapping for the specified keys, and + * false otherwise. */ public boolean containsKey(Object key1, Object key2) { return findEntry(key1, key2) != null; @@ -219,6 +227,7 @@ /** * Return the value by keys + * * @param key1 * @param key2 * @return @@ -239,14 +248,15 @@ } /** - * Returns the number of mappings + * Returns the number of mappings */ public int size() { return size; } - + /** - * Creates new entry + * Creates new entry + * * @param hashCode * @param key1 * @param key2 @@ -254,13 +264,14 @@ * @param next * @return */ - Entry createEntry(int hashCode, E key1, K key2, - V value, Entry next) { + Entry createEntry(int hashCode, E key1, K key2, V value, + Entry next) { return new Entry(hashCode, key1, key2, value, next); } /** * Creates entries iterator + * * @return */ Iterator> createEntrySetIterator() { @@ -269,18 +280,18 @@ /** * Creates values iterator + * * @return */ Iterator createValueCollectionIterator() { return new ValueIteratorImpl(); } - /** * Entry implementation for the TwoKeyHashMap class * */ - public static class Entry implements Map.Entry { + public static class Entry implements Map.Entry { int hash; E key1; K key2; @@ -294,7 +305,7 @@ this.value = value; this.next = next; } - + public String getKey() { return key1.toString() + key2.toString(); } @@ -302,7 +313,7 @@ public E getKey1() { return key1; } - + public K getKey2() { return key2; } @@ -326,12 +337,11 @@ Object getKey1 = e.getKey1(); Object getKey2 = e.getKey2(); Object getValue = e.getValue(); - if ((key1 == null && getKey1 != null) || - (key2 == null && getKey2 != null) || - (value == null && getValue != null) || - !key1.equals(e.getKey1()) || - !key2.equals(e.getKey2()) || - !value.equals(getValue)) { + if ((key1 == null && getKey1 != null) + || (key2 == null && getKey2 != null) + || (value == null && getValue != null) + || !key1.equals(e.getKey1()) || !key2.equals(e.getKey2()) + || !value.equals(getValue)) { return false; } return true; @@ -342,9 +352,9 @@ int hash2 = (key2 == null ? 0 : key2.hashCode()); return (hash1 + hash2) ^ (value == null ? 0 : value.hashCode()); } - + } - + class EntrySetImpl extends AbstractSet> { public int size() { return size; @@ -377,7 +387,7 @@ if (!(obj instanceof Entry)) { return false; } - return removeEntry(((Entry) obj).getKey1(), ((Entry)obj).getKey2()) != null; + return removeEntry(((Entry) obj).getKey1(), ((Entry) obj).getKey2()) != null; } public Iterator> iterator() { @@ -427,14 +437,14 @@ found = false; returned_index = curr; returned_entry = curr_entry; - return (Map.Entry)curr_entry; + return (Map.Entry) curr_entry; } public void remove() { if (returned_index == -1) { throw new IllegalStateException(); } - + if (modCount != startModCount) { throw new ConcurrentModificationException(); } @@ -456,7 +466,7 @@ returned_index = -1; } } - + private final Entry findEntry(Object key1, Object key2) { if (key1 == null && key2 == null) { return arr[arrSize]; @@ -467,14 +477,15 @@ Entry e = arr[index]; while (e != null) { - if (hash == e.hash && key1.equals(e.getKey1()) && key2.equals(e.getKey2())) { + if (hash == e.hash && key1.equals(e.getKey1()) + && key2.equals(e.getKey2())) { return e; } e = e.next; } return null; } - + // Removes entry private final Entry removeEntry(Object key1, Object key2) { if (key1 == null && key2 == null) { @@ -495,7 +506,8 @@ Entry e = arr[index]; Entry prev = e; while (e != null) { - if (hash == e.hash && key1.equals(e.getKey1()) && key2.equals(e.getKey2())) { + if (hash == e.hash && key1.equals(e.getKey1()) + && key2.equals(e.getKey2())) { if (prev == e) { arr[index] = e.next; } else { @@ -531,12 +543,12 @@ public Iterator iterator() { return createValueCollectionIterator(); } - + public boolean contains(Object obj) { return containsValue(obj); } } - + class ValueIteratorImpl implements Iterator { private EntryIteratorImpl itr; Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/luniglob.c URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/luniglob.c?rev=617085&r1=617084&r2=617085&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/luniglob.c (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/luniglob.c Thu Jan 31 02:04:05 2008 @@ -291,6 +291,7 @@ char *bootDirectory; char *propsFile; char *bootstrapClassPath = NULL; + char *currentBootstrapClassPath = NULL; vmiError rcGetProperty; jint returnCode; key_value_pair * props = NULL; @@ -347,6 +348,9 @@ goto cleanup; } + /* Save current bootstrapClassPath so we don't free it */ + currentBootstrapClassPath = bootstrapClassPath; + qsort(props, number, sizeof(key_value_pair), props_compare); for (;i < number; i++) @@ -365,7 +369,9 @@ bootstrapClassPath = str_concat (PORTLIB, bootstrapClassPath, cpSeparator, bootDirectory, props[i].value, NULL); - hymem_free_memory (oldPath); + if (oldPath != currentBootstrapClassPath) { + hymem_free_memory (oldPath); + } } if (!bootstrapClassPath) Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileDescriptorTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileDescriptorTest.java?rev=617085&r1=617084&r2=617085&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileDescriptorTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileDescriptorTest.java Thu Jan 31 02:04:05 2008 @@ -25,7 +25,9 @@ import java.io.IOException; import java.io.RandomAccessFile; -public class FileDescriptorTest extends junit.framework.TestCase { +import junit.framework.TestCase; + +public class FileDescriptorTest extends TestCase { private static String platformId = "JDK" + System.getProperty("java.vm.version").replace('.', '-'); Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java?rev=617085&r1=617084&r2=617085&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java Thu Jan 31 02:04:05 2008 @@ -1,406 +1,407 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.harmony.luni.tests.java.io; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FilePermission; -import java.io.IOException; -import java.security.Permission; - -import tests.support.Support_PlatformFile; - -public class FileInputStreamTest extends junit.framework.TestCase { - - public String fileName; - - private java.io.InputStream is; - - byte[] ibuf = new byte[4096]; - - public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_Cl assNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_ Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_Sock etException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n"; - - /** - * @tests java.io.FileInputStream#FileInputStream(java.io.File) - */ - public void test_ConstructorLjava_io_File() throws IOException { - java.io.File f = new File(fileName); - is = new FileInputStream(f); - is.close(); - } - - /** - * @tests java.io.FileInputStream#FileInputStream(java.io.FileDescriptor) - */ - public void test_ConstructorLjava_io_FileDescriptor() throws IOException { - FileOutputStream fos = new FileOutputStream(fileName); - FileInputStream fis = new FileInputStream(fos.getFD()); - fos.close(); - fis.close(); - } - - /** - * @tests java.io.FileInputStream#FileInputStream(java.lang.String) - */ - public void test_ConstructorLjava_lang_String() throws IOException { - is = new FileInputStream(fileName); - is.close(); - } - - /** - * @tests java.io.FileInputStream#available() - */ - public void test_available() throws IOException { - try { - is = new FileInputStream(fileName); - assertTrue("Returned incorrect number of available bytes", is - .available() == fileString.length()); - } finally { - try { - is.close(); - } catch (IOException e) { - } - } - } - - /** - * @tests java.io.FileInputStream#close() - */ - public void test_close() throws IOException { - is = new FileInputStream(fileName); - is.close(); - - try { - is.read(); - fail("Able to read from closed stream"); - } catch (IOException e) { - // Expected - } - } - - /** - * @tests java.io.FileInputStream#getFD() - */ - public void test_getFD() throws IOException { - FileInputStream fis = new FileInputStream(fileName); - assertTrue("Returned invalid fd", fis.getFD().valid()); - fis.close(); - assertTrue("Returned invalid fd", !fis.getFD().valid()); - } - - /** - * @tests java.io.FileInputStream#read() - */ - public void test_read() throws IOException { - is = new FileInputStream(fileName); - int c = is.read(); - is.close(); - assertTrue("read returned incorrect char", c == fileString.charAt(0)); - } - - /** - * @tests java.io.FileInputStream#read(byte[]) - */ - public void test_read$B() throws IOException { - byte[] buf1 = new byte[100]; - is = new FileInputStream(fileName); - is.skip(3000); - is.read(buf1); - is.close(); - assertTrue("Failed to read correct data", new String(buf1, 0, - buf1.length).equals(fileString.substring(3000, 3100))); - } - - /** - * @tests java.io.FileInputStream#read(byte[], int, int) - */ - public void test_read$BII() throws IOException { - byte[] buf1 = new byte[100]; - is = new FileInputStream(fileName); - is.skip(3000); - is.read(buf1, 0, buf1.length); - is.close(); - assertTrue("Failed to read correct data", new String(buf1, 0, - buf1.length).equals(fileString.substring(3000, 3100))); - - // Regression test for HARMONY-285 - File file = new File("FileInputStream.tmp"); - file.createNewFile(); - file.deleteOnExit(); - FileInputStream in = new FileInputStream(file); - try { - in.read(null, 0, 0); - fail("Should throw NullPointerException"); - } catch (NullPointerException e) { - // Expected - } finally { - in.close(); - } - } - - /** - * @tests java.io.FileInputStream#read(byte[], int, int) - */ - public void test_read_$BII_IOException() throws IOException { - byte[] buf = new byte[1000]; - try { - is = new FileInputStream(fileName); - is.read(buf, -1, 0); - fail("should throw IndexOutOfBoundsException"); - } catch (IndexOutOfBoundsException e) { - // Expected - } finally { - is.close(); - } - - try { - is = new FileInputStream(fileName); - is.read(buf, 0, -1); - fail("should throw IndexOutOfBoundsException"); - } catch (IndexOutOfBoundsException e) { - // Expected - } finally { - is.close(); - } - - try { - is = new FileInputStream(fileName); - is.read(buf, -1, -1); - fail("should throw IndexOutOfBoundsException"); - } catch (IndexOutOfBoundsException e) { - // Expected - } finally { - is.close(); - } - - try { - is = new FileInputStream(fileName); - is.read(buf, 0, 1001); - fail("should throw IndexOutOfBoundsException"); - } catch (IndexOutOfBoundsException e) { - // Expected - } finally { - is.close(); - } - - try { - is = new FileInputStream(fileName); - is.read(buf, 1001, 0); - fail("should throw IndexOutOfBoundsException"); - } catch (IndexOutOfBoundsException e) { - // Expected - } finally { - is.close(); - } - - try { - is = new FileInputStream(fileName); - is.read(buf, 500, 501); - fail("should throw IndexOutOfBoundsException"); - } catch (IndexOutOfBoundsException e) { - // Expected - } finally { - is.close(); - } - - try { - is = new FileInputStream(fileName); - is.close(); - is.read(buf, 0, 100); - fail("should throw IOException"); - } catch (IOException e) { - // Expected - } finally { - is.close(); - } - - try { - is = new FileInputStream(fileName); - is.close(); - is.read(buf, 0, 0); - } finally { - is.close(); - } - } - - /** - * @tests java.io.FileInputStream#read(byte[], int, int) - */ - public void test_read_$BII_NullPointerException() throws IOException { - byte[] buf = null; - try { - is = new FileInputStream(fileName); - is.read(buf, -1, 0); - fail("should throw NullPointerException"); - } catch (NullPointerException e) { - // Expected - } finally { - is.close(); - } - } - - /** - * @tests java.io.FileInputStream#read(byte[], int, int) - */ - public void test_read_$BII_IndexOutOfBoundsException() throws IOException { - byte[] buf = new byte[1000]; - try { - is = new FileInputStream(fileName); - is.close(); - is.read(buf, -1, -1); - fail("should throw IndexOutOfBoundsException"); - } catch (IndexOutOfBoundsException e) { - // Expected - } finally { - is.close(); - } - } - - /** - * @tests java.io.FileInputStream#skip(long) - */ - public void test_skipJ() throws IOException { - byte[] buf1 = new byte[10]; - is = new FileInputStream(fileName); - is.skip(1000); - is.read(buf1, 0, buf1.length); - is.close(); - assertTrue("Failed to skip to correct position", new String(buf1, 0, - buf1.length).equals(fileString.substring(1000, 1010))); - } - - /** - * @tests java.io.FileInputStream#read(byte[], int, int)) - */ - public void test_regressionNNN() throws IOException { - // Regression for HARMONY-434 - FileInputStream fis = new FileInputStream(fileName); - - try { - fis.read(new byte[1], -1, 1); - fail("IndexOutOfBoundsException must be thrown if off <0"); - } catch (IndexOutOfBoundsException e) { - // Expected - } - - try { - fis.read(new byte[1], 0, -1); - fail("IndexOutOfBoundsException must be thrown if len <0"); - } catch (IndexOutOfBoundsException e) { - // Expected - } - - try { - fis.read(new byte[1], 0, 5); - fail("IndexOutOfBoundsException must be thrown if off+len > b.length"); - } catch (IndexOutOfBoundsException e) { - // Expected - } - - try { - fis.read(new byte[10], Integer.MAX_VALUE, 5); - fail("IndexOutOfBoundsException expected"); - } catch (IndexOutOfBoundsException e) { - // Expected - } - - try { - fis.read(new byte[10], 5, Integer.MAX_VALUE); - fail("IndexOutOfBoundsException expected"); - } catch (IndexOutOfBoundsException e) { - // Expected - } - fis.close(); - } - - /** - * @tests java.io.FileInputStream#FileInputStream(String) - */ - public void test_Constructor_LString_WithSecurityManager() - throws IOException { - SecurityManager old = System.getSecurityManager(); - try { - MockSecurityManager msm = new MockSecurityManager(); - System.setSecurityManager(msm); - new FileInputStream((String) null); - fail("should throw SecurityException"); - } catch (SecurityException e) { - // expected - } finally { - System.setSecurityManager(old); - } - } - - /** - * @tests java.io.FileInputStream#skip(long) - */ - public void test_skipNegativeArgumentJ() throws IOException { - FileInputStream fis = new FileInputStream(fileName); - try { - fis.skip(-5); - fail("IOException must be thrown if number of bytes to skip <0"); - } catch (IOException e) { - // Expected IOException - } finally { - fis.close(); - } - } - - /** - * Sets up the fixture, for example, open a network connection. This method - * is called before a test is executed. - */ - protected void setUp() throws IOException { - fileName = System.getProperty("user.dir"); - String separator = System.getProperty("file.separator"); - if (fileName.charAt(fileName.length() - 1) == separator.charAt(0)) - fileName = Support_PlatformFile.getNewPlatformFile(fileName, - "input.tst"); - else - fileName = Support_PlatformFile.getNewPlatformFile(fileName - + separator, "input.tst"); - java.io.OutputStream fos = new java.io.FileOutputStream(fileName); - fos.write(fileString.getBytes()); - fos.close(); - } - - /** - * Tears down the fixture, for example, close a network connection. This - * method is called after a test is executed. - */ - protected void tearDown() { - new File(fileName).delete(); - } -} - -class MockSecurityManager extends SecurityManager { - public void checkPermission(Permission permission) { - if (permission instanceof FilePermission) { - if (permission.getActions().indexOf("read") == 0) - throw new SecurityException(); - } - } - - public void checkRead(String file) { - if (null == file) { - file = ""; - } - checkPermission(new FilePermission(file, "read")); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.harmony.luni.tests.java.io; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FilePermission; +import java.io.IOException; +import java.security.Permission; + +import junit.framework.TestCase; +import tests.support.Support_PlatformFile; + +public class FileInputStreamTest extends TestCase { + + public String fileName; + + private java.io.InputStream is; + + byte[] ibuf = new byte[4096]; + + public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_Cl assNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_ Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_Sock etException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n"; + + /** + * @tests java.io.FileInputStream#FileInputStream(java.io.File) + */ + public void test_ConstructorLjava_io_File() throws IOException { + java.io.File f = new File(fileName); + is = new FileInputStream(f); + is.close(); + } + + /** + * @tests java.io.FileInputStream#FileInputStream(java.io.FileDescriptor) + */ + public void test_ConstructorLjava_io_FileDescriptor() throws IOException { + FileOutputStream fos = new FileOutputStream(fileName); + FileInputStream fis = new FileInputStream(fos.getFD()); + fos.close(); + fis.close(); + } + + /** + * @tests java.io.FileInputStream#FileInputStream(java.lang.String) + */ + public void test_ConstructorLjava_lang_String() throws IOException { + is = new FileInputStream(fileName); + is.close(); + } + + /** + * @tests java.io.FileInputStream#available() + */ + public void test_available() throws IOException { + try { + is = new FileInputStream(fileName); + assertTrue("Returned incorrect number of available bytes", is + .available() == fileString.length()); + } finally { + try { + is.close(); + } catch (IOException e) { + } + } + } + + /** + * @tests java.io.FileInputStream#close() + */ + public void test_close() throws IOException { + is = new FileInputStream(fileName); + is.close(); + + try { + is.read(); + fail("Able to read from closed stream"); + } catch (IOException e) { + // Expected + } + } + + /** + * @tests java.io.FileInputStream#getFD() + */ + public void test_getFD() throws IOException { + FileInputStream fis = new FileInputStream(fileName); + assertTrue("Returned invalid fd", fis.getFD().valid()); + fis.close(); + assertTrue("Returned invalid fd", !fis.getFD().valid()); + } + + /** + * @tests java.io.FileInputStream#read() + */ + public void test_read() throws IOException { + is = new FileInputStream(fileName); + int c = is.read(); + is.close(); + assertTrue("read returned incorrect char", c == fileString.charAt(0)); + } + + /** + * @tests java.io.FileInputStream#read(byte[]) + */ + public void test_read$B() throws IOException { + byte[] buf1 = new byte[100]; + is = new FileInputStream(fileName); + is.skip(3000); + is.read(buf1); + is.close(); + assertTrue("Failed to read correct data", new String(buf1, 0, + buf1.length).equals(fileString.substring(3000, 3100))); + } + + /** + * @tests java.io.FileInputStream#read(byte[], int, int) + */ + public void test_read$BII() throws IOException { + byte[] buf1 = new byte[100]; + is = new FileInputStream(fileName); + is.skip(3000); + is.read(buf1, 0, buf1.length); + is.close(); + assertTrue("Failed to read correct data", new String(buf1, 0, + buf1.length).equals(fileString.substring(3000, 3100))); + + // Regression test for HARMONY-285 + File file = new File("FileInputStream.tmp"); + file.createNewFile(); + file.deleteOnExit(); + FileInputStream in = new FileInputStream(file); + try { + in.read(null, 0, 0); + fail("Should throw NullPointerException"); + } catch (NullPointerException e) { + // Expected + } finally { + in.close(); + } + } + + /** + * @tests java.io.FileInputStream#read(byte[], int, int) + */ + public void test_read_$BII_IOException() throws IOException { + byte[] buf = new byte[1000]; + try { + is = new FileInputStream(fileName); + is.read(buf, -1, 0); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + // Expected + } finally { + is.close(); + } + + try { + is = new FileInputStream(fileName); + is.read(buf, 0, -1); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + // Expected + } finally { + is.close(); + } + + try { + is = new FileInputStream(fileName); + is.read(buf, -1, -1); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + // Expected + } finally { + is.close(); + } + + try { + is = new FileInputStream(fileName); + is.read(buf, 0, 1001); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + // Expected + } finally { + is.close(); + } + + try { + is = new FileInputStream(fileName); + is.read(buf, 1001, 0); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + // Expected + } finally { + is.close(); + } + + try { + is = new FileInputStream(fileName); + is.read(buf, 500, 501); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + // Expected + } finally { + is.close(); + } + + try { + is = new FileInputStream(fileName); + is.close(); + is.read(buf, 0, 100); + fail("should throw IOException"); + } catch (IOException e) { + // Expected + } finally { + is.close(); + } + + try { + is = new FileInputStream(fileName); + is.close(); + is.read(buf, 0, 0); + } finally { + is.close(); + } + } + + /** + * @tests java.io.FileInputStream#read(byte[], int, int) + */ + public void test_read_$BII_NullPointerException() throws IOException { + byte[] buf = null; + try { + is = new FileInputStream(fileName); + is.read(buf, -1, 0); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // Expected + } finally { + is.close(); + } + } + + /** + * @tests java.io.FileInputStream#read(byte[], int, int) + */ + public void test_read_$BII_IndexOutOfBoundsException() throws IOException { + byte[] buf = new byte[1000]; + try { + is = new FileInputStream(fileName); + is.close(); + is.read(buf, -1, -1); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + // Expected + } finally { + is.close(); + } + } + + /** + * @tests java.io.FileInputStream#skip(long) + */ + public void test_skipJ() throws IOException { + byte[] buf1 = new byte[10]; + is = new FileInputStream(fileName); + is.skip(1000); + is.read(buf1, 0, buf1.length); + is.close(); + assertTrue("Failed to skip to correct position", new String(buf1, 0, + buf1.length).equals(fileString.substring(1000, 1010))); + } + + /** + * @tests java.io.FileInputStream#read(byte[], int, int)) + */ + public void test_regressionNNN() throws IOException { + // Regression for HARMONY-434 + FileInputStream fis = new FileInputStream(fileName); + + try { + fis.read(new byte[1], -1, 1); + fail("IndexOutOfBoundsException must be thrown if off <0"); + } catch (IndexOutOfBoundsException e) { + // Expected + } + + try { + fis.read(new byte[1], 0, -1); + fail("IndexOutOfBoundsException must be thrown if len <0"); + } catch (IndexOutOfBoundsException e) { + // Expected + } + + try { + fis.read(new byte[1], 0, 5); + fail("IndexOutOfBoundsException must be thrown if off+len > b.length"); + } catch (IndexOutOfBoundsException e) { + // Expected + } + + try { + fis.read(new byte[10], Integer.MAX_VALUE, 5); + fail("IndexOutOfBoundsException expected"); + } catch (IndexOutOfBoundsException e) { + // Expected + } + + try { + fis.read(new byte[10], 5, Integer.MAX_VALUE); + fail("IndexOutOfBoundsException expected"); + } catch (IndexOutOfBoundsException e) { + // Expected + } + fis.close(); + } + + /** + * @tests java.io.FileInputStream#FileInputStream(String) + */ + public void test_Constructor_LString_WithSecurityManager() + throws IOException { + SecurityManager old = System.getSecurityManager(); + try { + MockSecurityManager msm = new MockSecurityManager(); + System.setSecurityManager(msm); + new FileInputStream((String) null); + fail("should throw SecurityException"); + } catch (SecurityException e) { + // expected + } finally { + System.setSecurityManager(old); + } + } + + /** + * @tests java.io.FileInputStream#skip(long) + */ + public void test_skipNegativeArgumentJ() throws IOException { + FileInputStream fis = new FileInputStream(fileName); + try { + fis.skip(-5); + fail("IOException must be thrown if number of bytes to skip <0"); + } catch (IOException e) { + // Expected IOException + } finally { + fis.close(); + } + } + + /** + * Sets up the fixture, for example, open a network connection. This method + * is called before a test is executed. + */ + protected void setUp() throws IOException { + fileName = System.getProperty("user.dir"); + String separator = System.getProperty("file.separator"); + if (fileName.charAt(fileName.length() - 1) == separator.charAt(0)) + fileName = Support_PlatformFile.getNewPlatformFile(fileName, + "input.tst"); + else + fileName = Support_PlatformFile.getNewPlatformFile(fileName + + separator, "input.tst"); + java.io.OutputStream fos = new java.io.FileOutputStream(fileName); + fos.write(fileString.getBytes()); + fos.close(); + } + + /** + * Tears down the fixture, for example, close a network connection. This + * method is called after a test is executed. + */ + protected void tearDown() { + new File(fileName).delete(); + } +} + +class MockSecurityManager extends SecurityManager { + public void checkPermission(Permission permission) { + if (permission instanceof FilePermission) { + if (permission.getActions().indexOf("read") == 0) + throw new SecurityException(); + } + } + + public void checkRead(String file) { + if (null == file) { + file = ""; + } + checkPermission(new FilePermission(file, "read")); + } +} Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileNotFoundExceptionTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileNotFoundExceptionTest.java?rev=617085&r1=617084&r2=617085&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileNotFoundExceptionTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileNotFoundExceptionTest.java Thu Jan 31 02:04:05 2008 @@ -19,7 +19,9 @@ import java.io.FileNotFoundException; -public class FileNotFoundExceptionTest extends junit.framework.TestCase { +import junit.framework.TestCase; + +public class FileNotFoundExceptionTest extends TestCase { /** * @tests java.io.FileNotFoundException#FileNotFoundException() Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java?rev=617085&r1=617084&r2=617085&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java Thu Jan 31 02:04:05 2008 @@ -1,263 +1,265 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package org.apache.harmony.luni.tests.java.io; - -import java.io.File; -import java.io.FileDescriptor; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; - -public class FileOutputStreamTest extends junit.framework.TestCase { - - public String fileName; - - FileOutputStream fos; - - FileInputStream fis; - - File f; - - byte[] ibuf = new byte[4096]; - - public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_Cl assNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_ Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_Sock etException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n"; - - /** - * @tests java.io.FileOutputStream#FileOutputStream(java.io.File) - */ - public void test_ConstructorLjava_io_File() throws IOException { - f = new File(fileName = System.getProperty("user.home"), "fos.tst"); - fos = new FileOutputStream(f); - } - - /** - * @tests java.io.FileOutputStream#FileOutputStream(java.io.FileDescriptor) - */ - public void test_ConstructorLjava_io_FileDescriptor() throws IOException { - f = new File(fileName = System.getProperty("user.home"), "fos.tst"); - fileName = f.getAbsolutePath(); - fos = new FileOutputStream(fileName); - fos.write('l'); - fos.close(); - fis = new FileInputStream(fileName); - fos = new FileOutputStream(fis.getFD()); - fos.close(); - fis.close(); - } - - /** - * @tests java.io.FileOutputStream#FileOutputStream(java.lang.String) - */ - public void test_ConstructorLjava_lang_String() throws IOException { - f = new File(fileName = System.getProperty("user.home"), "fos.tst"); - fileName = f.getAbsolutePath(); - fos = new FileOutputStream(fileName); - - // Regression test for HARMONY-4012 - new FileOutputStream("nul"); - } - - /** - * @tests java.io.FileOutputStream#FileOutputStream(java.lang.String, - * boolean) - */ - public void test_ConstructorLjava_lang_StringZ() throws IOException { - f = new File(System.getProperty("user.home"), "fos.tst"); - fos = new FileOutputStream(f.getPath(), false); - fos.write("HI".getBytes(), 0, 2); - fos.close(); - fos = new FileOutputStream(f.getPath(), true); - fos.write(fileString.getBytes()); - fos.close(); - byte[] buf = new byte[fileString.length() + 2]; - fis = new FileInputStream(f.getPath()); - fis.read(buf, 0, buf.length); - assertTrue("Failed to create appending stream", new String(buf, 0, - buf.length).equals("HI" + fileString)); - } - - /** - * @tests java.io.FileOutputStream#close() - */ - public void test_close() throws IOException { - f = new File(System.getProperty("user.home"), "output.tst"); - fos = new FileOutputStream(f.getPath()); - fos.close(); - - try { - fos.write(fileString.getBytes()); - fail("Close test failed - wrote to closed stream"); - } catch (IOException e) { - // Expected - } - } - - /** - * @tests java.io.FileOutputStream#getFD() - */ - public void test_getFD() throws IOException { - f = new File(fileName = System.getProperty("user.home"), "testfd"); - fileName = f.getAbsolutePath(); - fos = new FileOutputStream(f); - assertTrue("Returned invalid fd", fos.getFD().valid()); - fos.close(); - assertTrue("Returned invalid fd", !fos.getFD().valid()); - } - - /** - * @tests java.io.FileOutputStream#write(byte[]) - */ - public void test_write$B() throws IOException { - f = new File(System.getProperty("user.home"), "output.tst"); - fos = new FileOutputStream(f.getPath()); - fos.write(fileString.getBytes()); - fis = new FileInputStream(f.getPath()); - byte rbytes[] = new byte[4000]; - fis.read(rbytes, 0, fileString.length()); - assertTrue("Incorrect string returned", new String(rbytes, 0, - fileString.length()).equals(fileString)); - } - - /** - * @tests java.io.FileOutputStream#write(byte[], int, int) - */ - public void test_write$BII() throws IOException { - f = new File(System.getProperty("user.home"), "output.tst"); - fos = new FileOutputStream(f.getPath()); - fos.write(fileString.getBytes(), 0, fileString.length()); - fis = new FileInputStream(f.getPath()); - byte rbytes[] = new byte[4000]; - fis.read(rbytes, 0, fileString.length()); - assertTrue("Incorrect bytes written", new String(rbytes, 0, fileString - .length()).equals(fileString)); - - // Regression test for HARMONY-285 - File file = new File("FileOutputStream.tmp"); - file.deleteOnExit(); - FileOutputStream out = new FileOutputStream(file); - try { - out.write(null, 0, 0); - fail("Should throw NullPointerException"); - } catch (NullPointerException e) { - // Expected - } - } - - /** - * @tests java.io.FileOutputStream#write(int) - */ - public void test_writeI() throws IOException { - f = new File(System.getProperty("user.home"), "output.tst"); - fos = new FileOutputStream(f.getPath()); - fos.write('t'); - fis = new FileInputStream(f.getPath()); - assertEquals("Incorrect char written", 't', fis.read()); - } - - /** - * @tests java.io.FileOutputStream#write(byte[], int, int) - */ - public void test_write$BII2() throws IOException { - // Regression for HARMONY-437 - f = new File(System.getProperty("user.home"), "output.tst"); - fos = new FileOutputStream(f.getPath()); - - try { - fos.write(null, 1, 1); - fail("NullPointerException must be thrown"); - } catch (NullPointerException e) { - } - - try { - fos.write(new byte[1], -1, 1); - fail("IndexOutOfBoundsException must be thrown if off <0"); - } catch (IndexOutOfBoundsException e) { - } - - try { - fos.write(new byte[1], 0, -1); - fail("IndexOutOfBoundsException must be thrown if len <0"); - } catch (IndexOutOfBoundsException e) { - } - - try { - fos.write(new byte[1], 0, 5); - fail("IndexOutOfBoundsException must be thrown if off+len > b.length"); - } catch (IndexOutOfBoundsException e) { - } - - try { - fos.write(new byte[10], Integer.MAX_VALUE, 5); - fail("IndexOutOfBoundsException expected"); - } catch (IndexOutOfBoundsException e) { - } - - try { - fos.write(new byte[10], 5, Integer.MAX_VALUE); - fail("IndexOutOfBoundsException expected"); - } catch (IndexOutOfBoundsException e) { - } - fos.close(); - } - - /** - * @tests java.io.FileOutputStream#write(byte[], int, int) - */ - public void test_write$BII3() throws IOException { - // Regression for HARMONY-834 - // no exception expected - new FileOutputStream(new FileDescriptor()).write(new byte[1], 0, 0); - } - - /** - * @tests java.io.FileOutputStream#getChannel() - */ - public void test_getChannel() throws IOException { - // Regression for HARMONY-508 - File tmpfile = File.createTempFile("FileOutputStream", "tmp"); - tmpfile.deleteOnExit(); - FileOutputStream fos = new FileOutputStream(tmpfile); - byte[] b = new byte[10]; - for (int i = 0; i < b.length; i++) { - b[i] = (byte) i; - } - fos.write(b); - fos.flush(); - fos.close(); - FileOutputStream f = new FileOutputStream(tmpfile, true); - assertEquals(10, f.getChannel().position()); - } - - /** - * Tears down the fixture, for example, close a network connection. This - * method is called after a test is executed. - */ - @Override - protected void tearDown() throws Exception { - super.tearDown(); - if (f != null) { - f.delete(); - } - if (fis != null) { - fis.close(); - } - if (fos != null) { - fos.close(); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.harmony.luni.tests.java.io; + +import java.io.File; +import java.io.FileDescriptor; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +import junit.framework.TestCase; + +public class FileOutputStreamTest extends TestCase { + + public String fileName; + + FileOutputStream fos; + + FileInputStream fis; + + File f; + + byte[] ibuf = new byte[4096]; + + public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_Cl assNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_ Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_Sock etException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n"; + + /** + * @tests java.io.FileOutputStream#FileOutputStream(java.io.File) + */ + public void test_ConstructorLjava_io_File() throws IOException { + f = new File(fileName = System.getProperty("user.home"), "fos.tst"); + fos = new FileOutputStream(f); + } + + /** + * @tests java.io.FileOutputStream#FileOutputStream(java.io.FileDescriptor) + */ + public void test_ConstructorLjava_io_FileDescriptor() throws IOException { + f = new File(fileName = System.getProperty("user.home"), "fos.tst"); + fileName = f.getAbsolutePath(); + fos = new FileOutputStream(fileName); + fos.write('l'); + fos.close(); + fis = new FileInputStream(fileName); + fos = new FileOutputStream(fis.getFD()); + fos.close(); + fis.close(); + } + + /** + * @tests java.io.FileOutputStream#FileOutputStream(java.lang.String) + */ + public void test_ConstructorLjava_lang_String() throws IOException { + f = new File(fileName = System.getProperty("user.home"), "fos.tst"); + fileName = f.getAbsolutePath(); + fos = new FileOutputStream(fileName); + + // Regression test for HARMONY-4012 + new FileOutputStream("nul"); + } + + /** + * @tests java.io.FileOutputStream#FileOutputStream(java.lang.String, + * boolean) + */ + public void test_ConstructorLjava_lang_StringZ() throws IOException { + f = new File(System.getProperty("user.home"), "fos.tst"); + fos = new FileOutputStream(f.getPath(), false); + fos.write("HI".getBytes(), 0, 2); + fos.close(); + fos = new FileOutputStream(f.getPath(), true); + fos.write(fileString.getBytes()); + fos.close(); + byte[] buf = new byte[fileString.length() + 2]; + fis = new FileInputStream(f.getPath()); + fis.read(buf, 0, buf.length); + assertTrue("Failed to create appending stream", new String(buf, 0, + buf.length).equals("HI" + fileString)); + } + + /** + * @tests java.io.FileOutputStream#close() + */ + public void test_close() throws IOException { + f = new File(System.getProperty("user.home"), "output.tst"); + fos = new FileOutputStream(f.getPath()); + fos.close(); + + try { + fos.write(fileString.getBytes()); + fail("Close test failed - wrote to closed stream"); + } catch (IOException e) { + // Expected + } + } + + /** + * @tests java.io.FileOutputStream#getFD() + */ + public void test_getFD() throws IOException { + f = new File(fileName = System.getProperty("user.home"), "testfd"); + fileName = f.getAbsolutePath(); + fos = new FileOutputStream(f); + assertTrue("Returned invalid fd", fos.getFD().valid()); + fos.close(); + assertTrue("Returned invalid fd", !fos.getFD().valid()); + } + + /** + * @tests java.io.FileOutputStream#write(byte[]) + */ + public void test_write$B() throws IOException { + f = new File(System.getProperty("user.home"), "output.tst"); + fos = new FileOutputStream(f.getPath()); + fos.write(fileString.getBytes()); + fis = new FileInputStream(f.getPath()); + byte rbytes[] = new byte[4000]; + fis.read(rbytes, 0, fileString.length()); + assertTrue("Incorrect string returned", new String(rbytes, 0, + fileString.length()).equals(fileString)); + } + + /** + * @tests java.io.FileOutputStream#write(byte[], int, int) + */ + public void test_write$BII() throws IOException { + f = new File(System.getProperty("user.home"), "output.tst"); + fos = new FileOutputStream(f.getPath()); + fos.write(fileString.getBytes(), 0, fileString.length()); + fis = new FileInputStream(f.getPath()); + byte rbytes[] = new byte[4000]; + fis.read(rbytes, 0, fileString.length()); + assertTrue("Incorrect bytes written", new String(rbytes, 0, fileString + .length()).equals(fileString)); + + // Regression test for HARMONY-285 + File file = new File("FileOutputStream.tmp"); + file.deleteOnExit(); + FileOutputStream out = new FileOutputStream(file); + try { + out.write(null, 0, 0); + fail("Should throw NullPointerException"); + } catch (NullPointerException e) { + // Expected + } + } + + /** + * @tests java.io.FileOutputStream#write(int) + */ + public void test_writeI() throws IOException { + f = new File(System.getProperty("user.home"), "output.tst"); + fos = new FileOutputStream(f.getPath()); + fos.write('t'); + fis = new FileInputStream(f.getPath()); + assertEquals("Incorrect char written", 't', fis.read()); + } + + /** + * @tests java.io.FileOutputStream#write(byte[], int, int) + */ + public void test_write$BII2() throws IOException { + // Regression for HARMONY-437 + f = new File(System.getProperty("user.home"), "output.tst"); + fos = new FileOutputStream(f.getPath()); + + try { + fos.write(null, 1, 1); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + } + + try { + fos.write(new byte[1], -1, 1); + fail("IndexOutOfBoundsException must be thrown if off <0"); + } catch (IndexOutOfBoundsException e) { + } + + try { + fos.write(new byte[1], 0, -1); + fail("IndexOutOfBoundsException must be thrown if len <0"); + } catch (IndexOutOfBoundsException e) { + } + + try { + fos.write(new byte[1], 0, 5); + fail("IndexOutOfBoundsException must be thrown if off+len > b.length"); + } catch (IndexOutOfBoundsException e) { + } + + try { + fos.write(new byte[10], Integer.MAX_VALUE, 5); + fail("IndexOutOfBoundsException expected"); + } catch (IndexOutOfBoundsException e) { + } + + try { + fos.write(new byte[10], 5, Integer.MAX_VALUE); + fail("IndexOutOfBoundsException expected"); + } catch (IndexOutOfBoundsException e) { + } + fos.close(); + } + + /** + * @tests java.io.FileOutputStream#write(byte[], int, int) + */ + public void test_write$BII3() throws IOException { + // Regression for HARMONY-834 + // no exception expected + new FileOutputStream(new FileDescriptor()).write(new byte[1], 0, 0); + } + + /** + * @tests java.io.FileOutputStream#getChannel() + */ + public void test_getChannel() throws IOException { + // Regression for HARMONY-508 + File tmpfile = File.createTempFile("FileOutputStream", "tmp"); + tmpfile.deleteOnExit(); + FileOutputStream fos = new FileOutputStream(tmpfile); + byte[] b = new byte[10]; + for (int i = 0; i < b.length; i++) { + b[i] = (byte) i; + } + fos.write(b); + fos.flush(); + fos.close(); + FileOutputStream f = new FileOutputStream(tmpfile, true); + assertEquals(10, f.getChannel().position()); + } + + /** + * Tears down the fixture, for example, close a network connection. This + * method is called after a test is executed. + */ + @Override + protected void tearDown() throws Exception { + super.tearDown(); + if (f != null) { + f.delete(); + } + if (fis != null) { + fis.close(); + } + if (fos != null) { + fos.close(); + } + } +}