Skip to content

Commit

Permalink
Merge pull request #1196 from dbwiddis/largeintfix
Browse files Browse the repository at this point in the history
LARGE_INTEGER needs to populate both union fields
  • Loading branch information
matthiasblaesing authored May 17, 2020
2 parents 90e7a14 + 76414e4 commit 2afa6da
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============
Expand Down
6 changes: 6 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 @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]{
Expand All @@ -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());
}
}
}

0 comments on commit 2afa6da

Please sign in to comment.