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