Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 300fa04

Browse files
committed
Add test for defining a new interface and adding it to a type
1 parent a5c6546 commit 300fa04

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/subclass/object.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ mod test {
295295

296296
glib_object_subclass!();
297297

298+
fn type_init(type_: &mut subclass::InitializingType<Self>) {
299+
type_.add_interface::<DummyInterface>();
300+
}
301+
298302
fn class_init(klass: &mut subclass::simple::ClassStruct<Self>) {
299303
klass.install_properties(&PROPERTIES);
300304

@@ -363,11 +367,42 @@ mod test {
363367
}
364368
}
365369

370+
#[repr(C)]
371+
pub struct DummyInterface {
372+
parent: gobject_ffi::GTypeInterface,
373+
}
374+
375+
impl ObjectInterface for DummyInterface {
376+
const NAME: &'static str = "DummyInterface";
377+
378+
glib_object_interface!();
379+
380+
fn type_init(type_: &mut subclass::InitializingType<Self>) {
381+
type_.add_prerequisite::<Object>();
382+
}
383+
}
384+
385+
// Usually this would be implemented on a Rust wrapper type defined
386+
// with glib_wrapper!() but for the test the following is sufficient
387+
impl StaticType for DummyInterface {
388+
fn static_type() -> Type {
389+
DummyInterface::get_type()
390+
}
391+
}
392+
393+
// Usually this would be implemented on a Rust wrapper type defined
394+
// with glib_wrapper!() but for the test the following is sufficient
395+
unsafe impl<T: ObjectSubclass> IsImplementable<T> for DummyInterface {
396+
unsafe extern "C" fn interface_init(_iface: ffi::gpointer, _iface_data: ffi::gpointer) {}
397+
}
398+
366399
#[test]
367400
fn test_create() {
368401
let type_ = SimpleObject::get_type();
369402
let obj = Object::new(type_, &[]).unwrap();
370403

404+
assert!(obj.get_type().is_a(&DummyInterface::static_type()));
405+
371406
assert_eq!(
372407
obj.get_property("constructed").unwrap().get::<bool>(),
373408
Some(true)

0 commit comments

Comments
 (0)