Skip to content

Commit

Permalink
Add a couple more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
necauqua committed Jul 26, 2023
1 parent ec3ecff commit 77ab1b5
Show file tree
Hide file tree
Showing 7 changed files with 449 additions and 10 deletions.
13 changes: 12 additions & 1 deletion src/highlevel/object_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
class_object_reference::ReflectedType,
string_reference::Value,
thread_group_reference::{self, Children, Parent},
virtual_machine::DisposeObjects,
ArrayID, ArrayRegion, ClassLoaderID, ClassObjectID, JdwpValue, ObjectID, StringID, Tag,
TaggedObjectID, ThreadGroupID,
},
Expand All @@ -18,7 +19,17 @@ use super::{

pub type ObjectReference = PlainJvmObject<ObjectID>;

impl ObjectReference {}
impl ObjectReference {
pub fn dispose_single(&self) -> Result<(), ClientError> {
self.dispose(1)
}

pub fn dispose(&self, refcount: u32) -> Result<(), ClientError> {
self.client()
.get()
.send(DisposeObjects::new(&[(self.id(), refcount)]))
}
}

pub type JvmArray = ExtendedJvmObject<ArrayID>;

Expand Down
23 changes: 22 additions & 1 deletion src/highlevel/reference_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl ReferenceType {
.send(SourceDebugExtension::new(self.id()))
}

pub fn signature_with_generic(&self) -> Result<SignatureWithGenericReply, ClientError> {
pub fn signature_generic(&self) -> Result<SignatureWithGenericReply, ClientError> {
self.client()
.get()
.send(SignatureWithGeneric::new(self.id()))
Expand Down Expand Up @@ -236,6 +236,27 @@ impl TaggedReferenceType {
// SAFETY: Self and TypeTag fulfill the requirements
unsafe { crate::spec::tag(self) }
}

pub fn unwrap_class(self) -> ClassType {
match self {
TaggedReferenceType::Class(class) => class,
_ => panic!("Expected a class"),
}
}

pub fn unwrap_interface(self) -> InterfaceType {
match self {
TaggedReferenceType::Interface(interface) => interface,
_ => panic!("Expected an interface"),
}
}

pub fn unwrap_array(self) -> ArrayType {
match self {
TaggedReferenceType::Array(array) => array,
_ => panic!("Expected an array"),
}
}
}

impl Deref for TaggedReferenceType {
Expand Down
2 changes: 1 addition & 1 deletion src/highlevel/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl VM {
.send(virtual_machine::SetDefaultStratum::new(stratum))
}

pub fn all_classes_with_generic(&self) -> Result<Vec<Class>, ClientError> {
pub fn all_classes_generic(&self) -> Result<Vec<Class>, ClientError> {
let classes = self.client.get().send(AllClassesWithGeneric)?;
let classes = classes
.into_iter()
Expand Down
48 changes: 48 additions & 0 deletions tests/array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use common::Result;

mod common;

#[test]
fn length() -> Result {
let vm = common::launch_and_attach_vm("basic")?;
let (class_type, _) = vm.class_by_signature("[I")?;

let array_type = class_type.unwrap_array();
let array = array_type.new_instance(10)?;

assert_eq!(array.length()?, 10);

Ok(())
}

#[test]
fn set_get_values() -> Result {
let vm = common::launch_and_attach_vm("basic")?;
let (class_type, _) = vm.class_by_signature("[I")?;

let array_type = class_type.unwrap_array();
let array = array_type.new_instance(10)?;

array.set_values(0, &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10])?;

let region = array.get_values(0, 10)?;

assert_snapshot!(region, @r###"
Int(
[
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
],
)
"###);

Ok(())
}
9 changes: 6 additions & 3 deletions tests/fixtures/Basic.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import java.util.HashMap;
import java.util.function.IntSupplier;

class Basic implements IntSupplier {
class Basic<T> implements IntSupplier {

static int staticInt = 42;
public static Basic running = new Basic();
public static Basic secondInstance = new Basic();
public static Basic<String> running = new Basic<>();
public static Basic<?> secondInstance = new Basic<>();

public long ticks = 0;

Expand Down Expand Up @@ -49,6 +49,9 @@ private static void ping(Object ignored) {
// noop lol
}

static <T extends IntSupplier> void withGeneric(int param1, T param2) {
}

class NestedClass {
float field;
}
Expand Down
Loading

0 comments on commit 77ab1b5

Please sign in to comment.