More minor cleanup.

- Runs rustfmt.
- Speel check help-text
This commit is contained in:
Tyler 2021-07-02 14:24:01 -07:00
parent 7f03ecf74b
commit 8e862b86dd
10 changed files with 1107 additions and 1622 deletions

View file

@ -39,7 +39,6 @@ pub const ASCII_LCASE_TO_UCASE: ConversionTable = [
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
];
pub const ASCII_TO_EBCDIC: ConversionTable = [
@ -137,7 +136,6 @@ pub const ASCII_TO_IBM_UCASE_TO_LCASE: ConversionTable = [
0xdc, 0xdd, 0xde, 0xdf, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
];
pub const ASCII_TO_IBM_LCASE_TO_UCASE: ConversionTable = [
0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, 0x25, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f,
@ -176,7 +174,6 @@ pub const EBCDIC_TO_ASCII: ConversionTable = [
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
];
pub const EBCDIC_TO_ASCII_UCASE_TO_LCASE: ConversionTable = [
0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, 0x25, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f,
@ -214,4 +211,3 @@ pub const EBCDIC_TO_ASCII_LCASE_TO_UCASE: ConversionTable = [
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xda, 0xdb,
0xdc, 0xdd, 0xde, 0xdf, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
];

View file

@ -3,8 +3,7 @@ use crate::conversion_tables::*;
use std::error::Error;
use std::time;
pub struct ProgUpdate
{
pub struct ProgUpdate {
pub reads_complete: u64,
pub reads_partial: u64,
pub writes_complete: u64,
@ -14,16 +13,13 @@ pub struct ProgUpdate
pub duration: time::Duration,
}
pub struct ReadStat
{
pub struct ReadStat {
pub reads_complete: u64,
pub reads_partial: u64,
pub records_truncated: u32,
}
impl std::ops::AddAssign for ReadStat
{
fn add_assign(&mut self, other: Self)
{
impl std::ops::AddAssign for ReadStat {
fn add_assign(&mut self, other: Self) {
*self = Self {
reads_complete: self.reads_complete + other.reads_complete,
reads_partial: self.reads_partial + other.reads_partial,
@ -32,16 +28,13 @@ impl std::ops::AddAssign for ReadStat
}
}
pub struct WriteStat
{
pub struct WriteStat {
pub writes_complete: u64,
pub writes_partial: u64,
pub bytes_total: u128,
}
impl std::ops::AddAssign for WriteStat
{
fn add_assign(&mut self, other: Self)
{
impl std::ops::AddAssign for WriteStat {
fn add_assign(&mut self, other: Self) {
*self = Self {
writes_complete: self.writes_complete + other.writes_complete,
writes_partial: self.writes_partial + other.writes_partial,
@ -53,8 +46,7 @@ impl std::ops::AddAssign for WriteStat
type Cbs = usize;
/// Stores all Conv Flags that apply to the input
pub struct IConvFlags
{
pub struct IConvFlags {
pub ctable: Option<&'static ConversionTable>,
pub block: Option<Cbs>,
pub unblock: Option<Cbs>,
@ -65,8 +57,7 @@ pub struct IConvFlags
/// Stores all Conv Flags that apply to the output
#[derive(Debug, PartialEq)]
pub struct OConvFlags
{
pub struct OConvFlags {
pub sparse: bool,
pub excl: bool,
pub nocreat: bool,
@ -76,8 +67,7 @@ pub struct OConvFlags
}
/// Stores all Flags that apply to the input
pub struct IFlags
{
pub struct IFlags {
pub cio: bool,
pub direct: bool,
pub directory: bool,
@ -97,8 +87,7 @@ pub struct IFlags
}
/// Stores all Flags that apply to the output
pub struct OFlags
{
pub struct OFlags {
pub append: bool,
pub cio: bool,
pub direct: bool,
@ -119,8 +108,7 @@ pub struct OFlags
/// The value of the status cl-option.
/// Controls printing of transfer stats
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum StatusLevel
{
pub enum StatusLevel {
Progress,
Noxfer,
None,
@ -130,38 +118,35 @@ pub enum StatusLevel
/// Defaults to Reads(N)
/// if iflag=count_bytes
/// then becomes Bytes(N)
pub enum CountType
{
pub enum CountType {
Reads(usize),
Bytes(usize),
}
#[derive(Debug)]
pub enum InternalError
{
pub enum InternalError {
WrongInputType,
WrongOutputType,
InvalidConvBlockUnblockCase,
}
impl std::fmt::Display for InternalError
{
impl std::fmt::Display for InternalError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self
{
Self::WrongInputType |
Self::WrongOutputType =>
write!(f, "Internal dd error: Wrong Input/Output data type"),
Self::InvalidConvBlockUnblockCase =>
write!(f, "Internal dd error: Invalid Conversion, Block, or Unblock data"),
match self {
Self::WrongInputType | Self::WrongOutputType => {
write!(f, "Internal dd error: Wrong Input/Output data type")
}
Self::InvalidConvBlockUnblockCase => write!(
f,
"Internal dd error: Invalid Conversion, Block, or Unblock data"
),
}
}
}
impl Error for InternalError {}
pub mod options
{
pub mod options {
pub const INFILE: &'static str = "if";
pub const OUTFILE: &'static str = "of";
pub const IBS: &'static str = "ibs";

File diff suppressed because it is too large Load diff

View file

@ -81,176 +81,176 @@ macro_rules! make_unblock_test (
);
#[test]
fn block_test_no_nl()
{
fn block_test_no_nl() {
let mut rs = rs!();
let buf = vec![0u8, 1u8, 2u8, 3u8];
let res = block(buf, 4, &mut rs);
assert_eq!(res, vec![
vec![0u8, 1u8, 2u8, 3u8],
]);
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, 3u8],]);
}
#[test]
fn block_test_no_nl_short_record()
{
fn block_test_no_nl_short_record() {
let mut rs = rs!();
let buf = vec![0u8, 1u8, 2u8, 3u8];
let res = block(buf, 8, &mut rs);
assert_eq!(res, vec![
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
]);
assert_eq!(
res,
vec![vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],]
);
}
#[test]
fn block_test_no_nl_trunc()
{
fn block_test_no_nl_trunc() {
let mut rs = rs!();
let buf = vec![0u8, 1u8, 2u8, 3u8, 4u8];
let res = block(buf, 4, &mut rs);
assert_eq!(res, vec![
vec![0u8, 1u8, 2u8, 3u8/*, 4u8*/],
]);
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, 3u8 /*, 4u8*/],]);
assert_eq!(rs.records_truncated, 1);
}
#[test]
fn block_test_nl_gt_cbs_trunc()
{
fn block_test_nl_gt_cbs_trunc() {
let mut rs = rs!();
let buf = vec![0u8, 1u8, 2u8, 3u8, 4u8, NL, 0u8, 1u8, 2u8, 3u8, 4u8, NL, 5u8, 6u8, 7u8, 8u8];
let buf = vec![
0u8, 1u8, 2u8, 3u8, 4u8, NL, 0u8, 1u8, 2u8, 3u8, 4u8, NL, 5u8, 6u8, 7u8, 8u8,
];
let res = block(buf, 4, &mut rs);
assert_eq!(res, vec![
vec![0u8, 1u8, 2u8, 3u8],
// vec![4u8, SPACE, SPACE, SPACE],
vec![0u8, 1u8, 2u8, 3u8],
// vec![4u8, SPACE, SPACE, SPACE],
vec![5u8, 6u8, 7u8, 8u8],
]);
assert_eq!(
res,
vec![
vec![0u8, 1u8, 2u8, 3u8],
// vec![4u8, SPACE, SPACE, SPACE],
vec![0u8, 1u8, 2u8, 3u8],
// vec![4u8, SPACE, SPACE, SPACE],
vec![5u8, 6u8, 7u8, 8u8],
]
);
assert_eq!(rs.records_truncated, 2);
}
#[test]
fn block_test_surrounded_nl()
{
fn block_test_surrounded_nl() {
let mut rs = rs!();
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, 4u8, 5u8, 6u8, 7u8, 8u8];
let res = block(buf, 8, &mut rs);
assert_eq!(res, vec![
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
vec![4u8, 5u8, 6u8, 7u8, 8u8, SPACE, SPACE, SPACE],
]);
assert_eq!(
res,
vec![
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
vec![4u8, 5u8, 6u8, 7u8, 8u8, SPACE, SPACE, SPACE],
]
);
}
#[test]
fn block_test_multiple_nl_same_cbs_block()
{
fn block_test_multiple_nl_same_cbs_block() {
let mut rs = rs!();
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, 4u8, NL, 5u8, 6u8, 7u8, 8u8, 9u8];
let res = block(buf, 8, &mut rs);
assert_eq!(res, vec![
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
vec![4u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE],
vec![5u8, 6u8, 7u8, 8u8, 9u8, SPACE, SPACE, SPACE],
]);
assert_eq!(
res,
vec![
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
vec![4u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE],
vec![5u8, 6u8, 7u8, 8u8, 9u8, SPACE, SPACE, SPACE],
]
);
}
#[test]
fn block_test_multiple_nl_diff_cbs_block()
{
fn block_test_multiple_nl_diff_cbs_block() {
let mut rs = rs!();
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, 4u8, 5u8, 6u8, 7u8, NL, 8u8, 9u8];
let res = block(buf, 8, &mut rs);
assert_eq!(res, vec![
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
vec![4u8, 5u8, 6u8, 7u8, SPACE, SPACE, SPACE, SPACE],
vec![8u8, 9u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE],
]);
assert_eq!(
res,
vec![
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
vec![4u8, 5u8, 6u8, 7u8, SPACE, SPACE, SPACE, SPACE],
vec![8u8, 9u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE],
]
);
}
#[test]
fn block_test_end_nl_diff_cbs_block()
{
fn block_test_end_nl_diff_cbs_block() {
let mut rs = rs!();
let buf = vec![0u8, 1u8, 2u8, 3u8, NL];
let res = block(buf, 4, &mut rs);
assert_eq!(res, vec![
vec![0u8, 1u8, 2u8, 3u8],
]);
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, 3u8],]);
}
#[test]
fn block_test_end_nl_same_cbs_block()
{
fn block_test_end_nl_same_cbs_block() {
let mut rs = rs!();
let buf = vec![0u8, 1u8, 2u8, NL];
let res = block(buf, 4, &mut rs);
assert_eq!(res, vec![
vec![0u8, 1u8, 2u8, SPACE]
]);
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, SPACE]]);
}
#[test]
fn block_test_double_end_nl()
{
fn block_test_double_end_nl() {
let mut rs = rs!();
let buf = vec![0u8, 1u8, 2u8, NL, NL];
let res = block(buf, 4, &mut rs);
assert_eq!(res, vec![
vec![0u8, 1u8, 2u8, SPACE],
vec![SPACE, SPACE, SPACE, SPACE],
]);
assert_eq!(
res,
vec![vec![0u8, 1u8, 2u8, SPACE], vec![SPACE, SPACE, SPACE, SPACE],]
);
}
#[test]
fn block_test_start_nl()
{
fn block_test_start_nl() {
let mut rs = rs!();
let buf = vec![NL, 0u8, 1u8, 2u8, 3u8];
let res = block(buf, 4, &mut rs);
assert_eq!(res, vec![
vec![SPACE, SPACE, SPACE, SPACE],
vec![0u8, 1u8, 2u8, 3u8],
]);
assert_eq!(
res,
vec![vec![SPACE, SPACE, SPACE, SPACE], vec![0u8, 1u8, 2u8, 3u8],]
);
}
#[test]
fn block_test_double_surrounded_nl_no_trunc()
{
fn block_test_double_surrounded_nl_no_trunc() {
let mut rs = rs!();
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, NL, 4u8, 5u8, 6u8, 7u8];
let res = block(buf, 8, &mut rs);
assert_eq!(res, vec![
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
vec![SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE],
vec![4u8, 5u8, 6u8, 7u8, SPACE, SPACE, SPACE, SPACE],
]);
assert_eq!(
res,
vec![
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
vec![SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE],
vec![4u8, 5u8, 6u8, 7u8, SPACE, SPACE, SPACE, SPACE],
]
);
}
#[test]
fn block_test_double_surrounded_nl_double_trunc()
{
fn block_test_double_surrounded_nl_double_trunc() {
let mut rs = rs!();
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, NL, 4u8, 5u8, 6u8, 7u8, 8u8];
let res = block(buf, 4, &mut rs);
assert_eq!(res, vec![
vec![0u8, 1u8, 2u8, 3u8],
vec![SPACE, SPACE, SPACE, SPACE],
vec![4u8, 5u8, 6u8, 7u8/*, 8u8*/],
]);
assert_eq!(
res,
vec![
vec![0u8, 1u8, 2u8, 3u8],
vec![SPACE, SPACE, SPACE, SPACE],
vec![4u8, 5u8, 6u8, 7u8 /*, 8u8*/],
]
);
assert_eq!(rs.records_truncated, 1);
}
@ -279,58 +279,51 @@ make_block_test!(
);
#[test]
fn unblock_test_full_cbs()
{
fn unblock_test_full_cbs() {
let buf = vec![0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8];
let res = unblock(buf, 8);
assert_eq!(res,
vec![0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, NL],
);
assert_eq!(res, vec![0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, NL],);
}
#[test]
fn unblock_test_all_space()
{
fn unblock_test_all_space() {
let buf = vec![SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE];
let res = unblock(buf, 8);
assert_eq!(res,
vec![NL],
);
assert_eq!(res, vec![NL],);
}
#[test]
fn unblock_test_decoy_spaces()
{
fn unblock_test_decoy_spaces() {
let buf = vec![0u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, 7u8];
let res = unblock(buf, 8);
assert_eq!(res,
vec![0u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, 7u8, NL],
assert_eq!(
res,
vec![0u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, 7u8, NL],
);
}
#[test]
fn unblock_test_strip_single_cbs()
{
fn unblock_test_strip_single_cbs() {
let buf = vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE];
let res = unblock(buf, 8);
assert_eq!(res,
vec![0u8, 1u8, 2u8, 3u8, NL],
);
assert_eq!(res, vec![0u8, 1u8, 2u8, 3u8, NL],);
}
#[test]
fn unblock_test_strip_multi_cbs()
{
fn unblock_test_strip_multi_cbs() {
let buf = vec![
vec![0u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE],
vec![0u8, 1u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE],
vec![0u8, 1u8, 2u8, SPACE, SPACE, SPACE, SPACE, SPACE],
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
].into_iter().flatten().collect::<Vec<_>>();
]
.into_iter()
.flatten()
.collect::<Vec<_>>();
let res = unblock(buf, 8);
@ -339,7 +332,10 @@ fn unblock_test_strip_multi_cbs()
vec![0u8, 1u8, NL],
vec![0u8, 1u8, 2u8, NL],
vec![0u8, 1u8, 2u8, 3u8, NL],
].into_iter().flatten().collect::<Vec<_>>();
]
.into_iter()
.flatten()
.collect::<Vec<_>>();
assert_eq!(res, exp);
}

View file

@ -99,7 +99,9 @@ make_sync_test!(
make_sync_test!(
deadbeef_16_delayed,
"deadbeef-16-delayed",
LazyReader { src: File::open("./test-resources/deadbeef-16.test").unwrap() },
LazyReader {
src: File::open("./test-resources/deadbeef-16.test").unwrap()
},
Some(0u8),
16,
32,

View file

@ -129,14 +129,16 @@ make_conv_test!(
);
#[test]
fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test()
{
fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test() {
// ASCII->EBCDIC
let test_name = "all-valid-ascii-to-ebcdic";
let tmp_fname_ae = format!("./test-resources/FAILED-{}.test", test_name);
let i = Input {
src: File::open("./test-resources/all-valid-ascii-chars-37eff01866ba3f538421b30b7cbefcac.test").unwrap(),
src: File::open(
"./test-resources/all-valid-ascii-chars-37eff01866ba3f538421b30b7cbefcac.test",
)
.unwrap(),
non_ascii: false,
ibs: 128,
xfer_stats: None,
@ -152,7 +154,7 @@ fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test()
oflags: DEFAULT_OFLAGS,
};
dd_fileout(i,o).unwrap();
dd_fileout(i, o).unwrap();
// EBCDIC->ASCII
let test_name = "all-valid-ebcdic-to-ascii";
@ -175,13 +177,18 @@ fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test()
oflags: DEFAULT_OFLAGS,
};
dd_fileout(i,o).unwrap();
dd_fileout(i, o).unwrap();
// Final Comparison
let res = File::open(&tmp_fname_ea).unwrap();
let spec = File::open("./test-resources/all-valid-ascii-chars-37eff01866ba3f538421b30b7cbefcac.test").unwrap();
let spec =
File::open("./test-resources/all-valid-ascii-chars-37eff01866ba3f538421b30b7cbefcac.test")
.unwrap();
assert_eq!(res.metadata().unwrap().len(), spec.metadata().unwrap().len());
assert_eq!(
res.metadata().unwrap().len(),
spec.metadata().unwrap().len()
);
let res = BufReader::new(res);
let spec = BufReader::new(spec);
@ -189,10 +196,8 @@ fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test()
let res = BufReader::new(res);
// Check all bytes match
for (b_res, b_spec) in res.bytes().zip(spec.bytes())
{
assert_eq!(b_res.unwrap(),
b_spec.unwrap());
for (b_res, b_spec) in res.bytes().zip(spec.bytes()) {
assert_eq!(b_res.unwrap(), b_spec.unwrap());
}
fs::remove_file(&tmp_fname_ae).unwrap();

View file

@ -1,13 +1,13 @@
use super::*;
mod sanity_tests;
mod conversion_tests;
mod block_unblock_tests;
mod conv_sync_tests;
mod conversion_tests;
mod sanity_tests;
use std::fs;
use std::io::prelude::*;
use std::io::BufReader;
use std::fs;
const DEFAULT_CFO: OConvFlags = OConvFlags {
sparse: false,
@ -55,15 +55,12 @@ const DEFAULT_OFLAGS: OFlags = OFlags {
seek_bytes: false,
};
struct LazyReader<R: Read>
{
struct LazyReader<R: Read> {
src: R,
}
impl<R: Read> Read for LazyReader<R>
{
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize>
{
impl<R: Read> Read for LazyReader<R> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let reduced = cmp::max(buf.len() / 2, 1);
self.src.read(&mut buf[..reduced])
}
@ -143,4 +140,3 @@ macro_rules! make_spec_test (
}
};
);

View file

@ -115,7 +115,7 @@ make_io_test!(
non_ascii: false,
ibs: 531,
xfer_stats: None,
count: Some(CountType::Bytes(32*1024)),
count: Some(CountType::Bytes(32 * 1024)),
cflags: icf!(),
iflags: DEFAULT_IFLAGS,
},
@ -199,7 +199,7 @@ make_io_test!(
non_ascii: false,
ibs: 521,
xfer_stats: None,
count: Some(CountType::Bytes(32*1024)),
count: Some(CountType::Bytes(32 * 1024)),
cflags: icf!(),
iflags: DEFAULT_IFLAGS,
},
@ -217,7 +217,8 @@ make_io_test!(
"random-73k-test-lazy-fullblock",
Input {
src: LazyReader {
src: File::open("./test-resources/random-5828891cb1230748e146f34223bbd3b5.test").unwrap()
src: File::open("./test-resources/random-5828891cb1230748e146f34223bbd3b5.test")
.unwrap()
},
non_ascii: false,
ibs: 521,
@ -254,53 +255,48 @@ make_io_test!(
// Test internal buffer size fn
#[test]
fn bsize_test_primes()
{
let (n,m) = (7901, 7919);
fn bsize_test_primes() {
let (n, m) = (7901, 7919);
let res = calc_bsize(n, m);
assert!(res % n == 0);
assert!(res % m == 0);
assert_eq!(res, n*m);
assert_eq!(res, n * m);
}
#[test]
fn bsize_test_rel_prime_obs_greater()
{
let (n,m) = (7*5119, 13*5119);
fn bsize_test_rel_prime_obs_greater() {
let (n, m) = (7 * 5119, 13 * 5119);
let res = calc_bsize(n, m);
assert!(res % n == 0);
assert!(res % m == 0);
assert_eq!(res, 7*13*5119);
assert_eq!(res, 7 * 13 * 5119);
}
#[test]
fn bsize_test_rel_prime_ibs_greater()
{
let (n,m) = (13*5119, 7*5119);
fn bsize_test_rel_prime_ibs_greater() {
let (n, m) = (13 * 5119, 7 * 5119);
let res = calc_bsize(n, m);
assert!(res % n == 0);
assert!(res % m == 0);
assert_eq!(res, 7*13*5119);
assert_eq!(res, 7 * 13 * 5119);
}
#[test]
fn bsize_test_3fac_rel_prime()
{
let (n,m) = (11*13*5119, 7*11*5119);
fn bsize_test_3fac_rel_prime() {
let (n, m) = (11 * 13 * 5119, 7 * 11 * 5119);
let res = calc_bsize(n, m);
assert!(res % n == 0);
assert!(res % m == 0);
assert_eq!(res, 7*11*13*5119);
assert_eq!(res, 7 * 11 * 13 * 5119);
}
#[test]
fn bsize_test_ibs_greater()
{
let (n,m) = (512*1024, 256*1024);
fn bsize_test_ibs_greater() {
let (n, m) = (512 * 1024, 256 * 1024);
let res = calc_bsize(n, m);
assert!(res % n == 0);
assert!(res % m == 0);
@ -309,9 +305,8 @@ fn bsize_test_ibs_greater()
}
#[test]
fn bsize_test_obs_greater()
{
let (n,m) = (256*1024, 512*1024);
fn bsize_test_obs_greater() {
let (n, m) = (256 * 1024, 512 * 1024);
let res = calc_bsize(n, m);
assert!(res % n == 0);
assert!(res % m == 0);
@ -320,9 +315,8 @@ fn bsize_test_obs_greater()
}
#[test]
fn bsize_test_bs_eq()
{
let (n,m) = (1024, 1024);
fn bsize_test_bs_eq() {
let (n, m) = (1024, 1024);
let res = calc_bsize(n, m);
assert!(res % n == 0);
assert!(res % m == 0);

File diff suppressed because it is too large Load diff

View file

@ -1,19 +1,23 @@
use super::*;
use crate::{
build_dd_app,
StatusLevel,
};
use crate::{build_dd_app, StatusLevel};
#[cfg(not(unix))]
#[test]
fn unimplemented_flags_should_error_non_unix()
{
fn unimplemented_flags_should_error_non_unix() {
let mut unfailed = Vec::new();
// The following flags are only implemented in unix
for flag in vec!["direct", "directory", "dsync", "sync", "nonblock", "noatime", "noctty", "nofollow"]
{
for flag in vec![
"direct",
"directory",
"dsync",
"sync",
"nonblock",
"noatime",
"noctty",
"nofollow",
] {
let args = vec![
String::from("dd"),
format!("--iflag={}", flag),
@ -21,36 +25,30 @@ fn unimplemented_flags_should_error_non_unix()
];
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
match parse_iflags(&matches)
{
Ok(_) =>
unfailed.push(format!("iflag={}", flag)),
Err(_) =>
{/* expected behaviour :-) */},
match parse_iflags(&matches) {
Ok(_) => unfailed.push(format!("iflag={}", flag)),
Err(_) => { /* expected behaviour :-) */ }
}
match parse_oflags(&matches)
{
Ok(_) =>
unfailed.push(format!("oflag={}", flag)),
Err(_) =>
{/* expected behaviour :-) */},
match parse_oflags(&matches) {
Ok(_) => unfailed.push(format!("oflag={}", flag)),
Err(_) => { /* expected behaviour :-) */ }
}
}
if !unfailed.is_empty()
{
panic!("The following flags did not panic as expected: {:?}", unfailed);
if !unfailed.is_empty() {
panic!(
"The following flags did not panic as expected: {:?}",
unfailed
);
}
}
#[test]
fn unimplemented_flags_should_error()
{
fn unimplemented_flags_should_error() {
let mut unfailed = Vec::new();
// The following flags are not implemented
for flag in vec!["cio", "nocache", "nolinks", "text", "binary"]
{
for flag in vec!["cio", "nocache", "nolinks", "text", "binary"] {
let args = vec![
String::from("dd"),
format!("--iflag={}", flag),
@ -58,31 +56,26 @@ fn unimplemented_flags_should_error()
];
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
match parse_iflags(&matches)
{
Ok(_) =>
unfailed.push(format!("iflag={}", flag)),
Err(_) =>
{/* expected behaviour :-) */},
match parse_iflags(&matches) {
Ok(_) => unfailed.push(format!("iflag={}", flag)),
Err(_) => { /* expected behaviour :-) */ }
}
match parse_oflags(&matches)
{
Ok(_) =>
unfailed.push(format!("oflag={}", flag)),
Err(_) =>
{/* expected behaviour :-) */},
match parse_oflags(&matches) {
Ok(_) => unfailed.push(format!("oflag={}", flag)),
Err(_) => { /* expected behaviour :-) */ }
}
}
if !unfailed.is_empty()
{
panic!("The following flags did not panic as expected: {:?}", unfailed);
if !unfailed.is_empty() {
panic!(
"The following flags did not panic as expected: {:?}",
unfailed
);
}
}
#[test]
fn test_status_level_absent()
{
fn test_status_level_absent() {
let args = vec![
String::from("dd"),
String::from("--if=foo.file"),
@ -96,8 +89,7 @@ fn test_status_level_absent()
}
#[test]
fn test_status_level_none()
{
fn test_status_level_none() {
let args = vec![
String::from("dd"),
String::from("--status=none"),
@ -112,8 +104,7 @@ fn test_status_level_none()
}
#[test]
fn test_status_level_progress()
{
fn test_status_level_progress() {
let args = vec![
String::from("dd"),
String::from("--if=foo.file"),
@ -128,8 +119,7 @@ fn test_status_level_progress()
}
#[test]
fn test_status_level_noxfer()
{
fn test_status_level_noxfer() {
let args = vec![
String::from("dd"),
String::from("--if=foo.file"),
@ -147,12 +137,8 @@ fn test_status_level_noxfer()
#[test]
#[should_panic]
fn icf_ctable_error()
{
let args = vec![
String::from("dd"),
String::from("--conv=ascii,ebcdic,ibm"),
];
fn icf_ctable_error() {
let args = vec![String::from("dd"), String::from("--conv=ascii,ebcdic,ibm")];
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
@ -161,12 +147,8 @@ fn icf_ctable_error()
#[test]
#[should_panic]
fn icf_case_error()
{
let args = vec![
String::from("dd"),
String::from("--conv=ucase,lcase"),
];
fn icf_case_error() {
let args = vec![String::from("dd"), String::from("--conv=ucase,lcase")];
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
@ -175,12 +157,8 @@ fn icf_case_error()
#[test]
#[should_panic]
fn icf_block_error()
{
let args = vec![
String::from("dd"),
String::from("--conv=block,unblock"),
];
fn icf_block_error() {
let args = vec![String::from("dd"), String::from("--conv=block,unblock")];
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
@ -189,12 +167,8 @@ fn icf_block_error()
#[test]
#[should_panic]
fn icf_creat_error()
{
let args = vec![
String::from("dd"),
String::from("--conv=excl,nocreat"),
];
fn icf_creat_error() {
let args = vec![String::from("dd"), String::from("--conv=excl,nocreat")];
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
@ -202,35 +176,23 @@ fn icf_creat_error()
}
#[test]
fn parse_icf_token_ibm()
{
let exp = vec![
ConvFlag::FmtAtoI,
];
fn parse_icf_token_ibm() {
let exp = vec![ConvFlag::FmtAtoI];
let args = vec![
String::from("dd"),
String::from("--conv=ibm"),
];
let args = vec![String::from("dd"), String::from("--conv=ibm")];
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
let act = parse_flag_list::<ConvFlag>("conv", &matches).unwrap();
assert_eq!(exp.len(), act.len());
for cf in &exp
{
for cf in &exp {
assert!(exp.contains(&cf));
}
}
#[test]
fn parse_icf_tokens_elu()
{
let exp = vec![
ConvFlag::FmtEtoA,
ConvFlag::LCase,
ConvFlag::Unblock,
];
fn parse_icf_tokens_elu() {
let exp = vec![ConvFlag::FmtEtoA, ConvFlag::LCase, ConvFlag::Unblock];
let args = vec![
String::from("dd"),
@ -240,15 +202,13 @@ fn parse_icf_tokens_elu()
let act = parse_flag_list::<ConvFlag>("conv", &matches).unwrap();
assert_eq!(exp.len(), act.len());
for cf in &exp
{
for cf in &exp {
assert!(exp.contains(&cf));
}
}
#[test]
fn parse_icf_tokens_remaining()
{
fn parse_icf_tokens_remaining() {
let exp = vec![
ConvFlag::FmtAtoE,
ConvFlag::UCase,
@ -274,8 +234,7 @@ fn parse_icf_tokens_remaining()
let act = parse_flag_list::<ConvFlag>("conv", &matches).unwrap();
assert_eq!(exp.len(), act.len());
for cf in &exp
{
for cf in &exp {
assert!(exp.contains(&cf));
}
}
@ -294,130 +253,53 @@ macro_rules! test_byte_parser (
}
);
test_byte_parser!(
test_bytes_n,
"765",
765
);
test_byte_parser!(
test_bytes_c,
"13c",
13
);
test_byte_parser!(test_bytes_n, "765", 765);
test_byte_parser!(test_bytes_c, "13c", 13);
test_byte_parser!(
test_bytes_w,
"1w",
2
);
test_byte_parser!(test_bytes_w, "1w", 2);
test_byte_parser!(
test_bytes_b,
"1b",
512
);
test_byte_parser!(test_bytes_b, "1b", 512);
test_byte_parser!(
test_bytes_k,
"1kB",
1000
);
test_byte_parser!(
test_bytes_K,
"1K",
1024
);
test_byte_parser!(
test_bytes_Ki,
"1KiB",
1024
);
test_byte_parser!(test_bytes_k, "1kB", 1000);
test_byte_parser!(test_bytes_K, "1K", 1024);
test_byte_parser!(test_bytes_Ki, "1KiB", 1024);
test_byte_parser!(
test_bytes_MB,
"2MB",
2*1000*1000
);
test_byte_parser!(
test_bytes_M,
"2M",
2*1024*1024
);
test_byte_parser!(
test_bytes_Mi,
"2MiB",
2*1024*1024
);
test_byte_parser!(test_bytes_MB, "2MB", 2 * 1000 * 1000);
test_byte_parser!(test_bytes_M, "2M", 2 * 1024 * 1024);
test_byte_parser!(test_bytes_Mi, "2MiB", 2 * 1024 * 1024);
test_byte_parser!(
test_bytes_GB,
"3GB",
3*1000*1000*1000
);
test_byte_parser!(
test_bytes_G,
"3G",
3*1024*1024*1024
);
test_byte_parser!(
test_bytes_Gi,
"3GiB",
3*1024*1024*1024
);
test_byte_parser!(test_bytes_GB, "3GB", 3 * 1000 * 1000 * 1000);
test_byte_parser!(test_bytes_G, "3G", 3 * 1024 * 1024 * 1024);
test_byte_parser!(test_bytes_Gi, "3GiB", 3 * 1024 * 1024 * 1024);
test_byte_parser!(
test_bytes_TB,
"4TB",
4*1000*1000*1000*1000
);
test_byte_parser!(
test_bytes_T,
"4T",
4*1024*1024*1024*1024
);
test_byte_parser!(
test_bytes_Ti,
"4TiB",
4*1024*1024*1024*1024
);
test_byte_parser!(test_bytes_TB, "4TB", 4 * 1000 * 1000 * 1000 * 1000);
test_byte_parser!(test_bytes_T, "4T", 4 * 1024 * 1024 * 1024 * 1024);
test_byte_parser!(test_bytes_Ti, "4TiB", 4 * 1024 * 1024 * 1024 * 1024);
test_byte_parser!(
test_bytes_PB,
"5PB",
5*1000*1000*1000*1000*1000
);
test_byte_parser!(
test_bytes_P,
"5P",
5*1024*1024*1024*1024*1024
);
test_byte_parser!(
test_bytes_Pi,
"5PiB",
5*1024*1024*1024*1024*1024
);
test_byte_parser!(test_bytes_PB, "5PB", 5 * 1000 * 1000 * 1000 * 1000 * 1000);
test_byte_parser!(test_bytes_P, "5P", 5 * 1024 * 1024 * 1024 * 1024 * 1024);
test_byte_parser!(test_bytes_Pi, "5PiB", 5 * 1024 * 1024 * 1024 * 1024 * 1024);
test_byte_parser!(
test_bytes_EB,
"6EB",
6*1000*1000*1000*1000*1000*1000
6 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000
);
test_byte_parser!(
test_bytes_E,
"6E",
6*1024*1024*1024*1024*1024*1024
6 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024
);
test_byte_parser!(
test_bytes_Ei,
"6EiB",
6*1024*1024*1024*1024*1024*1024
6 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024
);
#[test]
#[should_panic]
#[allow(non_snake_case)]
fn test_KB_multiplier_error()
{
fn test_KB_multiplier_error() {
// KB is not valid (kB, K, and KiB are)
let bs_str = "2000KB";
@ -426,8 +308,7 @@ fn test_KB_multiplier_error()
#[test]
#[should_panic]
fn test_overflow_panic()
{
fn test_overflow_panic() {
let bs_str = format!("{}KiB", usize::MAX);
parse_bytes_with_opt_multiplier(&bs_str).unwrap();
@ -435,8 +316,7 @@ fn test_overflow_panic()
#[test]
#[should_panic]
fn test_neg_panic()
{
fn test_neg_panic() {
let bs_str = format!("{}KiB", -1);
parse_bytes_with_opt_multiplier(&bs_str).unwrap();