Skip to content

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Donkie committed Dec 24, 2019
1 parent 66d188c commit 4ac030a
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 6 deletions.
14 changes: 14 additions & 0 deletions I3DShapesTool.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.26730.10
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "I3DShapesTool", "I3DShapesTool\I3DShapesTool.csproj", "{0E254DD0-B7E2-4009-A460-ED817130AAFD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "I3DShapesToolTest", "I3DShapesToolTest\I3DShapesToolTest.csproj", "{9DFD6611-B506-4F53-961E-912DCE4EFD9E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,18 @@ Global
{0E254DD0-B7E2-4009-A460-ED817130AAFD}.Release|x64.Build.0 = Release|x64
{0E254DD0-B7E2-4009-A460-ED817130AAFD}.Release|x86.ActiveCfg = Release|x86
{0E254DD0-B7E2-4009-A460-ED817130AAFD}.Release|x86.Build.0 = Release|x86
{9DFD6611-B506-4F53-961E-912DCE4EFD9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9DFD6611-B506-4F53-961E-912DCE4EFD9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9DFD6611-B506-4F53-961E-912DCE4EFD9E}.Debug|x64.ActiveCfg = Debug|Any CPU
{9DFD6611-B506-4F53-961E-912DCE4EFD9E}.Debug|x64.Build.0 = Debug|Any CPU
{9DFD6611-B506-4F53-961E-912DCE4EFD9E}.Debug|x86.ActiveCfg = Debug|Any CPU
{9DFD6611-B506-4F53-961E-912DCE4EFD9E}.Debug|x86.Build.0 = Debug|Any CPU
{9DFD6611-B506-4F53-961E-912DCE4EFD9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9DFD6611-B506-4F53-961E-912DCE4EFD9E}.Release|Any CPU.Build.0 = Release|Any CPU
{9DFD6611-B506-4F53-961E-912DCE4EFD9E}.Release|x64.ActiveCfg = Release|Any CPU
{9DFD6611-B506-4F53-961E-912DCE4EFD9E}.Release|x64.Build.0 = Release|Any CPU
{9DFD6611-B506-4F53-961E-912DCE4EFD9E}.Release|x86.ActiveCfg = Release|Any CPU
{9DFD6611-B506-4F53-961E-912DCE4EFD9E}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion I3DShapesTool/I3DShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace I3DShapesTool
{
class I3DShape
public class I3DShape
{
public int Type { get; }

Expand Down
2 changes: 1 addition & 1 deletion I3DShapesTool/I3DShapesFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace I3DShapesTool
{
class I3DShapesFile
public class I3DShapesFile
{
public string FilePath { get; private set; }
public string FileName => Path.GetFileName(FilePath);
Expand Down
2 changes: 1 addition & 1 deletion I3DShapesTool/I3DTri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace I3DShapesTool
{
class I3DTri
public class I3DTri
{
public ushort P1Idx { get; set; }
public ushort P2Idx { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion I3DShapesTool/I3DUV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace I3DShapesTool
{
class I3DUV
public class I3DUV
{
public float U { get; }
public float V { get; }
Expand Down
2 changes: 1 addition & 1 deletion I3DShapesTool/I3DVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace I3DShapesTool
{
class I3DVector
public class I3DVector
{
public float X { get; set; }
public float Y { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion I3DShapesTool/WavefrontObj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace I3DShapesTool
{
class WavefrontObj
public class WavefrontObj
{
public string Name { get; set; }

Expand Down
75 changes: 75 additions & 0 deletions I3DShapesToolTest/I3DShapesToolTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9DFD6611-B506-4F53-961E-912DCE4EFD9E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>I3DShapesToolTest</RootNamespace>
<AssemblyName>I3DShapesToolTest</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="SteamHelper.cs" />
<Compile Include="UnitTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\I3DShapesTool\I3DShapesTool.csproj">
<Project>{0e254dd0-b7e2-4009-a460-ed817130aafd}</Project>
<Name>I3DShapesTool</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
</Project>
20 changes: 20 additions & 0 deletions I3DShapesToolTest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("I3DShapesToolTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("I3DShapesToolTest")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]

[assembly: Guid("9dfd6611-b506-4f53-961e-912dce4efd9e")]

// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
88 changes: 88 additions & 0 deletions I3DShapesToolTest/SteamHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Win32;

namespace I3DShapesToolTest
{
class SteamHelper
{
private static List<string> steamGameDirs;

public static void LoadSteamGameDirectories()
{
steamGameDirs = new List<string>();
const string steam32 = "SOFTWARE\\VALVE\\";
const string steam64 = "SOFTWARE\\Wow6432Node\\Valve\\";
var key32 = Registry.LocalMachine.OpenSubKey(steam32);
var key64 = Registry.LocalMachine.OpenSubKey(steam64);
if (key64?.ToString() == null || key64.ToString() == "")
{
foreach (var k32SubKey in key32.GetSubKeyNames())
{
using (var subKey = key32.OpenSubKey(k32SubKey))
{
var steam32Path = subKey?.GetValue("InstallPath").ToString();
var config32Path = $"{steam32Path}/steamapps/libraryfolders.vdf";
const string driveRegex = @"[A-Z]:\\";
if (!File.Exists(config32Path)) continue;
var configLines = File.ReadAllLines(config32Path);
foreach (var item in configLines)
{
//Console.WriteLine($"32: {item}");
var match = Regex.Match(item, driveRegex);
if (item == string.Empty || !match.Success) continue;
var matched = match.ToString();
var item2 = item.Substring(item.IndexOf(matched, StringComparison.Ordinal));
item2 = item2.Replace("\\\\", "\\");
item2 = item2.Replace("\"", "\\steamapps\\common\\");
steamGameDirs.Add(item2);
}
steamGameDirs.Add($"{steam32Path}\\steamapps\\common\\");
}
}
}
foreach (var k64SubKey in key64.GetSubKeyNames())
{
using (var subKey = key64.OpenSubKey(k64SubKey))
{
var steam64Path = subKey?.GetValue("InstallPath").ToString();
var config64Path = $"{steam64Path}/steamapps/libraryfolders.vdf";
const string driveRegex = @"[A-Z]:\\";
if (!File.Exists(config64Path)) continue;
var configLines = File.ReadAllLines(config64Path);
foreach (var item in configLines)
{
//Console.WriteLine($"64: {item}");
var match = Regex.Match(item, driveRegex);
if (item == string.Empty || !match.Success) continue;
var matched = match.ToString();
var item2 = item.Substring(item.IndexOf(matched, StringComparison.Ordinal));
item2 = item2.Replace("\\\\", "\\");
item2 = item2.Replace("\"", "\\steamapps\\common\\");
steamGameDirs.Add(item2);
}
steamGameDirs.Add($"{steam64Path}\\steamapps\\common\\");
}
}
}

public static string GetGameDirectory(string gameFolderName)
{
foreach (var steamGameDir in steamGameDirs)
{
if (Directory.Exists(Path.Combine(steamGameDir, gameFolderName)))
return Path.Combine(steamGameDir, gameFolderName);
}

Assert.Inconclusive($"{gameFolderName} not found installed.");

return null;
}
}
}
78 changes: 78 additions & 0 deletions I3DShapesToolTest/UnitTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using I3DShapesTool;

namespace I3DShapesToolTest
{
[TestClass]
public class UnitTest
{
[TestInitialize]
public void TestInit()
{
SteamHelper.LoadSteamGameDirectories();
}

private static void AssertShapesFile(I3DShapesFile file, int seed, int version, int shapeCount)
{
Assert.AreEqual(seed, file.Seed, "Unexpected seed");
Assert.AreEqual(version, file.Version, "Unexpected version");
Assert.AreEqual(shapeCount, file.ShapeCount, "Unexpected shape count");
}

private static void AssertShape(I3DShape shape, string name, uint shapeId, int vertexCount, int faceCount)
{
Assert.AreEqual(name, shape.Name);
Assert.AreEqual(shapeId, shape.ShapeId);
Assert.AreEqual(vertexCount, shape.Positions.Length);
Assert.AreEqual(vertexCount, shape.Normals.Length);
Assert.AreEqual(vertexCount, shape.UVs.Length);
Assert.AreEqual(faceCount, shape.Triangles.Length);
}

[TestMethod]
public void TestFS19_1()
{
var gameFolder = SteamHelper.GetGameDirectory("Farming Simulator 19");

var file = new I3DShapesFile();
file.Load(Path.Combine(gameFolder, @"data\vehicles\magsi\telehandlerBaleFork\telehandlerBaleFork.i3d.shapes"));
AssertShapesFile(file, 201, 5, 9);
AssertShape(file.Shapes[0], "colPartBackShape1", 4, 24, 12);
}

[TestMethod]
public void TestFS17_1()
{
var gameFolder = SteamHelper.GetGameDirectory("Farming Simulator 17");

var file = new I3DShapesFile();
file.Load(Path.Combine(gameFolder, @"data\vehicles\tools\magsi\wheelLoaderLogFork.i3d.shapes"));
AssertShapesFile(file, 49, 5, 12);
AssertShape(file.Shapes[0], "wheelLoaderLogForkShape", 1, 24, 12);
}

[TestMethod]
public void TestFS15_1()
{
var gameFolder = SteamHelper.GetGameDirectory("Farming Simulator 15");

var file = new I3DShapesFile();
file.Load(Path.Combine(gameFolder, @"data\vehicles\tools\grimme\grimmeFT300.i3d.shapes"));
AssertShapesFile(file, 188, 3, 16);
AssertShape(file.Shapes[0], "grimmeFTShape300", 1, 40, 20);
}

[TestMethod]
public void TestFS13_1()
{
var gameFolder = SteamHelper.GetGameDirectory("Farming Simulator 2013");

var file = new I3DShapesFile();
file.Load(Path.Combine(gameFolder, @"data\vehicles\tools\kuhn\kuhnGA4521GM.i3d.shapes"));
AssertShapesFile(file, 68, 2, 32);
AssertShape(file.Shapes[0], "blanketBarShape2", 26, 68, 44);
}
}
}
5 changes: 5 additions & 0 deletions I3DShapesToolTest/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net461" />
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net461" />
</packages>

0 comments on commit 4ac030a

Please sign in to comment.