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