Buttplug sex toy control library
1// Buttplug Rust Source Code File - See https://buttplug.io for more info.
2//
3// Copyright 2016-2024 Nonpolynomial Labs LLC. All rights reserved.
4//
5// Licensed under the BSD 3-Clause license. See LICENSE file in the project root
6// for full license information.
7
8mod util;
9use buttplug_core::message::{
10 BUTTPLUG_CURRENT_API_MAJOR_VERSION,
11 BUTTPLUG_CURRENT_API_MINOR_VERSION,
12 ButtplugServerMessageV4,
13 RequestServerInfoV4,
14 StartScanningV0,
15};
16use buttplug_server::message::{ButtplugClientMessageVariant, ButtplugServerMessageVariant};
17
18use futures::{StreamExt, pin_mut};
19pub use util::test_device_manager::TestDeviceCommunicationManagerBuilder;
20use util::test_server_with_device;
21
22// Test devices that have protocols that support movements not all devices do.
23// For instance, the Onyx+ is part of a protocol that supports vibration, but
24// the device itself does not.
25#[tokio::test]
26#[ignore = "Need to figure out what exposure we're testing here"]
27async fn test_capabilities_exposure() {
28 tracing_subscriber::fmt::init();
29 // Hold the channel but don't do anything with it.
30 let (server, _channel) = test_server_with_device("Onyx+");
31 let recv = server.event_stream();
32 pin_mut!(recv);
33
34 server
35 .parse_message(ButtplugClientMessageVariant::V4(
36 RequestServerInfoV4::new(
37 "Test Client",
38 BUTTPLUG_CURRENT_API_MAJOR_VERSION,
39 BUTTPLUG_CURRENT_API_MINOR_VERSION,
40 )
41 .into(),
42 ))
43 .await
44 .expect("Test, assuming infallible.");
45 server
46 .parse_message(ButtplugClientMessageVariant::V4(
47 StartScanningV0::default().into(),
48 ))
49 .await
50 .expect("Test, assuming infallible.");
51 while let Some(msg) = recv.next().await {
52 if let ButtplugServerMessageVariant::V4(ButtplugServerMessageV4::DeviceList(_list)) = msg {
53 // TODO Figure out what we're actually testing here?!
54 //assert!(device.device_features().iter().any(|x| x.actuator().));
55 //assert!(device.device_messages().linear_cmd().is_some());
56 return;
57 }
58 }
59}
60
61/*
62#[cfg(target_os = "windows")]
63#[ignore = "Has weird timeout issues"]
64#[tokio::test]
65async fn test_repeated_address_additions() {
66 let mut server_builder = ButtplugServerBuilder::default();
67 let builder = TestDeviceCommunicationManagerBuilder::default();
68 let helper = builder.helper();
69 server_builder.comm_manager(builder);
70 let server = server_builder.finish().unwrap();
71 let recv = server.event_stream();
72 pin_mut!(recv);
73 helper
74 .add_ble_device_with_address("Massage Demo", "SameAddress")
75 .await;
76 helper
77 .add_ble_device_with_address("Massage Demo", "SameAddress")
78 .await;
79 assert!(server
80 .parse_message(
81 messages::RequestServerInfo::new("Test Client", BUTTPLUG_CURRENT_MESSAGE_SPEC_VERSION)
82 .into()
83 )
84 .await
85 .is_ok());
86 assert!(server
87 .parse_message(messages::StartScanning::default().into())
88 .await
89 .is_ok());
90 let mut device_index = None;
91 let mut device_removed_called = true;
92 while let Some(msg) = recv.next().await {
93 match msg {
94 ButtplugServerScanningFinished(_) => continue,
95 ButtplugServerDeviceAdded(da) => {
96 assert_eq!(da.device_name(), "Aneros Vivi");
97 if device_index.is_none() {
98 device_index = Some(da.device_index());
99 } else {
100 assert!(device_removed_called);
101 assert_eq!(
102 da.device_index(),
103 device_index.expect("Test, assuming infallible.")
104 );
105 return;
106 }
107 }
108 ButtplugServerDeviceRemoved(dr) => {
109 assert_eq!(
110 dr.device_index(),
111 device_index.expect("Test, assuming infallible.")
112 );
113 device_removed_called = true;
114 }
115 _ => {
116 panic!(
117 "Returned message was not a DeviceAdded message or timed out: {:?}",
118 msg
119 );
120 }
121 }
122 }
123}
124*/