Skip to content

Commit b3ec739

Browse files
committed
Add test for arrays of strings
1 parent 2411e6d commit b3ec739

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/templ.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ macro_rules! string_array_arg {
8181
.iter()
8282
.map(|x| ::std::ffi::CString::new(*x).expect("invalid C string"))
8383
.collect::<::std::vec::Vec<_>>();
84-
let $name = $name
85-
.iter()
86-
.map(|x| x.as_ptr())
87-
.collect::<::std::vec::Vec<_>>();
84+
let $name = $name.iter().map(|x| x.as_ptr()).collect::<::std::vec::Vec<_>>();
8885
};
8986
}
9087

@@ -95,11 +92,8 @@ macro_rules! string_array_arg_mut {
9592
.iter()
9693
.map(|x| ::std::ffi::CString::new(*x).expect("invalid C string"))
9794
.collect::<::std::vec::Vec<_>>();
98-
// Casting to mut below trusts on undefined CString behavior.
99-
let mut $name = $name
100-
.iter()
101-
.map(|x| x.as_ptr().cast_mut())
102-
.collect::<::std::vec::Vec<_>>();
95+
// fixme: Casting to mut below trusts on undefined CString behavior.
96+
let mut $name = $name.iter().map(|x| x.as_ptr().cast_mut()).collect::<::std::vec::Vec<_>>();
10397
};
10498
}
10599

tests/marshalling.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Contains all tests that cover marshalling types to and from C++
22
33
use opencv::core;
4-
use opencv::core::{Scalar, SparseMat, Tuple};
4+
use opencv::core::{CommandLineParser, Scalar, SparseMat, Tuple};
55
use opencv::prelude::*;
66
use opencv::Result;
77

@@ -273,3 +273,12 @@ fn tuple() -> Result<()> {
273273
// assert_eq!(mat.data_typed()?, mat_src.data_typed()?);
274274
// Ok(())
275275
// }
276+
277+
#[test]
278+
fn string_array() -> Result<()> {
279+
let args = ["test", "-a=b"];
280+
let mut parser = CommandLineParser::new(i32::try_from(args.len())?, &args, "{a | | }")?;
281+
assert!(parser.has("a")?);
282+
assert_eq!("b", parser.get_str("a", true)?);
283+
Ok(())
284+
}

0 commit comments

Comments
 (0)