Skip to content

Commit e94f781

Browse files
Lauri W Ahonendblock
authored andcommitted
Fix variant constructors, add a test that makes sure they now longer throw immediately
1 parent d6675fa commit e94f781

3 files changed

Lines changed: 47 additions & 8 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Bug Fixes
4545
* Fix publish doc links - [@bhamail](https://github.com/bhamail).
4646
* [#388](https://github.com/twall/jna/issues/388): Ensure native library always opened with provided flags - [@zolyfarkas](https://github.com/zolyfarkas).
4747
* [#403](https://github.com/twall/jna/pull/403): Fix `com.sun.jna.platform.win32.COM.COMUtils.SUCCEEDED` and `FAILED` - [@lwahonen](https://github.com/lwahonen).
48+
* [#404](https://github.com/twall/jna/pull/404): Fix `VARIANT` constructors for `int`, `short`, and `long` - [@lwahonen](https://github.com/lwahonen).
4849

4950
Release 4.1
5051
===========

contrib/platform/src/com/sun/jna/platform/win32/Variant.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,32 @@ public static class VARIANT extends Union {
116116

117117
public static class ByReference extends VARIANT implements
118118
Structure.ByReference {
119+
public ByReference(VARIANT variant) {
120+
setValue(variant.getVarType(), variant.getValue());
121+
}
122+
123+
public ByReference(Pointer variant) {
124+
super(variant);
125+
}
126+
127+
public ByReference() {
128+
super();
129+
}
130+
}
131+
132+
public static class ByValue extends VARIANT implements
133+
Structure.ByValue {
134+
public ByValue(VARIANT variant) {
135+
setValue(variant.getVarType(), variant.getValue());
136+
}
137+
138+
public ByValue(Pointer variant) {
139+
super(variant);
140+
}
141+
142+
public ByValue() {
143+
super();
144+
}
119145
}
120146

121147
public _VARIANT _variant;
@@ -170,17 +196,17 @@ public VARIANT(DATE value) {
170196

171197
public VARIANT(short value) {
172198
this();
173-
this.setValue(VT_I2, value);
199+
this.setValue(VT_I2, new SHORT(value));
174200
}
175201

176202
public VARIANT(int value) {
177203
this();
178-
this.setValue(VT_I4, value);
204+
this.setValue(VT_I4, new LONG(value));
179205
}
180206

181207
public VARIANT(long value) {
182208
this();
183-
this.setValue(VT_I8, value);
209+
this.setValue(VT_I8, new LONGLONG(value));
184210
}
185211

186212
public VARIANT(float value) {

contrib/platform/test/com/sun/jna/platform/win32/VariantTest.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.sun.jna.platform.win32.WinNT.HRESULT;
1111
import com.sun.jna.ptr.DoubleByReference;
1212

13+
import java.util.Date;
14+
1315
public class VariantTest extends TestCase {
1416

1517
public static void main(String[] args) {
@@ -56,15 +58,25 @@ public void testVariantDate() {
5658

5759
VARIANT variantDate = new VARIANT(new DATE(pvtime.getValue()));
5860
}
59-
61+
6062
public void testVariantRecord() {
61-
VARIANT._VARIANT.__VARIANT.BRECORD pvRecord = new VARIANT._VARIANT.__VARIANT.BRECORD();
63+
VARIANT._VARIANT.__VARIANT.BRECORD pvRecord = new VARIANT._VARIANT.__VARIANT.BRECORD();
6264
VARIANT._VARIANT.__VARIANT.BRECORD pvRecord2;
63-
65+
6466
VARIANT variant = new VARIANT();
6567
variant.setValue(Variant.VT_RECORD, pvRecord);
66-
68+
6769
pvRecord2 = (VARIANT._VARIANT.__VARIANT.BRECORD)variant.getValue();
6870
}
69-
71+
72+
public void testVariantConstructors() {
73+
VARIANT variant = new VARIANT((short) 1);
74+
variant = new VARIANT((int) 1);
75+
variant = new VARIANT((long) 1);
76+
variant = new VARIANT((float) 1);
77+
variant = new VARIANT((double) 1);
78+
variant = new VARIANT("1");
79+
variant = new VARIANT(true);
80+
variant = new VARIANT(new Date());
81+
}
7082
}

0 commit comments

Comments
 (0)