001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.luni.tests.java.net;
019:
020: import java.io.FileDescriptor;
021: import java.io.IOException;
022: import java.io.InputStream;
023: import java.io.OutputStream;
024: import java.net.InetAddress;
025: import java.net.SocketAddress;
026: import java.net.SocketException;
027: import java.net.SocketImpl;
028:
029: public class SocketImplTest extends junit.framework.TestCase {
030:
031: /**
032: * @tests java.net.SocketImpl#SocketImpl()
033: */
034: public void test_Constructor_fd() {
035: // Regression test for HARMONY-1117
036: MockSocketImpl mockSocketImpl = new MockSocketImpl();
037: assertNull(mockSocketImpl.getFileDescriptor());
038: }
039:
040: /**
041: * @tests java.net.SocketImpl#setPerformancePreference()
042: */
043: public void test_setPerformancePreference_Int_Int_Int() {
044: MockSocketImpl theSocket = new MockSocketImpl();
045: theSocket.setPerformancePreference(1, 1, 1);
046: }
047:
048: /**
049: * @tests java.net.SocketImpl#shutdownOutput()
050: */
051: public void test_shutdownOutput() {
052: MockSocketImpl s = new MockSocketImpl();
053: try {
054: s.shutdownOutput();
055: fail("This method is still not implemented yet,It should throw IOException.");
056: } catch (IOException e) {
057: // expected
058: }
059: }
060:
061: /**
062: * @tests java.net.SocketImpl#shutdownOutput()
063: */
064: public void test_supportsUrgentData() {
065: MockSocketImpl s = new MockSocketImpl();
066: assertFalse(s.testSupportsUrgentData());
067: }
068:
069: // the mock class for test, leave all methods empty
070: class MockSocketImpl extends SocketImpl {
071:
072: protected void accept(SocketImpl newSocket) throws IOException {
073: }
074:
075: protected int available() throws IOException {
076: return 0;
077: }
078:
079: protected void bind(InetAddress address, int port)
080: throws IOException {
081: }
082:
083: protected void close() throws IOException {
084: }
085:
086: protected void connect(String host, int port)
087: throws IOException {
088: }
089:
090: protected void connect(InetAddress address, int port)
091: throws IOException {
092: }
093:
094: protected void create(boolean isStreaming) throws IOException {
095: }
096:
097: protected InputStream getInputStream() throws IOException {
098: return null;
099: }
100:
101: public Object getOption(int optID) throws SocketException {
102: return null;
103: }
104:
105: protected OutputStream getOutputStream() throws IOException {
106: return null;
107: }
108:
109: protected void listen(int backlog) throws IOException {
110: }
111:
112: public void setOption(int optID, Object val)
113: throws SocketException {
114: }
115:
116: protected void connect(SocketAddress remoteAddr, int timeout)
117: throws IOException {
118: }
119:
120: protected void sendUrgentData(int value) throws IOException {
121: }
122:
123: public void setPerformancePreference(int connectionTime,
124: int latency, int bandwidth) {
125: super .setPerformancePreferences(connectionTime, latency,
126: bandwidth);
127: }
128:
129: public FileDescriptor getFileDescriptor() {
130: return super .getFileDescriptor();
131: }
132:
133: public void shutdownOutput() throws IOException {
134: super .shutdownOutput();
135: }
136:
137: public boolean testSupportsUrgentData() {
138: return super.supportsUrgentData();
139: }
140:
141: }
142: }
|