summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-11 11:43:26 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-11 11:43:26 +0100
commitd1723322ec05e3ddfd3a5a8d56ceb5f23fc7d372 (patch)
tree2d461b8c6d7743202353b5a761e2b4fef6b696b9 /tests
parente571469bbb1d91744819a4744ed6a8c7975e7467 (diff)
downloadads1x1x-async-d1723322ec05e3ddfd3a5a8d56ceb5f23fc7d372.tar.gz
ads1x1x-async-d1723322ec05e3ddfd3a5a8d56ceb5f23fc7d372.tar.xz
ads1x1x-async-d1723322ec05e3ddfd3a5a8d56ceb5f23fc7d372.zip
Refactor tests
Diffstat (limited to 'tests')
-rw-r--r--tests/tier2_i2c.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/tests/tier2_i2c.rs b/tests/tier2_i2c.rs
index e032a6c..b8b15fe 100644
--- a/tests/tier2_i2c.rs
+++ b/tests/tier2_i2c.rs
@@ -9,11 +9,12 @@ mod common;
use common::{ new_ads1014, destroy_ads1014,
DEVICE_ADDRESS as DEV_ADDR, Register, BitFlags, Config };
+
macro_rules! set_value_test {
- ($name:ident, $method:ident, $value:expr, $config:expr) => {
+ ($name:ident, $method:ident, $value:expr, $reg:ident, $msb:expr, $lsb:expr) => {
#[test]
fn $name() {
- let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, $config.msb(), $config.lsb()]) ];
+ let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::$reg, $msb, $lsb]) ];
let mut dev = new_ads1014(&transactions);
dev.$method($value).unwrap();
destroy_ads1014(dev);
@@ -21,21 +22,27 @@ macro_rules! set_value_test {
}
}
+macro_rules! config_test {
+ ($name:ident, $method:ident, $value:expr, $config:expr) => {
+ set_value_test!($name, $method, $value, CONFIG, $config.msb(), $config.lsb());
+ }
+}
+
mod can_set_comparator_mode {
use super::*;
- 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));
+ config_test!(traditional, set_comparator_mode, ComparatorMode::Traditional, Config::default().with_low( BitFlags::COMP_MODE));
+ config_test!(window, set_comparator_mode, ComparatorMode::Window, Config::default().with_high(BitFlags::COMP_MODE));
}
mod can_set_comparator_polarity {
use super::*;
- 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));
+ config_test!(low, set_comparator_polarity, ComparatorPolarity::ActiveLow, Config::default().with_low( BitFlags::COMP_POL));
+ config_test!(high, set_comparator_polarity, ComparatorPolarity::ActiveHigh, Config::default().with_high(BitFlags::COMP_POL));
}
mod can_set_comparator_latching {
use super::*;
- set_value_test!(non, set_comparator_latching, ComparatorLatching::Nonlatching, Config::default().with_low( BitFlags::COMP_LAT));
- set_value_test!(lat, set_comparator_latching, ComparatorLatching::Latching, Config::default().with_high(BitFlags::COMP_LAT));
+ config_test!(non, set_comparator_latching, ComparatorLatching::Nonlatching, Config::default().with_low( BitFlags::COMP_LAT));
+ config_test!(lat, set_comparator_latching, ComparatorLatching::Latching, Config::default().with_high(BitFlags::COMP_LAT));
}