Skip to content

Commit

Permalink
Found and fixed duplicate method definitions for the same API
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyor Goldstein committed Aug 6, 2015
1 parent ab7eea6 commit 403360d
Show file tree
Hide file tree
Showing 9 changed files with 996 additions and 982 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Features
* Loosen OSGI OS name matching to accommodate Windows 8 family - Niels Bertram.
* [#436] (https://github.com/twall/jna/pull/469): Added basic Pdh API implementation to 'com.sun.jna.platform.win32' - [@lgoldstein](https://github.com/lgoldstein).
* [#481] (https://github.com/twall/jna/pull/481): Added volume management functions to 'com.sun.jna.platform.win32' - [@lgoldstein](https://github.com/lgoldstein).
* [#483] (https://github.com/twall/jna/pull/483): Found and fixed duplicate method definitions for the same API in 'com.sun.jna.platform.win32' - [@lgoldstein](https://github.com/lgoldstein).

Bug Fixes
---------
Expand Down
584 changes: 235 additions & 349 deletions contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java

Large diffs are not rendered by default.

607 changes: 270 additions & 337 deletions contrib/platform/src/com/sun/jna/platform/win32/User32.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,52 @@
*/
package com.sun.jna.platform.win32;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import com.sun.jna.platform.AbstractPlatformTestSupport;
import com.sun.jna.platform.win32.WinNT.HANDLE;

/**
* @author lgoldstein
*/
public abstract class AbstractWin32TestSupport extends AbstractPlatformTestSupport {
protected AbstractWin32TestSupport() {
super();
}

/**
* Makes sure that the method names (which represent APIs) do not repeat
* themselves. This check is in order where APIs are WIN32 API <U>functions</U>
* since these are C functions - which means no overloading is possible.
*
* @param ifc The interface (not checked) class to test
* @see #detectDuplicateMethods(Class)
*/
public static final void assertNoDuplicateMethodsNames(Class<?> ifc) {
Collection<String> dupSet = detectDuplicateMethods(ifc);
assertTrue("Duplicate names found in " + ifc.getSimpleName() + ": " + dupSet, dupSet.isEmpty());
}

/**
* Checks if there are methods with the same name - regardless of the signature
*
* @param ifc The interface (not checked) class to test
* @return The {@link Set} of duplicate names - empty if no duplicates
*/
public static final Set<String> detectDuplicateMethods(Class<?> ifc) {
Method[] methods = ifc.getMethods();
Set<String> nameSet = new HashSet<String>(methods.length);
Set<String> dupSet = new HashSet<String>();
for (Method m : methods) {
String name = m.getName();
if (!nameSet.add(name)) {
dupSet.add(name);
}
}

return dupSet;
}

/**
* Checks if the API call result is {@code true}. If not, then calls
* {@link Kernel32#GetLastError()} and fails with the error code.
Expand All @@ -35,15 +70,15 @@ public static final void assertCallSucceeded(String message, boolean result) {
if (result) {
return;
}

int hr = Kernel32.INSTANCE.GetLastError();
if (hr == WinError.ERROR_SUCCESS) {
fail(message + " failed with unknown reason code");
} else {
fail(message + " failed: hr=" + hr + " - 0x" + Integer.toHexString(hr));
}
}

/**
* Checks if the status code is ERROR_SUCCESS
* @param message Message to display if code is an error
Expand All @@ -59,7 +94,7 @@ public static final void assertErrorSuccess(String message, int statusCode, bool
assertEquals(message, WinError.ERROR_SUCCESS, statusCode);
}
}

/**
* Makes sure that the handle argument is not {@code null} or {@link WinBase#INVALID_HANDLE_VALUE}.
* If invalid handle detected, then it invokes {@link Kernel32#GetLastError()}
Expand Down
Loading

0 comments on commit 403360d

Please sign in to comment.