first test

This commit is contained in:
Robin Müller 2023-11-26 23:52:34 +01:00
parent fdf6e1de90
commit c0805db137
Signed by: muellerr
GPG Key ID: A649FB78196E3849
4 changed files with 90 additions and 5 deletions

View File

@ -63,7 +63,7 @@ impl AckPdu {
.unwrap() .unwrap()
} }
pub fn new_for_finished_pdu( pub fn new_for_ack_pdu(
pdu_header: PduHeader, pdu_header: PduHeader,
condition_code: ConditionCode, condition_code: ConditionCode,
transaction_status: TransactionStatus, transaction_status: TransactionStatus,
@ -192,8 +192,42 @@ impl WritablePduPacket for AckPdu {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::cfdp::{
pdu::tests::{common_pdu_conf, TEST_DEST_ID, TEST_SEQ_NUM, TEST_SRC_ID},
LargeFileFlag, PduType, TransmissionMode,
};
use super::*;
#[test] #[test]
fn test_basic() { fn test_basic() {
todo!(); let pdu_conf = common_pdu_conf(CrcFlag::NoCrc, LargeFileFlag::Normal);
let pdu_header = PduHeader::new_no_file_data(pdu_conf, 0);
let ack_pdu = AckPdu::new(
pdu_header,
FileDirectiveType::FinishedPdu,
ConditionCode::NoError,
TransactionStatus::Active,
)
.expect("creating ACK PDU failed");
assert_eq!(
ack_pdu.directive_code_of_acked_pdu(),
FileDirectiveType::FinishedPdu
);
assert_eq!(ack_pdu.condition_code(), ConditionCode::NoError);
assert_eq!(ack_pdu.transaction_status(), TransactionStatus::Active);
assert_eq!(ack_pdu.crc_flag(), CrcFlag::NoCrc);
assert_eq!(ack_pdu.file_flag(), LargeFileFlag::Normal);
assert_eq!(ack_pdu.pdu_type(), PduType::FileDirective);
assert_eq!(
ack_pdu.file_directive_type(),
Some(FileDirectiveType::AckPdu)
);
assert_eq!(ack_pdu.transmission_mode(), TransmissionMode::Acknowledged);
assert_eq!(ack_pdu.direction(), Direction::TowardsReceiver);
assert_eq!(ack_pdu.source_id(), TEST_SRC_ID.into());
assert_eq!(ack_pdu.dest_id(), TEST_DEST_ID.into());
assert_eq!(ack_pdu.transaction_seq_num(), TEST_SEQ_NUM.into());
} }
} }

View File

@ -253,6 +253,21 @@ mod tests {
#[test] #[test]
fn test_with_crc() { fn test_with_crc() {
todo!(); let pdu_conf = common_pdu_conf(CrcFlag::WithCrc, LargeFileFlag::Normal);
let pdu_header = PduHeader::new_no_file_data(pdu_conf, 0);
let eof_pdu = EofPdu::new_no_error(pdu_header, 0x01020304, 12);
let mut buf: [u8; 64] = [0; 64];
let written = eof_pdu.write_to_bytes(&mut buf).unwrap();
assert_eq!(written, eof_pdu.len_written());
let eof_from_raw = EofPdu::from_bytes(&buf).expect("creating EOF PDU failed");
assert_eq!(eof_from_raw, eof_pdu);
buf[written - 1] -= 1;
let crc: u16 = ((buf[written - 2] as u16) << 8) as u16 | buf[written - 1] as u16;
let error = EofPdu::from_bytes(&buf).unwrap_err();
if let PduError::ChecksumError(e) = error {
assert_eq!(e, crc);
} else {
panic!("expected crc error");
}
} }
} }

View File

@ -331,7 +331,25 @@ mod tests {
#[test] #[test]
fn test_with_crc() { fn test_with_crc() {
todo!(); let mut common_conf =
CommonPduConfig::new_with_byte_fields(TEST_SRC_ID, TEST_DEST_ID, TEST_SEQ_NUM).unwrap();
common_conf.crc_flag = true.into();
let pdu_header = PduHeader::new_for_file_data_default(common_conf, 0);
let file_data: [u8; 4] = [1, 2, 3, 4];
let fd_pdu = FileDataPdu::new_no_seg_metadata(pdu_header, 10, &file_data);
let mut buf: [u8; 64] = [0; 64];
let written = fd_pdu.write_to_bytes(&mut buf).unwrap();
assert_eq!(written, fd_pdu.len_written());
let finished_pdu_from_raw = FileDataPdu::from_bytes(&buf).unwrap();
assert_eq!(finished_pdu_from_raw, fd_pdu);
buf[written - 1] -= 1;
let crc: u16 = ((buf[written - 2] as u16) << 8) | buf[written - 1] as u16;
let error = FileDataPdu::from_bytes(&buf).unwrap_err();
if let PduError::ChecksumError(e) = error {
assert_eq!(e, crc);
} else {
panic!("expected crc error");
}
} }
#[test] #[test]

View File

@ -395,6 +395,24 @@ mod tests {
#[test] #[test]
fn test_with_crc() { fn test_with_crc() {
todo!(); let finished_pdu = generic_finished_pdu(
CrcFlag::WithCrc,
LargeFileFlag::Normal,
DeliveryCode::Complete,
FileStatus::Retained,
);
let mut buf: [u8; 64] = [0; 64];
let written = finished_pdu.write_to_bytes(&mut buf).unwrap();
assert_eq!(written, finished_pdu.len_written());
let finished_pdu_from_raw = FinishedPdu::from_bytes(&buf).unwrap();
assert_eq!(finished_pdu_from_raw, finished_pdu);
buf[written - 1] -= 1;
let crc: u16 = ((buf[written - 2] as u16) << 8) as u16 | buf[written - 1] as u16;
let error = FinishedPdu::from_bytes(&buf).unwrap_err();
if let PduError::ChecksumError(e) = error {
assert_eq!(e, crc);
} else {
panic!("expected crc error");
}
} }
} }