Skip to content

Commit

Permalink
Add JNI test support
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse committed Sep 19, 2024
1 parent 287b9d9 commit f1c84ed
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
31 changes: 30 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import edu.wpi.first.toolchain.*

plugins {
id 'cpp'
id 'java'
Expand Down Expand Up @@ -35,6 +37,19 @@ dependencies {
implementation "com.fasterxml.jackson.core:jackson-core:2.15.2"
implementation "com.fasterxml.jackson.core:jackson-databind:2.15.2"
implementation 'edu.wpi.first.thirdparty.frc2024.opencv:opencv-java:4.8.0-2'

testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

// Set up java tests
test {
useJUnitPlatform()
systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true'
testLogging {
events "failed"
exceptionFormat "full"
}
}

// Set up exports properly
Expand All @@ -52,6 +67,12 @@ nativeUtils {
}
}

ext.getCurrentArch = {
return NativePlatforms.desktop
}

def systemArch = getCurrentArch()

model {
components {
Vendor(NativeLibrarySpec) {
Expand Down Expand Up @@ -105,6 +126,15 @@ model {

binaries.all {
lib library: 'VendorDriver', linkage: 'shared'

def arch = it.targetPlatform.name
if (systemArch == arch && it.buildType.name == 'debug') {
def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib'
test.dependsOn it.tasks.install
test.systemProperty 'java.library.path', filePath
test.environment 'LD_LIBRARY_PATH', filePath
test.workingDir filePath
}
}

nativeUtils.useRequiredLibrary(it, "wpilib_executable_shared", "googletest_static")
Expand All @@ -117,7 +147,6 @@ model {
include '**/*.cpp'
}
}

nativeUtils.useRequiredLibrary(it, "wpilib_executable_shared", "googletest_static")
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/com/vendor/jni/VendorJNITest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.vendor.jni;

import org.junit.jupiter.api.Test;

public class VendorJNITest {
@Test
void jniLinkTest() {
// Test to verify that the JNI test link works correctly.
VendorJNI.initialize();
}
}

0 comments on commit f1c84ed

Please sign in to comment.