Quellcode durchsuchen

- Migrate tests into own plugin.

Stephen Damm vor 6 Jahren
Ursprung
Commit
9ae1b32ed3

+ 67 - 0
SongBrowserPluginTest/Plugin.cs

@@ -0,0 +1,67 @@
+using IllusionPlugin;
+using SongBrowserPluginTests;
+using System;
+using UnityEngine.SceneManagement;
+
+namespace SongBrowserPluginTest
+{
+    public class Plugin : IPlugin
+    {
+        public const bool RunTests = true;
+
+        private bool _didRunTests = false;
+
+        public string Name
+        {
+            get { return "Song Browser Plugin Test"; }
+        }
+
+        public string Version
+        {
+            get { return "v1.0-test"; }
+        }
+
+        public void OnApplicationStart()
+        {
+
+        }
+
+        public void OnApplicationQuit()
+        {
+
+        }
+
+        private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
+        {
+
+        }
+
+        private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
+        {
+        }
+
+        public void OnLevelWasLoaded(int level)
+        {
+            if (RunTests && !_didRunTests)
+            {
+                new SongBrowserTestRunner().RunTests();
+                _didRunTests = true;
+            }
+        }
+
+        public void OnLevelWasInitialized(int level)
+        {
+            //Console.WriteLine("OnLevelWasInitialized=" + level);
+        }
+
+        public void OnUpdate()
+        {
+
+        }
+
+        public void OnFixedUpdate()
+        {
+
+        }
+    }
+}

+ 35 - 0
SongBrowserPluginTest/Properties/AssemblyInfo.cs

