Skip to content

Commit

Permalink
TMP
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Sep 20, 2023
1 parent f497013 commit ef1b194
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/objc2/src/declare/ivar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,14 @@ mod tests {

#[test]
fn access_ivar() {
std::println!("create");
let mut obj = test_utils::custom_object();
std::println!("setFoo");
let _: () = unsafe { msg_send![&mut obj, setFoo: 42u32] };

std::println!("convert");
let obj = unsafe { Id::as_ptr(&obj).cast::<IvarTestObject>().as_ref().unwrap() };
std::println!("access");
assert_eq!(*obj.foo, 42);
}

Expand Down
7 changes: 6 additions & 1 deletion crates/objc2/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ pub(crate) fn custom_class() -> &'static AnyClass {
static REGISTER_CUSTOM_CLASS: Once = Once::new();

REGISTER_CUSTOM_CLASS.call_once(|| {
std::println!("register class");
// The runtime will call this method, so it has to be implemented
extern "C" fn custom_obj_class_initialize(_this: &AnyClass, _cmd: Sel) {}
extern "C" fn custom_obj_class_initialize(_this: &AnyClass, _cmd: Sel) {
std::println!("init class");
}

let mut builder = ClassBuilder::root(
"CustomObject",
Expand All @@ -86,6 +89,7 @@ pub(crate) fn custom_class() -> &'static AnyClass {
builder.add_ivar::<u32>("_foo");

unsafe extern "C" fn custom_obj_release(this: *mut AnyObject, _cmd: Sel) {
std::println!("release class");
unsafe {
#[allow(deprecated)]
ffi::object_dispose(this.cast());
Expand Down Expand Up @@ -184,6 +188,7 @@ pub(crate) fn custom_class() -> &'static AnyClass {
builder.register();
});

std::println!("get class");
// Can't use `class!` here since `CustomObject` is dynamically created.
AnyClass::get("CustomObject").unwrap()
}
Expand Down

0 comments on commit ef1b194

Please sign in to comment.