Skip to content

Commit

Permalink
Add tests for #69
Browse files Browse the repository at this point in the history
  • Loading branch information
uvlad7 committed Mar 19, 2024
1 parent 6182ca0 commit 511c295
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/driver/native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub mod jni {
#[field]
pub username: Field<'env, 'borrow, String>,
pub password: String,
#[field]
pub bytes: Field<'env, 'borrow, Box<[i8]>>,
}

impl<'env: 'borrow, 'borrow> User<'env, 'borrow> {
Expand Down
2 changes: 2 additions & 0 deletions tests/driver/src/main/java/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class User {

private String username;
private String password;
private byte[] bytes;

@Override
public String toString() {
Expand Down Expand Up @@ -155,6 +156,7 @@ public User(String username, String password) {

this.username = username;
this.password = password;
this.bytes = password.getBytes();
}

public static String getNullableString(String v) {
Expand Down
8 changes: 8 additions & 0 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ fn vm_creation_and_object_usage() {
assert_eq!("42__", User::cloneUser(&env, &borrow_user).password);
// Mutable class fields work as expected
assert_eq!("borrow__", borrow_user.username.get().expect("unable to get username"));
// This field is simply not updated on the java side
let expected = "42".as_bytes();
assert_eq!(
unsafe {
&*std::ptr::slice_from_raw_parts(expected.as_ref().as_ptr() as *const i8, expected.as_ref().len())
}.to_vec(),
borrow_user.bytes.get().expect("unable to get bytes").to_vec(),
);

assert_eq!(borrow_user.toString(&env), "User{username='borrow__', password='42__'}");
assert_eq!(borrow_user_opt.toString(&env), "User{username='borrow_opt____', password='42____'}");
Expand Down

0 comments on commit 511c295

Please sign in to comment.