Skip to content

Commit e12a33d

Browse files
committed
C#: Disposal tests do not depend on external DLLs.
1 parent d64c244 commit e12a33d

File tree

9 files changed

+58
-438
lines changed

9 files changed

+58
-438
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
3+
namespace DisposalTests
4+
{
5+
public class MyType : IDisposable
6+
{
7+
public void Dispose()
8+
{
9+
}
10+
}
11+
12+
public class Class1 : IDisposable
13+
{
14+
public void DisposesParameter(IDisposable p1, IDisposable p2)
15+
{
16+
p1.Dispose();
17+
}
18+
19+
public void CapturesDisposable(MyType p1, MyType p2)
20+
{
21+
field1 = p1;
22+
field2 = p2;
23+
}
24+
25+
public void DisposesSelf()
26+
{
27+
Dispose();
28+
}
29+
30+
MyType field1, field2;
31+
32+
public void Dispose()
33+
{
34+
field1.Dispose();
35+
}
36+
37+
public static void Dispose(IDisposable d)
38+
{
39+
d.Dispose();
40+
}
41+
}
42+
}

csharp/ql/test/library-tests/commons/Disposal/Disposal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public Disposal(IDisposable p1, object p2, System.IO.TextWriter fs)
2121
field1 = p1;
2222
if(p2 is IDisposable d)
2323
d.Dispose();
24-
Console.SetOut(fs);
24+
DisposalTests.Class1.Dispose(fs);
2525
}
2626
}
Binary file not shown.
Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1 @@
1-
| System.IO.BufferedStream._stream |
2-
| System.IO.Stream.SyncStream._stream |
3-
| System.IO.SyncTextReader._in |
4-
| System.IO.SyncTextWriter._out |
5-
| System.IO.UnmanagedMemoryStreamWrapper._unmanagedStream |
6-
| System.Net.Http.DecompressionHandler.DecompressedContent._originalContent |
7-
| System.Net.Http.DecompressionHandler._innerHandler |
8-
| System.Net.Http.DelegatingHandler._innerHandler |
9-
| System.Net.Http.DelegatingStream._innerStream |
10-
| System.Net.Http.HttpAuthenticatedConnectionHandler._poolManager |
11-
| System.Net.Http.HttpClient._pendingRequestsCts |
12-
| System.Net.Http.HttpConnection.HttpConnectionResponseContent._stream |
13-
| System.Net.Http.HttpConnection._stream |
14-
| System.Net.Http.HttpConnectionHandler._poolManager |
15-
| System.Net.Http.HttpConnectionPool.CachedConnection._connection |
16-
| System.Net.Http.HttpConnectionPool.ConnectionWaiter._cancellationTokenRegistration |
17-
| System.Net.Http.HttpConnectionPoolManager._cleaningTimer |
18-
| System.Net.Http.HttpContent._bufferedContent |
19-
| System.Net.Http.HttpContentStream._connection |
20-
| System.Net.Http.HttpMessageInvoker._handler |
21-
| System.Net.Http.HttpRequestMessage._content |
22-
| System.Net.Http.HttpResponseMessage._content |
23-
| System.Net.Http.NoWriteNoSeekStreamContent._content |
24-
| System.Net.Http.RedirectHandler._initialInnerHandler |
25-
| System.Net.Http.RedirectHandler._redirectInnerHandler |
26-
| System.Net.Http.SocketsHttpHandler._handler |
27-
| System.Net.Http.StreamContent._content |
28-
| System.Net.NTAuthentication._credentialsHandle |
29-
| System.Net.NTAuthentication._securityContext |
30-
| System.Net.Security.SafeDeleteNegoContext._context |
31-
| System.Net.Security.SafeDeleteNegoContext._targetName |
32-
| System.Security.SecureString._buffer |
33-
| System.Threading.CancellationTokenSource.Linked1CancellationTokenSource._reg1 |
34-
| System.Threading.CancellationTokenSource.Linked2CancellationTokenSource._reg1 |
35-
| System.Threading.CancellationTokenSource.Linked2CancellationTokenSource._reg2 |
36-
| System.Threading.CancellationTokenSource._timer |
37-
| System.Threading.ReaderWriterLockSlim._readEvent |
38-
| System.Threading.ReaderWriterLockSlim._upgradeEvent |
39-
| System.Threading.ReaderWriterLockSlim._waitUpgradeEvent |
40-
| System.Threading.ReaderWriterLockSlim._writeEvent |
41-
| System.Xml.Serialization.XmlCountingReader._innerReader |
42-
| System.Xml.XmlAsyncCheckReader._coreReader |
43-
| System.Xml.XmlAsyncCheckWriter._coreWriter |
44-
| System.Xml.XmlAutoDetectWriter._strm |
45-
| System.Xml.XmlAutoDetectWriter._textWriter |
46-
| System.Xml.XmlAutoDetectWriter._wrapped |
47-
| System.Xml.XmlSqlBinaryReader._inStrm |
48-
| System.Xml.XmlTextWriter._textWriter |
49-
| System.Xml.Xsl.Runtime.XmlRawWriterWrapper._wrapped |
1+
| DisposalTests.Class1.field1 |
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import cil
22
import semmle.code.csharp.commons.Disposal
3-
import Whitelist
43

54
from CIL::Field field
65
where
76
mayBeDisposed(field) and
8-
field.getName().charAt(0) = "_" and // Filter the results a little
9-
not whitelistedType(field.getDeclaringType())
7+
field.getDeclaringType().getQualifiedName() = "DisposalTests.Class1"
108
select field.getQualifiedName()

csharp/ql/test/library-tests/commons/Disposal/DisposedParameter.expected

Lines changed: 6 additions & 348 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import dotnet
22
import semmle.code.csharp.commons.Disposal
3-
import Whitelist
43

54
from DotNet::Callable c, DotNet::Parameter param, int p
65
where
76
mayBeDisposed(param) and
87
param = c.getParameter(p) and
9-
not whitelistedType(c.getDeclaringType())
8+
c.getDeclaringType().getQualifiedName() = "DisposalTests.Class1"
109
select c.toStringWithTypes(), p
Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,4 @@
1-
| Execute(TextWriter) | 0 |
2-
| HtmlDecode(string, TextWriter) | 1 |
3-
| HtmlEncode(string, TextWriter) | 1 |
4-
| IndentedTextWriter(TextWriter) | 0 |
5-
| IndentedTextWriter(TextWriter, string) | 0 |
6-
| Synchronized(TextWriter) | 0 |
7-
| System.IO.TextWriter System.Console.EnsureInitialized<System.IO.TextWriter>(System.IO.TextWriter,System.Func<System.IO.TextWriter>) | 0 |
8-
| System.IO.TextWriter System.IO.TextWriter.Synchronized(System.IO.TextWriter) | 0 |
9-
| System.IO.TextWriter System.Threading.Volatile.Read<System.IO.TextWriter>(System.IO.TextWriter) | 0 |
10-
| System.Tuple<System.IO.TextWriter,System.ReadOnlyMemory<System.Char>> System.Tuple.Create<System.IO.TextWriter,System.ReadOnlyMemory<System.Char>>(System.IO.TextWriter,System.ReadOnlyMemory<System.Char>) | 0 |
11-
| System.Void System.CodeDom.Compiler.IndentedTextWriter..ctor(System.IO.TextWriter) | 0 |
12-
| System.Void System.CodeDom.Compiler.IndentedTextWriter..ctor(System.IO.TextWriter,System.String) | 0 |
13-
| System.Void System.IO.TextWriter.SyncTextWriter..ctor(System.IO.TextWriter) | 0 |
14-
| System.Void System.Net.WebUtility.HtmlDecode(System.String,System.IO.TextWriter) | 1 |
15-
| System.Void System.Net.WebUtility.HtmlEncode(System.String,System.IO.TextWriter) | 1 |
16-
| System.Void System.Threading.Volatile.Write<System.IO.TextWriter>(System.IO.TextWriter,System.IO.TextWriter) | 0 |
17-
| System.Void System.Threading.Volatile.Write<System.IO.TextWriter>(System.IO.TextWriter,System.IO.TextWriter) | 1 |
18-
| System.Void System.Tuple<System.Char,System.IO.TextWriter>..ctor(System.IO.TextWriter,System.Char) | 0 |
19-
| System.Void System.Tuple<System.Char[],System.IO.TextWriter,System.Int32,System.Int32>..ctor(System.IO.TextWriter,System.Char[],System.Int32,System.Int32) | 0 |
20-
| System.Void System.Tuple<System.IO.TextWriter,System.String>..ctor(System.IO.TextWriter,System.String) | 0 |
21-
| System.Void System.Xml.Serialization.IndentedWriter..ctor(System.IO.TextWriter,System.Boolean) | 0 |
22-
| System.Void System.Xml.XmlTextEncoder..ctor(System.IO.TextWriter) | 0 |
23-
| System.Void System.Xml.Xsl.XslTransform.Transform(System.Xml.XPath.IXPathNavigable,System.Xml.Xsl.XsltArgumentList,System.IO.TextWriter) | 2 |
24-
| System.Void System.Xml.Xsl.XslTransform.Transform(System.Xml.XPath.IXPathNavigable,System.Xml.Xsl.XsltArgumentList,System.IO.TextWriter,System.Xml.XmlResolver) | 2 |
25-
| System.Void System.Xml.Xsl.XslTransform.Transform(System.Xml.XPath.XPathNavigator,System.Xml.Xsl.XsltArgumentList,System.IO.TextWriter) | 2 |
26-
| System.Void System.Xml.Xsl.XslTransform.Transform(System.Xml.XPath.XPathNavigator,System.Xml.Xsl.XsltArgumentList,System.IO.TextWriter,System.Xml.XmlResolver) | 2 |
27-
| System.Void System.Xml.Xsl.XsltOld.Processor.Execute(System.IO.TextWriter) | 0 |
28-
| System.Void System.Xml.Xsl.XsltOld.TextOnlyOutput..ctor(System.Xml.Xsl.XsltOld.Processor,System.IO.TextWriter) | 1 |
29-
| System.Void System.Xml.Xsl.XsltOld.TextOutput..ctor(System.Xml.Xsl.XsltOld.Processor,System.IO.TextWriter) | 1 |
30-
| Transform(IXPathNavigable, XsltArgumentList, TextWriter) | 2 |
31-
| Transform(IXPathNavigable, XsltArgumentList, TextWriter, XmlResolver) | 2 |
32-
| Transform(XPathNavigator, XsltArgumentList, TextWriter) | 2 |
33-
| Transform(XPathNavigator, XsltArgumentList, TextWriter, XmlResolver) | 2 |
1+
| CapturesDisposable(MyType, MyType) | 1 |
2+
| DisposesParameter(IDisposable, IDisposable) | 1 |
3+
| System.Void DisposalTests.Class1.CapturesDisposable(DisposalTests.MyType,DisposalTests.MyType) | 1 |
4+
| System.Void DisposalTests.Class1.DisposesParameter(System.IDisposable,System.IDisposable) | 1 |

csharp/ql/test/library-tests/commons/Disposal/UndisposedParameter.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import cil
55
from DotNet::Callable c, DotNet::Parameter param, int p
66
where
77
not mayBeDisposed(param) and
8-
param.getType().hasName("TextWriter") and
9-
param = c.getParameter(p)
8+
param = c.getParameter(p) and
9+
c.getDeclaringType().getQualifiedName() = "DisposalTests.Class1"
1010
select c.toStringWithTypes(), p

0 commit comments

Comments
 (0)