Skip to content

Commit 34df83d

Browse files
committed
[tests] Fix new code analysis warnings.
1 parent b56402f commit 34df83d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tests/monotouch-test/Compression/CompressionStreamTest.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void CheckNullRead ()
101101
Assert.Ignore ("Requires iOS 9.0+ or macOS 10.11+");
102102
MemoryStream backing = new MemoryStream (compressed_data);
103103
DeflateStream decompressing = new DeflateStream (backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);
104-
Assert.Throws<ArgumentNullException> (() => decompressing.Read (null, 0, 20));
104+
Assert.Throws<ArgumentNullException> (() => IgnoreReturnValue (decompressing.Read (null, 0, 20)));
105105
}
106106

107107
[Test]
@@ -112,7 +112,7 @@ public void CheckCompressingRead ()
112112
byte [] dummy = new byte [20];
113113
MemoryStream backing = new MemoryStream ();
114114
DeflateStream compressing = new DeflateStream (backing, CompressionMode.Compress, CompressionAlgorithm.Zlib);
115-
Assert.Throws<InvalidOperationException> (() => compressing.Read (dummy, 0, 20));
115+
Assert.Throws<InvalidOperationException> (() => IgnoreReturnValue (compressing.Read (dummy, 0, 20)));
116116
}
117117

118118
[Test]
@@ -123,7 +123,7 @@ public void CheckRangeRead ()
123123
byte [] dummy = new byte [20];
124124
MemoryStream backing = new MemoryStream (compressed_data);
125125
DeflateStream decompressing = new DeflateStream (backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);
126-
Assert.Throws<ArgumentException> (() => decompressing.Read (dummy, 10, 20));
126+
Assert.Throws<ArgumentException> (() => IgnoreReturnValue (decompressing.Read (dummy, 10, 20)));
127127
}
128128

129129
[Test]
@@ -135,7 +135,7 @@ public void CheckClosedRead ()
135135
MemoryStream backing = new MemoryStream (compressed_data);
136136
DeflateStream decompressing = new DeflateStream (backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);
137137
decompressing.Close ();
138-
Assert.Throws<ObjectDisposedException> (() => decompressing.Read (dummy, 0, 20));
138+
Assert.Throws<ObjectDisposedException> (() => IgnoreReturnValue (decompressing.Read (dummy, 0, 20)));
139139
}
140140

141141
[Test]
@@ -335,7 +335,13 @@ public void Bug19313 ()
335335
byte [] buffer = new byte [512];
336336
using (var backing = new Bug19313Stream (compressed_data))
337337
using (var decompressing = new DeflateStream (backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib))
338-
decompressing.Read (buffer, 0, buffer.Length);
338+
IgnoreReturnValue (decompressing.Read (buffer, 0, buffer.Length));
339+
}
340+
341+
// Call this with the return value from CompressionStream.Read to avoid:
342+
// error CA2022: Avoid inexact read with 'Compression.CompressionStream.Read(byte[], int, int)' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)
343+
void IgnoreReturnValue (int value)
344+
{
339345
}
340346
}
341347
}

0 commit comments

Comments
 (0)