Buttplug sex toy control library

test: Add a few simple device config tests

+192
+3
crates/buttplug_server_device_config/Cargo.toml
··· 42 42 serde_json = "1.0.140" 43 43 serde = { version = "1.0.219", features = ["derive"] } 44 44 buttplug_core = { path = "../buttplug_core" } 45 + 46 + [dev-dependencies] 47 + test-case = "3.3.1"
+54
crates/buttplug_server_device_config/tests/test_configs/base_aneros_protocol.json
··· 1 + { 2 + "version": { 3 + "major": 4, 4 + "minor": 1 5 + }, 6 + "protocols": { 7 + "aneros": { 8 + "communication": [ 9 + { 10 + "btle": { 11 + "names": [ 12 + "Massage Demo" 13 + ], 14 + "services": { 15 + "0000ff00-0000-1000-8000-00805f9b34fb": { 16 + "tx": "0000ff01-0000-1000-8000-00805f9b34fb" 17 + } 18 + } 19 + } 20 + } 21 + ], 22 + "defaults": { 23 + "features": [ 24 + { 25 + "description": "Perineum Vibrator", 26 + "id": "a980bc1a-5554-4293-a75f-6d17bf25ebee", 27 + "output": { 28 + "vibrate": { 29 + "value": [ 30 + 0, 31 + 127 32 + ] 33 + } 34 + } 35 + }, 36 + { 37 + "description": "Internal Vibrator", 38 + "id": "811d7d6e-6a75-4925-943a-a06042223e3a", 39 + "output": { 40 + "vibrate": { 41 + "value": [ 42 + 0, 43 + 127 44 + ] 45 + } 46 + } 47 + } 48 + ], 49 + "id": "f023f0f4-6629-469e-84c4-171ed4939f3d", 50 + "name": "Aneros Vivi" 51 + } 52 + } 53 + } 54 + }
+37
crates/buttplug_server_device_config/tests/test_configs/base_tcode_protocol.json
··· 1 + { 2 + "version": { 3 + "major": 4, 4 + "minor": 1 5 + }, 6 + "protocols": { 7 + "tcode-v03": { 8 + "defaults": { 9 + "features": [ 10 + { 11 + "id": "4097edde-7efb-4c3e-afdb-0aeb82a03fd9", 12 + "output": { 13 + "position": { 14 + "value": [ 15 + 0, 16 + 1000 17 + ] 18 + }, 19 + "position_with_duration": { 20 + "position": [ 21 + 0, 22 + 1000 23 + ], 24 + "duration": [ 25 + 0, 26 + 30000 27 + ] 28 + } 29 + } 30 + } 31 + ], 32 + "id": "211da02e-467c-4788-96bd-689049867e85", 33 + "name": "TCode v0.3 (Single Linear Axis)" 34 + } 35 + } 36 + } 37 + }
+36
crates/buttplug_server_device_config/tests/test_configs/user_tcode_protocol.json
··· 1 + { 2 + "version": { 3 + "major": 4, 4 + "minor": 1 5 + }, 6 + "user-configs": { 7 + "protocols": { 8 + "tcode-v03": { 9 + "communication": [ 10 + { 11 + "serial": { 12 + "baud-rate": 115200, 13 + "data-bits": 8, 14 + "parity": "N", 15 + "port": "COM1", 16 + "stop-bits": 1 17 + } 18 + }, 19 + { 20 + "btle": { 21 + "names": [ 22 + "tcode-test" 23 + ], 24 + "services": { 25 + "97f2cb39-8098-4ca3-b7b0-05dd9eb1bde0": { 26 + "tx": "97f2cb39-8098-4ca3-b7b0-05dd9eb1bde1", 27 + "rx": "97f2cb39-8098-4ca3-b7b0-05dd9eb1bde2" 28 + } 29 + } 30 + } 31 + } 32 + ] 33 + } 34 + } 35 + } 36 + }
+6
crates/buttplug_server_device_config/tests/test_configs/version_only.json
··· 1 + { 2 + "version": { 3 + "major": 4, 4 + "minor": 0 5 + } 6 + }
+56
crates/buttplug_server_device_config/tests/test_device_config.rs
··· 1 + use buttplug_server_device_config::{UserDeviceIdentifier, load_protocol_configs}; 2 + use test_case::test_case; 3 + 4 + #[test_case("version_only.json" ; "Version Only")] 5 + #[test_case("base_aneros_protocol.json" ; "Aneros Protocol")] 6 + #[test_case("base_tcode_protocol.json" ; "TCode Protocol")] 7 + fn test_valid_base_config(test_file: &str) { 8 + load_protocol_configs( 9 + &Some( 10 + str::from_utf8(&std::fs::read(format!("tests/test_configs/{}", test_file)).unwrap()) 11 + .unwrap() 12 + .to_owned(), 13 + ), 14 + &None, 15 + false, 16 + ) 17 + .unwrap().finish().unwrap(); 18 + } 19 + 20 + #[test_case("base_tcode_protocol.json", "user_tcode_protocol.json" ; "TCode Protocol")] 21 + fn test_valid_user_config(base_config: &str, user_config: &str) { 22 + load_protocol_configs( 23 + &Some( 24 + str::from_utf8(&std::fs::read(format!("tests/test_configs/{}", base_config)).unwrap()) 25 + .unwrap() 26 + .to_owned(), 27 + ), 28 + &Some( 29 + str::from_utf8(&std::fs::read(format!("tests/test_configs/{}", user_config)).unwrap()) 30 + .unwrap() 31 + .to_owned(), 32 + ), 33 + false, 34 + ) 35 + .unwrap().finish().unwrap(); 36 + } 37 + 38 + #[test] 39 + fn test_tcode_device_creation() { 40 + let dcm = load_protocol_configs( 41 + &Some( 42 + str::from_utf8(&std::fs::read("tests/test_configs/base_tcode_protocol.json").unwrap()) 43 + .unwrap() 44 + .to_owned(), 45 + ), 46 + &Some( 47 + str::from_utf8(&std::fs::read("tests/test_configs/user_tcode_protocol.json").unwrap()) 48 + .unwrap() 49 + .to_owned(), 50 + ), 51 + false, 52 + ) 53 + .unwrap().finish().unwrap(); 54 + let device = dcm.device_definition(&UserDeviceIdentifier::new("COM1", "tcode-v03", &None)).unwrap(); 55 + assert_eq!(device.name(), "TCode v0.3 (Single Linear Axis)"); 56 + }