1
1
// Copyright (c) Microsoft. All rights reserved.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
- using System ;
5
- using System . Collections . Generic ;
4
+ using System . Reflection ;
6
5
using System . Text ;
7
6
using System . Threading . Tasks ;
8
- using System . IO ;
9
- using System . Reflection ;
10
- using System . IO . Compression ;
11
7
using Xunit ;
12
8
13
9
namespace System . IO . Compression . Tests
14
10
{
15
- public partial class DeflateStreamTests
11
+ public class ZLibDeflateStreamTests : DeflateStreamTests , IDisposable
12
+ {
13
+ public ZLibDeflateStreamTests ( ) { Common . SetDeflaterMode ( "zlib" ) ; }
14
+ public void Dispose ( ) { Common . SetDeflaterMode ( "unknown" ) ; }
15
+ }
16
+
17
+ public class ManagedDeflateStreamTests : DeflateStreamTests , IDisposable
18
+ {
19
+ public ManagedDeflateStreamTests ( ) { Common . SetDeflaterMode ( "managed" ) ; }
20
+ public void Dispose ( ) { Common . SetDeflaterMode ( "unknown" ) ; }
21
+ }
22
+
23
+ public abstract class DeflateStreamTests
16
24
{
17
25
static string gzTestFile ( String fileName ) { return Path . Combine ( "GZTestData" , fileName ) ; }
18
26
19
27
[ Fact ]
20
- public static void BaseStream1 ( )
28
+ public void BaseStream1 ( )
21
29
{
22
30
var writeStream = new MemoryStream ( ) ;
23
31
var zip = new DeflateStream ( writeStream , CompressionMode . Compress ) ;
@@ -27,7 +35,7 @@ public static void BaseStream1()
27
35
}
28
36
29
37
[ Fact ]
30
- public static void BaseStream2 ( )
38
+ public void BaseStream2 ( )
31
39
{
32
40
var ms = new MemoryStream ( ) ;
33
41
var zip = new DeflateStream ( ms , CompressionMode . Decompress ) ;
@@ -37,7 +45,7 @@ public static void BaseStream2()
37
45
}
38
46
39
47
[ Fact ]
40
- public static async Task ModifyBaseStream ( )
48
+ public async Task ModifyBaseStream ( )
41
49
{
42
50
var ms = await LocalMemoryStream . readAppFileAsync ( gzTestFile ( "GZTestDocument.txt.gz" ) ) ;
43
51
var newMs = StripHeaderAndFooter . Strip ( ms ) ;
@@ -52,7 +60,7 @@ public static async Task ModifyBaseStream()
52
60
}
53
61
54
62
[ Fact ]
55
- public static void DecompressCanRead ( )
63
+ public void DecompressCanRead ( )
56
64
{
57
65
var ms = new MemoryStream ( ) ;
58
66
var zip = new DeflateStream ( ms , CompressionMode . Decompress ) ;
@@ -64,7 +72,7 @@ public static void DecompressCanRead()
64
72
}
65
73
66
74
[ Fact ]
67
- public static void CompressCanWrite ( )
75
+ public void CompressCanWrite ( )
68
76
{
69
77
var ms = new MemoryStream ( ) ;
70
78
var zip = new DeflateStream ( ms , CompressionMode . Compress ) ;
@@ -75,15 +83,15 @@ public static void CompressCanWrite()
75
83
}
76
84
77
85
[ Fact ]
78
- public static void CanDisposeBaseStream ( )
86
+ public void CanDisposeBaseStream ( )
79
87
{
80
88
var ms = new MemoryStream ( ) ;
81
89
var zip = new DeflateStream ( ms , CompressionMode . Compress ) ;
82
90
ms . Dispose ( ) ; // This would throw if this was invalid
83
91
}
84
92
85
93
[ Fact ]
86
- public static void CanDisposeDeflateStream ( )
94
+ public void CanDisposeDeflateStream ( )
87
95
{
88
96
var ms = new MemoryStream ( ) ;
89
97
var zip = new DeflateStream ( ms , CompressionMode . Compress ) ;
@@ -96,7 +104,7 @@ public static void CanDisposeDeflateStream()
96
104
}
97
105
98
106
[ Fact ]
99
- public static async Task CanReadBaseStreamAfterDispose ( )
107
+ public async Task CanReadBaseStreamAfterDispose ( )
100
108
{
101
109
var ms = await LocalMemoryStream . readAppFileAsync ( gzTestFile ( "GZTestDocument.txt.gz" ) ) ;
102
110
var newMs = StripHeaderAndFooter . Strip ( ms ) ;
@@ -114,7 +122,7 @@ public static async Task CanReadBaseStreamAfterDispose()
114
122
}
115
123
116
124
[ Fact ]
117
- public static async Task DecompressWorks ( )
125
+ public async Task DecompressWorks ( )
118
126
{
119
127
var compareStream = await LocalMemoryStream . readAppFileAsync ( gzTestFile ( "GZTestDocument.txt" ) ) ;
120
128
var gzStream = await LocalMemoryStream . readAppFileAsync ( gzTestFile ( "GZTestDocument.txt.gz" ) ) ;
@@ -123,7 +131,7 @@ public static async Task DecompressWorks()
123
131
}
124
132
125
133
[ Fact ]
126
- public static async Task DecompressWorksWithBinaryFile ( )
134
+ public async Task DecompressWorksWithBinaryFile ( )
127
135
{
128
136
var compareStream = await LocalMemoryStream . readAppFileAsync ( gzTestFile ( "GZTestDocument.doc" ) ) ;
129
137
var gzStream = await LocalMemoryStream . readAppFileAsync ( gzTestFile ( "GZTestDocument.doc.gz" ) ) ;
@@ -132,7 +140,7 @@ public static async Task DecompressWorksWithBinaryFile()
132
140
}
133
141
134
142
// Making this async since regular read/write are tested below
135
- private static async Task DecompressAsync ( MemoryStream compareStream , MemoryStream gzStream )
143
+ private async Task DecompressAsync ( MemoryStream compareStream , MemoryStream gzStream )
136
144
{
137
145
var strippedMs = StripHeaderAndFooter . Strip ( gzStream ) ;
138
146
@@ -167,8 +175,9 @@ private static async Task DecompressAsync(MemoryStream compareStream, MemoryStre
167
175
Assert . Equal ( compareArray [ i ] , writtenArray [ i ] ) ;
168
176
}
169
177
}
178
+
170
179
[ Fact ]
171
- public static async Task DecompressFailsWithRealGzStream ( )
180
+ public async Task DecompressFailsWithRealGzStream ( )
172
181
{
173
182
String [ ] files = { gzTestFile ( "GZTestDocument.doc.gz" ) , gzTestFile ( "GZTestDocument.txt.gz" ) } ;
174
183
foreach ( String fileName in files )
@@ -181,8 +190,9 @@ public static async Task DecompressFailsWithRealGzStream()
181
190
zip . Dispose ( ) ;
182
191
}
183
192
}
193
+
184
194
[ Fact ]
185
- public static void NullBaseStreamThrows ( )
195
+ public void NullBaseStreamThrows ( )
186
196
{
187
197
Assert . Throws < ArgumentNullException > ( ( ) =>
188
198
{
@@ -194,8 +204,9 @@ public static void NullBaseStreamThrows()
194
204
var deflate = new DeflateStream ( null , CompressionMode . Compress ) ;
195
205
} ) ;
196
206
}
207
+
197
208
[ Fact ]
198
- public static void DisposedBaseStreamThrows ( )
209
+ public void DisposedBaseStreamThrows ( )
199
210
{
200
211
var ms = new MemoryStream ( ) ;
201
212
ms . Dispose ( ) ;
@@ -209,8 +220,9 @@ public static void DisposedBaseStreamThrows()
209
220
var deflate = new DeflateStream ( ms , CompressionMode . Compress ) ;
210
221
} ) ;
211
222
}
223
+
212
224
[ Fact ]
213
- public static void ReadOnlyStreamThrowsOnCompress ( )
225
+ public void ReadOnlyStreamThrowsOnCompress ( )
214
226
{
215
227
var ms = new LocalMemoryStream ( ) ;
216
228
ms . SetCanWrite ( false ) ;
@@ -220,8 +232,9 @@ public static void ReadOnlyStreamThrowsOnCompress()
220
232
var gzip = new DeflateStream ( ms , CompressionMode . Compress ) ;
221
233
} ) ;
222
234
}
235
+
223
236
[ Fact ]
224
- public static void WriteOnlyStreamThrowsOnDecompress ( )
237
+ public void WriteOnlyStreamThrowsOnDecompress ( )
225
238
{
226
239
var ms = new LocalMemoryStream ( ) ;
227
240
ms . SetCanRead ( false ) ;
@@ -231,8 +244,9 @@ public static void WriteOnlyStreamThrowsOnDecompress()
231
244
var gzip = new DeflateStream ( ms , CompressionMode . Decompress ) ;
232
245
} ) ;
233
246
}
247
+
234
248
[ Fact ]
235
- public static void TestCtors ( )
249
+ public void TestCtors ( )
236
250
{
237
251
CompressionLevel [ ] legalValues = new CompressionLevel [ ] { CompressionLevel . Optimal , CompressionLevel . Fastest , CompressionLevel . NoCompression } ;
238
252
@@ -246,23 +260,26 @@ public static void TestCtors()
246
260
}
247
261
}
248
262
}
263
+
249
264
[ Fact ]
250
- public static void TestLevelOptimial ( )
265
+ public void TestLevelOptimial ( )
251
266
{
252
267
TestCtor ( CompressionLevel . Optimal ) ;
253
268
}
269
+
254
270
[ Fact ]
255
- public static void TestLevelNoCompression ( )
271
+ public void TestLevelNoCompression ( )
256
272
{
257
273
TestCtor ( CompressionLevel . NoCompression ) ;
258
274
}
275
+
259
276
[ Fact ]
260
- public static void TestLevelFastest ( )
277
+ public void TestLevelFastest ( )
261
278
{
262
279
TestCtor ( CompressionLevel . Fastest ) ;
263
280
}
264
281
265
- public static void TestCtor ( CompressionLevel level , bool ? leaveOpen = null )
282
+ private static void TestCtor ( CompressionLevel level , bool ? leaveOpen = null )
266
283
{
267
284
//Create the DeflateStream
268
285
int _bufferSize = 1024 ;
@@ -314,7 +331,7 @@ public static void TestCtor(CompressionLevel level, bool? leaveOpen = null)
314
331
}
315
332
316
333
[ Fact ]
317
- public static async Task Flush ( )
334
+ public async Task Flush ( )
318
335
{
319
336
var ms = new MemoryStream ( ) ;
320
337
var ds = new DeflateStream ( ms , CompressionMode . Compress ) ;
@@ -323,16 +340,18 @@ public static async Task Flush()
323
340
324
341
// Just ensuring Flush doesn't throw
325
342
}
343
+
326
344
[ Fact ]
327
- public static void FlushFailsAfterDispose ( )
345
+ public void FlushFailsAfterDispose ( )
328
346
{
329
347
var ms = new MemoryStream ( ) ;
330
348
var ds = new DeflateStream ( ms , CompressionMode . Compress ) ;
331
349
ds . Dispose ( ) ;
332
350
Assert . Throws < ObjectDisposedException > ( ( ) => { ds . Flush ( ) ; } ) ;
333
351
}
352
+
334
353
[ Fact ]
335
- public static async Task FlushAsyncFailsAfterDispose ( )
354
+ public async Task FlushAsyncFailsAfterDispose ( )
336
355
{
337
356
338
357
var ms = new MemoryStream ( ) ;
@@ -346,7 +365,7 @@ await Assert.ThrowsAsync<ObjectDisposedException>(async () =>
346
365
}
347
366
348
367
[ Fact ]
349
- public static void TestSeekMethodsDecompress ( )
368
+ public void TestSeekMethodsDecompress ( )
350
369
{
351
370
var ms = new MemoryStream ( ) ;
352
371
var zip = new DeflateStream ( ms , CompressionMode . Decompress ) ;
@@ -360,8 +379,9 @@ public static void TestSeekMethodsDecompress()
360
379
//Should we try all the enums? doesn't seem necessary
361
380
Assert . Throws < NotSupportedException > ( delegate { zip . Seek ( 100L , SeekOrigin . Begin ) ; } ) ;
362
381
}
382
+
363
383
[ Fact ]
364
- public static void TestSeekMethodsCompress ( )
384
+ public void TestSeekMethodsCompress ( )
365
385
{
366
386
var ms = new MemoryStream ( ) ;
367
387
var zip = new DeflateStream ( ms , CompressionMode . Compress ) ;
0 commit comments