Exemple #1
0
        public void AddGamepadMappings_Test()
        {
            var stoneProvider = new StoneProvider();

            foreach (var testmappings in stoneProvider.Controllers.Values)
            {
                var realmapping =
                    JsonConvert.DeserializeObject <ControllerLayout>(
                        TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
                var mapcol = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);

                var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();
                optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");

                var elementStore = new ControllerElementMappingsStore(optionsBuilder);

                elementStore.AddMappings(mapcol, "default");

                var retStore = elementStore.GetMappings(mapcol.ControllerId, mapcol.DeviceId, "default");

                foreach (var element in retStore)
                {
                    Assert.Contains(element.LayoutElement, mapcol.Select(x => x.LayoutElement));
                    Assert.Equal(element.DeviceElement,
                                 mapcol.First(x => x.LayoutElement == element.LayoutElement).DeviceElement);
                }
            }
        }
Exemple #2
0
        public void GetMultipleMappings_Test()
        {
            var stoneProvider = new StoneProvider();

            foreach (var testmappings in stoneProvider.Controllers.Values)
            {
                var realmapping =
                    JsonConvert.DeserializeObject <ControllerLayout>(
                        TestUtilities.GetStringResource("InputMappings.keyboard_device.json"));
                var mapcol = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);

                var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();
                optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");
                var elementStore = new ControllerElementMappingsStore(optionsBuilder);

                elementStore.AddMappings(mapcol, "default");
                elementStore.AddMappings(mapcol, "default2");

                Assert.Equal(2, elementStore.GetMappings(mapcol.ControllerId, mapcol.DeviceId).Count());
                elementStore.DeleteMappings(mapcol.ControllerId, mapcol.DeviceId, "default");
                Assert.Single(elementStore.GetMappings(mapcol.ControllerId, mapcol.DeviceId));
                elementStore.DeleteMappings(mapcol.ControllerId, mapcol.DeviceId);
                Assert.Empty(elementStore.GetMappings(mapcol.ControllerId, mapcol.DeviceId));
            }
        }
Exemple #3
0
        public void InputTemplateToAbstractConfigurationNodeXmlSerializer_Test()
        {
            var testmappings = new StoneProvider().Controllers["XBOX_CONTROLLER"];
            var realmapping  =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
            var           mapcol   = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);
            string        _mapping = TestUtilities.GetStringResource("InputMappings.DirectInput.XINPUT_DEVICE.json");
            IInputMapping mapping  = JsonConvert.DeserializeObject <InputMapping>(_mapping);
            var           input    =
                new InputTemplate <IRetroArchInput>(mapcol).Template;


            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var context = new ConfigurationTraversalContext();

            var list = context.TraverseInputTemplate(input, mapping, 0);

            var xmlSerializer = new SimpleXmlConfigurationSerializer("Config");

            string    outputXml = xmlSerializer.Transform(list);
            XDocument doc       = XDocument.Parse(outputXml);

            Assert.NotEmpty(doc.Nodes());
        }
        public void ConfigurationFactoryInput_Test()
        {
            IInputMapping mapping = JsonConvert.DeserializeObject <InputMapping>
                                        (TestUtilities.GetStringResource("InputMappings.DirectInput.KEYBOARD_DEVICE.json"));

            var configFactory = new TestConfigurationFactory(new[] { mapping });

            var realLayout =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.keyboard_device.json"));

            var targetLayout =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.xinput_device.json"));

            var fakeInputDevice = new Mock <IInputDevice>();

            fakeInputDevice.Setup(p => p.DeviceId).Returns("KEYBOARD_DEVICE");
            fakeInputDevice.Setup(p => p.DeviceLayout).Returns(realLayout);
            fakeInputDevice.Setup(p => p.DeviceApi).Returns(InputApi.DirectInput);

            var map = ControllerElementMappings.GetDefaultMappings(realLayout, targetLayout);
            var emulatedController = new EmulatedController(0, fakeInputDevice.Object, targetLayout, map);

            (IInputTemplate template, IInputMapping inputMappings) = configFactory.GetInputMappings(emulatedController);
            Assert.Equal(ControllerElement.KeyZ, template[ControllerElement.ButtonA]);
        }
Exemple #5
0
        public IControllerElementMappings GetDefaultProfile(string controllerId, string deviceId,
                                                            string profileName = "default")
        {
            var emulatedController = this.StoneProvider.Controllers[controllerId];
            var realController     = this.GetAllInputDevices().FirstOrDefault(p => p.DeviceId == deviceId)?.DeviceLayout;

            // todo: check for nulls
            return(ControllerElementMappings.GetDefaultMappings(realController, emulatedController));
        }
Exemple #6
0
        public IControllerElementMappings CreateProfile(DefaultMappedControllerElementCollectionInputObject input)
        {
            var emulatedController = this.StoneProvider.Controllers[input.ControllerId];
            var realController     = this.GetAllInputDevices().FirstOrDefault(p => p.DeviceId == input.DeviceId)
                                     ?.DeviceLayout;

            // todo: check for nulls
            var defaults = ControllerElementMappings.GetDefaultMappings(realController, emulatedController);

            this.MappedElementStore.AddMappings(defaults, input.ProfileName);
            return(this.MappedElementStore.GetMappings(input.ControllerId, input.DeviceId, input.ProfileName));
        }
