|
1 | 1 | using System;
|
2 | 2 | using System.IO;
|
3 | 3 | using System.Text;
|
| 4 | +using System.Security; |
4 | 5 |
|
5 | 6 | using NUnit.Framework;
|
6 | 7 |
|
@@ -145,5 +146,63 @@ public void TestInflateDeflate()
|
145 | 146 | Assert.AreEqual(buf2[i], buf[i]);
|
146 | 147 | }
|
147 | 148 | }
|
| 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 | + } |
148 | 207 | }
|
149 | 208 | }
|
0 commit comments