Skip to content

Commit

Permalink
Fix linting checks on NAME
Browse files Browse the repository at this point in the history
Fixes some failed checks from clippy.
  • Loading branch information
ad3154 committed Aug 8, 2023
1 parent ae212f8 commit aaad2fe
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/network_management/name.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright 2023 Raven Industries inc.
#![allow(dead_code)]
const DEFAULT_NAME: u64 = 0xFFFFFFFFFFFFFFFF;

#[derive(PartialEq, Eq, Clone, Copy)]
Expand Down Expand Up @@ -33,6 +32,7 @@ impl NAME {
Self { raw_name }
}

#[allow(clippy::too_many_arguments)]
pub fn build(
short_identity_number: u16,
extended_identity_number: u8,
Expand Down Expand Up @@ -61,7 +61,7 @@ impl NAME {

pub fn check_mask(name_to_check: &NAME, name_fields: &Vec<NameFieldValue>) -> bool {
let mut matched = false;
if (0 != name_fields.len()) && (DEFAULT_NAME != name_to_check.raw_name) {
if (!name_fields.is_empty()) && (DEFAULT_NAME != name_to_check.raw_name) {
matched = true;

for field in name_fields {
Expand Down Expand Up @@ -205,7 +205,7 @@ impl NAME {
}
}
}
return matched;
matched
}

pub fn get_device_class(&self) -> u8 {
Expand Down Expand Up @@ -326,7 +326,7 @@ mod tests {
name_under_test.set_device_class_instance(7);
name_under_test.set_manufacturer_code(8);

assert_eq!(true, name_under_test.get_self_configurable_address());
assert!(name_under_test.get_self_configurable_address());
assert_eq!(1, name_under_test.get_industry_group());
assert_eq!(2, name_under_test.get_device_class());
assert_eq!(3, name_under_test.get_function());
Expand Down Expand Up @@ -388,88 +388,88 @@ mod tests {
};
filters_to_test.push(identity_number_filter);

assert_eq!(false, NAME::check_mask(&test_name, &filters_to_test));
assert!(!NAME::check_mask(&test_name, &filters_to_test));
test_name.set_identity_number(1);
assert_eq!(true, NAME::check_mask(&test_name, &filters_to_test));
assert!(NAME::check_mask(&test_name, &filters_to_test));

let manufacturer_number_filter = NameFieldValue {
value: 2,
field: NameField::ManufacturerCode,
};
filters_to_test.push(manufacturer_number_filter);

assert_eq!(false, NAME::check_mask(&test_name, &filters_to_test));
assert!(!NAME::check_mask(&test_name, &filters_to_test));
test_name.set_manufacturer_code(2);
assert_eq!(true, NAME::check_mask(&test_name, &filters_to_test));
assert!(NAME::check_mask(&test_name, &filters_to_test));

let ecu_instance_filter = NameFieldValue {
value: 3,
field: NameField::EcuInstance,
};
filters_to_test.push(ecu_instance_filter);

assert_eq!(false, NAME::check_mask(&test_name, &filters_to_test));
assert!(!NAME::check_mask(&test_name, &filters_to_test));
test_name.set_ecu_instance(3);
assert_eq!(true, NAME::check_mask(&test_name, &filters_to_test));
assert!(NAME::check_mask(&test_name, &filters_to_test));

let function_instance_filter = NameFieldValue {
value: 4,
field: NameField::FunctionInstance,
};
filters_to_test.push(function_instance_filter);

assert_eq!(false, NAME::check_mask(&test_name, &filters_to_test));
assert!(!NAME::check_mask(&test_name, &filters_to_test));
test_name.set_function_instance(4);
assert_eq!(true, NAME::check_mask(&test_name, &filters_to_test));
assert!(NAME::check_mask(&test_name, &filters_to_test));

let function_filter = NameFieldValue {
value: 5,
field: NameField::Function,
};
filters_to_test.push(function_filter);

assert_eq!(false, NAME::check_mask(&test_name, &filters_to_test));
assert!(!NAME::check_mask(&test_name, &filters_to_test));
test_name.set_function(5);
assert_eq!(true, NAME::check_mask(&test_name, &filters_to_test));
assert!(NAME::check_mask(&test_name, &filters_to_test));

let device_class_filter = NameFieldValue {
value: 6,
field: NameField::DeviceClass,
};
filters_to_test.push(device_class_filter);

assert_eq!(false, NAME::check_mask(&test_name, &filters_to_test));
assert!(!NAME::check_mask(&test_name, &filters_to_test));
test_name.set_device_class(6);
assert_eq!(true, NAME::check_mask(&test_name, &filters_to_test));
assert!(NAME::check_mask(&test_name, &filters_to_test));

let industry_group_filter = NameFieldValue {
value: 7,
field: NameField::IndustryGroup,
};
filters_to_test.push(industry_group_filter);

assert_eq!(false, NAME::check_mask(&test_name, &filters_to_test));
assert!(!NAME::check_mask(&test_name, &filters_to_test));
test_name.set_industry_group(7);
assert_eq!(true, NAME::check_mask(&test_name, &filters_to_test));
assert!(NAME::check_mask(&test_name, &filters_to_test));

let device_class_instance_filter = NameFieldValue {
value: 8,
field: NameField::DeviceClassInstance,
};
filters_to_test.push(device_class_instance_filter);

assert_eq!(false, NAME::check_mask(&test_name, &filters_to_test));
assert!(!NAME::check_mask(&test_name, &filters_to_test));
test_name.set_device_class_instance(8);
assert_eq!(true, NAME::check_mask(&test_name, &filters_to_test));
assert!(NAME::check_mask(&test_name, &filters_to_test));

let self_configurable_address_filter = NameFieldValue {
value: true as u32,
field: NameField::SelfConfigurableAddress,
};
filters_to_test.push(self_configurable_address_filter);

assert_eq!(false, NAME::check_mask(&test_name, &filters_to_test));
assert!(!NAME::check_mask(&test_name, &filters_to_test));
test_name.set_self_configurable_address(true);
assert_eq!(true, NAME::check_mask(&test_name, &filters_to_test));
assert!(NAME::check_mask(&test_name, &filters_to_test));
}
}

0 comments on commit aaad2fe

Please sign in to comment.