Support transaction list

pull/4/head
Diego Barrios Romero 2018-10-28 15:43:06 +01:00
parent ba5213adf2
commit 63fe08c6b5
2 changed files with 14 additions and 12 deletions

View File

@ -39,11 +39,11 @@ pub fn new_ds3234(transactions: &[SpiTrans])
#[macro_export]
macro_rules! get_test {
($name:ident, $method:ident, $create_method:ident, $expected:expr, $transaction:expr) => {
($name:ident, $method:ident, $create_method:ident, $expected:expr, $transactions:expr) => {
#[test]
fn $name() {
let transactions = [ $transaction ];
let mut dev = $create_method(&transactions);
let trans = $transactions;
let mut dev = $create_method(&trans);
assert_eq!($expected, dev.$method().unwrap());
}
};
@ -51,11 +51,11 @@ macro_rules! get_test {
#[macro_export]
macro_rules! set_test {
($name:ident, $method:ident, $create_method:ident, $value:expr, $transaction:expr) => {
($name:ident, $method:ident, $create_method:ident, $value:expr, $transactions:expr) => {
#[test]
fn $name() {
let transactions = [ $transaction ];
let mut dev = $create_method(&transactions);
let trans = $transactions;
let mut dev = $create_method(&trans);
dev.$method($value).unwrap();
}
};

View File

@ -12,26 +12,28 @@ use ds323x::{ Hours, Error };
macro_rules! get_param_test {
($method:ident, $register:ident, $value:expr, $binary_value:expr) => {
get_test!(can_get_ds3231, $method, new_ds3231, $value,
I2cTrans::write_read(DEV_ADDR, vec![Register::$register], vec![$binary_value]));
[ I2cTrans::write_read(DEV_ADDR, vec![Register::$register], vec![$binary_value]) ]);
get_test!(can_get_ds3232, $method, new_ds3232, $value,
I2cTrans::write_read(DEV_ADDR, vec![Register::$register], vec![$binary_value]));
[ I2cTrans::write_read(DEV_ADDR, vec![Register::$register], vec![$binary_value]) ]);
get_test!(can_get_ds3234, $method, new_ds3234, $value,
SpiTrans::transfer(vec![Register::$register, 0], vec![Register::$register, $binary_value]));
[ SpiTrans::transfer(vec![Register::$register, 0], vec![Register::$register, $binary_value]) ]);
};
}
macro_rules! set_param_test {
($method:ident, $register:ident, $value:expr, $binary_value:expr) => {
set_test!(can_set_ds3231, $method, new_ds3231, $value,
I2cTrans::write(DEV_ADDR, vec![Register::$register, $binary_value]));
[ I2cTrans::write(DEV_ADDR, vec![Register::$register, $binary_value]) ]);
set_test!(can_set_ds3232, $method, new_ds3232, $value,
I2cTrans::write(DEV_ADDR, vec![Register::$register, $binary_value]));
[ I2cTrans::write(DEV_ADDR, vec![Register::$register, $binary_value]) ]);
set_test!(can_set_ds3234, $method, new_ds3234, $value,
SpiTrans::write(vec![Register::$register + 0x80, $binary_value]));
[ SpiTrans::write(vec![Register::$register + 0x80, $binary_value]) ]);
};
}
};
}