Fixed PartialEq Implementation for PusTm Struct, branched from fix of PusTc Implementation. #13
@ -14,8 +14,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
## Fixed
|
## Fixed
|
||||||
|
|
||||||
- Correct manual implementation of Trait `PartialEq` for `PusTc`. The previous auto-derivation was
|
- Correct implementation of Trait `PartialEq` for `PusTc` and `PusTm`. The previous auto-derivation
|
||||||
incorrect because it also compared fields unrelated to the raw byte representation.
|
were incorrect because they also compared fields unrelated to the raw byte representation.
|
||||||
|
|
||||||
# [v0.5.1] 2023-01-22
|
# [v0.5.1] 2023-01-22
|
||||||
|
|
||||||
|
@ -757,7 +757,7 @@ mod tests {
|
|||||||
fn partial_eq_serialized_vs_derialized() {
|
fn partial_eq_serialized_vs_derialized() {
|
||||||
let pus_tc = base_ping_tc_simple_ctor();
|
let pus_tc = base_ping_tc_simple_ctor();
|
||||||
let mut buf = [0; 32];
|
let mut buf = [0; 32];
|
||||||
let size = pus_tc.write_to_bytes(&mut buf).unwrap();
|
pus_tc.write_to_bytes(&mut buf).unwrap();
|
||||||
assert_eq!(pus_tc, PusTc::from_bytes(&buf).unwrap().0);
|
assert_eq!(pus_tc, PusTc::from_bytes(&buf).unwrap().0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
31
src/tm.rs
31
src/tm.rs
@ -202,7 +202,7 @@ impl<'slice> TryFrom<zc::PusTmSecHeader<'slice>> for PusTmSecondaryHeader<'slice
|
|||||||
///
|
///
|
||||||
/// * `'src_data` - Life time of a buffer where the user provided time stamp and source data will
|
/// * `'src_data` - Life time of a buffer where the user provided time stamp and source data will
|
||||||
/// be serialized into.
|
/// be serialized into.
|
||||||
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
|
#[derive(Eq, Debug, Copy, Clone)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct PusTm<'src_data> {
|
pub struct PusTm<'src_data> {
|
||||||
pub sp_header: SpHeader,
|
pub sp_header: SpHeader,
|
||||||
@ -443,6 +443,14 @@ impl<'src_data> PusTm<'src_data> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq for PusTm<'_> {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
self.sp_header == other.sp_header
|
||||||
|
&& self.sec_header == other.sec_header
|
||||||
|
&& self.source_data == other.source_data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//noinspection RsTraitImplementation
|
//noinspection RsTraitImplementation
|
||||||
impl CcsdsPacket for PusTm<'_> {
|
impl CcsdsPacket for PusTm<'_> {
|
||||||
ccsds_impl!();
|
ccsds_impl!();
|
||||||
@ -485,8 +493,8 @@ mod tests {
|
|||||||
|
|
||||||
fn base_ping_reply_full_ctor(timestamp: &[u8]) -> PusTm {
|
fn base_ping_reply_full_ctor(timestamp: &[u8]) -> PusTm {
|
||||||
let mut sph = SpHeader::tm_unseg(0x123, 0x234, 0).unwrap();
|
let mut sph = SpHeader::tm_unseg(0x123, 0x234, 0).unwrap();
|
||||||
let tc_header = PusTmSecondaryHeader::new_simple(17, 2, ×tamp);
|
let tm_header = PusTmSecondaryHeader::new_simple(17, 2, ×tamp);
|
||||||
PusTm::new(&mut sph, tc_header, None, true)
|
PusTm::new(&mut sph, tm_header, None, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn base_hk_reply<'a>(timestamp: &'a [u8], src_data: &'a [u8]) -> PusTm<'a> {
|
fn base_hk_reply<'a>(timestamp: &'a [u8], src_data: &'a [u8]) -> PusTm<'a> {
|
||||||
@ -680,4 +688,21 @@ mod tests {
|
|||||||
assert_eq!(tm.msg_counter(), 0x0000);
|
assert_eq!(tm.msg_counter(), 0x0000);
|
||||||
assert_eq!(tm.sc_time_ref_status(), 0b0000);
|
assert_eq!(tm.sc_time_ref_status(), 0b0000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn partial_eq_pus_tm() {
|
||||||
|
let timestamp = dummy_timestamp();
|
||||||
|
let pus_tm_1 = base_ping_reply_full_ctor(timestamp);
|
||||||
|
let pus_tm_2 = base_ping_reply_full_ctor(timestamp);
|
||||||
|
assert_eq!(pus_tm_1, pus_tm_2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn partial_eq_serialized_vs_derialized() {
|
||||||
|
let timestamp = dummy_timestamp();
|
||||||
|
let pus_tm = base_ping_reply_full_ctor(timestamp);
|
||||||
|
let mut buf = [0; 32];
|
||||||
|
pus_tm.write_to_bytes(&mut buf).unwrap();
|
||||||
|
assert_eq!(pus_tm, PusTm::from_bytes(&buf, timestamp.len()).unwrap().0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user