harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r765517 - in /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io: FileInputStreamTest.java FileOutputStreamTest.java
Date Thu, 16 Apr 2009 08:52:03 GMT
Author: regisxu
Date: Thu Apr 16 08:52:03 2009
New Revision: 765517

URL: http://svn.apache.org/viewvc?rev=765517&view=rev
Log:
Apply patch for HARMONY-6135: [classlib][luni] Add new testcases on getChannel method of FileInputStream
and FileOutputStream

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java?rev=765517&r1=765516&r2=765517&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileInputStreamTest.java
Thu Apr 16 08:52:03 2009
@@ -364,6 +364,40 @@
         }
     }
 
+    public void test_getChannel() throws Exception {
+        FileInputStream fis = new FileInputStream(fileName);
+        assertEquals(0, fis.getChannel().position());
+        int r;
+        int count = 1;
+        while((r = fis.read()) != -1) {
+            assertEquals(count++, fis.getChannel().position());
+        }
+        fis.close();
+        
+        try {
+            fis.getChannel().position();
+            fail("should throw ClosedChannelException");
+        } catch(java.nio.channels.ClosedChannelException e){
+            // Expected
+        }
+        
+        fis = new FileInputStream(fileName);
+        assertEquals(0, fis.getChannel().position());
+        byte[] bs = new byte[10];
+        r = fis.read(bs);
+        assertEquals(10, fis.getChannel().position());
+        fis.close();
+        
+        fis = new FileInputStream(fileName);
+        assertEquals(0, fis.getChannel().position());
+        bs = new byte[10];
+        fis.skip(100);
+        assertEquals(100, fis.getChannel().position());
+        r = fis.read(bs);
+        assertEquals(110, fis.getChannel().position());
+        fis.close();
+    }
+
     /**
      * Sets up the fixture, for example, open a network connection. This method
      * is called before a test is executed.

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java?rev=765517&r1=765516&r2=765517&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileOutputStreamTest.java
Thu Apr 16 08:52:03 2009
@@ -39,6 +39,8 @@
 
     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";
 
+    byte[] bytes;
+
     /**
      * @tests java.io.FileOutputStream#FileOutputStream(java.io.File)
      */
@@ -237,17 +239,118 @@
         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.write(bytes);
         fos.flush();
         fos.close();
         FileOutputStream f = new FileOutputStream(tmpfile, true);
         assertEquals(10, f.getChannel().position());
     }
 
+    public void test_getChannel_Append() throws IOException {
+        File tmpfile = File.createTempFile("FileOutputStream", "tmp");
+        tmpfile.deleteOnExit();
+        FileOutputStream fos = new FileOutputStream(tmpfile, true);
+        assertEquals(0, fos.getChannel().position());
+        fos.write(bytes);
+        assertEquals(10, fos.getChannel().position());
+        fos.write(bytes);
+        assertEquals(20, fos.getChannel().position());
+        fos.write(bytes);
+        assertEquals(30, fos.getChannel().position());
+        fos.close();
+
+        try {
+            fos.getChannel().position();
+            fail("should throw ClosedChannelException");
+        } catch (java.nio.channels.ClosedChannelException e){
+            // Expected
+        }
+    }
+
+    public void test_getChannel_UnAppend() throws IOException {
+        File tmpfile = File.createTempFile("FileOutputStream", "tmp");
+        tmpfile.deleteOnExit();
+        FileOutputStream fos = new FileOutputStream(tmpfile, false);
+        assertEquals(0, fos.getChannel().position());
+        fos.write(bytes);
+        assertEquals(10, fos.getChannel().position());
+        fos.write(bytes);
+        assertEquals(20, fos.getChannel().position());
+        fos.write(bytes);
+        assertEquals(30, fos.getChannel().position());
+        fos.close();
+
+        try {
+            fos.getChannel().position();
+            fail("should throw ClosedChannelException");
+        } catch (java.nio.channels.ClosedChannelException e){
+            // Expected
+        }
+    }
+
+    public void test_getChannel_Unappend_Unappend() throws IOException {
+        File tmpfile = File.createTempFile("FileOutputStream", "tmp");
+        tmpfile.deleteOnExit();
+        FileOutputStream fos = new FileOutputStream(tmpfile, false);
+        assertEquals(0, fos.getChannel().position());
+        fos.write(bytes);
+        assertEquals(10, fos.getChannel().position());
+        fos.close();
+
+        fos = new FileOutputStream(tmpfile, false);
+        assertEquals(0, fos.getChannel().position());
+        fos.close();
+    }
+
+    public void test_getChannel_Unappend_Append() throws IOException {
+        File tmpfile = File.createTempFile("FileOutputStream", "tmp");
+        tmpfile.deleteOnExit();
+        FileOutputStream fos = new FileOutputStream(tmpfile, false);
+        assertEquals(0, fos.getChannel().position());
+        fos.write(bytes);
+        assertEquals(10, fos.getChannel().position());
+        fos.close();
+
+        fos = new FileOutputStream(tmpfile, true);
+        assertEquals(10, fos.getChannel().position());
+        fos.close();
+    }
+
+    public void test_getChannel_Append_Unappend() throws IOException {
+        File tmpfile = File.createTempFile("FileOutputStream", "tmp");
+        tmpfile.deleteOnExit();
+        FileOutputStream fos = new FileOutputStream(tmpfile, true);
+        assertEquals(0, fos.getChannel().position());
+        fos.write(bytes);
+        assertEquals(10, fos.getChannel().position());
+        fos.close();
+        
+        fos = new FileOutputStream(tmpfile, false);
+        assertEquals(0, fos.getChannel().position());
+        fos.close();
+    }
+
+    public void test_getChanne_Append_Append() throws IOException {
+        File tmpfile = File.createTempFile("FileOutputStream", "tmp");
+        tmpfile.deleteOnExit();
+        FileOutputStream fos = new FileOutputStream(tmpfile, true);
+        assertEquals(0, fos.getChannel().position());
+        fos.write(bytes);
+        assertEquals(10, fos.getChannel().position());
+        fos.close();
+        
+        fos = new FileOutputStream(tmpfile, true);
+        assertEquals(10, fos.getChannel().position());
+        fos.close();
+    }
+
+    protected void setUp() {
+        bytes = new byte[10];
+        for (int i = 0; i < bytes.length; i++) {
+            bytes[i] = (byte) i;
+        }
+    }
+
     /**
      * Tears down the fixture, for example, close a network connection. This
      * method is called after a test is executed.



Mime
View raw message