You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public static enum Enumeration {
STATUS_0(0), STATUS_1(1), STATUS_ERROR(-1);
private final int code;
Enumeration(int code) { this.code = code; }
public int getCode() { return code; }
public static Enumeration fromCode(int code) {
switch(code) {
case 0: return STATUS_0;
case 1: return STATUS_1;
default: return STATUS_ERROR;
}
}
}
public static class DirectTypeMappedEnumerationTestLibrary {
public native Enumeration returnInt32Argument(Enumeration e);
static {
DefaultTypeMapper mapper = new DefaultTypeMapper();
mapper.addTypeConverter(Enumeration.class, new TypeConverter() {
public Object toNative(Object arg, ToNativeContext ctx) {
return new Integer(((Enumeration)arg).getCode());
}
public Object fromNative(Object value, FromNativeContext context) {
return Enumeration.fromCode(((Integer)value).intValue());
}
public Class nativeType() {
return Integer.class;
}
});
Map options = new HashMap();
options.put(Library.OPTION_TYPE_MAPPER, mapper);
Native.register(NativeLibrary.getInstance("testlib", options));
}
}
public void testEnumerationConversion() {
DirectTypeMappedEnumerationTestLibrary lib = new DirectTypeMappedEnumerationTestLibrary();
Enumeration e = lib.returnInt32Argument(Enumeration.STATUS_1);
assertEquals("Failed to convert enumeration", Enumeration.STATUS_1, e);
}
java -cp build/classes:build/test-classes:lib/junit.jar -Djna.library.path=build/native-darwin com.sun.jna.DirectTypeMapperTest
..E.....
Time: 0.06
There was 1 error:
1) testEnumerationConversion(com.sun.jna.DirectTypeMapperTest)java.lang.ExceptionInInitializerError
at com.sun.jna.DirectTypeMapperTest.testEnumerationConversion(DirectTypeMapperTest.java:225)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at com.sun.jna.DirectTypeMapperTest.main(DirectTypeMapperTest.java:231)
Caused by: java.lang.IllegalArgumentException: Unsupported Structure field type class com.sun.jna.DirectTypeMapperTest$Enumeration
at com.sun.jna.Structure$FFIType.get(Structure.java:1843)
at com.sun.jna.Structure$FFIType.get(Structure.java:1798)
at com.sun.jna.Native.register(Native.java:1447)
at com.sun.jna.Native.register(Native.java:1175)
at com.sun.jna.DirectTypeMapperTest$DirectTypeMappedEnumerationTestLibrary.<clinit>(DirectTypeMapperTest.java:221)
... 18 more
FAILURES!!!
Tests run: 7, Failures: 0, Errors: 1
The text was updated successfully, but these errors were encountered:
Sample failing test case:
The text was updated successfully, but these errors were encountered: