Skip to content

Commit 3cbfbbc

Browse files
committed
Fixes #12
Added tests for shared environment Add system headers parsing option Fixed test variables Fixed issue with alignment (4-bytes by default)
1 parent ebf83d4 commit 3cbfbbc

File tree

21 files changed

+184
-101
lines changed

21 files changed

+184
-101
lines changed

annotation-processor-test/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ jar {
2727

2828
test {
2929
useJUnitPlatform()
30-
jvmArgs ['--enable-native-access=ALL_UNNAMED']
30+
jvmArgs "--enable-native-access=ALL-UNNAMED"
3131
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
systemProp.version=6.2.0-39

annotation-processor-test/src/test/java/io/github/digitalsmile/gpio/libcurl/Libcurl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@NativeMemory(headers = "libcurl/curl/include/curl/curl.h")
1717
@NativeMemoryOptions(systemIncludes = {
1818
"/usr/lib/gcc/x86_64-linux-gnu/12/include/"
19-
}, debugMode = true)
19+
}, debugMode = true, processRootConstants = true)
2020
@Structs({
2121
@Struct(name = "CURL", javaName = "CurlInstance")
2222
})

annotation-processor-test/src/test/java/io/github/digitalsmile/gpio/libcurl/LibcurlTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ public class LibcurlTest {
1010

1111
@Test
1212
public void libcurl() throws NativeMemoryException {
13-
var libcurl = new LibcurlNative();
14-
var code = libcurl.globalInit(CurlConstants.CURL_GLOBAL_DEFAULT);
15-
assertEquals(code, CURLcode.CURLE_OK);
16-
var curl = libcurl.easyInit();
17-
code = libcurl.easySetOpt(curl, CURLoption.CURLOPT_URL, "https://example.com");
18-
assertEquals(code, CURLcode.CURLE_OK);
19-
code = libcurl.easySetOpt(curl, CURLoption.CURLOPT_FOLLOWLOCATION, 1L);
20-
assertEquals(code, CURLcode.CURLE_OK);
13+
try(var libcurl = new LibcurlNative()) {
14+
var code = libcurl.globalInit(CurlConstants.CURL_GLOBAL_DEFAULT);
15+
assertEquals(code, CURLcode.CURLE_OK);
16+
var curl = libcurl.easyInit();
17+
code = libcurl.easySetOpt(curl, CURLoption.CURLOPT_URL, "https://example.com");
18+
assertEquals(code, CURLcode.CURLE_OK);
19+
code = libcurl.easySetOpt(curl, CURLoption.CURLOPT_FOLLOWLOCATION, 1L);
20+
assertEquals(code, CURLcode.CURLE_OK);
2121

22-
code = libcurl.easyPerform(curl);
23-
assertEquals(code, CURLcode.CURLE_OK);
22+
code = libcurl.easyPerform(curl);
23+
assertEquals(code, CURLcode.CURLE_OK);
24+
}
2425
}
2526
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.github.digitalsmile.gpio.shared;
2+
3+
4+
import io.github.digitalsmile.gpio.shared.structs.Stat;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.nio.file.Path;
8+
import java.util.Objects;
9+
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
12+
public class SharedTest {
13+
14+
@Test
15+
public void shared() throws Throwable {
16+
var file = Path.of(Objects.requireNonNull(SharedTest.class.getResource("/shared/test1.h")).toURI()).toFile().getAbsolutePath();
17+
int fd;
18+
try (var fileLib = new SharedTestOneNative()) {
19+
fd = fileLib.open(file, 0);
20+
}
21+
22+
try (var statLib = new SharedTestTwoNative()) {
23+
var stats = statLib.stat(fd, Stat.createEmpty());
24+
assertEquals(stats.stSize(), 35);
25+
}
26+
}
27+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.github.digitalsmile.gpio.shared;
2+
3+
import io.github.digitalsmile.annotation.ArenaType;
4+
import io.github.digitalsmile.annotation.NativeMemory;
5+
import io.github.digitalsmile.annotation.NativeMemoryException;
6+
import io.github.digitalsmile.annotation.NativeMemoryOptions;
7+
import io.github.digitalsmile.annotation.function.NativeManualFunction;
8+
import io.github.digitalsmile.annotation.structure.Structs;
9+
10+
@NativeMemory(headers = "shared/test1.h")
11+
@NativeMemoryOptions(arena = ArenaType.CONFINED)
12+
@Structs
13+
public interface SharedTestOne {
14+
15+
@NativeManualFunction(name = "open64")
16+
int open(String path, int openFlag) throws NativeMemoryException;
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.github.digitalsmile.gpio.shared;
2+
3+
import io.github.digitalsmile.annotation.NativeMemory;
4+
import io.github.digitalsmile.annotation.NativeMemoryException;
5+
import io.github.digitalsmile.annotation.NativeMemoryOptions;
6+
import io.github.digitalsmile.annotation.function.NativeManualFunction;
7+
import io.github.digitalsmile.annotation.function.Returns;
8+
import io.github.digitalsmile.annotation.structure.Struct;
9+
import io.github.digitalsmile.annotation.structure.Structs;
10+
import io.github.digitalsmile.gpio.shared.structs.Stat;
11+
12+
@NativeMemory(headers = "/usr/include/x86_64-linux-gnu/sys/stat.h")
13+
@NativeMemoryOptions(systemHeader = true)
14+
@Structs(
15+
@Struct(name = "stat")
16+
)
17+
public interface SharedTestTwo {
18+
19+
@NativeManualFunction(name = "fstat")
20+
Stat stat(int fd, @Returns Stat stat) throws NativeMemoryException;
21+
}

annotation-processor-test/src/test/java/io/github/digitalsmile/gpio/GPIOTest.java renamed to annotation-processor-test/src/test/java/io/github/digitalsmile/gpio/types/all/GPIOTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
package io.github.digitalsmile.gpio;
1+
package io.github.digitalsmile.gpio.types.all;
22

3-
import io.github.digitalsmile.gpio.types.all.*;
43
import io.github.digitalsmile.gpio.types.all.structs.*;
5-
import io.github.digitalsmile.gpio.types.all.enums.*;
64
import org.junit.jupiter.api.Test;
75

86
import java.lang.foreign.Arena;

annotation-processor-test/src/test/java/io/github/digitalsmile/gpio/types/all/GPIOTypesAll.java

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,4 @@
1414
@Enums
1515
@Unions
1616
public interface GPIOTypesAll {
17-
}
18-
19-
//@NativeMemory(headers = "/usr/src/linux-headers-6.2.0-39/include/uapi/linux/gpio.h")
20-
//@NativeMemoryOptions(
21-
// processRootConstants = true
22-
//)
23-
//@Structs({
24-
// @Struct(name = "gpiochip_info", javaName = "ChipInfo"),
25-
// @Struct(name = "gpio_v2_line_attribute", javaName = "LineAttribute"),
26-
// @Struct(name = "gpio_v2_line_config", javaName = "LineConfig"),
27-
// @Struct(name = "gpio_v2_line_config_attribute", javaName = "LineConfigAttribute"),
28-
// @Struct(name = "gpio_v2_line_event", javaName = "LineEvent"),
29-
// @Struct(name = "gpio_v2_line_info", javaName = "LineInfo"),
30-
// @Struct(name = "gpio_v2_line_request", javaName = "LineRequest"),
31-
// @Struct(name = "gpio_v2_line_values", javaName = "LineValues")
32-
//})
33-
//@Enums({
34-
// @Enum(name = "gpio_v2_line_event_id", javaName = "LineEventId")
35-
//})
36-
////@Enums
37-
//public interface GPIOTypesPrimitives {
38-
//
39-
// @Function(name = "ioctl", useErrno = true, returnType = int.class)
40-
// ChipInfo nativeCall(int fd, long command, @Returns ChipInfo data) throws NativeMemoryException;
41-
//
42-
// @Function(name = "ioctl", useErrno = true, returnType = ChipInfo.class)
43-
// ChipInfo nativeCall(int fd, double command, @Returns ChipInfo data) throws NativeMemoryException;
44-
//
45-
// @Function(name = "ioctl", useErrno = true)
46-
// void nativeCall2(int fd, double command, ChipInfo data) throws NativeMemoryException;
47-
//
48-
// @Function(name = "ioctl", useErrno = true, returnType = float.class)
49-
// float nativeCall2(int fd, long command, int data) throws NativeMemoryException;
50-
//
51-
// @Function(name = "ioctl", useErrno = true, returnType = float.class)
52-
// float nativeCall2(int fd, long command, float data) throws NativeMemoryException;
53-
//
54-
// @Function(name = "ioctl", useErrno = true)
55-
// void nativeCall2(double fd, long command, float data) throws NativeMemoryException;
56-
//}
57-
58-
59-
//@NativeMemory(headers = "/home/ds/vlc/include/vlc/vlc.h")
60-
//@NativeMemoryOptions(includes = {
61-
// "/home/ds/vlc/include",
62-
// "/usr/lib/llvm-15/lib/clang/15.0.7/include/"
63-
//})
64-
//@Structs
65-
//@Enums
66-
//@Unions
67-
//public interface LibVLC {
68-
//}
17+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
struct a {
2+
int x;
3+
int y;
4+
};

0 commit comments

Comments
 (0)