Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions libtest/struct/NumericStruct.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,16 @@ GET_VAL(pointer);
int struct_num_size() {
return sizeof(NumericStruct);
}

long struct_num_al_test(FfiStrList s) {
return s.count;
}
/*
This will work but I don't have access to the original code and I rather not create a wrapper in c
int struct_num_al_test(FfiStrList *s) {
return struct_num_al_test_internal(*s);
}

int struct_num_al_test_internal(FfiStrList s) {
return s.count;
}*/
9 changes: 9 additions & 0 deletions libtest/struct/StructTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@ typedef union NestedUnion_t {
NumericStruct *ptr_NumericStruct;
NumericUnion *ptr_NumericUnion;
} NestedUnion;

typedef const char *FfiStr;

typedef struct FfiList_FfiStr {
size_t count;
} FfiList_FfiStr;

typedef struct FfiList_FfiStr FfiStrList;

21 changes: 21 additions & 0 deletions src/test/java/jnr/ffi/struct/NumericStructTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public class NumericStructTest {

public enum Enum {e0, e1, e2, e3}

public static class FfiStrList extends Struct {
//public final UTF8String count = new UTF8String(32); <-- works as per example
public final Struct.LONG count = new Struct.LONG(); //<-- not working
//public final PointerByReference data; //TODO add in rest of structure
//public final Struct.Pointer[] data; // Or this ???
public FfiStrList(jnr.ffi.Runtime runtime /*, java.lang.String[] sAry*/) {
super(runtime);
}
}

public static class NumericStruct extends Struct {
public final Struct.Signed8 val_int8_t = new Struct.Signed8();
public final Struct.Signed16 val_int16_t = new Struct.Signed16();
Expand Down Expand Up @@ -87,6 +97,8 @@ public void reset() {
}

public static interface Lib {

public long struct_num_al_test(FfiStrList s);
public byte struct_num_get_int8_t(NumericStruct s);
public void struct_num_set_int8_t(NumericStruct s, byte v);

Expand Down Expand Up @@ -145,6 +157,15 @@ public static void beforeAll() {
runtime = Runtime.getRuntime(lib);
}

@Test
public void testAlNumeric() {
FfiStrList s = new FfiStrList(runtime);
s.count.set(34);

long r = lib.struct_num_al_test(s);
assertEquals(34, r);
}

// ========================= Byte ===============================

@Test
Expand Down