tests/libjava-mauve/src/gnu/testlet/java/nio/channels/Channels/ChannelsTest.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Tags: JDK1.4
       
     2 
       
     3 // Copyright (C) 2004 Michael Koch <konqueror@gmx.de>
       
     4 
       
     5 // This file is part of Mauve.
       
     6 
       
     7 // Mauve is free software; you can redistribute it and/or modify
       
     8 // it under the terms of the GNU General Public License as published by
       
     9 // the Free Software Foundation; either version 2, or (at your option)
       
    10 // any later version.
       
    11 
       
    12 // Mauve is distributed in the hope that it will be useful,
       
    13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    15 // GNU General Public License for more details.
       
    16 
       
    17 // You should have received a copy of the GNU General Public License
       
    18 // along with Mauve; see the file COPYING.  If not, write to
       
    19 // the Free Software Foundation, 59 Temple Place - Suite 330,
       
    20 // Boston, MA 02111-1307, USA.
       
    21 
       
    22 
       
    23 package gnu.testlet.java.nio.channels.Channels;
       
    24 
       
    25 import gnu.testlet.Testlet;
       
    26 import gnu.testlet.TestHarness;
       
    27 
       
    28 import java.io.*;
       
    29 import java.nio.*;
       
    30 import java.nio.channels.*;
       
    31 
       
    32 public class ChannelsTest implements Testlet
       
    33 {
       
    34   class ByteArrayChannel
       
    35     implements ReadableByteChannel, WritableByteChannel
       
    36   {
       
    37     public ByteArrayChannel()
       
    38     {
       
    39     }
       
    40 
       
    41     public boolean isOpen()
       
    42     {
       
    43       return true;
       
    44     }
       
    45 
       
    46     public void close() throws IOException
       
    47     {
       
    48     }
       
    49     
       
    50     public int read(ByteBuffer dst) throws IOException
       
    51     {
       
    52       return 0;
       
    53     }
       
    54 
       
    55     public int write(ByteBuffer src) throws IOException
       
    56     {
       
    57       return 0;
       
    58     }
       
    59   }
       
    60   
       
    61   public void test(TestHarness h)
       
    62   {
       
    63     String tmpfile = h.getTempDirectory() + File.separator + "mauve-channels.tst";
       
    64 
       
    65     File f = new File(tmpfile);
       
    66 
       
    67     try
       
    68       {
       
    69 	RandomAccessFile raf = new RandomAccessFile(f, "rw");
       
    70 	FileChannel fch = raf.getChannel();
       
    71 
       
    72 	ByteArrayChannel bac = new ByteArrayChannel();
       
    73     
       
    74 	h.checkPoint("newInputStream");
       
    75     
       
    76 	InputStream in;
       
    77     
       
    78 	in = Channels.newInputStream(bac);
       
    79 	h.check(in != null);
       
    80     
       
    81 	in = Channels.newInputStream(fch);
       
    82 	h.check(in != null);
       
    83 
       
    84 	h.checkPoint("newOutputStream");
       
    85 
       
    86 	OutputStream out;
       
    87 
       
    88 	out = Channels.newOutputStream(bac);
       
    89 	h.check(out != null);
       
    90 
       
    91 	out = Channels.newOutputStream(fch);
       
    92 	h.check(out != null);
       
    93       }
       
    94     catch (FileNotFoundException e)
       
    95       {
       
    96 	h.debug(e);
       
    97 	h.fail("cannot create temporary file");
       
    98       }
       
    99     finally
       
   100       {
       
   101 	f.delete();
       
   102       }
       
   103   }
       
   104 }