diff options
-rw-r--r-- | tests/tier2_i2c.rs | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/tests/tier2_i2c.rs b/tests/tier2_i2c.rs index 5a3c950..e8162c4 100644 --- a/tests/tier2_i2c.rs +++ b/tests/tier2_i2c.rs @@ -9,13 +9,13 @@ mod common; use common::{ new_ads1014, destroy_ads1014, DEVICE_ADDRESS as DEV_ADDR, Register, BitFlags, Config }; -macro_rules! test_set_comparator_mode { - ($name:ident, $variant:ident, $config:expr) => { +macro_rules! set_value_test { + ($name:ident, $method:ident, $value:expr, $config:expr) => { #[test] fn $name() { let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, $config.msb(), $config.lsb()]) ]; let mut dev = new_ads1014(&transactions); - dev.set_comparator_mode(ComparatorMode::$variant).unwrap(); + dev.$method($value).unwrap(); destroy_ads1014(dev); } } @@ -23,26 +23,14 @@ macro_rules! test_set_comparator_mode { mod can_set_comparator_mode { use super::*; - test_set_comparator_mode!(traditional, Traditional, Config::default().with_low( BitFlags::COMP_MODE)); - test_set_comparator_mode!(window, Window, Config::default().with_high(BitFlags::COMP_MODE)); -} - -macro_rules! test_set_comparator_pol { - ($name:ident, $variant:ident, $config:expr) => { - #[test] - fn $name() { - let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, $config.msb(), $config.lsb()]) ]; - let mut dev = new_ads1014(&transactions); - dev.set_comparator_polarity(ComparatorPolarity::$variant).unwrap(); - destroy_ads1014(dev); - } - } + set_value_test!(traditional, set_comparator_mode, ComparatorMode::Traditional, Config::default().with_low( BitFlags::COMP_MODE)); + set_value_test!(window, set_comparator_mode, ComparatorMode::Window, Config::default().with_high(BitFlags::COMP_MODE)); } mod can_set_comparator_polarity { use super::*; - test_set_comparator_pol!(low, ActiveLow, Config::default().with_low( BitFlags::COMP_POL)); - test_set_comparator_pol!(high, ActiveHigh, Config::default().with_high(BitFlags::COMP_POL)); + set_value_test!(low, set_comparator_polarity, ComparatorPolarity::ActiveLow, Config::default().with_low( BitFlags::COMP_POL)); + set_value_test!(high, set_comparator_polarity, ComparatorPolarity::ActiveHigh, Config::default().with_high(BitFlags::COMP_POL)); } |