harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r386058 [6/49] - in /incubator/harmony/enhanced/classlib/trunk: make/ modules/archive/make/common/ modules/archive/src/test/java/tests/ modules/archive/src/test/java/tests/api/ modules/archive/src/test/java/tests/api/java/ modules/archive/s...
Date Wed, 15 Mar 2006 11:47:39 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileInputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileInputStreamTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileInputStreamTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileInputStreamTest.java
Wed Mar 15 03:46:17 2006
@@ -0,0 +1,244 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 tests.api.java.io;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+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_Class
 NotFoundException\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_Obj
 ect\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_SocketE
 xception\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() {
+		// Test for method java.io.FileInputStream(java.io.File)
+		try {
+			java.io.File f = new java.io.File(fileName);
+			is = new java.io.FileInputStream(f);
+			is.close();
+		} catch (Exception e) {
+			fail("Failed to create FileInputStream : " + e.getMessage());
+		}
+
+	}
+
+	/**
+	 * @tests java.io.FileInputStream#FileInputStream(java.io.FileDescriptor)
+	 */
+	public void test_ConstructorLjava_io_FileDescriptor() {
+		// Test for method java.io.FileInputStream(java.io.FileDescriptor)
+		try {
+			FileOutputStream fos = new FileOutputStream(fileName);
+			FileInputStream fis = new FileInputStream(fos.getFD());
+			fos.close();
+			fis.close();
+		} catch (Exception e) {
+			fail("Exception during constrcutor test: " + e.toString());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileInputStream#FileInputStream(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.io.FileInputStream(java.lang.String)
+		try {
+			is = new java.io.FileInputStream(fileName);
+			is.close();
+		} catch (Exception e) {
+			fail("Failed to create FileInputStream : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileInputStream#available()
+	 */
+	public void test_available() {
+		// Test for method int java.io.FileInputStream.available()
+		try {
+			is = new java.io.FileInputStream(fileName);
+			assertTrue("Returned incorrect number of available bytes", is
+					.available() == fileString.length());
+		} catch (Exception e) {
+			fail("Exception during available test : " + e.getMessage());
+		} finally {
+			try {
+				is.close();
+			} catch (java.io.IOException e) {
+			}
+		}
+	}
+
+	/**
+	 * @tests java.io.FileInputStream#close()
+	 */
+	public void test_close() {
+		// Test for method void java.io.FileInputStream.close()
+
+		try {
+			is = new java.io.FileInputStream(fileName);
+			is.close();
+		} catch (java.io.IOException e) {
+			fail("Exception attempting to close stream : " + e.getMessage());
+		}
+		;
+
+		try {
+			is.read();
+		} catch (java.io.IOException e) {
+			return;
+		}
+		fail("Able to read from closed stream");
+	}
+
+	/**
+	 * @tests java.io.FileInputStream#getFD()
+	 */
+	public void test_getFD() {
+		// Test for method java.io.FileDescriptor
+		// java.io.FileInputStream.getFD()
+		try {
+
+			FileInputStream fis = new FileInputStream(fileName);
+			assertTrue("Returned invalid fd", fis.getFD().valid());
+			fis.close();
+			assertTrue("Returned invalid fd", !fis.getFD().valid());
+		} catch (FileNotFoundException e) {
+			fail("Could not find : " + fileName);
+		}
+
+		catch (IOException e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileInputStream#read()
+	 */
+	public void test_read() {
+		// Test for method int java.io.FileInputStream.read()
+		try {
+			is = new java.io.FileInputStream(fileName);
+			int c = is.read();
+			is.close();
+			assertTrue("read returned incorrect char", c == fileString
+					.charAt(0));
+		} catch (Exception e) {
+			fail("Exception during read test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileInputStream#read(byte[])
+	 */
+	public void test_read$B() {
+		// Test for method int java.io.FileInputStream.read(byte [])
+		byte[] buf1 = new byte[100];
+		try {
+			is = new java.io.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)));
+
+		} catch (Exception e) {
+			fail("Exception during read test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileInputStream#read(byte[], int, int)
+	 */
+	public void test_read$BII() {
+		// Test for method int java.io.FileInputStream.read(byte [], int, int)
+		byte[] buf1 = new byte[100];
+		try {
+			is = new java.io.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)));
+
+		} catch (Exception e) {
+			fail("Exception during read test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileInputStream#skip(long)
+	 */
+	public void test_skipJ() {
+		// Test for method long java.io.FileInputStream.skip(long)
+		byte[] buf1 = new byte[10];
+		try {
+			is = new java.io.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)));
+		} catch (Exception e) {
+			fail("Exception during skip test " + e.getMessage());
+		}
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		try {
+			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();
+		} catch (java.io.IOException e) {
+			System.out.println("Exception during setup");
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * 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();
+
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileNotFoundExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileNotFoundExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileNotFoundExceptionTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileNotFoundExceptionTest.java
Wed Mar 15 03:46:17 2006
@@ -0,0 +1,59 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 tests.api.java.io;
+
+public class FileNotFoundExceptionTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.io.FileNotFoundException#FileNotFoundException()
+	 */
+	public void test_Constructor() {
+		// Test for method java.io.FileNotFoundException()
+		try {
+			new java.io.FileInputStream("9://0//l");
+		} catch (java.io.FileNotFoundException e) {
+			return;
+		}
+		fail("Failed to generate Exception");
+	}
+
+	/**
+	 * @tests java.io.FileNotFoundException#FileNotFoundException(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.io.FileNotFoundException(java.lang.String)
+		try {
+			new java.io.FileInputStream("9://0//l");
+		} catch (java.io.FileNotFoundException e) {
+			return;
+		}
+		fail("Failed to generate Exception");
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java
Wed Mar 15 03:46:17 2006
@@ -0,0 +1,227 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 tests.api.java.io;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class FileOutputStreamTest extends junit.framework.TestCase {
+
+	public String fileName;
+
+	private java.io.InputStream is;
+
+	java.io.FileOutputStream fos;
+
+	java.io.FileInputStream fis;
+
+	java.io.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_Class
 NotFoundException\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_Obj
 ect\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_SocketE
 xception\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() {
+		// Test for method java.io.FileOutputStream(java.io.File)
+		try {
+			f = new File(fileName = System.getProperty("user.home"), "fos.tst");
+			fos = new java.io.FileOutputStream(f);
+		} catch (java.io.IOException e) {
+			fail("Exception during Constructor test" + e.toString());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileOutputStream#FileOutputStream(java.io.FileDescriptor)
+	 */
+	public void test_ConstructorLjava_io_FileDescriptor() {
+		// Test for method java.io.FileOutputStream(java.io.FileDescriptor)
+		try {
+			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();
+		} catch (Exception e) {
+			fail("Exception during constrcutor test: " + e.toString());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileOutputStream#FileOutputStream(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.io.FileOutputStream(java.lang.String)
+		try {
+			f = new File(fileName = System.getProperty("user.home"), "fos.tst");
+			fileName = f.getAbsolutePath();
+			fos = new java.io.FileOutputStream(f);
+		} catch (java.io.IOException e) {
+			fail("Exception during Constructor test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileOutputStream#FileOutputStream(java.lang.String,
+	 *        boolean)
+	 */
+	public void test_ConstructorLjava_lang_StringZ() {
+		// Test for method java.io.FileOutputStream(java.lang.String, boolean)
+		try {
+			f = new java.io.File(System.getProperty("user.home"), "fos.tst");
+			fos = new java.io.FileOutputStream(f.getPath(), false);
+			fos.write("HI".getBytes(), 0, 2);
+			fos.close();
+			fos = new java.io.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));
+		} catch (java.io.IOException e) {
+			fail("Exception during Constructor test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileOutputStream#close()
+	 */
+	public void test_close() {
+		// Test for method void java.io.FileOutputStream.close()
+
+		try {
+			f = new java.io.File(System.getProperty("user.home"), "output.tst");
+			fos = new java.io.FileOutputStream(f.getPath());
+			fos.close();
+			fos.write(fileString.getBytes());
+			fail("Close test failed - wrote to closed stream");
+		} catch (java.io.IOException e) {
+			// correct
+		}
+
+	}
+
+	/**
+	 * @tests java.io.FileOutputStream#getFD()
+	 */
+	public void test_getFD() {
+		// Test for method java.io.FileDescriptor
+		// java.io.FileOutputStream.getFD()
+		try {
+			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());
+		} catch (FileNotFoundException e) {
+			fail("Could not find : " + fileName);
+		} catch (IOException e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileOutputStream#write(byte[])
+	 */
+	public void test_write$B() {
+		// Test for method void java.io.FileOutputStream.write(byte [])
+		try {
+			f = new java.io.File(System.getProperty("user.home"), "output.tst");
+			fos = new java.io.FileOutputStream(f.getPath());
+			fos.write(fileString.getBytes());
+			fis = new java.io.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));
+		} catch (java.io.IOException e) {
+			fail("Exception during write test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileOutputStream#write(byte[], int, int)
+	 */
+	public void test_write$BII() {
+		// Test for method void java.io.FileOutputStream.write(byte [], int,
+		// int)
+		try {
+			f = new java.io.File(System.getProperty("user.home"), "output.tst");
+			fos = new java.io.FileOutputStream(f.getPath());
+			fos.write(fileString.getBytes(), 0, fileString.length());
+			fis = new java.io.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));
+		} catch (java.io.IOException e) {
+			fail("Exception during write test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileOutputStream#write(int)
+	 */
+	public void test_writeI() {
+		// Test for method void java.io.FileOutputStream.write(int)
+		try {
+			f = new java.io.File(System.getProperty("user.home"), "output.tst");
+			fos = new java.io.FileOutputStream(f.getPath());
+			fos.write('t');
+			fis = new java.io.FileInputStream(f.getPath());
+			assertTrue("Incorrect char written", fis.read() == 't');
+		} catch (java.io.IOException e) {
+			fail("Exception during write test : " + e.getMessage());
+		}
+
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+		try {
+			if (f != null)
+				f.delete();
+			if (fis != null)
+				fis.close();
+			if (fos != null)
+				fos.close();
+		} catch (Exception e) {
+		}
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilePermissionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilePermissionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilePermissionTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilePermissionTest.java
Wed Mar 15 03:46:17 2006
@@ -0,0 +1,198 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 tests.api.java.io;
+
+import java.io.File;
+import java.io.FilePermission;
+import java.security.PermissionCollection;
+
+public class FilePermissionTest extends junit.framework.TestCase {
+
+	FilePermission readAllFiles = new FilePermission("<<ALL FILES>>", "read");
+
+	FilePermission alsoReadAllFiles = new FilePermission("<<ALL FILES>>",
+			"read");
+
+	FilePermission allInCurrent = new FilePermission("*",
+			"read, write, execute,delete");
+
+	FilePermission readInCurrent = new FilePermission("*", "read");
+
+	FilePermission readInFile = new FilePermission("aFile.file", "read");
+
+	/**
+	 * @tests java.io.FilePermission#FilePermission(java.lang.String,
+	 *        java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_StringLjava_lang_String() {
+		// Test for method java.io.FilePermission(java.lang.String,
+		// java.lang.String)
+		assertTrue("Used to test", true);
+		FilePermission constructFile = new FilePermission("test constructor",
+				"write");
+		assertTrue(
+				"action given to the constructor did not correspond - constructor failed",
+				constructFile.getActions().equals("write"));
+		assertTrue(
+				"name given to the construcotr did not correspond - construcotr failed",
+				constructFile.getName() == "test constructor");
+
+	}
+
+	/**
+	 * @tests java.io.FilePermission#getActions()
+	 */
+	public void test_getActions() {
+		// Test for method java.lang.String java.io.FilePermission.getActions()
+		assertTrue("getActions should have returned only read", readAllFiles
+				.getActions().equals("read"));
+		assertTrue("getActions should have returned all actions", allInCurrent
+				.getActions().equals("read,write,execute,delete"));
+	}
+
+	/**
+	 * @tests java.io.FilePermission#equals(java.lang.Object)
+	 */
+	public void test_equalsLjava_lang_Object() {
+		// test for method java.io.FilePermission.equals()
+		assertTrue(
+				"returned false when two instance of FilePermission is equal",
+				readAllFiles.equals(alsoReadAllFiles));
+		assertTrue(
+				"returned true when two instance	of FilePermission is not equal",
+				!(readInCurrent.equals(readInFile)));
+	}
+
+	/**
+	 * @tests java.io.FilePermission#implies(java.security.Permission)
+	 */
+	public void test_impliesLjava_security_Permission() {
+		// Test for method boolean
+		// java.io.FilePermission.implies(java.security.Permission)
+		assertTrue("Returned true for non-subset of actions", !readAllFiles
+				.implies(allInCurrent));
+		assertTrue("Returned true for non-subset of files", !allInCurrent
+				.implies(readAllFiles));
+		assertTrue("Returned false for subset of actions", allInCurrent
+				.implies(readInCurrent));
+		assertTrue("Returned false for subset of files", readAllFiles
+				.implies(readInCurrent));
+		assertTrue("Returned false for subset of files and actions",
+				allInCurrent.implies(readInFile));
+		assertTrue("Returned false for equal FilePermissions", readAllFiles
+				.implies(alsoReadAllFiles));
+
+		FilePermission fp3 = new FilePermission("/bob/*".replace('/',
+				File.separatorChar), "read,write");
+		FilePermission fp4 = new FilePermission("/bob/".replace('/',
+				File.separatorChar), "write");
+		assertTrue("returned true for same dir using * and not *", !fp3
+				.implies(fp4));
+		FilePermission fp5 = new FilePermission("/bob/file".replace('/',
+				File.separatorChar), "write");
+		assertTrue("returned false for same dir using * and file", fp3
+				.implies(fp5));
+
+		FilePermission fp6 = new FilePermission("/bob/".replace('/',
+				File.separatorChar), "read,write");
+		FilePermission fp7 = new FilePermission("/bob/*".replace('/',
+				File.separatorChar), "write");
+		assertTrue("returned false for same dir using not * and *", !fp6
+				.implies(fp7));
+		assertTrue("returned false for same subdir", fp6.implies(fp4));
+
+		FilePermission fp8 = new FilePermission("/".replace('/',
+				File.separatorChar), "read,write");
+		FilePermission fp9 = new FilePermission("/".replace('/',
+				File.separatorChar), "write");
+		assertTrue("returned false for same dir", fp8.implies(fp9));
+
+		FilePermission fp10 = new FilePermission("/".replace('/',
+				File.separatorChar), "read,write");
+		FilePermission fp11 = new FilePermission("/".replace('/',
+				File.separatorChar), "write");
+		assertTrue("returned false for same dir", fp10.implies(fp11));
+
+		FilePermission fp12 = new FilePermission("/*".replace('/',
+				File.separatorChar), "read,write");
+		assertTrue("returned false for same dir using * and dir", !fp12
+				.implies(fp10));
+	}
+
+	/**
+	 * @tests java.io.FilePermission#newPermissionCollection()
+	 */
+	public void test_newPermissionCollection() {
+		// test for method java.io.FilePermission.newPermissionCollection
+		char s = File.separatorChar;
+		FilePermission perm[] = new FilePermission[4];
+		perm[0] = readAllFiles;
+		perm[1] = allInCurrent;
+		perm[2] = new FilePermission(s + "tmp" + s + "test" + s + "*",
+				"read,write");
+		perm[3] = new FilePermission(s + "tmp" + s + "test" + s
+				+ "collection.file", "read");
+
+		PermissionCollection collect = perm[0].newPermissionCollection();
+		for (int i = 0; i < perm.length; i++) {
+			collect.add(perm[i]);
+		}
+		assertTrue("returned false for subset of files", collect
+				.implies(new FilePermission("*", "write")));
+		assertTrue("returned false for subset of name and action", collect
+				.implies(new FilePermission(s + "tmp", "read")));
+		assertTrue("returned true for non subset of file and action", collect
+				.implies(readInFile));
+
+		FilePermission fp1 = new FilePermission("/tmp/-".replace('/',
+				File.separatorChar), "read");
+		PermissionCollection fpc = fp1.newPermissionCollection();
+		fpc.add(fp1);
+		fpc.add(new FilePermission("/tmp/scratch/foo/*".replace('/',
+				File.separatorChar), "write"));
+		FilePermission fp2 = new FilePermission("/tmp/scratch/foo/file"
+				.replace('/', File.separatorChar), "read,write");
+		assertTrue("collection does not collate", fpc.implies(fp2));
+	}
+
+	/**
+	 * @tests java.io.FilePermission#hashCode()
+	 */
+	public void test_hashCode() {
+		// test method java.io.FilePermission.hasCode()
+		assertTrue(
+				"two equal filePermission instances returned different hashCode",
+				readAllFiles.hashCode() == alsoReadAllFiles.hashCode());
+		assertTrue(
+				"two filePermission instances with same permission name returned same hashCode",
+				readInCurrent.hashCode() != allInCurrent.hashCode());
+
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileReaderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileReaderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileReaderTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileReaderTest.java
Wed Mar 15 03:46:17 2006
@@ -0,0 +1,130 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 tests.api.java.io;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+
+public class FileReaderTest extends junit.framework.TestCase {
+
+	FileReader br;
+
+	BufferedWriter bw;
+
+	FileInputStream fis;
+
+	File f;
+
+	/**
+	 * @tests java.io.FileReader#FileReader(java.io.File)
+	 */
+	public void test_ConstructorLjava_io_File() {
+		// Test for method java.io.FileReader(java.io.File)
+		try {
+			bw = new BufferedWriter(new FileWriter(f.getPath()));
+			bw.write(" After test string", 0, 18);
+			bw.close();
+			br = new FileReader(f);
+			char[] buf = new char[100];
+			int r = br.read(buf);
+			br.close();
+			assertTrue("Failed to read correct chars", new String(buf, 0, r)
+					.equals(" After test string"));
+		} catch (Exception e) {
+			fail("Exception during Constructor test " + e.toString());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileReader#FileReader(java.io.FileDescriptor)
+	 */
+	public void test_ConstructorLjava_io_FileDescriptor() {
+		// Test for method java.io.FileReader(java.io.FileDescriptor)
+		try {
+			bw = new BufferedWriter(new FileWriter(f.getPath()));
+			bw.write(" After test string", 0, 18);
+			bw.close();
+			FileInputStream fis = new FileInputStream(f.getPath());
+			br = new FileReader(fis.getFD());
+			char[] buf = new char[100];
+			int r = br.read(buf);
+			br.close();
+			fis.close();
+			assertTrue("Failed to read correct chars", new String(buf, 0, r)
+					.equals(" After test string"));
+		} catch (Exception e) {
+			fail("Exception during Constructor test " + e.toString());
+		}
+	}
+
+	/**
+	 * @tests java.io.FileReader#FileReader(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.io.FileReader(java.lang.String)
+		try {
+			bw = new BufferedWriter(new FileWriter(f.getPath()));
+			bw.write(" After test string", 0, 18);
+			bw.close();
+			br = new FileReader(f.getPath());
+			char[] buf = new char[100];
+			int r = br.read(buf);
+			br.close();
+			assertTrue("Failed to read correct chars", new String(buf, 0, r)
+					.equals(" After test string"));
+		} catch (Exception e) {
+			fail("Exception during Constructor test " + e.toString());
+		}
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+
+		f = new File(System.getProperty("user.home"), "reader.tst");
+
+		if (f.exists()) {
+			if (!f.delete()) {
+				fail("Unable to delete test file");
+			}
+		}
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+
+		try {
+			bw.close();
+			br.close();
+		} catch (Exception e) {
+		}
+
+		try {
+			if (fis != null)
+				fis.close();
+		} catch (Exception e) {
+		}
+		f.delete();
+	}
+}



Mime
View raw message