summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2019-03-30 12:55:05 +0200
committerDiego Barrios Romero <eldruin@gmail.com>2019-03-31 13:41:26 +0200
commite6c1725b6a3419d5a28542d79bde271d0d5ef6f6 (patch)
tree9aab4c1a4b22eda261068a27e9230778a7fcd9c1 /tests
parentb226a3605f3b83f88581111723f527aae30fa34c (diff)
downloadads1x1x-async-e6c1725b6a3419d5a28542d79bde271d0d5ef6f6.tar.gz
ads1x1x-async-e6c1725b6a3419d5a28542d79bde271d0d5ef6f6.tar.xz
ads1x1x-async-e6c1725b6a3419d5a28542d79bde271d0d5ef6f6.zip
Integrate mode change into `into...` methods
Diffstat (limited to 'tests')
-rw-r--r--tests/mux.rs12
-rw-r--r--tests/tier1.rs65
2 files changed, 28 insertions, 49 deletions
diff --git a/tests/mux.rs b/tests/mux.rs
index f67690f..b961fc7 100644
--- a/tests/mux.rs
+++ b/tests/mux.rs
@@ -51,10 +51,16 @@ macro_rules! mux_test {
#[test]
fn continuous_can_select_channel() {
- let config = Config::default().with_high($config_bits);
- let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config.msb(), config.lsb()]) ];
+ let config1 = Config::default().with_low(BF::OP_MODE);
+ let config2 = config1.with_high($config_bits);
+ let transactions = [
+ I2cTrans::write(DEV_ADDR,
+ vec![Register::CONFIG, config1.msb(), config1.lsb()]),
+ I2cTrans::write(DEV_ADDR,
+ vec![Register::CONFIG, config2.msb(), config2.lsb()])
+ ];
let dev = new(&transactions);
- let mut dev = dev.into_continuous().unwrap();
+ let mut dev = dev.into_continuous().ok().unwrap();
dev.select_channel(&mut channel::$CS).unwrap();
destroy(dev);
}
diff --git a/tests/tier1.rs b/tests/tier1.rs
index 1def511..de44b3c 100644
--- a/tests/tier1.rs
+++ b/tests/tier1.rs
@@ -4,7 +4,7 @@ extern crate embedded_hal;
extern crate embedded_hal_mock as hal;
use hal::i2c::Transaction as I2cTrans;
extern crate ads1x1x;
-use ads1x1x::{ channel, DataRate12Bit, DataRate16Bit, Error };
+use ads1x1x::{channel, DataRate12Bit, DataRate16Bit};
mod common;
use common::{ new_ads1013, destroy_ads1013, new_ads1113, destroy_ads1113,
@@ -49,8 +49,7 @@ macro_rules! measure_tests {
let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config.msb(), config.lsb()]),
I2cTrans::write_read(DEV_ADDR, vec![Register::CONVERSION], vec![0x80, 0x00] ) ];
let dev = $create(&transactions);
- let mut dev = dev.into_continuous().unwrap();
- dev.start().unwrap();
+ let mut dev = dev.into_continuous().ok().unwrap();
let measurement = dev.read().unwrap();
assert_eq!($expected, measurement);
$destroy(dev);
@@ -130,55 +129,29 @@ fn can_read_measurement_not_in_progress() {
#[test]
fn can_convert_to_continuous() {
- let dev = new_ads1013(&[]);
- let dev = dev.into_continuous().unwrap();
+ let config = Config::default().with_low(BitFlags::OP_MODE);
+ let transactions = [I2cTrans::write(
+ DEV_ADDR,
+ vec![Register::CONFIG, config.msb(), config.lsb()],
+ )];
+ let dev = new_ads1013(&transactions);
+ let dev = dev.into_continuous().ok().unwrap();
destroy_ads1013(dev);
}
#[test]
fn can_convert_to_one_shot() {
+ let config_cont = Config::default().with_low(BitFlags::OP_MODE);
let config_os = Config::default();
- let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config_os.msb(), config_os.lsb()]) ];
+ let transactions = [I2cTrans::write(
+ DEV_ADDR,
+ vec![Register::CONFIG, config_cont.msb(), config_cont.lsb()]),
+ I2cTrans::write(
+ DEV_ADDR,
+ vec![Register::CONFIG, config_os.msb(), config_os.lsb()],
+ )];
let dev = new_ads1013(&transactions);
- let dev = dev.into_continuous().unwrap();
- let dev = dev.into_one_shot().unwrap();
+ let dev = dev.into_continuous().ok().unwrap();
+ let dev = dev.into_one_shot().ok().unwrap();
destroy_ads1013(dev);
}
-
-mod continuous {
- use super::*;
- #[test]
- fn can_start() {
- let config = Config::default().with_low(BitFlags::OP_MODE);
- let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config.msb(), config.lsb()]) ];
- let dev = new_ads1013(&transactions);
- let mut dev = dev.into_continuous().unwrap();
- dev.start().unwrap();
- destroy_ads1013(dev);
- }
-
- fn assert_not_started<T, E>(result: Result<T, Error<E>>) {
- match result {
- Err(Error::NotStarted) => (),
- _ => panic!("Error::NotStarted not returned.")
- }
- }
- #[test]
- fn check_assert_matches() {
- assert_not_started::<(), ()>(Err(Error::NotStarted));
- }
-
- #[test]
- #[should_panic]
- fn check_assert_fails() {
- assert_not_started::<(), ()>(Ok(()));
- }
-
- #[test]
- fn cannot_read_if_not_started() {
- let dev = new_ads1013(&[]);
- let mut dev = dev.into_continuous().unwrap();
- assert_not_started(dev.read());
- destroy_ads1013(dev);
- }
-}