forked from mirrors/gstreamer-rs
Fix various new clippy warnings from 1.40
This commit is contained in:
parent
d26ffc2c21
commit
69be1ce2fc
31 changed files with 101 additions and 108 deletions
|
@ -168,7 +168,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
|
|||
.map(|s| String::from(s.get_path_string()))
|
||||
.unwrap_or_else(|| String::from("None")),
|
||||
error: err.get_error().description().into(),
|
||||
debug: Some(err.get_debug().unwrap().to_string()),
|
||||
debug: err.get_debug(),
|
||||
cause: err.get_error(),
|
||||
}
|
||||
.into());
|
||||
|
|
|
@ -160,7 +160,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
|
|||
.map(|s| String::from(s.get_path_string()))
|
||||
.unwrap_or_else(|| String::from("None")),
|
||||
error: err.get_error().description().into(),
|
||||
debug: Some(err.get_debug().unwrap().to_string()),
|
||||
debug: err.get_debug(),
|
||||
cause: err.get_error(),
|
||||
}
|
||||
.into());
|
||||
|
|
|
@ -281,7 +281,7 @@ fn example_main() -> Result<(), Error> {
|
|||
.map(|s| String::from(s.get_path_string()))
|
||||
.unwrap_or_else(|| String::from("None")),
|
||||
error: err.get_error().description().into(),
|
||||
debug: Some(err.get_debug().unwrap().to_string()),
|
||||
debug: err.get_debug(),
|
||||
cause: err.get_error(),
|
||||
}
|
||||
.into()),
|
||||
|
@ -295,7 +295,7 @@ fn example_main() -> Result<(), Error> {
|
|||
.map(|s| String::from(s.get_path_string()))
|
||||
.unwrap_or_else(|| String::from("None")),
|
||||
error: err.get_error().description().into(),
|
||||
debug: Some(err.get_debug().unwrap().to_string()),
|
||||
debug: err.get_debug(),
|
||||
cause: err.get_error(),
|
||||
}
|
||||
.into());
|
||||
|
|
|
@ -311,7 +311,7 @@ fn example_main() -> Result<(), Error> {
|
|||
.map(|s| String::from(s.get_path_string()))
|
||||
.unwrap_or_else(|| String::from("None")),
|
||||
error: err.get_error().description().into(),
|
||||
debug: Some(err.get_debug().unwrap().to_string()),
|
||||
debug: err.get_debug(),
|
||||
cause: err.get_error(),
|
||||
}
|
||||
.into()),
|
||||
|
@ -325,7 +325,7 @@ fn example_main() -> Result<(), Error> {
|
|||
.map(|s| String::from(s.get_path_string()))
|
||||
.unwrap_or_else(|| String::from("None")),
|
||||
error: err.get_error().description().into(),
|
||||
debug: Some(err.get_debug().unwrap().to_string()),
|
||||
debug: err.get_debug(),
|
||||
cause: err.get_error(),
|
||||
}
|
||||
.into());
|
||||
|
|
|
@ -594,7 +594,7 @@ impl App {
|
|||
.map(|s| String::from(s.get_path_string()))
|
||||
.unwrap_or_else(|| String::from("None")),
|
||||
error: err.get_error().description().into(),
|
||||
debug: Some(err.get_debug().unwrap().to_string()),
|
||||
debug: err.get_debug(),
|
||||
cause: err.get_error(),
|
||||
}
|
||||
.into());
|
||||
|
|
|
@ -144,7 +144,6 @@ fn create_ui(app: >k::Application) {
|
|||
// simplifies the code within the callback. What this actually does, however, is creating
|
||||
// a memory leak.
|
||||
let video_overlay = sink
|
||||
.clone()
|
||||
.dynamic_cast::<gst_video::VideoOverlay>()
|
||||
.unwrap()
|
||||
.downgrade();
|
||||
|
|
|
@ -213,7 +213,6 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
|||
})
|
||||
.unwrap();
|
||||
|
||||
let drawer_clone = drawer.clone();
|
||||
// Add a signal handler to the overlay's "caps-changed" signal. This could e.g.
|
||||
// be called when the sink that we render to does not support resizing the image
|
||||
// itself - but the user just changed the window-size. The element after the overlay
|
||||
|
@ -226,7 +225,6 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
|||
let _overlay = args[0].get::<gst::Element>().unwrap().unwrap();
|
||||
let caps = args[1].get::<gst::Caps>().unwrap().unwrap();
|
||||
|
||||
let drawer = &drawer_clone;
|
||||
let mut drawer = drawer.lock().unwrap();
|
||||
drawer.info = Some(gst_video::VideoInfo::from_caps(&caps).unwrap());
|
||||
|
||||
|
@ -257,7 +255,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
|
|||
.map(|s| String::from(s.get_path_string()))
|
||||
.unwrap_or_else(|| String::from("None")),
|
||||
error: err.get_error().description().into(),
|
||||
debug: Some(err.get_debug().unwrap().to_string()),
|
||||
debug: err.get_debug(),
|
||||
cause: err.get_error(),
|
||||
}
|
||||
.into());
|
||||
|
|
|
@ -275,7 +275,7 @@ fn example_main() -> Result<(), Error> {
|
|||
.map(|s| String::from(s.get_path_string()))
|
||||
.unwrap_or_else(|| String::from("None")),
|
||||
error: err.get_error().description().into(),
|
||||
debug: Some(err.get_debug().unwrap().to_string()),
|
||||
debug: err.get_debug(),
|
||||
cause: err.get_error(),
|
||||
}
|
||||
.into());
|
||||
|
|
|
@ -146,9 +146,8 @@ fn example_main() -> Result<(), Error> {
|
|||
let sinkpad = get_static_pad(&sink, "sink")?;
|
||||
srcpad.link(&sinkpad)?;
|
||||
|
||||
let convclone = conv.clone();
|
||||
src.connect_pad_added(move |decodebin, src_pad| {
|
||||
match connect_decodebin_pad(&src_pad, &convclone) {
|
||||
src.connect_pad_added(
|
||||
move |decodebin, src_pad| match connect_decodebin_pad(&src_pad, &conv) {
|
||||
Ok(_) => (),
|
||||
Err(err) => {
|
||||
gst_element_error!(
|
||||
|
@ -158,8 +157,8 @@ fn example_main() -> Result<(), Error> {
|
|||
["{}", err]
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
let video_caps = gst::Caps::new_simple("video/x-raw", &[]);
|
||||
|
||||
|
@ -199,7 +198,7 @@ fn example_main() -> Result<(), Error> {
|
|||
.map(|s| String::from(s.get_path_string()))
|
||||
.unwrap_or_else(|| String::from("None")),
|
||||
error: err.get_error().description().into(),
|
||||
debug: Some(err.get_debug().unwrap().to_string()),
|
||||
debug: err.get_debug(),
|
||||
cause: err.get_error(),
|
||||
}
|
||||
.into());
|
||||
|
|
|
@ -385,7 +385,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
|
|||
.map(|s| String::from(s.get_path_string()))
|
||||
.unwrap_or_else(|| String::from("None")),
|
||||
error: err.get_error().description().into(),
|
||||
debug: Some(err.get_debug().unwrap().to_string()),
|
||||
debug: err.get_debug(),
|
||||
cause: err.get_error(),
|
||||
}
|
||||
.into());
|
||||
|
|
|
@ -109,7 +109,7 @@ fn example_main() -> Result<(), Error> {
|
|||
.unwrap_or_else(|| "None".into())
|
||||
.to_string(),
|
||||
error: err.get_error().description().into(),
|
||||
debug: Some(err.get_debug().unwrap().to_string()),
|
||||
debug: err.get_debug(),
|
||||
cause: err.get_error(),
|
||||
}
|
||||
.into());
|
||||
|
|
|
@ -175,7 +175,7 @@ fn example_main() -> Result<(), Error> {
|
|||
.map(|s| String::from(s.get_path_string()))
|
||||
.unwrap_or_else(|| String::from("None")),
|
||||
error: err.get_error().description().into(),
|
||||
debug: Some(err.get_debug().unwrap().to_string()),
|
||||
debug: err.get_debug(),
|
||||
cause: err.get_error(),
|
||||
}
|
||||
.into());
|
||||
|
|
|
@ -488,19 +488,19 @@ mod tests {
|
|||
use auto::EncodingVideoProfile;
|
||||
use gst;
|
||||
|
||||
const AUDIO_PROFILE_NAME: &'static str = "audio-profile";
|
||||
const AUDIO_PROFILE_DESCRIPTION: &'static str = "audio-profile-description";
|
||||
const PRESET: &'static str = "preset";
|
||||
const PRESET_NAME: &'static str = "preset-name";
|
||||
const AUDIO_PROFILE_NAME: &str = "audio-profile";
|
||||
const AUDIO_PROFILE_DESCRIPTION: &str = "audio-profile-description";
|
||||
const PRESET: &str = "preset";
|
||||
const PRESET_NAME: &str = "preset-name";
|
||||
const PRESENCE: u32 = 5;
|
||||
const ALLOW_DYNAMIC_OUTPUT: bool = false;
|
||||
const ENABLED: bool = false;
|
||||
|
||||
const VIDEO_PROFILE_NAME: &'static str = "video-profile";
|
||||
const VIDEO_PROFILE_DESCRIPTION: &'static str = "video-profile-description";
|
||||
const VIDEO_PROFILE_NAME: &str = "video-profile";
|
||||
const VIDEO_PROFILE_DESCRIPTION: &str = "video-profile-description";
|
||||
|
||||
const CONTAINER_PROFILE_NAME: &'static str = "container-profile";
|
||||
const CONTAINER_PROFILE_DESCRIPTION: &'static str = "container-profile-description";
|
||||
const CONTAINER_PROFILE_NAME: &str = "container-profile";
|
||||
const CONTAINER_PROFILE_DESCRIPTION: &str = "container-profile-description";
|
||||
|
||||
// Video profile exclusive attributes
|
||||
const PASS: u32 = 8;
|
||||
|
|
|
@ -156,7 +156,6 @@ mod tests {
|
|||
l.run();
|
||||
|
||||
let res = res_store.lock().unwrap().take().unwrap();
|
||||
assert!(res.is_ok(), "Error {}", res.unwrap_err());
|
||||
let res = res.unwrap();
|
||||
|
||||
let converted_out_caps = res.get_caps().unwrap();
|
||||
|
|
|
@ -973,13 +973,13 @@ mod tests {
|
|||
.expect("Failed to create VideoInfo");
|
||||
|
||||
assert_eq!(info.stride(), [1920, 1920]);
|
||||
assert_eq!(info.offset(), [0, 2073600]);
|
||||
assert_eq!(info.offset(), [0, 2_073_600]);
|
||||
|
||||
let mut align = ::VideoAlignment::new(0, 0, 0, 8, &[0; VIDEO_MAX_PLANES]);
|
||||
assert!(info.align(&mut align));
|
||||
|
||||
assert_eq!(info.stride(), [1928, 1928]);
|
||||
assert_eq!(info.offset(), [0, 2082240]);
|
||||
assert_eq!(info.offset(), [0, 2_082_240]);
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "v1_12", feature = "dox"))]
|
||||
|
|
|
@ -247,7 +247,7 @@ mod tests {
|
|||
let mut pretty_config = ron::ser::PrettyConfig::default();
|
||||
pretty_config.new_line = "".to_string();
|
||||
|
||||
let res = ron::ser::to_string_pretty(&caps, pretty_config.clone());
|
||||
let res = ron::ser::to_string_pretty(&caps, pretty_config);
|
||||
assert_eq!(
|
||||
Ok(concat!(
|
||||
"Some([",
|
||||
|
@ -279,7 +279,7 @@ mod tests {
|
|||
let mut pretty_config = ron::ser::PrettyConfig::default();
|
||||
pretty_config.new_line = "".to_string();
|
||||
|
||||
let res = ron::ser::to_string_pretty(&caps, pretty_config.clone());
|
||||
let res = ron::ser::to_string_pretty(&caps, pretty_config);
|
||||
assert_eq!(
|
||||
Ok(concat!(
|
||||
"Some([",
|
||||
|
@ -339,7 +339,7 @@ mod tests {
|
|||
assert_eq!(Ok("Any".to_owned()), res);
|
||||
|
||||
let caps_empty = Caps::new_empty();
|
||||
let res = ron::ser::to_string_pretty(&caps_empty, pretty_config.clone());
|
||||
let res = ron::ser::to_string_pretty(&caps_empty, pretty_config);
|
||||
assert_eq!(Ok("Empty".to_owned()), res);
|
||||
}
|
||||
|
||||
|
|
|
@ -106,13 +106,7 @@ impl ClockId {
|
|||
unsafe {
|
||||
let res =
|
||||
gst_sys::gst_clock_id_compare_func(self.to_glib_none().0, other.to_glib_none().0);
|
||||
if res < 0 {
|
||||
cmp::Ordering::Less
|
||||
} else if res > 0 {
|
||||
cmp::Ordering::Greater
|
||||
} else {
|
||||
cmp::Ordering::Equal
|
||||
}
|
||||
res.cmp(&0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -87,13 +87,7 @@ impl cmp::PartialOrd for DateTime {
|
|||
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
|
||||
#[inline]
|
||||
fn get_cmp(delta: i32) -> Option<cmp::Ordering> {
|
||||
Some(if delta < 0 {
|
||||
cmp::Ordering::Less
|
||||
} else if delta == 0 {
|
||||
cmp::Ordering::Equal
|
||||
} else {
|
||||
cmp::Ordering::Greater
|
||||
})
|
||||
Some(delta.cmp(&0))
|
||||
}
|
||||
|
||||
if !(self.has_year() && other.has_year()) {
|
||||
|
@ -239,6 +233,7 @@ impl fmt::Display for DateTime {
|
|||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
#[test]
|
||||
fn test_to_utc() {
|
||||
::init().unwrap();
|
||||
|
|
|
@ -197,7 +197,7 @@ mod tests {
|
|||
assert_eq!(Ok("YM(2018, 5)".to_owned()), res);
|
||||
|
||||
let datetime = DateTime::new_y(2018);
|
||||
let res = ron::ser::to_string_pretty(&datetime, pretty_config.clone());
|
||||
let res = ron::ser::to_string_pretty(&datetime, pretty_config);
|
||||
assert_eq!(Ok("Y(2018)".to_owned()), res);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,13 +68,7 @@ impl cmp::Ord for Seqnum {
|
|||
fn cmp(&self, other: &Seqnum) -> cmp::Ordering {
|
||||
unsafe {
|
||||
let ret = gst_sys::gst_util_seqnum_compare(self.0, other.0);
|
||||
if ret < 0 {
|
||||
cmp::Ordering::Less
|
||||
} else if ret > 0 {
|
||||
cmp::Ordering::Greater
|
||||
} else {
|
||||
cmp::Ordering::Equal
|
||||
}
|
||||
ret.cmp(&0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ mod tests {
|
|||
assert_eq!("{\"Other\":[\"Percent\",42]}".to_owned(), res);
|
||||
|
||||
let value = GenericFormattedValue::Other(Format::__Unknown(7), 42);
|
||||
let res = ron::ser::to_string_pretty(&value, pretty_config.clone());
|
||||
let res = ron::ser::to_string_pretty(&value, pretty_config);
|
||||
assert_eq!(Ok("Other(__Unknown(7), 42)".to_owned()), res);
|
||||
let res = serde_json::to_string(&value).unwrap();
|
||||
assert_eq!("{\"Other\":[{\"__Unknown\":7},42]}".to_owned(), res);
|
||||
|
|
|
@ -474,7 +474,7 @@ mod tests {
|
|||
let log_fn = debug_add_log_function(handler);
|
||||
gst_info!(cat, obj: &obj, "meh");
|
||||
|
||||
let _ = receiver.recv().unwrap();
|
||||
receiver.recv().unwrap();
|
||||
|
||||
debug_remove_log_function(log_fn);
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@ mod tests {
|
|||
let notify = Arc::new(Mutex::new(None));
|
||||
let notify_clone = notify.clone();
|
||||
bin.connect_deep_notify(None, move |_, id, prop| {
|
||||
*notify_clone.lock().unwrap() = Some((id.clone(), String::from(prop.get_name())));
|
||||
*notify_clone.lock().unwrap() = Some((id.clone(), prop.get_name()));
|
||||
});
|
||||
|
||||
identity.set_property("silent", &false).unwrap();
|
||||
|
|
|
@ -191,8 +191,8 @@ mod tests {
|
|||
segment.get_flags(),
|
||||
SegmentFlags::RESET | SegmentFlags::SEGMENT
|
||||
);
|
||||
assert_eq!(segment.get_rate(), 1f64);
|
||||
assert_eq!(segment.get_applied_rate(), 0.9f64);
|
||||
assert!((segment.get_rate() - 1f64).abs() < std::f64::EPSILON);
|
||||
assert!((segment.get_applied_rate() - 0.9f64).abs() < std::f64::EPSILON);
|
||||
assert_eq!(segment.get_format(), Format::Time);
|
||||
assert_eq!(
|
||||
segment.get_base(),
|
||||
|
@ -254,8 +254,8 @@ mod tests {
|
|||
fmt_seg.get_flags(),
|
||||
SegmentFlags::RESET | SegmentFlags::SEGMENT
|
||||
);
|
||||
assert_eq!(fmt_seg.get_rate(), 1f64);
|
||||
assert_eq!(fmt_seg.get_applied_rate(), 0.9f64);
|
||||
assert!((fmt_seg.get_rate() - 1f64).abs() < std::f64::EPSILON);
|
||||
assert!((fmt_seg.get_applied_rate() - 0.9f64).abs() < std::f64::EPSILON);
|
||||
assert_eq!(fmt_seg.get_format(), Format::Time);
|
||||
assert_eq!(fmt_seg.get_base(), ClockTime::from_nseconds(123));
|
||||
assert_eq!(fmt_seg.get_offset(), ClockTime::from_nseconds(42));
|
||||
|
@ -286,8 +286,10 @@ mod tests {
|
|||
|
||||
let segment_de: Segment = ron::de::from_str(segment_se.as_str()).unwrap();
|
||||
assert_eq!(segment_de.get_flags(), segment.get_flags());
|
||||
assert_eq!(segment_de.get_rate(), segment.get_rate());
|
||||
assert_eq!(segment_de.get_applied_rate(), segment.get_applied_rate());
|
||||
assert!((segment_de.get_rate() - segment.get_rate()).abs() < std::f64::EPSILON);
|
||||
assert!(
|
||||
(segment_de.get_applied_rate() - segment.get_applied_rate()).abs() < std::f64::EPSILON
|
||||
);
|
||||
assert_eq!(segment_de.get_format(), segment.get_format());
|
||||
assert_eq!(segment_de.get_base(), segment.get_base());
|
||||
assert_eq!(segment_de.get_offset(), segment.get_offset());
|
||||
|
|
|
@ -523,13 +523,13 @@ mod tests {
|
|||
use super::*;
|
||||
use glib;
|
||||
use glib::subclass;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::atomic;
|
||||
|
||||
struct TestElement {
|
||||
srcpad: ::Pad,
|
||||
sinkpad: ::Pad,
|
||||
n_buffers: Mutex<u32>,
|
||||
reached_playing: Mutex<bool>,
|
||||
n_buffers: atomic::AtomicU32,
|
||||
reached_playing: atomic::AtomicBool,
|
||||
}
|
||||
|
||||
impl TestElement {
|
||||
|
@ -578,7 +578,7 @@ mod tests {
|
|||
_element: &::Element,
|
||||
buffer: ::Buffer,
|
||||
) -> Result<::FlowSuccess, ::FlowError> {
|
||||
*self.n_buffers.lock().unwrap() += 1;
|
||||
self.n_buffers.fetch_add(1, atomic::Ordering::SeqCst);
|
||||
self.srcpad.push(buffer)
|
||||
}
|
||||
|
||||
|
@ -616,8 +616,8 @@ mod tests {
|
|||
TestElement::set_pad_functions(&sinkpad, &srcpad);
|
||||
|
||||
Self {
|
||||
n_buffers: Mutex::new(0),
|
||||
reached_playing: Mutex::new(false),
|
||||
n_buffers: atomic::AtomicU32::new(0),
|
||||
reached_playing: atomic::AtomicBool::new(false),
|
||||
srcpad,
|
||||
sinkpad,
|
||||
}
|
||||
|
@ -665,7 +665,7 @@ mod tests {
|
|||
let res = self.parent_change_state(element, transition)?;
|
||||
|
||||
if transition == ::StateChange::PausedToPlaying {
|
||||
*self.reached_playing.lock().unwrap() = true;
|
||||
self.reached_playing.store(true, atomic::Ordering::SeqCst);
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
|
@ -706,7 +706,7 @@ mod tests {
|
|||
pipeline.set_state(::State::Null).unwrap();
|
||||
|
||||
let imp = TestElement::from_instance(&element);
|
||||
assert_eq!(*imp.n_buffers.lock().unwrap(), 100);
|
||||
assert_eq!(*imp.reached_playing.lock().unwrap(), true);
|
||||
assert_eq!(imp.n_buffers.load(atomic::Ordering::SeqCst), 100);
|
||||
assert_eq!(imp.reached_playing.load(atomic::Ordering::SeqCst), true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,11 +102,11 @@ mod tests {
|
|||
use crate::prelude::*;
|
||||
use glib;
|
||||
use glib::subclass;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::atomic;
|
||||
|
||||
struct TestPad {
|
||||
linked: Mutex<bool>,
|
||||
unlinked: Mutex<bool>,
|
||||
linked: atomic::AtomicBool,
|
||||
unlinked: atomic::AtomicBool,
|
||||
}
|
||||
|
||||
impl ObjectSubclass for TestPad {
|
||||
|
@ -119,8 +119,8 @@ mod tests {
|
|||
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
linked: Mutex::new(false),
|
||||
unlinked: Mutex::new(false),
|
||||
linked: atomic::AtomicBool::new(false),
|
||||
unlinked: atomic::AtomicBool::new(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,12 +131,12 @@ mod tests {
|
|||
|
||||
impl PadImpl for TestPad {
|
||||
fn linked(&self, pad: &Pad, peer: &Pad) {
|
||||
*self.linked.lock().unwrap() = true;
|
||||
self.linked.store(true, atomic::Ordering::SeqCst);
|
||||
self.parent_linked(pad, peer)
|
||||
}
|
||||
|
||||
fn unlinked(&self, pad: &Pad, peer: &Pad) {
|
||||
*self.unlinked.lock().unwrap() = true;
|
||||
self.unlinked.store(true, atomic::Ordering::SeqCst);
|
||||
self.parent_unlinked(pad, peer)
|
||||
}
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ mod tests {
|
|||
pad.unlink(&otherpad).unwrap();
|
||||
|
||||
let imp = TestPad::from_instance(&pad);
|
||||
assert!(*imp.linked.lock().unwrap());
|
||||
assert!(*imp.unlinked.lock().unwrap());
|
||||
assert!(imp.linked.load(atomic::Ordering::SeqCst));
|
||||
assert!(imp.unlinked.load(atomic::Ordering::SeqCst));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -893,7 +893,7 @@ mod tests {
|
|||
{
|
||||
let tags = tags.get_mut().unwrap();
|
||||
tags.add::<Title>(&"some title", TagMergeMode::Append);
|
||||
tags.add::<Duration>(&(::SECOND * 120).into(), TagMergeMode::Append);
|
||||
tags.add::<Duration>(&(::SECOND * 120), TagMergeMode::Append);
|
||||
}
|
||||
assert_eq!(
|
||||
tags.to_string(),
|
||||
|
@ -910,7 +910,7 @@ mod tests {
|
|||
{
|
||||
let tags = tags.get_mut().unwrap();
|
||||
tags.add::<Title>(&"some title", TagMergeMode::Append);
|
||||
tags.add::<Duration>(&(::SECOND * 120).into(), TagMergeMode::Append);
|
||||
tags.add::<Duration>(&(::SECOND * 120), TagMergeMode::Append);
|
||||
}
|
||||
|
||||
assert_eq!(tags.get::<Title>().unwrap().get(), Some("some title"));
|
||||
|
@ -939,6 +939,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
fn test_generic() {
|
||||
::init().unwrap();
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ use serde::ser;
|
|||
use serde::ser::{Serialize, SerializeSeq, SerializeStruct, SerializeTuple, Serializer};
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
|
||||
|
@ -123,18 +124,20 @@ struct TagListSer<'a>(&'a TagListRef);
|
|||
impl<'a> Serialize for TagListSer<'a> {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
let tag_count = self.0.n_tags();
|
||||
if tag_count > 0 {
|
||||
match tag_count.cmp(&0) {
|
||||
cmp::Ordering::Greater => {
|
||||
let mut seq = serializer.serialize_seq(Some(tag_count as usize))?;
|
||||
let tag_list_iter = self.0.iter_generic();
|
||||
for (tag_name, tag_iter) in tag_list_iter {
|
||||
seq.serialize_element(&TagsSer::new(tag_name, tag_iter))?;
|
||||
}
|
||||
seq.end()
|
||||
} else if tag_count == 0 {
|
||||
}
|
||||
cmp::Ordering::Equal => {
|
||||
let seq = serializer.serialize_seq(None)?;
|
||||
seq.end()
|
||||
} else {
|
||||
Err(ser::Error::custom("tag count < 0"))
|
||||
}
|
||||
cmp::Ordering::Less => Err(ser::Error::custom("tag count < 0")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -337,7 +340,7 @@ mod tests {
|
|||
let tags = tags.get_mut().unwrap();
|
||||
tags.add::<Title>(&"a title", TagMergeMode::Append); // String
|
||||
tags.add::<Title>(&"another title", TagMergeMode::Append); // String
|
||||
tags.add::<Duration>(&(::SECOND * 120).into(), TagMergeMode::Append); // u64
|
||||
tags.add::<Duration>(&(::SECOND * 120), TagMergeMode::Append); // u64
|
||||
tags.add::<Bitrate>(&96_000, TagMergeMode::Append); // u32
|
||||
tags.add::<TrackGain>(&1f64, TagMergeMode::Append); // f64
|
||||
tags.add::<Date>(
|
||||
|
@ -485,7 +488,9 @@ mod tests {
|
|||
::SECOND * 120
|
||||
);
|
||||
assert_eq!(tags.get_index::<Bitrate>(0).unwrap().get_some(), 96_000);
|
||||
assert_eq!(tags.get_index::<TrackGain>(0).unwrap().get_some(), 1f64);
|
||||
assert!(
|
||||
(tags.get_index::<TrackGain>(0).unwrap().get_some() - 1f64).abs() < std::f64::EPSILON
|
||||
);
|
||||
assert_eq!(
|
||||
tags.get_index::<Date>(0).unwrap().get().unwrap(),
|
||||
glib::Date::new_dmy(28, glib::DateMonth::May, 2018)
|
||||
|
@ -524,7 +529,9 @@ mod tests {
|
|||
Some("another title")
|
||||
);
|
||||
assert_eq!(tags.get_index::<Bitrate>(0).unwrap().get_some(), 96_000);
|
||||
assert_eq!(tags.get_index::<TrackGain>(0).unwrap().get_some(), 1f64);
|
||||
assert!(
|
||||
(tags.get_index::<TrackGain>(0).unwrap().get_some() - 1f64).abs() < std::f64::EPSILON
|
||||
);
|
||||
assert_eq!(
|
||||
tags.get_index::<Date>(0).unwrap().get().unwrap(),
|
||||
glib::Date::new_dmy(28, glib::DateMonth::May, 2018)
|
||||
|
@ -552,7 +559,7 @@ mod tests {
|
|||
tags.set_scope(TagScope::Global);
|
||||
tags.add::<Title>(&"a title", TagMergeMode::Append); // String
|
||||
tags.add::<Title>(&"another title", TagMergeMode::Append); // String
|
||||
tags.add::<Duration>(&(::SECOND * 120).into(), TagMergeMode::Append); // u64
|
||||
tags.add::<Duration>(&(::SECOND * 120), TagMergeMode::Append); // u64
|
||||
tags.add::<Bitrate>(&96_000, TagMergeMode::Append); // u32
|
||||
tags.add::<TrackGain>(&1f64, TagMergeMode::Append); // f64
|
||||
tags.add::<Date>(
|
||||
|
@ -593,9 +600,11 @@ mod tests {
|
|||
tags_de.get_index::<Bitrate>(0).unwrap().get_some(),
|
||||
tags.get_index::<Bitrate>(0).unwrap().get_some(),
|
||||
);
|
||||
assert_eq!(
|
||||
tags_de.get_index::<TrackGain>(0).unwrap().get_some(),
|
||||
tags.get_index::<TrackGain>(0).unwrap().get_some(),
|
||||
assert!(
|
||||
(tags_de.get_index::<TrackGain>(0).unwrap().get_some()
|
||||
- tags.get_index::<TrackGain>(0).unwrap().get_some())
|
||||
.abs()
|
||||
< std::f64::EPSILON
|
||||
);
|
||||
assert_eq!(
|
||||
tags_de.get_index::<Date>(0).unwrap().get(),
|
||||
|
|
|
@ -283,6 +283,7 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
#[test]
|
||||
fn test_deserialize() {
|
||||
use tags::Title;
|
||||
|
@ -417,6 +418,7 @@ mod tests {
|
|||
assert_eq!(0, chapter2.get_sub_entries().len());
|
||||
}
|
||||
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
#[test]
|
||||
fn test_serde_roundtrip() {
|
||||
::init().unwrap();
|
||||
|
|
|
@ -913,9 +913,9 @@ mod tests {
|
|||
let f1 = ::Fraction::new(1, 2);
|
||||
let f2 = ::Fraction::new(2, 3);
|
||||
let mut f3 = f1 * f2;
|
||||
let f4 = f1 * &f2;
|
||||
let f4 = f1 * f2;
|
||||
f3 *= f2;
|
||||
f3 *= &f4;
|
||||
f3 *= f4;
|
||||
|
||||
assert_eq!(f3, ::Fraction::new(2, 27));
|
||||
}
|
||||
|
|
|
@ -348,7 +348,7 @@ mod tests {
|
|||
// Bitmask
|
||||
let bitmask = Bitmask::new(1024 + 128 + 32);
|
||||
|
||||
let res = ron::ser::to_string_pretty(&bitmask, pretty_config.clone());
|
||||
let res = ron::ser::to_string_pretty(&bitmask, pretty_config);
|
||||
assert_eq!(Ok("(1184)".to_owned()), res);
|
||||
|
||||
let res = serde_json::to_string(&bitmask).unwrap();
|
||||
|
@ -448,7 +448,7 @@ mod tests {
|
|||
&send_value_date_time_none,
|
||||
]);
|
||||
|
||||
let res = ron::ser::to_string_pretty(&list, pretty_config.clone());
|
||||
let res = ron::ser::to_string_pretty(&list, pretty_config);
|
||||
assert_eq!(
|
||||
Ok(concat!(
|
||||
r#"["#,
|
||||
|
@ -555,6 +555,7 @@ mod tests {
|
|||
assert_eq!(bitmask_de, bitmask);
|
||||
}
|
||||
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
#[test]
|
||||
fn test_deserialize_collections() {
|
||||
::init().unwrap();
|
||||
|
|
Loading…
Reference in a new issue