twall/jna — pull request #183 by bhamail (2013-01-24 07:49:27+00:00)
Title: Test Structure.getFieldOrder()

We've seen a number of problems with missing or outdated Structure.getFieldOrder() implementations, so I put together a unit test (and reusable unit test utility class) that scans for Structure sub types and flags problematic getFieldOrder() implementations.

I used the "Reflections" library to do this, and put it's libs in a new "lib/test" sub folder (to keep them outta the distro).

Currently, the scan shows no problems in the core jna project, but there appear to be a number of problems (23) in the platform tree. If we commit this right now, the platform build will start failing due to these problems. I have pasted the output of these scans below. Maybe some of these are false alarms, but I'm pretty sure some of them are genuine problems.
Should we commit, and fix? Or fix, then commit?

Dan

```
java.lang.RuntimeException: Some Structure sub types (23) have problems with getFieldOrder():
com.sun.jna.platform.win32.WinUser$INPUT.getFieldOrder() [[type, input]] does not include declared field: INPUT_MOUSE;
Could not instantiate Structure sub type: com.sun.jna.platform.win32.DBT$DEV_BROADCAST_HANDLE;
The Structure sub type: com.sun.jna.platform.win32.WinNT$ACE_HEADER must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.Sspi$TimeStamp must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.unix.X11$XPointerMovedEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.WinNT$ACCESS_DENIED_ACE must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.Sspi$CtxtHandle must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
com.sun.jna.platform.win32.WinBase$FILETIME.getFieldOrder() [[dwLowDateTime, dwHighDateTime]] does not include declared field: EPOCH_DIFF;
Parameterless constructor failed on Structure sub type: com.sun.jna.platform.win32.WinNT$TOKEN_PRIVILEGES;
com.sun.jna.platform.win32.WinNT$SECURITY_DESCRIPTOR_RELATIVE.getFieldOrder() [[Revision, Sbz1, Control, Owner, Group, Sacl, Dacl]] does not include declared field: DACL;
The Structure sub type: com.sun.jna.platform.unix.X11$XButtonReleasedEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
com.sun.jna.platform.win32.WinUser$KEYBDINPUT.getFieldOrder() [[wVk, wScan, dwFlags, time, dwExtraInfo]] does not include declared field: KEYEVENTF_EXTENDEDKEY;
The Structure sub type: com.sun.jna.platform.unix.X11$XFocusOutEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.unix.X11$XLeaveWindowEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.WinNT$ACCESS_ALLOWED_ACE must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.win32.Sspi$CredHandle must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
Parameterless constructor failed on Structure sub type: com.sun.jna.platform.win32.WinGDI$RGNDATA;
com.sun.jna.platform.win32.WinNT$ACL.getFieldOrder() [[AclRevision, Sbz1, AclSize, AceCount, Sbz2]] does not include declared field: ACEs;
The Structure sub type: com.sun.jna.platform.unix.X11$XEnterWindowEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
The Structure sub type: com.sun.jna.platform.unix.X11$XButtonPressedEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
Could not instantiate Structure sub type: com.sun.jna.platform.win32.DBT$DEV_BROADCAST_PORT;
The Structure sub type: com.sun.jna.platform.unix.X11$XFocusInEvent must define the method: getFieldOrder(). See the javadoc for Structure.getFieldOrder() for details.;
Could not instantiate Structure sub type: com.sun.jna.platform.win32.LMAccess$GROUP_INFO_3;

at com.sun.jna.StructureFieldOrderInspector.batchCheckStructureGetFieldOrder(StructureFieldOrderInspector.java:55)
at com.sun.jna.platform.StructureFieldOrderTest.testMethodGetFieldOrder(StructureFieldOrderTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:139)
at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:52)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
'''