Skip to content

Commit 38b3ae8

Browse files
committed
test: Fix Lovense tests for dealing with notify-only identification
Lovense tests relied on reads for device identification, which was removed because devices only use notify/indicate. Update tests to reflect this.
1 parent bb1f4c8 commit 38b3ae8

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

Buttplug.Test/Devices/Protocols/LovenseTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public async Task Init()
3232

3333
// Just leave name the same as the prefix, we'll set device type via initialize.
3434
awaittestUtil.SetupTest<LovenseProtocol>("LVS",false);
35-
testUtil.AddExpectedRead(Endpoints.Tx,Encoding.ASCII.GetBytes("W:39:000000000000"));
35+
testUtil.AddExpectedNotify("DeviceType;",Encoding.ASCII.GetBytes("W:39:000000000000"));
3636
awaittestUtil.Initialize();
3737
}
3838

@@ -119,7 +119,7 @@ public async Task Init()
119119

120120
// Just leave name the same as the prefix, we'll set device type via initialize.
121121
awaittestUtil.SetupTest<LovenseProtocol>("LVS",false);
122-
testUtil.AddExpectedRead(Endpoints.Tx,Encoding.ASCII.GetBytes("P:39:000000000000"));
122+
testUtil.AddExpectedNotify("DeviceType;",Encoding.ASCII.GetBytes("P:39:000000000000"));
123123
awaittestUtil.Initialize();
124124
}
125125

@@ -210,7 +210,7 @@ public async Task Init()
210210

211211
// Just leave name the same as the prefix, we'll set device type via initialize.
212212
awaittestUtil.SetupTest<LovenseProtocol>("LVS",false);
213-
testUtil.AddExpectedRead(Endpoints.Tx,Encoding.ASCII.GetBytes("A:13:000000000000"));
213+
testUtil.AddExpectedNotify("DeviceType;",Encoding.ASCII.GetBytes("A:13:000000000000"));
214214
awaittestUtil.Initialize();
215215
}
216216

Buttplug.Test/Devices/Protocols/Utils/ProtocolTestUtils.cs

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public void AddExpectedRead(string aCharacteristic, byte[] aValue)
6262
_testImpl.AddExpectedRead(aCharacteristic,aValue);
6363
}
6464

65+
publicvoidAddExpectedNotify(stringaTriggerString,byte[]aValue)
66+
{
67+
_testImpl.AddExpectedNotify(aTriggerString,aValue);
68+
}
69+
6570
privatevoidClear()
6671
{
6772
_testImpl.LastWritten.Clear();

Buttplug/Test/TestDeviceImpl.cs

+21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
usingSystem.Collections.Generic;
33
usingSystem.Diagnostics.CodeAnalysis;
44
usingSystem.Linq;
5+
usingSystem.Text;
56
usingSystem.Threading;
67
usingSystem.Threading.Tasks;
78
usingButtplug.Core.Logging;
@@ -27,6 +28,8 @@ public class ReadData
2728

2829
publicList<WriteData>LastWritten=newList<WriteData>();
2930
publicDictionary<string,List<byte[]>>ExpectedRead=newDictionary<string,List<byte[]>>();
31+
// Maps a string we get as a write to a return packet. Mostly used for Lovense.
32+
publicDictionary<string,byte[]>ExpectedNotify=newDictionary<string,byte[]>();
3033

3134
publiceventEventHandlerValueWritten;
3235

@@ -56,6 +59,11 @@ public void AddExpectedRead(string aCharacteristicIndex, byte[] aValue)
5659
ExpectedRead[aCharacteristicIndex].Add(aValue);
5760
}
5861

62+
publicvoidAddExpectedNotify(stringaNotifyStr,byte[]aValue)
63+
{
64+
ExpectedNotify.Add(aNotifyStr,aValue);
65+
}
66+
5967
publicoverrideTaskWriteValueAsyncInternal(byte[]aValue,
6068
ButtplugDeviceWriteOptionsaOptions,
6169
CancellationTokenaToken=default(CancellationToken))
@@ -67,6 +75,19 @@ public override Task WriteValueAsyncInternal(byte[] aValue,
6775
WriteWithResponse=aOptions.WriteWithResponse,
6876
});
6977
ValueWritten?.Invoke(this,newEventArgs());
78+
try
79+
{
80+
varvalueStr=Encoding.UTF8.GetString(aValue,0,aValue.Length);
81+
if(ExpectedNotify.ContainsKey(valueStr))
82+
{
83+
InvokeDataReceived(newButtplugDeviceDataEventArgs("tx",ExpectedNotify[valueStr]));
84+
}
85+
}
86+
catch
87+
{
88+
// noop.
89+
}
90+
7091
returnTask.CompletedTask;
7192
}
7293

0 commit comments

Comments
 (0)
close