Skip to content

Commit

Permalink
Merge pull request #1376 from matthiasblaesing/fix_appveyor
Browse files Browse the repository at this point in the history
Fix appveyor
  • Loading branch information
matthiasblaesing committed Aug 19, 2021
2 parents fd6a9a6 + c8260ae commit 2f56de8
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 6 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
Expand Up @@ -8,14 +8,14 @@ environment:
matrix:
- TARGET_ARCH: x86_64
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CYGWIN_PACKAGES: git,make,automake,libtool,mingw64-x86_64-gcc-g++,mingw64-x86_64-gcc-core
CYGWIN_PACKAGES: git,make,automake,libtool,mingw64-x86_64-gcc-g++,mingw64-x86_64-gcc-core,perl
CHOCO_PACKAGES: ant cygwin
CYGWIN_SETUP: cygwinsetup.exe # from choco
JAVA_HOME: C:\Program Files\Java\jdk1.8.0

- TARGET_ARCH: x86
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CYGWIN_PACKAGES: git,make,automake,libtool,mingw64-i686-gcc-g++,mingw64-i686-gcc-core
CYGWIN_PACKAGES: git,make,automake,libtool,mingw64-i686-gcc-g++,mingw64-i686-gcc-core,perl
CHOCO_PACKAGES: ant cygwin
CYGWIN_SETUP: cygwinsetup.exe # from choco
JAVA_HOME: C:\Program Files (x86)\Java\jdk1.8.0 # 32-bit
Expand Down
62 changes: 62 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/Cfgmgr32.java
Expand Up @@ -38,8 +38,70 @@ public interface Cfgmgr32 extends Library {
Cfgmgr32 INSTANCE = Native.load("Cfgmgr32", Cfgmgr32.class, W32APIOptions.DEFAULT_OPTIONS);

int CR_SUCCESS = 0;
int CR_DEFAULT = 0x00000001;
int CR_OUT_OF_MEMORY = 0x00000002;
int CR_INVALID_POINTER = 0x00000003;
int CR_INVALID_FLAG = 0x00000004;
int CR_INVALID_DEVNODE = 0x00000005;
int CR_INVALID_DEVINST = CR_INVALID_DEVNODE;
int CR_INVALID_RES_DES = 0x00000006;
int CR_INVALID_LOG_CONF = 0x00000007;
int CR_INVALID_ARBITRATOR = 0x00000008;
int CR_INVALID_NODELIST = 0x00000009;
int CR_DEVNODE_HAS_REQS = 0x0000000A;
int CR_DEVINST_HAS_REQS = CR_DEVNODE_HAS_REQS;
int CR_INVALID_RESOURCEID = 0x0000000B;
int CR_DLVXD_NOT_FOUND = 0x0000000C; // WIN 95 ONLY
int CR_NO_SUCH_DEVNODE = 0x0000000D;
int CR_NO_SUCH_DEVINST = CR_NO_SUCH_DEVNODE;
int CR_NO_MORE_LOG_CONF = 0x0000000E;
int CR_NO_MORE_RES_DES = 0x0000000F;
int CR_ALREADY_SUCH_DEVNODE = 0x00000010;
int CR_ALREADY_SUCH_DEVINST = CR_ALREADY_SUCH_DEVNODE;
int CR_INVALID_RANGE_LIST = 0x00000011;
int CR_INVALID_RANGE = 0x00000012;
int CR_FAILURE = 0x00000013;
int CR_NO_SUCH_LOGICAL_DEV = 0x00000014;
int CR_CREATE_BLOCKED = 0x00000015;
int CR_NOT_SYSTEM_VM = 0x00000016; // WIN 95 ONLY
int CR_REMOVE_VETOED = 0x00000017;
int CR_APM_VETOED = 0x00000018;
int CR_INVALID_LOAD_TYPE = 0x00000019;
int CR_BUFFER_SMALL = 0x0000001A;
int CR_NO_ARBITRATOR = 0x0000001B;
int CR_NO_REGISTRY_HANDLE = 0x0000001C;
int CR_REGISTRY_ERROR = 0x0000001D;
int CR_INVALID_DEVICE_ID = 0x0000001E;
int CR_INVALID_DATA = 0x0000001F;
int CR_INVALID_API = 0x00000020;
int CR_DEVLOADER_NOT_READY = 0x00000021;
int CR_NEED_RESTART = 0x00000022;
int CR_NO_MORE_HW_PROFILES = 0x00000023;
int CR_DEVICE_NOT_THERE = 0x00000024;
int CR_NO_SUCH_VALUE = 0x00000025;
int CR_WRONG_TYPE = 0x00000026;
int CR_INVALID_PRIORITY = 0x00000027;
int CR_NOT_DISABLEABLE = 0x00000028;
int CR_FREE_RESOURCES = 0x00000029;
int CR_QUERY_VETOED = 0x0000002A;
int CR_CANT_SHARE_IRQ = 0x0000002B;
int CR_NO_DEPENDENT = 0x0000002C;
int CR_SAME_RESOURCES = 0x0000002D;
int CR_NO_SUCH_REGISTRY_KEY = 0x0000002E;
int CR_INVALID_MACHINENAME = 0x0000002F; // NT ONLY
int CR_REMOTE_COMM_FAILURE = 0x00000030; // NT ONLY
int CR_MACHINE_UNAVAILABLE = 0x00000031; // NT ONLY
int CR_NO_CM_SERVICES = 0x00000032; // NT ONLY
int CR_ACCESS_DENIED = 0x00000033; // NT ONLY
int CR_CALL_NOT_IMPLEMENTED = 0x00000034;
int CR_INVALID_PROPERTY = 0x00000035;
int CR_DEVICE_INTERFACE_ACTIVE = 0x00000036;
int CR_NO_SUCH_DEVICE_INTERFACE = 0x00000037;
int CR_INVALID_REFERENCE_STRING = 0x00000038;
int CR_INVALID_CONFLICT_LIST = 0x00000039;
int CR_INVALID_INDEX = 0x0000003A;
int CR_INVALID_STRUCTURE_SIZE = 0x0000003B;
int NUM_CR_RESULTS = 0x0000003C;

int CM_LOCATE_DEVNODE_NORMAL = 0;
int CM_LOCATE_DEVNODE_PHANTOM = 1;
Expand Down
Expand Up @@ -43,6 +43,11 @@ public Cfgmgr32Exception(int errorCode) {
public int getErrorCode() {
return errorCode;
}

@Override
public String toString() {
return super.toString() + String.format(" [errorCode: 0x%08x]", errorCode);
}
}

/**
Expand Down
21 changes: 17 additions & 4 deletions contrib/platform/test/com/sun/jna/platform/win32/Cfgmgr32Test.java
Expand Up @@ -30,7 +30,6 @@
import static com.sun.jna.platform.win32.Cfgmgr32.CM_LOCATE_DEVNODE_NORMAL;
import static com.sun.jna.platform.win32.Cfgmgr32.CR_SUCCESS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.UnsupportedEncodingException;
Expand All @@ -41,6 +40,9 @@

import com.sun.jna.ptr.IntByReference;

import static com.sun.jna.platform.win32.Cfgmgr32.CR_INVALID_DEVNODE;
import static com.sun.jna.platform.win32.Cfgmgr32.CR_INVALID_PROPERTY;

/**
* Tests methods in Cfgmgr32
*/
Expand Down Expand Up @@ -99,9 +101,15 @@ public void testDeviceId() {
*/
@Test
public void testDeviceProperties() {
Object props;

// Test an invalid node
Object props = Cfgmgr32Util.CM_Get_DevNode_Registry_Property(-1, CM_DRP_DEVICEDESC);
assertNull(props);
try {
props = Cfgmgr32Util.CM_Get_DevNode_Registry_Property(-1, CM_DRP_DEVICEDESC);
assertTrue("Should not be reached - method is expected to raise a Cfgmgr32Exception", false);
} catch (Cfgmgr32Util.Cfgmgr32Exception ex) {
assertEquals(CR_INVALID_DEVNODE, ex.getErrorCode());
}

// Not all devices have all properties and will fail with CR_NO_SUCH_VALUE.
// So do BFS of device tree and run tests on all devices until we've tested each
Expand Down Expand Up @@ -147,7 +155,12 @@ public void testDeviceProperties() {
powerTested = true;
}
// Test an invalid type
assertNull(Cfgmgr32Util.CM_Get_DevNode_Registry_Property(node, 0));
try {
props = Cfgmgr32Util.CM_Get_DevNode_Registry_Property(node, 0);
assertTrue("Should not be reached - method is expected to raise a Cfgmgr32Exception", false);
} catch (Cfgmgr32Util.Cfgmgr32Exception ex) {
assertEquals(CR_INVALID_PROPERTY, ex.getErrorCode());
}

// If we've done all tests we can exit the loop
if (descTested && hwidTested && flagsTested && powerTested) {
Expand Down

0 comments on commit 2f56de8

Please sign in to comment.