Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LARGE_INTEGER needs to populate both union fields #1196

Merged
merged 2 commits into from
May 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
}