mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
More minor cleanup.
- Runs rustfmt. - Speel check help-text
This commit is contained in:
parent
7f03ecf74b
commit
8e862b86dd
10 changed files with 1107 additions and 1622 deletions
|
@ -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,
|
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,
|
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,
|
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
pub const ASCII_TO_EBCDIC: ConversionTable = [
|
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,
|
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 = [
|
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,
|
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,
|
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,
|
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 = [
|
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,
|
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,
|
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,
|
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,
|
0xdc, 0xdd, 0xde, 0xdf, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,7 @@ use crate::conversion_tables::*;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::time;
|
use std::time;
|
||||||
|
|
||||||
pub struct ProgUpdate
|
pub struct ProgUpdate {
|
||||||
{
|
|
||||||
pub reads_complete: u64,
|
pub reads_complete: u64,
|
||||||
pub reads_partial: u64,
|
pub reads_partial: u64,
|
||||||
pub writes_complete: u64,
|
pub writes_complete: u64,
|
||||||
|
@ -14,16 +13,13 @@ pub struct ProgUpdate
|
||||||
pub duration: time::Duration,
|
pub duration: time::Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ReadStat
|
pub struct ReadStat {
|
||||||
{
|
|
||||||
pub reads_complete: u64,
|
pub reads_complete: u64,
|
||||||
pub reads_partial: u64,
|
pub reads_partial: u64,
|
||||||
pub records_truncated: u32,
|
pub records_truncated: u32,
|
||||||
}
|
}
|
||||||
impl std::ops::AddAssign for ReadStat
|
impl std::ops::AddAssign for ReadStat {
|
||||||
{
|
fn add_assign(&mut self, other: Self) {
|
||||||
fn add_assign(&mut self, other: Self)
|
|
||||||
{
|
|
||||||
*self = Self {
|
*self = Self {
|
||||||
reads_complete: self.reads_complete + other.reads_complete,
|
reads_complete: self.reads_complete + other.reads_complete,
|
||||||
reads_partial: self.reads_partial + other.reads_partial,
|
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_complete: u64,
|
||||||
pub writes_partial: u64,
|
pub writes_partial: u64,
|
||||||
pub bytes_total: u128,
|
pub bytes_total: u128,
|
||||||
}
|
}
|
||||||
impl std::ops::AddAssign for WriteStat
|
impl std::ops::AddAssign for WriteStat {
|
||||||
{
|
fn add_assign(&mut self, other: Self) {
|
||||||
fn add_assign(&mut self, other: Self)
|
|
||||||
{
|
|
||||||
*self = Self {
|
*self = Self {
|
||||||
writes_complete: self.writes_complete + other.writes_complete,
|
writes_complete: self.writes_complete + other.writes_complete,
|
||||||
writes_partial: self.writes_partial + other.writes_partial,
|
writes_partial: self.writes_partial + other.writes_partial,
|
||||||
|
@ -53,8 +46,7 @@ impl std::ops::AddAssign for WriteStat
|
||||||
type Cbs = usize;
|
type Cbs = usize;
|
||||||
|
|
||||||
/// Stores all Conv Flags that apply to the input
|
/// Stores all Conv Flags that apply to the input
|
||||||
pub struct IConvFlags
|
pub struct IConvFlags {
|
||||||
{
|
|
||||||
pub ctable: Option<&'static ConversionTable>,
|
pub ctable: Option<&'static ConversionTable>,
|
||||||
pub block: Option<Cbs>,
|
pub block: Option<Cbs>,
|
||||||
pub unblock: Option<Cbs>,
|
pub unblock: Option<Cbs>,
|
||||||
|
@ -65,8 +57,7 @@ pub struct IConvFlags
|
||||||
|
|
||||||
/// Stores all Conv Flags that apply to the output
|
/// Stores all Conv Flags that apply to the output
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct OConvFlags
|
pub struct OConvFlags {
|
||||||
{
|
|
||||||
pub sparse: bool,
|
pub sparse: bool,
|
||||||
pub excl: bool,
|
pub excl: bool,
|
||||||
pub nocreat: bool,
|
pub nocreat: bool,
|
||||||
|
@ -76,8 +67,7 @@ pub struct OConvFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores all Flags that apply to the input
|
/// Stores all Flags that apply to the input
|
||||||
pub struct IFlags
|
pub struct IFlags {
|
||||||
{
|
|
||||||
pub cio: bool,
|
pub cio: bool,
|
||||||
pub direct: bool,
|
pub direct: bool,
|
||||||
pub directory: bool,
|
pub directory: bool,
|
||||||
|
@ -97,8 +87,7 @@ pub struct IFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores all Flags that apply to the output
|
/// Stores all Flags that apply to the output
|
||||||
pub struct OFlags
|
pub struct OFlags {
|
||||||
{
|
|
||||||
pub append: bool,
|
pub append: bool,
|
||||||
pub cio: bool,
|
pub cio: bool,
|
||||||
pub direct: bool,
|
pub direct: bool,
|
||||||
|
@ -119,8 +108,7 @@ pub struct OFlags
|
||||||
/// The value of the status cl-option.
|
/// The value of the status cl-option.
|
||||||
/// Controls printing of transfer stats
|
/// Controls printing of transfer stats
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
pub enum StatusLevel
|
pub enum StatusLevel {
|
||||||
{
|
|
||||||
Progress,
|
Progress,
|
||||||
Noxfer,
|
Noxfer,
|
||||||
None,
|
None,
|
||||||
|
@ -130,38 +118,35 @@ pub enum StatusLevel
|
||||||
/// Defaults to Reads(N)
|
/// Defaults to Reads(N)
|
||||||
/// if iflag=count_bytes
|
/// if iflag=count_bytes
|
||||||
/// then becomes Bytes(N)
|
/// then becomes Bytes(N)
|
||||||
pub enum CountType
|
pub enum CountType {
|
||||||
{
|
|
||||||
Reads(usize),
|
Reads(usize),
|
||||||
Bytes(usize),
|
Bytes(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum InternalError
|
pub enum InternalError {
|
||||||
{
|
|
||||||
WrongInputType,
|
WrongInputType,
|
||||||
WrongOutputType,
|
WrongOutputType,
|
||||||
InvalidConvBlockUnblockCase,
|
InvalidConvBlockUnblockCase,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for InternalError
|
impl std::fmt::Display for InternalError {
|
||||||
{
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self
|
match self {
|
||||||
{
|
Self::WrongInputType | Self::WrongOutputType => {
|
||||||
Self::WrongInputType |
|
write!(f, "Internal dd error: Wrong Input/Output data type")
|
||||||
Self::WrongOutputType =>
|
}
|
||||||
write!(f, "Internal dd error: Wrong Input/Output data type"),
|
Self::InvalidConvBlockUnblockCase => write!(
|
||||||
Self::InvalidConvBlockUnblockCase =>
|
f,
|
||||||
write!(f, "Internal dd error: Invalid Conversion, Block, or Unblock data"),
|
"Internal dd error: Invalid Conversion, Block, or Unblock data"
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for InternalError {}
|
impl Error for InternalError {}
|
||||||
|
|
||||||
pub mod options
|
pub mod options {
|
||||||
{
|
|
||||||
pub const INFILE: &'static str = "if";
|
pub const INFILE: &'static str = "if";
|
||||||
pub const OUTFILE: &'static str = "of";
|
pub const OUTFILE: &'static str = "of";
|
||||||
pub const IBS: &'static str = "ibs";
|
pub const IBS: &'static str = "ibs";
|
||||||
|
|
1149
src/uu/dd/src/dd.rs
1149
src/uu/dd/src/dd.rs
File diff suppressed because it is too large
Load diff
|
@ -81,176 +81,176 @@ macro_rules! make_unblock_test (
|
||||||
);
|
);
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn block_test_no_nl()
|
fn block_test_no_nl() {
|
||||||
{
|
|
||||||
let mut rs = rs!();
|
let mut rs = rs!();
|
||||||
let buf = vec![0u8, 1u8, 2u8, 3u8];
|
let buf = vec![0u8, 1u8, 2u8, 3u8];
|
||||||
let res = block(buf, 4, &mut rs);
|
let res = block(buf, 4, &mut rs);
|
||||||
|
|
||||||
assert_eq!(res, vec![
|
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, 3u8],]);
|
||||||
vec![0u8, 1u8, 2u8, 3u8],
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn block_test_no_nl_short_record()
|
fn block_test_no_nl_short_record() {
|
||||||
{
|
|
||||||
let mut rs = rs!();
|
let mut rs = rs!();
|
||||||
let buf = vec![0u8, 1u8, 2u8, 3u8];
|
let buf = vec![0u8, 1u8, 2u8, 3u8];
|
||||||
let res = block(buf, 8, &mut rs);
|
let res = block(buf, 8, &mut rs);
|
||||||
|
|
||||||
assert_eq!(res, vec![
|
assert_eq!(
|
||||||
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
|
res,
|
||||||
]);
|
vec![vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn block_test_no_nl_trunc()
|
fn block_test_no_nl_trunc() {
|
||||||
{
|
|
||||||
let mut rs = rs!();
|
let mut rs = rs!();
|
||||||
let buf = vec![0u8, 1u8, 2u8, 3u8, 4u8];
|
let buf = vec![0u8, 1u8, 2u8, 3u8, 4u8];
|
||||||
let res = block(buf, 4, &mut rs);
|
let res = block(buf, 4, &mut rs);
|
||||||
|
|
||||||
assert_eq!(res, vec![
|
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, 3u8 /*, 4u8*/],]);
|
||||||
vec![0u8, 1u8, 2u8, 3u8/*, 4u8*/],
|
|
||||||
]);
|
|
||||||
assert_eq!(rs.records_truncated, 1);
|
assert_eq!(rs.records_truncated, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn block_test_nl_gt_cbs_trunc()
|
fn block_test_nl_gt_cbs_trunc() {
|
||||||
{
|
|
||||||
let mut rs = rs!();
|
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);
|
let res = block(buf, 4, &mut rs);
|
||||||
|
|
||||||
assert_eq!(res, vec![
|
assert_eq!(
|
||||||
vec![0u8, 1u8, 2u8, 3u8],
|
res,
|
||||||
// vec![4u8, SPACE, SPACE, SPACE],
|
vec![
|
||||||
vec![0u8, 1u8, 2u8, 3u8],
|
vec![0u8, 1u8, 2u8, 3u8],
|
||||||
// vec![4u8, SPACE, SPACE, SPACE],
|
// vec![4u8, SPACE, SPACE, SPACE],
|
||||||
vec![5u8, 6u8, 7u8, 8u8],
|
vec![0u8, 1u8, 2u8, 3u8],
|
||||||
]);
|
// vec![4u8, SPACE, SPACE, SPACE],
|
||||||
|
vec![5u8, 6u8, 7u8, 8u8],
|
||||||
|
]
|
||||||
|
);
|
||||||
assert_eq!(rs.records_truncated, 2);
|
assert_eq!(rs.records_truncated, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn block_test_surrounded_nl()
|
fn block_test_surrounded_nl() {
|
||||||
{
|
|
||||||
let mut rs = rs!();
|
let mut rs = rs!();
|
||||||
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, 4u8, 5u8, 6u8, 7u8, 8u8];
|
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, 4u8, 5u8, 6u8, 7u8, 8u8];
|
||||||
let res = block(buf, 8, &mut rs);
|
let res = block(buf, 8, &mut rs);
|
||||||
|
|
||||||
assert_eq!(res, vec![
|
assert_eq!(
|
||||||
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
|
res,
|
||||||
vec![4u8, 5u8, 6u8, 7u8, 8u8, SPACE, SPACE, SPACE],
|
vec![
|
||||||
]);
|
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
|
||||||
|
vec![4u8, 5u8, 6u8, 7u8, 8u8, SPACE, SPACE, SPACE],
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn block_test_multiple_nl_same_cbs_block()
|
fn block_test_multiple_nl_same_cbs_block() {
|
||||||
{
|
|
||||||
let mut rs = rs!();
|
let mut rs = rs!();
|
||||||
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, 4u8, NL, 5u8, 6u8, 7u8, 8u8, 9u8];
|
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, 4u8, NL, 5u8, 6u8, 7u8, 8u8, 9u8];
|
||||||
let res = block(buf, 8, &mut rs);
|
let res = block(buf, 8, &mut rs);
|
||||||
|
|
||||||
assert_eq!(res, vec![
|
assert_eq!(
|
||||||
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
|
res,
|
||||||
vec![4u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE],
|
vec![
|
||||||
vec![5u8, 6u8, 7u8, 8u8, 9u8, SPACE, SPACE, SPACE],
|
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]
|
#[test]
|
||||||
fn block_test_multiple_nl_diff_cbs_block()
|
fn block_test_multiple_nl_diff_cbs_block() {
|
||||||
{
|
|
||||||
let mut rs = rs!();
|
let mut rs = rs!();
|
||||||
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, 4u8, 5u8, 6u8, 7u8, NL, 8u8, 9u8];
|
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, 4u8, 5u8, 6u8, 7u8, NL, 8u8, 9u8];
|
||||||
let res = block(buf, 8, &mut rs);
|
let res = block(buf, 8, &mut rs);
|
||||||
|
|
||||||
assert_eq!(res, vec![
|
assert_eq!(
|
||||||
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
|
res,
|
||||||
vec![4u8, 5u8, 6u8, 7u8, SPACE, SPACE, SPACE, SPACE],
|
vec![
|
||||||
vec![8u8, 9u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE],
|
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]
|
#[test]
|
||||||
fn block_test_end_nl_diff_cbs_block()
|
fn block_test_end_nl_diff_cbs_block() {
|
||||||
{
|
|
||||||
let mut rs = rs!();
|
let mut rs = rs!();
|
||||||
let buf = vec![0u8, 1u8, 2u8, 3u8, NL];
|
let buf = vec![0u8, 1u8, 2u8, 3u8, NL];
|
||||||
let res = block(buf, 4, &mut rs);
|
let res = block(buf, 4, &mut rs);
|
||||||
|
|
||||||
assert_eq!(res, vec![
|
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, 3u8],]);
|
||||||
vec![0u8, 1u8, 2u8, 3u8],
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn block_test_end_nl_same_cbs_block()
|
fn block_test_end_nl_same_cbs_block() {
|
||||||
{
|
|
||||||
let mut rs = rs!();
|
let mut rs = rs!();
|
||||||
let buf = vec![0u8, 1u8, 2u8, NL];
|
let buf = vec![0u8, 1u8, 2u8, NL];
|
||||||
let res = block(buf, 4, &mut rs);
|
let res = block(buf, 4, &mut rs);
|
||||||
|
|
||||||
assert_eq!(res, vec![
|
assert_eq!(res, vec![vec![0u8, 1u8, 2u8, SPACE]]);
|
||||||
vec![0u8, 1u8, 2u8, SPACE]
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn block_test_double_end_nl()
|
fn block_test_double_end_nl() {
|
||||||
{
|
|
||||||
let mut rs = rs!();
|
let mut rs = rs!();
|
||||||
let buf = vec![0u8, 1u8, 2u8, NL, NL];
|
let buf = vec![0u8, 1u8, 2u8, NL, NL];
|
||||||
let res = block(buf, 4, &mut rs);
|
let res = block(buf, 4, &mut rs);
|
||||||
|
|
||||||
assert_eq!(res, vec![
|
assert_eq!(
|
||||||
vec![0u8, 1u8, 2u8, SPACE],
|
res,
|
||||||
vec![SPACE, SPACE, SPACE, SPACE],
|
vec![vec![0u8, 1u8, 2u8, SPACE], vec![SPACE, SPACE, SPACE, SPACE],]
|
||||||
]);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn block_test_start_nl()
|
fn block_test_start_nl() {
|
||||||
{
|
|
||||||
let mut rs = rs!();
|
let mut rs = rs!();
|
||||||
let buf = vec![NL, 0u8, 1u8, 2u8, 3u8];
|
let buf = vec![NL, 0u8, 1u8, 2u8, 3u8];
|
||||||
let res = block(buf, 4, &mut rs);
|
let res = block(buf, 4, &mut rs);
|
||||||
|
|
||||||
assert_eq!(res, vec![
|
assert_eq!(
|
||||||
vec![SPACE, SPACE, SPACE, SPACE],
|
res,
|
||||||
vec![0u8, 1u8, 2u8, 3u8],
|
vec![vec![SPACE, SPACE, SPACE, SPACE], vec![0u8, 1u8, 2u8, 3u8],]
|
||||||
]);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn block_test_double_surrounded_nl_no_trunc()
|
fn block_test_double_surrounded_nl_no_trunc() {
|
||||||
{
|
|
||||||
let mut rs = rs!();
|
let mut rs = rs!();
|
||||||
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, NL, 4u8, 5u8, 6u8, 7u8];
|
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, NL, 4u8, 5u8, 6u8, 7u8];
|
||||||
let res = block(buf, 8, &mut rs);
|
let res = block(buf, 8, &mut rs);
|
||||||
|
|
||||||
assert_eq!(res, vec![
|
assert_eq!(
|
||||||
vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE],
|
res,
|
||||||
vec![SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE],
|
vec![
|
||||||
vec![4u8, 5u8, 6u8, 7u8, SPACE, SPACE, SPACE, SPACE],
|
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]
|
#[test]
|
||||||
fn block_test_double_surrounded_nl_double_trunc()
|
fn block_test_double_surrounded_nl_double_trunc() {
|
||||||
{
|
|
||||||
let mut rs = rs!();
|
let mut rs = rs!();
|
||||||
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, NL, 4u8, 5u8, 6u8, 7u8, 8u8];
|
let buf = vec![0u8, 1u8, 2u8, 3u8, NL, NL, 4u8, 5u8, 6u8, 7u8, 8u8];
|
||||||
let res = block(buf, 4, &mut rs);
|
let res = block(buf, 4, &mut rs);
|
||||||
|
|
||||||
assert_eq!(res, vec![
|
assert_eq!(
|
||||||
vec![0u8, 1u8, 2u8, 3u8],
|
res,
|
||||||
vec![SPACE, SPACE, SPACE, SPACE],
|
vec![
|
||||||
vec![4u8, 5u8, 6u8, 7u8/*, 8u8*/],
|
vec![0u8, 1u8, 2u8, 3u8],
|
||||||
]);
|
vec![SPACE, SPACE, SPACE, SPACE],
|
||||||
|
vec![4u8, 5u8, 6u8, 7u8 /*, 8u8*/],
|
||||||
|
]
|
||||||
|
);
|
||||||
assert_eq!(rs.records_truncated, 1);
|
assert_eq!(rs.records_truncated, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,58 +279,51 @@ make_block_test!(
|
||||||
);
|
);
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unblock_test_full_cbs()
|
fn unblock_test_full_cbs() {
|
||||||
{
|
|
||||||
let buf = vec![0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8];
|
let buf = vec![0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8];
|
||||||
let res = unblock(buf, 8);
|
let res = unblock(buf, 8);
|
||||||
|
|
||||||
assert_eq!(res,
|
assert_eq!(res, vec![0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, NL],);
|
||||||
vec![0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, NL],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unblock_test_all_space()
|
fn unblock_test_all_space() {
|
||||||
{
|
|
||||||
let buf = vec![SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE];
|
let buf = vec![SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE];
|
||||||
let res = unblock(buf, 8);
|
let res = unblock(buf, 8);
|
||||||
|
|
||||||
assert_eq!(res,
|
assert_eq!(res, vec![NL],);
|
||||||
vec![NL],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unblock_test_decoy_spaces()
|
fn unblock_test_decoy_spaces() {
|
||||||
{
|
|
||||||
let buf = vec![0u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, 7u8];
|
let buf = vec![0u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, 7u8];
|
||||||
let res = unblock(buf, 8);
|
let res = unblock(buf, 8);
|
||||||
|
|
||||||
assert_eq!(res,
|
assert_eq!(
|
||||||
vec![0u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, 7u8, NL],
|
res,
|
||||||
|
vec![0u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, 7u8, NL],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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 buf = vec![0u8, 1u8, 2u8, 3u8, SPACE, SPACE, SPACE, SPACE];
|
||||||
let res = unblock(buf, 8);
|
let res = unblock(buf, 8);
|
||||||
|
|
||||||
assert_eq!(res,
|
assert_eq!(res, vec![0u8, 1u8, 2u8, 3u8, NL],);
|
||||||
vec![0u8, 1u8, 2u8, 3u8, NL],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unblock_test_strip_multi_cbs()
|
fn unblock_test_strip_multi_cbs() {
|
||||||
{
|
|
||||||
let buf = vec![
|
let buf = vec![
|
||||||
vec![0u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE],
|
vec![0u8, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE],
|
||||||
vec![0u8, 1u8, 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, SPACE, SPACE, SPACE, SPACE, SPACE],
|
||||||
vec![0u8, 1u8, 2u8, 3u8, 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);
|
let res = unblock(buf, 8);
|
||||||
|
|
||||||
|
@ -339,7 +332,10 @@ fn unblock_test_strip_multi_cbs()
|
||||||
vec![0u8, 1u8, NL],
|
vec![0u8, 1u8, NL],
|
||||||
vec![0u8, 1u8, 2u8, NL],
|
vec![0u8, 1u8, 2u8, NL],
|
||||||
vec![0u8, 1u8, 2u8, 3u8, NL],
|
vec![0u8, 1u8, 2u8, 3u8, NL],
|
||||||
].into_iter().flatten().collect::<Vec<_>>();
|
]
|
||||||
|
.into_iter()
|
||||||
|
.flatten()
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
assert_eq!(res, exp);
|
assert_eq!(res, exp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,9 @@ make_sync_test!(
|
||||||
make_sync_test!(
|
make_sync_test!(
|
||||||
deadbeef_16_delayed,
|
deadbeef_16_delayed,
|
||||||
"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),
|
Some(0u8),
|
||||||
16,
|
16,
|
||||||
32,
|
32,
|
||||||
|
|
|
@ -129,14 +129,16 @@ make_conv_test!(
|
||||||
);
|
);
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test()
|
fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test() {
|
||||||
{
|
|
||||||
// ASCII->EBCDIC
|
// ASCII->EBCDIC
|
||||||
let test_name = "all-valid-ascii-to-ebcdic";
|
let test_name = "all-valid-ascii-to-ebcdic";
|
||||||
let tmp_fname_ae = format!("./test-resources/FAILED-{}.test", test_name);
|
let tmp_fname_ae = format!("./test-resources/FAILED-{}.test", test_name);
|
||||||
|
|
||||||
let i = Input {
|
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,
|
non_ascii: false,
|
||||||
ibs: 128,
|
ibs: 128,
|
||||||
xfer_stats: None,
|
xfer_stats: None,
|
||||||
|
@ -152,7 +154,7 @@ fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test()
|
||||||
oflags: DEFAULT_OFLAGS,
|
oflags: DEFAULT_OFLAGS,
|
||||||
};
|
};
|
||||||
|
|
||||||
dd_fileout(i,o).unwrap();
|
dd_fileout(i, o).unwrap();
|
||||||
|
|
||||||
// EBCDIC->ASCII
|
// EBCDIC->ASCII
|
||||||
let test_name = "all-valid-ebcdic-to-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,
|
oflags: DEFAULT_OFLAGS,
|
||||||
};
|
};
|
||||||
|
|
||||||
dd_fileout(i,o).unwrap();
|
dd_fileout(i, o).unwrap();
|
||||||
|
|
||||||
// Final Comparison
|
// Final Comparison
|
||||||
let res = File::open(&tmp_fname_ea).unwrap();
|
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 res = BufReader::new(res);
|
||||||
let spec = BufReader::new(spec);
|
let spec = BufReader::new(spec);
|
||||||
|
@ -189,10 +196,8 @@ fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test()
|
||||||
let res = BufReader::new(res);
|
let res = BufReader::new(res);
|
||||||
|
|
||||||
// Check all bytes match
|
// Check all bytes match
|
||||||
for (b_res, b_spec) in res.bytes().zip(spec.bytes())
|
for (b_res, b_spec) in res.bytes().zip(spec.bytes()) {
|
||||||
{
|
assert_eq!(b_res.unwrap(), b_spec.unwrap());
|
||||||
assert_eq!(b_res.unwrap(),
|
|
||||||
b_spec.unwrap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::remove_file(&tmp_fname_ae).unwrap();
|
fs::remove_file(&tmp_fname_ae).unwrap();
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
mod sanity_tests;
|
|
||||||
mod conversion_tests;
|
|
||||||
mod block_unblock_tests;
|
mod block_unblock_tests;
|
||||||
mod conv_sync_tests;
|
mod conv_sync_tests;
|
||||||
|
mod conversion_tests;
|
||||||
|
mod sanity_tests;
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
const DEFAULT_CFO: OConvFlags = OConvFlags {
|
const DEFAULT_CFO: OConvFlags = OConvFlags {
|
||||||
sparse: false,
|
sparse: false,
|
||||||
|
@ -55,15 +55,12 @@ const DEFAULT_OFLAGS: OFlags = OFlags {
|
||||||
seek_bytes: false,
|
seek_bytes: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LazyReader<R: Read>
|
struct LazyReader<R: Read> {
|
||||||
{
|
|
||||||
src: R,
|
src: R,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: Read> Read for LazyReader<R>
|
impl<R: Read> Read for LazyReader<R> {
|
||||||
{
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize>
|
|
||||||
{
|
|
||||||
let reduced = cmp::max(buf.len() / 2, 1);
|
let reduced = cmp::max(buf.len() / 2, 1);
|
||||||
self.src.read(&mut buf[..reduced])
|
self.src.read(&mut buf[..reduced])
|
||||||
}
|
}
|
||||||
|
@ -143,4 +140,3 @@ macro_rules! make_spec_test (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ make_io_test!(
|
||||||
non_ascii: false,
|
non_ascii: false,
|
||||||
ibs: 531,
|
ibs: 531,
|
||||||
xfer_stats: None,
|
xfer_stats: None,
|
||||||
count: Some(CountType::Bytes(32*1024)),
|
count: Some(CountType::Bytes(32 * 1024)),
|
||||||
cflags: icf!(),
|
cflags: icf!(),
|
||||||
iflags: DEFAULT_IFLAGS,
|
iflags: DEFAULT_IFLAGS,
|
||||||
},
|
},
|
||||||
|
@ -199,7 +199,7 @@ make_io_test!(
|
||||||
non_ascii: false,
|
non_ascii: false,
|
||||||
ibs: 521,
|
ibs: 521,
|
||||||
xfer_stats: None,
|
xfer_stats: None,
|
||||||
count: Some(CountType::Bytes(32*1024)),
|
count: Some(CountType::Bytes(32 * 1024)),
|
||||||
cflags: icf!(),
|
cflags: icf!(),
|
||||||
iflags: DEFAULT_IFLAGS,
|
iflags: DEFAULT_IFLAGS,
|
||||||
},
|
},
|
||||||
|
@ -217,7 +217,8 @@ make_io_test!(
|
||||||
"random-73k-test-lazy-fullblock",
|
"random-73k-test-lazy-fullblock",
|
||||||
Input {
|
Input {
|
||||||
src: LazyReader {
|
src: LazyReader {
|
||||||
src: File::open("./test-resources/random-5828891cb1230748e146f34223bbd3b5.test").unwrap()
|
src: File::open("./test-resources/random-5828891cb1230748e146f34223bbd3b5.test")
|
||||||
|
.unwrap()
|
||||||
},
|
},
|
||||||
non_ascii: false,
|
non_ascii: false,
|
||||||
ibs: 521,
|
ibs: 521,
|
||||||
|
@ -254,53 +255,48 @@ make_io_test!(
|
||||||
|
|
||||||
// Test internal buffer size fn
|
// Test internal buffer size fn
|
||||||
#[test]
|
#[test]
|
||||||
fn bsize_test_primes()
|
fn bsize_test_primes() {
|
||||||
{
|
let (n, m) = (7901, 7919);
|
||||||
let (n,m) = (7901, 7919);
|
|
||||||
let res = calc_bsize(n, m);
|
let res = calc_bsize(n, m);
|
||||||
assert!(res % n == 0);
|
assert!(res % n == 0);
|
||||||
assert!(res % m == 0);
|
assert!(res % m == 0);
|
||||||
|
|
||||||
assert_eq!(res, n*m);
|
assert_eq!(res, n * m);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bsize_test_rel_prime_obs_greater()
|
fn bsize_test_rel_prime_obs_greater() {
|
||||||
{
|
let (n, m) = (7 * 5119, 13 * 5119);
|
||||||
let (n,m) = (7*5119, 13*5119);
|
|
||||||
let res = calc_bsize(n, m);
|
let res = calc_bsize(n, m);
|
||||||
assert!(res % n == 0);
|
assert!(res % n == 0);
|
||||||
assert!(res % m == 0);
|
assert!(res % m == 0);
|
||||||
|
|
||||||
assert_eq!(res, 7*13*5119);
|
assert_eq!(res, 7 * 13 * 5119);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bsize_test_rel_prime_ibs_greater()
|
fn bsize_test_rel_prime_ibs_greater() {
|
||||||
{
|
let (n, m) = (13 * 5119, 7 * 5119);
|
||||||
let (n,m) = (13*5119, 7*5119);
|
|
||||||
let res = calc_bsize(n, m);
|
let res = calc_bsize(n, m);
|
||||||
assert!(res % n == 0);
|
assert!(res % n == 0);
|
||||||
assert!(res % m == 0);
|
assert!(res % m == 0);
|
||||||
|
|
||||||
assert_eq!(res, 7*13*5119);
|
assert_eq!(res, 7 * 13 * 5119);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bsize_test_3fac_rel_prime()
|
fn bsize_test_3fac_rel_prime() {
|
||||||
{
|
let (n, m) = (11 * 13 * 5119, 7 * 11 * 5119);
|
||||||
let (n,m) = (11*13*5119, 7*11*5119);
|
|
||||||
let res = calc_bsize(n, m);
|
let res = calc_bsize(n, m);
|
||||||
assert!(res % n == 0);
|
assert!(res % n == 0);
|
||||||
assert!(res % m == 0);
|
assert!(res % m == 0);
|
||||||
|
|
||||||
assert_eq!(res, 7*11*13*5119);
|
assert_eq!(res, 7 * 11 * 13 * 5119);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bsize_test_ibs_greater()
|
fn bsize_test_ibs_greater() {
|
||||||
{
|
let (n, m) = (512 * 1024, 256 * 1024);
|
||||||
let (n,m) = (512*1024, 256*1024);
|
|
||||||
let res = calc_bsize(n, m);
|
let res = calc_bsize(n, m);
|
||||||
assert!(res % n == 0);
|
assert!(res % n == 0);
|
||||||
assert!(res % m == 0);
|
assert!(res % m == 0);
|
||||||
|
@ -309,9 +305,8 @@ fn bsize_test_ibs_greater()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bsize_test_obs_greater()
|
fn bsize_test_obs_greater() {
|
||||||
{
|
let (n, m) = (256 * 1024, 512 * 1024);
|
||||||
let (n,m) = (256*1024, 512*1024);
|
|
||||||
let res = calc_bsize(n, m);
|
let res = calc_bsize(n, m);
|
||||||
assert!(res % n == 0);
|
assert!(res % n == 0);
|
||||||
assert!(res % m == 0);
|
assert!(res % m == 0);
|
||||||
|
@ -320,9 +315,8 @@ fn bsize_test_obs_greater()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bsize_test_bs_eq()
|
fn bsize_test_bs_eq() {
|
||||||
{
|
let (n, m) = (1024, 1024);
|
||||||
let (n,m) = (1024, 1024);
|
|
||||||
let res = calc_bsize(n, m);
|
let res = calc_bsize(n, m);
|
||||||
assert!(res % n == 0);
|
assert!(res % n == 0);
|
||||||
assert!(res % m == 0);
|
assert!(res % m == 0);
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,19 +1,23 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{build_dd_app, StatusLevel};
|
||||||
build_dd_app,
|
|
||||||
StatusLevel,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
#[test]
|
#[test]
|
||||||
fn unimplemented_flags_should_error_non_unix()
|
fn unimplemented_flags_should_error_non_unix() {
|
||||||
{
|
|
||||||
let mut unfailed = Vec::new();
|
let mut unfailed = Vec::new();
|
||||||
|
|
||||||
// The following flags are only implemented in unix
|
// 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![
|
let args = vec![
|
||||||
String::from("dd"),
|
String::from("dd"),
|
||||||
format!("--iflag={}", flag),
|
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();
|
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
||||||
|
|
||||||
match parse_iflags(&matches)
|
match parse_iflags(&matches) {
|
||||||
{
|
Ok(_) => unfailed.push(format!("iflag={}", flag)),
|
||||||
Ok(_) =>
|
Err(_) => { /* expected behaviour :-) */ }
|
||||||
unfailed.push(format!("iflag={}", flag)),
|
|
||||||
Err(_) =>
|
|
||||||
{/* expected behaviour :-) */},
|
|
||||||
}
|
}
|
||||||
match parse_oflags(&matches)
|
match parse_oflags(&matches) {
|
||||||
{
|
Ok(_) => unfailed.push(format!("oflag={}", flag)),
|
||||||
Ok(_) =>
|
Err(_) => { /* expected behaviour :-) */ }
|
||||||
unfailed.push(format!("oflag={}", flag)),
|
|
||||||
Err(_) =>
|
|
||||||
{/* expected behaviour :-) */},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !unfailed.is_empty()
|
if !unfailed.is_empty() {
|
||||||
{
|
panic!(
|
||||||
panic!("The following flags did not panic as expected: {:?}", unfailed);
|
"The following flags did not panic as expected: {:?}",
|
||||||
|
unfailed
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unimplemented_flags_should_error()
|
fn unimplemented_flags_should_error() {
|
||||||
{
|
|
||||||
let mut unfailed = Vec::new();
|
let mut unfailed = Vec::new();
|
||||||
|
|
||||||
// The following flags are not implemented
|
// 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![
|
let args = vec![
|
||||||
String::from("dd"),
|
String::from("dd"),
|
||||||
format!("--iflag={}", flag),
|
format!("--iflag={}", flag),
|
||||||
|
@ -58,31 +56,26 @@ fn unimplemented_flags_should_error()
|
||||||
];
|
];
|
||||||
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
||||||
|
|
||||||
match parse_iflags(&matches)
|
match parse_iflags(&matches) {
|
||||||
{
|
Ok(_) => unfailed.push(format!("iflag={}", flag)),
|
||||||
Ok(_) =>
|
Err(_) => { /* expected behaviour :-) */ }
|
||||||
unfailed.push(format!("iflag={}", flag)),
|
|
||||||
Err(_) =>
|
|
||||||
{/* expected behaviour :-) */},
|
|
||||||
}
|
}
|
||||||
match parse_oflags(&matches)
|
match parse_oflags(&matches) {
|
||||||
{
|
Ok(_) => unfailed.push(format!("oflag={}", flag)),
|
||||||
Ok(_) =>
|
Err(_) => { /* expected behaviour :-) */ }
|
||||||
unfailed.push(format!("oflag={}", flag)),
|
|
||||||
Err(_) =>
|
|
||||||
{/* expected behaviour :-) */},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !unfailed.is_empty()
|
if !unfailed.is_empty() {
|
||||||
{
|
panic!(
|
||||||
panic!("The following flags did not panic as expected: {:?}", unfailed);
|
"The following flags did not panic as expected: {:?}",
|
||||||
|
unfailed
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_status_level_absent()
|
fn test_status_level_absent() {
|
||||||
{
|
|
||||||
let args = vec![
|
let args = vec![
|
||||||
String::from("dd"),
|
String::from("dd"),
|
||||||
String::from("--if=foo.file"),
|
String::from("--if=foo.file"),
|
||||||
|
@ -96,8 +89,7 @@ fn test_status_level_absent()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_status_level_none()
|
fn test_status_level_none() {
|
||||||
{
|
|
||||||
let args = vec![
|
let args = vec![
|
||||||
String::from("dd"),
|
String::from("dd"),
|
||||||
String::from("--status=none"),
|
String::from("--status=none"),
|
||||||
|
@ -112,8 +104,7 @@ fn test_status_level_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_status_level_progress()
|
fn test_status_level_progress() {
|
||||||
{
|
|
||||||
let args = vec![
|
let args = vec![
|
||||||
String::from("dd"),
|
String::from("dd"),
|
||||||
String::from("--if=foo.file"),
|
String::from("--if=foo.file"),
|
||||||
|
@ -128,8 +119,7 @@ fn test_status_level_progress()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_status_level_noxfer()
|
fn test_status_level_noxfer() {
|
||||||
{
|
|
||||||
let args = vec![
|
let args = vec![
|
||||||
String::from("dd"),
|
String::from("dd"),
|
||||||
String::from("--if=foo.file"),
|
String::from("--if=foo.file"),
|
||||||
|
@ -147,12 +137,8 @@ fn test_status_level_noxfer()
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn icf_ctable_error()
|
fn icf_ctable_error() {
|
||||||
{
|
let args = vec![String::from("dd"), String::from("--conv=ascii,ebcdic,ibm")];
|
||||||
let args = vec![
|
|
||||||
String::from("dd"),
|
|
||||||
String::from("--conv=ascii,ebcdic,ibm"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
||||||
|
|
||||||
|
@ -161,12 +147,8 @@ fn icf_ctable_error()
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn icf_case_error()
|
fn icf_case_error() {
|
||||||
{
|
let args = vec![String::from("dd"), String::from("--conv=ucase,lcase")];
|
||||||
let args = vec![
|
|
||||||
String::from("dd"),
|
|
||||||
String::from("--conv=ucase,lcase"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
||||||
|
|
||||||
|
@ -175,12 +157,8 @@ fn icf_case_error()
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn icf_block_error()
|
fn icf_block_error() {
|
||||||
{
|
let args = vec![String::from("dd"), String::from("--conv=block,unblock")];
|
||||||
let args = vec![
|
|
||||||
String::from("dd"),
|
|
||||||
String::from("--conv=block,unblock"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
||||||
|
|
||||||
|
@ -189,12 +167,8 @@ fn icf_block_error()
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn icf_creat_error()
|
fn icf_creat_error() {
|
||||||
{
|
let args = vec![String::from("dd"), String::from("--conv=excl,nocreat")];
|
||||||
let args = vec![
|
|
||||||
String::from("dd"),
|
|
||||||
String::from("--conv=excl,nocreat"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
||||||
|
|
||||||
|
@ -202,35 +176,23 @@ fn icf_creat_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_icf_token_ibm()
|
fn parse_icf_token_ibm() {
|
||||||
{
|
let exp = vec![ConvFlag::FmtAtoI];
|
||||||
let exp = vec![
|
|
||||||
ConvFlag::FmtAtoI,
|
|
||||||
];
|
|
||||||
|
|
||||||
let args = vec![
|
let args = vec![String::from("dd"), String::from("--conv=ibm")];
|
||||||
String::from("dd"),
|
|
||||||
String::from("--conv=ibm"),
|
|
||||||
];
|
|
||||||
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
||||||
|
|
||||||
let act = parse_flag_list::<ConvFlag>("conv", &matches).unwrap();
|
let act = parse_flag_list::<ConvFlag>("conv", &matches).unwrap();
|
||||||
|
|
||||||
assert_eq!(exp.len(), act.len());
|
assert_eq!(exp.len(), act.len());
|
||||||
for cf in &exp
|
for cf in &exp {
|
||||||
{
|
|
||||||
assert!(exp.contains(&cf));
|
assert!(exp.contains(&cf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_icf_tokens_elu()
|
fn parse_icf_tokens_elu() {
|
||||||
{
|
let exp = vec![ConvFlag::FmtEtoA, ConvFlag::LCase, ConvFlag::Unblock];
|
||||||
let exp = vec![
|
|
||||||
ConvFlag::FmtEtoA,
|
|
||||||
ConvFlag::LCase,
|
|
||||||
ConvFlag::Unblock,
|
|
||||||
];
|
|
||||||
|
|
||||||
let args = vec![
|
let args = vec![
|
||||||
String::from("dd"),
|
String::from("dd"),
|
||||||
|
@ -240,15 +202,13 @@ fn parse_icf_tokens_elu()
|
||||||
let act = parse_flag_list::<ConvFlag>("conv", &matches).unwrap();
|
let act = parse_flag_list::<ConvFlag>("conv", &matches).unwrap();
|
||||||
|
|
||||||
assert_eq!(exp.len(), act.len());
|
assert_eq!(exp.len(), act.len());
|
||||||
for cf in &exp
|
for cf in &exp {
|
||||||
{
|
|
||||||
assert!(exp.contains(&cf));
|
assert!(exp.contains(&cf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_icf_tokens_remaining()
|
fn parse_icf_tokens_remaining() {
|
||||||
{
|
|
||||||
let exp = vec![
|
let exp = vec![
|
||||||
ConvFlag::FmtAtoE,
|
ConvFlag::FmtAtoE,
|
||||||
ConvFlag::UCase,
|
ConvFlag::UCase,
|
||||||
|
@ -274,8 +234,7 @@ fn parse_icf_tokens_remaining()
|
||||||
let act = parse_flag_list::<ConvFlag>("conv", &matches).unwrap();
|
let act = parse_flag_list::<ConvFlag>("conv", &matches).unwrap();
|
||||||
|
|
||||||
assert_eq!(exp.len(), act.len());
|
assert_eq!(exp.len(), act.len());
|
||||||
for cf in &exp
|
for cf in &exp {
|
||||||
{
|
|
||||||
assert!(exp.contains(&cf));
|
assert!(exp.contains(&cf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -294,130 +253,53 @@ macro_rules! test_byte_parser (
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
test_byte_parser!(
|
test_byte_parser!(test_bytes_n, "765", 765);
|
||||||
test_bytes_n,
|
test_byte_parser!(test_bytes_c, "13c", 13);
|
||||||
"765",
|
|
||||||
765
|
|
||||||
);
|
|
||||||
test_byte_parser!(
|
|
||||||
test_bytes_c,
|
|
||||||
"13c",
|
|
||||||
13
|
|
||||||
);
|
|
||||||
|
|
||||||
test_byte_parser!(
|
test_byte_parser!(test_bytes_w, "1w", 2);
|
||||||
test_bytes_w,
|
|
||||||
"1w",
|
|
||||||
2
|
|
||||||
);
|
|
||||||
|
|
||||||
test_byte_parser!(
|
test_byte_parser!(test_bytes_b, "1b", 512);
|
||||||
test_bytes_b,
|
|
||||||
"1b",
|
|
||||||
512
|
|
||||||
);
|
|
||||||
|
|
||||||
test_byte_parser!(
|
test_byte_parser!(test_bytes_k, "1kB", 1000);
|
||||||
test_bytes_k,
|
test_byte_parser!(test_bytes_K, "1K", 1024);
|
||||||
"1kB",
|
test_byte_parser!(test_bytes_Ki, "1KiB", 1024);
|
||||||
1000
|
|
||||||
);
|
|
||||||
test_byte_parser!(
|
|
||||||
test_bytes_K,
|
|
||||||
"1K",
|
|
||||||
1024
|
|
||||||
);
|
|
||||||
test_byte_parser!(
|
|
||||||
test_bytes_Ki,
|
|
||||||
"1KiB",
|
|
||||||
1024
|
|
||||||
);
|
|
||||||
|
|
||||||
test_byte_parser!(
|
test_byte_parser!(test_bytes_MB, "2MB", 2 * 1000 * 1000);
|
||||||
test_bytes_MB,
|
test_byte_parser!(test_bytes_M, "2M", 2 * 1024 * 1024);
|
||||||
"2MB",
|
test_byte_parser!(test_bytes_Mi, "2MiB", 2 * 1024 * 1024);
|
||||||
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_byte_parser!(test_bytes_GB, "3GB", 3 * 1000 * 1000 * 1000);
|
||||||
test_bytes_GB,
|
test_byte_parser!(test_bytes_G, "3G", 3 * 1024 * 1024 * 1024);
|
||||||
"3GB",
|
test_byte_parser!(test_bytes_Gi, "3GiB", 3 * 1024 * 1024 * 1024);
|
||||||
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_byte_parser!(test_bytes_TB, "4TB", 4 * 1000 * 1000 * 1000 * 1000);
|
||||||
test_bytes_TB,
|
test_byte_parser!(test_bytes_T, "4T", 4 * 1024 * 1024 * 1024 * 1024);
|
||||||
"4TB",
|
test_byte_parser!(test_bytes_Ti, "4TiB", 4 * 1024 * 1024 * 1024 * 1024);
|
||||||
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_byte_parser!(test_bytes_PB, "5PB", 5 * 1000 * 1000 * 1000 * 1000 * 1000);
|
||||||
test_bytes_PB,
|
test_byte_parser!(test_bytes_P, "5P", 5 * 1024 * 1024 * 1024 * 1024 * 1024);
|
||||||
"5PB",
|
test_byte_parser!(test_bytes_Pi, "5PiB", 5 * 1024 * 1024 * 1024 * 1024 * 1024);
|
||||||
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_byte_parser!(
|
||||||
test_bytes_EB,
|
test_bytes_EB,
|
||||||
"6EB",
|
"6EB",
|
||||||
6*1000*1000*1000*1000*1000*1000
|
6 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000
|
||||||
);
|
);
|
||||||
test_byte_parser!(
|
test_byte_parser!(
|
||||||
test_bytes_E,
|
test_bytes_E,
|
||||||
"6E",
|
"6E",
|
||||||
6*1024*1024*1024*1024*1024*1024
|
6 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024
|
||||||
);
|
);
|
||||||
test_byte_parser!(
|
test_byte_parser!(
|
||||||
test_bytes_Ei,
|
test_bytes_Ei,
|
||||||
"6EiB",
|
"6EiB",
|
||||||
6*1024*1024*1024*1024*1024*1024
|
6 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024
|
||||||
);
|
);
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn test_KB_multiplier_error()
|
fn test_KB_multiplier_error() {
|
||||||
{
|
|
||||||
// KB is not valid (kB, K, and KiB are)
|
// KB is not valid (kB, K, and KiB are)
|
||||||
let bs_str = "2000KB";
|
let bs_str = "2000KB";
|
||||||
|
|
||||||
|
@ -426,8 +308,7 @@ fn test_KB_multiplier_error()
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_overflow_panic()
|
fn test_overflow_panic() {
|
||||||
{
|
|
||||||
let bs_str = format!("{}KiB", usize::MAX);
|
let bs_str = format!("{}KiB", usize::MAX);
|
||||||
|
|
||||||
parse_bytes_with_opt_multiplier(&bs_str).unwrap();
|
parse_bytes_with_opt_multiplier(&bs_str).unwrap();
|
||||||
|
@ -435,8 +316,7 @@ fn test_overflow_panic()
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_neg_panic()
|
fn test_neg_panic() {
|
||||||
{
|
|
||||||
let bs_str = format!("{}KiB", -1);
|
let bs_str = format!("{}KiB", -1);
|
||||||
|
|
||||||
parse_bytes_with_opt_multiplier(&bs_str).unwrap();
|
parse_bytes_with_opt_multiplier(&bs_str).unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue