2020-08-03 15:17:03 +05:30
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
mod common;
|
2021-07-01 19:57:37 +05:30
|
|
|
|
|
|
|
use common::common_args::*;
|
2020-08-07 19:00:00 +05:30
|
|
|
use common::test_dir::*;
|
2021-05-04 13:40:20 +05:30
|
|
|
use common::*;
|
2020-08-03 15:17:03 +05:30
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
const USAGE: &str = "Usage: thin_rmap [options] {device|file}\n\
|
|
|
|
Options:\n \
|
|
|
|
{-h|--help}\n \
|
|
|
|
{-V|--version}\n \
|
|
|
|
{--region <block range>}*\n\
|
|
|
|
Where:\n \
|
|
|
|
<block range> is of the form <begin>..<one-past-the-end>\n \
|
|
|
|
for example 5..45 denotes blocks 5 to 44 inclusive, but not block 45";
|
2020-08-03 15:17:03 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
//------------------------------------------
|
2020-08-03 15:17:03 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
test_accepts_help!(THIN_RMAP, USAGE);
|
|
|
|
test_accepts_version!(THIN_RMAP);
|
|
|
|
test_rejects_bad_option!(THIN_RMAP);
|
2020-08-03 15:17:03 +05:30
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
//------------------------------------------
|
2020-08-03 15:17:03 +05:30
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn valid_region_format_should_pass() -> Result<()> {
|
|
|
|
let mut td = TestDir::new()?;
|
|
|
|
let md = mk_valid_md(&mut td)?;
|
2021-07-01 19:57:37 +05:30
|
|
|
let md_path = md.to_str().unwrap();
|
|
|
|
run_ok(THIN_RMAP, &["--region", "23..7890", md_path])?;
|
2020-08-03 15:17:03 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_regions_should_fail() -> Result<()> {
|
2021-05-04 13:40:20 +05:30
|
|
|
let invalid_regions = [
|
|
|
|
"23,7890",
|
|
|
|
"23..six",
|
|
|
|
"found..7890",
|
|
|
|
"89..88",
|
|
|
|
"89..89",
|
|
|
|
"89..",
|
|
|
|
"",
|
|
|
|
"89...99",
|
|
|
|
];
|
2020-08-03 15:17:03 +05:30
|
|
|
for r in &invalid_regions {
|
|
|
|
let mut td = TestDir::new()?;
|
|
|
|
let md = mk_valid_md(&mut td)?;
|
2021-07-01 19:57:37 +05:30
|
|
|
run_fail(THIN_RMAP, &[&r.to_string(), md.to_str().unwrap()])?;
|
2020-08-03 15:17:03 +05:30
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multiple_regions_should_pass() -> Result<()> {
|
|
|
|
let mut td = TestDir::new()?;
|
|
|
|
let md = mk_valid_md(&mut td)?;
|
2021-07-01 19:57:37 +05:30
|
|
|
run_ok(
|
|
|
|
THIN_RMAP,
|
|
|
|
&[
|
|
|
|
"--region",
|
|
|
|
"1..23",
|
|
|
|
"--region",
|
|
|
|
"45..78",
|
|
|
|
md.to_str().unwrap(),
|
|
|
|
],
|
|
|
|
)?;
|
2020-08-03 15:17:03 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn junk_input() -> Result<()> {
|
|
|
|
let mut td = TestDir::new()?;
|
|
|
|
let xml = mk_valid_xml(&mut td)?;
|
2021-07-01 19:57:37 +05:30
|
|
|
run_fail(THIN_RMAP, &["--region", "0..-1", xml.to_str().unwrap()])?;
|
2020-08-03 15:17:03 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|