test: add simple tests on java side

This commit is contained in:
əlemi 2024-09-24 01:58:10 +02:00
parent 10547d92b0
commit a1f9e8dfc1
Signed by: alemi
GPG key ID: A4895B84D311642C
8 changed files with 83 additions and 9 deletions

View file

@ -28,3 +28,5 @@ jobs:
toolchain: ${{ matrix.toolchain }} toolchain: ${{ matrix.toolchain }}
- run: cargo build --verbose - run: cargo build --verbose
- run: cargo test --verbose - run: cargo test --verbose
- uses: gradle/actions/setup-gradle@v4
- run: gradle test

9
.gitignore vendored
View file

@ -1 +1,10 @@
# rust
/target /target
# gradle
/build
/bin
/.settings
/.gradle
.project
.classpath

13
Cargo.lock generated
View file

@ -57,7 +57,7 @@ name = "jni-toolbox"
version = "0.1.3" version = "0.1.3"
dependencies = [ dependencies = [
"jni", "jni",
"jni-toolbox-macro 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "jni-toolbox-macro",
"uuid", "uuid",
] ]
@ -71,14 +71,11 @@ dependencies = [
] ]
[[package]] [[package]]
name = "jni-toolbox-macro" name = "jni-toolbox-test"
version = "0.1.3" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9970cad895bb316f70956593710d675d27a480ddbb8099f7e313042463a16d9b"
dependencies = [ dependencies = [
"proc-macro2", "jni",
"quote", "jni-toolbox",
"syn",
] ]
[[package]] [[package]]

View file

@ -1,5 +1,5 @@
[workspace] [workspace]
members = ["macro"] members = ["macro", "src/test"]
[package] [package]
name = "jni-toolbox" name = "jni-toolbox"

17
build.gradle Normal file
View file

@ -0,0 +1,17 @@
plugins {
id 'java-library'
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
}
repositories {
mavenCentral()
}
test {
useJUnitPlatform()
systemProperty 'java.library.path','target/debug'
}

13
src/test/Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "jni-toolbox-test"
description = "test binary for jni-toolbox"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
path = "test.rs"
[dependencies]
jni-toolbox = { path = "../.." }
jni = "0.21"

View file

@ -0,0 +1,25 @@
package toolbox;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Main {
static {
System.loadLibrary("jni_toolbox_test");
}
static native int sum(int a, int b);
static native String concat(String a, String b);
@Test
public void argumentsByValue() {
assertEquals(Main.sum(42, 13), 42 + 13);
}
@Test
public void argumentsByReference() {
assertEquals(Main.concat("hello", "world"), "hello -- world");
}
}

11
src/test/test.rs Normal file
View file

@ -0,0 +1,11 @@
use jni_toolbox::jni;
#[jni(package = "toolbox", class = "Main")]
fn sum(a: i32, b: i32) -> i32 {
a + b
}
#[jni(package = "toolbox", class = "Main")]
fn concat(a: String, b: String) -> String {
format!("{a} -- {b}")
}