mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-29 04:51:09 +00:00
gstreamer: implement HasParamSpec for ClockTime
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1225>
This commit is contained in:
parent
8afac7d31b
commit
9446401a46
1 changed files with 60 additions and 0 deletions
|
@ -368,6 +368,16 @@ impl glib::StaticType for ClockTime {
|
|||
}
|
||||
}
|
||||
|
||||
impl glib::HasParamSpec for ClockTime {
|
||||
type ParamSpec = glib::ParamSpecUInt64;
|
||||
type SetValue = Self;
|
||||
type BuilderFn = fn(&str) -> glib::ParamSpecUInt64Builder;
|
||||
|
||||
fn param_spec_builder() -> Self::BuilderFn {
|
||||
Self::ParamSpec::builder
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DurationError;
|
||||
|
||||
|
@ -1418,4 +1428,54 @@ mod tests {
|
|||
assert_eq!(i64::MIN as i128, -(((u64::MAX >> 1) + 1) as i128));
|
||||
assert_eq!(i64::try_from(time), Ok(i64::MIN));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn properties_macro_usage() {
|
||||
use super::ClockTime;
|
||||
use glib::{prelude::*, subclass::prelude::*, ParamSpecBuilderExt};
|
||||
use std::cell::Cell;
|
||||
|
||||
#[derive(Default, glib::Properties)]
|
||||
#[properties(wrapper_type = TestObject)]
|
||||
pub struct TestObjectImp {
|
||||
#[property(get, set)]
|
||||
clock_time: Cell<ClockTime>,
|
||||
#[property(get, set)]
|
||||
optional_clock_time: Cell<Option<ClockTime>>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for TestObjectImp {
|
||||
const NAME: &'static str = "GstTestObject";
|
||||
type Type = TestObject;
|
||||
}
|
||||
|
||||
impl ObjectImpl for TestObjectImp {
|
||||
fn properties() -> &'static [glib::ParamSpec] {
|
||||
Self::derived_properties()
|
||||
}
|
||||
|
||||
fn set_property(&self, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
||||
self.derived_set_property(id, value, pspec);
|
||||
}
|
||||
|
||||
fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value {
|
||||
self.derived_property(id, pspec)
|
||||
}
|
||||
}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct TestObject(ObjectSubclass<TestObjectImp>);
|
||||
}
|
||||
|
||||
let obj: TestObject = glib::Object::new();
|
||||
|
||||
assert_eq!(obj.clock_time(), ClockTime::default());
|
||||
obj.set_clock_time(ClockTime::MAX);
|
||||
assert_eq!(obj.clock_time(), ClockTime::MAX);
|
||||
|
||||
assert_eq!(obj.optional_clock_time(), None);
|
||||
obj.set_optional_clock_time(ClockTime::MAX);
|
||||
assert_eq!(obj.optional_clock_time(), Some(ClockTime::MAX));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue