diff --git a/ICSharpCode.Decompiler/Tests/CorrectnessTestRunner.cs b/ICSharpCode.Decompiler/Tests/CorrectnessTestRunner.cs index 88924cb01..ba9db8696 100644 --- a/ICSharpCode.Decompiler/Tests/CorrectnessTestRunner.cs +++ b/ICSharpCode.Decompiler/Tests/CorrectnessTestRunner.cs @@ -156,6 +156,12 @@ namespace ICSharpCode.Decompiler.Tests RunCS(options: options); } + [Test] + public void Capturing([ValueSource("defaultOptions")] CompilerOptions options) + { + RunCS(options: options); + } + void RunCS([CallerMemberName] string testName = null, CompilerOptions options = CompilerOptions.UseDebug) { string testFileName = testName + ".cs"; diff --git a/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj index c9e5cd4ff..744d56f33 100644 --- a/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj @@ -126,6 +126,7 @@ + diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Capturing.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Capturing.cs new file mode 100644 index 000000000..1dc1e15de --- /dev/null +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Capturing.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness +{ + class Capturing + { + static void Main(string[] args) + { + TestCase1(); + } + + static void TestCase1() + { + Console.WriteLine("TestCase1"); + for (int i = 0; i < 10; i++) + Console.WriteLine(i); + // i no longer declared + List actions = new List(); + int max = 5; + string line; + while (ReadLine(out line, ref max)) { + actions.Add(() => Console.WriteLine(line)); + } + // line still declared + line = null; + Console.WriteLine("----"); + foreach (var action in actions) + action(); + } + + private static bool ReadLine(out string line, ref int v) + { + line = v + " line"; + return --v > 0; + } + } +} diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Comparisons.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Comparisons.cs index 271f483ae..48277108e 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Comparisons.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Comparisons.cs @@ -20,7 +20,7 @@ using System; #pragma warning disable 652 -namespace ICSharpCode.Decompiler.Tests.TestCases +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { public class Comparisons { diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/CompoundAssignment.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/CompoundAssignment.cs index f874f1590..246d45af0 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/CompoundAssignment.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/CompoundAssignment.cs @@ -19,74 +19,79 @@ using System; using System.Collections.Generic; -class CompoundAssignment +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { - static void Main() + class CompoundAssignment { - PreIncrementProperty(); - } - - static void Test(int a, int b) - { - Console.WriteLine("{0} {1}", a, b); - } - - static int x; - - static int X() - { - Console.Write("X "); - return ++x; - } - - int instanceField; - - public int InstanceProperty { - get { - Console.WriteLine("In get_InstanceProperty"); - return instanceField; + static void Main() + { + PreIncrementProperty(); } - set { - Console.WriteLine("In set_InstanceProperty, value=" + value); - instanceField = value; + + static void Test(int a, int b) + { + Console.WriteLine("{0} {1}", a, b); } - } - - static int staticField; - - public static int StaticProperty { - get { - Console.WriteLine("In get_StaticProperty"); - return staticField; + + static int x; + + static int X() + { + Console.Write("X "); + return ++x; } - set { - Console.WriteLine("In set_StaticProperty, value=" + value); - staticField = value; + + int instanceField; + + public int InstanceProperty + { + get { + Console.WriteLine("In get_InstanceProperty"); + return instanceField; + } + set { + Console.WriteLine("In set_InstanceProperty, value=" + value); + instanceField = value; + } + } + + static int staticField; + + public static int StaticProperty + { + get { + Console.WriteLine("In get_StaticProperty"); + return staticField; + } + set { + Console.WriteLine("In set_StaticProperty, value=" + value); + staticField = value; + } + } + + public static Dictionary GetDict() + { + Console.WriteLine("In GetDict()"); + return new Dictionary(); + } + + static string GetString() + { + Console.WriteLine("In GetString()"); + return "the string"; + } + + static void PreIncrementProperty() + { + Console.WriteLine("PreIncrementProperty:"); + Test(X(), ++new CompoundAssignment().InstanceProperty); + Test(X(), ++StaticProperty); + } + + static void PreIncrementIndexer() + { + Console.WriteLine("PreIncrementIndexer:"); + Test(X(), ++GetDict()[GetString()]); } } - - public static Dictionary GetDict() - { - Console.WriteLine("In GetDict()"); - return new Dictionary(); - } - - static string GetString() - { - Console.WriteLine("In GetString()"); - return "the string"; - } - - static void PreIncrementProperty() - { - Console.WriteLine("PreIncrementProperty:"); - Test(X(), ++new CompoundAssignment().InstanceProperty); - Test(X(), ++StaticProperty); - } - - static void PreIncrementIndexer() - { - Console.WriteLine("PreIncrementIndexer:"); - Test(X(), ++GetDict()[GetString()]); - } -} +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/ConditionalAttr.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/ConditionalAttr.cs index 873116fca..611814c16 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/ConditionalAttr.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/ConditionalAttr.cs @@ -5,7 +5,6 @@ using System.Diagnostics; namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { - class ConditionalAttr { [Conditional("PRINT")] diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/ControlFlow.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/ControlFlow.cs index c2b77e7b9..5d75fbb79 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/ControlFlow.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/ControlFlow.cs @@ -18,88 +18,91 @@ using System; -class ControlFlow +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { - public static int Main() + class ControlFlow { - int result = 0; - EmptyIf("Empty", ref result); - EmptyIf("test", ref result); - NormalIf("none", ref result); - NormalIf("test", ref result); - NormalIf2("none", ref result); - NormalIf2("test", ref result); - NormalIf3("none", ref result); - NormalIf3("test", ref result); - Test("none", ref result); - Test("test", ref result); - Console.WriteLine(result); - return 0; - } - - static void EmptyIf(string input, ref int result) - { - if (input.Contains("test")) { + public static int Main() + { + int result = 0; + EmptyIf("Empty", ref result); + EmptyIf("test", ref result); + NormalIf("none", ref result); + NormalIf("test", ref result); + NormalIf2("none", ref result); + NormalIf2("test", ref result); + NormalIf3("none", ref result); + NormalIf3("test", ref result); + Test("none", ref result); + Test("test", ref result); + Console.WriteLine(result); + return 0; } - result = result + 1; - Console.WriteLine("EmptyIf"); - } - static void NormalIf(string input, ref int result) - { - if (input.Contains("test")) { - Console.WriteLine("result"); - } else { - Console.WriteLine("else"); + static void EmptyIf(string input, ref int result) + { + if (input.Contains("test")) { + } + result = result + 1; + Console.WriteLine("EmptyIf"); } - result = result + 1; - Console.WriteLine("end"); - } - static void NormalIf2(string input, ref int result) - { - if (input.Contains("test")) { - Console.WriteLine("result"); + static void NormalIf(string input, ref int result) + { + if (input.Contains("test")) { + Console.WriteLine("result"); + } else { + Console.WriteLine("else"); + } + result = result + 1; + Console.WriteLine("end"); } - result = result + 1; - Console.WriteLine("end"); - } - static void NormalIf3(string input, ref int result) - { - if (input.Contains("test")) { - Console.WriteLine("result"); - } else { - Console.WriteLine("else"); + static void NormalIf2(string input, ref int result) + { + if (input.Contains("test")) { + Console.WriteLine("result"); + } + result = result + 1; + Console.WriteLine("end"); } - result = result + 1; - } - static void Test(string input, ref int result) - { - foreach (char c in input) { - Console.Write(c); + static void NormalIf3(string input, ref int result) + { + if (input.Contains("test")) { + Console.WriteLine("result"); + } else { + Console.WriteLine("else"); + } result = result + 1; } - if (input.Contains("test")) { - Console.WriteLine("result"); - } else { - Console.WriteLine("else"); + + static void Test(string input, ref int result) + { + foreach (char c in input) { + Console.Write(c); + result = result + 1; + } + if (input.Contains("test")) { + Console.WriteLine("result"); + } else { + Console.WriteLine("else"); + } } - } - int Dim2Search(int arg) - { - var tens = new[] { 10, 20, 30 }; - var ones = new[] { 1, 2, 3 }; + int Dim2Search(int arg) + { + var tens = new[] { 10, 20, 30 }; + var ones = new[] { 1, 2, 3 }; - for (int i = 0; i < tens.Length; i++) { - for (int j = 0; j < ones.Length; j++) { - if (tens[i] + ones[j] == arg) - return i; + for (int i = 0; i < tens.Length; i++) { + for (int j = 0; j < ones.Length; j++) { + if (tens[i] + ones[j] == arg) + return i; + } } - } - return -1; + return -1; + } } -} +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Conversions.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Conversions.cs index 0771ae32a..b808aee34 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Conversions.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Conversions.cs @@ -21,7 +21,7 @@ using System; using ICSharpCode.Decompiler.Util; -namespace ICSharpCode.Decompiler.Tests.TestCases +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { public class Conversions { diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/DecimalFields.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/DecimalFields.cs index b683fffa1..6a2d57816 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/DecimalFields.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/DecimalFields.cs @@ -18,7 +18,7 @@ using System; -namespace ICSharpCode.Decompiler.Tests.TestCases +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { /// /// Description of DecimalFields. diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Generics.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Generics.cs index cb251deca..61d4d4875 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Generics.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Generics.cs @@ -18,7 +18,7 @@ using System; -namespace Generics +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { /// /// Description of Generics. diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/HelloWorld.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/HelloWorld.cs index c313e85a4..277b73ec6 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/HelloWorld.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/HelloWorld.cs @@ -18,7 +18,7 @@ using System; -namespace HelloWorld +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { class HelloWorld { diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/InitializerTests.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/InitializerTests.cs index 038bda3e6..1b88f7b54 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/InitializerTests.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/InitializerTests.cs @@ -19,192 +19,194 @@ using System; using System.Collections.Generic; -public class InitializerTests +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { - public static int Main() + public class InitializerTests { - int[,] test = new int[2,3]; - test[0,0] = 0; - test[0,1] = 1; - test[0,2] = 2; - int result = test.Length + test[0, 0] + test[0, 2]; - Console.WriteLine(result); - return 0; - } - - private enum MyEnum - { - a, - b - } - - private enum MyEnum2 - { - c, - d - } - - private class Data - { - public List FieldList = new List(); - public InitializerTests.MyEnum a + public static int Main() { - get; - set; + int[,] test = new int[2, 3]; + test[0, 0] = 0; + test[0, 1] = 1; + test[0, 2] = 2; + int result = test.Length + test[0, 0] + test[0, 2]; + Console.WriteLine(result); + return 0; } - public List PropertyList + + private enum MyEnum { - get; - set; + a, + b } - public InitializerTests.Data MoreData + private enum MyEnum2 { - get; - set; + c, + d } - - public InitializerTests.StructData NestedStruct + + private class Data { - get; - set; + public List FieldList = new List(); + public InitializerTests.MyEnum a + { + get; + set; + } + public List PropertyList + { + get; + set; + } + + public InitializerTests.Data MoreData + { + get; + set; + } + + public InitializerTests.StructData NestedStruct + { + get; + set; + } } - } - - private struct StructData - { - public int Field; - public int Property + + private struct StructData { - get; - set; + public int Field; + public int Property + { + get; + set; + } + + public InitializerTests.Data MoreData + { + get; + set; + } + + public StructData(int initialValue) + { + this = default(InitializerTests.StructData); + this.Field = initialValue; + this.Property = initialValue; + } } - - public InitializerTests.Data MoreData + + // Helper methods used to ensure initializers used within expressions work correctly + private static void X(object a, object b) { - get; - set; } - - public StructData(int initialValue) + + private static object Y() { - this = default(InitializerTests.StructData); - this.Field = initialValue; - this.Property = initialValue; + return null; } - } - - // Helper methods used to ensure initializers used within expressions work correctly - private static void X(object a, object b) - { - } - - private static object Y() - { - return null; - } - #region Array Initializers - public static void Array1() - { - InitializerTests.X(InitializerTests.Y(), new int[] - { + #region Array Initializers + public static void Array1() + { + InitializerTests.X(InitializerTests.Y(), new int[] + { 1, 2, 3, - 4, + 4, 5, 6, 7, 8, 9, 10 - }); - } + }); + } - public static void Array2(int a, int b, int c) - { - InitializerTests.X(InitializerTests.Y(), new int[] - { + public static void Array2(int a, int b, int c) + { + InitializerTests.X(InitializerTests.Y(), new int[] + { a, 0, - b, - 0, + b, + 0, c - }); - } + }); + } - public static void NestedArray(int a, int b, int c) - { - InitializerTests.X(InitializerTests.Y(), new int[][] + public static void NestedArray(int a, int b, int c) { + InitializerTests.X(InitializerTests.Y(), new int[][] + { new int[] { - 1, + 1, 2, - 3, + 3, 4, - 5, - 6, - 7, + 5, + 6, + 7, 8, - 9, + 9, 10 }, new int[] { - a, + a, b, c }, new int[] { 1, - 2, + 2, 3, - 4, - 5, + 4, + 5, 6 } - }); - } + }); + } - public static void ArrayBoolean() - { - InitializerTests.X(InitializerTests.Y(), new bool[] - { + public static void ArrayBoolean() + { + InitializerTests.X(InitializerTests.Y(), new bool[] + { + true, + false, + true, + false, + false, + false, true, - false, - true, - false, - false, - false, - true, true - }); - } + }); + } - public static void ArrayByte() - { - InitializerTests.X(InitializerTests.Y(), new byte[] - { + public static void ArrayByte() + { + InitializerTests.X(InitializerTests.Y(), new byte[] + { 1, 2, - 3, - 4, - 5, + 3, + 4, + 5, 6, 7, 8, 254, 255 - }); - } + }); + } - public static void ArraySByte() - { - InitializerTests.X(InitializerTests.Y(), new sbyte[] - { + public static void ArraySByte() + { + InitializerTests.X(InitializerTests.Y(), new sbyte[] + { -128, -127, 0, @@ -213,55 +215,55 @@ public class InitializerTests 3, 4, 127 - }); - } + }); + } - public static void ArrayShort() - { - InitializerTests.X(InitializerTests.Y(), new short[] - { + public static void ArrayShort() + { + InitializerTests.X(InitializerTests.Y(), new short[] + { -32768, -1, 0, 1, 32767 - }); - } + }); + } - public static void ArrayUShort() - { - InitializerTests.X(InitializerTests.Y(), new ushort[] - { + public static void ArrayUShort() + { + InitializerTests.X(InitializerTests.Y(), new ushort[] + { 0, 1, 32767, - 32768, + 32768, 65534, 65535 - }); - } + }); + } - public static void ArrayInt() - { - InitializerTests.X(InitializerTests.Y(), new int[] - { + public static void ArrayInt() + { + InitializerTests.X(InitializerTests.Y(), new int[] + { 1, -2, 2000000000, - 4, + 4, 5, -6, 7, 8, - 9, + 9, 10 - }); - } + }); + } - public static void ArrayUInt() - { - InitializerTests.X(InitializerTests.Y(), new uint[] - { + public static void ArrayUInt() + { + InitializerTests.X(InitializerTests.Y(), new uint[] + { 1u, 2000000000u, 3000000000u, @@ -272,25 +274,25 @@ public class InitializerTests 8u, 9u, 10u - }); - } + }); + } - public static void ArrayLong() - { - InitializerTests.X(InitializerTests.Y(), new long[] - { + public static void ArrayLong() + { + InitializerTests.X(InitializerTests.Y(), new long[] + { -4999999999999999999L, -1L, 0L, 1L, 4999999999999999999L - }); - } + }); + } - public static void ArrayULong() - { - InitializerTests.X(InitializerTests.Y(), new ulong[] - { + public static void ArrayULong() + { + InitializerTests.X(InitializerTests.Y(), new ulong[] + { 1uL, 2000000000uL, 3000000000uL, @@ -301,100 +303,100 @@ public class InitializerTests 8uL, 4999999999999999999uL, 9999999999999999999uL - }); - } + }); + } - public static void ArrayFloat() - { - InitializerTests.X(InitializerTests.Y(), new float[] - { + public static void ArrayFloat() + { + InitializerTests.X(InitializerTests.Y(), new float[] + { -1.5f, 0f, 1.5f, float.NegativeInfinity, float.PositiveInfinity, float.NaN - }); - } + }); + } - public static void ArrayDouble() - { - InitializerTests.X(InitializerTests.Y(), new double[] - { + public static void ArrayDouble() + { + InitializerTests.X(InitializerTests.Y(), new double[] + { -1.5, 0.0, 1.5, double.NegativeInfinity, double.PositiveInfinity, double.NaN - }); - } + }); + } - public static void ArrayDecimal() - { - InitializerTests.X(InitializerTests.Y(), new decimal[] - { + public static void ArrayDecimal() + { + InitializerTests.X(InitializerTests.Y(), new decimal[] + { -100m, 0m, 100m, - -79228162514264337593543950335m, - 79228162514264337593543950335m, + -79228162514264337593543950335m, + 79228162514264337593543950335m, 0.0000001m - }); - } + }); + } - public static void ArrayString() - { - InitializerTests.X(InitializerTests.Y(), new string[] - { + public static void ArrayString() + { + InitializerTests.X(InitializerTests.Y(), new string[] + { "", null, "Hello", "World" - }); - } + }); + } - public static void ArrayEnum() - { - InitializerTests.X(InitializerTests.Y(), new InitializerTests.MyEnum[] - { + public static void ArrayEnum() + { + InitializerTests.X(InitializerTests.Y(), new InitializerTests.MyEnum[] + { InitializerTests.MyEnum.a, InitializerTests.MyEnum.b, InitializerTests.MyEnum.a, InitializerTests.MyEnum.b - }); - } - - public static void RecursiveArrayInitializer() - { - int[] array = new int[3]; - array[0] = 1; - array[1] = 2; - array[2] = array[1] + 1; - array[0] = 0; - } - #endregion + }); + } - public static void CollectionInitializerList() - { - InitializerTests.X(InitializerTests.Y(), new List + public static void RecursiveArrayInitializer() + { + int[] array = new int[3]; + array[0] = 1; + array[1] = 2; + array[2] = array[1] + 1; + array[0] = 0; + } + #endregion + + public static void CollectionInitializerList() + { + InitializerTests.X(InitializerTests.Y(), new List { 1, 2, 3 }); - } + } - public static object RecursiveCollectionInitializer() - { - List list = new List(); - list.Add(list); - return list; - } + public static object RecursiveCollectionInitializer() + { + List list = new List(); + list.Add(list); + return list; + } - public static void CollectionInitializerDictionary() - { - InitializerTests.X(InitializerTests.Y(), new Dictionary + public static void CollectionInitializerDictionary() + { + InitializerTests.X(InitializerTests.Y(), new Dictionary { { "First", @@ -409,11 +411,11 @@ public class InitializerTests 3 } }); - } + } - public static void CollectionInitializerDictionaryWithEnumTypes() - { - InitializerTests.X(InitializerTests.Y(), new Dictionary + public static void CollectionInitializerDictionaryWithEnumTypes() + { + InitializerTests.X(InitializerTests.Y(), new Dictionary { { InitializerTests.MyEnum.a, @@ -424,132 +426,132 @@ public class InitializerTests InitializerTests.MyEnum2.d } }); - } + } - public static void NotACollectionInitializer() - { - List list = new List(); - list.Add(1); - list.Add(2); - list.Add(3); - InitializerTests.X(InitializerTests.Y(), list); - } + public static void NotACollectionInitializer() + { + List list = new List(); + list.Add(1); + list.Add(2); + list.Add(3); + InitializerTests.X(InitializerTests.Y(), list); + } - public static void ObjectInitializer() - { - InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data - { - a = InitializerTests.MyEnum.a - }); - } + public static void ObjectInitializer() + { + InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data + { + a = InitializerTests.MyEnum.a + }); + } - public static void NotAObjectInitializer() - { - InitializerTests.Data data = new InitializerTests.Data(); - data.a = InitializerTests.MyEnum.a; - InitializerTests.X(InitializerTests.Y(), data); - } + public static void NotAObjectInitializer() + { + InitializerTests.Data data = new InitializerTests.Data(); + data.a = InitializerTests.MyEnum.a; + InitializerTests.X(InitializerTests.Y(), data); + } - public static void ObjectInitializerAssignCollectionToField() - { - InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data - { - a = InitializerTests.MyEnum.a, - FieldList = new List + public static void ObjectInitializerAssignCollectionToField() + { + InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data + { + a = InitializerTests.MyEnum.a, + FieldList = new List { InitializerTests.MyEnum2.c, InitializerTests.MyEnum2.d } - }); - } + }); + } - public static void ObjectInitializerAddToCollectionInField() - { - InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data - { - a = InitializerTests.MyEnum.a, - FieldList = + public static void ObjectInitializerAddToCollectionInField() + { + InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data + { + a = InitializerTests.MyEnum.a, + FieldList = { InitializerTests.MyEnum2.c, InitializerTests.MyEnum2.d } - }); - } + }); + } - public static void ObjectInitializerAssignCollectionToProperty() - { - InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data - { - a = InitializerTests.MyEnum.a, - PropertyList = new List + public static void ObjectInitializerAssignCollectionToProperty() + { + InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data + { + a = InitializerTests.MyEnum.a, + PropertyList = new List { InitializerTests.MyEnum2.c, InitializerTests.MyEnum2.d } - }); - } + }); + } - public static void ObjectInitializerAddToCollectionInProperty() - { - InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data - { - a = InitializerTests.MyEnum.a, - PropertyList = + public static void ObjectInitializerAddToCollectionInProperty() + { + InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data + { + a = InitializerTests.MyEnum.a, + PropertyList = { InitializerTests.MyEnum2.c, InitializerTests.MyEnum2.d } - }); - } + }); + } - public static void ObjectInitializerWithInitializationOfNestedObjects() - { - InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data - { - MoreData = + public static void ObjectInitializerWithInitializationOfNestedObjects() + { + InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data + { + MoreData = { a = InitializerTests.MyEnum.a } - }); - } - - public static void StructInitializer_DefaultConstructor() - { - InitializerTests.X(InitializerTests.Y(), new InitializerTests.StructData + }); + } + + public static void StructInitializer_DefaultConstructor() + { + InitializerTests.X(InitializerTests.Y(), new InitializerTests.StructData { Field = 1, Property = 2 }); - } - - public static void StructInitializer_ExplicitConstructor() - { - InitializerTests.X(InitializerTests.Y(), new InitializerTests.StructData(0) + } + + public static void StructInitializer_ExplicitConstructor() + { + InitializerTests.X(InitializerTests.Y(), new InitializerTests.StructData(0) { Field = 1, Property = 2 }); - } - - public static void StructInitializerWithInitializationOfNestedObjects() - { - InitializerTests.X(InitializerTests.Y(), new InitializerTests.StructData - { - MoreData = + } + + public static void StructInitializerWithInitializationOfNestedObjects() + { + InitializerTests.X(InitializerTests.Y(), new InitializerTests.StructData + { + MoreData = { a = InitializerTests.MyEnum.a, FieldList = { - InitializerTests.MyEnum2.c, - InitializerTests.MyEnum2.d + InitializerTests.MyEnum2.c, + InitializerTests.MyEnum2.d } } - }); - } - - public static void StructInitializerWithinObjectInitializer() - { - InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data + }); + } + + public static void StructInitializerWithinObjectInitializer() + { + InitializerTests.X(InitializerTests.Y(), new InitializerTests.Data { NestedStruct = new InitializerTests.StructData(2) { @@ -557,265 +559,265 @@ public class InitializerTests Property = 2 } }); - } - - public int[,] MultidimensionalInit() - { - return new int[,] - { - - { - 0, - 0, - 0, - 0 - }, - - { - 1, - 1, - 1, - 1 - }, - - { - 0, - 0, - 0, - 0 - }, - - { - 0, - 0, - 0, - 0 - }, - - { - 0, - 0, - 1, - 0 - }, - - { - 0, - 0, - 1, - 0 - }, - - { - 0, - 0, - 1, - 0 - }, - - { - 0, - 0, - 1, - 0 - }, - - { - 0, - 0, - 0, - 0 - }, - - { - 1, - 1, - 1, - 1 - }, - - { - 0, - 0, - 0, - 0 - }, - - { - 0, - 0, - 0, - 0 - }, - - { - 0, - 0, - 1, - 0 - }, - - { - 0, - 0, - 1, - 0 - }, - - { - 0, - 0, - 1, - 0 - }, - - { - 0, - 0, - 1, - 0 + } + + public int[,] MultidimensionalInit() + { + return new int[,] + { + + { + 0, + 0, + 0, + 0 + }, + + { + 1, + 1, + 1, + 1 + }, + + { + 0, + 0, + 0, + 0 + }, + + { + 0, + 0, + 0, + 0 + }, + + { + 0, + 0, + 1, + 0 + }, + + { + 0, + 0, + 1, + 0 + }, + + { + 0, + 0, + 1, + 0 + }, + + { + 0, + 0, + 1, + 0 + }, + + { + 0, + 0, + 0, + 0 + }, + + { + 1, + 1, + 1, + 1 + }, + + { + 0, + 0, + 0, + 0 + }, + + { + 0, + 0, + 0, + 0 + }, + + { + 0, + 0, + 1, + 0 + }, + + { + 0, + 0, + 1, + 0 + }, + + { + 0, + 0, + 1, + 0 + }, + + { + 0, + 0, + 1, + 0 } - }; - } + }; + } - public int[][,] MultidimensionalInit2() - { - return new int[][,] + public int[][,] MultidimensionalInit2() { + return new int[][,] + { new int[,] - { + { - { + { 0, 0, 0, 0 }, - { + { 1, 1, 1, 1 }, - { + { 0, 0, 0, 0 }, - { + { 0, 0, 0, 0 } - }, - new int[,] - { + }, + new int[,] + { - { + { 0, 0, 1, 0 }, - { + { 0, 0, 1, 0 }, - { + { 0, 0, 1, 0 }, - { + { 0, 0, 1, 0 } - }, - new int[,] - { + }, + new int[,] + { - { + { 0, 0, 0, 0 }, - { + { 1, 1, 1, 1 }, - { + { 0, 0, 0, 0 }, - { + { 0, 0, 0, 0 } - }, - new int[,] - { + }, + new int[,] + { - { + { 0, 0, 1, 0 }, - { + { 0, 0, 1, 0 }, - { + { 0, 0, 1, 0 }, - { + { 0, 0, 1, 0 } - } - }; - } + } + }; + } - public int[][,,] ArrayOfArrayOfArrayInit() - { - return new int[][,,] + public int[][,,] ArrayOfArrayOfArrayInit() { + return new int[][,,] + { new int[,,] { { @@ -824,7 +826,7 @@ public class InitializerTests 2, 3 }, - { + { 4, 5, 6 @@ -891,6 +893,7 @@ public class InitializerTests } } } - }; + }; + } } -} +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/MemberLookup.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/MemberLookup.cs index 4fd25b93a..4d29ebcac 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/MemberLookup.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/MemberLookup.cs @@ -18,7 +18,7 @@ using System; -namespace ICSharpCode.Decompiler.Tests.TestCases +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { public class MemberLookup { diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/PropertiesAndEvents.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/PropertiesAndEvents.cs index 9919edd3b..dab3bac6d 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/PropertiesAndEvents.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/PropertiesAndEvents.cs @@ -1,8 +1,8 @@ using System; -namespace PropertiesAndEvents +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { - class Program + class PropertiesAndEvents { public static int Main(string[] args) { diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Switch.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Switch.cs index ea378164e..61ed2f347 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Switch.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/Switch.cs @@ -18,131 +18,133 @@ using System; -public static class Switch +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { - public static void Main() + public static class Switch { - TestCase(SparseIntegerSwitch, -100, 1, 2, 3, 4); - TestCase(ShortSwitchOverString, "First case", "Else"); - TestCase(SwitchOverString1, "First case", "Second case", "2nd case", "Third case", "Fourth case", "Fifth case", "Sixth case", null, "default", "else"); - Console.WriteLine(SwitchOverString2()); - Console.WriteLine(SwitchOverBool(true)); - Console.WriteLine(SwitchOverBool(false)); - } - - static void TestCase(Func target, params T[] args) - { - foreach (var arg in args) { - Console.WriteLine(target(arg)); + public static void Main() + { + TestCase(SparseIntegerSwitch, -100, 1, 2, 3, 4); + TestCase(ShortSwitchOverString, "First case", "Else"); + TestCase(SwitchOverString1, "First case", "Second case", "2nd case", "Third case", "Fourth case", "Fifth case", "Sixth case", null, "default", "else"); + Console.WriteLine(SwitchOverString2()); + Console.WriteLine(SwitchOverBool(true)); + Console.WriteLine(SwitchOverBool(false)); } - } - public static string SparseIntegerSwitch(int i) - { - switch (i) { - case -10000000: return "-10 mln"; - case -100: return "-hundred"; - case -1: return "-1"; - case 0: return "0"; - case 1: return "1"; - case 2: return "2"; - case 4: return "4"; - case 100: return "hundred"; - case 10000: return "ten thousand"; - case 10001: return "ten thousand and one"; - case int.MaxValue: return "int.MaxValue"; - default: return "something else"; + static void TestCase(Func target, params T[] args) + { + foreach (var arg in args) { + Console.WriteLine(target(arg)); + } } - } - - public static string ShortSwitchOverString(string text) - { - switch (text) { - case "First case": - return "Text"; - default: - return "Default"; + + public static string SparseIntegerSwitch(int i) + { + switch (i) { + case -10000000: return "-10 mln"; + case -100: return "-hundred"; + case -1: return "-1"; + case 0: return "0"; + case 1: return "1"; + case 2: return "2"; + case 4: return "4"; + case 100: return "hundred"; + case 10000: return "ten thousand"; + case 10001: return "ten thousand and one"; + case int.MaxValue: return "int.MaxValue"; + default: return "something else"; + } } - } - public static string SwitchOverString1(string text) - { - switch (text) { - case "First case": - return "Text1"; - case "Second case": - case "2nd case": - return "Text2"; - case "Third case": - return "Text3"; - case "Fourth case": - return "Text4"; - case "Fifth case": - return "Text5"; - case "Sixth case": - return "Text6"; - case null: - return null; - default: - return "Default"; + public static string ShortSwitchOverString(string text) + { + switch (text) { + case "First case": + return "Text"; + default: + return "Default"; + } } - } - public static string SwitchOverString2() - { - switch (Environment.UserName) { - case "First case": - return "Text1"; - case "Second case": - return "Text2"; - case "Third case": - return "Text3"; - case "Fourth case": - return "Text4"; - case "Fifth case": - return "Text5"; - case "Sixth case": - return "Text6"; - default: - return "Default"; + public static string SwitchOverString1(string text) + { + switch (text) { + case "First case": + return "Text1"; + case "Second case": + case "2nd case": + return "Text2"; + case "Third case": + return "Text3"; + case "Fourth case": + return "Text4"; + case "Fifth case": + return "Text5"; + case "Sixth case": + return "Text6"; + case null: + return null; + default: + return "Default"; + } } - } - public static string SwitchOverBool(bool b) - { - switch (b) { - case true: - return bool.TrueString; - case false: - return bool.FalseString; - default: - return null; + public static string SwitchOverString2() + { + switch (Environment.UserName) { + case "First case": + return "Text1"; + case "Second case": + return "Text2"; + case "Third case": + return "Text3"; + case "Fourth case": + return "Text4"; + case "Fifth case": + return "Text5"; + case "Sixth case": + return "Text6"; + default: + return "Default"; + } } - } - public static void SwitchInLoop(int i) - { - while (true) { - switch (i) { - case 1: - Console.WriteLine("one"); - break; - case 2: - Console.WriteLine("two"); - break; - case 3: - Console.WriteLine("three"); - continue; - case 4: - Console.WriteLine("four"); - return; + public static string SwitchOverBool(bool b) + { + switch (b) { + case true: + return bool.TrueString; + case false: + return bool.FalseString; default: - Console.WriteLine("default"); - Console.WriteLine("more code"); - throw new ArgumentException(); + return null; } - i++; } - } -} + public static void SwitchInLoop(int i) + { + while (true) { + switch (i) { + case 1: + Console.WriteLine("one"); + break; + case 2: + Console.WriteLine("two"); + break; + case 3: + Console.WriteLine("three"); + continue; + case 4: + Console.WriteLine("four"); + return; + default: + Console.WriteLine("default"); + Console.WriteLine("more code"); + throw new ArgumentException(); + } + i++; + } + } + } +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/UndocumentedExpressions.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/UndocumentedExpressions.cs index 3d3837eeb..7b1e7b0a2 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/UndocumentedExpressions.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/UndocumentedExpressions.cs @@ -18,48 +18,51 @@ using System; -public class UndocumentedExpressions +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { - static void Main(string[] args) + public class UndocumentedExpressions { - MakeTypedRef("abc"); - VarArgs(1, __arglist()); - VarArgs(__arglist(1)); - VarArgs(1, __arglist("abc", 2, true)); - } - - public static void VarArgs(int normalArg, __arglist) - { - ArgIterator argIterator = new ArgIterator(__arglist); - Console.WriteLine("Called with {0} arguments", argIterator.GetRemainingCount()); - int pos = 0; - while (argIterator.GetRemainingCount() > 0) { - TypedReference tr = argIterator.GetNextArg(); - object val; - try { - val = __refvalue(tr, object); - } catch (Exception ex) { - val = ex.GetType().Name; + static void Main(string[] args) + { + MakeTypedRef("abc"); + VarArgs(1, __arglist()); + VarArgs(__arglist(1)); + VarArgs(1, __arglist("abc", 2, true)); + } + + public static void VarArgs(int normalArg, __arglist) + { + ArgIterator argIterator = new ArgIterator(__arglist); + Console.WriteLine("Called with {0} arguments", argIterator.GetRemainingCount()); + int pos = 0; + while (argIterator.GetRemainingCount() > 0) { + TypedReference tr = argIterator.GetNextArg(); + object val; + try { + val = __refvalue(tr, object); + } catch (Exception ex) { + val = ex.GetType().Name; + } + Console.WriteLine("{0} : {1} = {2}", pos++, __reftype(tr).Name, val); } - Console.WriteLine("{0} : {1} = {2}", pos++, __reftype(tr).Name, val); } - } - public static void VarArgs(__arglist) - { - Console.WriteLine("The other varargs overload"); - } - - public static void MakeTypedRef(object o) - { - TypedReference tr = __makeref(o); - UndocumentedExpressions.AcceptTypedRef(tr); - } - - private static void AcceptTypedRef(TypedReference tr) - { - Console.WriteLine("Value is: " + __refvalue(tr, object).ToString()); - Console.WriteLine("Type is: " + __reftype(tr).Name); - __refvalue(tr, object) = 1; + public static void VarArgs(__arglist) + { + Console.WriteLine("The other varargs overload"); + } + + public static void MakeTypedRef(object o) + { + TypedReference tr = __makeref(o); + UndocumentedExpressions.AcceptTypedRef(tr); + } + + private static void AcceptTypedRef(TypedReference tr) + { + Console.WriteLine("Value is: " + __refvalue(tr, object).ToString()); + Console.WriteLine("Type is: " + __reftype(tr).Name); + __refvalue(tr, object) = 1; + } } -} +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/UnsafeCode.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/UnsafeCode.cs index d96d0eb36..bb98dc77e 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/UnsafeCode.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/UnsafeCode.cs @@ -18,201 +18,194 @@ using System; -public class UnsafeCode +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { - struct SimpleStruct + public class UnsafeCode { - public int X; - public double Y; - } - - static void Main() - { - // TODO: test behavior, or convert this into a pretty-test - // (but for now, it's already valuable knowing whether the decompiled code can be re-compiled) - } - - public unsafe int* NullPointer - { - get + struct SimpleStruct { - return null; + public int X; + public double Y; } - } - - public unsafe int* PointerCast(long* p) - { - return (int*)p; - } - - public unsafe long ConvertDoubleToLong(double d) - { - return *(long*)(&d); - } - - public unsafe double ConvertLongToDouble(long d) - { - return *(double*)(&d); - } - - public unsafe int ConvertFloatToInt(float d) - { - return *(int*)(&d); - } - - public unsafe float ConvertIntToFloat(int d) - { - return *(float*)(&d); - } - - public unsafe void PassRefParameterAsPointer(ref int p) - { - fixed (int* ptr = &p) + + static void Main() { - this.PassPointerAsRefParameter(ptr); + // TODO: test behavior, or convert this into a pretty-test + // (but for now, it's already valuable knowing whether the decompiled code can be re-compiled) } - } - - public unsafe void PassPointerAsRefParameter(int* p) - { - this.PassRefParameterAsPointer(ref *p); - } - - public unsafe void AddressInMultiDimensionalArray(double[,] matrix) - { - fixed (double* ptr = &matrix[1, 2]) + + public unsafe int* NullPointer { - this.PointerReferenceExpression(ptr); - this.PointerReferenceExpression(ptr); + get { + return null; + } } - } - - public unsafe int MultipleExitsOutOfFixedBlock(int[] arr) - { - fixed (int* ptr = &arr[0]) - { - if (*ptr < 0) - return *ptr; - if (*ptr == 21) - return 42; - if (*ptr == 42) - goto outside; - } - return 1; - outside: - Console.WriteLine("outside"); - return 2; - } - - public unsafe void FixedStringAccess(string text) - { - fixed (char* ptr = text) + + public unsafe int* PointerCast(long* p) { - char* ptr2 = ptr; - while (*ptr2 != '\0') - { - *ptr2 = 'A'; - ptr2++; + return (int*)p; + } + + public unsafe long ConvertDoubleToLong(double d) + { + return *(long*)(&d); + } + + public unsafe double ConvertLongToDouble(long d) + { + return *(double*)(&d); + } + + public unsafe int ConvertFloatToInt(float d) + { + return *(int*)(&d); + } + + public unsafe float ConvertIntToFloat(int d) + { + return *(float*)(&d); + } + + public unsafe void PassRefParameterAsPointer(ref int p) + { + fixed (int* ptr = &p) { + this.PassPointerAsRefParameter(ptr); } } - } - - public unsafe void PutDoubleIntoLongArray1(long[] array, int index, double val) - { - fixed (long* ptr = array) + + public unsafe void PassPointerAsRefParameter(int* p) { - ((double*)ptr)[index] = val; + this.PassRefParameterAsPointer(ref *p); } - } - - public unsafe void PutDoubleIntoLongArray2(long[] array, int index, double val) - { - fixed (long* ptr = &array[index]) + + public unsafe void AddressInMultiDimensionalArray(double[,] matrix) { - *(double*)ptr = val; + fixed (double* ptr = &matrix[1, 2]) { + this.PointerReferenceExpression(ptr); + this.PointerReferenceExpression(ptr); + } } - } - - public unsafe string PointerReferenceExpression(double* d) - { - return d->ToString(); - } - - public unsafe string PointerReferenceExpression2(long addr) - { - return ((int*)addr)->ToString(); - } - - public unsafe void FixMultipleStrings(string text) - { - fixed (char* ptr = text, userName = Environment.UserName, ptr2 = text) + + public unsafe int MultipleExitsOutOfFixedBlock(int[] arr) { - *ptr = 'c'; - *userName = 'd'; - *ptr2 = 'e'; + fixed (int* ptr = &arr[0]) { + if (*ptr < 0) + return *ptr; + if (*ptr == 21) + return 42; + if (*ptr == 42) + goto outside; + } + return 1; + outside: + Console.WriteLine("outside"); + return 2; } - } - - public unsafe string StackAlloc(int count) - { - char* ptr = stackalloc char[count]; - char* ptr2 = stackalloc char[100]; - for (int i = 0; i < count; i++) + + public unsafe void FixedStringAccess(string text) { - ptr[i] = (char)i; + fixed (char* ptr = text) { + char* ptr2 = ptr; + while (*ptr2 != '\0') { + *ptr2 = 'A'; + ptr2++; + } + } } - return this.PointerReferenceExpression((double*)ptr); - } - public unsafe string StackAllocStruct(int count) - { - SimpleStruct* s = stackalloc SimpleStruct[checked(count * 2)]; - SimpleStruct* p = stackalloc SimpleStruct[10]; - return this.PointerReferenceExpression(&s->Y); - } - - public unsafe int* PointerArithmetic(int* p) - { - return p + 2; - } + public unsafe void PutDoubleIntoLongArray1(long[] array, int index, double val) + { + fixed (long* ptr = array) { + ((double*)ptr)[index] = val; + } + } - public unsafe byte* PointerArithmetic2(long* p, int y, int x) - { - return (byte*)((short*)p + (y * x)); - } + public unsafe void PutDoubleIntoLongArray2(long[] array, int index, double val) + { + fixed (long* ptr = &array[index]) { + *(double*)ptr = val; + } + } - public unsafe long* PointerArithmetic3(long* p) - { - return (long*)((byte*)p + 3); - } + public unsafe string PointerReferenceExpression(double* d) + { + return d->ToString(); + } - public unsafe long* PointerArithmetic4(void* p) - { - return (long*)((byte*)p + 3); - } + public unsafe string PointerReferenceExpression2(long addr) + { + return ((int*)addr)->ToString(); + } - public unsafe int PointerArithmetic5(void* p, byte* q, int i) - { - return (int)(q[i] + *(byte*)p); - } + public unsafe void FixMultipleStrings(string text) + { + fixed (char* ptr = text, userName = Environment.UserName, ptr2 = text) { + *ptr = 'c'; + *userName = 'd'; + *ptr2 = 'e'; + } + } - public unsafe int PointerSubtraction(long* p, long* q) - { - return (int)((long)(p - q)); - } + public unsafe string StackAlloc(int count) + { + char* ptr = stackalloc char[count]; + char* ptr2 = stackalloc char[100]; + for (int i = 0; i < count; i++) { + ptr[i] = (char)i; + } + return this.PointerReferenceExpression((double*)ptr); + } - public unsafe int PointerSubtraction2(long* p, short* q) - { - return (int)((long)((byte*)p - (byte*)q)); - } + public unsafe string StackAllocStruct(int count) + { + SimpleStruct* s = stackalloc SimpleStruct[checked(count * 2)]; + SimpleStruct* p = stackalloc SimpleStruct[10]; + return this.PointerReferenceExpression(&s->Y); + } - public unsafe int PointerSubtraction3(void* p, void* q) - { - return (int)((long)((byte*)p - (byte*)q)); - } + public unsafe int* PointerArithmetic(int* p) + { + return p + 2; + } - unsafe ~UnsafeCode() - { - this.PassPointerAsRefParameter(this.NullPointer); + public unsafe byte* PointerArithmetic2(long* p, int y, int x) + { + return (byte*)((short*)p + (y * x)); + } + + public unsafe long* PointerArithmetic3(long* p) + { + return (long*)((byte*)p + 3); + } + + public unsafe long* PointerArithmetic4(void* p) + { + return (long*)((byte*)p + 3); + } + + public unsafe int PointerArithmetic5(void* p, byte* q, int i) + { + return (int)(q[i] + *(byte*)p); + } + + public unsafe int PointerSubtraction(long* p, long* q) + { + return (int)((long)(p - q)); + } + + public unsafe int PointerSubtraction2(long* p, short* q) + { + return (int)((long)((byte*)p - (byte*)q)); + } + + public unsafe int PointerSubtraction3(void* p, void* q) + { + return (int)((long)((byte*)p - (byte*)q)); + } + + unsafe ~UnsafeCode() + { + this.PassPointerAsRefParameter(this.NullPointer); + } } -} +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/ValueTypeCall.cs b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/ValueTypeCall.cs index 64c42b03f..e58919237 100644 --- a/ICSharpCode.Decompiler/Tests/TestCases/Correctness/ValueTypeCall.cs +++ b/ICSharpCode.Decompiler/Tests/TestCases/Correctness/ValueTypeCall.cs @@ -1,6 +1,6 @@ using System; -namespace ValueTypeCall +namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { public struct MutValueType { @@ -41,7 +41,7 @@ namespace ValueTypeCall } } - public class Program + public class ValueTypeCall { public static void Main() { @@ -52,7 +52,7 @@ namespace ValueTypeCall Box(); var gvt = new GenericValueType("Test"); gvt.Call(ref gvt); - new Program().InstanceFieldTests(); + new ValueTypeCall().InstanceFieldTests(); } static void RefParameter(ref MutValueType m)