1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
// mod.rs
// *************************************************************************
// * Copyright (C) 2019 Daniel Mueller (deso@posteo.net) *
// * *
// * This program is free software: you can redistribute it and/or modify *
// * it under the terms of the GNU General Public License as published by *
// * the Free Software Foundation, either version 3 of the License, or *
// * (at your option) any later version. *
// * *
// * This program is distributed in the hope that it will be useful, *
// * but WITHOUT ANY WARRANTY; without even the implied warranty of *
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
// * GNU General Public License for more details. *
// * *
// * You should have received a copy of the GNU General Public License *
// * along with this program. If not, see <http://www.gnu.org/licenses/>. *
// *************************************************************************
use nitrokey::CommunicationError;
use nitrokey::Device;
use nitrokey::Error;
use nitrokey::Model;
#[nitrokey_test::test]
fn no_dev() {
let mut manager = nitrokey::force_take().unwrap();
let error = manager.connect().unwrap_err();
match error {
Error::CommunicationError(CommunicationError::NotConnected) => (),
_ => panic!("received unexpected error: {:?}", error),
}
}
#[nitrokey_test::test]
fn pro(device: Pro) {
assert_eq!(device.get_model(), Model::Pro);
let manager = device.into_manager();
assert!(manager.connect_pro().is_ok())
}
#[nitrokey_test::test(pro)]
fn pro_filter() {
let mut manager = nitrokey::force_take().unwrap();
assert!(manager.connect_pro().is_ok());
}
#[nitrokey_test::test(pro)]
fn pro_model(model: Model) {
assert_eq!(model, Model::Pro);
let mut manager = nitrokey::force_take().unwrap();
assert!(manager.connect_pro().is_ok());
}
#[nitrokey_test::test]
fn storage(device: Storage) {
assert_eq!(device.get_model(), Model::Storage);
let manager = device.into_manager();
assert!(manager.connect_storage().is_ok())
}
#[nitrokey_test::test]
fn storage_mut(mut device: Storage) {
// We don't actually want to execute anything, but the wink method
// requires a mutable device and we want to make sure that type checks
// correctly.
if false {
let _ = device.wink();
}
}
#[nitrokey_test::test(storage)]
fn storage_filter() {
let mut manager = nitrokey::force_take().unwrap();
assert!(manager.connect_storage().is_ok());
}
#[nitrokey_test::test(storage)]
fn storage_model(model: Model) {
assert_eq!(model, Model::Storage);
let mut manager = nitrokey::force_take().unwrap();
assert!(manager.connect_storage().is_ok());
}
#[nitrokey_test::test]
fn any(device: DeviceWrapper) {
let model = device.get_model();
let manager = device.into_manager();
assert!(manager.connect_model(model).is_ok())
}
#[nitrokey_test::test(storage)]
fn any_storage_filter(device: DeviceWrapper) {
match device {
nitrokey::DeviceWrapper::Storage(_) => (),
_ => panic!("received invalid model: {:?}", device),
}
}
#[nitrokey_test::test(pro)]
fn any_pro_filter(device: DeviceWrapper) {
match device {
nitrokey::DeviceWrapper::Pro(_) => (),
_ => panic!("received invalid model: {:?}", device),
}
}
#[nitrokey_test::test]
fn any_model(model: Model) {
let mut manager = nitrokey::force_take().unwrap();
assert!(manager.connect_model(model).is_ok());
}
#[nitrokey_test::test]
#[ignore]
fn ignore_no_dev() {
panic!("should be ignored")
}
#[nitrokey_test::test]
#[ignore]
fn ignore_any(_device: nitrokey::DeviceWrapper) {
panic!("should be ignored")
}
/// A trait providing a method with a &mut self signature.
trait MutableDevice<'mgr> {
fn test_mut(&mut self) -> bool {
true
}
}
impl<'mgr> MutableDevice<'mgr> for nitrokey::DeviceWrapper<'mgr> {}
#[nitrokey_test::test]
fn mutable_device(mut device: nitrokey::DeviceWrapper) {
assert!(device.test_mut())
}
#[nitrokey_test::test]
fn aribtrary_argument_name(foobarbaz: nitrokey::DeviceWrapper) {
let _ = foobarbaz.get_model();
}
|