@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("SongBrowserPluginTest")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("SongBrowserPluginTest")]
+[assembly: AssemblyCopyright("Copyright ©  2018")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("0e98323b-bb8c-44d9-ae42-55222aade6ef")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 108 - 0
SongBrowserPluginTest/SongBrowserPluginTest.csproj

@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <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>{E5465EF3-B227-47BE-B7D1-624E0DAC275D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>SongBrowserPluginTest</RootNamespace>
+    <AssemblyName>SongBrowserPluginTest</AssemblyName>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <LangVersion>6</LangVersion>
+    <TargetFrameworkProfile>
+    </TargetFrameworkProfile>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <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' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
+      <HintPath>D:\Games\Steam\SteamApps\common\Beat Saber\Beat Saber_Data\Managed\Assembly-CSharp.dll</HintPath>
+    </Reference>
+    <Reference Include="IllusionPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
+      <HintPath>D:\Games\Steam\SteamApps\common\Beat Saber\Beat Saber_Data\Managed\IllusionPlugin.dll</HintPath>
+    </Reference>
+    <Reference Include="SongLoaderPlugin">
+      <HintPath>D:\Games\Steam\SteamApps\common\Beat Saber\Plugins\SongLoaderPlugin.dll</HintPath>
+    </Reference>
+    <Reference Include="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+      <HintPath>D:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\System.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+      <HintPath>D:\SteamLibrary\steamapps\common\Beat Saber\Beat Saber_Data\Managed\System.Core.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+    <Reference Include="TextMeshPro-1.0.55.2017.1.0b12, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>D:\Games\Steam\SteamApps\common\Beat Saber\Beat Saber_Data\Managed\TextMeshPro-1.0.55.2017.1.0b12.dll</HintPath>
+    </Reference>
+    <Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
+      <HintPath>D:\Games\Steam\SteamApps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>
+    </Reference>
+    <Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
+      <HintPath>D:\Games\Steam\SteamApps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
+    </Reference>
+    <Reference Include="UnityEngine.JSONSerializeModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
+      <HintPath>D:\Games\Steam\SteamApps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.JSONSerializeModule.dll</HintPath>
+    </Reference>
+    <Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>D:\Games\Steam\SteamApps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UI.dll</HintPath>
+    </Reference>
+    <Reference Include="UnityEngine.UIElementsModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>D:\Games\Steam\SteamApps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UIElementsModule.dll</HintPath>
+    </Reference>
+    <Reference Include="UnityEngine.UIModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>D:\Games\Steam\SteamApps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UIModule.dll</HintPath>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Plugin.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Tests\ISongBrowserTest.cs" />
+    <Compile Include="Tests\SongBrowserModelTests.cs" />
+    <Compile Include="Tests\SongBrowserTestRunner.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Internals\" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="packages.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\SongBrowserPlugin\SongBrowserPlugin.csproj">
+      <Project>{6f9b6801-9f4b-4d1f-805d-271c95733814}</Project>
+      <Name>SongBrowserPlugin</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+         Other similar extension points exist, see Microsoft.Common.targets.
+    <Target Name="BeforeBuild">
+    </Target>
+    <Target Name="AfterBuild">
+    </Target>
+    -->
+</Project>

+ 12 - 0
SongBrowserPluginTest/Tests/ISongBrowserTest.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace SongBrowserPluginTests
+{
+    interface ISongBrowserTest
+    {
+        void RunTest();
+    }
+}

+ 88 - 0
SongBrowserPluginTest/Tests/SongBrowserModelTests.cs

@@ -0,0 +1,88 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using SongBrowserPlugin;
+
+namespace SongBrowserPluginTests
+{
+    class MockBeatSaberSongList : SongBrowserPlugin.DataAccess.IBeatSaberSongList
+    {
+        List<LevelStaticData> testList;
+
+        public MockBeatSaberSongList()
+        {
+            testList = new List<LevelStaticData>();
+            for (int i = 0; i < 10000; i++)
+            {
+                LevelStaticData level = new LevelStaticData();
+                SongBrowserPlugin.ReflectionUtil.SetPrivateField(level, "_songName", "SongName" + i);
+                SongBrowserPlugin.ReflectionUtil.SetPrivateField(level, "_authorName", "AuthorName" + i);
+                SongBrowserPlugin.ReflectionUtil.SetPrivateField(level, "_levelId", "LevelId" + i);
+                testList.Add(level);
+            }
+
+        }
+
+        public List<LevelStaticData> AcquireSongList()
+        {
+            return testList;
+        }
+
+        public void OverwriteBeatSaberSongList(List<LevelStaticData> newSongList)
+        {
+            return;
+        }
+    }
+
+    class SongBrowserModelTests : ISongBrowserTest
+    {
+        private Logger _log = new Logger("SongBrowserModelTests");
+
+        public void RunTest()
+        {
+            _log.Info("SongBrowserModelTests - All tests in Milliseconds");
+
+            Stopwatch stopwatch = Stopwatch.StartNew();
+            SongBrowserModel model = new SongBrowserModel();
+            model.Init(new MockBeatSaberSongList());
+            stopwatch.Stop();
+            _log.Info("Created a bunch of LevelStaticData: {0}", stopwatch.ElapsedMilliseconds);
+
+            stopwatch = Stopwatch.StartNew();
+            model.Settings.sortMode = SongSortMode.Original;
+            model.UpdateSongLists(false);
+            stopwatch.Stop();
+            _log.Info("Song Loading and Sorting as original: {0}", stopwatch.ElapsedMilliseconds);
+
+            stopwatch = Stopwatch.StartNew();
+            model.Settings.sortMode = SongSortMode.Default;
+            model.UpdateSongLists(false);
+            stopwatch.Stop();        
+            _log.Info("Song Loading and Sorting as favorites: {0}", stopwatch.ElapsedMilliseconds);
+
+            stopwatch = Stopwatch.StartNew();
+            model.Settings.sortMode = SongSortMode.Favorites;
+            model.UpdateSongLists(false);
+            stopwatch.Stop();
+            _log.Info("Song Loading and Sorting as favorites: {0}", stopwatch.ElapsedMilliseconds);
+
+            stopwatch = Stopwatch.StartNew();
+            model.Settings.sortMode = SongSortMode.Newest;
+            model.UpdateSongLists(false);
+            stopwatch.Stop();
+            _log.Info("Song Loading and Sorting as newest: {0}", stopwatch.ElapsedMilliseconds);
+
+            stopwatch = Stopwatch.StartNew();
+            for (int i = 0; i < 1; i++)
+            {
+                var m1 = model.SortedSongList.ToArray();
+                var m2 = model.SortedSongList.ToArray();
+                var m3 = model.SortedSongList.ToArray();
+            }
+            stopwatch.Stop();
+            _log.Info("Converting big list into array a bunch of times: {0}", stopwatch.ElapsedMilliseconds);
+        }
+    }
+}

+ 25 - 0
SongBrowserPluginTest/Tests/SongBrowserTestRunner.cs

@@ -0,0 +1,25 @@
+using SongBrowserPlugin;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace SongBrowserPluginTests
+{
+    public class SongBrowserTestRunner
+    {
+        private Logger _log = new Logger("SongBrowserTestRunner");
+
+        public SongBrowserTestRunner()
+        {
+
+        }
+
+        public void RunTests()
+        {
+            _log.Info("Running Song Browser Tests");
+
+            new SongBrowserModelTests().RunTest();
+        }
+    }
+}

+ 4 - 0
SongBrowserPluginTest/packages.config

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  
+</packages>