Skip to content

Commit abc8947

Browse files
committed
Bump version + fix typo on level. Enabled GPIO tests
1 parent 9ffb3ea commit abc8947

File tree

7 files changed

+111
-113
lines changed

7 files changed

+111
-113
lines changed

annotation-processor-test/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ repositories {
99
}
1010

1111
dependencies {
12-
testImplementation 'io.github.digitalsmile.native:annotation:1.1.3'
13-
testAnnotationProcessor 'io.github.digitalsmile.native:annotation-processor:1.1.3'
12+
testImplementation 'io.github.digitalsmile.native:annotation:1.1.4'
13+
testAnnotationProcessor 'io.github.digitalsmile.native:annotation-processor:1.1.4'
1414

1515
testImplementation platform('org.junit:junit-bom:5.10.0')
1616
testImplementation 'org.junit.jupiter:junit-jupiter'

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import io.github.digitalsmile.annotation.NativeMemoryOptions;
66
import io.github.digitalsmile.annotation.function.ByAddress;
77
import io.github.digitalsmile.annotation.function.NativeManualFunction;
8-
import io.github.digitalsmile.annotation.library.NativeFunction;
9-
import io.github.digitalsmile.annotation.library.NativeMemoryLibrary;
108
import io.github.digitalsmile.annotation.structure.Enum;
119
import io.github.digitalsmile.annotation.structure.Enums;
1210
import io.github.digitalsmile.annotation.structure.Struct;

annotation-processor-test/src/test/java/io/github/digitalsmile/gpio/libvlc/LibVLC.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package io.github.digitalsmile.gpio.libvlc;
22

33
import io.github.digitalsmile.annotation.NativeMemory;
4+
import io.github.digitalsmile.annotation.NativeMemoryException;
45
import io.github.digitalsmile.annotation.NativeMemoryOptions;
56
import io.github.digitalsmile.annotation.function.NativeManualFunction;
6-
import io.github.digitalsmile.annotation.NativeMemoryException;
77
import io.github.digitalsmile.annotation.structure.Enums;
88
import io.github.digitalsmile.annotation.structure.Structs;
99
import io.github.digitalsmile.annotation.structure.Unions;

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

Lines changed: 102 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -10,107 +10,107 @@
1010
import static org.junit.jupiter.api.Assertions.*;
1111

1212
public class GPIOTest {
13-
//
14-
// private static final byte[] STRING = "Test".getBytes();
15-
// private static final byte[] BYTE_ARRAY = new byte[]{0x01, 0x02, 0x03};
16-
// private static final int[] INT_ARRAY = new int[]{1, 2, 3};
17-
//
18-
// @Test
19-
// public void testGPIOV1AllTypes() {
20-
// try (var arena = Arena.ofConfined()) {
21-
// var chipInfo = new GpiochipInfo(STRING, STRING, 3);
22-
// var memoryBuffer = arena.allocate(chipInfo.getMemoryLayout());
23-
// chipInfo.toBytes(memoryBuffer);
24-
// var newChipInfo = GpiochipInfo.createEmpty().fromBytes(memoryBuffer);
25-
// assertArrayEquals(newChipInfo.name(), prepareByteArray(32, STRING));
26-
// assertArrayEquals(newChipInfo.label(), prepareByteArray(32, STRING));
27-
// assertEquals(newChipInfo.lines(), 3);
28-
// assertTrue(GpiochipInfo.createEmpty().isEmpty());
29-
//
30-
// assertEquals(GpioConstants.class.getFields().length, 40);
31-
//
32-
// //assertEquals(GpioConstants.values().length, 3);
33-
//
34-
// var eventData = new GpioeventData(100, 5);
35-
// memoryBuffer = arena.allocate(eventData.getMemoryLayout());
36-
// eventData.toBytes(memoryBuffer);
37-
// var newEventData = GpioeventData.createEmpty().fromBytes(memoryBuffer);
38-
// assertEquals(newEventData.timestamp(), 100);
39-
// assertEquals(newEventData.id(), 5);
40-
// assertTrue(GpioeventData.createEmpty().isEmpty());
41-
//
42-
// var eventRequest = new GpioeventRequest(1, 2, 3, STRING, 4);
43-
// memoryBuffer = arena.allocate(eventRequest.getMemoryLayout());
44-
// eventRequest.toBytes(memoryBuffer);
45-
// var newEventRequest = GpioeventRequest.createEmpty().fromBytes(memoryBuffer);
46-
// assertEquals(newEventRequest.lineoffset(), 1);
47-
// assertEquals(newEventRequest.handleflags(), 2);
48-
// assertEquals(newEventRequest.eventflags(), 3);
49-
// assertArrayEquals(newEventRequest.consumerLabel(), prepareByteArray(32, STRING));
50-
// assertEquals(newEventRequest.fd(), 4);
51-
// assertTrue(GpioeventRequest.createEmpty().isEmpty());
52-
//
53-
// var handleConfig = new GpiohandleConfig(1, BYTE_ARRAY, INT_ARRAY);
54-
// memoryBuffer = arena.allocate(handleConfig.getMemoryLayout());
55-
// handleConfig.toBytes(memoryBuffer);
56-
// var newHandleConfig = GpiohandleConfig.createEmpty().fromBytes(memoryBuffer);
57-
// assertEquals(newHandleConfig.flags(), 1);
58-
// assertArrayEquals(newHandleConfig.defaultValues(), prepareByteArray(64, BYTE_ARRAY));
59-
// assertArrayEquals(newHandleConfig.padding(), prepareIntArray(4, INT_ARRAY));
60-
// assertTrue(GpiohandleConfig.createEmpty().isEmpty());
61-
//
62-
// var handleData = new GpiohandleData(BYTE_ARRAY);
63-
// memoryBuffer = arena.allocate(handleData.getMemoryLayout());
64-
// handleData.toBytes(memoryBuffer);
65-
// var newHandleData = GpiohandleData.createEmpty().fromBytes(memoryBuffer);
66-
// assertArrayEquals(newHandleData.values(), prepareByteArray(64, BYTE_ARRAY));
67-
// assertTrue(GpiohandleData.createEmpty().isEmpty());
68-
//
69-
// var handleRequest = new GpiohandleRequest(INT_ARRAY, 1, BYTE_ARRAY, STRING, 2, 3);
70-
// memoryBuffer = arena.allocate(handleRequest.getMemoryLayout());
71-
// handleRequest.toBytes(memoryBuffer);
72-
// var newHandleRequest = GpiohandleRequest.createEmpty().fromBytes(memoryBuffer);
73-
// assertArrayEquals(newHandleRequest.lineoffsets(), prepareIntArray(64, INT_ARRAY));
74-
// assertEquals(newHandleRequest.flags(), 1);
75-
// assertArrayEquals(newHandleRequest.defaultValues(), prepareByteArray(64, BYTE_ARRAY));
76-
// assertArrayEquals(newHandleRequest.consumerLabel(), prepareByteArray(32, STRING));
77-
// assertEquals(newHandleRequest.lines(), 2);
78-
// assertEquals(newHandleRequest.fd(), 3);
79-
// assertTrue(GpiohandleRequest.createEmpty().isEmpty());
80-
//
81-
// var lineInfo = new GpiolineInfo(1, 2, STRING, STRING);
82-
// memoryBuffer = arena.allocate(lineInfo.getMemoryLayout());
83-
// lineInfo.toBytes(memoryBuffer);
84-
// var newLineInfo = GpiolineInfo.createEmpty().fromBytes(memoryBuffer);
85-
// assertEquals(newLineInfo.lineOffset(), 1);
86-
// assertEquals(newLineInfo.flags(), 2);
87-
// assertArrayEquals(newLineInfo.name(), prepareByteArray(32, STRING));
88-
// assertArrayEquals(newLineInfo.consumer(), prepareByteArray(32, STRING));
89-
// assertTrue(GpiolineInfo.createEmpty().isEmpty());
90-
//
91-
// var lineInfoChanged = new GpiolineInfoChanged(newLineInfo, 1, 2, INT_ARRAY);
92-
// memoryBuffer = arena.allocate(lineInfoChanged.getMemoryLayout());
93-
// lineInfoChanged.toBytes(memoryBuffer);
94-
// var newLineInfoChanged = GpiolineInfoChanged.createEmpty().fromBytes(memoryBuffer);
95-
// assertThat(newLineInfoChanged.info()).usingRecursiveComparison().isEqualTo(newLineInfo);
96-
// assertEquals(newLineInfoChanged.timestamp(), 1);
97-
// assertEquals(newLineInfoChanged.eventType(), 2);
98-
// assertArrayEquals(newLineInfoChanged.padding(), prepareIntArray(5, INT_ARRAY));
99-
// assertTrue(GpiolineInfoChanged.createEmpty().isEmpty());
100-
// } catch (Throwable e) {
101-
// fail(e);
102-
// }
103-
//
104-
// }
105-
//
106-
// private byte[] prepareByteArray(int size, byte... values) {
107-
// return ByteBuffer.allocate(size).put(values).array();
108-
// }
109-
//
110-
// private int[] prepareIntArray(int size, int... values) {
111-
// var array = new int[size];
112-
// System.arraycopy(values, 0, array, 0, values.length);
113-
// return array;
114-
// }
13+
14+
private static final byte[] STRING = "Test".getBytes();
15+
private static final byte[] BYTE_ARRAY = new byte[]{0x01, 0x02, 0x03};
16+
private static final int[] INT_ARRAY = new int[]{1, 2, 3};
17+
18+
@Test
19+
public void testGPIOV1AllTypes() {
20+
try (var arena = Arena.ofConfined()) {
21+
var chipInfo = new GpiochipInfo(STRING, STRING, 3);
22+
var memoryBuffer = arena.allocate(chipInfo.getMemoryLayout());
23+
chipInfo.toBytes(memoryBuffer);
24+
var newChipInfo = GpiochipInfo.createEmpty().fromBytes(memoryBuffer);
25+
assertArrayEquals(newChipInfo.name(), prepareByteArray(32, STRING));
26+
assertArrayEquals(newChipInfo.label(), prepareByteArray(32, STRING));
27+
assertEquals(newChipInfo.lines(), 3);
28+
assertTrue(GpiochipInfo.createEmpty().isEmpty());
29+
30+
assertEquals(GpioConstants.class.getFields().length, 40);
31+
32+
//assertEquals(GpioConstants.values().length, 3);
33+
34+
var eventData = new GpioeventData(100, 5);
35+
memoryBuffer = arena.allocate(eventData.getMemoryLayout());
36+
eventData.toBytes(memoryBuffer);
37+
var newEventData = GpioeventData.createEmpty().fromBytes(memoryBuffer);
38+
assertEquals(newEventData.timestamp(), 100);
39+
assertEquals(newEventData.id(), 5);
40+
assertTrue(GpioeventData.createEmpty().isEmpty());
41+
42+
var eventRequest = new GpioeventRequest(1, 2, 3, STRING, 4);
43+
memoryBuffer = arena.allocate(eventRequest.getMemoryLayout());
44+
eventRequest.toBytes(memoryBuffer);
45+
var newEventRequest = GpioeventRequest.createEmpty().fromBytes(memoryBuffer);
46+
assertEquals(newEventRequest.lineoffset(), 1);
47+
assertEquals(newEventRequest.handleflags(), 2);
48+
assertEquals(newEventRequest.eventflags(), 3);
49+
assertArrayEquals(newEventRequest.consumerLabel(), prepareByteArray(32, STRING));
50+
assertEquals(newEventRequest.fd(), 4);
51+
assertTrue(GpioeventRequest.createEmpty().isEmpty());
52+
53+
var handleConfig = new GpiohandleConfig(1, BYTE_ARRAY, INT_ARRAY);
54+
memoryBuffer = arena.allocate(handleConfig.getMemoryLayout());
55+
handleConfig.toBytes(memoryBuffer);
56+
var newHandleConfig = GpiohandleConfig.createEmpty().fromBytes(memoryBuffer);
57+
assertEquals(newHandleConfig.flags(), 1);
58+
assertArrayEquals(newHandleConfig.defaultValues(), prepareByteArray(64, BYTE_ARRAY));
59+
assertArrayEquals(newHandleConfig.padding(), prepareIntArray(4, INT_ARRAY));
60+
assertTrue(GpiohandleConfig.createEmpty().isEmpty());
61+
62+
var handleData = new GpiohandleData(BYTE_ARRAY);
63+
memoryBuffer = arena.allocate(handleData.getMemoryLayout());
64+
handleData.toBytes(memoryBuffer);
65+
var newHandleData = GpiohandleData.createEmpty().fromBytes(memoryBuffer);
66+
assertArrayEquals(newHandleData.values(), prepareByteArray(64, BYTE_ARRAY));
67+
assertTrue(GpiohandleData.createEmpty().isEmpty());
68+
69+
var handleRequest = new GpiohandleRequest(INT_ARRAY, 1, BYTE_ARRAY, STRING, 2, 3);
70+
memoryBuffer = arena.allocate(handleRequest.getMemoryLayout());
71+
handleRequest.toBytes(memoryBuffer);
72+
var newHandleRequest = GpiohandleRequest.createEmpty().fromBytes(memoryBuffer);
73+
assertArrayEquals(newHandleRequest.lineoffsets(), prepareIntArray(64, INT_ARRAY));
74+
assertEquals(newHandleRequest.flags(), 1);
75+
assertArrayEquals(newHandleRequest.defaultValues(), prepareByteArray(64, BYTE_ARRAY));
76+
assertArrayEquals(newHandleRequest.consumerLabel(), prepareByteArray(32, STRING));
77+
assertEquals(newHandleRequest.lines(), 2);
78+
assertEquals(newHandleRequest.fd(), 3);
79+
assertTrue(GpiohandleRequest.createEmpty().isEmpty());
80+
81+
var lineInfo = new GpiolineInfo(1, 2, STRING, STRING);
82+
memoryBuffer = arena.allocate(lineInfo.getMemoryLayout());
83+
lineInfo.toBytes(memoryBuffer);
84+
var newLineInfo = GpiolineInfo.createEmpty().fromBytes(memoryBuffer);
85+
assertEquals(newLineInfo.lineOffset(), 1);
86+
assertEquals(newLineInfo.flags(), 2);
87+
assertArrayEquals(newLineInfo.name(), prepareByteArray(32, STRING));
88+
assertArrayEquals(newLineInfo.consumer(), prepareByteArray(32, STRING));
89+
assertTrue(GpiolineInfo.createEmpty().isEmpty());
90+
91+
var lineInfoChanged = new GpiolineInfoChanged(newLineInfo, 1, 2, INT_ARRAY);
92+
memoryBuffer = arena.allocate(lineInfoChanged.getMemoryLayout());
93+
lineInfoChanged.toBytes(memoryBuffer);
94+
var newLineInfoChanged = GpiolineInfoChanged.createEmpty().fromBytes(memoryBuffer);
95+
assertThat(newLineInfoChanged.info()).usingRecursiveComparison().isEqualTo(newLineInfo);
96+
assertEquals(newLineInfoChanged.timestamp(), 1);
97+
assertEquals(newLineInfoChanged.eventType(), 2);
98+
assertArrayEquals(newLineInfoChanged.padding(), prepareIntArray(5, INT_ARRAY));
99+
assertTrue(GpiolineInfoChanged.createEmpty().isEmpty());
100+
} catch (Throwable e) {
101+
fail(e);
102+
}
103+
104+
}
105+
106+
private byte[] prepareByteArray(int size, byte... values) {
107+
return ByteBuffer.allocate(size).put(values).array();
108+
}
109+
110+
private int[] prepareIntArray(int size, int... values) {
111+
var array = new int[size];
112+
System.arraycopy(values, 0, array, 0, values.length);
113+
return array;
114+
}
115115

116116
}

annotation-processor/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ plugins {
44
}
55

66
group = 'io.github.digitalsmile.native'
7-
version = '1.1.3'
7+
version = '1.1.4'
88

99
repositories {
1010
mavenCentral()
1111
}
1212

1313
dependencies {
1414
implementation 'io.soabase.java-composer:java-composer:1.0'
15-
implementation 'io.github.digitalsmile.native:annotation:1.1.3'
15+
implementation 'io.github.digitalsmile.native:annotation:1.1.4'
1616

1717
annotationProcessor 'io.avaje:avaje-prisms:1.28'
1818
implementation 'io.avaje:avaje-prisms:1.28'
@@ -26,7 +26,7 @@ import com.vanniktech.maven.publish.SonatypeHost
2626
mavenPublishing {
2727
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
2828
signAllPublications()
29-
coordinates("io.github.digitalsmile.native", "annotation-processor", "1.1.3")
29+
coordinates("io.github.digitalsmile.native", "annotation-processor", "1.1.4")
3030

3131
pom {
3232
name = "Native Memory Annotation processor"

annotation-processor/src/main/java/io/github/digitalsmile/headers/DeclarationParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ private NativeMemoryNode parseVariable(Declaration declaration, Type type, int l
223223
} else if (notInScope(typeDeclared.tree())) {
224224
parseDeclarations(typeDeclared.tree(), node, false);
225225
return node;
226-
} else if (level > 1) {
226+
} else if (level >= 1) {
227227
return node;
228228
} else {
229229
return null;

annotation/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = 'io.github.digitalsmile.native'
7-
version = '1.1.3'
7+
version = '1.1.4'
88

99
repositories {
1010
mavenCentral()
@@ -18,7 +18,7 @@ import com.vanniktech.maven.publish.SonatypeHost
1818
mavenPublishing {
1919
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
2020
signAllPublications()
21-
coordinates("io.github.digitalsmile.native", "annotation", "1.1.3")
21+
coordinates("io.github.digitalsmile.native", "annotation", "1.1.4")
2222

2323
pom {
2424
name = "Native Memory Annotation"

0 commit comments

Comments
 (0)