diff --git a/QSB.sln b/QSB.sln index e09c90a2..d26bfbf2 100644 --- a/QSB.sln +++ b/QSB.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QSB", "QSB\QSB.csproj", "{1F00090A-C697-4C55-B401-192F3CFB9DC2}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QSBTests", "QSBTests\QSBTests.csproj", "{2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2569F98D-F671-42AA-82DE-505B05CDCEF2}" ProjectSection(SolutionItems) = preProject .gitignore = .gitignore @@ -32,10 +30,6 @@ Global {1F00090A-C697-4C55-B401-192F3CFB9DC2}.Debug|Any CPU.Build.0 = Debug|Any CPU {1F00090A-C697-4C55-B401-192F3CFB9DC2}.Release|Any CPU.ActiveCfg = Release|Any CPU {1F00090A-C697-4C55-B401-192F3CFB9DC2}.Release|Any CPU.Build.0 = Release|Any CPU - {2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3}.Release|Any CPU.Build.0 = Release|Any CPU {DA8A467E-15BA-456C-9034-6EB80BAF1FF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DA8A467E-15BA-456C-9034-6EB80BAF1FF9}.Debug|Any CPU.Build.0 = Debug|Any CPU {DA8A467E-15BA-456C-9034-6EB80BAF1FF9}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/QSBTests/MessageTests.cs b/QSBTests/MessageTests.cs deleted file mode 100644 index e3aa5175..00000000 --- a/QSBTests/MessageTests.cs +++ /dev/null @@ -1,94 +0,0 @@ -using HarmonyLib; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Mono.Cecil; -using Mono.Cecil.Cil; -using Mono.Cecil.Rocks; -using MonoMod.Cil; -using MonoMod.Utils; -using QSB.Messaging; -using QSB.Utility; -using System; -using System.Linq; -using System.Reflection; - -namespace QSBTests -{ - [TestClass] - public class MessageTests - { - [TestMethod] - public void TestMessages() - { - var module = ModuleDefinition.ReadModule("QSB.dll"); - var messageTypes = typeof(QSBMessage).GetDerivedTypes(); - - var fromField = typeof(QSBMessage).GetField("From", Util.AllInstance); - var toField = typeof(QSBMessage).GetField("To", Util.AllInstance); - var objectIdField = typeof(QSBWorldObjectMessage<>).GetField("ObjectId", Util.AllInstance); - - foreach (var type in messageTypes) - { - var fields = type.GetFields(Util.AllInstance) - .Select(x => module.ImportReference(x).Resolve()); - - var constructor = module.ImportReference(type.GetConstructors(Util.AllInstance).Single()).Resolve(); - var serialize = module.ImportReference(type.GetMethod("Serialize", Util.AllInstance)).Resolve(); - var deserialize = module.ImportReference(type.GetMethod("Deserialize", Util.AllInstance)).Resolve(); - - foreach (var field in fields) - { - if (!field.Is(fromField) && !field.Is(toField) && !field.Is(objectIdField)) - { - constructor.CheckUses(field, Util.UseType.Store); - } - - serialize.CheckUses(field, Util.UseType.Load); - deserialize.CheckUses(field, Util.UseType.Store); - } - } - } - } - - public static class Util - { - public static readonly BindingFlags AllInstance = AccessTools.all ^ BindingFlags.Static; - - public enum UseType { Store, Load } - - public static void CheckUses(this MethodDefinition method, FieldDefinition field, UseType useType) - { - Func matches = useType switch - { - UseType.Store => x => x.MatchStfld(out var f) && f.Resolve() == field, - UseType.Load => i => (i.MatchLdfld(out var f) || i.MatchLdflda(out f)) && f.Resolve() == field, - _ => throw new ArgumentOutOfRangeException(nameof(useType), useType, null) - }; - - while (true) - { - var instructions = method.Body.Instructions; - var uses = instructions.Any(matches); - if (uses) - { - return; - } - - var baseMethod = method.GetBaseMethod(); - if (baseMethod == method) - { - break; - } - - var callsBase = instructions.Any(x => x.MatchCall(out var m) && m.Resolve() == baseMethod); - if (!callsBase) - { - break; - } - - method = baseMethod; - } - - Assert.Fail($"{method} does not {useType} {field}"); - } - } -} diff --git a/QSBTests/QSBTests.csproj b/QSBTests/QSBTests.csproj deleted file mode 100644 index ed742ecd..00000000 --- a/QSBTests/QSBTests.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - QSBTests - QSBTests - {2FE8256C-0CB6-48F1-A4C0-5FA18A1846A3} - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - - - - - - - - - \ No newline at end of file