Skip to content

Commit 4fe0cce

Browse files
committed
Added tests for multiple close problem
1 parent 1af3785 commit 4fe0cce

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/Base/InflaterDeflaterTests.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Text;
4+
using System.Security;
45

56
using NUnit.Framework;
67

@@ -145,5 +146,63 @@ public void TestInflateDeflate()
145146
Assert.AreEqual(buf2[i], buf[i]);
146147
}
147148
}
149+
150+
[Test]
151+
[Category("Base")]
152+
public void CloseDeflatorWithNestedUsing()
153+
{
154+
string tempFile = null;
155+
try {
156+
tempFile = Path.GetTempPath();
157+
}
158+
catch (SecurityException) {
159+
}
160+
161+
Assert.IsNotNull(tempFile, "No permission to execute this test?");
162+
if (tempFile != null) {
163+
tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
164+
165+
using (FileStream diskFile = File.Create(tempFile))
166+
using (DeflaterOutputStream deflator = new DeflaterOutputStream(diskFile))
167+
using (StreamWriter txtFile = new StreamWriter(deflator)) {
168+
txtFile.Write("Hello");
169+
txtFile.Flush();
170+
}
171+
172+
File.Delete(tempFile);
173+
}
174+
}
175+
176+
[Test]
177+
[Category("Base")]
178+
public void CloseInflatorWithNestedUsing()
179+
{
180+
string tempFile = null;
181+
try {
182+
tempFile = Path.GetTempPath();
183+
}
184+
catch (SecurityException) {
185+
}
186+
187+
Assert.IsNotNull(tempFile, "No permission to execute this test?");
188+
if (tempFile != null) {
189+
tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
190+
using (FileStream diskFile = File.Create(tempFile))
191+
using (DeflaterOutputStream deflator = new DeflaterOutputStream(diskFile))
192+
using (StreamWriter txtFile = new StreamWriter(deflator)) {
193+
txtFile.Write("Hello");
194+
txtFile.Flush();
195+
}
196+
197+
// This wont actually fail... Test is not valid
198+
using (FileStream diskFile = File.OpenRead(tempFile))
199+
using (InflaterInputStream deflator = new InflaterInputStream(diskFile))
200+
using (StreamReader reader = new StreamReader(deflator)) {
201+
reader.Peek();
202+
}
203+
204+
File.Delete(tempFile);
205+
}
206+
}
148207
}
149208
}

0 commit comments

Comments
 (0)