Beispiel #1
0
        public void TestSSLConnection()
        {
            _server = new ButtplugWebsocketServer();
            _server.StartServer(this, 12346, true, true);

            _client = new ButtplugTestClient("Test client");
            _client.Connect(new Uri("wss://localhost:12346/b******g"), true).Wait();

            var msgId = _client.NextMsgId;
            var res   = _client.SendMsg(new Core.Messages.Test("Test string", msgId)).GetAwaiter().GetResult();

            Assert.True(res != null);
            Assert.True(res is Core.Messages.Test);
            Assert.True(((Core.Messages.Test)res).TestString == "Test string");
            Assert.True(((Core.Messages.Test)res).Id > msgId);

            // Check ping is working
            Thread.Sleep(400);

            msgId = _client.NextMsgId;
            res   = _client.SendMsg(new Core.Messages.Test("Test string", msgId)).GetAwaiter().GetResult();
            Assert.True(res != null);
            Assert.True(res is Core.Messages.Test);
            Assert.True(((Core.Messages.Test)res).TestString == "Test string");
            Assert.True(((Core.Messages.Test)res).Id > msgId);

            Assert.True(_client.NextMsgId > 4);

            // Shut it down
            _client.Disconnect().Wait();
            _server.StopServer();
        }
Beispiel #2
0
 public void StopServer()
 {
     _ws.StopServer();
     ConnToggleButton.Content = "Start";
     SecureCheckBox.IsEnabled = true;
     PortTextBox.IsEnabled    = true;
 }
 public void StopServer()
 {
     _ws.StopServer();
     ConnToggleButton.Content = "Start";
     SecureCheckBox.IsEnabled = true;
     PortTextBox.IsEnabled    = true;
     ConnInfo.Visibility      = Visibility.Collapsed;
 }
Beispiel #4
0
 public void StopServer()
 {
     _ws?.StopServer();
     ConnToggleButton.Content   = "Start";
     SecureCheckBox.IsEnabled   = true;
     PortTextBox.IsEnabled      = true;
     LoopbackCheckBox.IsEnabled = true;
     ConnInfo.IsEnabled         = false;
 }
        public async void TestConnection()
        {
            var server = new ButtplugWebsocketServer();

            server.StartServer(this);

            var client = new ButtplugTestClient("Test client");
            await client.Connect(new Uri("ws://localhost:12345/b******g"));

            Console.WriteLine("test msg 1");
            var msgId = client.nextMsgId;
            var res   = await client.SendMsg(new Core.Messages.Test("Test string", msgId));

            Assert.True(res != null);
            Assert.True(res is Core.Messages.Test);
            Assert.True(((Core.Messages.Test)res).TestString == "Test string");
            Assert.True(((Core.Messages.Test)res).Id == msgId);

            // Check ping is working
            Thread.Sleep(400);

            Console.WriteLine("test msg 2");
            msgId = client.nextMsgId;
            res   = await client.SendMsg(new Core.Messages.Test("Test string", msgId));

            Assert.True(res != null);
            Assert.True(res is Core.Messages.Test);
            Assert.True(((Core.Messages.Test)res).TestString == "Test string");
            Assert.True(((Core.Messages.Test)res).Id == msgId);

            Assert.True(client.nextMsgId > 4);

            await client.RequestDeviceList();

            Console.WriteLine("FINISHED CLIENT DISCONNECT");

            // Shut it down
            await client.Disconnect();

            server.StopServer();
        }
Beispiel #6
0
        public void TestConnection()
        {
            var eEvent = new AutoResetEvent(false);

            _subtypeMgr.AddDevice(new TestDevice(_logMgr, "A", "1"));
            _server = new ButtplugWebsocketServer();
            _server.StartServer(this);

            _client = new ButtplugTestClient("Test client");
            _client.Connect(new Uri("ws://localhost:12345/b******g")).Wait();

            var msgId = _client.NextMsgId;
            var res   = _client.SendMsg(new Core.Messages.Test("Test string", msgId)).GetAwaiter().GetResult();

            Assert.True(res != null);
            Assert.True(res is Core.Messages.Test);
            Assert.True(((Core.Messages.Test)res).TestString == "Test string");
            Assert.True(((Core.Messages.Test)res).Id > msgId);

            // Check ping is working
            Thread.Sleep(400);

            msgId = _client.NextMsgId;
            res   = _client.SendMsg(new Core.Messages.Test("Test string", msgId)).GetAwaiter().GetResult();
            Assert.True(res != null);
            Assert.True(res is Core.Messages.Test);
            Assert.True(((Core.Messages.Test)res).TestString == "Test string");
            Assert.True(((Core.Messages.Test)res).Id > msgId);

            res = _client.SendMsg(new Core.Messages.Test("Test string")).GetAwaiter().GetResult();
            Assert.True(res != null);
            Assert.True(res is Core.Messages.Test);
            Assert.True(((Core.Messages.Test)res).TestString == "Test string");
            Assert.True(((Core.Messages.Test)res).Id > msgId);

            Assert.True(_client.NextMsgId > 5);

            // Test that events are raised
            var scanningFinished             = false;
            ButtplugClientDevice lastAdded   = null;
            ButtplugClientDevice lastRemoved = null;

            _client.ScanningFinished += (aSender, aArg) =>
            {
                scanningFinished = true;
                eEvent.Set();
            };

            _client.DeviceAdded += (aSender, aArg) =>
            {
                lastAdded = aArg.Device;
                eEvent.Set();
            };

            _client.DeviceRemoved += (aSender, aArg) =>
            {
                lastRemoved = aArg.Device;
                eEvent.Set();
            };
            _client.StartScanning().Wait();
            Assert.Null(lastAdded);
            _subtypeMgr.AddDevice(new TestDevice(_logMgr, "B", "2"));
            eEvent.WaitOne(10000);
            eEvent.Reset();
            Assert.NotNull(lastAdded);
            Assert.AreEqual("B", lastAdded.Name);

            Assert.True(!scanningFinished);
            _client.StopScanning().Wait();
            eEvent.WaitOne(10000);
            eEvent.Reset();
            Assert.True(scanningFinished);

            Assert.AreEqual(2, _client.Devices.Length);
            Assert.AreEqual("A", _client.Devices[0].Name);
            Assert.AreEqual("B", _client.Devices[1].Name);

            eEvent.Reset();
            Assert.Null(lastRemoved);
            foreach (var dev in _devMgr._devices.Values)
            {
                if ((dev as TestDevice)?.Identifier == "2")
                {
                    (dev as TestDevice).RemoveDevice();
                }
            }

            eEvent.WaitOne(10000);
            eEvent.Reset();
            Assert.NotNull(lastRemoved);
            Assert.AreEqual("B", lastRemoved.Name);
            Assert.AreEqual(1, _client.Devices.Length);
            Assert.AreEqual("A", _client.Devices[0].Name);

            // Shut it down
            _client.Disconnect().Wait();
            _server.StopServer();
        }