Home | History | Annotate | Download | only in net
      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.net.DatagramPacket;
     23 import java.net.DatagramSocketImpl;
     24 import java.net.InetAddress;
     25 import java.net.NetworkInterface;
     26 import java.net.SocketAddress;
     27 import java.net.SocketException;
     28 
     29 public class DatagramSocketImplTest extends junit.framework.TestCase {
     30     /**
     31      * @tests java.net.DatagramSocketImpl#DatagramSocketImpl()
     32      */
     33     public void test_Constructor() throws Exception {
     34         // regression test for Harmony-1117
     35         MockDatagramSocketImpl impl = new MockDatagramSocketImpl();
     36         assertNull(impl.getFileDescriptor());
     37     }
     38 
     39 
     40     public void test_connect() throws Exception {
     41         MockDatagramSocketImpl impl = new MockDatagramSocketImpl();
     42         InetAddress localhost = InetAddress.getByName("localhost"); //$NON-NLS-1$
     43         // connect do nothing, so will not throw exception
     44         impl.test_connect(localhost, 0);
     45         impl.test_connect(localhost, -1);
     46         impl.test_connect(null, -1);
     47         // disconnect
     48         impl.test_disconnect();
     49     }
     50 }
     51 
     52 class MockDatagramSocketImpl extends DatagramSocketImpl {
     53 
     54     @Override
     55     public FileDescriptor getFileDescriptor() {
     56         return super.getFileDescriptor();
     57     }
     58 
     59     @Override
     60     protected void bind(int port, InetAddress addr) throws SocketException {
     61         // empty
     62     }
     63 
     64     @Override
     65     protected void close() {
     66         // empty
     67     }
     68 
     69     @Override
     70     protected void create() throws SocketException {
     71         // empty
     72     }
     73 
     74     public Object getOption(int optID) throws SocketException {
     75         return null;
     76     }
     77 
     78     @Override
     79     protected byte getTTL() throws IOException {
     80         return 0;
     81     }
     82 
     83     @Override
     84     protected int getTimeToLive() throws IOException {
     85         return 0;
     86     }
     87 
     88     @Override
     89     protected void join(InetAddress addr) throws IOException {
     90         // empty
     91     }
     92 
     93     @Override
     94     protected void joinGroup(SocketAddress addr, NetworkInterface netInterface)
     95             throws IOException {
     96         // empty
     97     }
     98 
     99     @Override
    100     protected void leave(InetAddress addr) throws IOException {
    101         // empty
    102     }
    103 
    104     @Override
    105     protected void leaveGroup(SocketAddress addr, NetworkInterface netInterface)
    106             throws IOException {
    107         // empty
    108     }
    109 
    110     @Override
    111     protected int peek(InetAddress sender) throws IOException {
    112         return 0;
    113     }
    114 
    115     @Override
    116     protected int peekData(DatagramPacket pack) throws IOException {
    117         return 0;
    118     }
    119 
    120     @Override
    121     protected void receive(DatagramPacket pack) throws IOException {
    122         // empty
    123     }
    124 
    125     @Override
    126     protected void send(DatagramPacket pack) throws IOException {
    127         // empty
    128 
    129     }
    130 
    131     public void setOption(int optID, Object val) throws SocketException {
    132         // empty
    133     }
    134 
    135     @Override
    136     protected void setTTL(byte ttl) throws IOException {
    137         // empty
    138     }
    139 
    140     @Override
    141     protected void setTimeToLive(int ttl) throws IOException {
    142         // empty
    143     }
    144 
    145     public void test_connect(InetAddress inetAddr, int port ) throws SocketException{
    146         super.connect(inetAddr, port);
    147     }
    148 
    149     public void test_disconnect(){
    150         super.disconnect();
    151     }
    152 }
    153