01: /* Licensed to the Apache Software Foundation (ASF) under one or more
02: * contributor license agreements. See the NOTICE file distributed with
03: * this work for additional information regarding copyright ownership.
04: * The ASF licenses this file to You under the Apache License, Version 2.0
05: * (the "License"); you may not use this file except in compliance with
06: * the License. You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.harmony.nio.tests;
18:
19: import java.io.IOException;
20: import java.nio.ByteBuffer;
21: import java.nio.channels.Channel;
22: import java.nio.channels.DatagramChannel;
23: import java.nio.channels.ServerSocketChannel;
24: import java.nio.channels.SocketChannel;
25:
26: import junit.framework.TestCase;
27:
28: import org.apache.harmony.nio.AddressUtil;
29:
30: public class AddressUtilTest extends TestCase {
31:
32: /**
33: * @tests AddressUtil#getDirectBufferAddress
34: */
35: public void test_getDirectBufferAddress() throws Exception {
36: ByteBuffer buf = ByteBuffer.allocateDirect(10);
37: assertTrue(AddressUtil.getDirectBufferAddress(buf) != 0);
38: }
39:
40: /**
41: * @tests AddressUtil#getChannelAddress
42: */
43: public void test_getFileChannelAddress() throws Exception {
44: // FileChannel fc = new FileInputStream("src/main/java/org/apache/harmony/nio/AddressUtil.java").getChannel();
45: // assertTrue(AddressUtil.getChannelAddress(fc) > 0);
46: }
47:
48: /**
49: * @tests AddressUtil#getChannelAddress
50: */
51: public void test_getSocketChannelAddress() throws Exception {
52: SocketChannel sc = SocketChannel.open();
53: assertTrue(AddressUtil.getChannelAddress(sc) > 0);
54: }
55:
56: /**
57: * @tests AddressUtil#getChannelAddress
58: */
59: public void test_getDatagramChannelAddress() throws Exception {
60: DatagramChannel dc = DatagramChannel.open();
61: assertTrue(AddressUtil.getChannelAddress(dc) > 0);
62: }
63:
64: /**
65: * @tests AddressUtil#getChannelAddress
66: */
67: public void test_getServerSocketChannelAddress() throws Exception {
68: ServerSocketChannel ssc = ServerSocketChannel.open();
69: assertTrue(AddressUtil.getChannelAddress(ssc) > 0);
70: }
71:
72: /**
73: * @tests AddressUtil#getChannelAddress
74: */
75: public void test_getNonNativeChannelAddress() throws Exception {
76: Channel channel = new MockChannel();
77: assertEquals(0, AddressUtil.getChannelAddress(channel));
78: }
79:
80: private static class MockChannel implements Channel {
81: public boolean isOpen() {
82: return false;
83: }
84:
85: public void close() throws IOException {
86: }
87: }
88: }
|