diff --git a/CHANGES.md b/CHANGES.md index 05c3720a1b..8fe435c716 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ Bug Fixes --------- * [#1183](https://github.com/java-native-access/jna/pull/1183): `c.s.j.p.win32.WinDef.CHARByReference#getValue` should only read one byte - [@dbwiddis](https://github.com/dbwiddis). * [#1184](https://github.com/java-native-access/jna/pull/1184): `c.s.j.p.win32.WinDef.ULONGLONG` should always be 8 bytes - [@dbwiddis](https://github.com/dbwiddis). +* [#1196](https://github.com/java-native-access/jna/pull/1196): `c.s.j.p.win32.WinNT.LARGE_INTEGER` needs to populate both union fields - [@dbwiddis](https://github.com/dbwiddis). Release 5.5.0 ============= diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java b/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java index aa3f79eb67..2a28d33a3b 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java @@ -1220,6 +1220,12 @@ public UNION(long value) { this.lh = new LowHigh(value); } + @Override + public void read() { + readField("lh"); + readField("value"); + } + public long longValue() { return value; } diff --git a/contrib/platform/test/com/sun/jna/platform/win32/WinNTTypesTest.java b/contrib/platform/test/com/sun/jna/platform/win32/WinNTTypesTest.java index 2eff9335f4..2bdac2b7c5 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/WinNTTypesTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/WinNTTypesTest.java @@ -25,10 +25,24 @@ import org.junit.Test; +import com.sun.jna.Memory; +import com.sun.jna.Pointer; +import com.sun.jna.Structure; +import com.sun.jna.Structure.FieldOrder; import com.sun.jna.platform.win32.WinNT.LARGE_INTEGER; public class WinNTTypesTest extends AbstractWin32TestSupport { + @FieldOrder({ "largeInt" }) + public class LargeIntegerStruct extends Structure { + public LARGE_INTEGER largeInt; + + public LargeIntegerStruct(Pointer p) { + super(p); + read(); + } + } + @Test public void testLargeIntegerLowHighLongValue() { for (long expected : new long[]{ @@ -47,12 +61,21 @@ public void testLargeIntegerUnionLongValue() { 0L, Long.MAX_VALUE, Integer.MAX_VALUE, Short.MAX_VALUE, Byte.MAX_VALUE }) { + // test with long constructor LARGE_INTEGER large = new LARGE_INTEGER(expected); assertEquals("Mismatched large value", expected, large.getValue()); LARGE_INTEGER.LowHigh loHi = new LARGE_INTEGER.LowHigh(expected); assertEquals("Mismatched low part", loHi.LowPart, large.getLow()); assertEquals("Mismatched high part", loHi.HighPart, large.getHigh()); + + // test populated from memory + Memory m = new Memory(Long.BYTES); + m.setLong(0, expected); + large = new LargeIntegerStruct(m).largeInt; + assertEquals("Mismatched large value in struct", expected, large.getValue()); + assertEquals("Mismatched low part in struct", loHi.LowPart, large.getLow()); + assertEquals("Mismatched high part in struct", loHi.HighPart, large.getHigh()); } } }