Skip to content

Commit

Permalink
Tests for dlt ft buffer new & bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianSchmid committed Jun 25, 2024
1 parent ad743e6 commit 583fa99
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 55 deletions.
109 changes: 107 additions & 2 deletions src/ft/dlt_ft_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl DltFtBuffer {
self.file_size = header.file_size.into();
self.number_of_packets = header.number_of_packages.into();
self.buffer_size = header.buffer_size.into();
self.file_serial_number = header.file_serial_number;
self.file_name.clear();
self.file_name.push_str(header.file_name);
self.creation_date.clear();
Expand Down Expand Up @@ -272,8 +273,8 @@ impl DltFtBuffer {
#[cfg(all(feature = "std", test))]
mod test {

use crate::ft::*;
use alloc::format;
use crate::{ft::*, error::FtReassembleError};
use alloc::{borrow::ToOwned, vec::Vec, format};

#[test]
fn debug_clone_eq() {
Expand Down Expand Up @@ -304,6 +305,110 @@ mod test {
};
assert_eq!(h1, h2);
}

#[test]
fn new() {
// ok case
{
let buf = DltFtBuffer::new(&DltFtHeaderPkg {
file_serial_number: DltFtUInt::U32(1234),
file_name: "a.txt",
file_size: DltFtUInt::U32(20),
creation_date: "2024-06-25",
number_of_packages: DltFtUInt::U32(2),
buffer_size: DltFtUInt::U32(10),
});
assert_eq!(
DltFtBuffer {
data: Vec::new(),
sections: Vec::new(),
file_size: 20,
number_of_packets: 2,
buffer_size: 10,
file_serial_number: DltFtUInt::U32(1234),
file_name: "a.txt".to_owned(),
creation_date: "2024-06-25".to_owned(),
end_received: false,
},
buf.unwrap()
);
}
// error case
{
let buf = DltFtBuffer::new(&DltFtHeaderPkg {
file_serial_number: DltFtUInt::U32(1234),
file_name: "a.txt",
file_size: DltFtUInt::U32(20),
creation_date: "2024-06-25",
// bad number of packages
number_of_packages: DltFtUInt::U32(0),
buffer_size: DltFtUInt::U32(10),
});
assert_eq!(
FtReassembleError::InconsitantHeaderLenValues {
file_size: 20,
number_of_packages: 0,
buffer_size: 10,
},
buf.unwrap_err()
);
}
}

#[cfg(target_pointer_width = "32")]
#[test]
fn reinit_from_header_pkg() {

}

#[test]
fn reinit_from_header_pkg() {
let base = {
let mut base = DltFtBuffer::new(&DltFtHeaderPkg {
file_serial_number: DltFtUInt::U32(0),
file_name: "base.txt",
file_size: DltFtUInt::U32(4),
creation_date: "0-0-0",
number_of_packages: DltFtUInt::U32(1),
buffer_size: DltFtUInt::U32(4),
}).unwrap();
base.consume_data_pkg(&DltFtDataPkg{
file_serial_number: DltFtUInt::U32(0),
package_nr: DltFtUInt::U32(1),
data: &[1,2,3,4],
}).unwrap();
base.set_end_received();
base
};

// ok init
{
let mut buf = base.clone();
buf.reinit_from_header_pkg(&DltFtHeaderPkg {
file_serial_number: DltFtUInt::U32(1234),
file_name: "file.txt",
file_size: DltFtUInt::U32(10),
creation_date: "2024-06-25",
number_of_packages: DltFtUInt::U32(2),
buffer_size: DltFtUInt::U32(5),
}).unwrap();
assert_eq!(
DltFtBuffer {
data: Vec::new(),
sections: Vec::new(),
file_size: 10,
number_of_packets: 2,
buffer_size: 5,
file_serial_number: DltFtUInt::U32(1234),
file_name: "file.txt".to_owned(),
creation_date: "2024-06-25".to_owned(),
end_received: false,
},
buf
);
}
}

/*
struct TestPacket {
offset: u32,
Expand Down
26 changes: 0 additions & 26 deletions src/ft/dlt_ft_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,6 @@ impl From<i64> for DltFtInt {
}
}

#[cfg(target_pointer_width = "32")]
impl From<isize> for DltFtInt {
fn from(value: isize) -> Self {
DltFtInt::I32(value as i32)
}
}

#[cfg(target_pointer_width = "64")]
#[cfg_attr(docsrs, doc(cfg(target_pointer_width = "64")))]
impl From<isize> for DltFtInt {
fn from(value: isize) -> Self {
DltFtInt::I64(value as i64)
}
}

#[cfg(target_pointer_width = "64")]
#[cfg_attr(docsrs, doc(cfg(target_pointer_width = "64")))]
impl From<DltFtInt> for isize {
fn from(value: DltFtInt) -> Self {
match value {
DltFtInt::I32(v) => v as isize,
DltFtInt::I64(v) => v as isize,
}
}
}

impl From<DltFtInt> for i64 {
fn from(value: DltFtInt) -> Self {
match value {
Expand Down
27 changes: 0 additions & 27 deletions src/ft/dlt_ft_uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,6 @@ impl From<u64> for DltFtUInt {
}
}

#[cfg(target_pointer_width = "32")]
impl From<usize> for DltFtUInt {
fn from(value: usize) -> Self {
DltFtUInt::U32(value as u32)
}
}

#[cfg(target_pointer_width = "64")]
#[cfg_attr(docsrs, doc(cfg(target_pointer_width = "64")))]
impl From<usize> for DltFtUInt {
fn from(value: usize) -> Self {
DltFtUInt::U64(value as u64)
}
}

#[cfg(target_pointer_width = "64")]
#[cfg_attr(docsrs, doc(cfg(target_pointer_width = "64")))]
impl From<DltFtUInt> for usize {
fn from(value: DltFtUInt) -> Self {
match value {
DltFtUInt::U16(v) => usize::from(v),
DltFtUInt::U32(v) => v as usize,
DltFtUInt::U64(v) => v as usize,
}
}
}

impl From<DltFtUInt> for u64 {
fn from(value: DltFtUInt) -> Self {
match value {
Expand Down

0 comments on commit 583fa99

Please sign in to comment.