Skip to content

Commit d033fb4

Browse files
authored
Fix some windows test failures (#1305)
1 parent ee4df00 commit d033fb4

File tree

3 files changed

+32
-38
lines changed

3 files changed

+32
-38
lines changed

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

+13-9
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,19 @@ public void testLookupAccountName() {
143143
String accountName = "Administrator";
144144
assertFalse(Advapi32.INSTANCE.LookupAccountName(
145145
null, accountName, null, pSid, null, pDomain, peUse));
146-
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
147-
assertTrue(pSid.getValue() > 0);
148-
Memory sidMemory = new Memory(pSid.getValue());
149-
PSID pSidMemory = new PSID(sidMemory);
150-
char[] referencedDomainName = new char[pDomain.getValue() + 1];
151-
assertTrue(Advapi32.INSTANCE.LookupAccountName(
152-
null, accountName, pSidMemory, pSid, referencedDomainName, pDomain, peUse));
153-
assertEquals(SID_NAME_USE.SidTypeUser, peUse.getPointer().getInt(0));
154-
assertTrue(Native.toString(referencedDomainName).length() > 0);
146+
int lastError = Kernel32.INSTANCE.GetLastError();
147+
// The Administrator account may not exist
148+
if (lastError != W32Errors.ERROR_NONE_MAPPED) {
149+
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, lastError);
150+
assertTrue(pSid.getValue() > 0);
151+
Memory sidMemory = new Memory(pSid.getValue());
152+
PSID pSidMemory = new PSID(sidMemory);
153+
char[] referencedDomainName = new char[pDomain.getValue() + 1];
154+
assertTrue(Advapi32.INSTANCE.LookupAccountName(null, accountName, pSidMemory, pSid, referencedDomainName,
155+
pDomain, peUse));
156+
assertEquals(SID_NAME_USE.SidTypeUser, peUse.getPointer().getInt(0));
157+
assertTrue(Native.toString(referencedDomainName).length() > 0);
158+
}
155159
}
156160

157161
public void testIsValidSid() {

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

+12-25
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static com.sun.jna.platform.win32.IPHlpAPI.AF_INET;
2727
import static com.sun.jna.platform.win32.IPHlpAPI.AF_INET6;
2828
import static org.junit.Assert.assertEquals;
29+
import static org.junit.Assert.assertNotEquals;
2930
import static org.junit.Assert.assertTrue;
3031

3132
import java.math.BigInteger;
@@ -66,25 +67,18 @@ public void testGetIfEntry() throws SocketException {
6667
MIB_IFROW ifRow = new MIB_IFROW();
6768
ifRow.dwIndex = netint.getIndex();
6869
assertEquals(WinError.NO_ERROR, IPHLP.GetIfEntry(ifRow));
69-
// Bytes should exceed packets
7070
// These originate from unsigned ints. Use standard Java
7171
// widening conversion to long which does sign-extension,
7272
// then drop any copies of the sign bit, to prevent the value
7373
// being considered a negative one by Java if it is set
74-
long bytesSent = (ifRow.dwOutOctets) & 0xffffffffL;
75-
long packetsSent = (ifRow.dwOutUcastPkts) & 0xffffffffL;
76-
if (packetsSent > 0) {
77-
assertTrue(bytesSent > packetsSent);
78-
} else {
79-
assertEquals(0, bytesSent);
80-
}
81-
long bytesRecv = (ifRow.dwInOctets) & 0xffffffffL;
82-
long packetsRecv = (ifRow.dwInUcastPkts) & 0xffffffffL;
83-
if (packetsRecv > 0) {
84-
assertTrue(bytesRecv > packetsRecv);
85-
} else {
86-
assertEquals(0, bytesRecv);
87-
}
74+
long bytesSent = ifRow.dwOutOctets & 0xffffffffL;
75+
long packetsSent = ifRow.dwOutUcastPkts & 0xffffffffL;
76+
long bytesRecv = ifRow.dwInOctets & 0xffffffffL;
77+
long packetsRecv = ifRow.dwInUcastPkts & 0xffffffffL;
78+
// Bytes should match or exceed minimum packet size of 20.
79+
// It is possible to have bytes not part of a packet but not vice versa.
80+
assertTrue(bytesSent >= packetsSent * 20L);
81+
assertTrue(bytesRecv >= packetsRecv * 20L);
8882
}
8983
}
9084

