It may be just my ignorance so apologies in advance if that's the case, but would still appreciate someone pointing me in the right direction!
I'm having problems with the BridJ output from JNAerator for enums.
// === C HEader File ===
typedef enum
{
None = 0,
Apple = 1,
Pear = 2,
Orange = 4,
Banana = 8
} Fruit;
void getFruit(Fruit* fruit);
// ===================
// JNAerate the above header with
JNAERATOR="/Tools/JNAerator/jnaerator-0.12-SNAPSHOT-20130323-2.jar"
java -jar $JNAERATOR -runtime BridJ -jar FruitSalad.jar -direct -library fruitsalad -mode StandaloneJar Headers/*.h
// Now I find the following problems when I attempt to use the jnaerated java classes (demonstrated in this test app)
import junit.framework.Assert;
import org.bridj.IntValuedEnum;
import org.bridj.Pointer;
import org.junit.Test;
import fruitsalad.FruitsaladLibrary;
import fruitsalad.FruitsaladLibrary.Fruit;
public class TestFruitSalad {
@Test
public final void testEnumAllocation() {
/*
* Java compile fails on the following with:
*
* The method getFruit(Pointer<IntValuedEnum<FruitsaladLibrary.Fruit>>) in the type
* FruitsaladLibrary is not applicable for the arguments (Pointer<FruitsaladLibrary.Fruit>)
*/
Pointer<Fruit> pFruit = Pointer.allocate(Fruit.class);
FruitsaladLibrary.getFruit(pFruit);
}
@Test
public final void testEnumPointerTo1() {
/*
* Java compile fails on the following with:
*
* Bound mismatch: The generic method pointerTo(N) of type Pointer<T> is not applicable for
* the arguments (FruitsaladLibrary.Fruit). The inferred type FruitsaladLibrary.Fruit is not
* a valid substitute for the bounded parameter <N extends NativeObject>
*/
Fruit fruit = Fruit.Apple;
Pointer<Fruit> pFruit = Pointer.pointerTo(fruit);
FruitsaladLibrary.getFruit(pFruit);
}
@Test
public final void testEnumPointerTo2() {
/*
* Java compile fails on the following with:
*
* Multiple markers at this line - Type mismatch: cannot convert from
* Pointer<FruitsaladLibrary.Fruit> to Pointer<IntValuedEnum<FruitsaladLibrary.Fruit>> -
* Bound mismatch: The generic method pointerTo(N) of type Pointer<T> is not applicable for
* the arguments (FruitsaladLibrary.Fruit). The inferred type FruitsaladLibrary.Fruit is not
* a valid substitute for the bounded parameter <N extends NativeObject>
*/
Fruit fruit = Fruit.Apple;
Pointer<IntValuedEnum<Fruit>> pFruit = Pointer.pointerTo(fruit);
FruitsaladLibrary.getFruit(pFruit);
}
@Test
public final void testEnumEquality() {
IntValuedEnum<Fruit> fruit = Fruit.fromValue(8);
System.out.printf("fruit is null -> %s\n", fruit == null); // OK
System.out.printf("fruit class=%s\n", fruit.getClass().getName()); // OK
System.out.printf("fruit.value()= %d\n", fruit.value()); // OK
System.out.printf("fruit=%s\n", fruit.toString()); // FAILS
Assert.assertTrue("fruit2.value == Fruit.Banana.value", Fruit.Banana.value == fruit.value()); // SUCCEEDS
Assert.assertTrue("fruit2.equals(Fruit.Banana)", Fruit.Banana == fruit); // FAILS
}
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4