public void OneTimeSetUp() { _logMgr = new ButtplugLogManager(); _devMgr = new DeviceManager(new ButtplugLogManager()); _subtypeMgr = new TestDeviceSubtypeManager(); _devMgr.AddDeviceSubtypeManager(_subtypeMgr); }
public void TestBaseDevice() { var log = new ButtplugLogManager(); var dev = new TestDevice(log, "testDev") { Index = 2, }; Assert.AreEqual(2, dev.Index); Assert.True(dev.Initialize().GetAwaiter().GetResult() is Ok); Assert.True(dev.ParseMessage(new StopDeviceCmd(2)).GetAwaiter().GetResult() is Ok); var outMsg = dev.ParseMessage(new RotateCmd(2, new List <RotateCmd.RotateSubcommand>())).GetAwaiter().GetResult(); Assert.True(outMsg is Error); Assert.AreEqual(Error.ErrorClass.ERROR_DEVICE, (outMsg as Error).ErrorCode); Assert.True((outMsg as Error).ErrorMessage.Contains("cannot handle message of type")); dev.Disconnect(); outMsg = dev.ParseMessage(new StopDeviceCmd(2)).GetAwaiter().GetResult(); Assert.True(outMsg is Error); Assert.AreEqual(Error.ErrorClass.ERROR_DEVICE, (outMsg as Error).ErrorCode); Assert.True((outMsg as Error).ErrorMessage.Contains("has disconnected")); }
public TestProtocolDoubleAdd(ButtplugLogManager aLogger, IButtplugDeviceImpl aDevice) : base(aLogger, aDevice) { // Add HandleRotateCmd twice, should throw AddMessageHandler <RotateCmd>(HandleRotateCmd); AddMessageHandler <RotateCmd>(HandleRotateCmd); }
public void TestFunctionDoubleAdd() { var logMgr = new ButtplugLogManager(); Action act = () => new TestProtocolDoubleAdd(logMgr, new TestDeviceImpl(logMgr, "Test")); act.Should().Throw <ArgumentException>(); }
public async Task OneTimeSetUp() { _logMgr = new ButtplugLogManager(); _subtypeMgr = new TestDeviceSubtypeManager(new TestDevice(_logMgr, "Test Device")); _websocketServer = new ButtplugWebsocketServer(); await _websocketServer.StartServerAsync(() => { var server = new TestServer(); server.AddDeviceSubtypeManager(aLogger => _subtypeMgr); return(server); }); }
public void OneTimeSetUp() { _logMgr = new ButtplugLogManager(); _subtypeMgr = new TestDeviceSubtypeManager(new TestDevice(_logMgr, "Test Device")); _ipcServer = new ButtplugIPCServer(); _ipcServer.StartServer(() => { var server = new TestServer(); server.AddDeviceSubtypeManager(aLogger => _subtypeMgr); return(server); }); }
public ServerControl(Func <ButtplugServer> aFactory) { InitializeComponent(); _logManager = new ButtplugLogManager(); _log = _logManager.GetLogger(GetType()); _ws = new ButtplugWebsocketServer(); _bpFactory = aFactory; _config = new ButtplugConfig("B******g"); _connUrls = new ConnUrlList(); _port = 12345; // Usually, if we throw errors then connect, it's not actually an error. If we don't // connect after a second of throwing an exception, pop the toaster, but not before then. _toastTimer = new Timer { Interval = 1000, AutoReset = false, Enabled = false, }; _toastTimer.Elapsed += PopToaster; if (uint.TryParse(_config.GetValue("b******g.server.port", "12345"), out uint pres)) { _port = pres; } _secure = true; if (bool.TryParse(_config.GetValue("b******g.server.secure", "true"), out bool sres)) { _secure = sres; } _loopback = true; if (bool.TryParse(_config.GetValue("b******g.server.loopbackOnly", "true"), out bool lres)) { _loopback = lres; } _hostname = _config.GetValue("b******g.server.hostname", "localhost"); PortTextBox.Text = _port.ToString(); SecureCheckBox.IsChecked = _secure; LoopbackCheckBox.IsChecked = _loopback; ConnectionUrl.ItemsSource = _connUrls; _ws.OnException += WebSocketExceptionHandler; _ws.ConnectionAccepted += WebSocketConnectionAccepted; _ws.ConnectionUpdated += WebSocketConnectionAccepted; _ws.ConnectionClosed += WebSocketConnectionClosed; _log.OnLogException += ExceptionLogged; }
/// <summary> /// Initializes a new instance of the <see cref="ButtplugWSClient"/> class. /// </summary> /// <param name="aClientName">The name of the client (used by the server for UI and permissions).</param> public ButtplugWSClient(string aClientName) { _clientName = aClientName; IButtplugLogManager bpLogManager = new ButtplugLogManager(); _bpLogger = bpLogManager.GetLogger(GetType()); _parser = new ButtplugJsonMessageParser(bpLogManager); _bpLogger.Info("Finished setting up ButtplugClient"); _owningDispatcher = SynchronizationContext.Current ?? new SynchronizationContext(); _tokenSource = new CancellationTokenSource(); _counter = 0; }
public void TestClientDeviceEquality() { var logMgr = new ButtplugLogManager(); var client = new ButtplugClient("Test Device Client", new ButtplugEmbeddedConnector("Test Device Server")); Task SendFunc(ButtplugClientDevice device, ButtplugMessage msg, CancellationToken token) => Task.CompletedTask; var testDevice = new ButtplugClientDevice(logMgr, client, SendFunc, 1, "Test Device", new Dictionary <string, MessageAttributes>() { { "SingleMotorVibrateCmd", new MessageAttributes() }, { "VibrateCmd", new MessageAttributes(2) }, { "StopDeviceCmd", new MessageAttributes() }, }); var testDevice2 = new ButtplugClientDevice(logMgr, client, SendFunc, 1, "Test Device", new Dictionary <string, MessageAttributes>() { { "SingleMotorVibrateCmd", new MessageAttributes() }, { "VibrateCmd", new MessageAttributes(2) }, { "StopDeviceCmd", new MessageAttributes() }, }); var testDevice3 = new ButtplugClientDevice(logMgr, client, SendFunc, 1, "Test Device", new Dictionary <string, MessageAttributes>() { { "SingleMotorVibrateCmd", new MessageAttributes() }, { "VibrateCmd", new MessageAttributes(2) }, }); var testDevice4 = new ButtplugClientDevice(logMgr, client, SendFunc, 1, "Test Device", new Dictionary <string, MessageAttributes>() { { "SingleMotorVibrateCmd", new MessageAttributes() }, { "VibrateCmd", new MessageAttributes(2) }, { "FleshlightLaunchFW12Cmd", new MessageAttributes() }, }); var testDevice5 = new ButtplugClientDevice(logMgr, client, SendFunc, 1, "Test Device", new Dictionary <string, MessageAttributes>() { { "SingleMotorVibrateCmd", new MessageAttributes() }, { "VibrateCmd", new MessageAttributes(2) }, { "StopDeviceCmd", new MessageAttributes() }, { "RotateCmd", new MessageAttributes(1) }, }); var newClient = new ButtplugClient("Other Test Device Client", new ButtplugEmbeddedConnector("Other Test Device Server")); var otherTestDevice = new ButtplugClientDevice(logMgr, newClient, SendFunc, 1, "Test Device", new Dictionary <string, MessageAttributes>() { { "SingleMotorVibrateCmd", new MessageAttributes() }, { "VibrateCmd", new MessageAttributes(2) }, { "StopDeviceCmd", new MessageAttributes() }, }); testDevice.Should().BeEquivalentTo(testDevice2); testDevice.Should().NotBe(testDevice3); testDevice.Should().NotBe(testDevice4); testDevice.Should().NotBe(testDevice5); testDevice.Should().NotBe(otherTestDevice); }
public async void SerializeUnhandledMessage() { var logger = new ButtplugLogManager(); var r = new ButtplugJsonMessageParser(logger).Serialize(new FakeMessage(1)); // Even though the message is defined outside the core library, it should at least serialize Assert.True(r.Length > 0); // However it shouldn't be taken by the server. var s = new TestServer(); var e = await s.SendMessage(r); Assert.True(e.Length == 1); Assert.True(e[0] is Error); }
public async Task SetupTest <T>(string aDeviceName, bool aShouldInitialize = true) where T : IButtplugDeviceProtocol { var logMgr = new ButtplugLogManager(); _testImpl = new TestDeviceImpl(logMgr, aDeviceName); _testDevice = new ButtplugDevice(logMgr, typeof(T), _testImpl); if (!aShouldInitialize) { return; } await Initialize(); }
public async Task TestBaseDevice() { var logMgr = new ButtplugLogManager(); var devImpl = new TestDeviceImpl(logMgr, "Device"); var dev = new ButtplugDevice(logMgr, new TestProtocol(logMgr, devImpl), devImpl) { Index = 2, }; await dev.InitializeAsync(default(CancellationToken)); (await dev.ParseMessageAsync(new StopDeviceCmd(2), default(CancellationToken))).Should().BeOfType <Ok>(); dev.Awaiting(async aDevice => await dev.ParseMessageAsync(new RotateCmd(2, new List <RotateCmd.RotateSubcommand>()), default(CancellationToken))).Should().Throw <ButtplugDeviceException>(); dev.Disconnect(); dev.Awaiting(async aDevice => await aDevice.ParseMessageAsync(new StopDeviceCmd(2), default(CancellationToken))).Should().Throw <ButtplugDeviceException>(); }
public SimulatorManager(IButtplugLogManager aLogManager) : base(aLogManager) { BpLogger.Info("Loading Simulator Manager"); _scanning = false; _parser = new PipeMessageParser(); _logManager = new ButtplugLogManager(); _pipeServer = new NamedPipeServerStream("ButtplugDeviceSimulator", PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous); _tokenSource = new CancellationTokenSource(); _readThread = new Task(() => { connAccepter(_tokenSource.Token); }, _tokenSource.Token, TaskCreationOptions.LongRunning); _writeThread = new Task(() => { pipeWriter(_tokenSource.Token); }, _tokenSource.Token, TaskCreationOptions.LongRunning); _pingThread = new Task(() => { pingWriter(_tokenSource.Token); }, _tokenSource.Token, TaskCreationOptions.LongRunning); _readThread.Start(); _writeThread.Start(); _pingThread.Start(); }
private void LogListBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) { if (sender != LogListBox) { return; } if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.C) { var builder = new StringBuilder(); foreach (var item in LogListBox.SelectedItems) { if (item is string) { builder.AppendLine(item as string); } else if (item is ListBoxItem) { builder.AppendLine((item as ListBoxItem).Content as string); } } try { Clipboard.SetText(builder.ToString()); } catch (Exception ex) { // We've seen weird instances of can't open clipboard // but it's pretty rare. Log it. var logMan = new ButtplugLogManager(); var log = logMan.GetLogger(GetType()); log.LogException(ex); } } }
public void OneTimeSetUp() { _logManager = new ButtplugLogManager(); _parser = new ButtplugJsonMessageParser(_logManager); }
public TestDevice(ButtplugLogManager aLogManager, string aName) : base(aLogManager, aName, "Test") { MsgFuncs.Add(typeof(SingleMotorVibrateCmd), HandleSingleMotorVibrateCmd); }
public TestDeviceDoubleAdd(ButtplugLogManager aLogger) : base(aLogger, "DoubleAdd") { }
public void SetUp() { _resetSource = new TaskCompletionSource <object>(); _logMgr = new ButtplugLogManager(); SetUpConnector(); }