@@ -105,18 +99,11 @@ public void testGetIfEntry2() throws SocketException {
10599
// These originate from unsigned longs.
106100
BigInteger bytesSent = new BigInteger(Long.toHexString(ifRow.OutOctets), 16);
107101
BigInteger packetsSent = new BigInteger(Long.toHexString(ifRow.OutUcastPkts), 16);
108-
if (packetsSent.longValue() > 0) {
109-
assertEquals(1, bytesSent.compareTo(packetsSent));
110-
} else {
111-
assertEquals(0, bytesSent.compareTo(packetsSent));
112-
}
113102
BigInteger bytesRecv = new BigInteger(Long.toHexString(ifRow.InOctets), 16);
114103
BigInteger packetsRecv = new BigInteger(Long.toHexString(ifRow.InUcastPkts), 16);
115-
if (packetsRecv.longValue() > 0) {
116-
assertEquals(1, bytesRecv.compareTo(packetsRecv));
117-
} else {
118-
assertEquals(0, bytesRecv.compareTo(packetsRecv));
119-
}
104+
BigInteger minPacketSize = BigInteger.valueOf(20);
105+
assertNotEquals(-1, bytesSent.compareTo(packetsSent.multiply(minPacketSize)));
106+
assertNotEquals(-1, bytesRecv.compareTo(packetsRecv.multiply(minPacketSize)));
120107
}
121108
}
122109
} else {

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ private Object[] toArrayGetElement(SAFEARRAY wrap) {
198198
wrap.lock();
199199
int rowMax = wrap.getUBound(2);
200200
int columnMax = wrap.getUBound(1);
201-
Object[][] result = new Object[(int) (rowMax + 1)][(int) (columnMax + 1)];
201+
Object[][] result = new Object[rowMax + 1][columnMax + 1];
202202
for(int i = 0; i <= rowMax; i++) {
203203
for(int j = 0; j <= columnMax; j++) {
204204
VARIANT cell = (VARIANT) wrap.getElement(i, j);
205-
result[(int)i][(int) j] = cell.getValue();
205+
result[i][j] = cell.getValue();
206206
OleAuto.INSTANCE.VariantClear(cell);
207207
}
208208
}
@@ -214,11 +214,11 @@ private Object[] toArrayPtrToElement(SAFEARRAY wrap) {
214214
wrap.lock();
215215
int rowMax = wrap.getUBound(2);
216216
int columnMax = wrap.getUBound(1);
217-
Object[][] result = new Object[(int) (rowMax + 1)][(int) (columnMax + 1)];
217+
Object[][] result = new Object[rowMax + 1][columnMax + 1];
218218
for(int i = 0; i <= rowMax; i++) {
219219
for(int j = 0; j <= columnMax; j++) {
220220
VARIANT cell = new VARIANT(wrap.ptrOfIndex(i, j));
221-
result[(int)i][(int) j] = cell.getValue();
221+
result[i][j] = cell.getValue();
222222
}
223223
}
224224
wrap.unlock();
@@ -498,6 +498,7 @@ public void testDataTypes() {
498498
* Test assumption: The windows search provider is present and holds at least
499499
* five entries. If this assumption is not met, this test fails.
500500
*/
501+
@Ignore("Assumes windows search provider present with five entries")
501502
@Test
502503
public void testADODB() {
503504
ObjectFactory fact = new ObjectFactory();
@@ -770,6 +771,7 @@ private CursorTypeEnum(long value) {
770771
}
771772
private long value;
772773

774+
@Override
773775
public long getValue() {
774776
return this.value;
775777
}
@@ -791,6 +793,7 @@ private LockTypeEnum(long value) {
791793
}
792794
private long value;
793795

796+
@Override
794797
public long getValue() {
795798
return this.value;
796799
}

0 commit comments

Comments
 (0)