Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros.address;
00018
00019 import static org.junit.Assert.assertEquals;
00020 import static org.junit.Assert.assertFalse;
00021 import static org.junit.Assert.assertTrue;
00022
00023 import org.junit.Test;
00024
00025 import java.net.InetAddress;
00026 import java.net.UnknownHostException;
00027
00031 public class AddressTest {
00032
00033 @Test
00034 public void testLocalhost() {
00035 InetAddress localhost = InetAddressFactory.newFromHostString(Address.LOCALHOST);
00036 assertEquals(Address.LOCALHOST, localhost.getHostName());
00037 assertTrue(localhost.isLoopbackAddress());
00038 }
00039
00040 @Test
00041 public void testLoopback() {
00042 InetAddress loopback = InetAddressFactory.newFromHostString(Address.LOOPBACK);
00043 assertEquals(Address.LOOPBACK, loopback.getHostName());
00044 assertTrue(loopback.isLoopbackAddress());
00045 }
00046
00047
00048
00049
00050 public void testPublicHost() throws UnknownHostException {
00051 String host = InetAddress.getLocalHost().getCanonicalHostName();
00052 InetAddress publicHost = InetAddressFactory.newFromHostString(host);
00053 assertEquals(host, publicHost.getHostName());
00054 assertFalse(publicHost.isLoopbackAddress());
00055 }
00056
00057 @Test
00058 public void testPublicIpv4() {
00059 String host = "1.2.3.4";
00060 InetAddress publicHost = InetAddressFactory.newFromHostString(host);
00061 assertEquals(host, publicHost.getHostName());
00062 assertFalse(publicHost.isLoopbackAddress());
00063 }
00064 }