diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2024-11-06 00:01:57 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2024-12-19 19:36:37 +0100 |
commit | ba3b81f3b668d3faa6cbdb39e123394f7bf637c7 (patch) | |
tree | 42d37373c9ad3d1004e2565e7b2e98647f3916d3 /rust/qemu-api/tests/tests.rs | |
parent | f50cd85c8475c16374d0e138efda222ce4455f53 (diff) | |
download | qemu-ba3b81f3b668d3faa6cbdb39e123394f7bf637c7.zip qemu-ba3b81f3b668d3faa6cbdb39e123394f7bf637c7.tar.gz qemu-ba3b81f3b668d3faa6cbdb39e123394f7bf637c7.tar.bz2 |
rust: qom: add initial subset of methods on Object
Add an example of implementing instance methods and converting the
result back to a Rust type. In this case the returned types are a
string (actually a Cow<str>; but that's transparent as long as it derefs
to &str) and a QOM class.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'rust/qemu-api/tests/tests.rs')
-rw-r--r-- | rust/qemu-api/tests/tests.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 7b63e28..1d2825b 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -88,6 +88,18 @@ fn test_object_new() { } } +#[test] +/// Try invoking a method on an object. +fn test_typename() { + init_qom(); + let p: *mut DummyState = unsafe { object_new(DummyState::TYPE_NAME.as_ptr()).cast() }; + let p_ref: &DummyState = unsafe { &*p }; + assert_eq!(p_ref.typename(), "dummy"); + unsafe { + object_unref(p_ref.as_object_mut_ptr().cast::<c_void>()); + } +} + // a note on all "cast" tests: usually, especially for downcasts the desired // class would be placed on the right, for example: // |