mirror of
https://github.com/hexedtech/jni-toolbox.git
synced 2024-11-23 07:54:51 +01:00
test: vecs, options, nulls, also build with gradle
This commit is contained in:
parent
218a816c2d
commit
3d3bc8b6d5
4 changed files with 43 additions and 1 deletions
1
.github/workflows/test.yml
vendored
1
.github/workflows/test.yml
vendored
|
@ -27,5 +27,4 @@ jobs:
|
|||
- run: cargo build --verbose
|
||||
- run: cargo test --verbose
|
||||
- uses: gradle/actions/setup-gradle@v4
|
||||
- run: cargo build -p jni-toolbox-test
|
||||
- run: gradle test
|
||||
|
|
|
@ -11,7 +11,14 @@ repositories {
|
|||
mavenCentral()
|
||||
}
|
||||
|
||||
task cargoBuild(type: Exec) {
|
||||
workingDir '.'
|
||||
commandLine 'cargo', 'build', '-p', 'jni-toolbox-test'
|
||||
}
|
||||
|
||||
test {
|
||||
dependsOn cargoBuild
|
||||
outputs.upToDateWhen { false }
|
||||
useJUnitPlatform()
|
||||
systemProperty 'java.library.path','target/debug'
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package toolbox;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
@ -11,6 +12,8 @@ public class Main {
|
|||
|
||||
static native int sum(int a, int b);
|
||||
static native String concat(String a, String b);
|
||||
static native String[] to_vec(String a, String b, String c);
|
||||
static native boolean maybe(String optional);
|
||||
|
||||
@Test
|
||||
public void argumentsByValue() {
|
||||
|
@ -22,4 +25,27 @@ public class Main {
|
|||
assertEquals(Main.concat("hello", "world"), "hello -- world");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checksForNull() {
|
||||
// TODO maybe these should throw NullPtrException
|
||||
assertThrows(RuntimeException.class, () -> Main.concat("a", null));
|
||||
assertThrows(RuntimeException.class, () -> Main.concat(null, "a"));
|
||||
assertThrows(RuntimeException.class, () -> Main.concat(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnVec() {
|
||||
String[] actual = new String[]{"a", "b", "c"};
|
||||
String[] from_rust = Main.to_vec("a", "b", "c");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
assertEquals(actual[i], from_rust[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optional() {
|
||||
assertEquals(Main.maybe(null), false);
|
||||
assertEquals(Main.maybe("aa"), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,3 +9,13 @@ fn sum(a: i32, b: i32) -> i32 {
|
|||
fn concat(a: String, b: String) -> String {
|
||||
format!("{a} -- {b}")
|
||||
}
|
||||
|
||||
#[jni(package = "toolbox", class = "Main")]
|
||||
fn to_vec(a: String, b: String, c: String) -> Vec<String> {
|
||||
vec![a, b, c]
|
||||
}
|
||||
|
||||
#[jni(package = "toolbox", class = "Main")]
|
||||
fn maybe(idk: Option<String>) -> bool {
|
||||
idk.is_some()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue