OSDN Git Service

am ac02d18: am 2de2459: AI 148670: More tests that need to be marked bro
authorJorg Pleumann <nobody@android.com>
Mon, 11 May 2009 17:16:41 +0000 (10:16 -0700)
committerThe Android Open Source Project <initial-contribution@android.com>
Mon, 11 May 2009 17:16:41 +0000 (10:16 -0700)
Merge commit 'ac02d185cf7f5b494c621ca67a4d786348deac3a'

* commit 'ac02d185cf7f5b494c621ca67a4d786348deac3a':
  AI 148670: More tests that need to be marked broken, since

1  2 
libcore/nio/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java

@@@ -22,14 -22,13 +22,15 @@@ import dalvik.annotation.TestTargetNew
  import dalvik.annotation.TestTargetClass;
  import dalvik.annotation.TestLevel;
  import dalvik.annotation.AndroidOnly;
+ import dalvik.annotation.BrokenTest;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.net.BindException;
  import java.net.ConnectException;
 +import java.net.Inet4Address;
 +import java.net.InetAddress;
  import java.net.InetSocketAddress;
  import java.net.ServerSocket;
  import java.net.Socket;
@@@ -2671,6 -2670,7 +2672,7 @@@ public class SocketChannelTest extends 
          method = "write",
          args = {java.nio.ByteBuffer.class}
      )
+     @BrokenTest("Occasionally fail in CTS, but works in CoreTestRunner")
      public void test_writeLjava_nio_ByteBuffer_Nonblocking_HugeData() throws IOException {
          // initialize write content
          ByteBuffer writeContent = ByteBuffer.allocate(CAPACITY_HUGE);
          }
      }
  
 +    /**
 +     * @throws IOException 
 +     * @tests java.nio.channels.SocketChannel#read(ByteBuffer)
 +     */
 +    @TestTargetNew(
 +        level = TestLevel.PARTIAL_COMPLETE,
 +        notes = "",
 +        method = "read",
 +        args = {java.nio.ByteBuffer[].class}
 +    ) 
 +    public void test_socketChannel_read_DirectByteBuffer() throws InterruptedException, IOException {
 +
 +        ServerThread server = new ServerThread();
 +        server.start();
 +        Thread.currentThread().sleep(1000);
 +
 +        InetSocketAddress address = new InetSocketAddress(InetAddress
 +                .getByName("localhost"), port);
 +
 +        // First test with array based byte buffer
 +        SocketChannel sc = SocketChannel.open();
 +        sc.connect(address);
 +
 +        ByteBuffer buf = ByteBuffer.allocate(data.length);
 +        buf.limit(data.length / 2);
 +        sc.read(buf);
 +
 +        buf.limit(buf.capacity());
 +        sc.read(buf);
 +        sc.close();
 +
 +        // Make sure the buffer is filled correctly
 +        buf.rewind();
 +        assertSameContent(data, buf);
 +
 +        // Now test with direct byte buffer
 +        sc = SocketChannel.open();
 +        sc.connect(address);
 +
 +        buf = ByteBuffer.allocateDirect(data.length);
 +        buf.limit(data.length / 2);
 +        sc.read(buf);
 +
 +        buf.limit(buf.capacity());
 +        sc.read(buf);
 +        sc.close();
 +
 +        // Make sure the buffer is filled correctly
 +        buf.rewind();
 +        assertSameContent(data, buf);
 +    }
 +
 +    private void assertSameContent(byte[] data, ByteBuffer buf) {
 +        for (byte b : data) {
 +            if (b != buf.get()) {
 +                int pos = buf.position() - 1;
 +                fail("Content not equal. Buffer position: " +
 +                        (pos) + " expected: " + b + " was: " + buf.get(pos));
 +            }
 +        }
 +    }
 +
 +    public static boolean done = false;
 +    public static int port = Support_PortManager.getNextPort();
 +    public static byte[] data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
 +
 +    static class ServerThread extends Thread {
 +        @Override
 +        public void run() {
 +            try {
 +                ServerSocketChannel ssc = ServerSocketChannel.open();
 +                InetSocketAddress addr = new InetSocketAddress(InetAddress
 +                        .getByAddress(new byte[] {0, 0, 0, 0}), port);
 +                ssc.socket().bind(addr, 0);
 +
 +                ByteBuffer buf = ByteBuffer.allocate(10);
 +                buf.put(data);
 +
 +                while (!done) {
 +                    SocketChannel sc = ssc.accept();
 +                    buf.rewind();
 +                    sc.write(buf);
 +                }
 +            } catch (Exception e) {
 +                // ignore
 +            }
 +        }
 +    }
 +
      class MockSocketChannel extends SocketChannel {
  
          private boolean isWriteCalled = false;