Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
Added test to check output XML string after profile migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryochan7 committed Dec 21, 2023
1 parent 4d3b3eb commit 35b3c03
Showing 1 changed file with 313 additions and 2 deletions.
315 changes: 313 additions & 2 deletions DS4WindowsTests/ProfileMigrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ You should have received a copy of the GNU General Public License
*/


using System.Text;
using System.Xml;
using System.Xml.Serialization;
using DS4Windows;
using DS4WinWPF.DS4Control.DTOXml;
using System.Xml.Serialization;

namespace DS4WindowsTests
{
Expand All @@ -28,12 +30,12 @@ public class ProfileMigrationTests
{
private const int EXPECTED_JAYS_MIGRATED_VERSION = 5;
private string ds4winJays2KingsOldProfile = string.Empty;
private string ds4winJays2KingsExpectedMigratedProfile = string.Empty;

public ProfileMigrationTests()
{
#region TempDS4WinProfileXML
ds4winJays2KingsOldProfile = @"<?xml version=""1.0"" encoding=""utf-8""?>
<!-- DS4Windows Configuration Data. 12/6/2023 4:31:21 PM -->
<DS4Windows>
<flushHIDQueue>True</flushHIDQueue>
Expand Down Expand Up @@ -79,6 +81,271 @@ public ProfileMigrationTests()
<Control />
<ShiftControl />
</DS4Windows>";

ds4winJays2KingsExpectedMigratedProfile = @"<?xml version=""1.0"" encoding=""utf-8""?>
<DS4Windows>
<touchToggle>True</touchToggle>
<idleDisconnectTimeout>0</idleDisconnectTimeout>
<outputDataToDS4>True</outputDataToDS4>
<Color>0,0,255</Color>
<RumbleBoost>100</RumbleBoost>
<RumbleAutostopTime>0</RumbleAutostopTime>
<LightbarMode>None</LightbarMode>
<ledAsBatteryIndicator>False</ledAsBatteryIndicator>
<FlashType>0</FlashType>
<flashBatteryAt>0</flashBatteryAt>
<touchSensitivity>100</touchSensitivity>
<LowColor>0,0,0</LowColor>
<ChargingColor>0,0,0</ChargingColor>
<FlashColor>0,0,0</FlashColor>
<touchpadJitterCompensation>True</touchpadJitterCompensation>
<lowerRCOn>False</lowerRCOn>
<tapSensitivity>0</tapSensitivity>
<doubleTap>False</doubleTap>
<scrollSensitivity>0</scrollSensitivity>
<LeftTriggerMiddle>0</LeftTriggerMiddle>
<RightTriggerMiddle>0</RightTriggerMiddle>
<TouchpadInvert>0</TouchpadInvert>
<TouchpadClickPassthru>False</TouchpadClickPassthru>
<L2AntiDeadZone>0</L2AntiDeadZone>
<R2AntiDeadZone>0</R2AntiDeadZone>
<L2MaxZone>0</L2MaxZone>
<R2MaxZone>0</R2MaxZone>
<L2MaxOutput>0</L2MaxOutput>
<R2MaxOutput>0</R2MaxOutput>
<ButtonMouseSensitivity>25</ButtonMouseSensitivity>
<ButtonMouseOffset>0</ButtonMouseOffset>
<Rainbow>0</Rainbow>
<MaxSatRainbow>0</MaxSatRainbow>
<LSDeadZone>10</LSDeadZone>
<RSDeadZone>10</RSDeadZone>
<LSAntiDeadZone>20</LSAntiDeadZone>
<RSAntiDeadZone>20</RSAntiDeadZone>
<LSMaxZone>100</LSMaxZone>
<RSMaxZone>100</RSMaxZone>
<LSVerticalScale>100</LSVerticalScale>
<RSVerticalScale>100</RSVerticalScale>
<LSMaxOutput>100</LSMaxOutput>
<RSMaxOutput>100</RSMaxOutput>
<LSMaxOutputForce>False</LSMaxOutputForce>
<RSMaxOutputForce>False</RSMaxOutputForce>
<LSDeadZoneType>Radial</LSDeadZoneType>
<RSDeadZoneType>Radial</RSDeadZoneType>
<LSAxialDeadOptions>
<DeadZoneX>0</DeadZoneX>
<DeadZoneY>0</DeadZoneY>
<MaxZoneX>0</MaxZoneX>
<MaxZoneY>0</MaxZoneY>
<AntiDeadZoneX>0</AntiDeadZoneX>
<AntiDeadZoneY>0</AntiDeadZoneY>
<MaxOutputX>0</MaxOutputX>
<MaxOutputY>0</MaxOutputY>
</LSAxialDeadOptions>
<RSAxialDeadOptions>
<DeadZoneX>0</DeadZoneX>
<DeadZoneY>0</DeadZoneY>
<MaxZoneX>0</MaxZoneX>
<MaxZoneY>0</MaxZoneY>
<AntiDeadZoneX>0</AntiDeadZoneX>
<AntiDeadZoneY>0</AntiDeadZoneY>
<MaxOutputX>0</MaxOutputX>
<MaxOutputY>0</MaxOutputY>
</RSAxialDeadOptions>
<LSRotation>0</LSRotation>
<RSRotation>0</RSRotation>
<LSFuzz>0</LSFuzz>
<RSFuzz>0</RSFuzz>
<LSOuterBindDead>75</LSOuterBindDead>
<RSOuterBindDead>75</RSOuterBindDead>
<LSOuterBindInvert>False</LSOuterBindInvert>
<RSOuterBindInvert>False</RSOuterBindInvert>
<LSDeltaAccelSettings>
<Enabled>False</Enabled>
<Multiplier>4</Multiplier>
<MaxTravel>0.2</MaxTravel>
<MinTravel>0.01</MinTravel>
<EasingDuration>0.2</EasingDuration>
<MinFactor>1</MinFactor>
</LSDeltaAccelSettings>
<RSDeltaAccelSettings>
<Enabled>False</Enabled>
<Multiplier>4</Multiplier>
<MaxTravel>0.2</MaxTravel>
<MinTravel>0.01</MinTravel>
<EasingDuration>0.2</EasingDuration>
<MinFactor>1</MinFactor>
</RSDeltaAccelSettings>
<SXDeadZone>0.25</SXDeadZone>
<SZDeadZone>0.25</SZDeadZone>
<SXMaxZone>100</SXMaxZone>
<SZMaxZone>100</SZMaxZone>
<SXAntiDeadZone>0</SXAntiDeadZone>
<SZAntiDeadZone>0</SZAntiDeadZone>
<Sensitivity>1|1|1|1|1|1</Sensitivity>
<ChargingType>0</ChargingType>
<MouseAcceleration>True</MouseAcceleration>
<ButtonMouseVerticalScale>0</ButtonMouseVerticalScale>
<LaunchProgram />
<DinputOnly>False</DinputOnly>
<StartTouchpadOff>False</StartTouchpadOff>
<TouchpadOutputMode>None</TouchpadOutputMode>
<SATriggers />
<SATriggerCond>and</SATriggerCond>
<SASteeringWheelEmulationAxis>None</SASteeringWheelEmulationAxis>
<SASteeringWheelEmulationRange>360</SASteeringWheelEmulationRange>
<SASteeringWheelFuzz>0</SASteeringWheelFuzz>
<SASteeringWheelSmoothingOptions>
<SASteeringWheelUseSmoothing>False</SASteeringWheelUseSmoothing>
<SASteeringWheelSmoothMinCutoff>0.1</SASteeringWheelSmoothMinCutoff>
<SASteeringWheelSmoothBeta>0.1</SASteeringWheelSmoothBeta>
</SASteeringWheelSmoothingOptions>
<TouchDisInvTriggers>-1</TouchDisInvTriggers>
<GyroSensitivity>100</GyroSensitivity>
<GyroSensVerticalScale>100</GyroSensVerticalScale>
<GyroInvert>0</GyroInvert>
<GyroTriggerTurns>False</GyroTriggerTurns>
<GyroControlsSettings>
<Triggers>-1</Triggers>
<TriggerCond>and</TriggerCond>
<TriggerTurns>True</TriggerTurns>
<Toggle>False</Toggle>
</GyroControlsSettings>
<GyroMouseSmoothingSettings>
<UseSmoothing>False</UseSmoothing>
<SmoothingMethod>one-euro</SmoothingMethod>
<SmoothingWeight>50</SmoothingWeight>
<SmoothingMinCutoff>0.4</SmoothingMinCutoff>
<SmoothingBeta>0.7</SmoothingBeta>
</GyroMouseSmoothingSettings>
<GyroMouseHAxis>0</GyroMouseHAxis>
<GyroMouseDeadZone>10</GyroMouseDeadZone>
<GyroMouseMinThreshold>1</GyroMouseMinThreshold>
<GyroMouseToggle>False</GyroMouseToggle>
<GyroMouseJitterCompensation>True</GyroMouseJitterCompensation>
<GyroOutputMode>Controls</GyroOutputMode>
<GyroMouseStickTriggers>-1</GyroMouseStickTriggers>
<GyroMouseStickTriggerCond>and</GyroMouseStickTriggerCond>
<GyroMouseStickTriggerTurns>True</GyroMouseStickTriggerTurns>
<GyroMouseStickHAxis>0</GyroMouseStickHAxis>
<GyroMouseStickDeadZone>30</GyroMouseStickDeadZone>
<GyroMouseStickMaxZone>830</GyroMouseStickMaxZone>
<GyroMouseStickOutputStick>None</GyroMouseStickOutputStick>
<GyroMouseStickOutputStickAxes>None</GyroMouseStickOutputStickAxes>
<GyroMouseStickAntiDeadX>0.4</GyroMouseStickAntiDeadX>
<GyroMouseStickAntiDeadY>0.4</GyroMouseStickAntiDeadY>
<GyroMouseStickInvert>0</GyroMouseStickInvert>
<GyroMouseStickToggle>False</GyroMouseStickToggle>
<GyroMouseStickMaxOutput>100</GyroMouseStickMaxOutput>
<GyroMouseStickMaxOutputEnabled>False</GyroMouseStickMaxOutputEnabled>
<GyroMouseStickVerticalScale>100</GyroMouseStickVerticalScale>
<GyroMouseStickJitterCompensation>False</GyroMouseStickJitterCompensation>
<GyroMouseStickSmoothingSettings>
<UseSmoothing>False</UseSmoothing>
<SmoothingMethod>one-euro</SmoothingMethod>
<SmoothingWeight>50</SmoothingWeight>
<SmoothingMinCutoff>0.4</SmoothingMinCutoff>
<SmoothingBeta>0.7</SmoothingBeta>
</GyroMouseStickSmoothingSettings>
<GyroSwipeSettings>
<DeadZoneX>80</DeadZoneX>
<DeadZoneY>80</DeadZoneY>
<Triggers>-1</Triggers>
<TriggerCond>and</TriggerCond>
<TriggerTurns>True</TriggerTurns>
<XAxis>Yaw</XAxis>
<DelayTime>0</DelayTime>
</GyroSwipeSettings>
<BTPollRate>4</BTPollRate>
<LSOutputCurveMode>linear</LSOutputCurveMode>
<RSOutputCurveMode>linear</RSOutputCurveMode>
<LSSquareStick>False</LSSquareStick>
<RSSquareStick>False</RSSquareStick>
<SquareStickRoundness>5</SquareStickRoundness>
<SquareRStickRoundness>5</SquareRStickRoundness>
<LSAntiSnapback>False</LSAntiSnapback>
<RSAntiSnapback>False</RSAntiSnapback>
<LSAntiSnapbackDelta>135</LSAntiSnapbackDelta>
<RSAntiSnapbackDelta>135</RSAntiSnapbackDelta>
<LSAntiSnapbackTimeout>50</LSAntiSnapbackTimeout>
<RSAntiSnapbackTimeout>50</RSAntiSnapbackTimeout>
<LSOutputMode>Controls</LSOutputMode>
<RSOutputMode>Controls</RSOutputMode>
<LSOutputSettings>
<FlickStickSettings>
<RealWorldCalibration>0</RealWorldCalibration>
<FlickThreshold>0</FlickThreshold>
<FlickTime>0</FlickTime>
<MinAngleThreshold>0</MinAngleThreshold>
</FlickStickSettings>
</LSOutputSettings>
<RSOutputSettings>
<FlickStickSettings>
<RealWorldCalibration>0</RealWorldCalibration>
<FlickThreshold>0</FlickThreshold>
<FlickTime>0</FlickTime>
<MinAngleThreshold>0</MinAngleThreshold>
</FlickStickSettings>
</RSOutputSettings>
<DualSenseControllerSettings>
<RumbleSettings>
<EmulationMode>Accurate</EmulationMode>
<EnableGenericRumbleRescale>False</EnableGenericRumbleRescale>
<HapticPowerLevel>0</HapticPowerLevel>
</RumbleSettings>
</DualSenseControllerSettings>
<L2OutputCurveMode>linear</L2OutputCurveMode>
<L2TwoStageMode>Disabled</L2TwoStageMode>
<R2TwoStageMode>Disabled</R2TwoStageMode>
<L2HipFireTime>0</L2HipFireTime>
<R2HipFireTime>0</R2HipFireTime>
<L2TriggerEffect>None</L2TriggerEffect>
<R2TriggerEffect>None</R2TriggerEffect>
<R2OutputCurveMode>linear</R2OutputCurveMode>
<SXOutputCurveMode>linear</SXOutputCurveMode>
<SZOutputCurveMode>linear</SZOutputCurveMode>
<TrackballMode>False</TrackballMode>
<TrackballFriction>10</TrackballFriction>
<TouchRelMouseRotation>0</TouchRelMouseRotation>
<TouchRelMouseMinThreshold>1</TouchRelMouseMinThreshold>
<TouchpadAbsMouseSettings>
<MaxZoneX>90</MaxZoneX>
<MaxZoneY>90</MaxZoneY>
<SnapToCenter>False</SnapToCenter>
</TouchpadAbsMouseSettings>
<TouchpadMouseStick>
<DeadZone>0</DeadZone>
<MaxZone>8</MaxZone>
<OutputStick>RightStick</OutputStick>
<OutputStickAxes>XY</OutputStickAxes>
<AntiDeadX>0.4</AntiDeadX>
<AntiDeadY>0.4</AntiDeadY>
<Invert>0</Invert>
<MaxOutput>100</MaxOutput>
<MaxOutputEnabled>False</MaxOutputEnabled>
<VerticalScale>100</VerticalScale>
<OutputCurve>Linear</OutputCurve>
<Rotation>0</Rotation>
<SmoothingSettings>
<SmoothingMethod>None</SmoothingMethod>
<SmoothingMinCutoff>0.8</SmoothingMinCutoff>
<SmoothingBeta>0.7</SmoothingBeta>
</SmoothingSettings>
</TouchpadMouseStick>
<TouchpadButtonMode>Click</TouchpadButtonMode>
<AbsMouseRegionSettings>
<AbsWidth>1</AbsWidth>
<AbsHeight>1</AbsHeight>
<AbsXCenter>0.5</AbsXCenter>
<AbsYCenter>0.5</AbsYCenter>
<AntiRadius>0</AntiRadius>
<SnapToCenter>True</SnapToCenter>
</AbsMouseRegionSettings>
<OutputContDevice>X360</OutputContDevice>
<ProfileActions>Disconnect Controller</ProfileActions>
<Control />
<ShiftControl />
</DS4Windows>";
#endregion
}

Expand Down Expand Up @@ -134,6 +401,50 @@ public void CheckJaysProfileRead()
DS4Color profileColor = tempStore.lightbarSettingInfo[0].ds4winSettings.m_Led;
Assert.AreEqual("0,0,255",
$"{profileColor.red},{profileColor.green},{profileColor.blue}");

// Check that profile migration worked as expected
string testMigratedProfileStr = ObtainConvertedJaysXML(tempStore);
Assert.AreEqual(ds4winJays2KingsExpectedMigratedProfile, testMigratedProfileStr);
}

private string ObtainConvertedJaysXML(BackingStore tempStore)
{
string testStr = string.Empty;
XmlSerializer serializer = new XmlSerializer(typeof(ProfileDTO),
ProfileDTO.GetAttributeOverrides());
using (Utf8StringWriter strWriter = new Utf8StringWriter())
{
using XmlWriter xmlWriter = XmlWriter.Create(strWriter,
new XmlWriterSettings()
{
Encoding = Encoding.UTF8,
Indent = true,
});

// Write header explicitly
//xmlWriter.WriteStartDocument();
//xmlWriter.WriteComment(string.Format(" DS4Windows Configuration Data. {0} ", DateTime.Now));
//xmlWriter.WriteComment(string.Format(" Made with DS4Windows version {0} ", Global.exeversion));
xmlWriter.WriteWhitespace("\r\n");
xmlWriter.WriteWhitespace("\r\n");

// Write root element and children
ProfileDTO dto = new ProfileDTO();
dto.DeviceIndex = 0; // Use default slot
dto.SerializeAppAttrs = false;
dto.MapFrom(tempStore);
// Omit xmlns:xsi and xmlns:xsd from output
serializer.Serialize(xmlWriter, dto,
new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty }));
xmlWriter.Flush();
xmlWriter.Close();

testStr = strWriter.ToString();
//Trace.WriteLine("TEST OUTPUT");
//Trace.WriteLine(testStr);
}

return testStr;
}
}
}

0 comments on commit 35b3c03

Please sign in to comment.