Browse Source

Add some failing tests for the using statement.

pull/877/head
Daniel Grunwald 8 years ago
parent
commit
c360292a06
  1. 49
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/ControlFlow.cs
  2. 29
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/ValueTypeCall.cs
  3. 7
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs
  4. 51
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.il
  5. 40
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.il
  6. 36
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.roslyn.il
  7. 41
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.roslyn.il

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

@ -42,6 +42,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -42,6 +42,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
BreakUnlessContinue(false);
TestConditionals();
ThisIsNotAUsingBlock();
NoUsing();
UsingObject();
return 0;
}
@ -153,17 +155,58 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -153,17 +155,58 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void ThisIsNotAUsingBlock()
{
object obj = new System.IO.StringWriter();
var obj = new System.IO.StringWriter();
IDisposable disposable;
try {
(obj as System.IO.TextWriter).WriteLine("ThisIsNotAUsingBlock");
obj.WriteLine("ThisIsNotAUsingBlock");
} finally {
disposable = (obj as IDisposable);
disposable = (object)obj as IDisposable;
if (disposable != null) {
disposable.Dispose();
}
}
Console.WriteLine(disposable);
}
private class PrintOnDispose : IDisposable
{
private string v;
public PrintOnDispose(string v)
{
this.v = v;
}
public void Dispose()
{
Console.WriteLine(this.v);
}
}
static void NoUsing()
{
PrintOnDispose printOnDispose = new PrintOnDispose("NoUsing(): Wrong");
try {
printOnDispose = new PrintOnDispose("NoUsing(): Correct");
} finally {
IDisposable disposable = (object)printOnDispose as IDisposable;
if (disposable != null) {
disposable.Dispose();
}
}
}
static void UsingObject()
{
object obj = new object();
try {
Console.WriteLine("UsingObject: {0}", obj);
} finally {
IDisposable disposable = obj as IDisposable;
if (disposable != null) {
disposable.Dispose();
}
}
}
}
}

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

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{
public struct MutValueType
public struct MutValueType : IDisposable
{
public int val;
@ -11,6 +11,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -11,6 +11,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine("Inc() called on {0}", val);
val = val + 1;
}
public void Dispose()
{
Console.WriteLine("MutValueType disposed on {0}", val);
}
}
public struct GenericValueType<T>
@ -50,6 +55,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -50,6 +55,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
ValueParameter(m);
Field();
Box();
Using();
var gvt = new GenericValueType<string>("Test");
gvt.Call(ref gvt);
new ValueTypeCall().InstanceFieldTests();
@ -103,5 +109,26 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -103,5 +109,26 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
mutableInstanceFieldWithReadOnlyMember = new ValueTypeWithReadOnlyMember(45);
Console.WriteLine(this.mutableInstanceFieldWithReadOnlyMember.Member);
}
static void Using()
{
Console.WriteLine("Using:");
using (var x = new MutValueType()) {
x.Increment();
}
Console.WriteLine("Not using:");
var y = new MutValueType();
try {
y.Increment();
} finally {
MutValueType x = y;
x.Dispose();
}
Console.WriteLine("Using with double var:");
MutValueType z;
using (var x = z = new MutValueType()) {
z.Increment();
}
}
}
}

7
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs

