From a813dddc012e293835f58b22bf48453edb546f6c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 12 Jul 2016 20:18:27 +0900 Subject: [PATCH] Add basic compound assignment test --- .../Tests/ICSharpCode.Decompiler.Tests.csproj | 1 + .../Tests/PrettyTestRunner.cs | 17 +++- .../Pretty/CompoundAssignmentTest.cs | 41 ++++++++ .../Pretty/CompoundAssignmentTest.il | 96 +++++++++++++++++++ .../TestCases/Pretty/InlineAssignmentTest.il | 12 +-- 5 files changed, 156 insertions(+), 11 deletions(-) create mode 100644 ICSharpCode.Decompiler/Tests/TestCases/Pretty/CompoundAssignmentTest.cs create mode 100644 ICSharpCode.Decompiler/Tests/TestCases/Pretty/CompoundAssignmentTest.il diff --git a/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj index ef784e404..3e0eac975 100644 --- a/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj @@ -134,6 +134,7 @@ + diff --git a/ICSharpCode.Decompiler/Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler/Tests/PrettyTestRunner.cs index 924cdcd3c..f10a3d434 100644 --- a/ICSharpCode.Decompiler/Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler/Tests/PrettyTestRunner.cs @@ -51,18 +51,25 @@ namespace ICSharpCode.Decompiler.Tests [Test] public void HelloWorld() { - Run("HelloWorld"); - Run("HelloWorld", AssemblerOptions.UseDebug); + Run(); + Run(asmOptions: AssemblerOptions.UseDebug); } [Test] public void InlineAssignmentTest() { - Run("InlineAssignmentTest"); - Run("InlineAssignmentTest", AssemblerOptions.UseDebug); + Run(); + Run(asmOptions: AssemblerOptions.UseDebug); } - void Run(string testName, AssemblerOptions asmOptions = AssemblerOptions.None) + [Test] + public void CompoundAssignmentTest() + { + Run(); + Run(asmOptions: AssemblerOptions.UseDebug); + } + + void Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None) { var ilFile = Path.Combine(TestCasePath, testName + ".il"); var csFile = Path.Combine(TestCasePath, testName + ".cs"); diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Pretty/CompoundAssignmentTest.cs b/ICSharpCode.Decompiler/Tests/TestCases/Pretty/CompoundAssignmentTest.cs new file mode 100644 index 000000000..8a05baba6 --- /dev/null +++ b/ICSharpCode.Decompiler/Tests/TestCases/Pretty/CompoundAssignmentTest.cs @@ -0,0 +1,41 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; + +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty +{ + public class CompoundAssignmentTest + { + public static void Main() + { + + } + + public void Integer(int i) + { + int V_0 = 0; + if (i > 5) { + V_0 += i; + } + else { + V_0 -= i; + } + } + } +} diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Pretty/CompoundAssignmentTest.il b/ICSharpCode.Decompiler/Tests/TestCases/Pretty/CompoundAssignmentTest.il new file mode 100644 index 000000000..e34b0bf24 --- /dev/null +++ b/ICSharpCode.Decompiler/Tests/TestCases/Pretty/CompoundAssignmentTest.il @@ -0,0 +1,96 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly '2lky0ish' +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) + .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module '2lky0ish.exe' +// MVID: {EF50960E-81BF-4C58-B168-629EA572CC14} +.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) +.imagebase 0x00400000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY +// Image base: 0x00D20000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest + extends [mscorlib]System.Object +{ + .method public hidebysig static void Main() cil managed + { + .entrypoint + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method CompoundAssignmentTest::Main + + .method public hidebysig instance void + Integer(int32 i) cil managed + { + // Code size 25 (0x19) + .maxstack 2 + .locals init (int32 V_0, + bool V_1) + IL_0000: nop + IL_0001: ldc.i4.0 + IL_0002: stloc.0 + IL_0003: ldarg.1 + IL_0004: ldc.i4.5 + IL_0005: cgt + IL_0007: ldc.i4.0 + IL_0008: ceq + IL_000a: stloc.1 + IL_000b: ldloc.1 + IL_000c: brtrue.s IL_0014 + + IL_000e: ldloc.0 + IL_000f: ldarg.1 + IL_0010: add + IL_0011: stloc.0 + IL_0012: br.s IL_0018 + + IL_0014: ldloc.0 + IL_0015: ldarg.1 + IL_0016: sub + IL_0017: stloc.0 + IL_0018: ret + } // end of method CompoundAssignmentTest::Integer + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method CompoundAssignmentTest::.ctor + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** +// WARNING: Created Win32 resource file ../../Tests/TestCases/Pretty\CompoundAssignmentTest.res diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Pretty/InlineAssignmentTest.il b/ICSharpCode.Decompiler/Tests/TestCases/Pretty/InlineAssignmentTest.il index 9c7efc14e..6a1399637 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Pretty/InlineAssignmentTest.il +++ b/ICSharpCode.Decompiler/Tests/TestCases/Pretty/InlineAssignmentTest.il @@ -10,7 +10,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly '02lbfa11' +.assembly xdhcadn4 { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx @@ -20,15 +20,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module '02lbfa11.exe' -// MVID: {47622B1B-1B9D-44A2-8E1D-D389FDB9C1FD} +.module xdhcadn4.exe +// MVID: {013854B0-173B-4858-BB3C-CA652EACC772} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x00400000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x03160000 +// Image base: 0x011B0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -155,7 +155,7 @@ } // end of method InlineAssignmentTest::AccessArray .method public hidebysig instance int32 - Test(int32& a) cil managed + Return(int32& a) cil managed { // Code size 12 (0xc) .maxstack 3 @@ -173,7 +173,7 @@ IL_000a: ldloc.0 IL_000b: ret - } // end of method InlineAssignmentTest::Test + } // end of method InlineAssignmentTest::Return .method public hidebysig specialname rtspecialname instance void .ctor() cil managed