Skip to content

Commit

Permalink
Merge branch 'master' into structure-fieldorder
Browse files Browse the repository at this point in the history
  • Loading branch information
idosu authored May 8, 2018
2 parents f16aba0 + 5936a34 commit 5283b2b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
3 changes: 3 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/WinNT.java
Original file line number Diff line number Diff line change
Expand Up @@ -2802,6 +2802,9 @@ public void write() {

@Override
public void read() {
if(SidStart == null) {
SidStart = new byte[4];
}
super.read();
int offsetOfSID = super.fieldOffset("SidStart");
int sizeOfSID = super.AceSize - super.fieldOffset("SidStart");
Expand Down
12 changes: 7 additions & 5 deletions contrib/platform/test/com/sun/jna/platform/win32/User32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.sun.jna.platform.win32.WinUser.MONITORENUMPROC;
import com.sun.jna.platform.win32.WinUser.MONITORINFO;
import com.sun.jna.platform.win32.WinUser.MONITORINFOEX;
import org.junit.Before;

/**
* @author dblock[at]dblock[dot]org
Expand All @@ -59,6 +60,11 @@ public static void main(String[] args) {
JUnitCore.runClasses(User32Test.class);
}

@Before
public void setUp() {
Native.setLastError(0);
}

/**
* Iterates over all currently available Desktop windows and searches for
* the window with the associated process whose full PE file path ends with
Expand Down Expand Up @@ -339,7 +345,6 @@ public void testIsWindowEnabled() {
public void testIsWindow() {
boolean iwResult = User32.INSTANCE.IsWindow(null);
assertFalse("IsWindow result should be false", iwResult);
assertEquals("GetLastError should be ERROR_SUCCESS.", WinError.ERROR_SUCCESS, Native.getLastError());
}

@Test
Expand All @@ -356,7 +361,6 @@ public void testGetAncestor() {

HWND result = User32.INSTANCE.GetAncestor(desktopWindow, WinUser.GA_PARENT);
assertNull("GetAncestor result should be null", result);
assertEquals("GetLastError should be ERROR_SUCCESS.", WinError.ERROR_SUCCESS, Native.getLastError());
}

@Test
Expand Down Expand Up @@ -414,10 +418,8 @@ public void testGetClassLong() {

@Test
public void testGetActiveWindow() {

HWND result = User32.INSTANCE.GetActiveWindow();
assertNull("GetActiveWindow result should be null", result);
assertEquals("GetLastError should be ERROR_SUCCESS.", WinError.ERROR_SUCCESS, Native.getLastError());
assertNull("GetActiveWindow result should be null (there is no active window)", result);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package com.sun.jna.platform.win32;

import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.Winsvc.HandlerEx;
import com.sun.jna.platform.win32.Winsvc.SC_HANDLE;
Expand All @@ -33,7 +34,7 @@
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.ProtectionDomain;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
Expand Down Expand Up @@ -100,29 +101,27 @@ public static boolean install() {
// a) an URLClassLoader
// b) holds all relevant dependencies
String invocation;
ClassLoader cl = W32ServiceTest.class.getClassLoader();
if (cl instanceof URLClassLoader) {
StringBuilder sb = new StringBuilder();
for (URL u : ((URLClassLoader) cl).getURLs()) {
if ("file".equals(u.getProtocol())) {
try {
File f = new File(u.toURI());
if (SUFFIXES.contains(f.getName())) {
if (sb.length() != 0) {
sb.append(";");
}
sb.append(f.getAbsolutePath());
StringBuilder sb = new StringBuilder();
for(Class c : new Class[]{W32ServiceTest.class,Native.class,W32Service.class}) {
ProtectionDomain pd = c.getProtectionDomain();
URL u = pd.getCodeSource().getLocation();

if ("file".equals(u.getProtocol())) {
try {
File f = new File(u.toURI());
if (SUFFIXES.contains(f.getName())) {
if (sb.length() != 0) {
sb.append(";");
}
} catch (URISyntaxException ex) {
Logger.getLogger(W32ServiceTest.class.getName()).log(Level.SEVERE, null, ex);
sb.append(f.getAbsolutePath());
}
} catch (URISyntaxException ex) {
Logger.getLogger(W32ServiceTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
invocation = String.format("java.exe -cp %s com.sun.jna.platform.win32.Win32ServiceDemo", sb.toString());
System.out.println("Invocation: " + invocation);
} else {
throw new IllegalStateException("Classloader loading Win32ServiceDemo must be an URLClassLoader");
}
invocation = String.format("java.exe -cp %s com.sun.jna.platform.win32.Win32ServiceDemo", sb.toString());
System.out.println("Invocation: " + invocation);

SERVICE_DESCRIPTION desc = new SERVICE_DESCRIPTION();
desc.lpDescription = description;
Expand Down
1 change: 1 addition & 0 deletions src/com/sun/jna/win32/DLLCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
*/
public interface DLLCallback extends Callback {
/** Total number of DLL callbacks available for allocation. */
@java.lang.annotation.Native
int DLL_FPTRS = 16;
}

0 comments on commit 5283b2b

Please sign in to comment.