-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JNA callback should check inputs and outputs for null. (#30)
This addresses #27 once we merge extism/extism#760 and release a new version of libextism. This PR simply check the parameters for null and the counts to be valid, in preparation for extism/extism#760 which otherwise would cause a NullPointerException when outputs and inputs are empty. Signed-off-by: Edoardo Vacchi <[email protected]>
- Loading branch information
Showing
3 changed files
with
119 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.extism.sdk; | ||
|
||
import com.sun.jna.Pointer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class HostFunctionTests { | ||
@Test | ||
public void callbackShouldAcceptNullParameters() { | ||
var callback = new HostFunction.Callback<>( | ||
(plugin, params, returns, userData) -> {/* NOOP */}, null); | ||
callback.invoke(Pointer.NULL, null, 0, null, 0, Pointer.NULL); | ||
} | ||
|
||
@Test | ||
public void callbackShouldThrowOnNullParametersAndNonzeroCounts() { | ||
var callback = new HostFunction.Callback<>( | ||
(plugin, params, returns, userData) -> {/* NOOP */}, null); | ||
assertThrows(ExtismException.class, () -> | ||
callback.invoke(Pointer.NULL, null, 1, null, 0, Pointer.NULL)); | ||
assertThrows(ExtismException.class, () -> | ||
callback.invoke(Pointer.NULL, null, 0, null, 1, Pointer.NULL)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters