From 192a21504fb5658efe2f49edbf05673f5c6b6007 Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Sun, 6 Oct 2019 16:40:39 -0700 Subject: [PATCH] SystemB extends LibCAPI --- .../src/com/sun/jna/platform/mac/SystemB.java | 21 +--------- .../com/sun/jna/platform/mac/SystemBTest.java | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/contrib/platform/src/com/sun/jna/platform/mac/SystemB.java b/contrib/platform/src/com/sun/jna/platform/mac/SystemB.java index 2fefff44f3..d11396b630 100644 --- a/contrib/platform/src/com/sun/jna/platform/mac/SystemB.java +++ b/contrib/platform/src/com/sun/jna/platform/mac/SystemB.java @@ -30,11 +30,12 @@ import com.sun.jna.NativeLong; import com.sun.jna.Pointer; import com.sun.jna.Structure; +import com.sun.jna.platform.unix.LibCAPI; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.LongByReference; import com.sun.jna.ptr.PointerByReference; -public interface SystemB extends Library { +public interface SystemB extends LibCAPI, Library { SystemB INSTANCE = Native.load("System", SystemB.class); @@ -730,24 +731,6 @@ class Timezone extends Structure { int host_processor_info(int hostPort, int flavor, IntByReference procCount, PointerByReference procInfo, IntByReference procInfoCount); - /** - * The getloadavg() function returns the number of processes in the system run - * queue averaged over various periods of time. Up to nelem samples are - * retrieved and assigned to successive elements of loadavg[]. The system - * imposes a maximum of 3 samples, representing averages over the last 1, 5, and - * 15 minutes, respectively. - * - * @param loadavg - * An array of doubles which will be filled with the results - * @param nelem - * Number of samples to return - * @return If the load average was unobtainable, -1 is returned; otherwise, the - * number of samples actually retrieved is returned. - * @see getloadavg(3) - */ - int getloadavg(double[] loadavg, int nelem); - /** * This function searches the password database for the given user uid, always * returning the first one encountered. diff --git a/contrib/platform/test/com/sun/jna/platform/mac/SystemBTest.java b/contrib/platform/test/com/sun/jna/platform/mac/SystemBTest.java index f24040314f..6b9af6ebca 100644 --- a/contrib/platform/test/com/sun/jna/platform/mac/SystemBTest.java +++ b/contrib/platform/test/com/sun/jna/platform/mac/SystemBTest.java @@ -25,6 +25,9 @@ import static org.junit.Assert.assertNotEquals; +import java.util.Date; +import java.util.Map; + import com.sun.jna.Memory; import com.sun.jna.Native; import com.sun.jna.Platform; @@ -167,6 +170,31 @@ public void testHostProcessorInfo() { procInfoCount.getValue()); } + // From Unix LibCAPI + public void testGetenv() { + Map env = System.getenv(); + for (Map.Entry ee : env.entrySet()) { + String name = ee.getKey(); + String expected = ee.getValue(); + String actual = SystemB.INSTANCE.getenv(name); + assertEquals(name, expected, actual); + } + } + + // From Unix LibCAPI + public void testSetenv() { + String name = "SystemBTestEnv"; + try { + String expected = new Date(System.currentTimeMillis()).toString(); + assertEquals("setenv", 0, SystemB.INSTANCE.setenv(name, expected, 1)); + assertEquals("Mismatched values", expected, SystemB.INSTANCE.getenv(name)); + assertEquals("unsetenv", 0, SystemB.INSTANCE.unsetenv(name)); + } finally { + SystemB.INSTANCE.unsetenv(name); + } + } + + // From Unix LibCAPI public void testGetLoadAvg() { double[] loadavg = new double[3]; int retval = SystemB.INSTANCE.getloadavg(loadavg, 3); @@ -176,6 +204,16 @@ public void testGetLoadAvg() { assertTrue(loadavg[2] >= 0); } + // From Unix LibCAPI + public void testGethostnameGetdomainname() { + byte[] buffer = new byte[256]; + assertEquals("gethostname", 0, SystemB.INSTANCE.gethostname(buffer, buffer.length)); + String hostname = Native.toString(buffer); + assertTrue(hostname.length() > 0); + assertEquals("getdomainname", 0, SystemB.INSTANCE.getdomainname(buffer, buffer.length)); + // May have length 0 + } + public void testTimeofDay() { Timeval tp = new Timeval(); long before = System.currentTimeMillis();