1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.harmony.luni.tests.java.net; 19 20 import java.io.FileDescriptor; 21 import java.io.IOException; 22 import java.io.InputStream; 23 import java.io.OutputStream; 24 import java.net.InetAddress; 25 import java.net.SocketAddress; 26 import java.net.SocketException; 27 import java.net.SocketImpl; 28 29 public class SocketImplTest extends junit.framework.TestCase { 30 31 /** 32 * @tests java.net.SocketImpl#SocketImpl() 33 */ test_Constructor_fd()34 public void test_Constructor_fd() { 35 // Regression test for HARMONY-1117 36 MockSocketImpl mockSocketImpl = new MockSocketImpl(); 37 assertNull(mockSocketImpl.getFileDescriptor()); 38 } 39 40 /** 41 * @tests java.net.SocketImpl#setPerformancePreference() 42 */ test_setPerformancePreference_Int_Int_Int()43 public void test_setPerformancePreference_Int_Int_Int() { 44 MockSocketImpl theSocket = new MockSocketImpl(); 45 theSocket.setPerformancePreference(1, 1, 1); 46 } 47 48 /** 49 * @tests java.net.SocketImpl#shutdownOutput() 50 */ test_shutdownOutput()51 public void test_shutdownOutput() { 52 MockSocketImpl s = new MockSocketImpl(); 53 try { 54 s.shutdownOutput(); 55 fail("This method is still not implemented yet,It should throw IOException."); 56 } catch (IOException e) { 57 // expected 58 } 59 } 60 61 /** 62 * @tests java.net.SocketImpl#shutdownInput() 63 */ test_shutdownInput()64 public void test_shutdownInput() { 65 MockSocketImpl s = new MockSocketImpl(); 66 try { 67 s.shutdownInput(); 68 fail("This method is still not implemented yet,It should throw IOException."); 69 } catch (IOException e) { 70 // Expected 71 } 72 } 73 74 /** 75 * @tests java.net.SocketImpl#supportsUrgentData() 76 */ test_supportsUrgentData()77 public void test_supportsUrgentData() { 78 MockSocketImpl s = new MockSocketImpl(); 79 assertFalse(s.testSupportsUrgentData()); 80 } 81 82 // the mock class for test, leave all methods empty 83 class MockSocketImpl extends SocketImpl { 84 accept(SocketImpl newSocket)85 protected void accept(SocketImpl newSocket) throws IOException { 86 } 87 available()88 protected int available() throws IOException { 89 return 0; 90 } 91 bind(InetAddress address, int port)92 protected void bind(InetAddress address, int port) throws IOException { 93 } 94 close()95 protected void close() throws IOException { 96 } 97 connect(String host, int port)98 protected void connect(String host, int port) throws IOException { 99 } 100 connect(InetAddress address, int port)101 protected void connect(InetAddress address, int port) 102 throws IOException { 103 } 104 create(boolean isStreaming)105 protected void create(boolean isStreaming) throws IOException { 106 } 107 getInputStream()108 protected InputStream getInputStream() throws IOException { 109 return null; 110 } 111 getOption(int optID)112 public Object getOption(int optID) throws SocketException { 113 return null; 114 } 115 getOutputStream()116 protected OutputStream getOutputStream() throws IOException { 117 return null; 118 } 119 listen(int backlog)120 protected void listen(int backlog) throws IOException { 121 } 122 setOption(int optID, Object val)123 public void setOption(int optID, Object val) throws SocketException { 124 } 125 connect(SocketAddress remoteAddr, int timeout)126 protected void connect(SocketAddress remoteAddr, int timeout) 127 throws IOException { 128 } 129 sendUrgentData(int value)130 protected void sendUrgentData(int value) throws IOException { 131 } 132 setPerformancePreference(int connectionTime, int latency, int bandwidth)133 public void setPerformancePreference(int connectionTime, int latency, 134 int bandwidth) { 135 super.setPerformancePreferences(connectionTime, latency, bandwidth); 136 } 137 getFileDescriptor()138 public FileDescriptor getFileDescriptor() { 139 return super.getFileDescriptor(); 140 } 141 shutdownOutput()142 public void shutdownOutput() throws IOException { 143 super.shutdownOutput(); 144 } 145 shutdownInput()146 public void shutdownInput() throws IOException{ 147 super.shutdownInput(); 148 } 149 testSupportsUrgentData()150 public boolean testSupportsUrgentData() { 151 return super.supportsUrgentData(); 152 } 153 154 } 155 } 156