2020-04-13 17:39:52 +00:00
|
|
|
// Copyright (C) 2020 Mathieu Duponchelle <mathieu@centricular.com>
|
|
|
|
//
|
2022-01-15 18:40:12 +00:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public License, v2.0.
|
|
|
|
// If a copy of the MPL was not distributed with this file, You can obtain one at
|
|
|
|
// <https://mozilla.org/MPL/2.0/>.
|
2020-04-13 17:39:52 +00:00
|
|
|
//
|
2022-01-15 18:40:12 +00:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
2020-04-13 17:39:52 +00:00
|
|
|
|
2021-06-03 18:20:54 +00:00
|
|
|
use gst::prelude::*;
|
2020-04-13 17:39:52 +00:00
|
|
|
|
|
|
|
fn init() {
|
|
|
|
use std::sync::Once;
|
|
|
|
static INIT: Once = Once::new();
|
|
|
|
|
|
|
|
INIT.call_once(|| {
|
|
|
|
gst::init().unwrap();
|
2022-10-23 15:42:58 +00:00
|
|
|
gsttextwrap::plugin_register_static().expect("textwrap test");
|
2020-04-13 17:39:52 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_columns() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let input = b"Split this text up";
|
|
|
|
|
|
|
|
let expected_output = "Split\nthis\ntext\nup";
|
|
|
|
|
|
|
|
let mut h = gst_check::Harness::new("textwrap");
|
|
|
|
|
|
|
|
{
|
2021-04-12 12:49:54 +00:00
|
|
|
let wrap = h.element().expect("Could not create textwrap");
|
2021-11-08 09:55:40 +00:00
|
|
|
wrap.set_property("columns", 5u32);
|
2020-04-13 17:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
h.set_src_caps_str("text/x-raw, format=utf8");
|
|
|
|
|
|
|
|
let buf = {
|
|
|
|
let mut buf = gst::Buffer::from_mut_slice(Vec::from(&input[..]));
|
|
|
|
let buf_ref = buf.get_mut().unwrap();
|
2022-10-17 17:48:43 +00:00
|
|
|
buf_ref.set_pts(gst::ClockTime::ZERO);
|
|
|
|
buf_ref.set_duration(2.seconds());
|
2020-04-13 17:39:52 +00:00
|
|
|
buf
|
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(h.push(buf), Ok(gst::FlowSuccess::Ok));
|
|
|
|
|
|
|
|
let buf = h.pull().expect("Couldn't pull buffer");
|
|
|
|
|
2021-05-26 17:03:09 +00:00
|
|
|
assert_eq!(buf.pts(), Some(gst::ClockTime::ZERO));
|
2022-10-17 17:48:43 +00:00
|
|
|
assert_eq!(buf.duration(), Some(2.seconds()));
|
2020-04-13 17:39:52 +00:00
|
|
|
|
|
|
|
let map = buf.map_readable().expect("Couldn't map buffer readable");
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
std::str::from_utf8(map.as_ref()),
|
|
|
|
std::str::from_utf8(expected_output.as_ref())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_lines() {
|
|
|
|
init();
|
|
|
|
|
|
|
|
let input = b"Split this text up";
|
|
|
|
|
|
|
|
let mut h = gst_check::Harness::new("textwrap");
|
|
|
|
|
|
|
|
{
|
2021-04-12 12:49:54 +00:00
|
|
|
let wrap = h.element().expect("Could not create textwrap");
|
2021-11-08 09:55:40 +00:00
|
|
|
wrap.set_property("columns", 5u32);
|
|
|
|
wrap.set_property("lines", 2u32);
|
2020-04-13 17:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
h.set_src_caps_str("text/x-raw, format=utf8");
|
|
|
|
|
|
|
|
let buf = {
|
|
|
|
let mut buf = gst::Buffer::from_mut_slice(Vec::from(&input[..]));
|
|
|
|
let buf_ref = buf.get_mut().unwrap();
|
2022-10-17 17:48:43 +00:00
|
|
|
buf_ref.set_pts(gst::ClockTime::ZERO);
|
|
|
|
buf_ref.set_duration(2.seconds());
|
2020-04-13 17:39:52 +00:00
|
|
|
buf
|
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(h.push(buf), Ok(gst::FlowSuccess::Ok));
|
|
|
|
|
|
|
|
let buf = h.pull().expect("Couldn't pull buffer");
|
|
|
|
|
2021-05-26 17:03:09 +00:00
|
|
|
assert_eq!(buf.pts(), Some(gst::ClockTime::ZERO));
|
|
|
|
assert_eq!(buf.duration(), Some(gst::ClockTime::SECOND));
|
2020-04-13 17:39:52 +00:00
|
|
|
|
|
|
|
let expected_output = "Split\nthis";
|
|
|
|
|
|
|
|
let map = buf.map_readable().expect("Couldn't map buffer readable");
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
std::str::from_utf8(map.as_ref()),
|
|
|
|
std::str::from_utf8(expected_output.as_ref())
|
|
|
|
);
|
|
|
|
|
|
|
|
let buf = h.pull().expect("Couldn't pull buffer");
|
|
|
|
|
2021-05-26 17:03:09 +00:00
|
|
|
assert_eq!(buf.pts(), Some(gst::ClockTime::SECOND));
|
|
|
|
assert_eq!(buf.duration(), Some(gst::ClockTime::SECOND));
|
2020-04-13 17:39:52 +00:00
|
|
|
|
|
|
|
let expected_output = "text\nup";
|
|
|
|
|
|
|
|
let map = buf.map_readable().expect("Couldn't map buffer readable");
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
std::str::from_utf8(map.as_ref()),
|
|
|
|
std::str::from_utf8(expected_output.as_ref())
|
|
|
|
);
|
|
|
|
}
|