Exemple #7
0
        public void NestedSetter_Test()
        {
            var stoneProvider = new StoneProvider();
            var testmappings  = stoneProvider.Controllers.First().Value;
            var realmapping   =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.keyboard_device.json"));
            var mapcol = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);
            var x      = new InputTemplate <IRetroArchInput>(mapcol);

            x[ControllerElement.ButtonA] = ControllerElement.DirectionalS;
            Assert.Equal(ControllerElement.DirectionalS, x.Template.Configuration.InputPlayerABtn);
        }
Exemple #8
0
        public void DefaultMappedElementCollection_Test()
        {
            var testmappings = new StoneProvider().Controllers.First().Value;
            var realmapping  =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
            var mapcol = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);

            foreach (var controllerElem in from elem in mapcol
                     where elem.DeviceElement != ControllerElement.NoElement
                     select elem.DeviceElement)
            {
                Assert.NotNull(realmapping.Layout[controllerElem]);
            }
        }
Exemple #9
0
        public void GetProfileNames_Test()
        {
            var stoneProvider = new StoneProvider();
            var testmappings  = stoneProvider.Controllers.First().Value;
            var realmapping   =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
            var mapcol = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);

            var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();

            optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");
            var elementStore = new ControllerElementMappingsStore(optionsBuilder);

            elementStore.AddMappings(mapcol, "default");
        }
Exemple #10
0
        public void InputTemplateGetterSetter_Test()
        {
            var realLayout =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.keyboard_device.json"));

            var targetLayout =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.xinput_device.json"));

            var            mapcol   = ControllerElementMappings.GetDefaultMappings(realLayout, targetLayout);
            IInputTemplate template = new InputTemplate <IRetroArchInput>(mapcol, 0);

            Assert.Equal(ControllerElement.KeyZ, template[ControllerElement.ButtonA]);
            template[ControllerElement.ButtonA] = ControllerElement.KeyX;
            Assert.Equal(ControllerElement.KeyX, template[ControllerElement.ButtonA]);
        }
Exemple #11
0
        public void IniSerialize_Test()
        {
            var           serializer   = new IniConfigurationSerializer(new BooleanMapping("true", "false"), "nul");
            string        _mapping     = TestUtilities.GetStringResource("InputMappings.DirectInput.XINPUT_DEVICE.json");
            IInputMapping mapping      = JsonConvert.DeserializeObject <InputMapping>(_mapping);
            var           testmappings = new StoneProvider().Controllers.First().Value;
            var           realmapping  =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
            var    mapcol          = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);
            var    template        = new InputTemplate <IRetroArchInput>(mapcol, 0);
            string serializedValue = new InputSerializer(serializer).Serialize(template, mapping)
                                     .Replace(Environment.NewLine, string.Empty);

            Assert.Equal(
                TestUtilities.GetStringResource("Configurations.ExampleInput.ini")
                .Replace(Environment.NewLine, string.Empty),
                serializedValue);
        }
Exemple #12
0
        public void InputTemplateToAbstractConfigurationNode_Test()
        {
            var testmappings = new StoneProvider().Controllers["XBOX_CONTROLLER"];
            var realmapping  =
                JsonConvert.DeserializeObject <ControllerLayout>(
                    TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
            var           mapcol   = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);
            string        _mapping = TestUtilities.GetStringResource("InputMappings.DirectInput.XINPUT_DEVICE.json");
            IInputMapping mapping  = JsonConvert.DeserializeObject <InputMapping>(_mapping);
            var           input    =
                new InputTemplate <IRetroArchInput>(mapcol).Template;

            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var context = new ConfigurationTraversalContext(("game", dir));
            var node    = context.TraverseInputTemplate(input, mapping, 0);
        }
Exemple #13
0
        public void UpdateMappedInputCollectionGamepad_Test()
        {
            var stoneProvider = new StoneProvider();

            foreach (var testmappings in stoneProvider.Controllers.Values)
            {
                var realmapping =
                    JsonConvert.DeserializeObject <ControllerLayout>(
                        TestUtilities.GetStringResource("InputMappings.xinput_device.json"));
                var mapcol = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings);

                var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>();
                optionsBuilder.UseSqlite($"Data Source={Path.GetTempFileName()}");

                var elementStore = new ControllerElementMappingsStore(optionsBuilder);

                elementStore.AddMappings(mapcol, "default");

                // map buttonA to buttonB.
                mapcol[ControllerElement.ButtonA] = ControllerElement.ButtonB;

                elementStore.UpdateMappings(mapcol, "default");
                var retStore = elementStore.GetMappings(mapcol.ControllerId, mapcol.DeviceId, "default");

                foreach (var element in retStore)
                {
                    Assert.Contains(element.LayoutElement, mapcol.Select(x => x.LayoutElement));
                    Assert.Equal(element.DeviceElement,
                                 mapcol.First(x => x.LayoutElement == element.LayoutElement).DeviceElement);
                }

                // Switch left joycon has no A button
                if (testmappings.Layout[ControllerElement.ButtonA] != null)
                {
                    Assert.Equal(ControllerElement.ButtonB, retStore[ControllerElement.ButtonA]);
                }
            }
        }