Browse Source

Move correctness tests to single namespace

pull/728/merge
Siegfried Pammer 9 years ago
parent
commit
f24f1e007e
  1. 6
      ICSharpCode.Decompiler/Tests/CorrectnessTestRunner.cs
  2. 1
      ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj
  3. 41
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/Capturing.cs
  4. 2
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/Comparisons.cs
  5. 133
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/CompoundAssignment.cs
  6. 1
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/ConditionalAttr.cs
  7. 137
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/ControlFlow.cs
  8. 2
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/Conversions.cs
  9. 2
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/DecimalFields.cs
  10. 2
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/Generics.cs
  11. 2
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/HelloWorld.cs
  12. 933
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/InitializerTests.cs
  13. 2
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/MemberLookup.cs
  14. 4
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/PropertiesAndEvents.cs
  15. 224
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/Switch.cs
  16. 81
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/UndocumentedExpressions.cs
  17. 331
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/UnsafeCode.cs
  18. 6
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/ValueTypeCall.cs

6
ICSharpCode.Decompiler/Tests/CorrectnessTestRunner.cs

@ -156,6 +156,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -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";

1
ICSharpCode.Decompiler/Tests/ICSharpCode.Decompiler.Tests.csproj

@ -126,6 +126,7 @@ @@ -126,6 +126,7 @@
<Compile Include="Helpers\TypeSystemHelper.cs" />
<Compile Include="PrettyTestRunner.cs" />
<Compile Include="RoundtripAssembly.cs" />
<Compile Include="TestCases\Correctness\Capturing.cs" />
<Compile Include="TestCases\Correctness\OverloadResolution.cs" />
<Compile Include="TestCases\Pretty\AnonymousTypes.cs" />
<Compile Include="TestCases\Pretty\Async.cs" />

41
ICSharpCode.Decompiler/Tests/TestCases/Correctness/Capturing.cs

@ -0,0 +1,41 @@ @@ -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<Action> actions = new List<Action>();
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;
}
}
}

2
ICSharpCode.Decompiler/Tests/TestCases/Correctness/Comparisons.cs

@ -20,7 +20,7 @@ using System; @@ -20,7 +20,7 @@ using System;
#pragma warning disable 652
namespace ICSharpCode.Decompiler.Tests.TestCases
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
public class Comparisons
{

133
ICSharpCode.Decompiler/Tests/TestCases/Correctness/CompoundAssignment.cs

@ -19,74 +19,79 @@ @@ -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<string, int> GetDict()
{
Console.WriteLine("In GetDict()");
return new Dictionary<string, int>();
}
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<string, int> GetDict()
{
Console.WriteLine("In GetDict()");
return new Dictionary<string, int>();
}
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()]);
}
}
}

1
ICSharpCode.Decompiler/Tests/TestCases/Correctness/ConditionalAttr.cs

@ -5,7 +5,6 @@ using System.Diagnostics; @@ -5,7 +5,6 @@ using System.Diagnostics;
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
class ConditionalAttr
{
[Conditional("PRINT")]

137
ICSharpCode.Decompiler/Tests/TestCases/Correctness/ControlFlow.cs

@ -18,88 +18,91 @@ @@ -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;
}
}
}
}

2
ICSharpCode.Decompiler/Tests/TestCases/Correctness/Conversions.cs

@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
using System;
using ICSharpCode.Decompiler.Util;
namespace ICSharpCode.Decompiler.Tests.TestCases
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
public class Conversions
{

2
ICSharpCode.Decompiler/Tests/TestCases/Correctness/DecimalFields.cs

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
using System;
namespace ICSharpCode.Decompiler.Tests.TestCases
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
/// <summary>
/// Description of DecimalFields.

2
ICSharpCode.Decompiler/Tests/TestCases/Correctness/Generics.cs

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
using System;
namespace Generics
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
/// <summary>
/// Description of Generics.

2
ICSharpCode.Decompiler/Tests/TestCases/Correctness/HelloWorld.cs

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
using System;
namespace HelloWorld
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
class HelloWorld
{

933
ICSharpCode.Decompiler/Tests/TestCases/Correctness/InitializerTests.cs

File diff suppressed because it is too large Load Diff

2
ICSharpCode.Decompiler/Tests/TestCases/Correctness/MemberLookup.cs

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
using System;
namespace ICSharpCode.Decompiler.Tests.TestCases
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
public class MemberLookup
{

4
ICSharpCode.Decompiler/Tests/TestCases/Correctness/PropertiesAndEvents.cs

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
using System;
namespace PropertiesAndEvents
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
class Program
class PropertiesAndEvents
{
public static int Main(string[] args)
{

224
ICSharpCode.Decompiler/Tests/TestCases/Correctness/Switch.cs

@ -18,131 +18,133 @@ @@ -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<T>(Func<T, string> 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<T>(Func<T, string> 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++;
}
}
}
}

81
ICSharpCode.Decompiler/Tests/TestCases/Correctness/UndocumentedExpressions.cs

@ -18,48 +18,51 @@ @@ -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;
}
}
}
}

331
ICSharpCode.Decompiler/Tests/TestCases/Correctness/UnsafeCode.cs

@ -18,201 +18,194 @@ @@ -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);
}
}
}
}

6
ICSharpCode.Decompiler/Tests/TestCases/Correctness/ValueTypeCall.cs

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
using System;
namespace ValueTypeCall
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
public struct MutValueType
{
@ -41,7 +41,7 @@ namespace ValueTypeCall @@ -41,7 +41,7 @@ namespace ValueTypeCall
}
}
public class Program
public class ValueTypeCall
{
public static void Main()
{
@ -52,7 +52,7 @@ namespace ValueTypeCall @@ -52,7 +52,7 @@ namespace ValueTypeCall
Box();
var gvt = new GenericValueType<string>("Test");
gvt.Call(ref gvt);
new Program().InstanceFieldTests();
new ValueTypeCall().InstanceFieldTests();
}
static void RefParameter(ref MutValueType m)

Loading…
Cancel
Save