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

Commit

Permalink
Added initial unit test project to solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryochan7 committed Dec 5, 2023
1 parent 376f9f5 commit e3eb73d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
24 changes: 24 additions & 0 deletions DS4WindowsTests/DS4WindowsTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<Platforms>AnyCPU;x64;x86</Platforms>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.4" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DS4Windows\DS4WinWPF.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions DS4WindowsTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;
64 changes: 64 additions & 0 deletions DS4WindowsTests/MacroParserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using DS4Windows;

namespace DS4WindowsTests
{
[TestClass]
public class MacroParserTests
{
private int[] testMacro = new int[]
{
87, // W key down
330, // Wait period 30 ms
1090220220, // Change lightbar (90, 220, 220)
83, // S key down
330, // Wait period 30 ms
1000000000, // Reset lightbar
83, // S key up
330, // Wait period 30 ms
87, // W key up
};

private MacroParser parser;

public MacroParserTests()
{
Setup();
}

private void Setup()
{
parser = new MacroParser(testMacro);
parser.LoadMacro();
}

[TestMethod]
public void CheckNumberSteps()
{
List<MacroStep> steps = parser.MacroSteps;
// Make sure parser interpreted all steps
Assert.AreEqual(testMacro.Length, steps.Count);
}

[TestMethod]
public void CheckStepTypes()
{
List<MacroStep> steps = parser.MacroSteps;

int waitStep = 1;
Assert.AreEqual(MacroStep.StepType.Wait, steps[waitStep].ActType);

int changeLightbarStep = 2;
Assert.AreEqual(MacroStep.StepOutput.Lightbar, steps[changeLightbarStep].OutputType);
Assert.AreEqual(MacroStep.StepType.ActDown, steps[changeLightbarStep].ActType);

int resetLightbarStep = 5;
Assert.AreEqual(MacroStep.StepOutput.Lightbar, steps[resetLightbarStep].OutputType);
Assert.AreEqual(MacroStep.StepType.ActUp, steps[resetLightbarStep].ActType);

int lastStep = testMacro.Length - 1;
Assert.AreEqual(MacroStep.StepType.ActUp, steps[lastStep].ActType);

return;
}
}
}
14 changes: 11 additions & 3 deletions DS4WindowsWPF.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29306.81
# Visual Studio Version 17
VisualStudioVersion = 17.8.34322.80
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DS4WinWPF", "DS4Windows\DS4WinWPF.csproj", "{0135A24D-5DBB-483C-9FC5-9A869E23DA9A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DS4WinWPF", "DS4Windows\DS4WinWPF.csproj", "{0135A24D-5DBB-483C-9FC5-9A869E23DA9A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DS4WindowsTests", "DS4WindowsTests\DS4WindowsTests.csproj", "{6BEB9062-56E7-4A0D-9243-BE43F09A711D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -21,6 +23,12 @@ Global
{0135A24D-5DBB-483C-9FC5-9A869E23DA9A}.Release|x64.Build.0 = Release|x64
{0135A24D-5DBB-483C-9FC5-9A869E23DA9A}.Release|x86.ActiveCfg = Release|x86
{0135A24D-5DBB-483C-9FC5-9A869E23DA9A}.Release|x86.Build.0 = Release|x86
{6BEB9062-56E7-4A0D-9243-BE43F09A711D}.Debug|x64.ActiveCfg = Debug|x64
{6BEB9062-56E7-4A0D-9243-BE43F09A711D}.Debug|x64.Build.0 = Debug|x64
{6BEB9062-56E7-4A0D-9243-BE43F09A711D}.Debug|x86.ActiveCfg = Debug|x86
{6BEB9062-56E7-4A0D-9243-BE43F09A711D}.Debug|x86.Build.0 = Debug|x86
{6BEB9062-56E7-4A0D-9243-BE43F09A711D}.Release|x64.ActiveCfg = Release|x64
{6BEB9062-56E7-4A0D-9243-BE43F09A711D}.Release|x86.ActiveCfg = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit e3eb73d

Please sign in to comment.