mirror of
https://github.com/hexedtech/jni-toolbox.git
synced 2024-12-23 05:44:52 +01:00
test: add simple tests on java side
This commit is contained in:
parent
10547d92b0
commit
a1f9e8dfc1
8 changed files with 83 additions and 9 deletions
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
|
@ -28,3 +28,5 @@ jobs:
|
|||
toolchain: ${{ matrix.toolchain }}
|
||||
- run: cargo build --verbose
|
||||
- run: cargo test --verbose
|
||||
- uses: gradle/actions/setup-gradle@v4
|
||||
- run: gradle test
|
||||
|
|
9
.gitignore
vendored
9
.gitignore
vendored
|
@ -1 +1,10 @@
|
|||
# rust
|
||||
/target
|
||||
|
||||
# gradle
|
||||
/build
|
||||
/bin
|
||||
/.settings
|
||||
/.gradle
|
||||
.project
|
||||
.classpath
|
||||
|
|
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -57,7 +57,7 @@ name = "jni-toolbox"
|
|||
version = "0.1.3"
|
||||
dependencies = [
|
||||
"jni",
|
||||
"jni-toolbox-macro 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jni-toolbox-macro",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
|
@ -71,14 +71,11 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "jni-toolbox-macro"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9970cad895bb316f70956593710d675d27a480ddbb8099f7e313042463a16d9b"
|
||||
name = "jni-toolbox-test"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"jni",
|
||||
"jni-toolbox",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[workspace]
|
||||
members = ["macro"]
|
||||
members = ["macro", "src/test"]
|
||||
|
||||
[package]
|
||||
name = "jni-toolbox"
|
||||
|
|
17
build.gradle
Normal file
17
build.gradle
Normal 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
13
src/test/Cargo.toml
Normal 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"
|
25
src/test/java/toolbox/Main.java
Normal file
25
src/test/java/toolbox/Main.java
Normal 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
11
src/test/test.rs
Normal 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}")
|
||||
}
|
Loading…
Reference in a new issue