This is an automated email from the ASF dual-hosted git repository.

matthiasblaesing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 7fc9a2e  Fix SOMEADDR_IPV4_RAW in platform/core.network module
     new 9043161  Merge pull request #1765 from 
blackleg/improve_core_network_tests
7fc9a2e is described below

commit 7fc9a2e6cc402173d9e2e91ef3c5e21c8a5aaf86
Author: Hector Espert <hectorespertpa...@gmail.com>
AuthorDate: Mon Dec 9 21:37:11 2019 +0100

    Fix SOMEADDR_IPV4_RAW in platform/core.network module
---
 .../core/network/utils/LocalAddressUtils.java      | 18 ++---
 .../core/network/utils/HostnameUtilsTest.java      | 35 +++++++++
 .../core/network/utils/LocalAddressUtilsTest.java  | 89 ++++++++++++----------
 .../utils/hname/linux/HostnameUtilsLinuxTest.java  | 43 +++++++++++
 .../utils/hname/unix/HostnameUtilsUnixTest.java    | 46 +++++++++++
 5 files changed, 180 insertions(+), 51 deletions(-)

diff --git 
a/platform/core.network/src/org/netbeans/core/network/utils/LocalAddressUtils.java
 
b/platform/core.network/src/org/netbeans/core/network/utils/LocalAddressUtils.java
index 73a24cf..e6d4df6 100644
--- 
a/platform/core.network/src/org/netbeans/core/network/utils/LocalAddressUtils.java
+++ 
b/platform/core.network/src/org/netbeans/core/network/utils/LocalAddressUtils.java
@@ -92,18 +92,18 @@ public class LocalAddressUtils {
     
     
     // 8.8.8.8  -- which incidentially is Google's DNS server, but we don't 
ever connect
-    private static final byte[] SOMEADDR_IPV4_RAW = new byte[]{
-        (byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80, 
(byte)0x80, (byte)0x80, (byte)0x80};
+    private static final byte[] SOMEADDR_IPV4_RAW = new byte[]{0x08, 0x08, 
0x08, 0x08};
 
     // 2001:4860:4860::8888  -- which incidentially is Google's DNS server, 
but we don't ever connect
     private static final byte[] SOMEADDR_IPV6_RAW = new byte[]{
         0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0x88, (byte)0x88};
     
-    private static InetAddress LOOPBACK_IPV4;
-    private static InetAddress LOOPBACK_IPV6;
-    private static InetAddress SOMEADDR_IPV4;
-    private static InetAddress SOMEADDR_IPV6;
+    private static final InetAddress LOOPBACK_IPV4;
+    private static final InetAddress LOOPBACK_IPV6;
+    private static final InetAddress SOMEADDR_IPV4;
+    private static final InetAddress SOMEADDR_IPV6;
+    
     static {
         try {
             LOOPBACK_IPV4 = InetAddress.getByAddress("local-ipv4-dummy", 
LOOPBACK_IPV4_RAW);
@@ -111,11 +111,7 @@ public class LocalAddressUtils {
             SOMEADDR_IPV4 = InetAddress.getByAddress("some-ipv4-dummy", 
SOMEADDR_IPV4_RAW);
             SOMEADDR_IPV6 = InetAddress.getByAddress("some-ipv6-dummy", 
SOMEADDR_IPV6_RAW);
         } catch (UnknownHostException ex) {
-            // Cannot happen by definition
-            LOOPBACK_IPV4 = null;
-            LOOPBACK_IPV6 = null;
-            SOMEADDR_IPV4 = null;
-            SOMEADDR_IPV6 = null;
+            throw new RuntimeException(ex);
         }
     }
             
diff --git 
a/platform/core.network/test/unit/src/org/netbeans/core/network/utils/HostnameUtilsTest.java
 
b/platform/core.network/test/unit/src/org/netbeans/core/network/utils/HostnameUtilsTest.java
new file mode 100644
index 0000000..fe1f53b
--- /dev/null
+++ 
b/platform/core.network/test/unit/src/org/netbeans/core/network/utils/HostnameUtilsTest.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.core.network.utils;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+
+/**
+ *
+ * @author Hector Espert
+ */
+public class HostnameUtilsTest {
+    
+    @Test
+    public void testGetNetworkHostname() throws Exception {
+        assertNotNull(HostnameUtils.getNetworkHostname());
+    }
+    
+}
diff --git 
a/platform/core.network/test/unit/src/org/netbeans/core/network/utils/LocalAddressUtilsTest.java
 
b/platform/core.network/test/unit/src/org/netbeans/core/network/utils/LocalAddressUtilsTest.java
index c71c5a9..bea9017 100644
--- 
a/platform/core.network/test/unit/src/org/netbeans/core/network/utils/LocalAddressUtilsTest.java
+++ 
b/platform/core.network/test/unit/src/org/netbeans/core/network/utils/LocalAddressUtilsTest.java
@@ -14,10 +14,10 @@
 package org.netbeans.core.network.utils;
 
 import java.net.InetAddress;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.List;
+import static org.junit.Assert.*;
 import org.junit.Test;
 
 /**
@@ -25,58 +25,67 @@ import org.junit.Test;
  * @author lbruun
  */
 public class LocalAddressUtilsTest {
-    
-    public LocalAddressUtilsTest() {
-    }
-    
-    @BeforeClass
-    public static void setUpClass() {
+
+    @Test
+    public void testWarmUp() {
+        LocalAddressUtils.warmUp();
     }
-    
-    @AfterClass
-    public static void tearDownClass() {
+
+    @Test
+    public void testRefreshNetworkInfo() {
+        LocalAddressUtils.refreshNetworkInfo(true);
     }
-    
-    @Before
-    public void setUp() {
+
+    @Test
+    public void testGetLocalHost() throws Exception {
+        InetAddress result = LocalAddressUtils.getLocalHost();
+        assertNotNull(result);
     }
-    
-    @After
-    public void tearDown() {
+
+    @Test
+    public void testGetLocalHostAddresses() throws Exception {
+        InetAddress[] result = 
LocalAddressUtils.getLocalHostAddresses(IpAddressUtils.IpTypePreference.IPV4_ONLY);
+        assertNotNull(result);
     }
 
-   
 
-    /**
-     * Test of getLocalHostAddr method, of class LocalAddressUtils.
-     */
     @Test
-    public void testGetLocalHostAddr() {
-        System.out.println("getLocalHostAddr");
+    public void testGetPrioritizedLocalHostAddresses() {
+        List<InetAddress> result = 
LocalAddressUtils.getPrioritizedLocalHostAddresses(IpAddressUtils.IpTypePreference.IPV4_ONLY);
+        assertNotNull(result);
     }
 
-    /**
-     * Test of getLoopbackAddress method, of class LocalAddressUtils.
-     */
     @Test
-    public void testGetLoopbackAddress() {
-        System.out.println("getLoopbackAddress");
+    public void testGetMostLikelyLocalInetAddresses() {
+        InetAddress[] result = 
LocalAddressUtils.getMostLikelyLocalInetAddresses(IpAddressUtils.IpTypePreference.IPV4_ONLY);
+        assertNotNull(result);
     }
 
-    /**
-     * Test of refreshLocalNetworkInterfaceAddr method, of class 
LocalAddressUtils.
-     */
     @Test
-    public void testRefreshLocalNetworkInterfaceAddr() {
-        System.out.println("refreshLocalNetworkInterfaceAddr");
+    public void testGetMostLikelyLocalInetAddress() {
+        InetAddress result = 
LocalAddressUtils.getMostLikelyLocalInetAddress(IpAddressUtils.IpTypePreference.IPV4_ONLY);
+        assertNotNull(result);
     }
 
-    /**
-     * Test of refreshLocalHostAddr method, of class LocalAddressUtils.
-     */
     @Test
-    public void testRefreshLocalHostAddr() {
-        System.out.println("refreshLocalHostAddr");
+    public void testGetLoopbackAddress() {
+        InetAddress inetAddress = 
LocalAddressUtils.getLoopbackAddress(IpAddressUtils.IpTypePreference.IPV4_ONLY);
+        assertEquals("local-ipv4-dummy", inetAddress.getHostName());
+        assertEquals("127.0.0.1", inetAddress.getHostAddress());
+        inetAddress = 
LocalAddressUtils.getLoopbackAddress(IpAddressUtils.IpTypePreference.IPV6_ONLY);
+        assertEquals("local-ipv6-dummy", inetAddress.getHostName());
+        assertEquals("0:0:0:0:0:0:0:1", inetAddress.getHostAddress());
+        inetAddress = 
LocalAddressUtils.getLoopbackAddress(IpAddressUtils.IpTypePreference.ANY_JDK_PREF);
+        assertEquals("local-ipv4-dummy", inetAddress.getHostName());
+        assertEquals("127.0.0.1", inetAddress.getHostAddress());
+    }
+
+
+    @Test
+    public void testIsSoftwareVirtualAdapter() throws SocketException {
+        InetAddress inetAddress = 
LocalAddressUtils.getLoopbackAddress(IpAddressUtils.IpTypePreference.ANY_IPV4_PREF);
+        NetworkInterface networkInterface = 
NetworkInterface.getByInetAddress(inetAddress);
+        
assertFalse(LocalAddressUtils.isSoftwareVirtualAdapter(networkInterface));
     }
     
 }
diff --git 
a/platform/core.network/test/unit/src/org/netbeans/core/network/utils/hname/linux/HostnameUtilsLinuxTest.java
 
b/platform/core.network/test/unit/src/org/netbeans/core/network/utils/hname/linux/HostnameUtilsLinuxTest.java
new file mode 100644
index 0000000..c5dfc0b
--- /dev/null
+++ 
b/platform/core.network/test/unit/src/org/netbeans/core/network/utils/hname/linux/HostnameUtilsLinuxTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.core.network.utils.hname.linux;
+
+import com.sun.jna.Platform;
+import org.netbeans.junit.NbTestCase;
+
+/**
+ *
+ * @author hector
+ */
+public class HostnameUtilsLinuxTest extends NbTestCase {
+
+    public HostnameUtilsLinuxTest(String name) {
+        super(name);
+    }
+
+    @Override
+    public boolean canRun() {
+        return super.canRun() && Platform.LINUX == Platform.getOSType();
+    }
+
+    public void testCLibGetHostname() throws Exception {
+        assertNotNull(HostnameUtilsLinux.cLibGetHostname());   
+    }
+    
+}
diff --git 
a/platform/core.network/test/unit/src/org/netbeans/core/network/utils/hname/unix/HostnameUtilsUnixTest.java
 
b/platform/core.network/test/unit/src/org/netbeans/core/network/utils/hname/unix/HostnameUtilsUnixTest.java
new file mode 100644
index 0000000..ab62bcc
--- /dev/null
+++ 
b/platform/core.network/test/unit/src/org/netbeans/core/network/utils/hname/unix/HostnameUtilsUnixTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.core.network.utils.hname.unix;
+
+import com.sun.jna.Platform;
+import org.junit.Test;
+import org.netbeans.junit.NbTestCase;
+
+/**
+ *
+ * @author hector
+ */
+public class HostnameUtilsUnixTest extends NbTestCase {
+
+    public HostnameUtilsUnixTest(String name) {
+        super(name);
+    }
+    
+    @Override
+    public boolean canRun() {
+        return super.canRun() && Platform.FREEBSD == Platform.getOSType();
+    }
+    
+   
+    @Test
+    public void testCLibGetHostname() throws Exception {
+        assertNotNull(HostnameUtilsUnix.cLibGetHostname()); 
+    }
+    
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to