@ -101,6 +101,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -101,6 +101,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
}
public void GenericUsing<T>(T t) where T : IDisposable
{
using (t) {
Console.WriteLine(t);
}
}
public void NoUsing()
{
PrintOnDispose printOnDispose = new PrintOnDispose("Wrong");

51
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.il

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.18020
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly ivwruwuv
.assembly l2hk2gwn
{
.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 @@ @@ -20,15 +20,15 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module ivwruwuv.dll
// MVID: {CC03EEA0-A20B-4731-ADE9-CC2419DB878B}
.module l2hk2gwn.dll
// MVID: {657FEAFC-6D05-4375-B9FF-DE1D3DB20A85}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x00BA0000
// Image base: 0x02BA0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -338,6 +338,47 @@ @@ -338,6 +338,47 @@
IL_0034: ret
} // end of method Using::UsingStatementOnStructWithVariable
.method public hidebysig instance void
GenericUsing<([mscorlib]System.IDisposable) T>(!!T t) cil managed
{
// Code size 49 (0x31)
.maxstack 2
.locals init (!!T V_0,
bool V_1)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: stloc.0
.try
{
IL_0003: nop
IL_0004: ldarg.1
IL_0005: box !!T
IL_000a: call void [mscorlib]System.Console::WriteLine(object)
IL_000f: nop
IL_0010: nop
IL_0011: leave.s IL_002f
} // end .try
finally
{
IL_0013: ldloc.0
IL_0014: box !!T
IL_0019: ldnull
IL_001a: ceq
IL_001c: stloc.1
IL_001d: ldloc.1
IL_001e: brtrue.s IL_002e
IL_0020: ldloca.s V_0
IL_0022: constrained. !!T
IL_0028: callvirt instance void [mscorlib]System.IDisposable::Dispose()
IL_002d: nop
IL_002e: endfinally
} // end handler
IL_002f: nop
IL_0030: ret
} // end of method Using::GenericUsing
.method public hidebysig instance void
NoUsing() cil managed
{

40
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.il

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.18020
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly '2darmbjq'
.assembly lseglqv2
{
.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 @@ @@ -20,15 +20,15 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module '2darmbjq.dll'
// MVID: {947C8C54-1B8B-4766-9D81-4FCCD54C005F}
.module lseglqv2.dll
// MVID: {57E840D4-DC5F-44E8-80CB-5FE3F73EAEF2}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x02B80000
// Image base: 0x02770000
// =============== CLASS MEMBERS DECLARATION ===================
@ -272,6 +272,36 @@ @@ -272,6 +272,36 @@
IL_002d: ret
} // end of method Using::UsingStatementOnStructWithVariable
.method public hidebysig instance void
GenericUsing<([mscorlib]System.IDisposable) T>(!!T t) cil managed
{
// Code size 38 (0x26)
.maxstack 1
.locals init (!!T V_0)
IL_0000: ldarg.1
IL_0001: stloc.0
.try
{
IL_0002: ldarg.1
IL_0003: box !!T
IL_0008: call void [mscorlib]System.Console::WriteLine(object)
IL_000d: leave.s IL_0025
} // end .try
finally
{
IL_000f: ldloc.0
IL_0010: box !!T
IL_0015: brfalse.s IL_0024
IL_0017: ldloca.s V_0
IL_0019: constrained. !!T
IL_001f: callvirt instance void [mscorlib]System.IDisposable::Dispose()
IL_0024: endfinally
} // end handler
IL_0025: ret
} // end of method Using::GenericUsing
.method public hidebysig instance void
NoUsing() cil managed
{

36
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.opt.roslyn.il

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.18020
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -25,14 +25,14 @@ @@ -25,14 +25,14 @@
.ver 0:0:0:0
}
.module Using.dll
// MVID: {8BD4B2FD-6883-4252-8E37-486B759E3F3E}
// MVID: {81DAF28D-BA8B-49CF-9CAC-D5C7BE5BE2AC}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x00CA0000
// Image base: 0x010E0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -249,6 +249,36 @@ @@ -249,6 +249,36 @@
IL_002d: ret
} // end of method Using::UsingStatementOnStructWithVariable
.method public hidebysig instance void
GenericUsing<([mscorlib]System.IDisposable) T>(!!T t) cil managed
{
// Code size 38 (0x26)
.maxstack 1
.locals init (!!T V_0)
IL_0000: ldarg.1
IL_0001: stloc.0
.try
{
IL_0002: ldarg.1
IL_0003: box !!T
IL_0008: call void [mscorlib]System.Console::WriteLine(object)
IL_000d: leave.s IL_0025
} // end .try
finally
{
IL_000f: ldloc.0
IL_0010: box !!T
IL_0015: brfalse.s IL_0024
IL_0017: ldloca.s V_0
IL_0019: constrained. !!T
IL_001f: callvirt instance void [mscorlib]System.IDisposable::Dispose()
IL_0024: endfinally
} // end handler
IL_0025: ret
} // end of method Using::GenericUsing
.method public hidebysig instance void
NoUsing() cil managed
{

41
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.roslyn.il

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.18020
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -25,14 +25,14 @@ @@ -25,14 +25,14 @@
.ver 0:0:0:0
}
.module Using.dll
// MVID: {3686D0B4-0A65-4B60-A432-7042528E2212}
// MVID: {75250624-2DF6-4B63-B8BF-A82776556583}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x02E50000
// Image base: 0x02BA0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -282,6 +282,41 @@ @@ -282,6 +282,41 @@
IL_0032: ret
} // end of method Using::UsingStatementOnStructWithVariable
.method public hidebysig instance void
GenericUsing<([mscorlib]System.IDisposable) T>(!!T t) cil managed
{
// Code size 43 (0x2b)
.maxstack 1
.locals init (!!T V_0)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: stloc.0
.try
{
IL_0003: nop
IL_0004: ldarg.1
IL_0005: box !!T
IL_000a: call void [mscorlib]System.Console::WriteLine(object)
IL_000f: nop
IL_0010: nop
IL_0011: leave.s IL_002a
} // end .try
finally
{
IL_0013: ldloc.0
IL_0014: box !!T
IL_0019: brfalse.s IL_0029
IL_001b: ldloca.s V_0
IL_001d: constrained. !!T
IL_0023: callvirt instance void [mscorlib]System.IDisposable::Dispose()
IL_0028: nop
IL_0029: endfinally
} // end handler
IL_002a: ret
} // end of method Using::GenericUsing
.method public hidebysig instance void
NoUsing() cil managed
{

Loading…
Cancel
Save