|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Moq; |
| 7 | +using NFluent; |
| 8 | +using ReClassNET.AddressParser; |
| 9 | +using ReClassNET.Memory; |
| 10 | +using Xunit; |
| 11 | + |
| 12 | +namespace ReClass.NET_Tests.AddressParser |
| 13 | +{ |
| 14 | + public abstract class ExecutorTest |
| 15 | + { |
| 16 | + protected abstract IExecuter CreateExecutor(); |
| 17 | + |
| 18 | + public static IEnumerable<object[]> GetSimpleExpressionTestData() => new List<object[]> |
| 19 | + { |
| 20 | + new object[] { "0", (IntPtr)0x0 }, |
| 21 | + new object[] { "0 + 0", (IntPtr)0x0 }, |
| 22 | + new object[] { "+0", (IntPtr)0x0 }, |
| 23 | + new object[] { "-0", (IntPtr)0x0 }, |
| 24 | + new object[] { "-1", (IntPtr)(-1) }, |
| 25 | + new object[] { "+0 + 0", (IntPtr)0x0 }, |
| 26 | + new object[] { "-0 - 0", (IntPtr)0x0 }, |
| 27 | + new object[] { "0 + 1", (IntPtr)0x1 }, |
| 28 | + new object[] { "0 - 1", (IntPtr)(-1) }, |
| 29 | + new object[] { "1 + 2 * 3", (IntPtr)0x7 }, |
| 30 | + new object[] { "0x123 + 0x234 * 0x345", (IntPtr)0x73527 } |
| 31 | + }; |
| 32 | + |
| 33 | + [Theory] |
| 34 | + [MemberData(nameof(GetSimpleExpressionTestData))] |
| 35 | + public void SimpleExpressionTest(string expression, IntPtr expected) |
| 36 | + { |
| 37 | + var mock = new Mock<IProcessReader>(); |
| 38 | + |
| 39 | + var executor = CreateExecutor(); |
| 40 | + |
| 41 | + Check.That(executor.Execute(Parser.Parse(expression), mock.Object)).IsEqualTo(expected); |
| 42 | + } |
| 43 | + |
| 44 | + public static IEnumerable<object[]> GetModuleExpressionTestData() => new List<object[]> |
| 45 | + { |
| 46 | + new object[] { "<test.module>", (IntPtr)0x100 }, |
| 47 | + new object[] { "<test.module> + 0", (IntPtr)0x100 }, |
| 48 | + new object[] { "<test.module> + 10", (IntPtr)0x110 }, |
| 49 | + new object[] { "<test.module> * 2", (IntPtr)0x200 } |
| 50 | + }; |
| 51 | + |
| 52 | + [Theory] |
| 53 | + [MemberData(nameof(GetModuleExpressionTestData))] |
| 54 | + public void ModuleExpressionTest(string expression, IntPtr expected) |
| 55 | + { |
| 56 | + var mock = new Mock<IProcessReader>(); |
| 57 | + mock.Setup(p => p.GetModuleByName("test.module")) |
| 58 | + .Returns(new Module { Start = (IntPtr)0x100 }); |
| 59 | + |
| 60 | + var executor = CreateExecutor(); |
| 61 | + |
| 62 | + Check.That(executor.Execute(Parser.Parse(expression), mock.Object)).IsEqualTo(expected); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments